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