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