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