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