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