]>
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> |
55682965 JB |
22 | #include "core.h" |
23 | #include "nl80211.h" | |
b2e1b302 | 24 | #include "reg.h" |
55682965 | 25 | |
5fb628e9 JM |
26 | static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type); |
27 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, | |
28 | struct genl_info *info, | |
29 | struct cfg80211_crypto_settings *settings, | |
30 | int cipher_limit); | |
31 | ||
4c476991 JB |
32 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, |
33 | struct genl_info *info); | |
34 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, | |
35 | struct genl_info *info); | |
36 | ||
55682965 JB |
37 | /* the netlink family */ |
38 | static struct genl_family nl80211_fam = { | |
39 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ | |
40 | .name = "nl80211", /* have users key off the name instead */ | |
41 | .hdrsize = 0, /* no private header */ | |
42 | .version = 1, /* no particular meaning now */ | |
43 | .maxattr = NL80211_ATTR_MAX, | |
463d0183 | 44 | .netnsok = true, |
4c476991 JB |
45 | .pre_doit = nl80211_pre_doit, |
46 | .post_doit = nl80211_post_doit, | |
55682965 JB |
47 | }; |
48 | ||
79c97e97 | 49 | /* internal helper: get rdev and dev */ |
00918d33 JB |
50 | static int get_rdev_dev_by_ifindex(struct net *netns, struct nlattr **attrs, |
51 | struct cfg80211_registered_device **rdev, | |
52 | struct net_device **dev) | |
55682965 JB |
53 | { |
54 | int ifindex; | |
55 | ||
bba95fef | 56 | if (!attrs[NL80211_ATTR_IFINDEX]) |
55682965 JB |
57 | return -EINVAL; |
58 | ||
bba95fef | 59 | ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
00918d33 | 60 | *dev = dev_get_by_index(netns, ifindex); |
55682965 JB |
61 | if (!*dev) |
62 | return -ENODEV; | |
63 | ||
00918d33 | 64 | *rdev = cfg80211_get_dev_from_ifindex(netns, ifindex); |
79c97e97 | 65 | if (IS_ERR(*rdev)) { |
55682965 | 66 | dev_put(*dev); |
79c97e97 | 67 | return PTR_ERR(*rdev); |
55682965 JB |
68 | } |
69 | ||
70 | return 0; | |
71 | } | |
72 | ||
73 | /* policy for the attributes */ | |
b54452b0 | 74 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
55682965 JB |
75 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
76 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, | |
079e24ed | 77 | .len = 20-1 }, |
31888487 | 78 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
72bdcf34 | 79 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
094d05dc | 80 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
b9a5f8ca JM |
81 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
82 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, | |
83 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, | |
84 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, | |
81077e82 | 85 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
55682965 JB |
86 | |
87 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, | |
88 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, | |
89 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, | |
41ade00f | 90 | |
e007b857 EP |
91 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
92 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, | |
41ade00f | 93 | |
b9454e83 | 94 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
41ade00f JB |
95 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
96 | .len = WLAN_MAX_KEY_LEN }, | |
97 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, | |
98 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, | |
99 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, | |
81962267 | 100 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
e31b8213 | 101 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
ed1b6cc7 JB |
102 | |
103 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, | |
104 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, | |
105 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, | |
106 | .len = IEEE80211_MAX_DATA_LEN }, | |
107 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, | |
108 | .len = IEEE80211_MAX_DATA_LEN }, | |
5727ef1b JB |
109 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
110 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, | |
111 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, | |
112 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, | |
113 | .len = NL80211_MAX_SUPP_RATES }, | |
2ec600d6 | 114 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
5727ef1b | 115 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
0a9542ee | 116 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
2ec600d6 LCC |
117 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
118 | .len = IEEE80211_MAX_MESH_ID_LEN }, | |
119 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, | |
9f1ba906 | 120 | |
b2e1b302 LR |
121 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
122 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, | |
123 | ||
9f1ba906 JM |
124 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
125 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, | |
126 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, | |
90c97a04 JM |
127 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
128 | .len = NL80211_MAX_SUPP_RATES }, | |
50b12f59 | 129 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
36aedc90 | 130 | |
24bdd9f4 | 131 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
15d5dda6 | 132 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
93da9cc1 | 133 | |
6c739419 | 134 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
9aed3cc1 JM |
135 | |
136 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, | |
137 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, | |
138 | .len = IEEE80211_MAX_DATA_LEN }, | |
2a519311 JB |
139 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
140 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, | |
636a5d36 JM |
141 | |
142 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, | |
143 | .len = IEEE80211_MAX_SSID_LEN }, | |
144 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, | |
145 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, | |
04a773ad | 146 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
1965c853 | 147 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
dc6382ce | 148 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
eccb8e8f JB |
149 | [NL80211_ATTR_STA_FLAGS2] = { |
150 | .len = sizeof(struct nl80211_sta_flag_update), | |
151 | }, | |
3f77316c | 152 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
c0692b8f JB |
153 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
154 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, | |
b23aa676 SO |
155 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
156 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, | |
157 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, | |
463d0183 | 158 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
8b787643 | 159 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
67fbb16b SO |
160 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
161 | .len = WLAN_PMKID_LEN }, | |
9588bbd5 JM |
162 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
163 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, | |
13ae75b1 | 164 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
026331c4 JM |
165 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
166 | .len = IEEE80211_MAX_DATA_LEN }, | |
167 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, | |
ffb9eb3d | 168 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
d6dc1a38 | 169 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
d5cdfacb | 170 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
fd8aaaf3 | 171 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
98d2ff8b JO |
172 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
173 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, | |
2e161f78 | 174 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
afe0cbf8 BR |
175 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
176 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, | |
885a46d0 | 177 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
f7ca38df | 178 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
dbd2fd65 | 179 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
ff1b6e69 | 180 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
9c3990aa | 181 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
bbe6ad6d | 182 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
e5497d76 | 183 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
34850ab2 | 184 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
32e9de84 | 185 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
9946ecfb JM |
186 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
187 | .len = IEEE80211_MAX_DATA_LEN }, | |
188 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, | |
189 | .len = IEEE80211_MAX_DATA_LEN }, | |
f4b34b55 | 190 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
a1f1c21c | 191 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
e9f935e3 | 192 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
109086ce AN |
193 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
194 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, | |
195 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, | |
196 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, | |
197 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, | |
e247bd90 | 198 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
00f740e1 AN |
199 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
200 | .len = IEEE80211_MAX_DATA_LEN }, | |
8b60b078 | 201 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
7e7c8926 BG |
202 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
203 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { | |
204 | .len = NL80211_HT_CAPABILITY_LEN | |
205 | }, | |
1d9d9213 | 206 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
1b658f11 | 207 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
4486ea98 | 208 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
55682965 JB |
209 | }; |
210 | ||
e31b8213 | 211 | /* policy for the key attributes */ |
b54452b0 | 212 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
fffd0934 | 213 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
b9454e83 JB |
214 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
215 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, | |
81962267 | 216 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
b9454e83 JB |
217 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
218 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, | |
e31b8213 | 219 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
dbd2fd65 JB |
220 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
221 | }; | |
222 | ||
223 | /* policy for the key default flags */ | |
224 | static const struct nla_policy | |
225 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { | |
226 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, | |
227 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, | |
b9454e83 JB |
228 | }; |
229 | ||
ff1b6e69 JB |
230 | /* policy for WoWLAN attributes */ |
231 | static const struct nla_policy | |
232 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { | |
233 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, | |
234 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, | |
235 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, | |
236 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, | |
77dbbb13 JB |
237 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
238 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, | |
239 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, | |
240 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, | |
ff1b6e69 JB |
241 | }; |
242 | ||
e5497d76 JB |
243 | /* policy for GTK rekey offload attributes */ |
244 | static const struct nla_policy | |
245 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { | |
246 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, | |
247 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, | |
248 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, | |
249 | }; | |
250 | ||
a1f1c21c LC |
251 | static const struct nla_policy |
252 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { | |
253 | [NL80211_ATTR_SCHED_SCAN_MATCH_SSID] = { .type = NLA_BINARY, | |
254 | .len = IEEE80211_MAX_SSID_LEN }, | |
255 | }; | |
256 | ||
a043897a HS |
257 | /* ifidx get helper */ |
258 | static int nl80211_get_ifidx(struct netlink_callback *cb) | |
259 | { | |
260 | int res; | |
261 | ||
262 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
263 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
264 | nl80211_policy); | |
265 | if (res) | |
266 | return res; | |
267 | ||
268 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) | |
269 | return -EINVAL; | |
270 | ||
271 | res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); | |
272 | if (!res) | |
273 | return -EINVAL; | |
274 | return res; | |
275 | } | |
276 | ||
67748893 JB |
277 | static int nl80211_prepare_netdev_dump(struct sk_buff *skb, |
278 | struct netlink_callback *cb, | |
279 | struct cfg80211_registered_device **rdev, | |
280 | struct net_device **dev) | |
281 | { | |
282 | int ifidx = cb->args[0]; | |
283 | int err; | |
284 | ||
285 | if (!ifidx) | |
286 | ifidx = nl80211_get_ifidx(cb); | |
287 | if (ifidx < 0) | |
288 | return ifidx; | |
289 | ||
290 | cb->args[0] = ifidx; | |
291 | ||
292 | rtnl_lock(); | |
293 | ||
294 | *dev = __dev_get_by_index(sock_net(skb->sk), ifidx); | |
295 | if (!*dev) { | |
296 | err = -ENODEV; | |
297 | goto out_rtnl; | |
298 | } | |
299 | ||
300 | *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); | |
3cc25e51 FF |
301 | if (IS_ERR(*rdev)) { |
302 | err = PTR_ERR(*rdev); | |
67748893 JB |
303 | goto out_rtnl; |
304 | } | |
305 | ||
306 | return 0; | |
307 | out_rtnl: | |
308 | rtnl_unlock(); | |
309 | return err; | |
310 | } | |
311 | ||
312 | static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev) | |
313 | { | |
314 | cfg80211_unlock_rdev(rdev); | |
315 | rtnl_unlock(); | |
316 | } | |
317 | ||
f4a11bb0 JB |
318 | /* IE validation */ |
319 | static bool is_valid_ie_attr(const struct nlattr *attr) | |
320 | { | |
321 | const u8 *pos; | |
322 | int len; | |
323 | ||
324 | if (!attr) | |
325 | return true; | |
326 | ||
327 | pos = nla_data(attr); | |
328 | len = nla_len(attr); | |
329 | ||
330 | while (len) { | |
331 | u8 elemlen; | |
332 | ||
333 | if (len < 2) | |
334 | return false; | |
335 | len -= 2; | |
336 | ||
337 | elemlen = pos[1]; | |
338 | if (elemlen > len) | |
339 | return false; | |
340 | ||
341 | len -= elemlen; | |
342 | pos += 2 + elemlen; | |
343 | } | |
344 | ||
345 | return true; | |
346 | } | |
347 | ||
55682965 JB |
348 | /* message building helper */ |
349 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq, | |
350 | int flags, u8 cmd) | |
351 | { | |
352 | /* since there is no private header just add the generic one */ | |
353 | return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd); | |
354 | } | |
355 | ||
5dab3b8a LR |
356 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
357 | struct ieee80211_channel *chan) | |
358 | { | |
9360ffd1 DM |
359 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
360 | chan->center_freq)) | |
361 | goto nla_put_failure; | |
5dab3b8a | 362 | |
9360ffd1 DM |
363 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
364 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) | |
365 | goto nla_put_failure; | |
366 | if ((chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) && | |
367 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN)) | |
368 | goto nla_put_failure; | |
369 | if ((chan->flags & IEEE80211_CHAN_NO_IBSS) && | |
370 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IBSS)) | |
371 | goto nla_put_failure; | |
372 | if ((chan->flags & IEEE80211_CHAN_RADAR) && | |
373 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) | |
374 | goto nla_put_failure; | |
5dab3b8a | 375 | |
9360ffd1 DM |
376 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
377 | DBM_TO_MBM(chan->max_power))) | |
378 | goto nla_put_failure; | |
5dab3b8a LR |
379 | |
380 | return 0; | |
381 | ||
382 | nla_put_failure: | |
383 | return -ENOBUFS; | |
384 | } | |
385 | ||
55682965 JB |
386 | /* netlink command implementations */ |
387 | ||
b9454e83 JB |
388 | struct key_parse { |
389 | struct key_params p; | |
390 | int idx; | |
e31b8213 | 391 | int type; |
b9454e83 | 392 | bool def, defmgmt; |
dbd2fd65 | 393 | bool def_uni, def_multi; |
b9454e83 JB |
394 | }; |
395 | ||
396 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) | |
397 | { | |
398 | struct nlattr *tb[NL80211_KEY_MAX + 1]; | |
399 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, | |
400 | nl80211_key_policy); | |
401 | if (err) | |
402 | return err; | |
403 | ||
404 | k->def = !!tb[NL80211_KEY_DEFAULT]; | |
405 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; | |
406 | ||
dbd2fd65 JB |
407 | if (k->def) { |
408 | k->def_uni = true; | |
409 | k->def_multi = true; | |
410 | } | |
411 | if (k->defmgmt) | |
412 | k->def_multi = true; | |
413 | ||
b9454e83 JB |
414 | if (tb[NL80211_KEY_IDX]) |
415 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); | |
416 | ||
417 | if (tb[NL80211_KEY_DATA]) { | |
418 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); | |
419 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); | |
420 | } | |
421 | ||
422 | if (tb[NL80211_KEY_SEQ]) { | |
423 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); | |
424 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); | |
425 | } | |
426 | ||
427 | if (tb[NL80211_KEY_CIPHER]) | |
428 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); | |
429 | ||
e31b8213 JB |
430 | if (tb[NL80211_KEY_TYPE]) { |
431 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); | |
432 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
433 | return -EINVAL; | |
434 | } | |
435 | ||
dbd2fd65 JB |
436 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
437 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
2da8f419 JB |
438 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
439 | tb[NL80211_KEY_DEFAULT_TYPES], | |
440 | nl80211_key_default_policy); | |
dbd2fd65 JB |
441 | if (err) |
442 | return err; | |
443 | ||
444 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
445 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
446 | } | |
447 | ||
b9454e83 JB |
448 | return 0; |
449 | } | |
450 | ||
451 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) | |
452 | { | |
453 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { | |
454 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); | |
455 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); | |
456 | } | |
457 | ||
458 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { | |
459 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
460 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
461 | } | |
462 | ||
463 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
464 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
465 | ||
466 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) | |
467 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); | |
468 | ||
469 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; | |
470 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; | |
471 | ||
dbd2fd65 JB |
472 | if (k->def) { |
473 | k->def_uni = true; | |
474 | k->def_multi = true; | |
475 | } | |
476 | if (k->defmgmt) | |
477 | k->def_multi = true; | |
478 | ||
e31b8213 JB |
479 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
480 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
481 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
482 | return -EINVAL; | |
483 | } | |
484 | ||
dbd2fd65 JB |
485 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
486 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
487 | int err = nla_parse_nested( | |
488 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, | |
489 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], | |
490 | nl80211_key_default_policy); | |
491 | if (err) | |
492 | return err; | |
493 | ||
494 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
495 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
496 | } | |
497 | ||
b9454e83 JB |
498 | return 0; |
499 | } | |
500 | ||
501 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) | |
502 | { | |
503 | int err; | |
504 | ||
505 | memset(k, 0, sizeof(*k)); | |
506 | k->idx = -1; | |
e31b8213 | 507 | k->type = -1; |
b9454e83 JB |
508 | |
509 | if (info->attrs[NL80211_ATTR_KEY]) | |
510 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); | |
511 | else | |
512 | err = nl80211_parse_key_old(info, k); | |
513 | ||
514 | if (err) | |
515 | return err; | |
516 | ||
517 | if (k->def && k->defmgmt) | |
518 | return -EINVAL; | |
519 | ||
dbd2fd65 JB |
520 | if (k->defmgmt) { |
521 | if (k->def_uni || !k->def_multi) | |
522 | return -EINVAL; | |
523 | } | |
524 | ||
b9454e83 JB |
525 | if (k->idx != -1) { |
526 | if (k->defmgmt) { | |
527 | if (k->idx < 4 || k->idx > 5) | |
528 | return -EINVAL; | |
529 | } else if (k->def) { | |
530 | if (k->idx < 0 || k->idx > 3) | |
531 | return -EINVAL; | |
532 | } else { | |
533 | if (k->idx < 0 || k->idx > 5) | |
534 | return -EINVAL; | |
535 | } | |
536 | } | |
537 | ||
538 | return 0; | |
539 | } | |
540 | ||
fffd0934 JB |
541 | static struct cfg80211_cached_keys * |
542 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, | |
543 | struct nlattr *keys) | |
544 | { | |
545 | struct key_parse parse; | |
546 | struct nlattr *key; | |
547 | struct cfg80211_cached_keys *result; | |
548 | int rem, err, def = 0; | |
549 | ||
550 | result = kzalloc(sizeof(*result), GFP_KERNEL); | |
551 | if (!result) | |
552 | return ERR_PTR(-ENOMEM); | |
553 | ||
554 | result->def = -1; | |
555 | result->defmgmt = -1; | |
556 | ||
557 | nla_for_each_nested(key, keys, rem) { | |
558 | memset(&parse, 0, sizeof(parse)); | |
559 | parse.idx = -1; | |
560 | ||
561 | err = nl80211_parse_key_new(key, &parse); | |
562 | if (err) | |
563 | goto error; | |
564 | err = -EINVAL; | |
565 | if (!parse.p.key) | |
566 | goto error; | |
567 | if (parse.idx < 0 || parse.idx > 4) | |
568 | goto error; | |
569 | if (parse.def) { | |
570 | if (def) | |
571 | goto error; | |
572 | def = 1; | |
573 | result->def = parse.idx; | |
dbd2fd65 JB |
574 | if (!parse.def_uni || !parse.def_multi) |
575 | goto error; | |
fffd0934 JB |
576 | } else if (parse.defmgmt) |
577 | goto error; | |
578 | err = cfg80211_validate_key_settings(rdev, &parse.p, | |
e31b8213 | 579 | parse.idx, false, NULL); |
fffd0934 JB |
580 | if (err) |
581 | goto error; | |
582 | result->params[parse.idx].cipher = parse.p.cipher; | |
583 | result->params[parse.idx].key_len = parse.p.key_len; | |
584 | result->params[parse.idx].key = result->data[parse.idx]; | |
585 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); | |
586 | } | |
587 | ||
588 | return result; | |
589 | error: | |
590 | kfree(result); | |
591 | return ERR_PTR(err); | |
592 | } | |
593 | ||
594 | static int nl80211_key_allowed(struct wireless_dev *wdev) | |
595 | { | |
596 | ASSERT_WDEV_LOCK(wdev); | |
597 | ||
fffd0934 JB |
598 | switch (wdev->iftype) { |
599 | case NL80211_IFTYPE_AP: | |
600 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 601 | case NL80211_IFTYPE_P2P_GO: |
ff973af7 | 602 | case NL80211_IFTYPE_MESH_POINT: |
fffd0934 JB |
603 | break; |
604 | case NL80211_IFTYPE_ADHOC: | |
605 | if (!wdev->current_bss) | |
606 | return -ENOLINK; | |
607 | break; | |
608 | case NL80211_IFTYPE_STATION: | |
074ac8df | 609 | case NL80211_IFTYPE_P2P_CLIENT: |
fffd0934 JB |
610 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
611 | return -ENOLINK; | |
612 | break; | |
613 | default: | |
614 | return -EINVAL; | |
615 | } | |
616 | ||
617 | return 0; | |
618 | } | |
619 | ||
7527a782 JB |
620 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
621 | { | |
622 | struct nlattr *nl_modes = nla_nest_start(msg, attr); | |
623 | int i; | |
624 | ||
625 | if (!nl_modes) | |
626 | goto nla_put_failure; | |
627 | ||
628 | i = 0; | |
629 | while (ifmodes) { | |
9360ffd1 DM |
630 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
631 | goto nla_put_failure; | |
7527a782 JB |
632 | ifmodes >>= 1; |
633 | i++; | |
634 | } | |
635 | ||
636 | nla_nest_end(msg, nl_modes); | |
637 | return 0; | |
638 | ||
639 | nla_put_failure: | |
640 | return -ENOBUFS; | |
641 | } | |
642 | ||
643 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, | |
644 | struct sk_buff *msg) | |
645 | { | |
646 | struct nlattr *nl_combis; | |
647 | int i, j; | |
648 | ||
649 | nl_combis = nla_nest_start(msg, | |
650 | NL80211_ATTR_INTERFACE_COMBINATIONS); | |
651 | if (!nl_combis) | |
652 | goto nla_put_failure; | |
653 | ||
654 | for (i = 0; i < wiphy->n_iface_combinations; i++) { | |
655 | const struct ieee80211_iface_combination *c; | |
656 | struct nlattr *nl_combi, *nl_limits; | |
657 | ||
658 | c = &wiphy->iface_combinations[i]; | |
659 | ||
660 | nl_combi = nla_nest_start(msg, i + 1); | |
661 | if (!nl_combi) | |
662 | goto nla_put_failure; | |
663 | ||
664 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); | |
665 | if (!nl_limits) | |
666 | goto nla_put_failure; | |
667 | ||
668 | for (j = 0; j < c->n_limits; j++) { | |
669 | struct nlattr *nl_limit; | |
670 | ||
671 | nl_limit = nla_nest_start(msg, j + 1); | |
672 | if (!nl_limit) | |
673 | goto nla_put_failure; | |
9360ffd1 DM |
674 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
675 | c->limits[j].max)) | |
676 | goto nla_put_failure; | |
7527a782 JB |
677 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
678 | c->limits[j].types)) | |
679 | goto nla_put_failure; | |
680 | nla_nest_end(msg, nl_limit); | |
681 | } | |
682 | ||
683 | nla_nest_end(msg, nl_limits); | |
684 | ||
9360ffd1 DM |
685 | if (c->beacon_int_infra_match && |
686 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) | |
687 | goto nla_put_failure; | |
688 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, | |
689 | c->num_different_channels) || | |
690 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, | |
691 | c->max_interfaces)) | |
692 | goto nla_put_failure; | |
7527a782 JB |
693 | |
694 | nla_nest_end(msg, nl_combi); | |
695 | } | |
696 | ||
697 | nla_nest_end(msg, nl_combis); | |
698 | ||
699 | return 0; | |
700 | nla_put_failure: | |
701 | return -ENOBUFS; | |
702 | } | |
703 | ||
55682965 JB |
704 | static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
705 | struct cfg80211_registered_device *dev) | |
706 | { | |
707 | void *hdr; | |
ee688b00 JB |
708 | struct nlattr *nl_bands, *nl_band; |
709 | struct nlattr *nl_freqs, *nl_freq; | |
710 | struct nlattr *nl_rates, *nl_rate; | |
8fdc621d | 711 | struct nlattr *nl_cmds; |
ee688b00 JB |
712 | enum ieee80211_band band; |
713 | struct ieee80211_channel *chan; | |
714 | struct ieee80211_rate *rate; | |
715 | int i; | |
2e161f78 JB |
716 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
717 | dev->wiphy.mgmt_stypes; | |
55682965 JB |
718 | |
719 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY); | |
720 | if (!hdr) | |
721 | return -1; | |
722 | ||
9360ffd1 DM |
723 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx) || |
724 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)) || | |
725 | nla_put_u32(msg, NL80211_ATTR_GENERATION, | |
726 | cfg80211_rdev_list_generation) || | |
727 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, | |
728 | dev->wiphy.retry_short) || | |
729 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, | |
730 | dev->wiphy.retry_long) || | |
731 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, | |
732 | dev->wiphy.frag_threshold) || | |
733 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, | |
734 | dev->wiphy.rts_threshold) || | |
735 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, | |
736 | dev->wiphy.coverage_class) || | |
737 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, | |
738 | dev->wiphy.max_scan_ssids) || | |
739 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, | |
740 | dev->wiphy.max_sched_scan_ssids) || | |
741 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, | |
742 | dev->wiphy.max_scan_ie_len) || | |
743 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, | |
744 | dev->wiphy.max_sched_scan_ie_len) || | |
745 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, | |
746 | dev->wiphy.max_match_sets)) | |
747 | goto nla_put_failure; | |
748 | ||
749 | if ((dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && | |
750 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) | |
751 | goto nla_put_failure; | |
752 | if ((dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && | |
753 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) | |
754 | goto nla_put_failure; | |
755 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && | |
756 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) | |
757 | goto nla_put_failure; | |
758 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && | |
759 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) | |
760 | goto nla_put_failure; | |
761 | if ((dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && | |
762 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) | |
763 | goto nla_put_failure; | |
764 | if ((dev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && | |
765 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) | |
766 | goto nla_put_failure; | |
767 | ||
768 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, | |
769 | sizeof(u32) * dev->wiphy.n_cipher_suites, | |
770 | dev->wiphy.cipher_suites)) | |
771 | goto nla_put_failure; | |
772 | ||
773 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, | |
774 | dev->wiphy.max_num_pmkids)) | |
775 | goto nla_put_failure; | |
776 | ||
777 | if ((dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | |
778 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) | |
779 | goto nla_put_failure; | |
780 | ||
781 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, | |
782 | dev->wiphy.available_antennas_tx) || | |
783 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, | |
784 | dev->wiphy.available_antennas_rx)) | |
785 | goto nla_put_failure; | |
786 | ||
787 | if ((dev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && | |
788 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, | |
789 | dev->wiphy.probe_resp_offload)) | |
790 | goto nla_put_failure; | |
87bbbe22 | 791 | |
7f531e03 BR |
792 | if ((dev->wiphy.available_antennas_tx || |
793 | dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) { | |
afe0cbf8 BR |
794 | u32 tx_ant = 0, rx_ant = 0; |
795 | int res; | |
796 | res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant); | |
797 | if (!res) { | |
9360ffd1 DM |
798 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, |
799 | tx_ant) || | |
800 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, | |
801 | rx_ant)) | |
802 | goto nla_put_failure; | |
afe0cbf8 BR |
803 | } |
804 | } | |
805 | ||
7527a782 JB |
806 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
807 | dev->wiphy.interface_modes)) | |
f59ac048 LR |
808 | goto nla_put_failure; |
809 | ||
ee688b00 JB |
810 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
811 | if (!nl_bands) | |
812 | goto nla_put_failure; | |
813 | ||
814 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
815 | if (!dev->wiphy.bands[band]) | |
816 | continue; | |
817 | ||
818 | nl_band = nla_nest_start(msg, band); | |
819 | if (!nl_band) | |
820 | goto nla_put_failure; | |
821 | ||
d51626df | 822 | /* add HT info */ |
9360ffd1 DM |
823 | if (dev->wiphy.bands[band]->ht_cap.ht_supported && |
824 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, | |
825 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), | |
826 | &dev->wiphy.bands[band]->ht_cap.mcs) || | |
827 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, | |
828 | dev->wiphy.bands[band]->ht_cap.cap) || | |
829 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, | |
830 | dev->wiphy.bands[band]->ht_cap.ampdu_factor) || | |
831 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, | |
832 | dev->wiphy.bands[band]->ht_cap.ampdu_density))) | |
833 | goto nla_put_failure; | |
d51626df | 834 | |
ee688b00 JB |
835 | /* add frequencies */ |
836 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); | |
837 | if (!nl_freqs) | |
838 | goto nla_put_failure; | |
839 | ||
840 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { | |
841 | nl_freq = nla_nest_start(msg, i); | |
842 | if (!nl_freq) | |
843 | goto nla_put_failure; | |
844 | ||
845 | chan = &dev->wiphy.bands[band]->channels[i]; | |
5dab3b8a LR |
846 | |
847 | if (nl80211_msg_put_channel(msg, chan)) | |
848 | goto nla_put_failure; | |
e2f367f2 | 849 | |
ee688b00 JB |
850 | nla_nest_end(msg, nl_freq); |
851 | } | |
852 | ||
853 | nla_nest_end(msg, nl_freqs); | |
854 | ||
855 | /* add bitrates */ | |
856 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); | |
857 | if (!nl_rates) | |
858 | goto nla_put_failure; | |
859 | ||
860 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { | |
861 | nl_rate = nla_nest_start(msg, i); | |
862 | if (!nl_rate) | |
863 | goto nla_put_failure; | |
864 | ||
865 | rate = &dev->wiphy.bands[band]->bitrates[i]; | |
9360ffd1 DM |
866 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, |
867 | rate->bitrate)) | |
868 | goto nla_put_failure; | |
869 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && | |
870 | nla_put_flag(msg, | |
871 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) | |
872 | goto nla_put_failure; | |
ee688b00 JB |
873 | |
874 | nla_nest_end(msg, nl_rate); | |
875 | } | |
876 | ||
877 | nla_nest_end(msg, nl_rates); | |
878 | ||
879 | nla_nest_end(msg, nl_band); | |
880 | } | |
881 | nla_nest_end(msg, nl_bands); | |
882 | ||
8fdc621d JB |
883 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
884 | if (!nl_cmds) | |
885 | goto nla_put_failure; | |
886 | ||
887 | i = 0; | |
888 | #define CMD(op, n) \ | |
889 | do { \ | |
890 | if (dev->ops->op) { \ | |
891 | i++; \ | |
9360ffd1 DM |
892 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ |
893 | goto nla_put_failure; \ | |
8fdc621d JB |
894 | } \ |
895 | } while (0) | |
896 | ||
897 | CMD(add_virtual_intf, NEW_INTERFACE); | |
898 | CMD(change_virtual_intf, SET_INTERFACE); | |
899 | CMD(add_key, NEW_KEY); | |
8860020e | 900 | CMD(start_ap, START_AP); |
8fdc621d JB |
901 | CMD(add_station, NEW_STATION); |
902 | CMD(add_mpath, NEW_MPATH); | |
24bdd9f4 | 903 | CMD(update_mesh_config, SET_MESH_CONFIG); |
8fdc621d | 904 | CMD(change_bss, SET_BSS); |
636a5d36 JM |
905 | CMD(auth, AUTHENTICATE); |
906 | CMD(assoc, ASSOCIATE); | |
907 | CMD(deauth, DEAUTHENTICATE); | |
908 | CMD(disassoc, DISASSOCIATE); | |
04a773ad | 909 | CMD(join_ibss, JOIN_IBSS); |
29cbe68c | 910 | CMD(join_mesh, JOIN_MESH); |
67fbb16b SO |
911 | CMD(set_pmksa, SET_PMKSA); |
912 | CMD(del_pmksa, DEL_PMKSA); | |
913 | CMD(flush_pmksa, FLUSH_PMKSA); | |
7c4ef712 JB |
914 | if (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
915 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); | |
13ae75b1 | 916 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
2e161f78 | 917 | CMD(mgmt_tx, FRAME); |
f7ca38df | 918 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); |
5be83de5 | 919 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
463d0183 | 920 | i++; |
9360ffd1 DM |
921 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) |
922 | goto nla_put_failure; | |
463d0183 | 923 | } |
aa430da4 JB |
924 | if (dev->ops->set_channel || dev->ops->start_ap) { |
925 | i++; | |
926 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) | |
927 | goto nla_put_failure; | |
928 | } | |
e8347eba | 929 | CMD(set_wds_peer, SET_WDS_PEER); |
109086ce AN |
930 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
931 | CMD(tdls_mgmt, TDLS_MGMT); | |
932 | CMD(tdls_oper, TDLS_OPER); | |
933 | } | |
807f8a8c LC |
934 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
935 | CMD(sched_scan_start, START_SCHED_SCAN); | |
7f6cf311 | 936 | CMD(probe_client, PROBE_CLIENT); |
1d9d9213 | 937 | CMD(set_noack_map, SET_NOACK_MAP); |
5e760230 JB |
938 | if (dev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
939 | i++; | |
9360ffd1 DM |
940 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) |
941 | goto nla_put_failure; | |
5e760230 | 942 | } |
8fdc621d | 943 | |
4745fc09 KV |
944 | #ifdef CONFIG_NL80211_TESTMODE |
945 | CMD(testmode_cmd, TESTMODE); | |
946 | #endif | |
947 | ||
8fdc621d | 948 | #undef CMD |
b23aa676 | 949 | |
6829c878 | 950 | if (dev->ops->connect || dev->ops->auth) { |
b23aa676 | 951 | i++; |
9360ffd1 DM |
952 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) |
953 | goto nla_put_failure; | |
b23aa676 SO |
954 | } |
955 | ||
6829c878 | 956 | if (dev->ops->disconnect || dev->ops->deauth) { |
b23aa676 | 957 | i++; |
9360ffd1 DM |
958 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) |
959 | goto nla_put_failure; | |
b23aa676 SO |
960 | } |
961 | ||
8fdc621d JB |
962 | nla_nest_end(msg, nl_cmds); |
963 | ||
7c4ef712 | 964 | if (dev->ops->remain_on_channel && |
9360ffd1 DM |
965 | (dev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && |
966 | nla_put_u32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, | |
967 | dev->wiphy.max_remain_on_channel_duration)) | |
968 | goto nla_put_failure; | |
a293911d | 969 | |
9360ffd1 DM |
970 | if ((dev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
971 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) | |
972 | goto nla_put_failure; | |
f7ca38df | 973 | |
2e161f78 JB |
974 | if (mgmt_stypes) { |
975 | u16 stypes; | |
976 | struct nlattr *nl_ftypes, *nl_ifs; | |
977 | enum nl80211_iftype ift; | |
978 | ||
979 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); | |
980 | if (!nl_ifs) | |
981 | goto nla_put_failure; | |
982 | ||
983 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { | |
984 | nl_ftypes = nla_nest_start(msg, ift); | |
985 | if (!nl_ftypes) | |
986 | goto nla_put_failure; | |
987 | i = 0; | |
988 | stypes = mgmt_stypes[ift].tx; | |
989 | while (stypes) { | |
9360ffd1 DM |
990 | if ((stypes & 1) && |
991 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
992 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
993 | goto nla_put_failure; | |
2e161f78 JB |
994 | stypes >>= 1; |
995 | i++; | |
996 | } | |
997 | nla_nest_end(msg, nl_ftypes); | |
998 | } | |
999 | ||
74b70a4e JB |
1000 | nla_nest_end(msg, nl_ifs); |
1001 | ||
2e161f78 JB |
1002 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
1003 | if (!nl_ifs) | |
1004 | goto nla_put_failure; | |
1005 | ||
1006 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { | |
1007 | nl_ftypes = nla_nest_start(msg, ift); | |
1008 | if (!nl_ftypes) | |
1009 | goto nla_put_failure; | |
1010 | i = 0; | |
1011 | stypes = mgmt_stypes[ift].rx; | |
1012 | while (stypes) { | |
9360ffd1 DM |
1013 | if ((stypes & 1) && |
1014 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1015 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1016 | goto nla_put_failure; | |
2e161f78 JB |
1017 | stypes >>= 1; |
1018 | i++; | |
1019 | } | |
1020 | nla_nest_end(msg, nl_ftypes); | |
1021 | } | |
1022 | nla_nest_end(msg, nl_ifs); | |
1023 | } | |
1024 | ||
ff1b6e69 JB |
1025 | if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) { |
1026 | struct nlattr *nl_wowlan; | |
1027 | ||
1028 | nl_wowlan = nla_nest_start(msg, | |
1029 | NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); | |
1030 | if (!nl_wowlan) | |
1031 | goto nla_put_failure; | |
1032 | ||
9360ffd1 DM |
1033 | if (((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) && |
1034 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || | |
1035 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) && | |
1036 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || | |
1037 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) && | |
1038 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || | |
1039 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && | |
1040 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || | |
1041 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && | |
1042 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || | |
1043 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && | |
1044 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || | |
1045 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && | |
1046 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || | |
1047 | ((dev->wiphy.wowlan.flags & WIPHY_WOWLAN_RFKILL_RELEASE) && | |
1048 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) | |
1049 | goto nla_put_failure; | |
ff1b6e69 JB |
1050 | if (dev->wiphy.wowlan.n_patterns) { |
1051 | struct nl80211_wowlan_pattern_support pat = { | |
1052 | .max_patterns = dev->wiphy.wowlan.n_patterns, | |
1053 | .min_pattern_len = | |
1054 | dev->wiphy.wowlan.pattern_min_len, | |
1055 | .max_pattern_len = | |
1056 | dev->wiphy.wowlan.pattern_max_len, | |
1057 | }; | |
9360ffd1 DM |
1058 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
1059 | sizeof(pat), &pat)) | |
1060 | goto nla_put_failure; | |
ff1b6e69 JB |
1061 | } |
1062 | ||
1063 | nla_nest_end(msg, nl_wowlan); | |
1064 | } | |
1065 | ||
7527a782 JB |
1066 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, |
1067 | dev->wiphy.software_iftypes)) | |
1068 | goto nla_put_failure; | |
1069 | ||
1070 | if (nl80211_put_iface_combinations(&dev->wiphy, msg)) | |
1071 | goto nla_put_failure; | |
1072 | ||
9360ffd1 DM |
1073 | if ((dev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
1074 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, | |
1075 | dev->wiphy.ap_sme_capa)) | |
1076 | goto nla_put_failure; | |
562a7480 | 1077 | |
9360ffd1 DM |
1078 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, |
1079 | dev->wiphy.features)) | |
1080 | goto nla_put_failure; | |
1f074bd8 | 1081 | |
9360ffd1 DM |
1082 | if (dev->wiphy.ht_capa_mod_mask && |
1083 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, | |
1084 | sizeof(*dev->wiphy.ht_capa_mod_mask), | |
1085 | dev->wiphy.ht_capa_mod_mask)) | |
1086 | goto nla_put_failure; | |
7e7c8926 | 1087 | |
55682965 JB |
1088 | return genlmsg_end(msg, hdr); |
1089 | ||
1090 | nla_put_failure: | |
bc3ed28c TG |
1091 | genlmsg_cancel(msg, hdr); |
1092 | return -EMSGSIZE; | |
55682965 JB |
1093 | } |
1094 | ||
1095 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) | |
1096 | { | |
1097 | int idx = 0; | |
1098 | int start = cb->args[0]; | |
1099 | struct cfg80211_registered_device *dev; | |
1100 | ||
a1794390 | 1101 | mutex_lock(&cfg80211_mutex); |
79c97e97 | 1102 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
463d0183 JB |
1103 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
1104 | continue; | |
b4637271 | 1105 | if (++idx <= start) |
55682965 JB |
1106 | continue; |
1107 | if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid, | |
1108 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
b4637271 JV |
1109 | dev) < 0) { |
1110 | idx--; | |
55682965 | 1111 | break; |
b4637271 | 1112 | } |
55682965 | 1113 | } |
a1794390 | 1114 | mutex_unlock(&cfg80211_mutex); |
55682965 JB |
1115 | |
1116 | cb->args[0] = idx; | |
1117 | ||
1118 | return skb->len; | |
1119 | } | |
1120 | ||
1121 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) | |
1122 | { | |
1123 | struct sk_buff *msg; | |
4c476991 | 1124 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
55682965 | 1125 | |
fd2120ca | 1126 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 | 1127 | if (!msg) |
4c476991 | 1128 | return -ENOMEM; |
55682965 | 1129 | |
4c476991 JB |
1130 | if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) { |
1131 | nlmsg_free(msg); | |
1132 | return -ENOBUFS; | |
1133 | } | |
55682965 | 1134 | |
134e6375 | 1135 | return genlmsg_reply(msg, info); |
55682965 JB |
1136 | } |
1137 | ||
31888487 JM |
1138 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
1139 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, | |
1140 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, | |
1141 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, | |
1142 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, | |
1143 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, | |
1144 | }; | |
1145 | ||
1146 | static int parse_txq_params(struct nlattr *tb[], | |
1147 | struct ieee80211_txq_params *txq_params) | |
1148 | { | |
a3304b0a | 1149 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
31888487 JM |
1150 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
1151 | !tb[NL80211_TXQ_ATTR_AIFS]) | |
1152 | return -EINVAL; | |
1153 | ||
a3304b0a | 1154 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
31888487 JM |
1155 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
1156 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); | |
1157 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); | |
1158 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); | |
1159 | ||
a3304b0a JB |
1160 | if (txq_params->ac >= NL80211_NUM_ACS) |
1161 | return -EINVAL; | |
1162 | ||
31888487 JM |
1163 | return 0; |
1164 | } | |
1165 | ||
f444de05 JB |
1166 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
1167 | { | |
1168 | /* | |
685d12a1 JB |
1169 | * You can only set the channel explicitly for AP and |
1170 | * mesh type interfaces; all others have their channel | |
f444de05 JB |
1171 | * managed via their respective "establish a connection" |
1172 | * command (connect, join, ...) | |
1173 | * | |
1174 | * Monitors are special as they are normally slaved to | |
1175 | * whatever else is going on, so they behave as though | |
1176 | * you tried setting the wiphy channel itself. | |
aa430da4 JB |
1177 | * |
1178 | * For AP/GO modes, it's only for compatibility, you can | |
1179 | * also give the channel to the start-AP command. | |
f444de05 JB |
1180 | */ |
1181 | return !wdev || | |
1182 | wdev->iftype == NL80211_IFTYPE_AP || | |
f444de05 | 1183 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
074ac8df JB |
1184 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
1185 | wdev->iftype == NL80211_IFTYPE_P2P_GO; | |
f444de05 JB |
1186 | } |
1187 | ||
cd6c6598 JB |
1188 | static bool nl80211_valid_channel_type(struct genl_info *info, |
1189 | enum nl80211_channel_type *channel_type) | |
1190 | { | |
1191 | enum nl80211_channel_type tmp; | |
1192 | ||
1193 | if (!info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) | |
1194 | return false; | |
1195 | ||
1196 | tmp = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
1197 | if (tmp != NL80211_CHAN_NO_HT && | |
1198 | tmp != NL80211_CHAN_HT20 && | |
1199 | tmp != NL80211_CHAN_HT40PLUS && | |
1200 | tmp != NL80211_CHAN_HT40MINUS) | |
1201 | return false; | |
1202 | ||
1203 | if (channel_type) | |
1204 | *channel_type = tmp; | |
1205 | ||
1206 | return true; | |
1207 | } | |
1208 | ||
f444de05 JB |
1209 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
1210 | struct wireless_dev *wdev, | |
1211 | struct genl_info *info) | |
1212 | { | |
aa430da4 | 1213 | struct ieee80211_channel *channel; |
f444de05 JB |
1214 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
1215 | u32 freq; | |
1216 | int result; | |
1217 | ||
1218 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
1219 | return -EINVAL; | |
1220 | ||
1221 | if (!nl80211_can_set_dev_channel(wdev)) | |
1222 | return -EOPNOTSUPP; | |
1223 | ||
cd6c6598 JB |
1224 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] && |
1225 | !nl80211_valid_channel_type(info, &channel_type)) | |
1226 | return -EINVAL; | |
f444de05 JB |
1227 | |
1228 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
1229 | ||
1230 | mutex_lock(&rdev->devlist_mtx); | |
aa430da4 JB |
1231 | if (wdev) switch (wdev->iftype) { |
1232 | case NL80211_IFTYPE_AP: | |
1233 | case NL80211_IFTYPE_P2P_GO: | |
1234 | if (wdev->beacon_interval) { | |
1235 | result = -EBUSY; | |
1236 | break; | |
1237 | } | |
1238 | channel = rdev_freq_to_chan(rdev, freq, channel_type); | |
1239 | if (!channel || !cfg80211_can_beacon_sec_chan(&rdev->wiphy, | |
1240 | channel, | |
1241 | channel_type)) { | |
1242 | result = -EINVAL; | |
1243 | break; | |
1244 | } | |
1245 | wdev->preset_chan = channel; | |
1246 | wdev->preset_chantype = channel_type; | |
1247 | result = 0; | |
1248 | break; | |
1249 | default: | |
f444de05 JB |
1250 | wdev_lock(wdev); |
1251 | result = cfg80211_set_freq(rdev, wdev, freq, channel_type); | |
1252 | wdev_unlock(wdev); | |
1253 | } else { | |
1254 | result = cfg80211_set_freq(rdev, NULL, freq, channel_type); | |
1255 | } | |
1256 | mutex_unlock(&rdev->devlist_mtx); | |
1257 | ||
1258 | return result; | |
1259 | } | |
1260 | ||
1261 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) | |
1262 | { | |
4c476991 JB |
1263 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1264 | struct net_device *netdev = info->user_ptr[1]; | |
f444de05 | 1265 | |
4c476991 | 1266 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
f444de05 JB |
1267 | } |
1268 | ||
e8347eba BJ |
1269 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
1270 | { | |
43b19952 JB |
1271 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1272 | struct net_device *dev = info->user_ptr[1]; | |
1273 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
388ac775 | 1274 | const u8 *bssid; |
e8347eba BJ |
1275 | |
1276 | if (!info->attrs[NL80211_ATTR_MAC]) | |
1277 | return -EINVAL; | |
1278 | ||
43b19952 JB |
1279 | if (netif_running(dev)) |
1280 | return -EBUSY; | |
e8347eba | 1281 | |
43b19952 JB |
1282 | if (!rdev->ops->set_wds_peer) |
1283 | return -EOPNOTSUPP; | |
e8347eba | 1284 | |
43b19952 JB |
1285 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
1286 | return -EOPNOTSUPP; | |
e8347eba BJ |
1287 | |
1288 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
43b19952 | 1289 | return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid); |
e8347eba BJ |
1290 | } |
1291 | ||
1292 | ||
55682965 JB |
1293 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
1294 | { | |
1295 | struct cfg80211_registered_device *rdev; | |
f444de05 JB |
1296 | struct net_device *netdev = NULL; |
1297 | struct wireless_dev *wdev; | |
a1e567c8 | 1298 | int result = 0, rem_txq_params = 0; |
31888487 | 1299 | struct nlattr *nl_txq_params; |
b9a5f8ca JM |
1300 | u32 changed; |
1301 | u8 retry_short = 0, retry_long = 0; | |
1302 | u32 frag_threshold = 0, rts_threshold = 0; | |
81077e82 | 1303 | u8 coverage_class = 0; |
55682965 | 1304 | |
f444de05 JB |
1305 | /* |
1306 | * Try to find the wiphy and netdev. Normally this | |
1307 | * function shouldn't need the netdev, but this is | |
1308 | * done for backward compatibility -- previously | |
1309 | * setting the channel was done per wiphy, but now | |
1310 | * it is per netdev. Previous userland like hostapd | |
1311 | * also passed a netdev to set_wiphy, so that it is | |
1312 | * possible to let that go to the right netdev! | |
1313 | */ | |
4bbf4d56 JB |
1314 | mutex_lock(&cfg80211_mutex); |
1315 | ||
f444de05 JB |
1316 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
1317 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); | |
1318 | ||
1319 | netdev = dev_get_by_index(genl_info_net(info), ifindex); | |
1320 | if (netdev && netdev->ieee80211_ptr) { | |
1321 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); | |
1322 | mutex_lock(&rdev->mtx); | |
1323 | } else | |
1324 | netdev = NULL; | |
4bbf4d56 JB |
1325 | } |
1326 | ||
f444de05 JB |
1327 | if (!netdev) { |
1328 | rdev = __cfg80211_rdev_from_info(info); | |
1329 | if (IS_ERR(rdev)) { | |
1330 | mutex_unlock(&cfg80211_mutex); | |
4c476991 | 1331 | return PTR_ERR(rdev); |
f444de05 JB |
1332 | } |
1333 | wdev = NULL; | |
1334 | netdev = NULL; | |
1335 | result = 0; | |
1336 | ||
1337 | mutex_lock(&rdev->mtx); | |
1338 | } else if (netif_running(netdev) && | |
1339 | nl80211_can_set_dev_channel(netdev->ieee80211_ptr)) | |
1340 | wdev = netdev->ieee80211_ptr; | |
1341 | else | |
1342 | wdev = NULL; | |
1343 | ||
1344 | /* | |
1345 | * end workaround code, by now the rdev is available | |
1346 | * and locked, and wdev may or may not be NULL. | |
1347 | */ | |
4bbf4d56 JB |
1348 | |
1349 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) | |
31888487 JM |
1350 | result = cfg80211_dev_rename( |
1351 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); | |
4bbf4d56 JB |
1352 | |
1353 | mutex_unlock(&cfg80211_mutex); | |
1354 | ||
1355 | if (result) | |
1356 | goto bad_res; | |
31888487 JM |
1357 | |
1358 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { | |
1359 | struct ieee80211_txq_params txq_params; | |
1360 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; | |
1361 | ||
1362 | if (!rdev->ops->set_txq_params) { | |
1363 | result = -EOPNOTSUPP; | |
1364 | goto bad_res; | |
1365 | } | |
1366 | ||
f70f01c2 EP |
1367 | if (!netdev) { |
1368 | result = -EINVAL; | |
1369 | goto bad_res; | |
1370 | } | |
1371 | ||
133a3ff2 JB |
1372 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
1373 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
1374 | result = -EINVAL; | |
1375 | goto bad_res; | |
1376 | } | |
1377 | ||
2b5f8b0b JB |
1378 | if (!netif_running(netdev)) { |
1379 | result = -ENETDOWN; | |
1380 | goto bad_res; | |
1381 | } | |
1382 | ||
31888487 JM |
1383 | nla_for_each_nested(nl_txq_params, |
1384 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], | |
1385 | rem_txq_params) { | |
1386 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, | |
1387 | nla_data(nl_txq_params), | |
1388 | nla_len(nl_txq_params), | |
1389 | txq_params_policy); | |
1390 | result = parse_txq_params(tb, &txq_params); | |
1391 | if (result) | |
1392 | goto bad_res; | |
1393 | ||
1394 | result = rdev->ops->set_txq_params(&rdev->wiphy, | |
f70f01c2 | 1395 | netdev, |
31888487 JM |
1396 | &txq_params); |
1397 | if (result) | |
1398 | goto bad_res; | |
1399 | } | |
1400 | } | |
55682965 | 1401 | |
72bdcf34 | 1402 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
f444de05 | 1403 | result = __nl80211_set_channel(rdev, wdev, info); |
72bdcf34 JM |
1404 | if (result) |
1405 | goto bad_res; | |
1406 | } | |
1407 | ||
98d2ff8b JO |
1408 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
1409 | enum nl80211_tx_power_setting type; | |
1410 | int idx, mbm = 0; | |
1411 | ||
1412 | if (!rdev->ops->set_tx_power) { | |
60ea385f | 1413 | result = -EOPNOTSUPP; |
98d2ff8b JO |
1414 | goto bad_res; |
1415 | } | |
1416 | ||
1417 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; | |
1418 | type = nla_get_u32(info->attrs[idx]); | |
1419 | ||
1420 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && | |
1421 | (type != NL80211_TX_POWER_AUTOMATIC)) { | |
1422 | result = -EINVAL; | |
1423 | goto bad_res; | |
1424 | } | |
1425 | ||
1426 | if (type != NL80211_TX_POWER_AUTOMATIC) { | |
1427 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; | |
1428 | mbm = nla_get_u32(info->attrs[idx]); | |
1429 | } | |
1430 | ||
1431 | result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm); | |
1432 | if (result) | |
1433 | goto bad_res; | |
1434 | } | |
1435 | ||
afe0cbf8 BR |
1436 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
1437 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { | |
1438 | u32 tx_ant, rx_ant; | |
7f531e03 BR |
1439 | if ((!rdev->wiphy.available_antennas_tx && |
1440 | !rdev->wiphy.available_antennas_rx) || | |
1441 | !rdev->ops->set_antenna) { | |
afe0cbf8 BR |
1442 | result = -EOPNOTSUPP; |
1443 | goto bad_res; | |
1444 | } | |
1445 | ||
1446 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); | |
1447 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); | |
1448 | ||
a7ffac95 | 1449 | /* reject antenna configurations which don't match the |
7f531e03 BR |
1450 | * available antenna masks, except for the "all" mask */ |
1451 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || | |
1452 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { | |
a7ffac95 BR |
1453 | result = -EINVAL; |
1454 | goto bad_res; | |
1455 | } | |
1456 | ||
7f531e03 BR |
1457 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
1458 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; | |
a7ffac95 | 1459 | |
afe0cbf8 BR |
1460 | result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant); |
1461 | if (result) | |
1462 | goto bad_res; | |
1463 | } | |
1464 | ||
b9a5f8ca JM |
1465 | changed = 0; |
1466 | ||
1467 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { | |
1468 | retry_short = nla_get_u8( | |
1469 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); | |
1470 | if (retry_short == 0) { | |
1471 | result = -EINVAL; | |
1472 | goto bad_res; | |
1473 | } | |
1474 | changed |= WIPHY_PARAM_RETRY_SHORT; | |
1475 | } | |
1476 | ||
1477 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { | |
1478 | retry_long = nla_get_u8( | |
1479 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); | |
1480 | if (retry_long == 0) { | |
1481 | result = -EINVAL; | |
1482 | goto bad_res; | |
1483 | } | |
1484 | changed |= WIPHY_PARAM_RETRY_LONG; | |
1485 | } | |
1486 | ||
1487 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { | |
1488 | frag_threshold = nla_get_u32( | |
1489 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); | |
1490 | if (frag_threshold < 256) { | |
1491 | result = -EINVAL; | |
1492 | goto bad_res; | |
1493 | } | |
1494 | if (frag_threshold != (u32) -1) { | |
1495 | /* | |
1496 | * Fragments (apart from the last one) are required to | |
1497 | * have even length. Make the fragmentation code | |
1498 | * simpler by stripping LSB should someone try to use | |
1499 | * odd threshold value. | |
1500 | */ | |
1501 | frag_threshold &= ~0x1; | |
1502 | } | |
1503 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; | |
1504 | } | |
1505 | ||
1506 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { | |
1507 | rts_threshold = nla_get_u32( | |
1508 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); | |
1509 | changed |= WIPHY_PARAM_RTS_THRESHOLD; | |
1510 | } | |
1511 | ||
81077e82 LT |
1512 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
1513 | coverage_class = nla_get_u8( | |
1514 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); | |
1515 | changed |= WIPHY_PARAM_COVERAGE_CLASS; | |
1516 | } | |
1517 | ||
b9a5f8ca JM |
1518 | if (changed) { |
1519 | u8 old_retry_short, old_retry_long; | |
1520 | u32 old_frag_threshold, old_rts_threshold; | |
81077e82 | 1521 | u8 old_coverage_class; |
b9a5f8ca JM |
1522 | |
1523 | if (!rdev->ops->set_wiphy_params) { | |
1524 | result = -EOPNOTSUPP; | |
1525 | goto bad_res; | |
1526 | } | |
1527 | ||
1528 | old_retry_short = rdev->wiphy.retry_short; | |
1529 | old_retry_long = rdev->wiphy.retry_long; | |
1530 | old_frag_threshold = rdev->wiphy.frag_threshold; | |
1531 | old_rts_threshold = rdev->wiphy.rts_threshold; | |
81077e82 | 1532 | old_coverage_class = rdev->wiphy.coverage_class; |
b9a5f8ca JM |
1533 | |
1534 | if (changed & WIPHY_PARAM_RETRY_SHORT) | |
1535 | rdev->wiphy.retry_short = retry_short; | |
1536 | if (changed & WIPHY_PARAM_RETRY_LONG) | |
1537 | rdev->wiphy.retry_long = retry_long; | |
1538 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) | |
1539 | rdev->wiphy.frag_threshold = frag_threshold; | |
1540 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) | |
1541 | rdev->wiphy.rts_threshold = rts_threshold; | |
81077e82 LT |
1542 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
1543 | rdev->wiphy.coverage_class = coverage_class; | |
b9a5f8ca JM |
1544 | |
1545 | result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed); | |
1546 | if (result) { | |
1547 | rdev->wiphy.retry_short = old_retry_short; | |
1548 | rdev->wiphy.retry_long = old_retry_long; | |
1549 | rdev->wiphy.frag_threshold = old_frag_threshold; | |
1550 | rdev->wiphy.rts_threshold = old_rts_threshold; | |
81077e82 | 1551 | rdev->wiphy.coverage_class = old_coverage_class; |
b9a5f8ca JM |
1552 | } |
1553 | } | |
72bdcf34 | 1554 | |
306d6112 | 1555 | bad_res: |
4bbf4d56 | 1556 | mutex_unlock(&rdev->mtx); |
f444de05 JB |
1557 | if (netdev) |
1558 | dev_put(netdev); | |
55682965 JB |
1559 | return result; |
1560 | } | |
1561 | ||
1562 | ||
1563 | static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags, | |
d726405a | 1564 | struct cfg80211_registered_device *rdev, |
55682965 JB |
1565 | struct net_device *dev) |
1566 | { | |
1567 | void *hdr; | |
1568 | ||
1569 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE); | |
1570 | if (!hdr) | |
1571 | return -1; | |
1572 | ||
9360ffd1 DM |
1573 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
1574 | nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
1575 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name) || | |
1576 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, | |
1577 | dev->ieee80211_ptr->iftype) || | |
1578 | nla_put_u32(msg, NL80211_ATTR_GENERATION, | |
1579 | rdev->devlist_generation ^ | |
1580 | (cfg80211_rdev_list_generation << 2))) | |
1581 | goto nla_put_failure; | |
f5ea9120 | 1582 | |
d91df0e3 PF |
1583 | if (rdev->ops->get_channel) { |
1584 | struct ieee80211_channel *chan; | |
1585 | enum nl80211_channel_type channel_type; | |
1586 | ||
1587 | chan = rdev->ops->get_channel(&rdev->wiphy, &channel_type); | |
59ef43e6 JL |
1588 | if (chan && |
1589 | (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, | |
1590 | chan->center_freq) || | |
1591 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
1592 | channel_type))) | |
1593 | goto nla_put_failure; | |
d91df0e3 PF |
1594 | } |
1595 | ||
55682965 JB |
1596 | return genlmsg_end(msg, hdr); |
1597 | ||
1598 | nla_put_failure: | |
bc3ed28c TG |
1599 | genlmsg_cancel(msg, hdr); |
1600 | return -EMSGSIZE; | |
55682965 JB |
1601 | } |
1602 | ||
1603 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) | |
1604 | { | |
1605 | int wp_idx = 0; | |
1606 | int if_idx = 0; | |
1607 | int wp_start = cb->args[0]; | |
1608 | int if_start = cb->args[1]; | |
f5ea9120 | 1609 | struct cfg80211_registered_device *rdev; |
55682965 JB |
1610 | struct wireless_dev *wdev; |
1611 | ||
a1794390 | 1612 | mutex_lock(&cfg80211_mutex); |
f5ea9120 JB |
1613 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
1614 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 1615 | continue; |
bba95fef JB |
1616 | if (wp_idx < wp_start) { |
1617 | wp_idx++; | |
55682965 | 1618 | continue; |
bba95fef | 1619 | } |
55682965 JB |
1620 | if_idx = 0; |
1621 | ||
f5ea9120 JB |
1622 | mutex_lock(&rdev->devlist_mtx); |
1623 | list_for_each_entry(wdev, &rdev->netdev_list, list) { | |
bba95fef JB |
1624 | if (if_idx < if_start) { |
1625 | if_idx++; | |
55682965 | 1626 | continue; |
bba95fef | 1627 | } |
55682965 JB |
1628 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid, |
1629 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
f5ea9120 JB |
1630 | rdev, wdev->netdev) < 0) { |
1631 | mutex_unlock(&rdev->devlist_mtx); | |
bba95fef JB |
1632 | goto out; |
1633 | } | |
1634 | if_idx++; | |
55682965 | 1635 | } |
f5ea9120 | 1636 | mutex_unlock(&rdev->devlist_mtx); |
bba95fef JB |
1637 | |
1638 | wp_idx++; | |
55682965 | 1639 | } |
bba95fef | 1640 | out: |
a1794390 | 1641 | mutex_unlock(&cfg80211_mutex); |
55682965 JB |
1642 | |
1643 | cb->args[0] = wp_idx; | |
1644 | cb->args[1] = if_idx; | |
1645 | ||
1646 | return skb->len; | |
1647 | } | |
1648 | ||
1649 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) | |
1650 | { | |
1651 | struct sk_buff *msg; | |
4c476991 JB |
1652 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
1653 | struct net_device *netdev = info->user_ptr[1]; | |
55682965 | 1654 | |
fd2120ca | 1655 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 | 1656 | if (!msg) |
4c476991 | 1657 | return -ENOMEM; |
55682965 | 1658 | |
d726405a | 1659 | if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0, |
4c476991 JB |
1660 | dev, netdev) < 0) { |
1661 | nlmsg_free(msg); | |
1662 | return -ENOBUFS; | |
1663 | } | |
55682965 | 1664 | |
134e6375 | 1665 | return genlmsg_reply(msg, info); |
55682965 JB |
1666 | } |
1667 | ||
66f7ac50 MW |
1668 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
1669 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, | |
1670 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, | |
1671 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, | |
1672 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, | |
1673 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, | |
1674 | }; | |
1675 | ||
1676 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) | |
1677 | { | |
1678 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; | |
1679 | int flag; | |
1680 | ||
1681 | *mntrflags = 0; | |
1682 | ||
1683 | if (!nla) | |
1684 | return -EINVAL; | |
1685 | ||
1686 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, | |
1687 | nla, mntr_flags_policy)) | |
1688 | return -EINVAL; | |
1689 | ||
1690 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) | |
1691 | if (flags[flag]) | |
1692 | *mntrflags |= (1<<flag); | |
1693 | ||
1694 | return 0; | |
1695 | } | |
1696 | ||
9bc383de | 1697 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
ad4bb6f8 JB |
1698 | struct net_device *netdev, u8 use_4addr, |
1699 | enum nl80211_iftype iftype) | |
9bc383de | 1700 | { |
ad4bb6f8 | 1701 | if (!use_4addr) { |
f350a0a8 | 1702 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
ad4bb6f8 | 1703 | return -EBUSY; |
9bc383de | 1704 | return 0; |
ad4bb6f8 | 1705 | } |
9bc383de JB |
1706 | |
1707 | switch (iftype) { | |
1708 | case NL80211_IFTYPE_AP_VLAN: | |
1709 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) | |
1710 | return 0; | |
1711 | break; | |
1712 | case NL80211_IFTYPE_STATION: | |
1713 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) | |
1714 | return 0; | |
1715 | break; | |
1716 | default: | |
1717 | break; | |
1718 | } | |
1719 | ||
1720 | return -EOPNOTSUPP; | |
1721 | } | |
1722 | ||
55682965 JB |
1723 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
1724 | { | |
4c476991 | 1725 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 1726 | struct vif_params params; |
e36d56b6 | 1727 | int err; |
04a773ad | 1728 | enum nl80211_iftype otype, ntype; |
4c476991 | 1729 | struct net_device *dev = info->user_ptr[1]; |
92ffe055 | 1730 | u32 _flags, *flags = NULL; |
ac7f9cfa | 1731 | bool change = false; |
55682965 | 1732 | |
2ec600d6 LCC |
1733 | memset(¶ms, 0, sizeof(params)); |
1734 | ||
04a773ad | 1735 | otype = ntype = dev->ieee80211_ptr->iftype; |
55682965 | 1736 | |
723b038d | 1737 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
ac7f9cfa | 1738 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
04a773ad | 1739 | if (otype != ntype) |
ac7f9cfa | 1740 | change = true; |
4c476991 JB |
1741 | if (ntype > NL80211_IFTYPE_MAX) |
1742 | return -EINVAL; | |
723b038d JB |
1743 | } |
1744 | ||
92ffe055 | 1745 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
29cbe68c JB |
1746 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
1747 | ||
4c476991 JB |
1748 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
1749 | return -EINVAL; | |
29cbe68c JB |
1750 | if (netif_running(dev)) |
1751 | return -EBUSY; | |
1752 | ||
1753 | wdev_lock(wdev); | |
1754 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
1755 | IEEE80211_MAX_MESH_ID_LEN); | |
1756 | wdev->mesh_id_up_len = | |
1757 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
1758 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
1759 | wdev->mesh_id_up_len); | |
1760 | wdev_unlock(wdev); | |
2ec600d6 LCC |
1761 | } |
1762 | ||
8b787643 FF |
1763 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
1764 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); | |
1765 | change = true; | |
ad4bb6f8 | 1766 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
9bc383de | 1767 | if (err) |
4c476991 | 1768 | return err; |
8b787643 FF |
1769 | } else { |
1770 | params.use_4addr = -1; | |
1771 | } | |
1772 | ||
92ffe055 | 1773 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
4c476991 JB |
1774 | if (ntype != NL80211_IFTYPE_MONITOR) |
1775 | return -EINVAL; | |
92ffe055 JB |
1776 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
1777 | &_flags); | |
ac7f9cfa | 1778 | if (err) |
4c476991 | 1779 | return err; |
ac7f9cfa JB |
1780 | |
1781 | flags = &_flags; | |
1782 | change = true; | |
92ffe055 | 1783 | } |
3b85875a | 1784 | |
ac7f9cfa | 1785 | if (change) |
3d54d255 | 1786 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
ac7f9cfa JB |
1787 | else |
1788 | err = 0; | |
60719ffd | 1789 | |
9bc383de JB |
1790 | if (!err && params.use_4addr != -1) |
1791 | dev->ieee80211_ptr->use_4addr = params.use_4addr; | |
1792 | ||
55682965 JB |
1793 | return err; |
1794 | } | |
1795 | ||
1796 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) | |
1797 | { | |
4c476991 | 1798 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 1799 | struct vif_params params; |
f9e10ce4 | 1800 | struct net_device *dev; |
55682965 JB |
1801 | int err; |
1802 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; | |
66f7ac50 | 1803 | u32 flags; |
55682965 | 1804 | |
2ec600d6 LCC |
1805 | memset(¶ms, 0, sizeof(params)); |
1806 | ||
55682965 JB |
1807 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
1808 | return -EINVAL; | |
1809 | ||
1810 | if (info->attrs[NL80211_ATTR_IFTYPE]) { | |
1811 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); | |
1812 | if (type > NL80211_IFTYPE_MAX) | |
1813 | return -EINVAL; | |
1814 | } | |
1815 | ||
79c97e97 | 1816 | if (!rdev->ops->add_virtual_intf || |
4c476991 JB |
1817 | !(rdev->wiphy.interface_modes & (1 << type))) |
1818 | return -EOPNOTSUPP; | |
55682965 | 1819 | |
9bc383de | 1820 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
8b787643 | 1821 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
ad4bb6f8 | 1822 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
9bc383de | 1823 | if (err) |
4c476991 | 1824 | return err; |
9bc383de | 1825 | } |
8b787643 | 1826 | |
66f7ac50 MW |
1827 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
1828 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, | |
1829 | &flags); | |
f9e10ce4 | 1830 | dev = rdev->ops->add_virtual_intf(&rdev->wiphy, |
66f7ac50 | 1831 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
2ec600d6 | 1832 | type, err ? NULL : &flags, ¶ms); |
f9e10ce4 JB |
1833 | if (IS_ERR(dev)) |
1834 | return PTR_ERR(dev); | |
2ec600d6 | 1835 | |
29cbe68c JB |
1836 | if (type == NL80211_IFTYPE_MESH_POINT && |
1837 | info->attrs[NL80211_ATTR_MESH_ID]) { | |
1838 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
1839 | ||
1840 | wdev_lock(wdev); | |
1841 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
1842 | IEEE80211_MAX_MESH_ID_LEN); | |
1843 | wdev->mesh_id_up_len = | |
1844 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
1845 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
1846 | wdev->mesh_id_up_len); | |
1847 | wdev_unlock(wdev); | |
1848 | } | |
1849 | ||
f9e10ce4 | 1850 | return 0; |
55682965 JB |
1851 | } |
1852 | ||
1853 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) | |
1854 | { | |
4c476991 JB |
1855 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1856 | struct net_device *dev = info->user_ptr[1]; | |
55682965 | 1857 | |
4c476991 JB |
1858 | if (!rdev->ops->del_virtual_intf) |
1859 | return -EOPNOTSUPP; | |
55682965 | 1860 | |
4c476991 | 1861 | return rdev->ops->del_virtual_intf(&rdev->wiphy, dev); |
55682965 JB |
1862 | } |
1863 | ||
1d9d9213 SW |
1864 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
1865 | { | |
1866 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
1867 | struct net_device *dev = info->user_ptr[1]; | |
1868 | u16 noack_map; | |
1869 | ||
1870 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) | |
1871 | return -EINVAL; | |
1872 | ||
1873 | if (!rdev->ops->set_noack_map) | |
1874 | return -EOPNOTSUPP; | |
1875 | ||
1876 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); | |
1877 | ||
1878 | return rdev->ops->set_noack_map(&rdev->wiphy, dev, noack_map); | |
1879 | } | |
1880 | ||
41ade00f JB |
1881 | struct get_key_cookie { |
1882 | struct sk_buff *msg; | |
1883 | int error; | |
b9454e83 | 1884 | int idx; |
41ade00f JB |
1885 | }; |
1886 | ||
1887 | static void get_key_callback(void *c, struct key_params *params) | |
1888 | { | |
b9454e83 | 1889 | struct nlattr *key; |
41ade00f JB |
1890 | struct get_key_cookie *cookie = c; |
1891 | ||
9360ffd1 DM |
1892 | if ((params->key && |
1893 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, | |
1894 | params->key_len, params->key)) || | |
1895 | (params->seq && | |
1896 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, | |
1897 | params->seq_len, params->seq)) || | |
1898 | (params->cipher && | |
1899 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, | |
1900 | params->cipher))) | |
1901 | goto nla_put_failure; | |
41ade00f | 1902 | |
b9454e83 JB |
1903 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
1904 | if (!key) | |
1905 | goto nla_put_failure; | |
1906 | ||
9360ffd1 DM |
1907 | if ((params->key && |
1908 | nla_put(cookie->msg, NL80211_KEY_DATA, | |
1909 | params->key_len, params->key)) || | |
1910 | (params->seq && | |
1911 | nla_put(cookie->msg, NL80211_KEY_SEQ, | |
1912 | params->seq_len, params->seq)) || | |
1913 | (params->cipher && | |
1914 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, | |
1915 | params->cipher))) | |
1916 | goto nla_put_failure; | |
b9454e83 | 1917 | |
9360ffd1 DM |
1918 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
1919 | goto nla_put_failure; | |
b9454e83 JB |
1920 | |
1921 | nla_nest_end(cookie->msg, key); | |
1922 | ||
41ade00f JB |
1923 | return; |
1924 | nla_put_failure: | |
1925 | cookie->error = 1; | |
1926 | } | |
1927 | ||
1928 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) | |
1929 | { | |
4c476991 | 1930 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 1931 | int err; |
4c476991 | 1932 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 1933 | u8 key_idx = 0; |
e31b8213 JB |
1934 | const u8 *mac_addr = NULL; |
1935 | bool pairwise; | |
41ade00f JB |
1936 | struct get_key_cookie cookie = { |
1937 | .error = 0, | |
1938 | }; | |
1939 | void *hdr; | |
1940 | struct sk_buff *msg; | |
1941 | ||
1942 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
1943 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
1944 | ||
3cfcf6ac | 1945 | if (key_idx > 5) |
41ade00f JB |
1946 | return -EINVAL; |
1947 | ||
1948 | if (info->attrs[NL80211_ATTR_MAC]) | |
1949 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
1950 | ||
e31b8213 JB |
1951 | pairwise = !!mac_addr; |
1952 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { | |
1953 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
1954 | if (kt >= NUM_NL80211_KEYTYPES) | |
1955 | return -EINVAL; | |
1956 | if (kt != NL80211_KEYTYPE_GROUP && | |
1957 | kt != NL80211_KEYTYPE_PAIRWISE) | |
1958 | return -EINVAL; | |
1959 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; | |
1960 | } | |
1961 | ||
4c476991 JB |
1962 | if (!rdev->ops->get_key) |
1963 | return -EOPNOTSUPP; | |
41ade00f | 1964 | |
fd2120ca | 1965 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
1966 | if (!msg) |
1967 | return -ENOMEM; | |
41ade00f JB |
1968 | |
1969 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | |
1970 | NL80211_CMD_NEW_KEY); | |
4c476991 JB |
1971 | if (IS_ERR(hdr)) |
1972 | return PTR_ERR(hdr); | |
41ade00f JB |
1973 | |
1974 | cookie.msg = msg; | |
b9454e83 | 1975 | cookie.idx = key_idx; |
41ade00f | 1976 | |
9360ffd1 DM |
1977 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
1978 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) | |
1979 | goto nla_put_failure; | |
1980 | if (mac_addr && | |
1981 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
1982 | goto nla_put_failure; | |
41ade00f | 1983 | |
e31b8213 JB |
1984 | if (pairwise && mac_addr && |
1985 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
1986 | return -ENOENT; | |
1987 | ||
1988 | err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise, | |
1989 | mac_addr, &cookie, get_key_callback); | |
41ade00f JB |
1990 | |
1991 | if (err) | |
6c95e2a2 | 1992 | goto free_msg; |
41ade00f JB |
1993 | |
1994 | if (cookie.error) | |
1995 | goto nla_put_failure; | |
1996 | ||
1997 | genlmsg_end(msg, hdr); | |
4c476991 | 1998 | return genlmsg_reply(msg, info); |
41ade00f JB |
1999 | |
2000 | nla_put_failure: | |
2001 | err = -ENOBUFS; | |
6c95e2a2 | 2002 | free_msg: |
41ade00f | 2003 | nlmsg_free(msg); |
41ade00f JB |
2004 | return err; |
2005 | } | |
2006 | ||
2007 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) | |
2008 | { | |
4c476991 | 2009 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
b9454e83 | 2010 | struct key_parse key; |
41ade00f | 2011 | int err; |
4c476991 | 2012 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2013 | |
b9454e83 JB |
2014 | err = nl80211_parse_key(info, &key); |
2015 | if (err) | |
2016 | return err; | |
41ade00f | 2017 | |
b9454e83 | 2018 | if (key.idx < 0) |
41ade00f JB |
2019 | return -EINVAL; |
2020 | ||
b9454e83 JB |
2021 | /* only support setting default key */ |
2022 | if (!key.def && !key.defmgmt) | |
41ade00f JB |
2023 | return -EINVAL; |
2024 | ||
dbd2fd65 | 2025 | wdev_lock(dev->ieee80211_ptr); |
3cfcf6ac | 2026 | |
dbd2fd65 JB |
2027 | if (key.def) { |
2028 | if (!rdev->ops->set_default_key) { | |
2029 | err = -EOPNOTSUPP; | |
2030 | goto out; | |
2031 | } | |
41ade00f | 2032 | |
dbd2fd65 JB |
2033 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
2034 | if (err) | |
2035 | goto out; | |
2036 | ||
dbd2fd65 JB |
2037 | err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx, |
2038 | key.def_uni, key.def_multi); | |
2039 | ||
2040 | if (err) | |
2041 | goto out; | |
fffd0934 | 2042 | |
3d23e349 | 2043 | #ifdef CONFIG_CFG80211_WEXT |
dbd2fd65 JB |
2044 | dev->ieee80211_ptr->wext.default_key = key.idx; |
2045 | #endif | |
2046 | } else { | |
2047 | if (key.def_uni || !key.def_multi) { | |
2048 | err = -EINVAL; | |
2049 | goto out; | |
2050 | } | |
2051 | ||
2052 | if (!rdev->ops->set_default_mgmt_key) { | |
2053 | err = -EOPNOTSUPP; | |
2054 | goto out; | |
2055 | } | |
2056 | ||
2057 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2058 | if (err) | |
2059 | goto out; | |
2060 | ||
2061 | err = rdev->ops->set_default_mgmt_key(&rdev->wiphy, | |
2062 | dev, key.idx); | |
2063 | if (err) | |
2064 | goto out; | |
2065 | ||
2066 | #ifdef CONFIG_CFG80211_WEXT | |
2067 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; | |
08645126 | 2068 | #endif |
dbd2fd65 JB |
2069 | } |
2070 | ||
2071 | out: | |
fffd0934 | 2072 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 2073 | |
41ade00f JB |
2074 | return err; |
2075 | } | |
2076 | ||
2077 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) | |
2078 | { | |
4c476991 | 2079 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fffd0934 | 2080 | int err; |
4c476991 | 2081 | struct net_device *dev = info->user_ptr[1]; |
b9454e83 | 2082 | struct key_parse key; |
e31b8213 | 2083 | const u8 *mac_addr = NULL; |
41ade00f | 2084 | |
b9454e83 JB |
2085 | err = nl80211_parse_key(info, &key); |
2086 | if (err) | |
2087 | return err; | |
41ade00f | 2088 | |
b9454e83 | 2089 | if (!key.p.key) |
41ade00f JB |
2090 | return -EINVAL; |
2091 | ||
41ade00f JB |
2092 | if (info->attrs[NL80211_ATTR_MAC]) |
2093 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2094 | ||
e31b8213 JB |
2095 | if (key.type == -1) { |
2096 | if (mac_addr) | |
2097 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
2098 | else | |
2099 | key.type = NL80211_KEYTYPE_GROUP; | |
2100 | } | |
2101 | ||
2102 | /* for now */ | |
2103 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
2104 | key.type != NL80211_KEYTYPE_GROUP) | |
2105 | return -EINVAL; | |
2106 | ||
4c476991 JB |
2107 | if (!rdev->ops->add_key) |
2108 | return -EOPNOTSUPP; | |
25e47c18 | 2109 | |
e31b8213 JB |
2110 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
2111 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2112 | mac_addr)) | |
4c476991 | 2113 | return -EINVAL; |
41ade00f | 2114 | |
fffd0934 JB |
2115 | wdev_lock(dev->ieee80211_ptr); |
2116 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2117 | if (!err) | |
2118 | err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx, | |
e31b8213 | 2119 | key.type == NL80211_KEYTYPE_PAIRWISE, |
fffd0934 JB |
2120 | mac_addr, &key.p); |
2121 | wdev_unlock(dev->ieee80211_ptr); | |
41ade00f | 2122 | |
41ade00f JB |
2123 | return err; |
2124 | } | |
2125 | ||
2126 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) | |
2127 | { | |
4c476991 | 2128 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2129 | int err; |
4c476991 | 2130 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2131 | u8 *mac_addr = NULL; |
b9454e83 | 2132 | struct key_parse key; |
41ade00f | 2133 | |
b9454e83 JB |
2134 | err = nl80211_parse_key(info, &key); |
2135 | if (err) | |
2136 | return err; | |
41ade00f JB |
2137 | |
2138 | if (info->attrs[NL80211_ATTR_MAC]) | |
2139 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2140 | ||
e31b8213 JB |
2141 | if (key.type == -1) { |
2142 | if (mac_addr) | |
2143 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
2144 | else | |
2145 | key.type = NL80211_KEYTYPE_GROUP; | |
2146 | } | |
2147 | ||
2148 | /* for now */ | |
2149 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
2150 | key.type != NL80211_KEYTYPE_GROUP) | |
2151 | return -EINVAL; | |
2152 | ||
4c476991 JB |
2153 | if (!rdev->ops->del_key) |
2154 | return -EOPNOTSUPP; | |
41ade00f | 2155 | |
fffd0934 JB |
2156 | wdev_lock(dev->ieee80211_ptr); |
2157 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
e31b8213 JB |
2158 | |
2159 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && | |
2160 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | |
2161 | err = -ENOENT; | |
2162 | ||
fffd0934 | 2163 | if (!err) |
e31b8213 JB |
2164 | err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx, |
2165 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
2166 | mac_addr); | |
41ade00f | 2167 | |
3d23e349 | 2168 | #ifdef CONFIG_CFG80211_WEXT |
08645126 | 2169 | if (!err) { |
b9454e83 | 2170 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
08645126 | 2171 | dev->ieee80211_ptr->wext.default_key = -1; |
b9454e83 | 2172 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
08645126 JB |
2173 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
2174 | } | |
2175 | #endif | |
fffd0934 | 2176 | wdev_unlock(dev->ieee80211_ptr); |
08645126 | 2177 | |
41ade00f JB |
2178 | return err; |
2179 | } | |
2180 | ||
8860020e JB |
2181 | static int nl80211_parse_beacon(struct genl_info *info, |
2182 | struct cfg80211_beacon_data *bcn) | |
ed1b6cc7 | 2183 | { |
8860020e | 2184 | bool haveinfo = false; |
ed1b6cc7 | 2185 | |
9946ecfb JM |
2186 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]) || |
2187 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]) || | |
2188 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_PROBE_RESP]) || | |
2189 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE_ASSOC_RESP])) | |
f4a11bb0 JB |
2190 | return -EINVAL; |
2191 | ||
8860020e | 2192 | memset(bcn, 0, sizeof(*bcn)); |
ed1b6cc7 | 2193 | |
ed1b6cc7 | 2194 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
8860020e JB |
2195 | bcn->head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
2196 | bcn->head_len = nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); | |
2197 | if (!bcn->head_len) | |
2198 | return -EINVAL; | |
2199 | haveinfo = true; | |
ed1b6cc7 JB |
2200 | } |
2201 | ||
2202 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { | |
8860020e JB |
2203 | bcn->tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
2204 | bcn->tail_len = | |
ed1b6cc7 | 2205 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
8860020e | 2206 | haveinfo = true; |
ed1b6cc7 JB |
2207 | } |
2208 | ||
4c476991 JB |
2209 | if (!haveinfo) |
2210 | return -EINVAL; | |
3b85875a | 2211 | |
9946ecfb | 2212 | if (info->attrs[NL80211_ATTR_IE]) { |
8860020e JB |
2213 | bcn->beacon_ies = nla_data(info->attrs[NL80211_ATTR_IE]); |
2214 | bcn->beacon_ies_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
9946ecfb JM |
2215 | } |
2216 | ||
2217 | if (info->attrs[NL80211_ATTR_IE_PROBE_RESP]) { | |
8860020e | 2218 | bcn->proberesp_ies = |
9946ecfb | 2219 | nla_data(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
8860020e | 2220 | bcn->proberesp_ies_len = |
9946ecfb JM |
2221 | nla_len(info->attrs[NL80211_ATTR_IE_PROBE_RESP]); |
2222 | } | |
2223 | ||
2224 | if (info->attrs[NL80211_ATTR_IE_ASSOC_RESP]) { | |
8860020e | 2225 | bcn->assocresp_ies = |
9946ecfb | 2226 | nla_data(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
8860020e | 2227 | bcn->assocresp_ies_len = |
9946ecfb JM |
2228 | nla_len(info->attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
2229 | } | |
2230 | ||
00f740e1 | 2231 | if (info->attrs[NL80211_ATTR_PROBE_RESP]) { |
8860020e | 2232 | bcn->probe_resp = |
00f740e1 | 2233 | nla_data(info->attrs[NL80211_ATTR_PROBE_RESP]); |
8860020e | 2234 | bcn->probe_resp_len = |
00f740e1 AN |
2235 | nla_len(info->attrs[NL80211_ATTR_PROBE_RESP]); |
2236 | } | |
2237 | ||
8860020e JB |
2238 | return 0; |
2239 | } | |
2240 | ||
2241 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) | |
2242 | { | |
2243 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2244 | struct net_device *dev = info->user_ptr[1]; | |
2245 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
2246 | struct cfg80211_ap_settings params; | |
2247 | int err; | |
2248 | ||
2249 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
2250 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
2251 | return -EOPNOTSUPP; | |
2252 | ||
2253 | if (!rdev->ops->start_ap) | |
2254 | return -EOPNOTSUPP; | |
2255 | ||
2256 | if (wdev->beacon_interval) | |
2257 | return -EALREADY; | |
2258 | ||
2259 | memset(¶ms, 0, sizeof(params)); | |
2260 | ||
2261 | /* these are required for START_AP */ | |
2262 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || | |
2263 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || | |
2264 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) | |
2265 | return -EINVAL; | |
2266 | ||
2267 | err = nl80211_parse_beacon(info, ¶ms.beacon); | |
2268 | if (err) | |
2269 | return err; | |
2270 | ||
2271 | params.beacon_interval = | |
2272 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
2273 | params.dtim_period = | |
2274 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
2275 | ||
2276 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); | |
2277 | if (err) | |
2278 | return err; | |
2279 | ||
2280 | /* | |
2281 | * In theory, some of these attributes should be required here | |
2282 | * but since they were not used when the command was originally | |
2283 | * added, keep them optional for old user space programs to let | |
2284 | * them continue to work with drivers that do not need the | |
2285 | * additional information -- drivers must check! | |
2286 | */ | |
2287 | if (info->attrs[NL80211_ATTR_SSID]) { | |
2288 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
2289 | params.ssid_len = | |
2290 | nla_len(info->attrs[NL80211_ATTR_SSID]); | |
2291 | if (params.ssid_len == 0 || | |
2292 | params.ssid_len > IEEE80211_MAX_SSID_LEN) | |
2293 | return -EINVAL; | |
2294 | } | |
2295 | ||
2296 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { | |
2297 | params.hidden_ssid = nla_get_u32( | |
2298 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); | |
2299 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && | |
2300 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && | |
2301 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) | |
2302 | return -EINVAL; | |
2303 | } | |
2304 | ||
2305 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; | |
2306 | ||
2307 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
2308 | params.auth_type = nla_get_u32( | |
2309 | info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
2310 | if (!nl80211_valid_auth_type(params.auth_type)) | |
2311 | return -EINVAL; | |
2312 | } else | |
2313 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
2314 | ||
2315 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, | |
2316 | NL80211_MAX_NR_CIPHER_SUITES); | |
2317 | if (err) | |
2318 | return err; | |
2319 | ||
1b658f11 VT |
2320 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
2321 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) | |
2322 | return -EOPNOTSUPP; | |
2323 | params.inactivity_timeout = nla_get_u16( | |
2324 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); | |
2325 | } | |
2326 | ||
aa430da4 JB |
2327 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
2328 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; | |
2329 | ||
2330 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] && | |
2331 | !nl80211_valid_channel_type(info, &channel_type)) | |
2332 | return -EINVAL; | |
2333 | ||
2334 | params.channel = rdev_freq_to_chan(rdev, | |
2335 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]), | |
2336 | channel_type); | |
2337 | if (!params.channel) | |
2338 | return -EINVAL; | |
2339 | params.channel_type = channel_type; | |
2340 | } else if (wdev->preset_chan) { | |
2341 | params.channel = wdev->preset_chan; | |
2342 | params.channel_type = wdev->preset_chantype; | |
2343 | } else | |
2344 | return -EINVAL; | |
2345 | ||
2346 | if (!cfg80211_can_beacon_sec_chan(&rdev->wiphy, params.channel, | |
2347 | params.channel_type)) | |
2348 | return -EINVAL; | |
2349 | ||
8860020e JB |
2350 | err = rdev->ops->start_ap(&rdev->wiphy, dev, ¶ms); |
2351 | if (!err) | |
2352 | wdev->beacon_interval = params.beacon_interval; | |
56d1893d | 2353 | return err; |
ed1b6cc7 JB |
2354 | } |
2355 | ||
8860020e JB |
2356 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
2357 | { | |
2358 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2359 | struct net_device *dev = info->user_ptr[1]; | |
2360 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
2361 | struct cfg80211_beacon_data params; | |
2362 | int err; | |
2363 | ||
2364 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
2365 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
2366 | return -EOPNOTSUPP; | |
2367 | ||
2368 | if (!rdev->ops->change_beacon) | |
2369 | return -EOPNOTSUPP; | |
2370 | ||
2371 | if (!wdev->beacon_interval) | |
2372 | return -EINVAL; | |
2373 | ||
2374 | err = nl80211_parse_beacon(info, ¶ms); | |
2375 | if (err) | |
2376 | return err; | |
2377 | ||
2378 | return rdev->ops->change_beacon(&rdev->wiphy, dev, ¶ms); | |
2379 | } | |
2380 | ||
2381 | static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) | |
ed1b6cc7 | 2382 | { |
4c476991 JB |
2383 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2384 | struct net_device *dev = info->user_ptr[1]; | |
56d1893d JB |
2385 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
2386 | int err; | |
ed1b6cc7 | 2387 | |
8860020e | 2388 | if (!rdev->ops->stop_ap) |
4c476991 | 2389 | return -EOPNOTSUPP; |
ed1b6cc7 | 2390 | |
074ac8df | 2391 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
4c476991 JB |
2392 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
2393 | return -EOPNOTSUPP; | |
3b85875a | 2394 | |
8860020e JB |
2395 | if (!wdev->beacon_interval) |
2396 | return -ENOENT; | |
2397 | ||
2398 | err = rdev->ops->stop_ap(&rdev->wiphy, dev); | |
56d1893d JB |
2399 | if (!err) |
2400 | wdev->beacon_interval = 0; | |
2401 | return err; | |
ed1b6cc7 JB |
2402 | } |
2403 | ||
5727ef1b JB |
2404 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
2405 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, | |
2406 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, | |
2407 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, | |
0e46724a | 2408 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
b39c48fa | 2409 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
d83023da | 2410 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
5727ef1b JB |
2411 | }; |
2412 | ||
eccb8e8f | 2413 | static int parse_station_flags(struct genl_info *info, |
bdd3ae3d | 2414 | enum nl80211_iftype iftype, |
eccb8e8f | 2415 | struct station_parameters *params) |
5727ef1b JB |
2416 | { |
2417 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; | |
eccb8e8f | 2418 | struct nlattr *nla; |
5727ef1b JB |
2419 | int flag; |
2420 | ||
eccb8e8f JB |
2421 | /* |
2422 | * Try parsing the new attribute first so userspace | |
2423 | * can specify both for older kernels. | |
2424 | */ | |
2425 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; | |
2426 | if (nla) { | |
2427 | struct nl80211_sta_flag_update *sta_flags; | |
2428 | ||
2429 | sta_flags = nla_data(nla); | |
2430 | params->sta_flags_mask = sta_flags->mask; | |
2431 | params->sta_flags_set = sta_flags->set; | |
2432 | if ((params->sta_flags_mask | | |
2433 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) | |
2434 | return -EINVAL; | |
2435 | return 0; | |
2436 | } | |
2437 | ||
2438 | /* if present, parse the old attribute */ | |
5727ef1b | 2439 | |
eccb8e8f | 2440 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
5727ef1b JB |
2441 | if (!nla) |
2442 | return 0; | |
2443 | ||
2444 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, | |
2445 | nla, sta_flags_policy)) | |
2446 | return -EINVAL; | |
2447 | ||
bdd3ae3d JB |
2448 | /* |
2449 | * Only allow certain flags for interface types so that | |
2450 | * other attributes are silently ignored. Remember that | |
2451 | * this is backward compatibility code with old userspace | |
2452 | * and shouldn't be hit in other cases anyway. | |
2453 | */ | |
2454 | switch (iftype) { | |
2455 | case NL80211_IFTYPE_AP: | |
2456 | case NL80211_IFTYPE_AP_VLAN: | |
2457 | case NL80211_IFTYPE_P2P_GO: | |
2458 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
2459 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
2460 | BIT(NL80211_STA_FLAG_WME) | | |
2461 | BIT(NL80211_STA_FLAG_MFP); | |
2462 | break; | |
2463 | case NL80211_IFTYPE_P2P_CLIENT: | |
2464 | case NL80211_IFTYPE_STATION: | |
2465 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
2466 | BIT(NL80211_STA_FLAG_TDLS_PEER); | |
2467 | break; | |
2468 | case NL80211_IFTYPE_MESH_POINT: | |
2469 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
2470 | BIT(NL80211_STA_FLAG_MFP) | | |
2471 | BIT(NL80211_STA_FLAG_AUTHORIZED); | |
2472 | default: | |
2473 | return -EINVAL; | |
2474 | } | |
5727ef1b | 2475 | |
3383b5a6 JB |
2476 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
2477 | if (flags[flag]) { | |
eccb8e8f | 2478 | params->sta_flags_set |= (1<<flag); |
5727ef1b | 2479 | |
3383b5a6 JB |
2480 | /* no longer support new API additions in old API */ |
2481 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) | |
2482 | return -EINVAL; | |
2483 | } | |
2484 | } | |
2485 | ||
5727ef1b JB |
2486 | return 0; |
2487 | } | |
2488 | ||
c8dcfd8a FF |
2489 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
2490 | int attr) | |
2491 | { | |
2492 | struct nlattr *rate; | |
2493 | u16 bitrate; | |
2494 | ||
2495 | rate = nla_nest_start(msg, attr); | |
2496 | if (!rate) | |
2497 | goto nla_put_failure; | |
2498 | ||
2499 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ | |
2500 | bitrate = cfg80211_calculate_bitrate(info); | |
9360ffd1 DM |
2501 | if ((bitrate > 0 && |
2502 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate)) || | |
2503 | ((info->flags & RATE_INFO_FLAGS_MCS) && | |
2504 | nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) || | |
2505 | ((info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) && | |
2506 | nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH)) || | |
2507 | ((info->flags & RATE_INFO_FLAGS_SHORT_GI) && | |
2508 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))) | |
2509 | goto nla_put_failure; | |
c8dcfd8a FF |
2510 | |
2511 | nla_nest_end(msg, rate); | |
2512 | return true; | |
2513 | ||
2514 | nla_put_failure: | |
2515 | return false; | |
2516 | } | |
2517 | ||
fd5b74dc | 2518 | static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, |
66266b3a JL |
2519 | int flags, |
2520 | struct cfg80211_registered_device *rdev, | |
2521 | struct net_device *dev, | |
98b62183 | 2522 | const u8 *mac_addr, struct station_info *sinfo) |
fd5b74dc JB |
2523 | { |
2524 | void *hdr; | |
f4263c98 | 2525 | struct nlattr *sinfoattr, *bss_param; |
fd5b74dc JB |
2526 | |
2527 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); | |
2528 | if (!hdr) | |
2529 | return -1; | |
2530 | ||
9360ffd1 DM |
2531 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
2532 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
2533 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) | |
2534 | goto nla_put_failure; | |
f5ea9120 | 2535 | |
2ec600d6 LCC |
2536 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
2537 | if (!sinfoattr) | |
fd5b74dc | 2538 | goto nla_put_failure; |
9360ffd1 DM |
2539 | if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) && |
2540 | nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME, | |
2541 | sinfo->connected_time)) | |
2542 | goto nla_put_failure; | |
2543 | if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) && | |
2544 | nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME, | |
2545 | sinfo->inactive_time)) | |
2546 | goto nla_put_failure; | |
2547 | if ((sinfo->filled & STATION_INFO_RX_BYTES) && | |
2548 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, | |
2549 | sinfo->rx_bytes)) | |
2550 | goto nla_put_failure; | |
2551 | if ((sinfo->filled & STATION_INFO_TX_BYTES) && | |
2552 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, | |
2553 | sinfo->tx_bytes)) | |
2554 | goto nla_put_failure; | |
2555 | if ((sinfo->filled & STATION_INFO_LLID) && | |
2556 | nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid)) | |
2557 | goto nla_put_failure; | |
2558 | if ((sinfo->filled & STATION_INFO_PLID) && | |
2559 | nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid)) | |
2560 | goto nla_put_failure; | |
2561 | if ((sinfo->filled & STATION_INFO_PLINK_STATE) && | |
2562 | nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE, | |
2563 | sinfo->plink_state)) | |
2564 | goto nla_put_failure; | |
66266b3a JL |
2565 | switch (rdev->wiphy.signal_type) { |
2566 | case CFG80211_SIGNAL_TYPE_MBM: | |
9360ffd1 DM |
2567 | if ((sinfo->filled & STATION_INFO_SIGNAL) && |
2568 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL, | |
2569 | sinfo->signal)) | |
2570 | goto nla_put_failure; | |
2571 | if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) && | |
2572 | nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG, | |
2573 | sinfo->signal_avg)) | |
2574 | goto nla_put_failure; | |
66266b3a JL |
2575 | break; |
2576 | default: | |
2577 | break; | |
2578 | } | |
420e7fab | 2579 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
c8dcfd8a FF |
2580 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
2581 | NL80211_STA_INFO_TX_BITRATE)) | |
2582 | goto nla_put_failure; | |
2583 | } | |
2584 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { | |
2585 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, | |
2586 | NL80211_STA_INFO_RX_BITRATE)) | |
420e7fab | 2587 | goto nla_put_failure; |
420e7fab | 2588 | } |
9360ffd1 DM |
2589 | if ((sinfo->filled & STATION_INFO_RX_PACKETS) && |
2590 | nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS, | |
2591 | sinfo->rx_packets)) | |
2592 | goto nla_put_failure; | |
2593 | if ((sinfo->filled & STATION_INFO_TX_PACKETS) && | |
2594 | nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS, | |
2595 | sinfo->tx_packets)) | |
2596 | goto nla_put_failure; | |
2597 | if ((sinfo->filled & STATION_INFO_TX_RETRIES) && | |
2598 | nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES, | |
2599 | sinfo->tx_retries)) | |
2600 | goto nla_put_failure; | |
2601 | if ((sinfo->filled & STATION_INFO_TX_FAILED) && | |
2602 | nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED, | |
2603 | sinfo->tx_failed)) | |
2604 | goto nla_put_failure; | |
2605 | if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) && | |
2606 | nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS, | |
2607 | sinfo->beacon_loss_count)) | |
2608 | goto nla_put_failure; | |
f4263c98 PS |
2609 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { |
2610 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); | |
2611 | if (!bss_param) | |
2612 | goto nla_put_failure; | |
2613 | ||
9360ffd1 DM |
2614 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
2615 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || | |
2616 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && | |
2617 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || | |
2618 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && | |
2619 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || | |
2620 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, | |
2621 | sinfo->bss_param.dtim_period) || | |
2622 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, | |
2623 | sinfo->bss_param.beacon_interval)) | |
2624 | goto nla_put_failure; | |
f4263c98 PS |
2625 | |
2626 | nla_nest_end(msg, bss_param); | |
2627 | } | |
9360ffd1 DM |
2628 | if ((sinfo->filled & STATION_INFO_STA_FLAGS) && |
2629 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, | |
2630 | sizeof(struct nl80211_sta_flag_update), | |
2631 | &sinfo->sta_flags)) | |
2632 | goto nla_put_failure; | |
7eab0f64 JL |
2633 | if ((sinfo->filled & STATION_INFO_T_OFFSET) && |
2634 | nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET, | |
2635 | sinfo->t_offset)) | |
2636 | goto nla_put_failure; | |
2ec600d6 | 2637 | nla_nest_end(msg, sinfoattr); |
fd5b74dc | 2638 | |
9360ffd1 DM |
2639 | if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) && |
2640 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, | |
2641 | sinfo->assoc_req_ies)) | |
2642 | goto nla_put_failure; | |
50d3dfb7 | 2643 | |
fd5b74dc JB |
2644 | return genlmsg_end(msg, hdr); |
2645 | ||
2646 | nla_put_failure: | |
bc3ed28c TG |
2647 | genlmsg_cancel(msg, hdr); |
2648 | return -EMSGSIZE; | |
fd5b74dc JB |
2649 | } |
2650 | ||
2ec600d6 | 2651 | static int nl80211_dump_station(struct sk_buff *skb, |
bba95fef | 2652 | struct netlink_callback *cb) |
2ec600d6 | 2653 | { |
2ec600d6 LCC |
2654 | struct station_info sinfo; |
2655 | struct cfg80211_registered_device *dev; | |
bba95fef | 2656 | struct net_device *netdev; |
2ec600d6 | 2657 | u8 mac_addr[ETH_ALEN]; |
bba95fef | 2658 | int sta_idx = cb->args[1]; |
2ec600d6 | 2659 | int err; |
2ec600d6 | 2660 | |
67748893 JB |
2661 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
2662 | if (err) | |
2663 | return err; | |
bba95fef JB |
2664 | |
2665 | if (!dev->ops->dump_station) { | |
eec60b03 | 2666 | err = -EOPNOTSUPP; |
bba95fef JB |
2667 | goto out_err; |
2668 | } | |
2669 | ||
bba95fef | 2670 | while (1) { |
f612cedf | 2671 | memset(&sinfo, 0, sizeof(sinfo)); |
bba95fef JB |
2672 | err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx, |
2673 | mac_addr, &sinfo); | |
2674 | if (err == -ENOENT) | |
2675 | break; | |
2676 | if (err) | |
3b85875a | 2677 | goto out_err; |
bba95fef JB |
2678 | |
2679 | if (nl80211_send_station(skb, | |
2680 | NETLINK_CB(cb->skb).pid, | |
2681 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
66266b3a | 2682 | dev, netdev, mac_addr, |
bba95fef JB |
2683 | &sinfo) < 0) |
2684 | goto out; | |
2685 | ||
2686 | sta_idx++; | |
2687 | } | |
2688 | ||
2689 | ||
2690 | out: | |
2691 | cb->args[1] = sta_idx; | |
2692 | err = skb->len; | |
bba95fef | 2693 | out_err: |
67748893 | 2694 | nl80211_finish_netdev_dump(dev); |
bba95fef JB |
2695 | |
2696 | return err; | |
2ec600d6 | 2697 | } |
fd5b74dc | 2698 | |
5727ef1b JB |
2699 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
2700 | { | |
4c476991 JB |
2701 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2702 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 | 2703 | struct station_info sinfo; |
fd5b74dc JB |
2704 | struct sk_buff *msg; |
2705 | u8 *mac_addr = NULL; | |
4c476991 | 2706 | int err; |
fd5b74dc | 2707 | |
2ec600d6 | 2708 | memset(&sinfo, 0, sizeof(sinfo)); |
fd5b74dc JB |
2709 | |
2710 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2711 | return -EINVAL; | |
2712 | ||
2713 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2714 | ||
4c476991 JB |
2715 | if (!rdev->ops->get_station) |
2716 | return -EOPNOTSUPP; | |
3b85875a | 2717 | |
4c476991 | 2718 | err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo); |
fd5b74dc | 2719 | if (err) |
4c476991 | 2720 | return err; |
2ec600d6 | 2721 | |
fd2120ca | 2722 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
fd5b74dc | 2723 | if (!msg) |
4c476991 | 2724 | return -ENOMEM; |
fd5b74dc JB |
2725 | |
2726 | if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0, | |
66266b3a | 2727 | rdev, dev, mac_addr, &sinfo) < 0) { |
4c476991 JB |
2728 | nlmsg_free(msg); |
2729 | return -ENOBUFS; | |
2730 | } | |
3b85875a | 2731 | |
4c476991 | 2732 | return genlmsg_reply(msg, info); |
5727ef1b JB |
2733 | } |
2734 | ||
2735 | /* | |
c258d2de | 2736 | * Get vlan interface making sure it is running and on the right wiphy. |
5727ef1b | 2737 | */ |
80b99899 JB |
2738 | static struct net_device *get_vlan(struct genl_info *info, |
2739 | struct cfg80211_registered_device *rdev) | |
5727ef1b | 2740 | { |
463d0183 | 2741 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
80b99899 JB |
2742 | struct net_device *v; |
2743 | int ret; | |
2744 | ||
2745 | if (!vlanattr) | |
2746 | return NULL; | |
2747 | ||
2748 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); | |
2749 | if (!v) | |
2750 | return ERR_PTR(-ENODEV); | |
2751 | ||
2752 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { | |
2753 | ret = -EINVAL; | |
2754 | goto error; | |
5727ef1b | 2755 | } |
80b99899 JB |
2756 | |
2757 | if (!netif_running(v)) { | |
2758 | ret = -ENETDOWN; | |
2759 | goto error; | |
2760 | } | |
2761 | ||
2762 | return v; | |
2763 | error: | |
2764 | dev_put(v); | |
2765 | return ERR_PTR(ret); | |
5727ef1b JB |
2766 | } |
2767 | ||
2768 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) | |
2769 | { | |
4c476991 | 2770 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5727ef1b | 2771 | int err; |
4c476991 | 2772 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b JB |
2773 | struct station_parameters params; |
2774 | u8 *mac_addr = NULL; | |
2775 | ||
2776 | memset(¶ms, 0, sizeof(params)); | |
2777 | ||
2778 | params.listen_interval = -1; | |
57cf8043 | 2779 | params.plink_state = -1; |
5727ef1b JB |
2780 | |
2781 | if (info->attrs[NL80211_ATTR_STA_AID]) | |
2782 | return -EINVAL; | |
2783 | ||
2784 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2785 | return -EINVAL; | |
2786 | ||
2787 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2788 | ||
2789 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { | |
2790 | params.supported_rates = | |
2791 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
2792 | params.supported_rates_len = | |
2793 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
2794 | } | |
2795 | ||
2796 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) | |
2797 | params.listen_interval = | |
2798 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
2799 | ||
36aedc90 JM |
2800 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
2801 | params.ht_capa = | |
2802 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
2803 | ||
bdd90d5e JB |
2804 | if (!rdev->ops->change_station) |
2805 | return -EOPNOTSUPP; | |
2806 | ||
bdd3ae3d | 2807 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
2808 | return -EINVAL; |
2809 | ||
2ec600d6 LCC |
2810 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
2811 | params.plink_action = | |
2812 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); | |
2813 | ||
9c3990aa JC |
2814 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) |
2815 | params.plink_state = | |
2816 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); | |
2817 | ||
a97f4424 JB |
2818 | switch (dev->ieee80211_ptr->iftype) { |
2819 | case NL80211_IFTYPE_AP: | |
2820 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 2821 | case NL80211_IFTYPE_P2P_GO: |
a97f4424 JB |
2822 | /* disallow mesh-specific things */ |
2823 | if (params.plink_action) | |
bdd90d5e JB |
2824 | return -EINVAL; |
2825 | ||
2826 | /* TDLS can't be set, ... */ | |
2827 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
2828 | return -EINVAL; | |
2829 | /* | |
2830 | * ... but don't bother the driver with it. This works around | |
2831 | * a hostapd/wpa_supplicant issue -- it always includes the | |
2832 | * TLDS_PEER flag in the mask even for AP mode. | |
2833 | */ | |
2834 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
2835 | ||
2836 | /* accept only the listed bits */ | |
2837 | if (params.sta_flags_mask & | |
2838 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
2839 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
2840 | BIT(NL80211_STA_FLAG_WME) | | |
2841 | BIT(NL80211_STA_FLAG_MFP))) | |
2842 | return -EINVAL; | |
2843 | ||
2844 | /* must be last in here for error handling */ | |
2845 | params.vlan = get_vlan(info, rdev); | |
2846 | if (IS_ERR(params.vlan)) | |
2847 | return PTR_ERR(params.vlan); | |
a97f4424 | 2848 | break; |
074ac8df | 2849 | case NL80211_IFTYPE_P2P_CLIENT: |
a97f4424 | 2850 | case NL80211_IFTYPE_STATION: |
bdd90d5e JB |
2851 | /* |
2852 | * Don't allow userspace to change the TDLS_PEER flag, | |
2853 | * but silently ignore attempts to change it since we | |
2854 | * don't have state here to verify that it doesn't try | |
2855 | * to change the flag. | |
2856 | */ | |
2857 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
267335d6 AQ |
2858 | /* fall through */ |
2859 | case NL80211_IFTYPE_ADHOC: | |
2860 | /* disallow things sta doesn't support */ | |
2861 | if (params.plink_action) | |
2862 | return -EINVAL; | |
2863 | if (params.ht_capa) | |
2864 | return -EINVAL; | |
2865 | if (params.listen_interval >= 0) | |
2866 | return -EINVAL; | |
bdd90d5e JB |
2867 | /* reject any changes other than AUTHORIZED */ |
2868 | if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
2869 | return -EINVAL; | |
a97f4424 JB |
2870 | break; |
2871 | case NL80211_IFTYPE_MESH_POINT: | |
2872 | /* disallow things mesh doesn't support */ | |
2873 | if (params.vlan) | |
bdd90d5e | 2874 | return -EINVAL; |
a97f4424 | 2875 | if (params.ht_capa) |
bdd90d5e | 2876 | return -EINVAL; |
a97f4424 | 2877 | if (params.listen_interval >= 0) |
bdd90d5e JB |
2878 | return -EINVAL; |
2879 | /* | |
2880 | * No special handling for TDLS here -- the userspace | |
2881 | * mesh code doesn't have this bug. | |
2882 | */ | |
b39c48fa JC |
2883 | if (params.sta_flags_mask & |
2884 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
8429828e | 2885 | BIT(NL80211_STA_FLAG_MFP) | |
b39c48fa | 2886 | BIT(NL80211_STA_FLAG_AUTHORIZED))) |
bdd90d5e | 2887 | return -EINVAL; |
a97f4424 JB |
2888 | break; |
2889 | default: | |
bdd90d5e | 2890 | return -EOPNOTSUPP; |
034d655e JB |
2891 | } |
2892 | ||
bdd90d5e | 2893 | /* be aware of params.vlan when changing code here */ |
5727ef1b | 2894 | |
79c97e97 | 2895 | err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
5727ef1b | 2896 | |
5727ef1b JB |
2897 | if (params.vlan) |
2898 | dev_put(params.vlan); | |
3b85875a | 2899 | |
5727ef1b JB |
2900 | return err; |
2901 | } | |
2902 | ||
c75786c9 EP |
2903 | static struct nla_policy |
2904 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] __read_mostly = { | |
2905 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, | |
2906 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, | |
2907 | }; | |
2908 | ||
5727ef1b JB |
2909 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
2910 | { | |
4c476991 | 2911 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5727ef1b | 2912 | int err; |
4c476991 | 2913 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b JB |
2914 | struct station_parameters params; |
2915 | u8 *mac_addr = NULL; | |
2916 | ||
2917 | memset(¶ms, 0, sizeof(params)); | |
2918 | ||
2919 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2920 | return -EINVAL; | |
2921 | ||
5727ef1b JB |
2922 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
2923 | return -EINVAL; | |
2924 | ||
2925 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) | |
2926 | return -EINVAL; | |
2927 | ||
0e956c13 TLSC |
2928 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
2929 | return -EINVAL; | |
2930 | ||
5727ef1b JB |
2931 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
2932 | params.supported_rates = | |
2933 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
2934 | params.supported_rates_len = | |
2935 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
2936 | params.listen_interval = | |
2937 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
51b50fbe | 2938 | |
0e956c13 TLSC |
2939 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
2940 | if (!params.aid || params.aid > IEEE80211_MAX_AID) | |
2941 | return -EINVAL; | |
51b50fbe | 2942 | |
36aedc90 JM |
2943 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
2944 | params.ht_capa = | |
2945 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
5727ef1b | 2946 | |
96b78dff JC |
2947 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
2948 | params.plink_action = | |
2949 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); | |
2950 | ||
bdd90d5e JB |
2951 | if (!rdev->ops->add_station) |
2952 | return -EOPNOTSUPP; | |
2953 | ||
bdd3ae3d | 2954 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
2955 | return -EINVAL; |
2956 | ||
bdd90d5e JB |
2957 | switch (dev->ieee80211_ptr->iftype) { |
2958 | case NL80211_IFTYPE_AP: | |
2959 | case NL80211_IFTYPE_AP_VLAN: | |
2960 | case NL80211_IFTYPE_P2P_GO: | |
2961 | /* parse WME attributes if sta is WME capable */ | |
2962 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && | |
2963 | (params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)) && | |
2964 | info->attrs[NL80211_ATTR_STA_WME]) { | |
2965 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; | |
2966 | struct nlattr *nla; | |
2967 | ||
2968 | nla = info->attrs[NL80211_ATTR_STA_WME]; | |
2969 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, | |
2970 | nl80211_sta_wme_policy); | |
2971 | if (err) | |
2972 | return err; | |
2973 | ||
2974 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) | |
2975 | params.uapsd_queues = | |
2976 | nla_get_u8(tb[NL80211_STA_WME_UAPSD_QUEUES]); | |
2977 | if (params.uapsd_queues & | |
2978 | ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) | |
2979 | return -EINVAL; | |
c75786c9 | 2980 | |
bdd90d5e JB |
2981 | if (tb[NL80211_STA_WME_MAX_SP]) |
2982 | params.max_sp = | |
2983 | nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); | |
c75786c9 | 2984 | |
bdd90d5e JB |
2985 | if (params.max_sp & |
2986 | ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) | |
2987 | return -EINVAL; | |
4319e193 | 2988 | |
bdd90d5e JB |
2989 | params.sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; |
2990 | } | |
2991 | /* TDLS peers cannot be added */ | |
2992 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
4319e193 | 2993 | return -EINVAL; |
bdd90d5e JB |
2994 | /* but don't bother the driver with it */ |
2995 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3b9ce80c | 2996 | |
bdd90d5e JB |
2997 | /* must be last in here for error handling */ |
2998 | params.vlan = get_vlan(info, rdev); | |
2999 | if (IS_ERR(params.vlan)) | |
3000 | return PTR_ERR(params.vlan); | |
3001 | break; | |
3002 | case NL80211_IFTYPE_MESH_POINT: | |
3003 | /* TDLS peers cannot be added */ | |
3004 | if (params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
3005 | return -EINVAL; | |
3006 | break; | |
3007 | case NL80211_IFTYPE_STATION: | |
3008 | /* Only TDLS peers can be added */ | |
3009 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
3010 | return -EINVAL; | |
3011 | /* Can only add if TDLS ... */ | |
3012 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) | |
3013 | return -EOPNOTSUPP; | |
3014 | /* ... with external setup is supported */ | |
3015 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) | |
3016 | return -EOPNOTSUPP; | |
3017 | break; | |
3018 | default: | |
3019 | return -EOPNOTSUPP; | |
c75786c9 EP |
3020 | } |
3021 | ||
bdd90d5e | 3022 | /* be aware of params.vlan when changing code here */ |
5727ef1b | 3023 | |
79c97e97 | 3024 | err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
5727ef1b | 3025 | |
5727ef1b JB |
3026 | if (params.vlan) |
3027 | dev_put(params.vlan); | |
5727ef1b JB |
3028 | return err; |
3029 | } | |
3030 | ||
3031 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) | |
3032 | { | |
4c476991 JB |
3033 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3034 | struct net_device *dev = info->user_ptr[1]; | |
5727ef1b JB |
3035 | u8 *mac_addr = NULL; |
3036 | ||
3037 | if (info->attrs[NL80211_ATTR_MAC]) | |
3038 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3039 | ||
e80cf853 | 3040 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
d5d9de02 | 3041 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
074ac8df | 3042 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
4c476991 JB |
3043 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
3044 | return -EINVAL; | |
5727ef1b | 3045 | |
4c476991 JB |
3046 | if (!rdev->ops->del_station) |
3047 | return -EOPNOTSUPP; | |
3b85875a | 3048 | |
4c476991 | 3049 | return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr); |
5727ef1b JB |
3050 | } |
3051 | ||
2ec600d6 LCC |
3052 | static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq, |
3053 | int flags, struct net_device *dev, | |
3054 | u8 *dst, u8 *next_hop, | |
3055 | struct mpath_info *pinfo) | |
3056 | { | |
3057 | void *hdr; | |
3058 | struct nlattr *pinfoattr; | |
3059 | ||
3060 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); | |
3061 | if (!hdr) | |
3062 | return -1; | |
3063 | ||
9360ffd1 DM |
3064 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
3065 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || | |
3066 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || | |
3067 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) | |
3068 | goto nla_put_failure; | |
f5ea9120 | 3069 | |
2ec600d6 LCC |
3070 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
3071 | if (!pinfoattr) | |
3072 | goto nla_put_failure; | |
9360ffd1 DM |
3073 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
3074 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, | |
3075 | pinfo->frame_qlen)) | |
3076 | goto nla_put_failure; | |
3077 | if (((pinfo->filled & MPATH_INFO_SN) && | |
3078 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || | |
3079 | ((pinfo->filled & MPATH_INFO_METRIC) && | |
3080 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, | |
3081 | pinfo->metric)) || | |
3082 | ((pinfo->filled & MPATH_INFO_EXPTIME) && | |
3083 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, | |
3084 | pinfo->exptime)) || | |
3085 | ((pinfo->filled & MPATH_INFO_FLAGS) && | |
3086 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, | |
3087 | pinfo->flags)) || | |
3088 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && | |
3089 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, | |
3090 | pinfo->discovery_timeout)) || | |
3091 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && | |
3092 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, | |
3093 | pinfo->discovery_retries))) | |
3094 | goto nla_put_failure; | |
2ec600d6 LCC |
3095 | |
3096 | nla_nest_end(msg, pinfoattr); | |
3097 | ||
3098 | return genlmsg_end(msg, hdr); | |
3099 | ||
3100 | nla_put_failure: | |
bc3ed28c TG |
3101 | genlmsg_cancel(msg, hdr); |
3102 | return -EMSGSIZE; | |
2ec600d6 LCC |
3103 | } |
3104 | ||
3105 | static int nl80211_dump_mpath(struct sk_buff *skb, | |
bba95fef | 3106 | struct netlink_callback *cb) |
2ec600d6 | 3107 | { |
2ec600d6 LCC |
3108 | struct mpath_info pinfo; |
3109 | struct cfg80211_registered_device *dev; | |
bba95fef | 3110 | struct net_device *netdev; |
2ec600d6 LCC |
3111 | u8 dst[ETH_ALEN]; |
3112 | u8 next_hop[ETH_ALEN]; | |
bba95fef | 3113 | int path_idx = cb->args[1]; |
2ec600d6 | 3114 | int err; |
2ec600d6 | 3115 | |
67748893 JB |
3116 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
3117 | if (err) | |
3118 | return err; | |
bba95fef JB |
3119 | |
3120 | if (!dev->ops->dump_mpath) { | |
eec60b03 | 3121 | err = -EOPNOTSUPP; |
bba95fef JB |
3122 | goto out_err; |
3123 | } | |
3124 | ||
eec60b03 JM |
3125 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
3126 | err = -EOPNOTSUPP; | |
0448b5fc | 3127 | goto out_err; |
eec60b03 JM |
3128 | } |
3129 | ||
bba95fef JB |
3130 | while (1) { |
3131 | err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx, | |
3132 | dst, next_hop, &pinfo); | |
3133 | if (err == -ENOENT) | |
2ec600d6 | 3134 | break; |
bba95fef | 3135 | if (err) |
3b85875a | 3136 | goto out_err; |
2ec600d6 | 3137 | |
bba95fef JB |
3138 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid, |
3139 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
3140 | netdev, dst, next_hop, | |
3141 | &pinfo) < 0) | |
3142 | goto out; | |
2ec600d6 | 3143 | |
bba95fef | 3144 | path_idx++; |
2ec600d6 | 3145 | } |
2ec600d6 | 3146 | |
2ec600d6 | 3147 | |
bba95fef JB |
3148 | out: |
3149 | cb->args[1] = path_idx; | |
3150 | err = skb->len; | |
bba95fef | 3151 | out_err: |
67748893 | 3152 | nl80211_finish_netdev_dump(dev); |
bba95fef | 3153 | return err; |
2ec600d6 LCC |
3154 | } |
3155 | ||
3156 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) | |
3157 | { | |
4c476991 | 3158 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 3159 | int err; |
4c476991 | 3160 | struct net_device *dev = info->user_ptr[1]; |
2ec600d6 LCC |
3161 | struct mpath_info pinfo; |
3162 | struct sk_buff *msg; | |
3163 | u8 *dst = NULL; | |
3164 | u8 next_hop[ETH_ALEN]; | |
3165 | ||
3166 | memset(&pinfo, 0, sizeof(pinfo)); | |
3167 | ||
3168 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3169 | return -EINVAL; | |
3170 | ||
3171 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3172 | ||
4c476991 JB |
3173 | if (!rdev->ops->get_mpath) |
3174 | return -EOPNOTSUPP; | |
2ec600d6 | 3175 | |
4c476991 JB |
3176 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
3177 | return -EOPNOTSUPP; | |
eec60b03 | 3178 | |
79c97e97 | 3179 | err = rdev->ops->get_mpath(&rdev->wiphy, dev, dst, next_hop, &pinfo); |
2ec600d6 | 3180 | if (err) |
4c476991 | 3181 | return err; |
2ec600d6 | 3182 | |
fd2120ca | 3183 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2ec600d6 | 3184 | if (!msg) |
4c476991 | 3185 | return -ENOMEM; |
2ec600d6 LCC |
3186 | |
3187 | if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0, | |
4c476991 JB |
3188 | dev, dst, next_hop, &pinfo) < 0) { |
3189 | nlmsg_free(msg); | |
3190 | return -ENOBUFS; | |
3191 | } | |
3b85875a | 3192 | |
4c476991 | 3193 | return genlmsg_reply(msg, info); |
2ec600d6 LCC |
3194 | } |
3195 | ||
3196 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) | |
3197 | { | |
4c476991 JB |
3198 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3199 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
3200 | u8 *dst = NULL; |
3201 | u8 *next_hop = NULL; | |
3202 | ||
3203 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3204 | return -EINVAL; | |
3205 | ||
3206 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
3207 | return -EINVAL; | |
3208 | ||
3209 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3210 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
3211 | ||
4c476991 JB |
3212 | if (!rdev->ops->change_mpath) |
3213 | return -EOPNOTSUPP; | |
35a8efe1 | 3214 | |
4c476991 JB |
3215 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
3216 | return -EOPNOTSUPP; | |
2ec600d6 | 3217 | |
4c476991 | 3218 | return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop); |
2ec600d6 | 3219 | } |
4c476991 | 3220 | |
2ec600d6 LCC |
3221 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
3222 | { | |
4c476991 JB |
3223 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3224 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
3225 | u8 *dst = NULL; |
3226 | u8 *next_hop = NULL; | |
3227 | ||
3228 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3229 | return -EINVAL; | |
3230 | ||
3231 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
3232 | return -EINVAL; | |
3233 | ||
3234 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3235 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
3236 | ||
4c476991 JB |
3237 | if (!rdev->ops->add_mpath) |
3238 | return -EOPNOTSUPP; | |
35a8efe1 | 3239 | |
4c476991 JB |
3240 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
3241 | return -EOPNOTSUPP; | |
2ec600d6 | 3242 | |
4c476991 | 3243 | return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop); |
2ec600d6 LCC |
3244 | } |
3245 | ||
3246 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) | |
3247 | { | |
4c476991 JB |
3248 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3249 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
3250 | u8 *dst = NULL; |
3251 | ||
3252 | if (info->attrs[NL80211_ATTR_MAC]) | |
3253 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3254 | ||
4c476991 JB |
3255 | if (!rdev->ops->del_mpath) |
3256 | return -EOPNOTSUPP; | |
3b85875a | 3257 | |
4c476991 | 3258 | return rdev->ops->del_mpath(&rdev->wiphy, dev, dst); |
2ec600d6 LCC |
3259 | } |
3260 | ||
9f1ba906 JM |
3261 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
3262 | { | |
4c476991 JB |
3263 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3264 | struct net_device *dev = info->user_ptr[1]; | |
9f1ba906 JM |
3265 | struct bss_parameters params; |
3266 | ||
3267 | memset(¶ms, 0, sizeof(params)); | |
3268 | /* default to not changing parameters */ | |
3269 | params.use_cts_prot = -1; | |
3270 | params.use_short_preamble = -1; | |
3271 | params.use_short_slot_time = -1; | |
fd8aaaf3 | 3272 | params.ap_isolate = -1; |
50b12f59 | 3273 | params.ht_opmode = -1; |
9f1ba906 JM |
3274 | |
3275 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) | |
3276 | params.use_cts_prot = | |
3277 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); | |
3278 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) | |
3279 | params.use_short_preamble = | |
3280 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); | |
3281 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) | |
3282 | params.use_short_slot_time = | |
3283 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); | |
90c97a04 JM |
3284 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
3285 | params.basic_rates = | |
3286 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
3287 | params.basic_rates_len = | |
3288 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
3289 | } | |
fd8aaaf3 FF |
3290 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
3291 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); | |
50b12f59 HS |
3292 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
3293 | params.ht_opmode = | |
3294 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); | |
9f1ba906 | 3295 | |
4c476991 JB |
3296 | if (!rdev->ops->change_bss) |
3297 | return -EOPNOTSUPP; | |
9f1ba906 | 3298 | |
074ac8df | 3299 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
4c476991 JB |
3300 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
3301 | return -EOPNOTSUPP; | |
3b85875a | 3302 | |
4c476991 | 3303 | return rdev->ops->change_bss(&rdev->wiphy, dev, ¶ms); |
9f1ba906 JM |
3304 | } |
3305 | ||
b54452b0 | 3306 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
b2e1b302 LR |
3307 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
3308 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, | |
3309 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, | |
3310 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, | |
3311 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, | |
3312 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, | |
3313 | }; | |
3314 | ||
3315 | static int parse_reg_rule(struct nlattr *tb[], | |
3316 | struct ieee80211_reg_rule *reg_rule) | |
3317 | { | |
3318 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; | |
3319 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; | |
3320 | ||
3321 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) | |
3322 | return -EINVAL; | |
3323 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) | |
3324 | return -EINVAL; | |
3325 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) | |
3326 | return -EINVAL; | |
3327 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) | |
3328 | return -EINVAL; | |
3329 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) | |
3330 | return -EINVAL; | |
3331 | ||
3332 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); | |
3333 | ||
3334 | freq_range->start_freq_khz = | |
3335 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); | |
3336 | freq_range->end_freq_khz = | |
3337 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); | |
3338 | freq_range->max_bandwidth_khz = | |
3339 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); | |
3340 | ||
3341 | power_rule->max_eirp = | |
3342 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); | |
3343 | ||
3344 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) | |
3345 | power_rule->max_antenna_gain = | |
3346 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); | |
3347 | ||
3348 | return 0; | |
3349 | } | |
3350 | ||
3351 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) | |
3352 | { | |
3353 | int r; | |
3354 | char *data = NULL; | |
3355 | ||
80778f18 LR |
3356 | /* |
3357 | * You should only get this when cfg80211 hasn't yet initialized | |
3358 | * completely when built-in to the kernel right between the time | |
3359 | * window between nl80211_init() and regulatory_init(), if that is | |
3360 | * even possible. | |
3361 | */ | |
3362 | mutex_lock(&cfg80211_mutex); | |
3363 | if (unlikely(!cfg80211_regdomain)) { | |
fe33eb39 LR |
3364 | mutex_unlock(&cfg80211_mutex); |
3365 | return -EINPROGRESS; | |
80778f18 | 3366 | } |
fe33eb39 | 3367 | mutex_unlock(&cfg80211_mutex); |
80778f18 | 3368 | |
fe33eb39 LR |
3369 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
3370 | return -EINVAL; | |
b2e1b302 LR |
3371 | |
3372 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
3373 | ||
fe33eb39 LR |
3374 | r = regulatory_hint_user(data); |
3375 | ||
b2e1b302 LR |
3376 | return r; |
3377 | } | |
3378 | ||
24bdd9f4 | 3379 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
29cbe68c | 3380 | struct genl_info *info) |
93da9cc1 | 3381 | { |
4c476991 | 3382 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 3383 | struct net_device *dev = info->user_ptr[1]; |
29cbe68c JB |
3384 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
3385 | struct mesh_config cur_params; | |
3386 | int err = 0; | |
93da9cc1 | 3387 | void *hdr; |
3388 | struct nlattr *pinfoattr; | |
3389 | struct sk_buff *msg; | |
3390 | ||
29cbe68c JB |
3391 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
3392 | return -EOPNOTSUPP; | |
3393 | ||
24bdd9f4 | 3394 | if (!rdev->ops->get_mesh_config) |
4c476991 | 3395 | return -EOPNOTSUPP; |
f3f92586 | 3396 | |
29cbe68c JB |
3397 | wdev_lock(wdev); |
3398 | /* If not connected, get default parameters */ | |
3399 | if (!wdev->mesh_id_len) | |
3400 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); | |
3401 | else | |
24bdd9f4 | 3402 | err = rdev->ops->get_mesh_config(&rdev->wiphy, dev, |
29cbe68c JB |
3403 | &cur_params); |
3404 | wdev_unlock(wdev); | |
3405 | ||
93da9cc1 | 3406 | if (err) |
4c476991 | 3407 | return err; |
93da9cc1 | 3408 | |
3409 | /* Draw up a netlink message to send back */ | |
fd2120ca | 3410 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
3411 | if (!msg) |
3412 | return -ENOMEM; | |
93da9cc1 | 3413 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
24bdd9f4 | 3414 | NL80211_CMD_GET_MESH_CONFIG); |
93da9cc1 | 3415 | if (!hdr) |
efe1cf0c | 3416 | goto out; |
24bdd9f4 | 3417 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
93da9cc1 | 3418 | if (!pinfoattr) |
3419 | goto nla_put_failure; | |
9360ffd1 DM |
3420 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
3421 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, | |
3422 | cur_params.dot11MeshRetryTimeout) || | |
3423 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, | |
3424 | cur_params.dot11MeshConfirmTimeout) || | |
3425 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, | |
3426 | cur_params.dot11MeshHoldingTimeout) || | |
3427 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
3428 | cur_params.dot11MeshMaxPeerLinks) || | |
3429 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, | |
3430 | cur_params.dot11MeshMaxRetries) || | |
3431 | nla_put_u8(msg, NL80211_MESHCONF_TTL, | |
3432 | cur_params.dot11MeshTTL) || | |
3433 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, | |
3434 | cur_params.element_ttl) || | |
3435 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | |
3436 | cur_params.auto_open_plinks) || | |
7eab0f64 JL |
3437 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
3438 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || | |
9360ffd1 DM |
3439 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
3440 | cur_params.dot11MeshHWMPmaxPREQretries) || | |
3441 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, | |
3442 | cur_params.path_refresh_time) || | |
3443 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
3444 | cur_params.min_discovery_timeout) || | |
3445 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
3446 | cur_params.dot11MeshHWMPactivePathTimeout) || | |
3447 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
3448 | cur_params.dot11MeshHWMPpreqMinInterval) || | |
3449 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
3450 | cur_params.dot11MeshHWMPperrMinInterval) || | |
3451 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
3452 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || | |
3453 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, | |
3454 | cur_params.dot11MeshHWMPRootMode) || | |
3455 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
3456 | cur_params.dot11MeshHWMPRannInterval) || | |
3457 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
3458 | cur_params.dot11MeshGateAnnouncementProtocol) || | |
3459 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, | |
3460 | cur_params.dot11MeshForwarding) || | |
3461 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, | |
70c33eaa AN |
3462 | cur_params.rssi_threshold) || |
3463 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, | |
3464 | cur_params.ht_opmode)) | |
9360ffd1 | 3465 | goto nla_put_failure; |
93da9cc1 | 3466 | nla_nest_end(msg, pinfoattr); |
3467 | genlmsg_end(msg, hdr); | |
4c476991 | 3468 | return genlmsg_reply(msg, info); |
93da9cc1 | 3469 | |
3b85875a | 3470 | nla_put_failure: |
93da9cc1 | 3471 | genlmsg_cancel(msg, hdr); |
efe1cf0c | 3472 | out: |
d080e275 | 3473 | nlmsg_free(msg); |
4c476991 | 3474 | return -ENOBUFS; |
93da9cc1 | 3475 | } |
3476 | ||
b54452b0 | 3477 | static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
93da9cc1 | 3478 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
3479 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, | |
3480 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, | |
3481 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, | |
3482 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, | |
3483 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, | |
45904f21 | 3484 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
93da9cc1 | 3485 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
d299a1f2 | 3486 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
93da9cc1 | 3487 | |
3488 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, | |
3489 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, | |
3490 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, | |
3491 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, | |
3492 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, | |
dca7e943 | 3493 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
93da9cc1 | 3494 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
699403db | 3495 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
0507e159 | 3496 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
16dd7267 | 3497 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
94f90656 | 3498 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
55335137 | 3499 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32}, |
70c33eaa | 3500 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16}, |
93da9cc1 | 3501 | }; |
3502 | ||
c80d545d JC |
3503 | static const struct nla_policy |
3504 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { | |
d299a1f2 | 3505 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
c80d545d JC |
3506 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
3507 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, | |
15d5dda6 | 3508 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
581a8b0f | 3509 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
c80d545d | 3510 | .len = IEEE80211_MAX_DATA_LEN }, |
b130e5ce | 3511 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
c80d545d JC |
3512 | }; |
3513 | ||
24bdd9f4 | 3514 | static int nl80211_parse_mesh_config(struct genl_info *info, |
bd90fdcc JB |
3515 | struct mesh_config *cfg, |
3516 | u32 *mask_out) | |
93da9cc1 | 3517 | { |
93da9cc1 | 3518 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
bd90fdcc | 3519 | u32 mask = 0; |
93da9cc1 | 3520 | |
bd90fdcc JB |
3521 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ |
3522 | do {\ | |
3523 | if (table[attr_num]) {\ | |
3524 | cfg->param = nla_fn(table[attr_num]); \ | |
3525 | mask |= (1 << (attr_num - 1)); \ | |
3526 | } \ | |
3527 | } while (0);\ | |
3528 | ||
3529 | ||
24bdd9f4 | 3530 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
93da9cc1 | 3531 | return -EINVAL; |
3532 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, | |
24bdd9f4 | 3533 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
bd90fdcc | 3534 | nl80211_meshconf_params_policy)) |
93da9cc1 | 3535 | return -EINVAL; |
3536 | ||
93da9cc1 | 3537 | /* This makes sure that there aren't more than 32 mesh config |
3538 | * parameters (otherwise our bitfield scheme would not work.) */ | |
3539 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); | |
3540 | ||
3541 | /* Fill in the params struct */ | |
93da9cc1 | 3542 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, |
3543 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); | |
3544 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, | |
3545 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16); | |
3546 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, | |
3547 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16); | |
3548 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, | |
3549 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16); | |
3550 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, | |
3551 | mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); | |
3552 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, | |
3553 | mask, NL80211_MESHCONF_TTL, nla_get_u8); | |
45904f21 JC |
3554 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, |
3555 | mask, NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8); | |
93da9cc1 | 3556 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, |
3557 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8); | |
d299a1f2 JC |
3558 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
3559 | mask, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, | |
3560 | nla_get_u32); | |
93da9cc1 | 3561 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, |
3562 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, | |
3563 | nla_get_u8); | |
3564 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, | |
3565 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32); | |
3566 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, | |
3567 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
3568 | nla_get_u16); | |
3569 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, | |
3570 | mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
3571 | nla_get_u32); | |
3572 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, | |
3573 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
3574 | nla_get_u16); | |
dca7e943 TP |
3575 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
3576 | mask, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
3577 | nla_get_u16); | |
93da9cc1 | 3578 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
3579 | dot11MeshHWMPnetDiameterTraversalTime, | |
3580 | mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
3581 | nla_get_u16); | |
63c5723b RP |
3582 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
3583 | dot11MeshHWMPRootMode, mask, | |
3584 | NL80211_MESHCONF_HWMP_ROOTMODE, | |
3585 | nla_get_u8); | |
0507e159 JC |
3586 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
3587 | dot11MeshHWMPRannInterval, mask, | |
3588 | NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
3589 | nla_get_u16); | |
16dd7267 JC |
3590 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
3591 | dot11MeshGateAnnouncementProtocol, mask, | |
3592 | NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
3593 | nla_get_u8); | |
94f90656 CYY |
3594 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, |
3595 | mask, NL80211_MESHCONF_FORWARDING, nla_get_u8); | |
55335137 AN |
3596 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, |
3597 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, nla_get_u32); | |
70c33eaa AN |
3598 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, |
3599 | mask, NL80211_MESHCONF_HT_OPMODE, nla_get_u16); | |
bd90fdcc JB |
3600 | if (mask_out) |
3601 | *mask_out = mask; | |
c80d545d | 3602 | |
bd90fdcc JB |
3603 | return 0; |
3604 | ||
3605 | #undef FILL_IN_MESH_PARAM_IF_SET | |
3606 | } | |
3607 | ||
c80d545d JC |
3608 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
3609 | struct mesh_setup *setup) | |
3610 | { | |
3611 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; | |
3612 | ||
3613 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) | |
3614 | return -EINVAL; | |
3615 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, | |
3616 | info->attrs[NL80211_ATTR_MESH_SETUP], | |
3617 | nl80211_mesh_setup_params_policy)) | |
3618 | return -EINVAL; | |
3619 | ||
d299a1f2 JC |
3620 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
3621 | setup->sync_method = | |
3622 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? | |
3623 | IEEE80211_SYNC_METHOD_VENDOR : | |
3624 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; | |
3625 | ||
c80d545d JC |
3626 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
3627 | setup->path_sel_proto = | |
3628 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? | |
3629 | IEEE80211_PATH_PROTOCOL_VENDOR : | |
3630 | IEEE80211_PATH_PROTOCOL_HWMP; | |
3631 | ||
3632 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) | |
3633 | setup->path_metric = | |
3634 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? | |
3635 | IEEE80211_PATH_METRIC_VENDOR : | |
3636 | IEEE80211_PATH_METRIC_AIRTIME; | |
3637 | ||
581a8b0f JC |
3638 | |
3639 | if (tb[NL80211_MESH_SETUP_IE]) { | |
c80d545d | 3640 | struct nlattr *ieattr = |
581a8b0f | 3641 | tb[NL80211_MESH_SETUP_IE]; |
c80d545d JC |
3642 | if (!is_valid_ie_attr(ieattr)) |
3643 | return -EINVAL; | |
581a8b0f JC |
3644 | setup->ie = nla_data(ieattr); |
3645 | setup->ie_len = nla_len(ieattr); | |
c80d545d | 3646 | } |
b130e5ce JC |
3647 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
3648 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); | |
c80d545d JC |
3649 | |
3650 | return 0; | |
3651 | } | |
3652 | ||
24bdd9f4 | 3653 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
29cbe68c | 3654 | struct genl_info *info) |
bd90fdcc JB |
3655 | { |
3656 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3657 | struct net_device *dev = info->user_ptr[1]; | |
29cbe68c | 3658 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
bd90fdcc JB |
3659 | struct mesh_config cfg; |
3660 | u32 mask; | |
3661 | int err; | |
3662 | ||
29cbe68c JB |
3663 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
3664 | return -EOPNOTSUPP; | |
3665 | ||
24bdd9f4 | 3666 | if (!rdev->ops->update_mesh_config) |
bd90fdcc JB |
3667 | return -EOPNOTSUPP; |
3668 | ||
24bdd9f4 | 3669 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
bd90fdcc JB |
3670 | if (err) |
3671 | return err; | |
3672 | ||
29cbe68c JB |
3673 | wdev_lock(wdev); |
3674 | if (!wdev->mesh_id_len) | |
3675 | err = -ENOLINK; | |
3676 | ||
3677 | if (!err) | |
24bdd9f4 | 3678 | err = rdev->ops->update_mesh_config(&rdev->wiphy, dev, |
29cbe68c JB |
3679 | mask, &cfg); |
3680 | ||
3681 | wdev_unlock(wdev); | |
3682 | ||
3683 | return err; | |
93da9cc1 | 3684 | } |
3685 | ||
f130347c LR |
3686 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
3687 | { | |
3688 | struct sk_buff *msg; | |
3689 | void *hdr = NULL; | |
3690 | struct nlattr *nl_reg_rules; | |
3691 | unsigned int i; | |
3692 | int err = -EINVAL; | |
3693 | ||
a1794390 | 3694 | mutex_lock(&cfg80211_mutex); |
f130347c LR |
3695 | |
3696 | if (!cfg80211_regdomain) | |
3697 | goto out; | |
3698 | ||
fd2120ca | 3699 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
f130347c LR |
3700 | if (!msg) { |
3701 | err = -ENOBUFS; | |
3702 | goto out; | |
3703 | } | |
3704 | ||
3705 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | |
3706 | NL80211_CMD_GET_REG); | |
3707 | if (!hdr) | |
efe1cf0c | 3708 | goto put_failure; |
f130347c | 3709 | |
9360ffd1 DM |
3710 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, |
3711 | cfg80211_regdomain->alpha2) || | |
3712 | (cfg80211_regdomain->dfs_region && | |
3713 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, | |
3714 | cfg80211_regdomain->dfs_region))) | |
3715 | goto nla_put_failure; | |
f130347c LR |
3716 | |
3717 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); | |
3718 | if (!nl_reg_rules) | |
3719 | goto nla_put_failure; | |
3720 | ||
3721 | for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { | |
3722 | struct nlattr *nl_reg_rule; | |
3723 | const struct ieee80211_reg_rule *reg_rule; | |
3724 | const struct ieee80211_freq_range *freq_range; | |
3725 | const struct ieee80211_power_rule *power_rule; | |
3726 | ||
3727 | reg_rule = &cfg80211_regdomain->reg_rules[i]; | |
3728 | freq_range = ®_rule->freq_range; | |
3729 | power_rule = ®_rule->power_rule; | |
3730 | ||
3731 | nl_reg_rule = nla_nest_start(msg, i); | |
3732 | if (!nl_reg_rule) | |
3733 | goto nla_put_failure; | |
3734 | ||
9360ffd1 DM |
3735 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
3736 | reg_rule->flags) || | |
3737 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, | |
3738 | freq_range->start_freq_khz) || | |
3739 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, | |
3740 | freq_range->end_freq_khz) || | |
3741 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, | |
3742 | freq_range->max_bandwidth_khz) || | |
3743 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, | |
3744 | power_rule->max_antenna_gain) || | |
3745 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, | |
3746 | power_rule->max_eirp)) | |
3747 | goto nla_put_failure; | |
f130347c LR |
3748 | |
3749 | nla_nest_end(msg, nl_reg_rule); | |
3750 | } | |
3751 | ||
3752 | nla_nest_end(msg, nl_reg_rules); | |
3753 | ||
3754 | genlmsg_end(msg, hdr); | |
134e6375 | 3755 | err = genlmsg_reply(msg, info); |
f130347c LR |
3756 | goto out; |
3757 | ||
3758 | nla_put_failure: | |
3759 | genlmsg_cancel(msg, hdr); | |
efe1cf0c | 3760 | put_failure: |
d080e275 | 3761 | nlmsg_free(msg); |
f130347c LR |
3762 | err = -EMSGSIZE; |
3763 | out: | |
a1794390 | 3764 | mutex_unlock(&cfg80211_mutex); |
f130347c LR |
3765 | return err; |
3766 | } | |
3767 | ||
b2e1b302 LR |
3768 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
3769 | { | |
3770 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; | |
3771 | struct nlattr *nl_reg_rule; | |
3772 | char *alpha2 = NULL; | |
3773 | int rem_reg_rules = 0, r = 0; | |
3774 | u32 num_rules = 0, rule_idx = 0, size_of_regd; | |
8b60b078 | 3775 | u8 dfs_region = 0; |
b2e1b302 LR |
3776 | struct ieee80211_regdomain *rd = NULL; |
3777 | ||
3778 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) | |
3779 | return -EINVAL; | |
3780 | ||
3781 | if (!info->attrs[NL80211_ATTR_REG_RULES]) | |
3782 | return -EINVAL; | |
3783 | ||
3784 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
3785 | ||
8b60b078 LR |
3786 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
3787 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); | |
3788 | ||
b2e1b302 LR |
3789 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
3790 | rem_reg_rules) { | |
3791 | num_rules++; | |
3792 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) | |
4776c6e7 | 3793 | return -EINVAL; |
b2e1b302 LR |
3794 | } |
3795 | ||
61405e97 LR |
3796 | mutex_lock(&cfg80211_mutex); |
3797 | ||
d0e18f83 LR |
3798 | if (!reg_is_valid_request(alpha2)) { |
3799 | r = -EINVAL; | |
3800 | goto bad_reg; | |
3801 | } | |
b2e1b302 LR |
3802 | |
3803 | size_of_regd = sizeof(struct ieee80211_regdomain) + | |
3804 | (num_rules * sizeof(struct ieee80211_reg_rule)); | |
3805 | ||
3806 | rd = kzalloc(size_of_regd, GFP_KERNEL); | |
d0e18f83 LR |
3807 | if (!rd) { |
3808 | r = -ENOMEM; | |
3809 | goto bad_reg; | |
3810 | } | |
b2e1b302 LR |
3811 | |
3812 | rd->n_reg_rules = num_rules; | |
3813 | rd->alpha2[0] = alpha2[0]; | |
3814 | rd->alpha2[1] = alpha2[1]; | |
3815 | ||
8b60b078 LR |
3816 | /* |
3817 | * Disable DFS master mode if the DFS region was | |
3818 | * not supported or known on this kernel. | |
3819 | */ | |
3820 | if (reg_supported_dfs_region(dfs_region)) | |
3821 | rd->dfs_region = dfs_region; | |
3822 | ||
b2e1b302 LR |
3823 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
3824 | rem_reg_rules) { | |
3825 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, | |
3826 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), | |
3827 | reg_rule_policy); | |
3828 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); | |
3829 | if (r) | |
3830 | goto bad_reg; | |
3831 | ||
3832 | rule_idx++; | |
3833 | ||
d0e18f83 LR |
3834 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
3835 | r = -EINVAL; | |
b2e1b302 | 3836 | goto bad_reg; |
d0e18f83 | 3837 | } |
b2e1b302 LR |
3838 | } |
3839 | ||
3840 | BUG_ON(rule_idx != num_rules); | |
3841 | ||
b2e1b302 | 3842 | r = set_regdom(rd); |
61405e97 | 3843 | |
a1794390 | 3844 | mutex_unlock(&cfg80211_mutex); |
d0e18f83 | 3845 | |
b2e1b302 LR |
3846 | return r; |
3847 | ||
d2372b31 | 3848 | bad_reg: |
61405e97 | 3849 | mutex_unlock(&cfg80211_mutex); |
b2e1b302 | 3850 | kfree(rd); |
d0e18f83 | 3851 | return r; |
b2e1b302 LR |
3852 | } |
3853 | ||
83f5e2cf JB |
3854 | static int validate_scan_freqs(struct nlattr *freqs) |
3855 | { | |
3856 | struct nlattr *attr1, *attr2; | |
3857 | int n_channels = 0, tmp1, tmp2; | |
3858 | ||
3859 | nla_for_each_nested(attr1, freqs, tmp1) { | |
3860 | n_channels++; | |
3861 | /* | |
3862 | * Some hardware has a limited channel list for | |
3863 | * scanning, and it is pretty much nonsensical | |
3864 | * to scan for a channel twice, so disallow that | |
3865 | * and don't require drivers to check that the | |
3866 | * channel list they get isn't longer than what | |
3867 | * they can scan, as long as they can scan all | |
3868 | * the channels they registered at once. | |
3869 | */ | |
3870 | nla_for_each_nested(attr2, freqs, tmp2) | |
3871 | if (attr1 != attr2 && | |
3872 | nla_get_u32(attr1) == nla_get_u32(attr2)) | |
3873 | return 0; | |
3874 | } | |
3875 | ||
3876 | return n_channels; | |
3877 | } | |
3878 | ||
2a519311 JB |
3879 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
3880 | { | |
4c476991 JB |
3881 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3882 | struct net_device *dev = info->user_ptr[1]; | |
2a519311 | 3883 | struct cfg80211_scan_request *request; |
2a519311 JB |
3884 | struct nlattr *attr; |
3885 | struct wiphy *wiphy; | |
83f5e2cf | 3886 | int err, tmp, n_ssids = 0, n_channels, i; |
70692ad2 | 3887 | size_t ie_len; |
2a519311 | 3888 | |
f4a11bb0 JB |
3889 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
3890 | return -EINVAL; | |
3891 | ||
79c97e97 | 3892 | wiphy = &rdev->wiphy; |
2a519311 | 3893 | |
4c476991 JB |
3894 | if (!rdev->ops->scan) |
3895 | return -EOPNOTSUPP; | |
2a519311 | 3896 | |
4c476991 JB |
3897 | if (rdev->scan_req) |
3898 | return -EBUSY; | |
2a519311 JB |
3899 | |
3900 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
83f5e2cf JB |
3901 | n_channels = validate_scan_freqs( |
3902 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
4c476991 JB |
3903 | if (!n_channels) |
3904 | return -EINVAL; | |
2a519311 | 3905 | } else { |
34850ab2 | 3906 | enum ieee80211_band band; |
83f5e2cf JB |
3907 | n_channels = 0; |
3908 | ||
2a519311 JB |
3909 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
3910 | if (wiphy->bands[band]) | |
3911 | n_channels += wiphy->bands[band]->n_channels; | |
3912 | } | |
3913 | ||
3914 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
3915 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) | |
3916 | n_ssids++; | |
3917 | ||
4c476991 JB |
3918 | if (n_ssids > wiphy->max_scan_ssids) |
3919 | return -EINVAL; | |
2a519311 | 3920 | |
70692ad2 JM |
3921 | if (info->attrs[NL80211_ATTR_IE]) |
3922 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
3923 | else | |
3924 | ie_len = 0; | |
3925 | ||
4c476991 JB |
3926 | if (ie_len > wiphy->max_scan_ie_len) |
3927 | return -EINVAL; | |
18a83659 | 3928 | |
2a519311 | 3929 | request = kzalloc(sizeof(*request) |
a2cd43c5 LC |
3930 | + sizeof(*request->ssids) * n_ssids |
3931 | + sizeof(*request->channels) * n_channels | |
70692ad2 | 3932 | + ie_len, GFP_KERNEL); |
4c476991 JB |
3933 | if (!request) |
3934 | return -ENOMEM; | |
2a519311 | 3935 | |
2a519311 | 3936 | if (n_ssids) |
5ba63533 | 3937 | request->ssids = (void *)&request->channels[n_channels]; |
2a519311 | 3938 | request->n_ssids = n_ssids; |
70692ad2 JM |
3939 | if (ie_len) { |
3940 | if (request->ssids) | |
3941 | request->ie = (void *)(request->ssids + n_ssids); | |
3942 | else | |
3943 | request->ie = (void *)(request->channels + n_channels); | |
3944 | } | |
2a519311 | 3945 | |
584991dc | 3946 | i = 0; |
2a519311 JB |
3947 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
3948 | /* user specified, bail out if channel not found */ | |
2a519311 | 3949 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
584991dc JB |
3950 | struct ieee80211_channel *chan; |
3951 | ||
3952 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
3953 | ||
3954 | if (!chan) { | |
2a519311 JB |
3955 | err = -EINVAL; |
3956 | goto out_free; | |
3957 | } | |
584991dc JB |
3958 | |
3959 | /* ignore disabled channels */ | |
3960 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
3961 | continue; | |
3962 | ||
3963 | request->channels[i] = chan; | |
2a519311 JB |
3964 | i++; |
3965 | } | |
3966 | } else { | |
34850ab2 JB |
3967 | enum ieee80211_band band; |
3968 | ||
2a519311 | 3969 | /* all channels */ |
2a519311 JB |
3970 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
3971 | int j; | |
3972 | if (!wiphy->bands[band]) | |
3973 | continue; | |
3974 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
584991dc JB |
3975 | struct ieee80211_channel *chan; |
3976 | ||
3977 | chan = &wiphy->bands[band]->channels[j]; | |
3978 | ||
3979 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
3980 | continue; | |
3981 | ||
3982 | request->channels[i] = chan; | |
2a519311 JB |
3983 | i++; |
3984 | } | |
3985 | } | |
3986 | } | |
3987 | ||
584991dc JB |
3988 | if (!i) { |
3989 | err = -EINVAL; | |
3990 | goto out_free; | |
3991 | } | |
3992 | ||
3993 | request->n_channels = i; | |
3994 | ||
2a519311 JB |
3995 | i = 0; |
3996 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
3997 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { | |
57a27e1d | 3998 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
2a519311 JB |
3999 | err = -EINVAL; |
4000 | goto out_free; | |
4001 | } | |
57a27e1d | 4002 | request->ssids[i].ssid_len = nla_len(attr); |
2a519311 | 4003 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
2a519311 JB |
4004 | i++; |
4005 | } | |
4006 | } | |
4007 | ||
70692ad2 JM |
4008 | if (info->attrs[NL80211_ATTR_IE]) { |
4009 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
de95a54b JB |
4010 | memcpy((void *)request->ie, |
4011 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
70692ad2 JM |
4012 | request->ie_len); |
4013 | } | |
4014 | ||
34850ab2 | 4015 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
a401d2bb JB |
4016 | if (wiphy->bands[i]) |
4017 | request->rates[i] = | |
4018 | (1 << wiphy->bands[i]->n_bitrates) - 1; | |
34850ab2 JB |
4019 | |
4020 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { | |
4021 | nla_for_each_nested(attr, | |
4022 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], | |
4023 | tmp) { | |
4024 | enum ieee80211_band band = nla_type(attr); | |
4025 | ||
84404623 | 4026 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
34850ab2 JB |
4027 | err = -EINVAL; |
4028 | goto out_free; | |
4029 | } | |
4030 | err = ieee80211_get_ratemask(wiphy->bands[band], | |
4031 | nla_data(attr), | |
4032 | nla_len(attr), | |
4033 | &request->rates[band]); | |
4034 | if (err) | |
4035 | goto out_free; | |
4036 | } | |
4037 | } | |
4038 | ||
e9f935e3 RM |
4039 | request->no_cck = |
4040 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); | |
4041 | ||
463d0183 | 4042 | request->dev = dev; |
79c97e97 | 4043 | request->wiphy = &rdev->wiphy; |
2a519311 | 4044 | |
79c97e97 JB |
4045 | rdev->scan_req = request; |
4046 | err = rdev->ops->scan(&rdev->wiphy, dev, request); | |
2a519311 | 4047 | |
463d0183 | 4048 | if (!err) { |
79c97e97 | 4049 | nl80211_send_scan_start(rdev, dev); |
463d0183 | 4050 | dev_hold(dev); |
4c476991 | 4051 | } else { |
2a519311 | 4052 | out_free: |
79c97e97 | 4053 | rdev->scan_req = NULL; |
2a519311 JB |
4054 | kfree(request); |
4055 | } | |
3b85875a | 4056 | |
2a519311 JB |
4057 | return err; |
4058 | } | |
4059 | ||
807f8a8c LC |
4060 | static int nl80211_start_sched_scan(struct sk_buff *skb, |
4061 | struct genl_info *info) | |
4062 | { | |
4063 | struct cfg80211_sched_scan_request *request; | |
4064 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
4065 | struct net_device *dev = info->user_ptr[1]; | |
807f8a8c LC |
4066 | struct nlattr *attr; |
4067 | struct wiphy *wiphy; | |
a1f1c21c | 4068 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i; |
bbe6ad6d | 4069 | u32 interval; |
807f8a8c LC |
4070 | enum ieee80211_band band; |
4071 | size_t ie_len; | |
a1f1c21c | 4072 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
807f8a8c LC |
4073 | |
4074 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
4075 | !rdev->ops->sched_scan_start) | |
4076 | return -EOPNOTSUPP; | |
4077 | ||
4078 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
4079 | return -EINVAL; | |
4080 | ||
bbe6ad6d LC |
4081 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
4082 | return -EINVAL; | |
4083 | ||
4084 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); | |
4085 | if (interval == 0) | |
4086 | return -EINVAL; | |
4087 | ||
807f8a8c LC |
4088 | wiphy = &rdev->wiphy; |
4089 | ||
4090 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
4091 | n_channels = validate_scan_freqs( | |
4092 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
4093 | if (!n_channels) | |
4094 | return -EINVAL; | |
4095 | } else { | |
4096 | n_channels = 0; | |
4097 | ||
4098 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) | |
4099 | if (wiphy->bands[band]) | |
4100 | n_channels += wiphy->bands[band]->n_channels; | |
4101 | } | |
4102 | ||
4103 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
4104 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], | |
4105 | tmp) | |
4106 | n_ssids++; | |
4107 | ||
93b6aa69 | 4108 | if (n_ssids > wiphy->max_sched_scan_ssids) |
807f8a8c LC |
4109 | return -EINVAL; |
4110 | ||
a1f1c21c LC |
4111 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) |
4112 | nla_for_each_nested(attr, | |
4113 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], | |
4114 | tmp) | |
4115 | n_match_sets++; | |
4116 | ||
4117 | if (n_match_sets > wiphy->max_match_sets) | |
4118 | return -EINVAL; | |
4119 | ||
807f8a8c LC |
4120 | if (info->attrs[NL80211_ATTR_IE]) |
4121 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
4122 | else | |
4123 | ie_len = 0; | |
4124 | ||
5a865bad | 4125 | if (ie_len > wiphy->max_sched_scan_ie_len) |
807f8a8c LC |
4126 | return -EINVAL; |
4127 | ||
c10841ca LC |
4128 | mutex_lock(&rdev->sched_scan_mtx); |
4129 | ||
4130 | if (rdev->sched_scan_req) { | |
4131 | err = -EINPROGRESS; | |
4132 | goto out; | |
4133 | } | |
4134 | ||
807f8a8c | 4135 | request = kzalloc(sizeof(*request) |
a2cd43c5 | 4136 | + sizeof(*request->ssids) * n_ssids |
a1f1c21c | 4137 | + sizeof(*request->match_sets) * n_match_sets |
a2cd43c5 | 4138 | + sizeof(*request->channels) * n_channels |
807f8a8c | 4139 | + ie_len, GFP_KERNEL); |
c10841ca LC |
4140 | if (!request) { |
4141 | err = -ENOMEM; | |
4142 | goto out; | |
4143 | } | |
807f8a8c LC |
4144 | |
4145 | if (n_ssids) | |
4146 | request->ssids = (void *)&request->channels[n_channels]; | |
4147 | request->n_ssids = n_ssids; | |
4148 | if (ie_len) { | |
4149 | if (request->ssids) | |
4150 | request->ie = (void *)(request->ssids + n_ssids); | |
4151 | else | |
4152 | request->ie = (void *)(request->channels + n_channels); | |
4153 | } | |
4154 | ||
a1f1c21c LC |
4155 | if (n_match_sets) { |
4156 | if (request->ie) | |
4157 | request->match_sets = (void *)(request->ie + ie_len); | |
4158 | else if (request->ssids) | |
4159 | request->match_sets = | |
4160 | (void *)(request->ssids + n_ssids); | |
4161 | else | |
4162 | request->match_sets = | |
4163 | (void *)(request->channels + n_channels); | |
4164 | } | |
4165 | request->n_match_sets = n_match_sets; | |
4166 | ||
807f8a8c LC |
4167 | i = 0; |
4168 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
4169 | /* user specified, bail out if channel not found */ | |
4170 | nla_for_each_nested(attr, | |
4171 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], | |
4172 | tmp) { | |
4173 | struct ieee80211_channel *chan; | |
4174 | ||
4175 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
4176 | ||
4177 | if (!chan) { | |
4178 | err = -EINVAL; | |
4179 | goto out_free; | |
4180 | } | |
4181 | ||
4182 | /* ignore disabled channels */ | |
4183 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
4184 | continue; | |
4185 | ||
4186 | request->channels[i] = chan; | |
4187 | i++; | |
4188 | } | |
4189 | } else { | |
4190 | /* all channels */ | |
4191 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
4192 | int j; | |
4193 | if (!wiphy->bands[band]) | |
4194 | continue; | |
4195 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
4196 | struct ieee80211_channel *chan; | |
4197 | ||
4198 | chan = &wiphy->bands[band]->channels[j]; | |
4199 | ||
4200 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
4201 | continue; | |
4202 | ||
4203 | request->channels[i] = chan; | |
4204 | i++; | |
4205 | } | |
4206 | } | |
4207 | } | |
4208 | ||
4209 | if (!i) { | |
4210 | err = -EINVAL; | |
4211 | goto out_free; | |
4212 | } | |
4213 | ||
4214 | request->n_channels = i; | |
4215 | ||
4216 | i = 0; | |
4217 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
4218 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], | |
4219 | tmp) { | |
57a27e1d | 4220 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
807f8a8c LC |
4221 | err = -EINVAL; |
4222 | goto out_free; | |
4223 | } | |
57a27e1d | 4224 | request->ssids[i].ssid_len = nla_len(attr); |
807f8a8c LC |
4225 | memcpy(request->ssids[i].ssid, nla_data(attr), |
4226 | nla_len(attr)); | |
807f8a8c LC |
4227 | i++; |
4228 | } | |
4229 | } | |
4230 | ||
a1f1c21c LC |
4231 | i = 0; |
4232 | if (info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { | |
4233 | nla_for_each_nested(attr, | |
4234 | info->attrs[NL80211_ATTR_SCHED_SCAN_MATCH], | |
4235 | tmp) { | |
4236 | struct nlattr *ssid; | |
4237 | ||
4238 | nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, | |
4239 | nla_data(attr), nla_len(attr), | |
4240 | nl80211_match_policy); | |
4241 | ssid = tb[NL80211_ATTR_SCHED_SCAN_MATCH_SSID]; | |
4242 | if (ssid) { | |
4243 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { | |
4244 | err = -EINVAL; | |
4245 | goto out_free; | |
4246 | } | |
4247 | memcpy(request->match_sets[i].ssid.ssid, | |
4248 | nla_data(ssid), nla_len(ssid)); | |
4249 | request->match_sets[i].ssid.ssid_len = | |
4250 | nla_len(ssid); | |
4251 | } | |
4252 | i++; | |
4253 | } | |
4254 | } | |
4255 | ||
807f8a8c LC |
4256 | if (info->attrs[NL80211_ATTR_IE]) { |
4257 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
4258 | memcpy((void *)request->ie, | |
4259 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
4260 | request->ie_len); | |
4261 | } | |
4262 | ||
4263 | request->dev = dev; | |
4264 | request->wiphy = &rdev->wiphy; | |
bbe6ad6d | 4265 | request->interval = interval; |
807f8a8c LC |
4266 | |
4267 | err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request); | |
4268 | if (!err) { | |
4269 | rdev->sched_scan_req = request; | |
4270 | nl80211_send_sched_scan(rdev, dev, | |
4271 | NL80211_CMD_START_SCHED_SCAN); | |
4272 | goto out; | |
4273 | } | |
4274 | ||
4275 | out_free: | |
4276 | kfree(request); | |
4277 | out: | |
c10841ca | 4278 | mutex_unlock(&rdev->sched_scan_mtx); |
807f8a8c LC |
4279 | return err; |
4280 | } | |
4281 | ||
4282 | static int nl80211_stop_sched_scan(struct sk_buff *skb, | |
4283 | struct genl_info *info) | |
4284 | { | |
4285 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
c10841ca | 4286 | int err; |
807f8a8c LC |
4287 | |
4288 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
4289 | !rdev->ops->sched_scan_stop) | |
4290 | return -EOPNOTSUPP; | |
4291 | ||
c10841ca LC |
4292 | mutex_lock(&rdev->sched_scan_mtx); |
4293 | err = __cfg80211_stop_sched_scan(rdev, false); | |
4294 | mutex_unlock(&rdev->sched_scan_mtx); | |
4295 | ||
4296 | return err; | |
807f8a8c LC |
4297 | } |
4298 | ||
9720bb3a JB |
4299 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
4300 | u32 seq, int flags, | |
2a519311 | 4301 | struct cfg80211_registered_device *rdev, |
48ab905d JB |
4302 | struct wireless_dev *wdev, |
4303 | struct cfg80211_internal_bss *intbss) | |
2a519311 | 4304 | { |
48ab905d | 4305 | struct cfg80211_bss *res = &intbss->pub; |
2a519311 JB |
4306 | void *hdr; |
4307 | struct nlattr *bss; | |
48ab905d JB |
4308 | |
4309 | ASSERT_WDEV_LOCK(wdev); | |
2a519311 | 4310 | |
9720bb3a | 4311 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).pid, seq, flags, |
2a519311 JB |
4312 | NL80211_CMD_NEW_SCAN_RESULTS); |
4313 | if (!hdr) | |
4314 | return -1; | |
4315 | ||
9720bb3a JB |
4316 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
4317 | ||
9360ffd1 DM |
4318 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation) || |
4319 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) | |
4320 | goto nla_put_failure; | |
2a519311 JB |
4321 | |
4322 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); | |
4323 | if (!bss) | |
4324 | goto nla_put_failure; | |
9360ffd1 DM |
4325 | if ((!is_zero_ether_addr(res->bssid) && |
4326 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)) || | |
4327 | (res->information_elements && res->len_information_elements && | |
4328 | nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, | |
4329 | res->len_information_elements, | |
4330 | res->information_elements)) || | |
4331 | (res->beacon_ies && res->len_beacon_ies && | |
4332 | res->beacon_ies != res->information_elements && | |
4333 | nla_put(msg, NL80211_BSS_BEACON_IES, | |
4334 | res->len_beacon_ies, res->beacon_ies))) | |
4335 | goto nla_put_failure; | |
4336 | if (res->tsf && | |
4337 | nla_put_u64(msg, NL80211_BSS_TSF, res->tsf)) | |
4338 | goto nla_put_failure; | |
4339 | if (res->beacon_interval && | |
4340 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) | |
4341 | goto nla_put_failure; | |
4342 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || | |
4343 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || | |
4344 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, | |
4345 | jiffies_to_msecs(jiffies - intbss->ts))) | |
4346 | goto nla_put_failure; | |
2a519311 | 4347 | |
77965c97 | 4348 | switch (rdev->wiphy.signal_type) { |
2a519311 | 4349 | case CFG80211_SIGNAL_TYPE_MBM: |
9360ffd1 DM |
4350 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
4351 | goto nla_put_failure; | |
2a519311 JB |
4352 | break; |
4353 | case CFG80211_SIGNAL_TYPE_UNSPEC: | |
9360ffd1 DM |
4354 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
4355 | goto nla_put_failure; | |
2a519311 JB |
4356 | break; |
4357 | default: | |
4358 | break; | |
4359 | } | |
4360 | ||
48ab905d | 4361 | switch (wdev->iftype) { |
074ac8df | 4362 | case NL80211_IFTYPE_P2P_CLIENT: |
48ab905d | 4363 | case NL80211_IFTYPE_STATION: |
9360ffd1 DM |
4364 | if (intbss == wdev->current_bss && |
4365 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
4366 | NL80211_BSS_STATUS_ASSOCIATED)) | |
4367 | goto nla_put_failure; | |
48ab905d JB |
4368 | break; |
4369 | case NL80211_IFTYPE_ADHOC: | |
9360ffd1 DM |
4370 | if (intbss == wdev->current_bss && |
4371 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
4372 | NL80211_BSS_STATUS_IBSS_JOINED)) | |
4373 | goto nla_put_failure; | |
48ab905d JB |
4374 | break; |
4375 | default: | |
4376 | break; | |
4377 | } | |
4378 | ||
2a519311 JB |
4379 | nla_nest_end(msg, bss); |
4380 | ||
4381 | return genlmsg_end(msg, hdr); | |
4382 | ||
4383 | nla_put_failure: | |
4384 | genlmsg_cancel(msg, hdr); | |
4385 | return -EMSGSIZE; | |
4386 | } | |
4387 | ||
4388 | static int nl80211_dump_scan(struct sk_buff *skb, | |
4389 | struct netlink_callback *cb) | |
4390 | { | |
48ab905d JB |
4391 | struct cfg80211_registered_device *rdev; |
4392 | struct net_device *dev; | |
2a519311 | 4393 | struct cfg80211_internal_bss *scan; |
48ab905d | 4394 | struct wireless_dev *wdev; |
2a519311 JB |
4395 | int start = cb->args[1], idx = 0; |
4396 | int err; | |
4397 | ||
67748893 JB |
4398 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
4399 | if (err) | |
4400 | return err; | |
2a519311 | 4401 | |
48ab905d | 4402 | wdev = dev->ieee80211_ptr; |
2a519311 | 4403 | |
48ab905d JB |
4404 | wdev_lock(wdev); |
4405 | spin_lock_bh(&rdev->bss_lock); | |
4406 | cfg80211_bss_expire(rdev); | |
4407 | ||
9720bb3a JB |
4408 | cb->seq = rdev->bss_generation; |
4409 | ||
48ab905d | 4410 | list_for_each_entry(scan, &rdev->bss_list, list) { |
2a519311 JB |
4411 | if (++idx <= start) |
4412 | continue; | |
9720bb3a | 4413 | if (nl80211_send_bss(skb, cb, |
2a519311 | 4414 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
48ab905d | 4415 | rdev, wdev, scan) < 0) { |
2a519311 | 4416 | idx--; |
67748893 | 4417 | break; |
2a519311 JB |
4418 | } |
4419 | } | |
4420 | ||
48ab905d JB |
4421 | spin_unlock_bh(&rdev->bss_lock); |
4422 | wdev_unlock(wdev); | |
2a519311 JB |
4423 | |
4424 | cb->args[1] = idx; | |
67748893 | 4425 | nl80211_finish_netdev_dump(rdev); |
2a519311 | 4426 | |
67748893 | 4427 | return skb->len; |
2a519311 JB |
4428 | } |
4429 | ||
61fa713c HS |
4430 | static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq, |
4431 | int flags, struct net_device *dev, | |
4432 | struct survey_info *survey) | |
4433 | { | |
4434 | void *hdr; | |
4435 | struct nlattr *infoattr; | |
4436 | ||
61fa713c HS |
4437 | hdr = nl80211hdr_put(msg, pid, seq, flags, |
4438 | NL80211_CMD_NEW_SURVEY_RESULTS); | |
4439 | if (!hdr) | |
4440 | return -ENOMEM; | |
4441 | ||
9360ffd1 DM |
4442 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
4443 | goto nla_put_failure; | |
61fa713c HS |
4444 | |
4445 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); | |
4446 | if (!infoattr) | |
4447 | goto nla_put_failure; | |
4448 | ||
9360ffd1 DM |
4449 | if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, |
4450 | survey->channel->center_freq)) | |
4451 | goto nla_put_failure; | |
4452 | ||
4453 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && | |
4454 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) | |
4455 | goto nla_put_failure; | |
4456 | if ((survey->filled & SURVEY_INFO_IN_USE) && | |
4457 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) | |
4458 | goto nla_put_failure; | |
4459 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) && | |
4460 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, | |
4461 | survey->channel_time)) | |
4462 | goto nla_put_failure; | |
4463 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) && | |
4464 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, | |
4465 | survey->channel_time_busy)) | |
4466 | goto nla_put_failure; | |
4467 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) && | |
4468 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, | |
4469 | survey->channel_time_ext_busy)) | |
4470 | goto nla_put_failure; | |
4471 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) && | |
4472 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, | |
4473 | survey->channel_time_rx)) | |
4474 | goto nla_put_failure; | |
4475 | if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) && | |
4476 | nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, | |
4477 | survey->channel_time_tx)) | |
4478 | goto nla_put_failure; | |
61fa713c HS |
4479 | |
4480 | nla_nest_end(msg, infoattr); | |
4481 | ||
4482 | return genlmsg_end(msg, hdr); | |
4483 | ||
4484 | nla_put_failure: | |
4485 | genlmsg_cancel(msg, hdr); | |
4486 | return -EMSGSIZE; | |
4487 | } | |
4488 | ||
4489 | static int nl80211_dump_survey(struct sk_buff *skb, | |
4490 | struct netlink_callback *cb) | |
4491 | { | |
4492 | struct survey_info survey; | |
4493 | struct cfg80211_registered_device *dev; | |
4494 | struct net_device *netdev; | |
61fa713c HS |
4495 | int survey_idx = cb->args[1]; |
4496 | int res; | |
4497 | ||
67748893 JB |
4498 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
4499 | if (res) | |
4500 | return res; | |
61fa713c HS |
4501 | |
4502 | if (!dev->ops->dump_survey) { | |
4503 | res = -EOPNOTSUPP; | |
4504 | goto out_err; | |
4505 | } | |
4506 | ||
4507 | while (1) { | |
180cdc79 LR |
4508 | struct ieee80211_channel *chan; |
4509 | ||
61fa713c HS |
4510 | res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx, |
4511 | &survey); | |
4512 | if (res == -ENOENT) | |
4513 | break; | |
4514 | if (res) | |
4515 | goto out_err; | |
4516 | ||
180cdc79 LR |
4517 | /* Survey without a channel doesn't make sense */ |
4518 | if (!survey.channel) { | |
4519 | res = -EINVAL; | |
4520 | goto out; | |
4521 | } | |
4522 | ||
4523 | chan = ieee80211_get_channel(&dev->wiphy, | |
4524 | survey.channel->center_freq); | |
4525 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) { | |
4526 | survey_idx++; | |
4527 | continue; | |
4528 | } | |
4529 | ||
61fa713c HS |
4530 | if (nl80211_send_survey(skb, |
4531 | NETLINK_CB(cb->skb).pid, | |
4532 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
4533 | netdev, | |
4534 | &survey) < 0) | |
4535 | goto out; | |
4536 | survey_idx++; | |
4537 | } | |
4538 | ||
4539 | out: | |
4540 | cb->args[1] = survey_idx; | |
4541 | res = skb->len; | |
4542 | out_err: | |
67748893 | 4543 | nl80211_finish_netdev_dump(dev); |
61fa713c HS |
4544 | return res; |
4545 | } | |
4546 | ||
255e737e JM |
4547 | static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type) |
4548 | { | |
b23aa676 SO |
4549 | return auth_type <= NL80211_AUTHTYPE_MAX; |
4550 | } | |
4551 | ||
4552 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) | |
4553 | { | |
4554 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | | |
4555 | NL80211_WPA_VERSION_2)); | |
4556 | } | |
4557 | ||
636a5d36 JM |
4558 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
4559 | { | |
4c476991 JB |
4560 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4561 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 JB |
4562 | struct ieee80211_channel *chan; |
4563 | const u8 *bssid, *ssid, *ie = NULL; | |
4564 | int err, ssid_len, ie_len = 0; | |
4565 | enum nl80211_auth_type auth_type; | |
fffd0934 | 4566 | struct key_parse key; |
d5cdfacb | 4567 | bool local_state_change; |
636a5d36 | 4568 | |
f4a11bb0 JB |
4569 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
4570 | return -EINVAL; | |
4571 | ||
4572 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4573 | return -EINVAL; | |
4574 | ||
1778092e JM |
4575 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
4576 | return -EINVAL; | |
4577 | ||
19957bb3 JB |
4578 | if (!info->attrs[NL80211_ATTR_SSID]) |
4579 | return -EINVAL; | |
4580 | ||
4581 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
4582 | return -EINVAL; | |
4583 | ||
fffd0934 JB |
4584 | err = nl80211_parse_key(info, &key); |
4585 | if (err) | |
4586 | return err; | |
4587 | ||
4588 | if (key.idx >= 0) { | |
e31b8213 JB |
4589 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
4590 | return -EINVAL; | |
fffd0934 JB |
4591 | if (!key.p.key || !key.p.key_len) |
4592 | return -EINVAL; | |
4593 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || | |
4594 | key.p.key_len != WLAN_KEY_LEN_WEP40) && | |
4595 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || | |
4596 | key.p.key_len != WLAN_KEY_LEN_WEP104)) | |
4597 | return -EINVAL; | |
4598 | if (key.idx > 4) | |
4599 | return -EINVAL; | |
4600 | } else { | |
4601 | key.p.key_len = 0; | |
4602 | key.p.key = NULL; | |
4603 | } | |
4604 | ||
afea0b7a JB |
4605 | if (key.idx >= 0) { |
4606 | int i; | |
4607 | bool ok = false; | |
4608 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { | |
4609 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { | |
4610 | ok = true; | |
4611 | break; | |
4612 | } | |
4613 | } | |
4c476991 JB |
4614 | if (!ok) |
4615 | return -EINVAL; | |
afea0b7a JB |
4616 | } |
4617 | ||
4c476991 JB |
4618 | if (!rdev->ops->auth) |
4619 | return -EOPNOTSUPP; | |
636a5d36 | 4620 | |
074ac8df | 4621 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
4622 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
4623 | return -EOPNOTSUPP; | |
eec60b03 | 4624 | |
19957bb3 | 4625 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
79c97e97 | 4626 | chan = ieee80211_get_channel(&rdev->wiphy, |
19957bb3 | 4627 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
4c476991 JB |
4628 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
4629 | return -EINVAL; | |
636a5d36 | 4630 | |
19957bb3 JB |
4631 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
4632 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
4633 | |
4634 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
4635 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
4636 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
4637 | } |
4638 | ||
19957bb3 | 4639 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
4c476991 JB |
4640 | if (!nl80211_valid_auth_type(auth_type)) |
4641 | return -EINVAL; | |
636a5d36 | 4642 | |
d5cdfacb JM |
4643 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
4644 | ||
95de817b JB |
4645 | /* |
4646 | * Since we no longer track auth state, ignore | |
4647 | * requests to only change local state. | |
4648 | */ | |
4649 | if (local_state_change) | |
4650 | return 0; | |
4651 | ||
4c476991 JB |
4652 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
4653 | ssid, ssid_len, ie, ie_len, | |
95de817b | 4654 | key.p.key, key.p.key_len, key.idx); |
636a5d36 JM |
4655 | } |
4656 | ||
c0692b8f JB |
4657 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
4658 | struct genl_info *info, | |
3dc27d25 JB |
4659 | struct cfg80211_crypto_settings *settings, |
4660 | int cipher_limit) | |
b23aa676 | 4661 | { |
c0b2bbd8 JB |
4662 | memset(settings, 0, sizeof(*settings)); |
4663 | ||
b23aa676 SO |
4664 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
4665 | ||
c0692b8f JB |
4666 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
4667 | u16 proto; | |
4668 | proto = nla_get_u16( | |
4669 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); | |
4670 | settings->control_port_ethertype = cpu_to_be16(proto); | |
4671 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | |
4672 | proto != ETH_P_PAE) | |
4673 | return -EINVAL; | |
4674 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) | |
4675 | settings->control_port_no_encrypt = true; | |
4676 | } else | |
4677 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); | |
4678 | ||
b23aa676 SO |
4679 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
4680 | void *data; | |
4681 | int len, i; | |
4682 | ||
4683 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
4684 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
4685 | settings->n_ciphers_pairwise = len / sizeof(u32); | |
4686 | ||
4687 | if (len % sizeof(u32)) | |
4688 | return -EINVAL; | |
4689 | ||
3dc27d25 | 4690 | if (settings->n_ciphers_pairwise > cipher_limit) |
b23aa676 SO |
4691 | return -EINVAL; |
4692 | ||
4693 | memcpy(settings->ciphers_pairwise, data, len); | |
4694 | ||
4695 | for (i = 0; i < settings->n_ciphers_pairwise; i++) | |
38ba3c57 JM |
4696 | if (!cfg80211_supported_cipher_suite( |
4697 | &rdev->wiphy, | |
b23aa676 SO |
4698 | settings->ciphers_pairwise[i])) |
4699 | return -EINVAL; | |
4700 | } | |
4701 | ||
4702 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { | |
4703 | settings->cipher_group = | |
4704 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); | |
38ba3c57 JM |
4705 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
4706 | settings->cipher_group)) | |
b23aa676 SO |
4707 | return -EINVAL; |
4708 | } | |
4709 | ||
4710 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { | |
4711 | settings->wpa_versions = | |
4712 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); | |
4713 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) | |
4714 | return -EINVAL; | |
4715 | } | |
4716 | ||
4717 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { | |
4718 | void *data; | |
6d30240e | 4719 | int len; |
b23aa676 SO |
4720 | |
4721 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
4722 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
4723 | settings->n_akm_suites = len / sizeof(u32); | |
4724 | ||
4725 | if (len % sizeof(u32)) | |
4726 | return -EINVAL; | |
4727 | ||
1b9ca027 JM |
4728 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
4729 | return -EINVAL; | |
4730 | ||
b23aa676 | 4731 | memcpy(settings->akm_suites, data, len); |
b23aa676 SO |
4732 | } |
4733 | ||
4734 | return 0; | |
4735 | } | |
4736 | ||
636a5d36 JM |
4737 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
4738 | { | |
4c476991 JB |
4739 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4740 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 4741 | struct cfg80211_crypto_settings crypto; |
f444de05 | 4742 | struct ieee80211_channel *chan; |
3e5d7649 | 4743 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
19957bb3 JB |
4744 | int err, ssid_len, ie_len = 0; |
4745 | bool use_mfp = false; | |
7e7c8926 BG |
4746 | u32 flags = 0; |
4747 | struct ieee80211_ht_cap *ht_capa = NULL; | |
4748 | struct ieee80211_ht_cap *ht_capa_mask = NULL; | |
636a5d36 | 4749 | |
f4a11bb0 JB |
4750 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
4751 | return -EINVAL; | |
4752 | ||
4753 | if (!info->attrs[NL80211_ATTR_MAC] || | |
19957bb3 JB |
4754 | !info->attrs[NL80211_ATTR_SSID] || |
4755 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
f4a11bb0 JB |
4756 | return -EINVAL; |
4757 | ||
4c476991 JB |
4758 | if (!rdev->ops->assoc) |
4759 | return -EOPNOTSUPP; | |
636a5d36 | 4760 | |
074ac8df | 4761 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
4762 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
4763 | return -EOPNOTSUPP; | |
eec60b03 | 4764 | |
19957bb3 | 4765 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 4766 | |
19957bb3 JB |
4767 | chan = ieee80211_get_channel(&rdev->wiphy, |
4768 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | |
4c476991 JB |
4769 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
4770 | return -EINVAL; | |
636a5d36 | 4771 | |
19957bb3 JB |
4772 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
4773 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
4774 | |
4775 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
4776 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
4777 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
4778 | } |
4779 | ||
dc6382ce | 4780 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
4f5dadce | 4781 | enum nl80211_mfp mfp = |
dc6382ce | 4782 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
4f5dadce | 4783 | if (mfp == NL80211_MFP_REQUIRED) |
19957bb3 | 4784 | use_mfp = true; |
4c476991 JB |
4785 | else if (mfp != NL80211_MFP_NO) |
4786 | return -EINVAL; | |
dc6382ce JM |
4787 | } |
4788 | ||
3e5d7649 JB |
4789 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
4790 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); | |
4791 | ||
7e7c8926 BG |
4792 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
4793 | flags |= ASSOC_REQ_DISABLE_HT; | |
4794 | ||
4795 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
4796 | ht_capa_mask = | |
4797 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]); | |
4798 | ||
4799 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
4800 | if (!ht_capa_mask) | |
4801 | return -EINVAL; | |
4802 | ht_capa = nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
4803 | } | |
4804 | ||
c0692b8f | 4805 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
b23aa676 | 4806 | if (!err) |
3e5d7649 JB |
4807 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
4808 | ssid, ssid_len, ie, ie_len, use_mfp, | |
7e7c8926 BG |
4809 | &crypto, flags, ht_capa, |
4810 | ht_capa_mask); | |
636a5d36 | 4811 | |
636a5d36 JM |
4812 | return err; |
4813 | } | |
4814 | ||
4815 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) | |
4816 | { | |
4c476991 JB |
4817 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4818 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 4819 | const u8 *ie = NULL, *bssid; |
4c476991 | 4820 | int ie_len = 0; |
19957bb3 | 4821 | u16 reason_code; |
d5cdfacb | 4822 | bool local_state_change; |
636a5d36 | 4823 | |
f4a11bb0 JB |
4824 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
4825 | return -EINVAL; | |
4826 | ||
4827 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4828 | return -EINVAL; | |
4829 | ||
4830 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
4831 | return -EINVAL; | |
4832 | ||
4c476991 JB |
4833 | if (!rdev->ops->deauth) |
4834 | return -EOPNOTSUPP; | |
636a5d36 | 4835 | |
074ac8df | 4836 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
4837 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
4838 | return -EOPNOTSUPP; | |
eec60b03 | 4839 | |
19957bb3 | 4840 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 4841 | |
19957bb3 JB |
4842 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
4843 | if (reason_code == 0) { | |
f4a11bb0 | 4844 | /* Reason Code 0 is reserved */ |
4c476991 | 4845 | return -EINVAL; |
255e737e | 4846 | } |
636a5d36 JM |
4847 | |
4848 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
4849 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
4850 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
4851 | } |
4852 | ||
d5cdfacb JM |
4853 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
4854 | ||
4c476991 JB |
4855 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
4856 | local_state_change); | |
636a5d36 JM |
4857 | } |
4858 | ||
4859 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) | |
4860 | { | |
4c476991 JB |
4861 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4862 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 4863 | const u8 *ie = NULL, *bssid; |
4c476991 | 4864 | int ie_len = 0; |
19957bb3 | 4865 | u16 reason_code; |
d5cdfacb | 4866 | bool local_state_change; |
636a5d36 | 4867 | |
f4a11bb0 JB |
4868 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
4869 | return -EINVAL; | |
4870 | ||
4871 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4872 | return -EINVAL; | |
4873 | ||
4874 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
4875 | return -EINVAL; | |
4876 | ||
4c476991 JB |
4877 | if (!rdev->ops->disassoc) |
4878 | return -EOPNOTSUPP; | |
636a5d36 | 4879 | |
074ac8df | 4880 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
4881 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
4882 | return -EOPNOTSUPP; | |
eec60b03 | 4883 | |
19957bb3 | 4884 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 4885 | |
19957bb3 JB |
4886 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
4887 | if (reason_code == 0) { | |
f4a11bb0 | 4888 | /* Reason Code 0 is reserved */ |
4c476991 | 4889 | return -EINVAL; |
255e737e | 4890 | } |
636a5d36 JM |
4891 | |
4892 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
4893 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
4894 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
4895 | } |
4896 | ||
d5cdfacb JM |
4897 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
4898 | ||
4c476991 JB |
4899 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
4900 | local_state_change); | |
636a5d36 JM |
4901 | } |
4902 | ||
dd5b4cc7 FF |
4903 | static bool |
4904 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, | |
4905 | int mcast_rate[IEEE80211_NUM_BANDS], | |
4906 | int rateval) | |
4907 | { | |
4908 | struct wiphy *wiphy = &rdev->wiphy; | |
4909 | bool found = false; | |
4910 | int band, i; | |
4911 | ||
4912 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
4913 | struct ieee80211_supported_band *sband; | |
4914 | ||
4915 | sband = wiphy->bands[band]; | |
4916 | if (!sband) | |
4917 | continue; | |
4918 | ||
4919 | for (i = 0; i < sband->n_bitrates; i++) { | |
4920 | if (sband->bitrates[i].bitrate == rateval) { | |
4921 | mcast_rate[band] = i + 1; | |
4922 | found = true; | |
4923 | break; | |
4924 | } | |
4925 | } | |
4926 | } | |
4927 | ||
4928 | return found; | |
4929 | } | |
4930 | ||
04a773ad JB |
4931 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
4932 | { | |
4c476991 JB |
4933 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4934 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad JB |
4935 | struct cfg80211_ibss_params ibss; |
4936 | struct wiphy *wiphy; | |
fffd0934 | 4937 | struct cfg80211_cached_keys *connkeys = NULL; |
04a773ad JB |
4938 | int err; |
4939 | ||
8e30bc55 JB |
4940 | memset(&ibss, 0, sizeof(ibss)); |
4941 | ||
04a773ad JB |
4942 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
4943 | return -EINVAL; | |
4944 | ||
4945 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
4946 | !info->attrs[NL80211_ATTR_SSID] || | |
4947 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
4948 | return -EINVAL; | |
4949 | ||
8e30bc55 JB |
4950 | ibss.beacon_interval = 100; |
4951 | ||
4952 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { | |
4953 | ibss.beacon_interval = | |
4954 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
4955 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) | |
4956 | return -EINVAL; | |
4957 | } | |
4958 | ||
4c476991 JB |
4959 | if (!rdev->ops->join_ibss) |
4960 | return -EOPNOTSUPP; | |
04a773ad | 4961 | |
4c476991 JB |
4962 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
4963 | return -EOPNOTSUPP; | |
04a773ad | 4964 | |
79c97e97 | 4965 | wiphy = &rdev->wiphy; |
04a773ad | 4966 | |
39193498 | 4967 | if (info->attrs[NL80211_ATTR_MAC]) { |
04a773ad | 4968 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
39193498 JB |
4969 | |
4970 | if (!is_valid_ether_addr(ibss.bssid)) | |
4971 | return -EINVAL; | |
4972 | } | |
04a773ad JB |
4973 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
4974 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
4975 | ||
4976 | if (info->attrs[NL80211_ATTR_IE]) { | |
4977 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
4978 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
4979 | } | |
4980 | ||
54858ee5 AS |
4981 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
4982 | enum nl80211_channel_type channel_type; | |
4983 | ||
cd6c6598 | 4984 | if (!nl80211_valid_channel_type(info, &channel_type)) |
54858ee5 AS |
4985 | return -EINVAL; |
4986 | ||
4987 | if (channel_type != NL80211_CHAN_NO_HT && | |
4988 | !(wiphy->features & NL80211_FEATURE_HT_IBSS)) | |
4989 | return -EINVAL; | |
4990 | ||
4991 | ibss.channel_type = channel_type; | |
4992 | } else { | |
4993 | ibss.channel_type = NL80211_CHAN_NO_HT; | |
4994 | } | |
4995 | ||
4996 | ibss.channel = rdev_freq_to_chan(rdev, | |
4997 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]), | |
4998 | ibss.channel_type); | |
04a773ad JB |
4999 | if (!ibss.channel || |
5000 | ibss.channel->flags & IEEE80211_CHAN_NO_IBSS || | |
4c476991 JB |
5001 | ibss.channel->flags & IEEE80211_CHAN_DISABLED) |
5002 | return -EINVAL; | |
04a773ad | 5003 | |
54858ee5 AS |
5004 | /* Both channels should be able to initiate communication */ |
5005 | if ((ibss.channel_type == NL80211_CHAN_HT40PLUS || | |
5006 | ibss.channel_type == NL80211_CHAN_HT40MINUS) && | |
5007 | !cfg80211_can_beacon_sec_chan(&rdev->wiphy, ibss.channel, | |
5008 | ibss.channel_type)) | |
5009 | return -EINVAL; | |
5010 | ||
04a773ad | 5011 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
fffd0934 JB |
5012 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
5013 | ||
fbd2c8dc TP |
5014 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
5015 | u8 *rates = | |
5016 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
5017 | int n_rates = | |
5018 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
5019 | struct ieee80211_supported_band *sband = | |
5020 | wiphy->bands[ibss.channel->band]; | |
fbd2c8dc | 5021 | |
34850ab2 JB |
5022 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
5023 | &ibss.basic_rates); | |
5024 | if (err) | |
5025 | return err; | |
fbd2c8dc | 5026 | } |
dd5b4cc7 FF |
5027 | |
5028 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && | |
5029 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, | |
5030 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
5031 | return -EINVAL; | |
fbd2c8dc | 5032 | |
4c476991 JB |
5033 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
5034 | connkeys = nl80211_parse_connkeys(rdev, | |
5035 | info->attrs[NL80211_ATTR_KEYS]); | |
5036 | if (IS_ERR(connkeys)) | |
5037 | return PTR_ERR(connkeys); | |
5038 | } | |
04a773ad | 5039 | |
267335d6 AQ |
5040 | ibss.control_port = |
5041 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); | |
5042 | ||
4c476991 | 5043 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
fffd0934 JB |
5044 | if (err) |
5045 | kfree(connkeys); | |
04a773ad JB |
5046 | return err; |
5047 | } | |
5048 | ||
5049 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) | |
5050 | { | |
4c476991 JB |
5051 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5052 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad | 5053 | |
4c476991 JB |
5054 | if (!rdev->ops->leave_ibss) |
5055 | return -EOPNOTSUPP; | |
04a773ad | 5056 | |
4c476991 JB |
5057 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
5058 | return -EOPNOTSUPP; | |
04a773ad | 5059 | |
4c476991 | 5060 | return cfg80211_leave_ibss(rdev, dev, false); |
04a773ad JB |
5061 | } |
5062 | ||
aff89a9b JB |
5063 | #ifdef CONFIG_NL80211_TESTMODE |
5064 | static struct genl_multicast_group nl80211_testmode_mcgrp = { | |
5065 | .name = "testmode", | |
5066 | }; | |
5067 | ||
5068 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) | |
5069 | { | |
4c476991 | 5070 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
aff89a9b JB |
5071 | int err; |
5072 | ||
5073 | if (!info->attrs[NL80211_ATTR_TESTDATA]) | |
5074 | return -EINVAL; | |
5075 | ||
aff89a9b JB |
5076 | err = -EOPNOTSUPP; |
5077 | if (rdev->ops->testmode_cmd) { | |
5078 | rdev->testmode_info = info; | |
5079 | err = rdev->ops->testmode_cmd(&rdev->wiphy, | |
5080 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), | |
5081 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); | |
5082 | rdev->testmode_info = NULL; | |
5083 | } | |
5084 | ||
aff89a9b JB |
5085 | return err; |
5086 | } | |
5087 | ||
71063f0e WYG |
5088 | static int nl80211_testmode_dump(struct sk_buff *skb, |
5089 | struct netlink_callback *cb) | |
5090 | { | |
00918d33 | 5091 | struct cfg80211_registered_device *rdev; |
71063f0e WYG |
5092 | int err; |
5093 | long phy_idx; | |
5094 | void *data = NULL; | |
5095 | int data_len = 0; | |
5096 | ||
5097 | if (cb->args[0]) { | |
5098 | /* | |
5099 | * 0 is a valid index, but not valid for args[0], | |
5100 | * so we need to offset by 1. | |
5101 | */ | |
5102 | phy_idx = cb->args[0] - 1; | |
5103 | } else { | |
5104 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
5105 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
5106 | nl80211_policy); | |
5107 | if (err) | |
5108 | return err; | |
00918d33 JB |
5109 | if (nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]) { |
5110 | phy_idx = nla_get_u32( | |
5111 | nl80211_fam.attrbuf[NL80211_ATTR_WIPHY]); | |
5112 | } else { | |
5113 | struct net_device *netdev; | |
5114 | ||
5115 | err = get_rdev_dev_by_ifindex(sock_net(skb->sk), | |
5116 | nl80211_fam.attrbuf, | |
5117 | &rdev, &netdev); | |
5118 | if (err) | |
5119 | return err; | |
5120 | dev_put(netdev); | |
5121 | phy_idx = rdev->wiphy_idx; | |
5122 | cfg80211_unlock_rdev(rdev); | |
5123 | } | |
71063f0e WYG |
5124 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
5125 | cb->args[1] = | |
5126 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; | |
5127 | } | |
5128 | ||
5129 | if (cb->args[1]) { | |
5130 | data = nla_data((void *)cb->args[1]); | |
5131 | data_len = nla_len((void *)cb->args[1]); | |
5132 | } | |
5133 | ||
5134 | mutex_lock(&cfg80211_mutex); | |
00918d33 JB |
5135 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
5136 | if (!rdev) { | |
71063f0e WYG |
5137 | mutex_unlock(&cfg80211_mutex); |
5138 | return -ENOENT; | |
5139 | } | |
00918d33 | 5140 | cfg80211_lock_rdev(rdev); |
71063f0e WYG |
5141 | mutex_unlock(&cfg80211_mutex); |
5142 | ||
00918d33 | 5143 | if (!rdev->ops->testmode_dump) { |
71063f0e WYG |
5144 | err = -EOPNOTSUPP; |
5145 | goto out_err; | |
5146 | } | |
5147 | ||
5148 | while (1) { | |
5149 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).pid, | |
5150 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
5151 | NL80211_CMD_TESTMODE); | |
5152 | struct nlattr *tmdata; | |
5153 | ||
9360ffd1 | 5154 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
71063f0e WYG |
5155 | genlmsg_cancel(skb, hdr); |
5156 | break; | |
5157 | } | |
5158 | ||
5159 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); | |
5160 | if (!tmdata) { | |
5161 | genlmsg_cancel(skb, hdr); | |
5162 | break; | |
5163 | } | |
00918d33 JB |
5164 | err = rdev->ops->testmode_dump(&rdev->wiphy, skb, cb, |
5165 | data, data_len); | |
71063f0e WYG |
5166 | nla_nest_end(skb, tmdata); |
5167 | ||
5168 | if (err == -ENOBUFS || err == -ENOENT) { | |
5169 | genlmsg_cancel(skb, hdr); | |
5170 | break; | |
5171 | } else if (err) { | |
5172 | genlmsg_cancel(skb, hdr); | |
5173 | goto out_err; | |
5174 | } | |
5175 | ||
5176 | genlmsg_end(skb, hdr); | |
5177 | } | |
5178 | ||
5179 | err = skb->len; | |
5180 | /* see above */ | |
5181 | cb->args[0] = phy_idx + 1; | |
5182 | out_err: | |
00918d33 | 5183 | cfg80211_unlock_rdev(rdev); |
71063f0e WYG |
5184 | return err; |
5185 | } | |
5186 | ||
aff89a9b JB |
5187 | static struct sk_buff * |
5188 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, | |
5189 | int approxlen, u32 pid, u32 seq, gfp_t gfp) | |
5190 | { | |
5191 | struct sk_buff *skb; | |
5192 | void *hdr; | |
5193 | struct nlattr *data; | |
5194 | ||
5195 | skb = nlmsg_new(approxlen + 100, gfp); | |
5196 | if (!skb) | |
5197 | return NULL; | |
5198 | ||
5199 | hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE); | |
5200 | if (!hdr) { | |
5201 | kfree_skb(skb); | |
5202 | return NULL; | |
5203 | } | |
5204 | ||
9360ffd1 DM |
5205 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) |
5206 | goto nla_put_failure; | |
aff89a9b JB |
5207 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
5208 | ||
5209 | ((void **)skb->cb)[0] = rdev; | |
5210 | ((void **)skb->cb)[1] = hdr; | |
5211 | ((void **)skb->cb)[2] = data; | |
5212 | ||
5213 | return skb; | |
5214 | ||
5215 | nla_put_failure: | |
5216 | kfree_skb(skb); | |
5217 | return NULL; | |
5218 | } | |
5219 | ||
5220 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, | |
5221 | int approxlen) | |
5222 | { | |
5223 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
5224 | ||
5225 | if (WARN_ON(!rdev->testmode_info)) | |
5226 | return NULL; | |
5227 | ||
5228 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, | |
5229 | rdev->testmode_info->snd_pid, | |
5230 | rdev->testmode_info->snd_seq, | |
5231 | GFP_KERNEL); | |
5232 | } | |
5233 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); | |
5234 | ||
5235 | int cfg80211_testmode_reply(struct sk_buff *skb) | |
5236 | { | |
5237 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
5238 | void *hdr = ((void **)skb->cb)[1]; | |
5239 | struct nlattr *data = ((void **)skb->cb)[2]; | |
5240 | ||
5241 | if (WARN_ON(!rdev->testmode_info)) { | |
5242 | kfree_skb(skb); | |
5243 | return -EINVAL; | |
5244 | } | |
5245 | ||
5246 | nla_nest_end(skb, data); | |
5247 | genlmsg_end(skb, hdr); | |
5248 | return genlmsg_reply(skb, rdev->testmode_info); | |
5249 | } | |
5250 | EXPORT_SYMBOL(cfg80211_testmode_reply); | |
5251 | ||
5252 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, | |
5253 | int approxlen, gfp_t gfp) | |
5254 | { | |
5255 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
5256 | ||
5257 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); | |
5258 | } | |
5259 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); | |
5260 | ||
5261 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) | |
5262 | { | |
5263 | void *hdr = ((void **)skb->cb)[1]; | |
5264 | struct nlattr *data = ((void **)skb->cb)[2]; | |
5265 | ||
5266 | nla_nest_end(skb, data); | |
5267 | genlmsg_end(skb, hdr); | |
5268 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); | |
5269 | } | |
5270 | EXPORT_SYMBOL(cfg80211_testmode_event); | |
5271 | #endif | |
5272 | ||
b23aa676 SO |
5273 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
5274 | { | |
4c476991 JB |
5275 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5276 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
5277 | struct cfg80211_connect_params connect; |
5278 | struct wiphy *wiphy; | |
fffd0934 | 5279 | struct cfg80211_cached_keys *connkeys = NULL; |
b23aa676 SO |
5280 | int err; |
5281 | ||
5282 | memset(&connect, 0, sizeof(connect)); | |
5283 | ||
5284 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
5285 | return -EINVAL; | |
5286 | ||
5287 | if (!info->attrs[NL80211_ATTR_SSID] || | |
5288 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
5289 | return -EINVAL; | |
5290 | ||
5291 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
5292 | connect.auth_type = | |
5293 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
5294 | if (!nl80211_valid_auth_type(connect.auth_type)) | |
5295 | return -EINVAL; | |
5296 | } else | |
5297 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
5298 | ||
5299 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; | |
5300 | ||
c0692b8f | 5301 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
3dc27d25 | 5302 | NL80211_MAX_NR_CIPHER_SUITES); |
b23aa676 SO |
5303 | if (err) |
5304 | return err; | |
b23aa676 | 5305 | |
074ac8df | 5306 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
5307 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
5308 | return -EOPNOTSUPP; | |
b23aa676 | 5309 | |
79c97e97 | 5310 | wiphy = &rdev->wiphy; |
b23aa676 | 5311 | |
4486ea98 BS |
5312 | connect.bg_scan_period = -1; |
5313 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && | |
5314 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { | |
5315 | connect.bg_scan_period = | |
5316 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); | |
5317 | } | |
5318 | ||
b23aa676 SO |
5319 | if (info->attrs[NL80211_ATTR_MAC]) |
5320 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
5321 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
5322 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
5323 | ||
5324 | if (info->attrs[NL80211_ATTR_IE]) { | |
5325 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
5326 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5327 | } | |
5328 | ||
5329 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | |
5330 | connect.channel = | |
5331 | ieee80211_get_channel(wiphy, | |
5332 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | |
5333 | if (!connect.channel || | |
4c476991 JB |
5334 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
5335 | return -EINVAL; | |
b23aa676 SO |
5336 | } |
5337 | ||
fffd0934 JB |
5338 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
5339 | connkeys = nl80211_parse_connkeys(rdev, | |
5340 | info->attrs[NL80211_ATTR_KEYS]); | |
4c476991 JB |
5341 | if (IS_ERR(connkeys)) |
5342 | return PTR_ERR(connkeys); | |
fffd0934 JB |
5343 | } |
5344 | ||
7e7c8926 BG |
5345 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
5346 | connect.flags |= ASSOC_REQ_DISABLE_HT; | |
5347 | ||
5348 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
5349 | memcpy(&connect.ht_capa_mask, | |
5350 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
5351 | sizeof(connect.ht_capa_mask)); | |
5352 | ||
5353 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
5354 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
5355 | return -EINVAL; | |
5356 | memcpy(&connect.ht_capa, | |
5357 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
5358 | sizeof(connect.ht_capa)); | |
5359 | } | |
5360 | ||
fffd0934 | 5361 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
fffd0934 JB |
5362 | if (err) |
5363 | kfree(connkeys); | |
b23aa676 SO |
5364 | return err; |
5365 | } | |
5366 | ||
5367 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) | |
5368 | { | |
4c476991 JB |
5369 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5370 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
5371 | u16 reason; |
5372 | ||
5373 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
5374 | reason = WLAN_REASON_DEAUTH_LEAVING; | |
5375 | else | |
5376 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
5377 | ||
5378 | if (reason == 0) | |
5379 | return -EINVAL; | |
5380 | ||
074ac8df | 5381 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
5382 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
5383 | return -EOPNOTSUPP; | |
b23aa676 | 5384 | |
4c476991 | 5385 | return cfg80211_disconnect(rdev, dev, reason, true); |
b23aa676 SO |
5386 | } |
5387 | ||
463d0183 JB |
5388 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
5389 | { | |
4c476991 | 5390 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
463d0183 JB |
5391 | struct net *net; |
5392 | int err; | |
5393 | u32 pid; | |
5394 | ||
5395 | if (!info->attrs[NL80211_ATTR_PID]) | |
5396 | return -EINVAL; | |
5397 | ||
5398 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); | |
5399 | ||
463d0183 | 5400 | net = get_net_ns_by_pid(pid); |
4c476991 JB |
5401 | if (IS_ERR(net)) |
5402 | return PTR_ERR(net); | |
463d0183 JB |
5403 | |
5404 | err = 0; | |
5405 | ||
5406 | /* check if anything to do */ | |
4c476991 JB |
5407 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
5408 | err = cfg80211_switch_netns(rdev, net); | |
463d0183 | 5409 | |
463d0183 | 5410 | put_net(net); |
463d0183 JB |
5411 | return err; |
5412 | } | |
5413 | ||
67fbb16b SO |
5414 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
5415 | { | |
4c476991 | 5416 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
67fbb16b SO |
5417 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
5418 | struct cfg80211_pmksa *pmksa) = NULL; | |
4c476991 | 5419 | struct net_device *dev = info->user_ptr[1]; |
67fbb16b SO |
5420 | struct cfg80211_pmksa pmksa; |
5421 | ||
5422 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); | |
5423 | ||
5424 | if (!info->attrs[NL80211_ATTR_MAC]) | |
5425 | return -EINVAL; | |
5426 | ||
5427 | if (!info->attrs[NL80211_ATTR_PMKID]) | |
5428 | return -EINVAL; | |
5429 | ||
67fbb16b SO |
5430 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
5431 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
5432 | ||
074ac8df | 5433 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
5434 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
5435 | return -EOPNOTSUPP; | |
67fbb16b SO |
5436 | |
5437 | switch (info->genlhdr->cmd) { | |
5438 | case NL80211_CMD_SET_PMKSA: | |
5439 | rdev_ops = rdev->ops->set_pmksa; | |
5440 | break; | |
5441 | case NL80211_CMD_DEL_PMKSA: | |
5442 | rdev_ops = rdev->ops->del_pmksa; | |
5443 | break; | |
5444 | default: | |
5445 | WARN_ON(1); | |
5446 | break; | |
5447 | } | |
5448 | ||
4c476991 JB |
5449 | if (!rdev_ops) |
5450 | return -EOPNOTSUPP; | |
67fbb16b | 5451 | |
4c476991 | 5452 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
67fbb16b SO |
5453 | } |
5454 | ||
5455 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) | |
5456 | { | |
4c476991 JB |
5457 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5458 | struct net_device *dev = info->user_ptr[1]; | |
67fbb16b | 5459 | |
074ac8df | 5460 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
5461 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
5462 | return -EOPNOTSUPP; | |
67fbb16b | 5463 | |
4c476991 JB |
5464 | if (!rdev->ops->flush_pmksa) |
5465 | return -EOPNOTSUPP; | |
67fbb16b | 5466 | |
4c476991 | 5467 | return rdev->ops->flush_pmksa(&rdev->wiphy, dev); |
67fbb16b SO |
5468 | } |
5469 | ||
109086ce AN |
5470 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
5471 | { | |
5472 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5473 | struct net_device *dev = info->user_ptr[1]; | |
5474 | u8 action_code, dialog_token; | |
5475 | u16 status_code; | |
5476 | u8 *peer; | |
5477 | ||
5478 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
5479 | !rdev->ops->tdls_mgmt) | |
5480 | return -EOPNOTSUPP; | |
5481 | ||
5482 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || | |
5483 | !info->attrs[NL80211_ATTR_STATUS_CODE] || | |
5484 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || | |
5485 | !info->attrs[NL80211_ATTR_IE] || | |
5486 | !info->attrs[NL80211_ATTR_MAC]) | |
5487 | return -EINVAL; | |
5488 | ||
5489 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
5490 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); | |
5491 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); | |
5492 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); | |
5493 | ||
5494 | return rdev->ops->tdls_mgmt(&rdev->wiphy, dev, peer, action_code, | |
5495 | dialog_token, status_code, | |
5496 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
5497 | nla_len(info->attrs[NL80211_ATTR_IE])); | |
5498 | } | |
5499 | ||
5500 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) | |
5501 | { | |
5502 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5503 | struct net_device *dev = info->user_ptr[1]; | |
5504 | enum nl80211_tdls_operation operation; | |
5505 | u8 *peer; | |
5506 | ||
5507 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
5508 | !rdev->ops->tdls_oper) | |
5509 | return -EOPNOTSUPP; | |
5510 | ||
5511 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || | |
5512 | !info->attrs[NL80211_ATTR_MAC]) | |
5513 | return -EINVAL; | |
5514 | ||
5515 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); | |
5516 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
5517 | ||
5518 | return rdev->ops->tdls_oper(&rdev->wiphy, dev, peer, operation); | |
5519 | } | |
5520 | ||
9588bbd5 JM |
5521 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
5522 | struct genl_info *info) | |
5523 | { | |
4c476991 JB |
5524 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5525 | struct net_device *dev = info->user_ptr[1]; | |
9588bbd5 JM |
5526 | struct ieee80211_channel *chan; |
5527 | struct sk_buff *msg; | |
5528 | void *hdr; | |
5529 | u64 cookie; | |
5530 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; | |
5531 | u32 freq, duration; | |
5532 | int err; | |
5533 | ||
5534 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
5535 | !info->attrs[NL80211_ATTR_DURATION]) | |
5536 | return -EINVAL; | |
5537 | ||
5538 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
5539 | ||
5540 | /* | |
5541 | * We should be on that channel for at least one jiffie, | |
5542 | * and more than 5 seconds seems excessive. | |
5543 | */ | |
a293911d JB |
5544 | if (!duration || !msecs_to_jiffies(duration) || |
5545 | duration > rdev->wiphy.max_remain_on_channel_duration) | |
9588bbd5 JM |
5546 | return -EINVAL; |
5547 | ||
7c4ef712 JB |
5548 | if (!rdev->ops->remain_on_channel || |
5549 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) | |
4c476991 | 5550 | return -EOPNOTSUPP; |
9588bbd5 | 5551 | |
cd6c6598 JB |
5552 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE] && |
5553 | !nl80211_valid_channel_type(info, &channel_type)) | |
5554 | return -EINVAL; | |
9588bbd5 JM |
5555 | |
5556 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
5557 | chan = rdev_freq_to_chan(rdev, freq, channel_type); | |
4c476991 JB |
5558 | if (chan == NULL) |
5559 | return -EINVAL; | |
9588bbd5 JM |
5560 | |
5561 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
5562 | if (!msg) |
5563 | return -ENOMEM; | |
9588bbd5 JM |
5564 | |
5565 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | |
5566 | NL80211_CMD_REMAIN_ON_CHANNEL); | |
5567 | ||
5568 | if (IS_ERR(hdr)) { | |
5569 | err = PTR_ERR(hdr); | |
5570 | goto free_msg; | |
5571 | } | |
5572 | ||
5573 | err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan, | |
5574 | channel_type, duration, &cookie); | |
5575 | ||
5576 | if (err) | |
5577 | goto free_msg; | |
5578 | ||
9360ffd1 DM |
5579 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
5580 | goto nla_put_failure; | |
9588bbd5 JM |
5581 | |
5582 | genlmsg_end(msg, hdr); | |
4c476991 JB |
5583 | |
5584 | return genlmsg_reply(msg, info); | |
9588bbd5 JM |
5585 | |
5586 | nla_put_failure: | |
5587 | err = -ENOBUFS; | |
5588 | free_msg: | |
5589 | nlmsg_free(msg); | |
9588bbd5 JM |
5590 | return err; |
5591 | } | |
5592 | ||
5593 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, | |
5594 | struct genl_info *info) | |
5595 | { | |
4c476991 JB |
5596 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5597 | struct net_device *dev = info->user_ptr[1]; | |
9588bbd5 | 5598 | u64 cookie; |
9588bbd5 JM |
5599 | |
5600 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
5601 | return -EINVAL; | |
5602 | ||
4c476991 JB |
5603 | if (!rdev->ops->cancel_remain_on_channel) |
5604 | return -EOPNOTSUPP; | |
9588bbd5 | 5605 | |
9588bbd5 JM |
5606 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
5607 | ||
4c476991 | 5608 | return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie); |
9588bbd5 JM |
5609 | } |
5610 | ||
13ae75b1 JM |
5611 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
5612 | u8 *rates, u8 rates_len) | |
5613 | { | |
5614 | u8 i; | |
5615 | u32 mask = 0; | |
5616 | ||
5617 | for (i = 0; i < rates_len; i++) { | |
5618 | int rate = (rates[i] & 0x7f) * 5; | |
5619 | int ridx; | |
5620 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { | |
5621 | struct ieee80211_rate *srate = | |
5622 | &sband->bitrates[ridx]; | |
5623 | if (rate == srate->bitrate) { | |
5624 | mask |= 1 << ridx; | |
5625 | break; | |
5626 | } | |
5627 | } | |
5628 | if (ridx == sband->n_bitrates) | |
5629 | return 0; /* rate not found */ | |
5630 | } | |
5631 | ||
5632 | return mask; | |
5633 | } | |
5634 | ||
24db78c0 SW |
5635 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
5636 | u8 *rates, u8 rates_len, | |
5637 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) | |
5638 | { | |
5639 | u8 i; | |
5640 | ||
5641 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); | |
5642 | ||
5643 | for (i = 0; i < rates_len; i++) { | |
5644 | int ridx, rbit; | |
5645 | ||
5646 | ridx = rates[i] / 8; | |
5647 | rbit = BIT(rates[i] % 8); | |
5648 | ||
5649 | /* check validity */ | |
910570b5 | 5650 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
24db78c0 SW |
5651 | return false; |
5652 | ||
5653 | /* check availability */ | |
5654 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) | |
5655 | mcs[ridx] |= rbit; | |
5656 | else | |
5657 | return false; | |
5658 | } | |
5659 | ||
5660 | return true; | |
5661 | } | |
5662 | ||
b54452b0 | 5663 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
13ae75b1 JM |
5664 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
5665 | .len = NL80211_MAX_SUPP_RATES }, | |
24db78c0 SW |
5666 | [NL80211_TXRATE_MCS] = { .type = NLA_BINARY, |
5667 | .len = NL80211_MAX_SUPP_HT_RATES }, | |
13ae75b1 JM |
5668 | }; |
5669 | ||
5670 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, | |
5671 | struct genl_info *info) | |
5672 | { | |
5673 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; | |
4c476991 | 5674 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
13ae75b1 | 5675 | struct cfg80211_bitrate_mask mask; |
4c476991 JB |
5676 | int rem, i; |
5677 | struct net_device *dev = info->user_ptr[1]; | |
13ae75b1 JM |
5678 | struct nlattr *tx_rates; |
5679 | struct ieee80211_supported_band *sband; | |
5680 | ||
5681 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) | |
5682 | return -EINVAL; | |
5683 | ||
4c476991 JB |
5684 | if (!rdev->ops->set_bitrate_mask) |
5685 | return -EOPNOTSUPP; | |
13ae75b1 JM |
5686 | |
5687 | memset(&mask, 0, sizeof(mask)); | |
5688 | /* Default to all rates enabled */ | |
5689 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { | |
5690 | sband = rdev->wiphy.bands[i]; | |
5691 | mask.control[i].legacy = | |
5692 | sband ? (1 << sband->n_bitrates) - 1 : 0; | |
24db78c0 SW |
5693 | if (sband) |
5694 | memcpy(mask.control[i].mcs, | |
5695 | sband->ht_cap.mcs.rx_mask, | |
5696 | sizeof(mask.control[i].mcs)); | |
5697 | else | |
5698 | memset(mask.control[i].mcs, 0, | |
5699 | sizeof(mask.control[i].mcs)); | |
13ae75b1 JM |
5700 | } |
5701 | ||
5702 | /* | |
5703 | * The nested attribute uses enum nl80211_band as the index. This maps | |
5704 | * directly to the enum ieee80211_band values used in cfg80211. | |
5705 | */ | |
24db78c0 | 5706 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
13ae75b1 JM |
5707 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
5708 | { | |
5709 | enum ieee80211_band band = nla_type(tx_rates); | |
4c476991 JB |
5710 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
5711 | return -EINVAL; | |
13ae75b1 | 5712 | sband = rdev->wiphy.bands[band]; |
4c476991 JB |
5713 | if (sband == NULL) |
5714 | return -EINVAL; | |
13ae75b1 JM |
5715 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
5716 | nla_len(tx_rates), nl80211_txattr_policy); | |
5717 | if (tb[NL80211_TXRATE_LEGACY]) { | |
5718 | mask.control[band].legacy = rateset_to_mask( | |
5719 | sband, | |
5720 | nla_data(tb[NL80211_TXRATE_LEGACY]), | |
5721 | nla_len(tb[NL80211_TXRATE_LEGACY])); | |
218d2e26 BS |
5722 | if ((mask.control[band].legacy == 0) && |
5723 | nla_len(tb[NL80211_TXRATE_LEGACY])) | |
5724 | return -EINVAL; | |
24db78c0 SW |
5725 | } |
5726 | if (tb[NL80211_TXRATE_MCS]) { | |
5727 | if (!ht_rateset_to_mask( | |
5728 | sband, | |
5729 | nla_data(tb[NL80211_TXRATE_MCS]), | |
5730 | nla_len(tb[NL80211_TXRATE_MCS]), | |
5731 | mask.control[band].mcs)) | |
5732 | return -EINVAL; | |
5733 | } | |
5734 | ||
5735 | if (mask.control[band].legacy == 0) { | |
5736 | /* don't allow empty legacy rates if HT | |
5737 | * is not even supported. */ | |
5738 | if (!rdev->wiphy.bands[band]->ht_cap.ht_supported) | |
5739 | return -EINVAL; | |
5740 | ||
5741 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) | |
5742 | if (mask.control[band].mcs[i]) | |
5743 | break; | |
5744 | ||
5745 | /* legacy and mcs rates may not be both empty */ | |
5746 | if (i == IEEE80211_HT_MCS_MASK_LEN) | |
4c476991 | 5747 | return -EINVAL; |
13ae75b1 JM |
5748 | } |
5749 | } | |
5750 | ||
4c476991 | 5751 | return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask); |
13ae75b1 JM |
5752 | } |
5753 | ||
2e161f78 | 5754 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 5755 | { |
4c476991 JB |
5756 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5757 | struct net_device *dev = info->user_ptr[1]; | |
2e161f78 | 5758 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
026331c4 JM |
5759 | |
5760 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) | |
5761 | return -EINVAL; | |
5762 | ||
2e161f78 JB |
5763 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
5764 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); | |
026331c4 | 5765 | |
9d38d85d | 5766 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
074ac8df | 5767 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
663fcafd JB |
5768 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
5769 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
5770 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && | |
c7108a71 | 5771 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
4c476991 JB |
5772 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
5773 | return -EOPNOTSUPP; | |
026331c4 JM |
5774 | |
5775 | /* not much point in registering if we can't reply */ | |
4c476991 JB |
5776 | if (!rdev->ops->mgmt_tx) |
5777 | return -EOPNOTSUPP; | |
026331c4 | 5778 | |
4c476991 | 5779 | return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid, |
2e161f78 | 5780 | frame_type, |
026331c4 JM |
5781 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
5782 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); | |
026331c4 JM |
5783 | } |
5784 | ||
2e161f78 | 5785 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 5786 | { |
4c476991 JB |
5787 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5788 | struct net_device *dev = info->user_ptr[1]; | |
026331c4 JM |
5789 | struct ieee80211_channel *chan; |
5790 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; | |
252aa631 | 5791 | bool channel_type_valid = false; |
026331c4 JM |
5792 | u32 freq; |
5793 | int err; | |
d64d373f | 5794 | void *hdr = NULL; |
026331c4 | 5795 | u64 cookie; |
e247bd90 | 5796 | struct sk_buff *msg = NULL; |
f7ca38df | 5797 | unsigned int wait = 0; |
e247bd90 JB |
5798 | bool offchan, no_cck, dont_wait_for_ack; |
5799 | ||
5800 | dont_wait_for_ack = info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK]; | |
026331c4 JM |
5801 | |
5802 | if (!info->attrs[NL80211_ATTR_FRAME] || | |
5803 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
5804 | return -EINVAL; | |
5805 | ||
4c476991 JB |
5806 | if (!rdev->ops->mgmt_tx) |
5807 | return -EOPNOTSUPP; | |
026331c4 | 5808 | |
9d38d85d | 5809 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
074ac8df | 5810 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
663fcafd JB |
5811 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
5812 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
5813 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && | |
c7108a71 | 5814 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
4c476991 JB |
5815 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
5816 | return -EOPNOTSUPP; | |
026331c4 | 5817 | |
f7ca38df | 5818 | if (info->attrs[NL80211_ATTR_DURATION]) { |
7c4ef712 | 5819 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
f7ca38df JB |
5820 | return -EINVAL; |
5821 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
5822 | } | |
5823 | ||
026331c4 | 5824 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
cd6c6598 | 5825 | if (!nl80211_valid_channel_type(info, &channel_type)) |
4c476991 | 5826 | return -EINVAL; |
252aa631 | 5827 | channel_type_valid = true; |
026331c4 JM |
5828 | } |
5829 | ||
f7ca38df JB |
5830 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
5831 | ||
7c4ef712 JB |
5832 | if (offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
5833 | return -EINVAL; | |
5834 | ||
e9f935e3 RM |
5835 | no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
5836 | ||
026331c4 JM |
5837 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
5838 | chan = rdev_freq_to_chan(rdev, freq, channel_type); | |
4c476991 JB |
5839 | if (chan == NULL) |
5840 | return -EINVAL; | |
026331c4 | 5841 | |
e247bd90 JB |
5842 | if (!dont_wait_for_ack) { |
5843 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
5844 | if (!msg) | |
5845 | return -ENOMEM; | |
026331c4 | 5846 | |
e247bd90 JB |
5847 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
5848 | NL80211_CMD_FRAME); | |
026331c4 | 5849 | |
e247bd90 JB |
5850 | if (IS_ERR(hdr)) { |
5851 | err = PTR_ERR(hdr); | |
5852 | goto free_msg; | |
5853 | } | |
026331c4 | 5854 | } |
e247bd90 | 5855 | |
f7ca38df JB |
5856 | err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type, |
5857 | channel_type_valid, wait, | |
2e161f78 JB |
5858 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
5859 | nla_len(info->attrs[NL80211_ATTR_FRAME]), | |
e247bd90 | 5860 | no_cck, dont_wait_for_ack, &cookie); |
026331c4 JM |
5861 | if (err) |
5862 | goto free_msg; | |
5863 | ||
e247bd90 | 5864 | if (msg) { |
9360ffd1 DM |
5865 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
5866 | goto nla_put_failure; | |
026331c4 | 5867 | |
e247bd90 JB |
5868 | genlmsg_end(msg, hdr); |
5869 | return genlmsg_reply(msg, info); | |
5870 | } | |
5871 | ||
5872 | return 0; | |
026331c4 JM |
5873 | |
5874 | nla_put_failure: | |
5875 | err = -ENOBUFS; | |
5876 | free_msg: | |
5877 | nlmsg_free(msg); | |
026331c4 JM |
5878 | return err; |
5879 | } | |
5880 | ||
f7ca38df JB |
5881 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
5882 | { | |
5883 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5884 | struct net_device *dev = info->user_ptr[1]; | |
5885 | u64 cookie; | |
5886 | ||
5887 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
5888 | return -EINVAL; | |
5889 | ||
5890 | if (!rdev->ops->mgmt_tx_cancel_wait) | |
5891 | return -EOPNOTSUPP; | |
5892 | ||
5893 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && | |
5894 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && | |
5895 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && | |
5896 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
5897 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && | |
5898 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
5899 | return -EOPNOTSUPP; | |
5900 | ||
5901 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | |
5902 | ||
5903 | return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie); | |
5904 | } | |
5905 | ||
ffb9eb3d KV |
5906 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
5907 | { | |
4c476991 | 5908 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d | 5909 | struct wireless_dev *wdev; |
4c476991 | 5910 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
5911 | u8 ps_state; |
5912 | bool state; | |
5913 | int err; | |
5914 | ||
4c476991 JB |
5915 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
5916 | return -EINVAL; | |
ffb9eb3d KV |
5917 | |
5918 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); | |
5919 | ||
4c476991 JB |
5920 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
5921 | return -EINVAL; | |
ffb9eb3d KV |
5922 | |
5923 | wdev = dev->ieee80211_ptr; | |
5924 | ||
4c476991 JB |
5925 | if (!rdev->ops->set_power_mgmt) |
5926 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
5927 | |
5928 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; | |
5929 | ||
5930 | if (state == wdev->ps) | |
4c476991 | 5931 | return 0; |
ffb9eb3d | 5932 | |
4c476991 JB |
5933 | err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state, |
5934 | wdev->ps_timeout); | |
5935 | if (!err) | |
5936 | wdev->ps = state; | |
ffb9eb3d KV |
5937 | return err; |
5938 | } | |
5939 | ||
5940 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) | |
5941 | { | |
4c476991 | 5942 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d KV |
5943 | enum nl80211_ps_state ps_state; |
5944 | struct wireless_dev *wdev; | |
4c476991 | 5945 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
5946 | struct sk_buff *msg; |
5947 | void *hdr; | |
5948 | int err; | |
5949 | ||
ffb9eb3d KV |
5950 | wdev = dev->ieee80211_ptr; |
5951 | ||
4c476991 JB |
5952 | if (!rdev->ops->set_power_mgmt) |
5953 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
5954 | |
5955 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
5956 | if (!msg) |
5957 | return -ENOMEM; | |
ffb9eb3d KV |
5958 | |
5959 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | |
5960 | NL80211_CMD_GET_POWER_SAVE); | |
5961 | if (!hdr) { | |
4c476991 | 5962 | err = -ENOBUFS; |
ffb9eb3d KV |
5963 | goto free_msg; |
5964 | } | |
5965 | ||
5966 | if (wdev->ps) | |
5967 | ps_state = NL80211_PS_ENABLED; | |
5968 | else | |
5969 | ps_state = NL80211_PS_DISABLED; | |
5970 | ||
9360ffd1 DM |
5971 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
5972 | goto nla_put_failure; | |
ffb9eb3d KV |
5973 | |
5974 | genlmsg_end(msg, hdr); | |
4c476991 | 5975 | return genlmsg_reply(msg, info); |
ffb9eb3d | 5976 | |
4c476991 | 5977 | nla_put_failure: |
ffb9eb3d | 5978 | err = -ENOBUFS; |
4c476991 | 5979 | free_msg: |
ffb9eb3d | 5980 | nlmsg_free(msg); |
ffb9eb3d KV |
5981 | return err; |
5982 | } | |
5983 | ||
d6dc1a38 JO |
5984 | static struct nla_policy |
5985 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { | |
5986 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, | |
5987 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, | |
5988 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, | |
5989 | }; | |
5990 | ||
5991 | static int nl80211_set_cqm_rssi(struct genl_info *info, | |
5992 | s32 threshold, u32 hysteresis) | |
5993 | { | |
4c476991 | 5994 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
d6dc1a38 | 5995 | struct wireless_dev *wdev; |
4c476991 | 5996 | struct net_device *dev = info->user_ptr[1]; |
d6dc1a38 JO |
5997 | |
5998 | if (threshold > 0) | |
5999 | return -EINVAL; | |
6000 | ||
d6dc1a38 JO |
6001 | wdev = dev->ieee80211_ptr; |
6002 | ||
4c476991 JB |
6003 | if (!rdev->ops->set_cqm_rssi_config) |
6004 | return -EOPNOTSUPP; | |
d6dc1a38 | 6005 | |
074ac8df | 6006 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6007 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6008 | return -EOPNOTSUPP; | |
d6dc1a38 | 6009 | |
4c476991 JB |
6010 | return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev, |
6011 | threshold, hysteresis); | |
d6dc1a38 JO |
6012 | } |
6013 | ||
6014 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) | |
6015 | { | |
6016 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; | |
6017 | struct nlattr *cqm; | |
6018 | int err; | |
6019 | ||
6020 | cqm = info->attrs[NL80211_ATTR_CQM]; | |
6021 | if (!cqm) { | |
6022 | err = -EINVAL; | |
6023 | goto out; | |
6024 | } | |
6025 | ||
6026 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, | |
6027 | nl80211_attr_cqm_policy); | |
6028 | if (err) | |
6029 | goto out; | |
6030 | ||
6031 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && | |
6032 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { | |
6033 | s32 threshold; | |
6034 | u32 hysteresis; | |
6035 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); | |
6036 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); | |
6037 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); | |
6038 | } else | |
6039 | err = -EINVAL; | |
6040 | ||
6041 | out: | |
6042 | return err; | |
6043 | } | |
6044 | ||
29cbe68c JB |
6045 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
6046 | { | |
6047 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6048 | struct net_device *dev = info->user_ptr[1]; | |
6049 | struct mesh_config cfg; | |
c80d545d | 6050 | struct mesh_setup setup; |
29cbe68c JB |
6051 | int err; |
6052 | ||
6053 | /* start with default */ | |
6054 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); | |
c80d545d | 6055 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
29cbe68c | 6056 | |
24bdd9f4 | 6057 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
29cbe68c | 6058 | /* and parse parameters if given */ |
24bdd9f4 | 6059 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
29cbe68c JB |
6060 | if (err) |
6061 | return err; | |
6062 | } | |
6063 | ||
6064 | if (!info->attrs[NL80211_ATTR_MESH_ID] || | |
6065 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) | |
6066 | return -EINVAL; | |
6067 | ||
c80d545d JC |
6068 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
6069 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
6070 | ||
4bb62344 CYY |
6071 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
6072 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, | |
6073 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
6074 | return -EINVAL; | |
6075 | ||
c80d545d JC |
6076 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
6077 | /* parse additional setup parameters if given */ | |
6078 | err = nl80211_parse_mesh_setup(info, &setup); | |
6079 | if (err) | |
6080 | return err; | |
6081 | } | |
6082 | ||
6083 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); | |
29cbe68c JB |
6084 | } |
6085 | ||
6086 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) | |
6087 | { | |
6088 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6089 | struct net_device *dev = info->user_ptr[1]; | |
6090 | ||
6091 | return cfg80211_leave_mesh(rdev, dev); | |
6092 | } | |
6093 | ||
ff1b6e69 JB |
6094 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
6095 | { | |
6096 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6097 | struct sk_buff *msg; | |
6098 | void *hdr; | |
6099 | ||
6100 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) | |
6101 | return -EOPNOTSUPP; | |
6102 | ||
6103 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
6104 | if (!msg) | |
6105 | return -ENOMEM; | |
6106 | ||
6107 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | |
6108 | NL80211_CMD_GET_WOWLAN); | |
6109 | if (!hdr) | |
6110 | goto nla_put_failure; | |
6111 | ||
6112 | if (rdev->wowlan) { | |
6113 | struct nlattr *nl_wowlan; | |
6114 | ||
6115 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
6116 | if (!nl_wowlan) | |
6117 | goto nla_put_failure; | |
6118 | ||
9360ffd1 DM |
6119 | if ((rdev->wowlan->any && |
6120 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || | |
6121 | (rdev->wowlan->disconnect && | |
6122 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || | |
6123 | (rdev->wowlan->magic_pkt && | |
6124 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || | |
6125 | (rdev->wowlan->gtk_rekey_failure && | |
6126 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || | |
6127 | (rdev->wowlan->eap_identity_req && | |
6128 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || | |
6129 | (rdev->wowlan->four_way_handshake && | |
6130 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || | |
6131 | (rdev->wowlan->rfkill_release && | |
6132 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) | |
6133 | goto nla_put_failure; | |
ff1b6e69 JB |
6134 | if (rdev->wowlan->n_patterns) { |
6135 | struct nlattr *nl_pats, *nl_pat; | |
6136 | int i, pat_len; | |
6137 | ||
6138 | nl_pats = nla_nest_start(msg, | |
6139 | NL80211_WOWLAN_TRIG_PKT_PATTERN); | |
6140 | if (!nl_pats) | |
6141 | goto nla_put_failure; | |
6142 | ||
6143 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { | |
6144 | nl_pat = nla_nest_start(msg, i + 1); | |
6145 | if (!nl_pat) | |
6146 | goto nla_put_failure; | |
6147 | pat_len = rdev->wowlan->patterns[i].pattern_len; | |
9360ffd1 DM |
6148 | if (nla_put(msg, NL80211_WOWLAN_PKTPAT_MASK, |
6149 | DIV_ROUND_UP(pat_len, 8), | |
6150 | rdev->wowlan->patterns[i].mask) || | |
6151 | nla_put(msg, NL80211_WOWLAN_PKTPAT_PATTERN, | |
6152 | pat_len, | |
6153 | rdev->wowlan->patterns[i].pattern)) | |
6154 | goto nla_put_failure; | |
ff1b6e69 JB |
6155 | nla_nest_end(msg, nl_pat); |
6156 | } | |
6157 | nla_nest_end(msg, nl_pats); | |
6158 | } | |
6159 | ||
6160 | nla_nest_end(msg, nl_wowlan); | |
6161 | } | |
6162 | ||
6163 | genlmsg_end(msg, hdr); | |
6164 | return genlmsg_reply(msg, info); | |
6165 | ||
6166 | nla_put_failure: | |
6167 | nlmsg_free(msg); | |
6168 | return -ENOBUFS; | |
6169 | } | |
6170 | ||
6171 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) | |
6172 | { | |
6173 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6174 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; | |
6175 | struct cfg80211_wowlan no_triggers = {}; | |
6176 | struct cfg80211_wowlan new_triggers = {}; | |
6177 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; | |
6178 | int err, i; | |
6d52563f | 6179 | bool prev_enabled = rdev->wowlan; |
ff1b6e69 JB |
6180 | |
6181 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) | |
6182 | return -EOPNOTSUPP; | |
6183 | ||
6184 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) | |
6185 | goto no_triggers; | |
6186 | ||
6187 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, | |
6188 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
6189 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
6190 | nl80211_wowlan_policy); | |
6191 | if (err) | |
6192 | return err; | |
6193 | ||
6194 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { | |
6195 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) | |
6196 | return -EINVAL; | |
6197 | new_triggers.any = true; | |
6198 | } | |
6199 | ||
6200 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { | |
6201 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) | |
6202 | return -EINVAL; | |
6203 | new_triggers.disconnect = true; | |
6204 | } | |
6205 | ||
6206 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { | |
6207 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) | |
6208 | return -EINVAL; | |
6209 | new_triggers.magic_pkt = true; | |
6210 | } | |
6211 | ||
77dbbb13 JB |
6212 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
6213 | return -EINVAL; | |
6214 | ||
6215 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { | |
6216 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) | |
6217 | return -EINVAL; | |
6218 | new_triggers.gtk_rekey_failure = true; | |
6219 | } | |
6220 | ||
6221 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { | |
6222 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) | |
6223 | return -EINVAL; | |
6224 | new_triggers.eap_identity_req = true; | |
6225 | } | |
6226 | ||
6227 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { | |
6228 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) | |
6229 | return -EINVAL; | |
6230 | new_triggers.four_way_handshake = true; | |
6231 | } | |
6232 | ||
6233 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { | |
6234 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) | |
6235 | return -EINVAL; | |
6236 | new_triggers.rfkill_release = true; | |
6237 | } | |
6238 | ||
ff1b6e69 JB |
6239 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
6240 | struct nlattr *pat; | |
6241 | int n_patterns = 0; | |
6242 | int rem, pat_len, mask_len; | |
6243 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; | |
6244 | ||
6245 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
6246 | rem) | |
6247 | n_patterns++; | |
6248 | if (n_patterns > wowlan->n_patterns) | |
6249 | return -EINVAL; | |
6250 | ||
6251 | new_triggers.patterns = kcalloc(n_patterns, | |
6252 | sizeof(new_triggers.patterns[0]), | |
6253 | GFP_KERNEL); | |
6254 | if (!new_triggers.patterns) | |
6255 | return -ENOMEM; | |
6256 | ||
6257 | new_triggers.n_patterns = n_patterns; | |
6258 | i = 0; | |
6259 | ||
6260 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
6261 | rem) { | |
6262 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, | |
6263 | nla_data(pat), nla_len(pat), NULL); | |
6264 | err = -EINVAL; | |
6265 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || | |
6266 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) | |
6267 | goto error; | |
6268 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); | |
6269 | mask_len = DIV_ROUND_UP(pat_len, 8); | |
6270 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != | |
6271 | mask_len) | |
6272 | goto error; | |
6273 | if (pat_len > wowlan->pattern_max_len || | |
6274 | pat_len < wowlan->pattern_min_len) | |
6275 | goto error; | |
6276 | ||
6277 | new_triggers.patterns[i].mask = | |
6278 | kmalloc(mask_len + pat_len, GFP_KERNEL); | |
6279 | if (!new_triggers.patterns[i].mask) { | |
6280 | err = -ENOMEM; | |
6281 | goto error; | |
6282 | } | |
6283 | new_triggers.patterns[i].pattern = | |
6284 | new_triggers.patterns[i].mask + mask_len; | |
6285 | memcpy(new_triggers.patterns[i].mask, | |
6286 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), | |
6287 | mask_len); | |
6288 | new_triggers.patterns[i].pattern_len = pat_len; | |
6289 | memcpy(new_triggers.patterns[i].pattern, | |
6290 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), | |
6291 | pat_len); | |
6292 | i++; | |
6293 | } | |
6294 | } | |
6295 | ||
6296 | if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) { | |
6297 | struct cfg80211_wowlan *ntrig; | |
6298 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), | |
6299 | GFP_KERNEL); | |
6300 | if (!ntrig) { | |
6301 | err = -ENOMEM; | |
6302 | goto error; | |
6303 | } | |
6304 | cfg80211_rdev_free_wowlan(rdev); | |
6305 | rdev->wowlan = ntrig; | |
6306 | } else { | |
6307 | no_triggers: | |
6308 | cfg80211_rdev_free_wowlan(rdev); | |
6309 | rdev->wowlan = NULL; | |
6310 | } | |
6311 | ||
6d52563f JB |
6312 | if (rdev->ops->set_wakeup && prev_enabled != !!rdev->wowlan) |
6313 | rdev->ops->set_wakeup(&rdev->wiphy, rdev->wowlan); | |
6314 | ||
ff1b6e69 JB |
6315 | return 0; |
6316 | error: | |
6317 | for (i = 0; i < new_triggers.n_patterns; i++) | |
6318 | kfree(new_triggers.patterns[i].mask); | |
6319 | kfree(new_triggers.patterns); | |
6320 | return err; | |
6321 | } | |
6322 | ||
e5497d76 JB |
6323 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
6324 | { | |
6325 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6326 | struct net_device *dev = info->user_ptr[1]; | |
6327 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
6328 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; | |
6329 | struct cfg80211_gtk_rekey_data rekey_data; | |
6330 | int err; | |
6331 | ||
6332 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) | |
6333 | return -EINVAL; | |
6334 | ||
6335 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, | |
6336 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
6337 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
6338 | nl80211_rekey_policy); | |
6339 | if (err) | |
6340 | return err; | |
6341 | ||
6342 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) | |
6343 | return -ERANGE; | |
6344 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) | |
6345 | return -ERANGE; | |
6346 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) | |
6347 | return -ERANGE; | |
6348 | ||
6349 | memcpy(rekey_data.kek, nla_data(tb[NL80211_REKEY_DATA_KEK]), | |
6350 | NL80211_KEK_LEN); | |
6351 | memcpy(rekey_data.kck, nla_data(tb[NL80211_REKEY_DATA_KCK]), | |
6352 | NL80211_KCK_LEN); | |
6353 | memcpy(rekey_data.replay_ctr, | |
6354 | nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]), | |
6355 | NL80211_REPLAY_CTR_LEN); | |
6356 | ||
6357 | wdev_lock(wdev); | |
6358 | if (!wdev->current_bss) { | |
6359 | err = -ENOTCONN; | |
6360 | goto out; | |
6361 | } | |
6362 | ||
6363 | if (!rdev->ops->set_rekey_data) { | |
6364 | err = -EOPNOTSUPP; | |
6365 | goto out; | |
6366 | } | |
6367 | ||
6368 | err = rdev->ops->set_rekey_data(&rdev->wiphy, dev, &rekey_data); | |
6369 | out: | |
6370 | wdev_unlock(wdev); | |
6371 | return err; | |
6372 | } | |
6373 | ||
28946da7 JB |
6374 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
6375 | struct genl_info *info) | |
6376 | { | |
6377 | struct net_device *dev = info->user_ptr[1]; | |
6378 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
6379 | ||
6380 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
6381 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
6382 | return -EINVAL; | |
6383 | ||
6384 | if (wdev->ap_unexpected_nlpid) | |
6385 | return -EBUSY; | |
6386 | ||
6387 | wdev->ap_unexpected_nlpid = info->snd_pid; | |
6388 | return 0; | |
6389 | } | |
6390 | ||
7f6cf311 JB |
6391 | static int nl80211_probe_client(struct sk_buff *skb, |
6392 | struct genl_info *info) | |
6393 | { | |
6394 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6395 | struct net_device *dev = info->user_ptr[1]; | |
6396 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
6397 | struct sk_buff *msg; | |
6398 | void *hdr; | |
6399 | const u8 *addr; | |
6400 | u64 cookie; | |
6401 | int err; | |
6402 | ||
6403 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
6404 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
6405 | return -EOPNOTSUPP; | |
6406 | ||
6407 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6408 | return -EINVAL; | |
6409 | ||
6410 | if (!rdev->ops->probe_client) | |
6411 | return -EOPNOTSUPP; | |
6412 | ||
6413 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
6414 | if (!msg) | |
6415 | return -ENOMEM; | |
6416 | ||
6417 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | |
6418 | NL80211_CMD_PROBE_CLIENT); | |
6419 | ||
6420 | if (IS_ERR(hdr)) { | |
6421 | err = PTR_ERR(hdr); | |
6422 | goto free_msg; | |
6423 | } | |
6424 | ||
6425 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
6426 | ||
6427 | err = rdev->ops->probe_client(&rdev->wiphy, dev, addr, &cookie); | |
6428 | if (err) | |
6429 | goto free_msg; | |
6430 | ||
9360ffd1 DM |
6431 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
6432 | goto nla_put_failure; | |
7f6cf311 JB |
6433 | |
6434 | genlmsg_end(msg, hdr); | |
6435 | ||
6436 | return genlmsg_reply(msg, info); | |
6437 | ||
6438 | nla_put_failure: | |
6439 | err = -ENOBUFS; | |
6440 | free_msg: | |
6441 | nlmsg_free(msg); | |
6442 | return err; | |
6443 | } | |
6444 | ||
5e760230 JB |
6445 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
6446 | { | |
6447 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6448 | ||
6449 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) | |
6450 | return -EOPNOTSUPP; | |
6451 | ||
6452 | if (rdev->ap_beacons_nlpid) | |
6453 | return -EBUSY; | |
6454 | ||
6455 | rdev->ap_beacons_nlpid = info->snd_pid; | |
6456 | ||
6457 | return 0; | |
6458 | } | |
6459 | ||
4c476991 JB |
6460 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
6461 | #define NL80211_FLAG_NEED_NETDEV 0x02 | |
6462 | #define NL80211_FLAG_NEED_RTNL 0x04 | |
41265714 JB |
6463 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
6464 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ | |
6465 | NL80211_FLAG_CHECK_NETDEV_UP) | |
4c476991 JB |
6466 | |
6467 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, | |
6468 | struct genl_info *info) | |
6469 | { | |
6470 | struct cfg80211_registered_device *rdev; | |
6471 | struct net_device *dev; | |
6472 | int err; | |
6473 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; | |
6474 | ||
6475 | if (rtnl) | |
6476 | rtnl_lock(); | |
6477 | ||
6478 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { | |
6479 | rdev = cfg80211_get_dev_from_info(info); | |
6480 | if (IS_ERR(rdev)) { | |
6481 | if (rtnl) | |
6482 | rtnl_unlock(); | |
6483 | return PTR_ERR(rdev); | |
6484 | } | |
6485 | info->user_ptr[0] = rdev; | |
6486 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { | |
00918d33 JB |
6487 | err = get_rdev_dev_by_ifindex(genl_info_net(info), info->attrs, |
6488 | &rdev, &dev); | |
4c476991 JB |
6489 | if (err) { |
6490 | if (rtnl) | |
6491 | rtnl_unlock(); | |
6492 | return err; | |
6493 | } | |
41265714 JB |
6494 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
6495 | !netif_running(dev)) { | |
d537f5fd JB |
6496 | cfg80211_unlock_rdev(rdev); |
6497 | dev_put(dev); | |
41265714 JB |
6498 | if (rtnl) |
6499 | rtnl_unlock(); | |
6500 | return -ENETDOWN; | |
6501 | } | |
4c476991 JB |
6502 | info->user_ptr[0] = rdev; |
6503 | info->user_ptr[1] = dev; | |
6504 | } | |
6505 | ||
6506 | return 0; | |
6507 | } | |
6508 | ||
6509 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, | |
6510 | struct genl_info *info) | |
6511 | { | |
6512 | if (info->user_ptr[0]) | |
6513 | cfg80211_unlock_rdev(info->user_ptr[0]); | |
6514 | if (info->user_ptr[1]) | |
6515 | dev_put(info->user_ptr[1]); | |
6516 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) | |
6517 | rtnl_unlock(); | |
6518 | } | |
6519 | ||
55682965 JB |
6520 | static struct genl_ops nl80211_ops[] = { |
6521 | { | |
6522 | .cmd = NL80211_CMD_GET_WIPHY, | |
6523 | .doit = nl80211_get_wiphy, | |
6524 | .dumpit = nl80211_dump_wiphy, | |
6525 | .policy = nl80211_policy, | |
6526 | /* can be retrieved by unprivileged users */ | |
4c476991 | 6527 | .internal_flags = NL80211_FLAG_NEED_WIPHY, |
55682965 JB |
6528 | }, |
6529 | { | |
6530 | .cmd = NL80211_CMD_SET_WIPHY, | |
6531 | .doit = nl80211_set_wiphy, | |
6532 | .policy = nl80211_policy, | |
6533 | .flags = GENL_ADMIN_PERM, | |
4c476991 | 6534 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
55682965 JB |
6535 | }, |
6536 | { | |
6537 | .cmd = NL80211_CMD_GET_INTERFACE, | |
6538 | .doit = nl80211_get_interface, | |
6539 | .dumpit = nl80211_dump_interface, | |
6540 | .policy = nl80211_policy, | |
6541 | /* can be retrieved by unprivileged users */ | |
4c476991 | 6542 | .internal_flags = NL80211_FLAG_NEED_NETDEV, |
55682965 JB |
6543 | }, |
6544 | { | |
6545 | .cmd = NL80211_CMD_SET_INTERFACE, | |
6546 | .doit = nl80211_set_interface, | |
6547 | .policy = nl80211_policy, | |
6548 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
6549 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
6550 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
6551 | }, |
6552 | { | |
6553 | .cmd = NL80211_CMD_NEW_INTERFACE, | |
6554 | .doit = nl80211_new_interface, | |
6555 | .policy = nl80211_policy, | |
6556 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
6557 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
6558 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
6559 | }, |
6560 | { | |
6561 | .cmd = NL80211_CMD_DEL_INTERFACE, | |
6562 | .doit = nl80211_del_interface, | |
6563 | .policy = nl80211_policy, | |
41ade00f | 6564 | .flags = GENL_ADMIN_PERM, |
4c476991 JB |
6565 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
6566 | NL80211_FLAG_NEED_RTNL, | |
41ade00f JB |
6567 | }, |
6568 | { | |
6569 | .cmd = NL80211_CMD_GET_KEY, | |
6570 | .doit = nl80211_get_key, | |
6571 | .policy = nl80211_policy, | |
6572 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 6573 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6574 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
6575 | }, |
6576 | { | |
6577 | .cmd = NL80211_CMD_SET_KEY, | |
6578 | .doit = nl80211_set_key, | |
6579 | .policy = nl80211_policy, | |
6580 | .flags = GENL_ADMIN_PERM, | |
41265714 | 6581 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6582 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
6583 | }, |
6584 | { | |
6585 | .cmd = NL80211_CMD_NEW_KEY, | |
6586 | .doit = nl80211_new_key, | |
6587 | .policy = nl80211_policy, | |
6588 | .flags = GENL_ADMIN_PERM, | |
41265714 | 6589 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6590 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
6591 | }, |
6592 | { | |
6593 | .cmd = NL80211_CMD_DEL_KEY, | |
6594 | .doit = nl80211_del_key, | |
6595 | .policy = nl80211_policy, | |
55682965 | 6596 | .flags = GENL_ADMIN_PERM, |
41265714 | 6597 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6598 | NL80211_FLAG_NEED_RTNL, |
55682965 | 6599 | }, |
ed1b6cc7 JB |
6600 | { |
6601 | .cmd = NL80211_CMD_SET_BEACON, | |
6602 | .policy = nl80211_policy, | |
6603 | .flags = GENL_ADMIN_PERM, | |
8860020e | 6604 | .doit = nl80211_set_beacon, |
2b5f8b0b | 6605 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6606 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
6607 | }, |
6608 | { | |
8860020e | 6609 | .cmd = NL80211_CMD_START_AP, |
ed1b6cc7 JB |
6610 | .policy = nl80211_policy, |
6611 | .flags = GENL_ADMIN_PERM, | |
8860020e | 6612 | .doit = nl80211_start_ap, |
2b5f8b0b | 6613 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6614 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
6615 | }, |
6616 | { | |
8860020e | 6617 | .cmd = NL80211_CMD_STOP_AP, |
ed1b6cc7 JB |
6618 | .policy = nl80211_policy, |
6619 | .flags = GENL_ADMIN_PERM, | |
8860020e | 6620 | .doit = nl80211_stop_ap, |
2b5f8b0b | 6621 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6622 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 | 6623 | }, |
5727ef1b JB |
6624 | { |
6625 | .cmd = NL80211_CMD_GET_STATION, | |
6626 | .doit = nl80211_get_station, | |
2ec600d6 | 6627 | .dumpit = nl80211_dump_station, |
5727ef1b | 6628 | .policy = nl80211_policy, |
4c476991 JB |
6629 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
6630 | NL80211_FLAG_NEED_RTNL, | |
5727ef1b JB |
6631 | }, |
6632 | { | |
6633 | .cmd = NL80211_CMD_SET_STATION, | |
6634 | .doit = nl80211_set_station, | |
6635 | .policy = nl80211_policy, | |
6636 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 6637 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6638 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
6639 | }, |
6640 | { | |
6641 | .cmd = NL80211_CMD_NEW_STATION, | |
6642 | .doit = nl80211_new_station, | |
6643 | .policy = nl80211_policy, | |
6644 | .flags = GENL_ADMIN_PERM, | |
41265714 | 6645 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6646 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
6647 | }, |
6648 | { | |
6649 | .cmd = NL80211_CMD_DEL_STATION, | |
6650 | .doit = nl80211_del_station, | |
6651 | .policy = nl80211_policy, | |
2ec600d6 | 6652 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 6653 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6654 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
6655 | }, |
6656 | { | |
6657 | .cmd = NL80211_CMD_GET_MPATH, | |
6658 | .doit = nl80211_get_mpath, | |
6659 | .dumpit = nl80211_dump_mpath, | |
6660 | .policy = nl80211_policy, | |
6661 | .flags = GENL_ADMIN_PERM, | |
41265714 | 6662 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6663 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
6664 | }, |
6665 | { | |
6666 | .cmd = NL80211_CMD_SET_MPATH, | |
6667 | .doit = nl80211_set_mpath, | |
6668 | .policy = nl80211_policy, | |
6669 | .flags = GENL_ADMIN_PERM, | |
41265714 | 6670 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6671 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
6672 | }, |
6673 | { | |
6674 | .cmd = NL80211_CMD_NEW_MPATH, | |
6675 | .doit = nl80211_new_mpath, | |
6676 | .policy = nl80211_policy, | |
6677 | .flags = GENL_ADMIN_PERM, | |
41265714 | 6678 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6679 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
6680 | }, |
6681 | { | |
6682 | .cmd = NL80211_CMD_DEL_MPATH, | |
6683 | .doit = nl80211_del_mpath, | |
6684 | .policy = nl80211_policy, | |
9f1ba906 | 6685 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 6686 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6687 | NL80211_FLAG_NEED_RTNL, |
9f1ba906 JM |
6688 | }, |
6689 | { | |
6690 | .cmd = NL80211_CMD_SET_BSS, | |
6691 | .doit = nl80211_set_bss, | |
6692 | .policy = nl80211_policy, | |
b2e1b302 | 6693 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 6694 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6695 | NL80211_FLAG_NEED_RTNL, |
b2e1b302 | 6696 | }, |
f130347c LR |
6697 | { |
6698 | .cmd = NL80211_CMD_GET_REG, | |
6699 | .doit = nl80211_get_reg, | |
6700 | .policy = nl80211_policy, | |
6701 | /* can be retrieved by unprivileged users */ | |
6702 | }, | |
b2e1b302 LR |
6703 | { |
6704 | .cmd = NL80211_CMD_SET_REG, | |
6705 | .doit = nl80211_set_reg, | |
6706 | .policy = nl80211_policy, | |
6707 | .flags = GENL_ADMIN_PERM, | |
6708 | }, | |
6709 | { | |
6710 | .cmd = NL80211_CMD_REQ_SET_REG, | |
6711 | .doit = nl80211_req_set_reg, | |
6712 | .policy = nl80211_policy, | |
93da9cc1 | 6713 | .flags = GENL_ADMIN_PERM, |
6714 | }, | |
6715 | { | |
24bdd9f4 JC |
6716 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
6717 | .doit = nl80211_get_mesh_config, | |
93da9cc1 | 6718 | .policy = nl80211_policy, |
6719 | /* can be retrieved by unprivileged users */ | |
2b5f8b0b | 6720 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6721 | NL80211_FLAG_NEED_RTNL, |
93da9cc1 | 6722 | }, |
6723 | { | |
24bdd9f4 JC |
6724 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
6725 | .doit = nl80211_update_mesh_config, | |
93da9cc1 | 6726 | .policy = nl80211_policy, |
9aed3cc1 | 6727 | .flags = GENL_ADMIN_PERM, |
29cbe68c | 6728 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6729 | NL80211_FLAG_NEED_RTNL, |
9aed3cc1 | 6730 | }, |
2a519311 JB |
6731 | { |
6732 | .cmd = NL80211_CMD_TRIGGER_SCAN, | |
6733 | .doit = nl80211_trigger_scan, | |
6734 | .policy = nl80211_policy, | |
6735 | .flags = GENL_ADMIN_PERM, | |
41265714 | 6736 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6737 | NL80211_FLAG_NEED_RTNL, |
2a519311 JB |
6738 | }, |
6739 | { | |
6740 | .cmd = NL80211_CMD_GET_SCAN, | |
6741 | .policy = nl80211_policy, | |
6742 | .dumpit = nl80211_dump_scan, | |
6743 | }, | |
807f8a8c LC |
6744 | { |
6745 | .cmd = NL80211_CMD_START_SCHED_SCAN, | |
6746 | .doit = nl80211_start_sched_scan, | |
6747 | .policy = nl80211_policy, | |
6748 | .flags = GENL_ADMIN_PERM, | |
6749 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
6750 | NL80211_FLAG_NEED_RTNL, | |
6751 | }, | |
6752 | { | |
6753 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, | |
6754 | .doit = nl80211_stop_sched_scan, | |
6755 | .policy = nl80211_policy, | |
6756 | .flags = GENL_ADMIN_PERM, | |
6757 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
6758 | NL80211_FLAG_NEED_RTNL, | |
6759 | }, | |
636a5d36 JM |
6760 | { |
6761 | .cmd = NL80211_CMD_AUTHENTICATE, | |
6762 | .doit = nl80211_authenticate, | |
6763 | .policy = nl80211_policy, | |
6764 | .flags = GENL_ADMIN_PERM, | |
41265714 | 6765 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6766 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
6767 | }, |
6768 | { | |
6769 | .cmd = NL80211_CMD_ASSOCIATE, | |
6770 | .doit = nl80211_associate, | |
6771 | .policy = nl80211_policy, | |
6772 | .flags = GENL_ADMIN_PERM, | |
41265714 | 6773 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6774 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
6775 | }, |
6776 | { | |
6777 | .cmd = NL80211_CMD_DEAUTHENTICATE, | |
6778 | .doit = nl80211_deauthenticate, | |
6779 | .policy = nl80211_policy, | |
6780 | .flags = GENL_ADMIN_PERM, | |
41265714 | 6781 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6782 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
6783 | }, |
6784 | { | |
6785 | .cmd = NL80211_CMD_DISASSOCIATE, | |
6786 | .doit = nl80211_disassociate, | |
6787 | .policy = nl80211_policy, | |
6788 | .flags = GENL_ADMIN_PERM, | |
41265714 | 6789 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6790 | NL80211_FLAG_NEED_RTNL, |
636a5d36 | 6791 | }, |
04a773ad JB |
6792 | { |
6793 | .cmd = NL80211_CMD_JOIN_IBSS, | |
6794 | .doit = nl80211_join_ibss, | |
6795 | .policy = nl80211_policy, | |
6796 | .flags = GENL_ADMIN_PERM, | |
41265714 | 6797 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6798 | NL80211_FLAG_NEED_RTNL, |
04a773ad JB |
6799 | }, |
6800 | { | |
6801 | .cmd = NL80211_CMD_LEAVE_IBSS, | |
6802 | .doit = nl80211_leave_ibss, | |
6803 | .policy = nl80211_policy, | |
6804 | .flags = GENL_ADMIN_PERM, | |
41265714 | 6805 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6806 | NL80211_FLAG_NEED_RTNL, |
04a773ad | 6807 | }, |
aff89a9b JB |
6808 | #ifdef CONFIG_NL80211_TESTMODE |
6809 | { | |
6810 | .cmd = NL80211_CMD_TESTMODE, | |
6811 | .doit = nl80211_testmode_do, | |
71063f0e | 6812 | .dumpit = nl80211_testmode_dump, |
aff89a9b JB |
6813 | .policy = nl80211_policy, |
6814 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
6815 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
6816 | NL80211_FLAG_NEED_RTNL, | |
aff89a9b JB |
6817 | }, |
6818 | #endif | |
b23aa676 SO |
6819 | { |
6820 | .cmd = NL80211_CMD_CONNECT, | |
6821 | .doit = nl80211_connect, | |
6822 | .policy = nl80211_policy, | |
6823 | .flags = GENL_ADMIN_PERM, | |
41265714 | 6824 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6825 | NL80211_FLAG_NEED_RTNL, |
b23aa676 SO |
6826 | }, |
6827 | { | |
6828 | .cmd = NL80211_CMD_DISCONNECT, | |
6829 | .doit = nl80211_disconnect, | |
6830 | .policy = nl80211_policy, | |
6831 | .flags = GENL_ADMIN_PERM, | |
41265714 | 6832 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6833 | NL80211_FLAG_NEED_RTNL, |
b23aa676 | 6834 | }, |
463d0183 JB |
6835 | { |
6836 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, | |
6837 | .doit = nl80211_wiphy_netns, | |
6838 | .policy = nl80211_policy, | |
6839 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
6840 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
6841 | NL80211_FLAG_NEED_RTNL, | |
463d0183 | 6842 | }, |
61fa713c HS |
6843 | { |
6844 | .cmd = NL80211_CMD_GET_SURVEY, | |
6845 | .policy = nl80211_policy, | |
6846 | .dumpit = nl80211_dump_survey, | |
6847 | }, | |
67fbb16b SO |
6848 | { |
6849 | .cmd = NL80211_CMD_SET_PMKSA, | |
6850 | .doit = nl80211_setdel_pmksa, | |
6851 | .policy = nl80211_policy, | |
6852 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 6853 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6854 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
6855 | }, |
6856 | { | |
6857 | .cmd = NL80211_CMD_DEL_PMKSA, | |
6858 | .doit = nl80211_setdel_pmksa, | |
6859 | .policy = nl80211_policy, | |
6860 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 6861 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6862 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
6863 | }, |
6864 | { | |
6865 | .cmd = NL80211_CMD_FLUSH_PMKSA, | |
6866 | .doit = nl80211_flush_pmksa, | |
6867 | .policy = nl80211_policy, | |
6868 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 6869 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6870 | NL80211_FLAG_NEED_RTNL, |
67fbb16b | 6871 | }, |
9588bbd5 JM |
6872 | { |
6873 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, | |
6874 | .doit = nl80211_remain_on_channel, | |
6875 | .policy = nl80211_policy, | |
6876 | .flags = GENL_ADMIN_PERM, | |
41265714 | 6877 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6878 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 JM |
6879 | }, |
6880 | { | |
6881 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
6882 | .doit = nl80211_cancel_remain_on_channel, | |
6883 | .policy = nl80211_policy, | |
6884 | .flags = GENL_ADMIN_PERM, | |
41265714 | 6885 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6886 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 | 6887 | }, |
13ae75b1 JM |
6888 | { |
6889 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, | |
6890 | .doit = nl80211_set_tx_bitrate_mask, | |
6891 | .policy = nl80211_policy, | |
6892 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
6893 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
6894 | NL80211_FLAG_NEED_RTNL, | |
13ae75b1 | 6895 | }, |
026331c4 | 6896 | { |
2e161f78 JB |
6897 | .cmd = NL80211_CMD_REGISTER_FRAME, |
6898 | .doit = nl80211_register_mgmt, | |
026331c4 JM |
6899 | .policy = nl80211_policy, |
6900 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
6901 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
6902 | NL80211_FLAG_NEED_RTNL, | |
026331c4 JM |
6903 | }, |
6904 | { | |
2e161f78 JB |
6905 | .cmd = NL80211_CMD_FRAME, |
6906 | .doit = nl80211_tx_mgmt, | |
026331c4 | 6907 | .policy = nl80211_policy, |
f7ca38df JB |
6908 | .flags = GENL_ADMIN_PERM, |
6909 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
6910 | NL80211_FLAG_NEED_RTNL, | |
6911 | }, | |
6912 | { | |
6913 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, | |
6914 | .doit = nl80211_tx_mgmt_cancel_wait, | |
6915 | .policy = nl80211_policy, | |
026331c4 | 6916 | .flags = GENL_ADMIN_PERM, |
41265714 | 6917 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 6918 | NL80211_FLAG_NEED_RTNL, |
026331c4 | 6919 | }, |
ffb9eb3d KV |
6920 | { |
6921 | .cmd = NL80211_CMD_SET_POWER_SAVE, | |
6922 | .doit = nl80211_set_power_save, | |
6923 | .policy = nl80211_policy, | |
6924 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
6925 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
6926 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d KV |
6927 | }, |
6928 | { | |
6929 | .cmd = NL80211_CMD_GET_POWER_SAVE, | |
6930 | .doit = nl80211_get_power_save, | |
6931 | .policy = nl80211_policy, | |
6932 | /* can be retrieved by unprivileged users */ | |
4c476991 JB |
6933 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
6934 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d | 6935 | }, |
d6dc1a38 JO |
6936 | { |
6937 | .cmd = NL80211_CMD_SET_CQM, | |
6938 | .doit = nl80211_set_cqm, | |
6939 | .policy = nl80211_policy, | |
6940 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
6941 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
6942 | NL80211_FLAG_NEED_RTNL, | |
d6dc1a38 | 6943 | }, |
f444de05 JB |
6944 | { |
6945 | .cmd = NL80211_CMD_SET_CHANNEL, | |
6946 | .doit = nl80211_set_channel, | |
6947 | .policy = nl80211_policy, | |
6948 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
6949 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
6950 | NL80211_FLAG_NEED_RTNL, | |
f444de05 | 6951 | }, |
e8347eba BJ |
6952 | { |
6953 | .cmd = NL80211_CMD_SET_WDS_PEER, | |
6954 | .doit = nl80211_set_wds_peer, | |
6955 | .policy = nl80211_policy, | |
6956 | .flags = GENL_ADMIN_PERM, | |
43b19952 JB |
6957 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
6958 | NL80211_FLAG_NEED_RTNL, | |
e8347eba | 6959 | }, |
29cbe68c JB |
6960 | { |
6961 | .cmd = NL80211_CMD_JOIN_MESH, | |
6962 | .doit = nl80211_join_mesh, | |
6963 | .policy = nl80211_policy, | |
6964 | .flags = GENL_ADMIN_PERM, | |
6965 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
6966 | NL80211_FLAG_NEED_RTNL, | |
6967 | }, | |
6968 | { | |
6969 | .cmd = NL80211_CMD_LEAVE_MESH, | |
6970 | .doit = nl80211_leave_mesh, | |
6971 | .policy = nl80211_policy, | |
6972 | .flags = GENL_ADMIN_PERM, | |
6973 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
6974 | NL80211_FLAG_NEED_RTNL, | |
6975 | }, | |
ff1b6e69 JB |
6976 | { |
6977 | .cmd = NL80211_CMD_GET_WOWLAN, | |
6978 | .doit = nl80211_get_wowlan, | |
6979 | .policy = nl80211_policy, | |
6980 | /* can be retrieved by unprivileged users */ | |
6981 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
6982 | NL80211_FLAG_NEED_RTNL, | |
6983 | }, | |
6984 | { | |
6985 | .cmd = NL80211_CMD_SET_WOWLAN, | |
6986 | .doit = nl80211_set_wowlan, | |
6987 | .policy = nl80211_policy, | |
6988 | .flags = GENL_ADMIN_PERM, | |
6989 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
6990 | NL80211_FLAG_NEED_RTNL, | |
6991 | }, | |
e5497d76 JB |
6992 | { |
6993 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, | |
6994 | .doit = nl80211_set_rekey_data, | |
6995 | .policy = nl80211_policy, | |
6996 | .flags = GENL_ADMIN_PERM, | |
6997 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
6998 | NL80211_FLAG_NEED_RTNL, | |
6999 | }, | |
109086ce AN |
7000 | { |
7001 | .cmd = NL80211_CMD_TDLS_MGMT, | |
7002 | .doit = nl80211_tdls_mgmt, | |
7003 | .policy = nl80211_policy, | |
7004 | .flags = GENL_ADMIN_PERM, | |
7005 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
7006 | NL80211_FLAG_NEED_RTNL, | |
7007 | }, | |
7008 | { | |
7009 | .cmd = NL80211_CMD_TDLS_OPER, | |
7010 | .doit = nl80211_tdls_oper, | |
7011 | .policy = nl80211_policy, | |
7012 | .flags = GENL_ADMIN_PERM, | |
7013 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
7014 | NL80211_FLAG_NEED_RTNL, | |
7015 | }, | |
28946da7 JB |
7016 | { |
7017 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, | |
7018 | .doit = nl80211_register_unexpected_frame, | |
7019 | .policy = nl80211_policy, | |
7020 | .flags = GENL_ADMIN_PERM, | |
7021 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
7022 | NL80211_FLAG_NEED_RTNL, | |
7023 | }, | |
7f6cf311 JB |
7024 | { |
7025 | .cmd = NL80211_CMD_PROBE_CLIENT, | |
7026 | .doit = nl80211_probe_client, | |
7027 | .policy = nl80211_policy, | |
7028 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 7029 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
7f6cf311 JB |
7030 | NL80211_FLAG_NEED_RTNL, |
7031 | }, | |
5e760230 JB |
7032 | { |
7033 | .cmd = NL80211_CMD_REGISTER_BEACONS, | |
7034 | .doit = nl80211_register_beacons, | |
7035 | .policy = nl80211_policy, | |
7036 | .flags = GENL_ADMIN_PERM, | |
7037 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
7038 | NL80211_FLAG_NEED_RTNL, | |
7039 | }, | |
1d9d9213 SW |
7040 | { |
7041 | .cmd = NL80211_CMD_SET_NOACK_MAP, | |
7042 | .doit = nl80211_set_noack_map, | |
7043 | .policy = nl80211_policy, | |
7044 | .flags = GENL_ADMIN_PERM, | |
7045 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
7046 | NL80211_FLAG_NEED_RTNL, | |
7047 | }, | |
7048 | ||
55682965 | 7049 | }; |
9588bbd5 | 7050 | |
6039f6d2 JM |
7051 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
7052 | .name = "mlme", | |
7053 | }; | |
55682965 JB |
7054 | |
7055 | /* multicast groups */ | |
7056 | static struct genl_multicast_group nl80211_config_mcgrp = { | |
7057 | .name = "config", | |
7058 | }; | |
2a519311 JB |
7059 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
7060 | .name = "scan", | |
7061 | }; | |
73d54c9e LR |
7062 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
7063 | .name = "regulatory", | |
7064 | }; | |
55682965 JB |
7065 | |
7066 | /* notification functions */ | |
7067 | ||
7068 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) | |
7069 | { | |
7070 | struct sk_buff *msg; | |
7071 | ||
fd2120ca | 7072 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 JB |
7073 | if (!msg) |
7074 | return; | |
7075 | ||
7076 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { | |
7077 | nlmsg_free(msg); | |
7078 | return; | |
7079 | } | |
7080 | ||
463d0183 JB |
7081 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
7082 | nl80211_config_mcgrp.id, GFP_KERNEL); | |
55682965 JB |
7083 | } |
7084 | ||
362a415d JB |
7085 | static int nl80211_add_scan_req(struct sk_buff *msg, |
7086 | struct cfg80211_registered_device *rdev) | |
7087 | { | |
7088 | struct cfg80211_scan_request *req = rdev->scan_req; | |
7089 | struct nlattr *nest; | |
7090 | int i; | |
7091 | ||
667503dd JB |
7092 | ASSERT_RDEV_LOCK(rdev); |
7093 | ||
362a415d JB |
7094 | if (WARN_ON(!req)) |
7095 | return 0; | |
7096 | ||
7097 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); | |
7098 | if (!nest) | |
7099 | goto nla_put_failure; | |
9360ffd1 DM |
7100 | for (i = 0; i < req->n_ssids; i++) { |
7101 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) | |
7102 | goto nla_put_failure; | |
7103 | } | |
362a415d JB |
7104 | nla_nest_end(msg, nest); |
7105 | ||
7106 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
7107 | if (!nest) | |
7108 | goto nla_put_failure; | |
9360ffd1 DM |
7109 | for (i = 0; i < req->n_channels; i++) { |
7110 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) | |
7111 | goto nla_put_failure; | |
7112 | } | |
362a415d JB |
7113 | nla_nest_end(msg, nest); |
7114 | ||
9360ffd1 DM |
7115 | if (req->ie && |
7116 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) | |
7117 | goto nla_put_failure; | |
362a415d JB |
7118 | |
7119 | return 0; | |
7120 | nla_put_failure: | |
7121 | return -ENOBUFS; | |
7122 | } | |
7123 | ||
a538e2d5 JB |
7124 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
7125 | struct cfg80211_registered_device *rdev, | |
7126 | struct net_device *netdev, | |
7127 | u32 pid, u32 seq, int flags, | |
7128 | u32 cmd) | |
2a519311 JB |
7129 | { |
7130 | void *hdr; | |
7131 | ||
7132 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); | |
7133 | if (!hdr) | |
7134 | return -1; | |
7135 | ||
9360ffd1 DM |
7136 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
7137 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
7138 | goto nla_put_failure; | |
2a519311 | 7139 | |
362a415d JB |
7140 | /* ignore errors and send incomplete event anyway */ |
7141 | nl80211_add_scan_req(msg, rdev); | |
2a519311 JB |
7142 | |
7143 | return genlmsg_end(msg, hdr); | |
7144 | ||
7145 | nla_put_failure: | |
7146 | genlmsg_cancel(msg, hdr); | |
7147 | return -EMSGSIZE; | |
7148 | } | |
7149 | ||
807f8a8c LC |
7150 | static int |
7151 | nl80211_send_sched_scan_msg(struct sk_buff *msg, | |
7152 | struct cfg80211_registered_device *rdev, | |
7153 | struct net_device *netdev, | |
7154 | u32 pid, u32 seq, int flags, u32 cmd) | |
7155 | { | |
7156 | void *hdr; | |
7157 | ||
7158 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); | |
7159 | if (!hdr) | |
7160 | return -1; | |
7161 | ||
9360ffd1 DM |
7162 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
7163 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
7164 | goto nla_put_failure; | |
807f8a8c LC |
7165 | |
7166 | return genlmsg_end(msg, hdr); | |
7167 | ||
7168 | nla_put_failure: | |
7169 | genlmsg_cancel(msg, hdr); | |
7170 | return -EMSGSIZE; | |
7171 | } | |
7172 | ||
a538e2d5 JB |
7173 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
7174 | struct net_device *netdev) | |
7175 | { | |
7176 | struct sk_buff *msg; | |
7177 | ||
7178 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); | |
7179 | if (!msg) | |
7180 | return; | |
7181 | ||
7182 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, | |
7183 | NL80211_CMD_TRIGGER_SCAN) < 0) { | |
7184 | nlmsg_free(msg); | |
7185 | return; | |
7186 | } | |
7187 | ||
463d0183 JB |
7188 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
7189 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
a538e2d5 JB |
7190 | } |
7191 | ||
2a519311 JB |
7192 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
7193 | struct net_device *netdev) | |
7194 | { | |
7195 | struct sk_buff *msg; | |
7196 | ||
fd2120ca | 7197 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 JB |
7198 | if (!msg) |
7199 | return; | |
7200 | ||
a538e2d5 JB |
7201 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
7202 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { | |
2a519311 JB |
7203 | nlmsg_free(msg); |
7204 | return; | |
7205 | } | |
7206 | ||
463d0183 JB |
7207 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
7208 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
2a519311 JB |
7209 | } |
7210 | ||
7211 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, | |
7212 | struct net_device *netdev) | |
7213 | { | |
7214 | struct sk_buff *msg; | |
7215 | ||
fd2120ca | 7216 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 JB |
7217 | if (!msg) |
7218 | return; | |
7219 | ||
a538e2d5 JB |
7220 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
7221 | NL80211_CMD_SCAN_ABORTED) < 0) { | |
2a519311 JB |
7222 | nlmsg_free(msg); |
7223 | return; | |
7224 | } | |
7225 | ||
463d0183 JB |
7226 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
7227 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
2a519311 JB |
7228 | } |
7229 | ||
807f8a8c LC |
7230 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
7231 | struct net_device *netdev) | |
7232 | { | |
7233 | struct sk_buff *msg; | |
7234 | ||
7235 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
7236 | if (!msg) | |
7237 | return; | |
7238 | ||
7239 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, | |
7240 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { | |
7241 | nlmsg_free(msg); | |
7242 | return; | |
7243 | } | |
7244 | ||
7245 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
7246 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
7247 | } | |
7248 | ||
7249 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, | |
7250 | struct net_device *netdev, u32 cmd) | |
7251 | { | |
7252 | struct sk_buff *msg; | |
7253 | ||
7254 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); | |
7255 | if (!msg) | |
7256 | return; | |
7257 | ||
7258 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { | |
7259 | nlmsg_free(msg); | |
7260 | return; | |
7261 | } | |
7262 | ||
7263 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
7264 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
7265 | } | |
7266 | ||
73d54c9e LR |
7267 | /* |
7268 | * This can happen on global regulatory changes or device specific settings | |
7269 | * based on custom world regulatory domains. | |
7270 | */ | |
7271 | void nl80211_send_reg_change_event(struct regulatory_request *request) | |
7272 | { | |
7273 | struct sk_buff *msg; | |
7274 | void *hdr; | |
7275 | ||
fd2120ca | 7276 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
73d54c9e LR |
7277 | if (!msg) |
7278 | return; | |
7279 | ||
7280 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); | |
7281 | if (!hdr) { | |
7282 | nlmsg_free(msg); | |
7283 | return; | |
7284 | } | |
7285 | ||
7286 | /* Userspace can always count this one always being set */ | |
9360ffd1 DM |
7287 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
7288 | goto nla_put_failure; | |
7289 | ||
7290 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { | |
7291 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
7292 | NL80211_REGDOM_TYPE_WORLD)) | |
7293 | goto nla_put_failure; | |
7294 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { | |
7295 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
7296 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) | |
7297 | goto nla_put_failure; | |
7298 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || | |
7299 | request->intersect) { | |
7300 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
7301 | NL80211_REGDOM_TYPE_INTERSECTION)) | |
7302 | goto nla_put_failure; | |
7303 | } else { | |
7304 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
7305 | NL80211_REGDOM_TYPE_COUNTRY) || | |
7306 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, | |
7307 | request->alpha2)) | |
7308 | goto nla_put_failure; | |
7309 | } | |
7310 | ||
7311 | if (wiphy_idx_valid(request->wiphy_idx) && | |
7312 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) | |
7313 | goto nla_put_failure; | |
73d54c9e | 7314 | |
3b7b72ee | 7315 | genlmsg_end(msg, hdr); |
73d54c9e | 7316 | |
bc43b28c | 7317 | rcu_read_lock(); |
463d0183 | 7318 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
bc43b28c JB |
7319 | GFP_ATOMIC); |
7320 | rcu_read_unlock(); | |
73d54c9e LR |
7321 | |
7322 | return; | |
7323 | ||
7324 | nla_put_failure: | |
7325 | genlmsg_cancel(msg, hdr); | |
7326 | nlmsg_free(msg); | |
7327 | } | |
7328 | ||
6039f6d2 JM |
7329 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
7330 | struct net_device *netdev, | |
7331 | const u8 *buf, size_t len, | |
e6d6e342 | 7332 | enum nl80211_commands cmd, gfp_t gfp) |
6039f6d2 JM |
7333 | { |
7334 | struct sk_buff *msg; | |
7335 | void *hdr; | |
7336 | ||
e6d6e342 | 7337 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
6039f6d2 JM |
7338 | if (!msg) |
7339 | return; | |
7340 | ||
7341 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
7342 | if (!hdr) { | |
7343 | nlmsg_free(msg); | |
7344 | return; | |
7345 | } | |
7346 | ||
9360ffd1 DM |
7347 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
7348 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
7349 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
7350 | goto nla_put_failure; | |
6039f6d2 | 7351 | |
3b7b72ee | 7352 | genlmsg_end(msg, hdr); |
6039f6d2 | 7353 | |
463d0183 JB |
7354 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
7355 | nl80211_mlme_mcgrp.id, gfp); | |
6039f6d2 JM |
7356 | return; |
7357 | ||
7358 | nla_put_failure: | |
7359 | genlmsg_cancel(msg, hdr); | |
7360 | nlmsg_free(msg); | |
7361 | } | |
7362 | ||
7363 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
7364 | struct net_device *netdev, const u8 *buf, |
7365 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
7366 | { |
7367 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 7368 | NL80211_CMD_AUTHENTICATE, gfp); |
6039f6d2 JM |
7369 | } |
7370 | ||
7371 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, | |
7372 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 7373 | size_t len, gfp_t gfp) |
6039f6d2 | 7374 | { |
e6d6e342 JB |
7375 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
7376 | NL80211_CMD_ASSOCIATE, gfp); | |
6039f6d2 JM |
7377 | } |
7378 | ||
53b46b84 | 7379 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
e6d6e342 JB |
7380 | struct net_device *netdev, const u8 *buf, |
7381 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
7382 | { |
7383 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 7384 | NL80211_CMD_DEAUTHENTICATE, gfp); |
6039f6d2 JM |
7385 | } |
7386 | ||
53b46b84 JM |
7387 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
7388 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 7389 | size_t len, gfp_t gfp) |
6039f6d2 JM |
7390 | { |
7391 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 7392 | NL80211_CMD_DISASSOCIATE, gfp); |
6039f6d2 JM |
7393 | } |
7394 | ||
cf4e594e JM |
7395 | void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev, |
7396 | struct net_device *netdev, const u8 *buf, | |
7397 | size_t len, gfp_t gfp) | |
7398 | { | |
7399 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
7400 | NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp); | |
7401 | } | |
7402 | ||
7403 | void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev, | |
7404 | struct net_device *netdev, const u8 *buf, | |
7405 | size_t len, gfp_t gfp) | |
7406 | { | |
7407 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
7408 | NL80211_CMD_UNPROT_DISASSOCIATE, gfp); | |
7409 | } | |
7410 | ||
1b06bb40 LR |
7411 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
7412 | struct net_device *netdev, int cmd, | |
e6d6e342 | 7413 | const u8 *addr, gfp_t gfp) |
1965c853 JM |
7414 | { |
7415 | struct sk_buff *msg; | |
7416 | void *hdr; | |
7417 | ||
e6d6e342 | 7418 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
1965c853 JM |
7419 | if (!msg) |
7420 | return; | |
7421 | ||
7422 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
7423 | if (!hdr) { | |
7424 | nlmsg_free(msg); | |
7425 | return; | |
7426 | } | |
7427 | ||
9360ffd1 DM |
7428 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
7429 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
7430 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || | |
7431 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
7432 | goto nla_put_failure; | |
1965c853 | 7433 | |
3b7b72ee | 7434 | genlmsg_end(msg, hdr); |
1965c853 | 7435 | |
463d0183 JB |
7436 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
7437 | nl80211_mlme_mcgrp.id, gfp); | |
1965c853 JM |
7438 | return; |
7439 | ||
7440 | nla_put_failure: | |
7441 | genlmsg_cancel(msg, hdr); | |
7442 | nlmsg_free(msg); | |
7443 | } | |
7444 | ||
7445 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
7446 | struct net_device *netdev, const u8 *addr, |
7447 | gfp_t gfp) | |
1965c853 JM |
7448 | { |
7449 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, | |
e6d6e342 | 7450 | addr, gfp); |
1965c853 JM |
7451 | } |
7452 | ||
7453 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
7454 | struct net_device *netdev, const u8 *addr, |
7455 | gfp_t gfp) | |
1965c853 | 7456 | { |
e6d6e342 JB |
7457 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
7458 | addr, gfp); | |
1965c853 JM |
7459 | } |
7460 | ||
b23aa676 SO |
7461 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
7462 | struct net_device *netdev, const u8 *bssid, | |
7463 | const u8 *req_ie, size_t req_ie_len, | |
7464 | const u8 *resp_ie, size_t resp_ie_len, | |
7465 | u16 status, gfp_t gfp) | |
7466 | { | |
7467 | struct sk_buff *msg; | |
7468 | void *hdr; | |
7469 | ||
7470 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
7471 | if (!msg) | |
7472 | return; | |
7473 | ||
7474 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); | |
7475 | if (!hdr) { | |
7476 | nlmsg_free(msg); | |
7477 | return; | |
7478 | } | |
7479 | ||
9360ffd1 DM |
7480 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
7481 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
7482 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || | |
7483 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || | |
7484 | (req_ie && | |
7485 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
7486 | (resp_ie && | |
7487 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
7488 | goto nla_put_failure; | |
b23aa676 | 7489 | |
3b7b72ee | 7490 | genlmsg_end(msg, hdr); |
b23aa676 | 7491 | |
463d0183 JB |
7492 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
7493 | nl80211_mlme_mcgrp.id, gfp); | |
b23aa676 SO |
7494 | return; |
7495 | ||
7496 | nla_put_failure: | |
7497 | genlmsg_cancel(msg, hdr); | |
7498 | nlmsg_free(msg); | |
7499 | ||
7500 | } | |
7501 | ||
7502 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, | |
7503 | struct net_device *netdev, const u8 *bssid, | |
7504 | const u8 *req_ie, size_t req_ie_len, | |
7505 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) | |
7506 | { | |
7507 | struct sk_buff *msg; | |
7508 | void *hdr; | |
7509 | ||
7510 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
7511 | if (!msg) | |
7512 | return; | |
7513 | ||
7514 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); | |
7515 | if (!hdr) { | |
7516 | nlmsg_free(msg); | |
7517 | return; | |
7518 | } | |
7519 | ||
9360ffd1 DM |
7520 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
7521 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
7522 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || | |
7523 | (req_ie && | |
7524 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
7525 | (resp_ie && | |
7526 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
7527 | goto nla_put_failure; | |
b23aa676 | 7528 | |
3b7b72ee | 7529 | genlmsg_end(msg, hdr); |
b23aa676 | 7530 | |
463d0183 JB |
7531 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
7532 | nl80211_mlme_mcgrp.id, gfp); | |
b23aa676 SO |
7533 | return; |
7534 | ||
7535 | nla_put_failure: | |
7536 | genlmsg_cancel(msg, hdr); | |
7537 | nlmsg_free(msg); | |
7538 | ||
7539 | } | |
7540 | ||
7541 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, | |
7542 | struct net_device *netdev, u16 reason, | |
667503dd | 7543 | const u8 *ie, size_t ie_len, bool from_ap) |
b23aa676 SO |
7544 | { |
7545 | struct sk_buff *msg; | |
7546 | void *hdr; | |
7547 | ||
667503dd | 7548 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
b23aa676 SO |
7549 | if (!msg) |
7550 | return; | |
7551 | ||
7552 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); | |
7553 | if (!hdr) { | |
7554 | nlmsg_free(msg); | |
7555 | return; | |
7556 | } | |
7557 | ||
9360ffd1 DM |
7558 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
7559 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
7560 | (from_ap && reason && | |
7561 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || | |
7562 | (from_ap && | |
7563 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || | |
7564 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) | |
7565 | goto nla_put_failure; | |
b23aa676 | 7566 | |
3b7b72ee | 7567 | genlmsg_end(msg, hdr); |
b23aa676 | 7568 | |
463d0183 JB |
7569 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
7570 | nl80211_mlme_mcgrp.id, GFP_KERNEL); | |
b23aa676 SO |
7571 | return; |
7572 | ||
7573 | nla_put_failure: | |
7574 | genlmsg_cancel(msg, hdr); | |
7575 | nlmsg_free(msg); | |
7576 | ||
7577 | } | |
7578 | ||
04a773ad JB |
7579 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
7580 | struct net_device *netdev, const u8 *bssid, | |
7581 | gfp_t gfp) | |
7582 | { | |
7583 | struct sk_buff *msg; | |
7584 | void *hdr; | |
7585 | ||
fd2120ca | 7586 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
04a773ad JB |
7587 | if (!msg) |
7588 | return; | |
7589 | ||
7590 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); | |
7591 | if (!hdr) { | |
7592 | nlmsg_free(msg); | |
7593 | return; | |
7594 | } | |
7595 | ||
9360ffd1 DM |
7596 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
7597 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
7598 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
7599 | goto nla_put_failure; | |
04a773ad | 7600 | |
3b7b72ee | 7601 | genlmsg_end(msg, hdr); |
04a773ad | 7602 | |
463d0183 JB |
7603 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
7604 | nl80211_mlme_mcgrp.id, gfp); | |
04a773ad JB |
7605 | return; |
7606 | ||
7607 | nla_put_failure: | |
7608 | genlmsg_cancel(msg, hdr); | |
7609 | nlmsg_free(msg); | |
7610 | } | |
7611 | ||
c93b5e71 JC |
7612 | void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev, |
7613 | struct net_device *netdev, | |
7614 | const u8 *macaddr, const u8* ie, u8 ie_len, | |
7615 | gfp_t gfp) | |
7616 | { | |
7617 | struct sk_buff *msg; | |
7618 | void *hdr; | |
7619 | ||
7620 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
7621 | if (!msg) | |
7622 | return; | |
7623 | ||
7624 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); | |
7625 | if (!hdr) { | |
7626 | nlmsg_free(msg); | |
7627 | return; | |
7628 | } | |
7629 | ||
9360ffd1 DM |
7630 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
7631 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
7632 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr) || | |
7633 | (ie_len && ie && | |
7634 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) | |
7635 | goto nla_put_failure; | |
c93b5e71 | 7636 | |
3b7b72ee | 7637 | genlmsg_end(msg, hdr); |
c93b5e71 JC |
7638 | |
7639 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
7640 | nl80211_mlme_mcgrp.id, gfp); | |
7641 | return; | |
7642 | ||
7643 | nla_put_failure: | |
7644 | genlmsg_cancel(msg, hdr); | |
7645 | nlmsg_free(msg); | |
7646 | } | |
7647 | ||
a3b8b056 JM |
7648 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
7649 | struct net_device *netdev, const u8 *addr, | |
7650 | enum nl80211_key_type key_type, int key_id, | |
e6d6e342 | 7651 | const u8 *tsc, gfp_t gfp) |
a3b8b056 JM |
7652 | { |
7653 | struct sk_buff *msg; | |
7654 | void *hdr; | |
7655 | ||
e6d6e342 | 7656 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
a3b8b056 JM |
7657 | if (!msg) |
7658 | return; | |
7659 | ||
7660 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); | |
7661 | if (!hdr) { | |
7662 | nlmsg_free(msg); | |
7663 | return; | |
7664 | } | |
7665 | ||
9360ffd1 DM |
7666 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
7667 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
7668 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | |
7669 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || | |
7670 | (key_id != -1 && | |
7671 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || | |
7672 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) | |
7673 | goto nla_put_failure; | |
a3b8b056 | 7674 | |
3b7b72ee | 7675 | genlmsg_end(msg, hdr); |
a3b8b056 | 7676 | |
463d0183 JB |
7677 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
7678 | nl80211_mlme_mcgrp.id, gfp); | |
a3b8b056 JM |
7679 | return; |
7680 | ||
7681 | nla_put_failure: | |
7682 | genlmsg_cancel(msg, hdr); | |
7683 | nlmsg_free(msg); | |
7684 | } | |
7685 | ||
6bad8766 LR |
7686 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
7687 | struct ieee80211_channel *channel_before, | |
7688 | struct ieee80211_channel *channel_after) | |
7689 | { | |
7690 | struct sk_buff *msg; | |
7691 | void *hdr; | |
7692 | struct nlattr *nl_freq; | |
7693 | ||
fd2120ca | 7694 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
6bad8766 LR |
7695 | if (!msg) |
7696 | return; | |
7697 | ||
7698 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); | |
7699 | if (!hdr) { | |
7700 | nlmsg_free(msg); | |
7701 | return; | |
7702 | } | |
7703 | ||
7704 | /* | |
7705 | * Since we are applying the beacon hint to a wiphy we know its | |
7706 | * wiphy_idx is valid | |
7707 | */ | |
9360ffd1 DM |
7708 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
7709 | goto nla_put_failure; | |
6bad8766 LR |
7710 | |
7711 | /* Before */ | |
7712 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); | |
7713 | if (!nl_freq) | |
7714 | goto nla_put_failure; | |
7715 | if (nl80211_msg_put_channel(msg, channel_before)) | |
7716 | goto nla_put_failure; | |
7717 | nla_nest_end(msg, nl_freq); | |
7718 | ||
7719 | /* After */ | |
7720 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); | |
7721 | if (!nl_freq) | |
7722 | goto nla_put_failure; | |
7723 | if (nl80211_msg_put_channel(msg, channel_after)) | |
7724 | goto nla_put_failure; | |
7725 | nla_nest_end(msg, nl_freq); | |
7726 | ||
3b7b72ee | 7727 | genlmsg_end(msg, hdr); |
6bad8766 | 7728 | |
463d0183 JB |
7729 | rcu_read_lock(); |
7730 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, | |
7731 | GFP_ATOMIC); | |
7732 | rcu_read_unlock(); | |
6bad8766 LR |
7733 | |
7734 | return; | |
7735 | ||
7736 | nla_put_failure: | |
7737 | genlmsg_cancel(msg, hdr); | |
7738 | nlmsg_free(msg); | |
7739 | } | |
7740 | ||
9588bbd5 JM |
7741 | static void nl80211_send_remain_on_chan_event( |
7742 | int cmd, struct cfg80211_registered_device *rdev, | |
7743 | struct net_device *netdev, u64 cookie, | |
7744 | struct ieee80211_channel *chan, | |
7745 | enum nl80211_channel_type channel_type, | |
7746 | unsigned int duration, gfp_t gfp) | |
7747 | { | |
7748 | struct sk_buff *msg; | |
7749 | void *hdr; | |
7750 | ||
7751 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
7752 | if (!msg) | |
7753 | return; | |
7754 | ||
7755 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
7756 | if (!hdr) { | |
7757 | nlmsg_free(msg); | |
7758 | return; | |
7759 | } | |
7760 | ||
9360ffd1 DM |
7761 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
7762 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
7763 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || | |
7764 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type) || | |
7765 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) | |
7766 | goto nla_put_failure; | |
9588bbd5 | 7767 | |
9360ffd1 DM |
7768 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
7769 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) | |
7770 | goto nla_put_failure; | |
9588bbd5 | 7771 | |
3b7b72ee | 7772 | genlmsg_end(msg, hdr); |
9588bbd5 JM |
7773 | |
7774 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
7775 | nl80211_mlme_mcgrp.id, gfp); | |
7776 | return; | |
7777 | ||
7778 | nla_put_failure: | |
7779 | genlmsg_cancel(msg, hdr); | |
7780 | nlmsg_free(msg); | |
7781 | } | |
7782 | ||
7783 | void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev, | |
7784 | struct net_device *netdev, u64 cookie, | |
7785 | struct ieee80211_channel *chan, | |
7786 | enum nl80211_channel_type channel_type, | |
7787 | unsigned int duration, gfp_t gfp) | |
7788 | { | |
7789 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, | |
7790 | rdev, netdev, cookie, chan, | |
7791 | channel_type, duration, gfp); | |
7792 | } | |
7793 | ||
7794 | void nl80211_send_remain_on_channel_cancel( | |
7795 | struct cfg80211_registered_device *rdev, struct net_device *netdev, | |
7796 | u64 cookie, struct ieee80211_channel *chan, | |
7797 | enum nl80211_channel_type channel_type, gfp_t gfp) | |
7798 | { | |
7799 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
7800 | rdev, netdev, cookie, chan, | |
7801 | channel_type, 0, gfp); | |
7802 | } | |
7803 | ||
98b62183 JB |
7804 | void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, |
7805 | struct net_device *dev, const u8 *mac_addr, | |
7806 | struct station_info *sinfo, gfp_t gfp) | |
7807 | { | |
7808 | struct sk_buff *msg; | |
7809 | ||
7810 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
7811 | if (!msg) | |
7812 | return; | |
7813 | ||
66266b3a JL |
7814 | if (nl80211_send_station(msg, 0, 0, 0, |
7815 | rdev, dev, mac_addr, sinfo) < 0) { | |
98b62183 JB |
7816 | nlmsg_free(msg); |
7817 | return; | |
7818 | } | |
7819 | ||
7820 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
7821 | nl80211_mlme_mcgrp.id, gfp); | |
7822 | } | |
7823 | ||
ec15e68b JM |
7824 | void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev, |
7825 | struct net_device *dev, const u8 *mac_addr, | |
7826 | gfp_t gfp) | |
7827 | { | |
7828 | struct sk_buff *msg; | |
7829 | void *hdr; | |
7830 | ||
7831 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
7832 | if (!msg) | |
7833 | return; | |
7834 | ||
7835 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); | |
7836 | if (!hdr) { | |
7837 | nlmsg_free(msg); | |
7838 | return; | |
7839 | } | |
7840 | ||
9360ffd1 DM |
7841 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
7842 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
7843 | goto nla_put_failure; | |
ec15e68b | 7844 | |
3b7b72ee | 7845 | genlmsg_end(msg, hdr); |
ec15e68b JM |
7846 | |
7847 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
7848 | nl80211_mlme_mcgrp.id, gfp); | |
7849 | return; | |
7850 | ||
7851 | nla_put_failure: | |
7852 | genlmsg_cancel(msg, hdr); | |
7853 | nlmsg_free(msg); | |
7854 | } | |
7855 | ||
b92ab5d8 JB |
7856 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
7857 | const u8 *addr, gfp_t gfp) | |
28946da7 JB |
7858 | { |
7859 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
7860 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
7861 | struct sk_buff *msg; | |
7862 | void *hdr; | |
7863 | int err; | |
7864 | u32 nlpid = ACCESS_ONCE(wdev->ap_unexpected_nlpid); | |
7865 | ||
7866 | if (!nlpid) | |
7867 | return false; | |
7868 | ||
7869 | msg = nlmsg_new(100, gfp); | |
7870 | if (!msg) | |
7871 | return true; | |
7872 | ||
b92ab5d8 | 7873 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
28946da7 JB |
7874 | if (!hdr) { |
7875 | nlmsg_free(msg); | |
7876 | return true; | |
7877 | } | |
7878 | ||
9360ffd1 DM |
7879 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
7880 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
7881 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
7882 | goto nla_put_failure; | |
28946da7 JB |
7883 | |
7884 | err = genlmsg_end(msg, hdr); | |
7885 | if (err < 0) { | |
7886 | nlmsg_free(msg); | |
7887 | return true; | |
7888 | } | |
7889 | ||
7890 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); | |
7891 | return true; | |
7892 | ||
7893 | nla_put_failure: | |
7894 | genlmsg_cancel(msg, hdr); | |
7895 | nlmsg_free(msg); | |
7896 | return true; | |
7897 | } | |
7898 | ||
b92ab5d8 JB |
7899 | bool nl80211_unexpected_frame(struct net_device *dev, const u8 *addr, gfp_t gfp) |
7900 | { | |
7901 | return __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, | |
7902 | addr, gfp); | |
7903 | } | |
7904 | ||
7905 | bool nl80211_unexpected_4addr_frame(struct net_device *dev, | |
7906 | const u8 *addr, gfp_t gfp) | |
7907 | { | |
7908 | return __nl80211_unexpected_frame(dev, | |
7909 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, | |
7910 | addr, gfp); | |
7911 | } | |
7912 | ||
2e161f78 JB |
7913 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
7914 | struct net_device *netdev, u32 nlpid, | |
804483e9 JB |
7915 | int freq, int sig_dbm, |
7916 | const u8 *buf, size_t len, gfp_t gfp) | |
026331c4 JM |
7917 | { |
7918 | struct sk_buff *msg; | |
7919 | void *hdr; | |
026331c4 JM |
7920 | |
7921 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
7922 | if (!msg) | |
7923 | return -ENOMEM; | |
7924 | ||
2e161f78 | 7925 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
026331c4 JM |
7926 | if (!hdr) { |
7927 | nlmsg_free(msg); | |
7928 | return -ENOMEM; | |
7929 | } | |
7930 | ||
9360ffd1 DM |
7931 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
7932 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
7933 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || | |
7934 | (sig_dbm && | |
7935 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
7936 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
7937 | goto nla_put_failure; | |
026331c4 | 7938 | |
3b7b72ee | 7939 | genlmsg_end(msg, hdr); |
026331c4 | 7940 | |
3b7b72ee | 7941 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); |
026331c4 JM |
7942 | |
7943 | nla_put_failure: | |
7944 | genlmsg_cancel(msg, hdr); | |
7945 | nlmsg_free(msg); | |
7946 | return -ENOBUFS; | |
7947 | } | |
7948 | ||
2e161f78 JB |
7949 | void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev, |
7950 | struct net_device *netdev, u64 cookie, | |
7951 | const u8 *buf, size_t len, bool ack, | |
7952 | gfp_t gfp) | |
026331c4 JM |
7953 | { |
7954 | struct sk_buff *msg; | |
7955 | void *hdr; | |
7956 | ||
7957 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
7958 | if (!msg) | |
7959 | return; | |
7960 | ||
2e161f78 | 7961 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
026331c4 JM |
7962 | if (!hdr) { |
7963 | nlmsg_free(msg); | |
7964 | return; | |
7965 | } | |
7966 | ||
9360ffd1 DM |
7967 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
7968 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
7969 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || | |
7970 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
7971 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
7972 | goto nla_put_failure; | |
026331c4 | 7973 | |
3b7b72ee | 7974 | genlmsg_end(msg, hdr); |
026331c4 JM |
7975 | |
7976 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); | |
7977 | return; | |
7978 | ||
7979 | nla_put_failure: | |
7980 | genlmsg_cancel(msg, hdr); | |
7981 | nlmsg_free(msg); | |
7982 | } | |
7983 | ||
d6dc1a38 JO |
7984 | void |
7985 | nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, | |
7986 | struct net_device *netdev, | |
7987 | enum nl80211_cqm_rssi_threshold_event rssi_event, | |
7988 | gfp_t gfp) | |
7989 | { | |
7990 | struct sk_buff *msg; | |
7991 | struct nlattr *pinfoattr; | |
7992 | void *hdr; | |
7993 | ||
7994 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
7995 | if (!msg) | |
7996 | return; | |
7997 | ||
7998 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
7999 | if (!hdr) { | |
8000 | nlmsg_free(msg); | |
8001 | return; | |
8002 | } | |
8003 | ||
9360ffd1 DM |
8004 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
8005 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
8006 | goto nla_put_failure; | |
d6dc1a38 JO |
8007 | |
8008 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
8009 | if (!pinfoattr) | |
8010 | goto nla_put_failure; | |
8011 | ||
9360ffd1 DM |
8012 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, |
8013 | rssi_event)) | |
8014 | goto nla_put_failure; | |
d6dc1a38 JO |
8015 | |
8016 | nla_nest_end(msg, pinfoattr); | |
8017 | ||
3b7b72ee | 8018 | genlmsg_end(msg, hdr); |
d6dc1a38 JO |
8019 | |
8020 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
8021 | nl80211_mlme_mcgrp.id, gfp); | |
8022 | return; | |
8023 | ||
8024 | nla_put_failure: | |
8025 | genlmsg_cancel(msg, hdr); | |
8026 | nlmsg_free(msg); | |
8027 | } | |
8028 | ||
e5497d76 JB |
8029 | void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
8030 | struct net_device *netdev, const u8 *bssid, | |
8031 | const u8 *replay_ctr, gfp_t gfp) | |
8032 | { | |
8033 | struct sk_buff *msg; | |
8034 | struct nlattr *rekey_attr; | |
8035 | void *hdr; | |
8036 | ||
8037 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
8038 | if (!msg) | |
8039 | return; | |
8040 | ||
8041 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); | |
8042 | if (!hdr) { | |
8043 | nlmsg_free(msg); | |
8044 | return; | |
8045 | } | |
8046 | ||
9360ffd1 DM |
8047 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
8048 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
8049 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
8050 | goto nla_put_failure; | |
e5497d76 JB |
8051 | |
8052 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); | |
8053 | if (!rekey_attr) | |
8054 | goto nla_put_failure; | |
8055 | ||
9360ffd1 DM |
8056 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
8057 | NL80211_REPLAY_CTR_LEN, replay_ctr)) | |
8058 | goto nla_put_failure; | |
e5497d76 JB |
8059 | |
8060 | nla_nest_end(msg, rekey_attr); | |
8061 | ||
3b7b72ee | 8062 | genlmsg_end(msg, hdr); |
e5497d76 JB |
8063 | |
8064 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
8065 | nl80211_mlme_mcgrp.id, gfp); | |
8066 | return; | |
8067 | ||
8068 | nla_put_failure: | |
8069 | genlmsg_cancel(msg, hdr); | |
8070 | nlmsg_free(msg); | |
8071 | } | |
8072 | ||
c9df56b4 JM |
8073 | void nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, |
8074 | struct net_device *netdev, int index, | |
8075 | const u8 *bssid, bool preauth, gfp_t gfp) | |
8076 | { | |
8077 | struct sk_buff *msg; | |
8078 | struct nlattr *attr; | |
8079 | void *hdr; | |
8080 | ||
8081 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
8082 | if (!msg) | |
8083 | return; | |
8084 | ||
8085 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); | |
8086 | if (!hdr) { | |
8087 | nlmsg_free(msg); | |
8088 | return; | |
8089 | } | |
8090 | ||
9360ffd1 DM |
8091 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
8092 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
8093 | goto nla_put_failure; | |
c9df56b4 JM |
8094 | |
8095 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); | |
8096 | if (!attr) | |
8097 | goto nla_put_failure; | |
8098 | ||
9360ffd1 DM |
8099 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
8100 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || | |
8101 | (preauth && | |
8102 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) | |
8103 | goto nla_put_failure; | |
c9df56b4 JM |
8104 | |
8105 | nla_nest_end(msg, attr); | |
8106 | ||
3b7b72ee | 8107 | genlmsg_end(msg, hdr); |
c9df56b4 JM |
8108 | |
8109 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
8110 | nl80211_mlme_mcgrp.id, gfp); | |
8111 | return; | |
8112 | ||
8113 | nla_put_failure: | |
8114 | genlmsg_cancel(msg, hdr); | |
8115 | nlmsg_free(msg); | |
8116 | } | |
8117 | ||
5314526b TP |
8118 | void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, |
8119 | struct net_device *netdev, int freq, | |
8120 | enum nl80211_channel_type type, gfp_t gfp) | |
8121 | { | |
8122 | struct sk_buff *msg; | |
8123 | void *hdr; | |
8124 | ||
8125 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
8126 | if (!msg) | |
8127 | return; | |
8128 | ||
8129 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CH_SWITCH_NOTIFY); | |
8130 | if (!hdr) { | |
8131 | nlmsg_free(msg); | |
8132 | return; | |
8133 | } | |
8134 | ||
7eab0f64 JL |
8135 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || |
8136 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || | |
8137 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, type)) | |
8138 | goto nla_put_failure; | |
5314526b TP |
8139 | |
8140 | genlmsg_end(msg, hdr); | |
8141 | ||
8142 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
8143 | nl80211_mlme_mcgrp.id, gfp); | |
8144 | return; | |
8145 | ||
8146 | nla_put_failure: | |
8147 | genlmsg_cancel(msg, hdr); | |
8148 | nlmsg_free(msg); | |
8149 | } | |
8150 | ||
c063dbf5 JB |
8151 | void |
8152 | nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev, | |
8153 | struct net_device *netdev, const u8 *peer, | |
8154 | u32 num_packets, gfp_t gfp) | |
8155 | { | |
8156 | struct sk_buff *msg; | |
8157 | struct nlattr *pinfoattr; | |
8158 | void *hdr; | |
8159 | ||
8160 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
8161 | if (!msg) | |
8162 | return; | |
8163 | ||
8164 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
8165 | if (!hdr) { | |
8166 | nlmsg_free(msg); | |
8167 | return; | |
8168 | } | |
8169 | ||
9360ffd1 DM |
8170 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
8171 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
8172 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) | |
8173 | goto nla_put_failure; | |
c063dbf5 JB |
8174 | |
8175 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
8176 | if (!pinfoattr) | |
8177 | goto nla_put_failure; | |
8178 | ||
9360ffd1 DM |
8179 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) |
8180 | goto nla_put_failure; | |
c063dbf5 JB |
8181 | |
8182 | nla_nest_end(msg, pinfoattr); | |
8183 | ||
3b7b72ee | 8184 | genlmsg_end(msg, hdr); |
c063dbf5 JB |
8185 | |
8186 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
8187 | nl80211_mlme_mcgrp.id, gfp); | |
8188 | return; | |
8189 | ||
8190 | nla_put_failure: | |
8191 | genlmsg_cancel(msg, hdr); | |
8192 | nlmsg_free(msg); | |
8193 | } | |
8194 | ||
7f6cf311 JB |
8195 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
8196 | u64 cookie, bool acked, gfp_t gfp) | |
8197 | { | |
8198 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
8199 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wdev->wiphy); | |
8200 | struct sk_buff *msg; | |
8201 | void *hdr; | |
8202 | int err; | |
8203 | ||
8204 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
8205 | if (!msg) | |
8206 | return; | |
8207 | ||
8208 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); | |
8209 | if (!hdr) { | |
8210 | nlmsg_free(msg); | |
8211 | return; | |
8212 | } | |
8213 | ||
9360ffd1 DM |
8214 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
8215 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
8216 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
8217 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
8218 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
8219 | goto nla_put_failure; | |
7f6cf311 JB |
8220 | |
8221 | err = genlmsg_end(msg, hdr); | |
8222 | if (err < 0) { | |
8223 | nlmsg_free(msg); | |
8224 | return; | |
8225 | } | |
8226 | ||
8227 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
8228 | nl80211_mlme_mcgrp.id, gfp); | |
8229 | return; | |
8230 | ||
8231 | nla_put_failure: | |
8232 | genlmsg_cancel(msg, hdr); | |
8233 | nlmsg_free(msg); | |
8234 | } | |
8235 | EXPORT_SYMBOL(cfg80211_probe_status); | |
8236 | ||
5e760230 JB |
8237 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
8238 | const u8 *frame, size_t len, | |
804483e9 | 8239 | int freq, int sig_dbm, gfp_t gfp) |
5e760230 JB |
8240 | { |
8241 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
8242 | struct sk_buff *msg; | |
8243 | void *hdr; | |
8244 | u32 nlpid = ACCESS_ONCE(rdev->ap_beacons_nlpid); | |
8245 | ||
8246 | if (!nlpid) | |
8247 | return; | |
8248 | ||
8249 | msg = nlmsg_new(len + 100, gfp); | |
8250 | if (!msg) | |
8251 | return; | |
8252 | ||
8253 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); | |
8254 | if (!hdr) { | |
8255 | nlmsg_free(msg); | |
8256 | return; | |
8257 | } | |
8258 | ||
9360ffd1 DM |
8259 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
8260 | (freq && | |
8261 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || | |
8262 | (sig_dbm && | |
8263 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
8264 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) | |
8265 | goto nla_put_failure; | |
5e760230 JB |
8266 | |
8267 | genlmsg_end(msg, hdr); | |
8268 | ||
8269 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); | |
8270 | return; | |
8271 | ||
8272 | nla_put_failure: | |
8273 | genlmsg_cancel(msg, hdr); | |
8274 | nlmsg_free(msg); | |
8275 | } | |
8276 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); | |
8277 | ||
026331c4 JM |
8278 | static int nl80211_netlink_notify(struct notifier_block * nb, |
8279 | unsigned long state, | |
8280 | void *_notify) | |
8281 | { | |
8282 | struct netlink_notify *notify = _notify; | |
8283 | struct cfg80211_registered_device *rdev; | |
8284 | struct wireless_dev *wdev; | |
8285 | ||
8286 | if (state != NETLINK_URELEASE) | |
8287 | return NOTIFY_DONE; | |
8288 | ||
8289 | rcu_read_lock(); | |
8290 | ||
5e760230 | 8291 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
026331c4 | 8292 | list_for_each_entry_rcu(wdev, &rdev->netdev_list, list) |
2e161f78 | 8293 | cfg80211_mlme_unregister_socket(wdev, notify->pid); |
5e760230 JB |
8294 | if (rdev->ap_beacons_nlpid == notify->pid) |
8295 | rdev->ap_beacons_nlpid = 0; | |
8296 | } | |
026331c4 JM |
8297 | |
8298 | rcu_read_unlock(); | |
8299 | ||
8300 | return NOTIFY_DONE; | |
8301 | } | |
8302 | ||
8303 | static struct notifier_block nl80211_netlink_notifier = { | |
8304 | .notifier_call = nl80211_netlink_notify, | |
8305 | }; | |
8306 | ||
55682965 JB |
8307 | /* initialisation/exit functions */ |
8308 | ||
8309 | int nl80211_init(void) | |
8310 | { | |
0d63cbb5 | 8311 | int err; |
55682965 | 8312 | |
0d63cbb5 MM |
8313 | err = genl_register_family_with_ops(&nl80211_fam, |
8314 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); | |
55682965 JB |
8315 | if (err) |
8316 | return err; | |
8317 | ||
55682965 JB |
8318 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
8319 | if (err) | |
8320 | goto err_out; | |
8321 | ||
2a519311 JB |
8322 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
8323 | if (err) | |
8324 | goto err_out; | |
8325 | ||
73d54c9e LR |
8326 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
8327 | if (err) | |
8328 | goto err_out; | |
8329 | ||
6039f6d2 JM |
8330 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
8331 | if (err) | |
8332 | goto err_out; | |
8333 | ||
aff89a9b JB |
8334 | #ifdef CONFIG_NL80211_TESTMODE |
8335 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); | |
8336 | if (err) | |
8337 | goto err_out; | |
8338 | #endif | |
8339 | ||
026331c4 JM |
8340 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
8341 | if (err) | |
8342 | goto err_out; | |
8343 | ||
55682965 JB |
8344 | return 0; |
8345 | err_out: | |
8346 | genl_unregister_family(&nl80211_fam); | |
8347 | return err; | |
8348 | } | |
8349 | ||
8350 | void nl80211_exit(void) | |
8351 | { | |
026331c4 | 8352 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
55682965 JB |
8353 | genl_unregister_family(&nl80211_fam); |
8354 | } |