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