diff options
Diffstat (limited to 'net/wireless/nl80211.c')
-rw-r--r-- | net/wireless/nl80211.c | 3581 |
1 files changed, 2127 insertions, 1454 deletions
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 37902a54e9c1..cea338150d05 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c | |||
@@ -23,6 +23,11 @@ | |||
23 | #include "nl80211.h" | 23 | #include "nl80211.h" |
24 | #include "reg.h" | 24 | #include "reg.h" |
25 | 25 | ||
26 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, | ||
27 | struct genl_info *info); | ||
28 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, | ||
29 | struct genl_info *info); | ||
30 | |||
26 | /* the netlink family */ | 31 | /* the netlink family */ |
27 | static struct genl_family nl80211_fam = { | 32 | static struct genl_family nl80211_fam = { |
28 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ | 33 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
@@ -31,6 +36,8 @@ static struct genl_family nl80211_fam = { | |||
31 | .version = 1, /* no particular meaning now */ | 36 | .version = 1, /* no particular meaning now */ |
32 | .maxattr = NL80211_ATTR_MAX, | 37 | .maxattr = NL80211_ATTR_MAX, |
33 | .netnsok = true, | 38 | .netnsok = true, |
39 | .pre_doit = nl80211_pre_doit, | ||
40 | .post_doit = nl80211_post_doit, | ||
34 | }; | 41 | }; |
35 | 42 | ||
36 | /* internal helper: get rdev and dev */ | 43 | /* internal helper: get rdev and dev */ |
@@ -86,6 +93,7 @@ static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { | |||
86 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, | 93 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
87 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, | 94 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
88 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 }, | 95 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 }, |
96 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, | ||
89 | 97 | ||
90 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, | 98 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
91 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, | 99 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
@@ -113,8 +121,10 @@ static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { | |||
113 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, | 121 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
114 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, | 122 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
115 | .len = NL80211_MAX_SUPP_RATES }, | 123 | .len = NL80211_MAX_SUPP_RATES }, |
124 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, | ||
116 | 125 | ||
117 | [NL80211_ATTR_MESH_PARAMS] = { .type = NLA_NESTED }, | 126 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
127 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, | ||
118 | 128 | ||
119 | [NL80211_ATTR_HT_CAPABILITY] = { .type = NLA_BINARY, | 129 | [NL80211_ATTR_HT_CAPABILITY] = { .type = NLA_BINARY, |
120 | .len = NL80211_HT_CAPABILITY_LEN }, | 130 | .len = NL80211_HT_CAPABILITY_LEN }, |
@@ -136,6 +146,8 @@ static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { | |||
136 | .len = sizeof(struct nl80211_sta_flag_update), | 146 | .len = sizeof(struct nl80211_sta_flag_update), |
137 | }, | 147 | }, |
138 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, | 148 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
149 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, | ||
150 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, | ||
139 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, | 151 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
140 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, | 152 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
141 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, | 153 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
@@ -153,12 +165,20 @@ static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { | |||
153 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, | 165 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
154 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, | 166 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
155 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, | 167 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
156 | |||
157 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, | 168 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
158 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, | 169 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, |
170 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, | ||
171 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, | ||
172 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, | ||
173 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, | ||
174 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, | ||
175 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, | ||
176 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, | ||
177 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, | ||
178 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, | ||
159 | }; | 179 | }; |
160 | 180 | ||
161 | /* policy for the attributes */ | 181 | /* policy for the key attributes */ |
162 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { | 182 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
163 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, | 183 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
164 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, | 184 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
@@ -166,6 +186,24 @@ static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { | |||
166 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 }, | 186 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 }, |
167 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, | 187 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
168 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, | 188 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
189 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, | ||
190 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, | ||
191 | }; | ||
192 | |||
193 | /* policy for the key default flags */ | ||
194 | static const struct nla_policy | ||
195 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { | ||
196 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, | ||
197 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, | ||
198 | }; | ||
199 | |||
200 | /* policy for WoWLAN attributes */ | ||
201 | static const struct nla_policy | ||
202 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { | ||
203 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, | ||
204 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, | ||
205 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, | ||
206 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, | ||
169 | }; | 207 | }; |
170 | 208 | ||
171 | /* ifidx get helper */ | 209 | /* ifidx get helper */ |
@@ -188,6 +226,47 @@ static int nl80211_get_ifidx(struct netlink_callback *cb) | |||
188 | return res; | 226 | return res; |
189 | } | 227 | } |
190 | 228 | ||
229 | static int nl80211_prepare_netdev_dump(struct sk_buff *skb, | ||
230 | struct netlink_callback *cb, | ||
231 | struct cfg80211_registered_device **rdev, | ||
232 | struct net_device **dev) | ||
233 | { | ||
234 | int ifidx = cb->args[0]; | ||
235 | int err; | ||
236 | |||
237 | if (!ifidx) | ||
238 | ifidx = nl80211_get_ifidx(cb); | ||
239 | if (ifidx < 0) | ||
240 | return ifidx; | ||
241 | |||
242 | cb->args[0] = ifidx; | ||
243 | |||
244 | rtnl_lock(); | ||
245 | |||
246 | *dev = __dev_get_by_index(sock_net(skb->sk), ifidx); | ||
247 | if (!*dev) { | ||
248 | err = -ENODEV; | ||
249 | goto out_rtnl; | ||
250 | } | ||
251 | |||
252 | *rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); | ||
253 | if (IS_ERR(*rdev)) { | ||
254 | err = PTR_ERR(*rdev); | ||
255 | goto out_rtnl; | ||
256 | } | ||
257 | |||
258 | return 0; | ||
259 | out_rtnl: | ||
260 | rtnl_unlock(); | ||
261 | return err; | ||
262 | } | ||
263 | |||
264 | static void nl80211_finish_netdev_dump(struct cfg80211_registered_device *rdev) | ||
265 | { | ||
266 | cfg80211_unlock_rdev(rdev); | ||
267 | rtnl_unlock(); | ||
268 | } | ||
269 | |||
191 | /* IE validation */ | 270 | /* IE validation */ |
192 | static bool is_valid_ie_attr(const struct nlattr *attr) | 271 | static bool is_valid_ie_attr(const struct nlattr *attr) |
193 | { | 272 | { |
@@ -255,7 +334,9 @@ static int nl80211_msg_put_channel(struct sk_buff *msg, | |||
255 | struct key_parse { | 334 | struct key_parse { |
256 | struct key_params p; | 335 | struct key_params p; |
257 | int idx; | 336 | int idx; |
337 | int type; | ||
258 | bool def, defmgmt; | 338 | bool def, defmgmt; |
339 | bool def_uni, def_multi; | ||
259 | }; | 340 | }; |
260 | 341 | ||
261 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) | 342 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
@@ -269,6 +350,13 @@ static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) | |||
269 | k->def = !!tb[NL80211_KEY_DEFAULT]; | 350 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
270 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; | 351 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
271 | 352 | ||
353 | if (k->def) { | ||
354 | k->def_uni = true; | ||
355 | k->def_multi = true; | ||
356 | } | ||
357 | if (k->defmgmt) | ||
358 | k->def_multi = true; | ||
359 | |||
272 | if (tb[NL80211_KEY_IDX]) | 360 | if (tb[NL80211_KEY_IDX]) |
273 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); | 361 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
274 | 362 | ||
@@ -285,6 +373,25 @@ static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) | |||
285 | if (tb[NL80211_KEY_CIPHER]) | 373 | if (tb[NL80211_KEY_CIPHER]) |
286 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); | 374 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
287 | 375 | ||
376 | if (tb[NL80211_KEY_TYPE]) { | ||
377 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); | ||
378 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | ||
379 | return -EINVAL; | ||
380 | } | ||
381 | |||
382 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { | ||
383 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | ||
384 | int err = nla_parse_nested(kdt, | ||
385 | NUM_NL80211_KEY_DEFAULT_TYPES - 1, | ||
386 | tb[NL80211_KEY_DEFAULT_TYPES], | ||
387 | nl80211_key_default_policy); | ||
388 | if (err) | ||
389 | return err; | ||
390 | |||
391 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | ||
392 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | ||
393 | } | ||
394 | |||
288 | return 0; | 395 | return 0; |
289 | } | 396 | } |
290 | 397 | ||
@@ -309,6 +416,32 @@ static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) | |||
309 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; | 416 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
310 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; | 417 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
311 | 418 | ||
419 | if (k->def) { | ||
420 | k->def_uni = true; | ||
421 | k->def_multi = true; | ||
422 | } | ||
423 | if (k->defmgmt) | ||
424 | k->def_multi = true; | ||
425 | |||
426 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { | ||
427 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | ||
428 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | ||
429 | return -EINVAL; | ||
430 | } | ||
431 | |||
432 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { | ||
433 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | ||
434 | int err = nla_parse_nested( | ||
435 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, | ||
436 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], | ||
437 | nl80211_key_default_policy); | ||
438 | if (err) | ||
439 | return err; | ||
440 | |||
441 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | ||
442 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | ||
443 | } | ||
444 | |||
312 | return 0; | 445 | return 0; |
313 | } | 446 | } |
314 | 447 | ||
@@ -318,6 +451,7 @@ static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) | |||
318 | 451 | ||
319 | memset(k, 0, sizeof(*k)); | 452 | memset(k, 0, sizeof(*k)); |
320 | k->idx = -1; | 453 | k->idx = -1; |
454 | k->type = -1; | ||
321 | 455 | ||
322 | if (info->attrs[NL80211_ATTR_KEY]) | 456 | if (info->attrs[NL80211_ATTR_KEY]) |
323 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); | 457 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
@@ -330,6 +464,11 @@ static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) | |||
330 | if (k->def && k->defmgmt) | 464 | if (k->def && k->defmgmt) |
331 | return -EINVAL; | 465 | return -EINVAL; |
332 | 466 | ||
467 | if (k->defmgmt) { | ||
468 | if (k->def_uni || !k->def_multi) | ||
469 | return -EINVAL; | ||
470 | } | ||
471 | |||
333 | if (k->idx != -1) { | 472 | if (k->idx != -1) { |
334 | if (k->defmgmt) { | 473 | if (k->defmgmt) { |
335 | if (k->idx < 4 || k->idx > 5) | 474 | if (k->idx < 4 || k->idx > 5) |
@@ -379,10 +518,12 @@ nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, | |||
379 | goto error; | 518 | goto error; |
380 | def = 1; | 519 | def = 1; |
381 | result->def = parse.idx; | 520 | result->def = parse.idx; |
521 | if (!parse.def_uni || !parse.def_multi) | ||
522 | goto error; | ||
382 | } else if (parse.defmgmt) | 523 | } else if (parse.defmgmt) |
383 | goto error; | 524 | goto error; |
384 | err = cfg80211_validate_key_settings(rdev, &parse.p, | 525 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
385 | parse.idx, NULL); | 526 | parse.idx, false, NULL); |
386 | if (err) | 527 | if (err) |
387 | goto error; | 528 | goto error; |
388 | result->params[parse.idx].cipher = parse.p.cipher; | 529 | result->params[parse.idx].cipher = parse.p.cipher; |
@@ -401,18 +542,18 @@ static int nl80211_key_allowed(struct wireless_dev *wdev) | |||
401 | { | 542 | { |
402 | ASSERT_WDEV_LOCK(wdev); | 543 | ASSERT_WDEV_LOCK(wdev); |
403 | 544 | ||
404 | if (!netif_running(wdev->netdev)) | ||
405 | return -ENETDOWN; | ||
406 | |||
407 | switch (wdev->iftype) { | 545 | switch (wdev->iftype) { |
408 | case NL80211_IFTYPE_AP: | 546 | case NL80211_IFTYPE_AP: |
409 | case NL80211_IFTYPE_AP_VLAN: | 547 | case NL80211_IFTYPE_AP_VLAN: |
548 | case NL80211_IFTYPE_P2P_GO: | ||
549 | case NL80211_IFTYPE_MESH_POINT: | ||
410 | break; | 550 | break; |
411 | case NL80211_IFTYPE_ADHOC: | 551 | case NL80211_IFTYPE_ADHOC: |
412 | if (!wdev->current_bss) | 552 | if (!wdev->current_bss) |
413 | return -ENOLINK; | 553 | return -ENOLINK; |
414 | break; | 554 | break; |
415 | case NL80211_IFTYPE_STATION: | 555 | case NL80211_IFTYPE_STATION: |
556 | case NL80211_IFTYPE_P2P_CLIENT: | ||
416 | if (wdev->sme_state != CFG80211_SME_CONNECTED) | 557 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
417 | return -ENOLINK; | 558 | return -ENOLINK; |
418 | break; | 559 | break; |
@@ -423,6 +564,88 @@ static int nl80211_key_allowed(struct wireless_dev *wdev) | |||
423 | return 0; | 564 | return 0; |
424 | } | 565 | } |
425 | 566 | ||
567 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) | ||
568 | { | ||
569 | struct nlattr *nl_modes = nla_nest_start(msg, attr); | ||
570 | int i; | ||
571 | |||
572 | if (!nl_modes) | ||
573 | goto nla_put_failure; | ||
574 | |||
575 | i = 0; | ||
576 | while (ifmodes) { | ||
577 | if (ifmodes & 1) | ||
578 | NLA_PUT_FLAG(msg, i); | ||
579 | ifmodes >>= 1; | ||
580 | i++; | ||
581 | } | ||
582 | |||
583 | nla_nest_end(msg, nl_modes); | ||
584 | return 0; | ||
585 | |||
586 | nla_put_failure: | ||
587 | return -ENOBUFS; | ||
588 | } | ||
589 | |||
590 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, | ||
591 | struct sk_buff *msg) | ||
592 | { | ||
593 | struct nlattr *nl_combis; | ||
594 | int i, j; | ||
595 | |||
596 | nl_combis = nla_nest_start(msg, | ||
597 | NL80211_ATTR_INTERFACE_COMBINATIONS); | ||
598 | if (!nl_combis) | ||
599 | goto nla_put_failure; | ||
600 | |||
601 | for (i = 0; i < wiphy->n_iface_combinations; i++) { | ||
602 | const struct ieee80211_iface_combination *c; | ||
603 | struct nlattr *nl_combi, *nl_limits; | ||
604 | |||
605 | c = &wiphy->iface_combinations[i]; | ||
606 | |||
607 | nl_combi = nla_nest_start(msg, i + 1); | ||
608 | if (!nl_combi) | ||
609 | goto nla_put_failure; | ||
610 | |||
611 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); | ||
612 | if (!nl_limits) | ||
613 | goto nla_put_failure; | ||
614 | |||
615 | for (j = 0; j < c->n_limits; j++) { | ||
616 | struct nlattr *nl_limit; | ||
617 | |||
618 | nl_limit = nla_nest_start(msg, j + 1); | ||
619 | if (!nl_limit) | ||
620 | goto nla_put_failure; | ||
621 | NLA_PUT_U32(msg, NL80211_IFACE_LIMIT_MAX, | ||
622 | c->limits[j].max); | ||
623 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, | ||
624 | c->limits[j].types)) | ||
625 | goto nla_put_failure; | ||
626 | nla_nest_end(msg, nl_limit); | ||
627 | } | ||
628 | |||
629 | nla_nest_end(msg, nl_limits); | ||
630 | |||
631 | if (c->beacon_int_infra_match) | ||
632 | NLA_PUT_FLAG(msg, | ||
633 | NL80211_IFACE_COMB_STA_AP_BI_MATCH); | ||
634 | NLA_PUT_U32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, | ||
635 | c->num_different_channels); | ||
636 | NLA_PUT_U32(msg, NL80211_IFACE_COMB_MAXNUM, | ||
637 | c->max_interfaces); | ||
638 | |||
639 | nla_nest_end(msg, nl_combi); | ||
640 | } | ||
641 | |||
642 | nla_nest_end(msg, nl_combis); | ||
643 | |||
644 | return 0; | ||
645 | nla_put_failure: | ||
646 | return -ENOBUFS; | ||
647 | } | ||
648 | |||
426 | static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, | 649 | static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
427 | struct cfg80211_registered_device *dev) | 650 | struct cfg80211_registered_device *dev) |
428 | { | 651 | { |
@@ -430,13 +653,13 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, | |||
430 | struct nlattr *nl_bands, *nl_band; | 653 | struct nlattr *nl_bands, *nl_band; |
431 | struct nlattr *nl_freqs, *nl_freq; | 654 | struct nlattr *nl_freqs, *nl_freq; |
432 | struct nlattr *nl_rates, *nl_rate; | 655 | struct nlattr *nl_rates, *nl_rate; |
433 | struct nlattr *nl_modes; | ||
434 | struct nlattr *nl_cmds; | 656 | struct nlattr *nl_cmds; |
435 | enum ieee80211_band band; | 657 | enum ieee80211_band band; |
436 | struct ieee80211_channel *chan; | 658 | struct ieee80211_channel *chan; |
437 | struct ieee80211_rate *rate; | 659 | struct ieee80211_rate *rate; |
438 | int i; | 660 | int i; |
439 | u16 ifmodes = dev->wiphy.interface_modes; | 661 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
662 | dev->wiphy.mgmt_stypes; | ||
440 | 663 | ||
441 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY); | 664 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY); |
442 | if (!hdr) | 665 | if (!hdr) |
@@ -458,12 +681,16 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, | |||
458 | dev->wiphy.rts_threshold); | 681 | dev->wiphy.rts_threshold); |
459 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, | 682 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
460 | dev->wiphy.coverage_class); | 683 | dev->wiphy.coverage_class); |
461 | |||
462 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, | 684 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
463 | dev->wiphy.max_scan_ssids); | 685 | dev->wiphy.max_scan_ssids); |
464 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, | 686 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
465 | dev->wiphy.max_scan_ie_len); | 687 | dev->wiphy.max_scan_ie_len); |
466 | 688 | ||
689 | if (dev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) | ||
690 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_IBSS_RSN); | ||
691 | if (dev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) | ||
692 | NLA_PUT_FLAG(msg, NL80211_ATTR_SUPPORT_MESH_AUTH); | ||
693 | |||
467 | NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES, | 694 | NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES, |
468 | sizeof(u32) * dev->wiphy.n_cipher_suites, | 695 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
469 | dev->wiphy.cipher_suites); | 696 | dev->wiphy.cipher_suites); |
@@ -471,19 +698,28 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, | |||
471 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, | 698 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
472 | dev->wiphy.max_num_pmkids); | 699 | dev->wiphy.max_num_pmkids); |
473 | 700 | ||
474 | nl_modes = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_IFTYPES); | 701 | if (dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) |
475 | if (!nl_modes) | 702 | NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE); |
476 | goto nla_put_failure; | 703 | |
477 | 704 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, | |
478 | i = 0; | 705 | dev->wiphy.available_antennas_tx); |
479 | while (ifmodes) { | 706 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
480 | if (ifmodes & 1) | 707 | dev->wiphy.available_antennas_rx); |
481 | NLA_PUT_FLAG(msg, i); | 708 | |
482 | ifmodes >>= 1; | 709 | if ((dev->wiphy.available_antennas_tx || |
483 | i++; | 710 | dev->wiphy.available_antennas_rx) && dev->ops->get_antenna) { |
711 | u32 tx_ant = 0, rx_ant = 0; | ||
712 | int res; | ||
713 | res = dev->ops->get_antenna(&dev->wiphy, &tx_ant, &rx_ant); | ||
714 | if (!res) { | ||
715 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_TX, tx_ant); | ||
716 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_ANTENNA_RX, rx_ant); | ||
717 | } | ||
484 | } | 718 | } |
485 | 719 | ||
486 | nla_nest_end(msg, nl_modes); | 720 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, |
721 | dev->wiphy.interface_modes)) | ||
722 | goto nla_put_failure; | ||
487 | 723 | ||
488 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); | 724 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
489 | if (!nl_bands) | 725 | if (!nl_bands) |
@@ -575,24 +811,29 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, | |||
575 | CMD(add_beacon, NEW_BEACON); | 811 | CMD(add_beacon, NEW_BEACON); |
576 | CMD(add_station, NEW_STATION); | 812 | CMD(add_station, NEW_STATION); |
577 | CMD(add_mpath, NEW_MPATH); | 813 | CMD(add_mpath, NEW_MPATH); |
578 | CMD(set_mesh_params, SET_MESH_PARAMS); | 814 | CMD(update_mesh_config, SET_MESH_CONFIG); |
579 | CMD(change_bss, SET_BSS); | 815 | CMD(change_bss, SET_BSS); |
580 | CMD(auth, AUTHENTICATE); | 816 | CMD(auth, AUTHENTICATE); |
581 | CMD(assoc, ASSOCIATE); | 817 | CMD(assoc, ASSOCIATE); |
582 | CMD(deauth, DEAUTHENTICATE); | 818 | CMD(deauth, DEAUTHENTICATE); |
583 | CMD(disassoc, DISASSOCIATE); | 819 | CMD(disassoc, DISASSOCIATE); |
584 | CMD(join_ibss, JOIN_IBSS); | 820 | CMD(join_ibss, JOIN_IBSS); |
821 | CMD(join_mesh, JOIN_MESH); | ||
585 | CMD(set_pmksa, SET_PMKSA); | 822 | CMD(set_pmksa, SET_PMKSA); |
586 | CMD(del_pmksa, DEL_PMKSA); | 823 | CMD(del_pmksa, DEL_PMKSA); |
587 | CMD(flush_pmksa, FLUSH_PMKSA); | 824 | CMD(flush_pmksa, FLUSH_PMKSA); |
588 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); | 825 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
589 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); | 826 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
590 | CMD(action, ACTION); | 827 | CMD(mgmt_tx, FRAME); |
828 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); | ||
591 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { | 829 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
592 | i++; | 830 | i++; |
593 | NLA_PUT_U32(msg, i, NL80211_CMD_SET_WIPHY_NETNS); | 831 | NLA_PUT_U32(msg, i, NL80211_CMD_SET_WIPHY_NETNS); |
594 | } | 832 | } |
595 | CMD(set_channel, SET_CHANNEL); | 833 | CMD(set_channel, SET_CHANNEL); |
834 | CMD(set_wds_peer, SET_WDS_PEER); | ||
835 | if (dev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) | ||
836 | CMD(sched_scan_start, START_SCHED_SCAN); | ||
596 | 837 | ||
597 | #undef CMD | 838 | #undef CMD |
598 | 839 | ||
@@ -608,6 +849,99 @@ static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, | |||
608 | 849 | ||
609 | nla_nest_end(msg, nl_cmds); | 850 | nla_nest_end(msg, nl_cmds); |
610 | 851 | ||
852 | if (dev->ops->remain_on_channel) | ||
853 | NLA_PUT_U32(msg, NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, | ||
854 | dev->wiphy.max_remain_on_channel_duration); | ||
855 | |||
856 | /* for now at least assume all drivers have it */ | ||
857 | if (dev->ops->mgmt_tx) | ||
858 | NLA_PUT_FLAG(msg, NL80211_ATTR_OFFCHANNEL_TX_OK); | ||
859 | |||
860 | if (mgmt_stypes) { | ||
861 | u16 stypes; | ||
862 | struct nlattr *nl_ftypes, *nl_ifs; | ||
863 | enum nl80211_iftype ift; | ||
864 | |||
865 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); | ||
866 | if (!nl_ifs) | ||
867 | goto nla_put_failure; | ||
868 | |||
869 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { | ||
870 | nl_ftypes = nla_nest_start(msg, ift); | ||
871 | if (!nl_ftypes) | ||
872 | goto nla_put_failure; | ||
873 | i = 0; | ||
874 | stypes = mgmt_stypes[ift].tx; | ||
875 | while (stypes) { | ||
876 | if (stypes & 1) | ||
877 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, | ||
878 | (i << 4) | IEEE80211_FTYPE_MGMT); | ||
879 | stypes >>= 1; | ||
880 | i++; | ||
881 | } | ||
882 | nla_nest_end(msg, nl_ftypes); | ||
883 | } | ||
884 | |||
885 | nla_nest_end(msg, nl_ifs); | ||
886 | |||
887 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); | ||
888 | if (!nl_ifs) | ||
889 | goto nla_put_failure; | ||
890 | |||
891 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { | ||
892 | nl_ftypes = nla_nest_start(msg, ift); | ||
893 | if (!nl_ftypes) | ||
894 | goto nla_put_failure; | ||
895 | i = 0; | ||
896 | stypes = mgmt_stypes[ift].rx; | ||
897 | while (stypes) { | ||
898 | if (stypes & 1) | ||
899 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, | ||
900 | (i << 4) | IEEE80211_FTYPE_MGMT); | ||
901 | stypes >>= 1; | ||
902 | i++; | ||
903 | } | ||
904 | nla_nest_end(msg, nl_ftypes); | ||
905 | } | ||
906 | nla_nest_end(msg, nl_ifs); | ||
907 | } | ||
908 | |||
909 | if (dev->wiphy.wowlan.flags || dev->wiphy.wowlan.n_patterns) { | ||
910 | struct nlattr *nl_wowlan; | ||
911 | |||
912 | nl_wowlan = nla_nest_start(msg, | ||
913 | NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); | ||
914 | if (!nl_wowlan) | ||
915 | goto nla_put_failure; | ||
916 | |||
917 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_ANY) | ||
918 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY); | ||
919 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_DISCONNECT) | ||
920 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT); | ||
921 | if (dev->wiphy.wowlan.flags & WIPHY_WOWLAN_MAGIC_PKT) | ||
922 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT); | ||
923 | if (dev->wiphy.wowlan.n_patterns) { | ||
924 | struct nl80211_wowlan_pattern_support pat = { | ||
925 | .max_patterns = dev->wiphy.wowlan.n_patterns, | ||
926 | .min_pattern_len = | ||
927 | dev->wiphy.wowlan.pattern_min_len, | ||
928 | .max_pattern_len = | ||
929 | dev->wiphy.wowlan.pattern_max_len, | ||
930 | }; | ||
931 | NLA_PUT(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, | ||
932 | sizeof(pat), &pat); | ||
933 | } | ||
934 | |||
935 | nla_nest_end(msg, nl_wowlan); | ||
936 | } | ||
937 | |||
938 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, | ||
939 | dev->wiphy.software_iftypes)) | ||
940 | goto nla_put_failure; | ||
941 | |||
942 | if (nl80211_put_iface_combinations(&dev->wiphy, msg)) | ||
943 | goto nla_put_failure; | ||
944 | |||
611 | return genlmsg_end(msg, hdr); | 945 | return genlmsg_end(msg, hdr); |
612 | 946 | ||
613 | nla_put_failure: | 947 | nla_put_failure: |
@@ -644,28 +978,18 @@ static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) | |||
644 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) | 978 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
645 | { | 979 | { |
646 | struct sk_buff *msg; | 980 | struct sk_buff *msg; |
647 | struct cfg80211_registered_device *dev; | 981 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
648 | |||
649 | dev = cfg80211_get_dev_from_info(info); | ||
650 | if (IS_ERR(dev)) | ||
651 | return PTR_ERR(dev); | ||
652 | 982 | ||
653 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 983 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
654 | if (!msg) | 984 | if (!msg) |
655 | goto out_err; | 985 | return -ENOMEM; |
656 | |||
657 | if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) | ||
658 | goto out_free; | ||
659 | 986 | ||
660 | cfg80211_unlock_rdev(dev); | 987 | if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) { |
988 | nlmsg_free(msg); | ||
989 | return -ENOBUFS; | ||
990 | } | ||
661 | 991 | ||
662 | return genlmsg_reply(msg, info); | 992 | return genlmsg_reply(msg, info); |
663 | |||
664 | out_free: | ||
665 | nlmsg_free(msg); | ||
666 | out_err: | ||
667 | cfg80211_unlock_rdev(dev); | ||
668 | return -ENOBUFS; | ||
669 | } | 993 | } |
670 | 994 | ||
671 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { | 995 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
@@ -709,7 +1033,8 @@ static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) | |||
709 | wdev->iftype == NL80211_IFTYPE_AP || | 1033 | wdev->iftype == NL80211_IFTYPE_AP || |
710 | wdev->iftype == NL80211_IFTYPE_WDS || | 1034 | wdev->iftype == NL80211_IFTYPE_WDS || |
711 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || | 1035 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
712 | wdev->iftype == NL80211_IFTYPE_MONITOR; | 1036 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
1037 | wdev->iftype == NL80211_IFTYPE_P2P_GO; | ||
713 | } | 1038 | } |
714 | 1039 | ||
715 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, | 1040 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
@@ -753,38 +1078,48 @@ static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, | |||
753 | 1078 | ||
754 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) | 1079 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) |
755 | { | 1080 | { |
756 | struct cfg80211_registered_device *rdev; | 1081 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
757 | struct net_device *netdev; | 1082 | struct net_device *netdev = info->user_ptr[1]; |
758 | int result; | ||
759 | 1083 | ||
760 | rtnl_lock(); | 1084 | return __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); |
1085 | } | ||
761 | 1086 | ||
762 | result = get_rdev_dev_by_info_ifindex(info, &rdev, &netdev); | 1087 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
763 | if (result) | 1088 | { |
764 | goto unlock; | 1089 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1090 | struct net_device *dev = info->user_ptr[1]; | ||
1091 | struct wireless_dev *wdev = dev->ieee80211_ptr; | ||
1092 | const u8 *bssid; | ||
765 | 1093 | ||
766 | result = __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); | 1094 | if (!info->attrs[NL80211_ATTR_MAC]) |
1095 | return -EINVAL; | ||
767 | 1096 | ||
768 | unlock: | 1097 | if (netif_running(dev)) |
769 | rtnl_unlock(); | 1098 | return -EBUSY; |
770 | 1099 | ||
771 | return result; | 1100 | if (!rdev->ops->set_wds_peer) |
1101 | return -EOPNOTSUPP; | ||
1102 | |||
1103 | if (wdev->iftype != NL80211_IFTYPE_WDS) | ||
1104 | return -EOPNOTSUPP; | ||
1105 | |||
1106 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | ||
1107 | return rdev->ops->set_wds_peer(wdev->wiphy, dev, bssid); | ||
772 | } | 1108 | } |
773 | 1109 | ||
1110 | |||
774 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) | 1111 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
775 | { | 1112 | { |
776 | struct cfg80211_registered_device *rdev; | 1113 | struct cfg80211_registered_device *rdev; |
777 | struct net_device *netdev = NULL; | 1114 | struct net_device *netdev = NULL; |
778 | struct wireless_dev *wdev; | 1115 | struct wireless_dev *wdev; |
779 | int result, rem_txq_params = 0; | 1116 | int result = 0, rem_txq_params = 0; |
780 | struct nlattr *nl_txq_params; | 1117 | struct nlattr *nl_txq_params; |
781 | u32 changed; | 1118 | u32 changed; |
782 | u8 retry_short = 0, retry_long = 0; | 1119 | u8 retry_short = 0, retry_long = 0; |
783 | u32 frag_threshold = 0, rts_threshold = 0; | 1120 | u32 frag_threshold = 0, rts_threshold = 0; |
784 | u8 coverage_class = 0; | 1121 | u8 coverage_class = 0; |
785 | 1122 | ||
786 | rtnl_lock(); | ||
787 | |||
788 | /* | 1123 | /* |
789 | * Try to find the wiphy and netdev. Normally this | 1124 | * Try to find the wiphy and netdev. Normally this |
790 | * function shouldn't need the netdev, but this is | 1125 | * function shouldn't need the netdev, but this is |
@@ -811,8 +1146,7 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) | |||
811 | rdev = __cfg80211_rdev_from_info(info); | 1146 | rdev = __cfg80211_rdev_from_info(info); |
812 | if (IS_ERR(rdev)) { | 1147 | if (IS_ERR(rdev)) { |
813 | mutex_unlock(&cfg80211_mutex); | 1148 | mutex_unlock(&cfg80211_mutex); |
814 | result = PTR_ERR(rdev); | 1149 | return PTR_ERR(rdev); |
815 | goto unlock; | ||
816 | } | 1150 | } |
817 | wdev = NULL; | 1151 | wdev = NULL; |
818 | netdev = NULL; | 1152 | netdev = NULL; |
@@ -900,6 +1234,35 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) | |||
900 | goto bad_res; | 1234 | goto bad_res; |
901 | } | 1235 | } |
902 | 1236 | ||
1237 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && | ||
1238 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { | ||
1239 | u32 tx_ant, rx_ant; | ||
1240 | if ((!rdev->wiphy.available_antennas_tx && | ||
1241 | !rdev->wiphy.available_antennas_rx) || | ||
1242 | !rdev->ops->set_antenna) { | ||
1243 | result = -EOPNOTSUPP; | ||
1244 | goto bad_res; | ||
1245 | } | ||
1246 | |||
1247 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); | ||
1248 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); | ||
1249 | |||
1250 | /* reject antenna configurations which don't match the | ||
1251 | * available antenna masks, except for the "all" mask */ | ||
1252 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || | ||
1253 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) { | ||
1254 | result = -EINVAL; | ||
1255 | goto bad_res; | ||
1256 | } | ||
1257 | |||
1258 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; | ||
1259 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; | ||
1260 | |||
1261 | result = rdev->ops->set_antenna(&rdev->wiphy, tx_ant, rx_ant); | ||
1262 | if (result) | ||
1263 | goto bad_res; | ||
1264 | } | ||
1265 | |||
903 | changed = 0; | 1266 | changed = 0; |
904 | 1267 | ||
905 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { | 1268 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
@@ -994,8 +1357,6 @@ static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) | |||
994 | mutex_unlock(&rdev->mtx); | 1357 | mutex_unlock(&rdev->mtx); |
995 | if (netdev) | 1358 | if (netdev) |
996 | dev_put(netdev); | 1359 | dev_put(netdev); |
997 | unlock: | ||
998 | rtnl_unlock(); | ||
999 | return result; | 1360 | return result; |
1000 | } | 1361 | } |
1001 | 1362 | ||
@@ -1075,33 +1436,20 @@ static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback * | |||
1075 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) | 1436 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
1076 | { | 1437 | { |
1077 | struct sk_buff *msg; | 1438 | struct sk_buff *msg; |
1078 | struct cfg80211_registered_device *dev; | 1439 | struct cfg80211_registered_device *dev = info->user_ptr[0]; |
1079 | struct net_device *netdev; | 1440 | struct net_device *netdev = info->user_ptr[1]; |
1080 | int err; | ||
1081 | |||
1082 | err = get_rdev_dev_by_info_ifindex(info, &dev, &netdev); | ||
1083 | if (err) | ||
1084 | return err; | ||
1085 | 1441 | ||
1086 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 1442 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
1087 | if (!msg) | 1443 | if (!msg) |
1088 | goto out_err; | 1444 | return -ENOMEM; |
1089 | 1445 | ||
1090 | if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0, | 1446 | if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0, |
1091 | dev, netdev) < 0) | 1447 | dev, netdev) < 0) { |
1092 | goto out_free; | 1448 | nlmsg_free(msg); |
1093 | 1449 | return -ENOBUFS; | |
1094 | dev_put(netdev); | 1450 | } |
1095 | cfg80211_unlock_rdev(dev); | ||
1096 | 1451 | ||
1097 | return genlmsg_reply(msg, info); | 1452 | return genlmsg_reply(msg, info); |
1098 | |||
1099 | out_free: | ||
1100 | nlmsg_free(msg); | ||
1101 | out_err: | ||
1102 | dev_put(netdev); | ||
1103 | cfg80211_unlock_rdev(dev); | ||
1104 | return -ENOBUFS; | ||
1105 | } | 1453 | } |
1106 | 1454 | ||
1107 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { | 1455 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
@@ -1161,42 +1509,42 @@ static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, | |||
1161 | 1509 | ||
1162 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) | 1510 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
1163 | { | 1511 | { |
1164 | struct cfg80211_registered_device *rdev; | 1512 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1165 | struct vif_params params; | 1513 | struct vif_params params; |
1166 | int err; | 1514 | int err; |
1167 | enum nl80211_iftype otype, ntype; | 1515 | enum nl80211_iftype otype, ntype; |
1168 | struct net_device *dev; | 1516 | struct net_device *dev = info->user_ptr[1]; |
1169 | u32 _flags, *flags = NULL; | 1517 | u32 _flags, *flags = NULL; |
1170 | bool change = false; | 1518 | bool change = false; |
1171 | 1519 | ||
1172 | memset(¶ms, 0, sizeof(params)); | 1520 | memset(¶ms, 0, sizeof(params)); |
1173 | 1521 | ||
1174 | rtnl_lock(); | ||
1175 | |||
1176 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | ||
1177 | if (err) | ||
1178 | goto unlock_rtnl; | ||
1179 | |||
1180 | otype = ntype = dev->ieee80211_ptr->iftype; | 1522 | otype = ntype = dev->ieee80211_ptr->iftype; |
1181 | 1523 | ||
1182 | if (info->attrs[NL80211_ATTR_IFTYPE]) { | 1524 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
1183 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); | 1525 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
1184 | if (otype != ntype) | 1526 | if (otype != ntype) |
1185 | change = true; | 1527 | change = true; |
1186 | if (ntype > NL80211_IFTYPE_MAX) { | 1528 | if (ntype > NL80211_IFTYPE_MAX) |
1187 | err = -EINVAL; | 1529 | return -EINVAL; |
1188 | goto unlock; | ||
1189 | } | ||
1190 | } | 1530 | } |
1191 | 1531 | ||
1192 | if (info->attrs[NL80211_ATTR_MESH_ID]) { | 1532 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
1193 | if (ntype != NL80211_IFTYPE_MESH_POINT) { | 1533 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
1194 | err = -EINVAL; | 1534 | |
1195 | goto unlock; | 1535 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
1196 | } | 1536 | return -EINVAL; |
1197 | params.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); | 1537 | if (netif_running(dev)) |
1198 | params.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | 1538 | return -EBUSY; |
1199 | change = true; | 1539 | |
1540 | wdev_lock(wdev); | ||
1541 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | ||
1542 | IEEE80211_MAX_MESH_ID_LEN); | ||
1543 | wdev->mesh_id_up_len = | ||
1544 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | ||
1545 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | ||
1546 | wdev->mesh_id_up_len); | ||
1547 | wdev_unlock(wdev); | ||
1200 | } | 1548 | } |
1201 | 1549 | ||
1202 | if (info->attrs[NL80211_ATTR_4ADDR]) { | 1550 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
@@ -1204,20 +1552,18 @@ static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) | |||
1204 | change = true; | 1552 | change = true; |
1205 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); | 1553 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
1206 | if (err) | 1554 | if (err) |
1207 | goto unlock; | 1555 | return err; |
1208 | } else { | 1556 | } else { |
1209 | params.use_4addr = -1; | 1557 | params.use_4addr = -1; |
1210 | } | 1558 | } |
1211 | 1559 | ||
1212 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { | 1560 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
1213 | if (ntype != NL80211_IFTYPE_MONITOR) { | 1561 | if (ntype != NL80211_IFTYPE_MONITOR) |
1214 | err = -EINVAL; | 1562 | return -EINVAL; |
1215 | goto unlock; | ||
1216 | } | ||
1217 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], | 1563 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
1218 | &_flags); | 1564 | &_flags); |
1219 | if (err) | 1565 | if (err) |
1220 | goto unlock; | 1566 | return err; |
1221 | 1567 | ||
1222 | flags = &_flags; | 1568 | flags = &_flags; |
1223 | change = true; | 1569 | change = true; |
@@ -1231,18 +1577,14 @@ static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) | |||
1231 | if (!err && params.use_4addr != -1) | 1577 | if (!err && params.use_4addr != -1) |
1232 | dev->ieee80211_ptr->use_4addr = params.use_4addr; | 1578 | dev->ieee80211_ptr->use_4addr = params.use_4addr; |
1233 | 1579 | ||
1234 | unlock: | ||
1235 | dev_put(dev); | ||
1236 | cfg80211_unlock_rdev(rdev); | ||
1237 | unlock_rtnl: | ||
1238 | rtnl_unlock(); | ||
1239 | return err; | 1580 | return err; |
1240 | } | 1581 | } |
1241 | 1582 | ||
1242 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) | 1583 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
1243 | { | 1584 | { |
1244 | struct cfg80211_registered_device *rdev; | 1585 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1245 | struct vif_params params; | 1586 | struct vif_params params; |
1587 | struct net_device *dev; | ||
1246 | int err; | 1588 | int err; |
1247 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; | 1589 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
1248 | u32 flags; | 1590 | u32 flags; |
@@ -1258,72 +1600,52 @@ static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) | |||
1258 | return -EINVAL; | 1600 | return -EINVAL; |
1259 | } | 1601 | } |
1260 | 1602 | ||
1261 | rtnl_lock(); | ||
1262 | |||
1263 | rdev = cfg80211_get_dev_from_info(info); | ||
1264 | if (IS_ERR(rdev)) { | ||
1265 | err = PTR_ERR(rdev); | ||
1266 | goto unlock_rtnl; | ||
1267 | } | ||
1268 | |||
1269 | if (!rdev->ops->add_virtual_intf || | 1603 | if (!rdev->ops->add_virtual_intf || |
1270 | !(rdev->wiphy.interface_modes & (1 << type))) { | 1604 | !(rdev->wiphy.interface_modes & (1 << type))) |
1271 | err = -EOPNOTSUPP; | 1605 | return -EOPNOTSUPP; |
1272 | goto unlock; | ||
1273 | } | ||
1274 | |||
1275 | if (type == NL80211_IFTYPE_MESH_POINT && | ||
1276 | info->attrs[NL80211_ATTR_MESH_ID]) { | ||
1277 | params.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); | ||
1278 | params.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | ||
1279 | } | ||
1280 | 1606 | ||
1281 | if (info->attrs[NL80211_ATTR_4ADDR]) { | 1607 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
1282 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); | 1608 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
1283 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); | 1609 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
1284 | if (err) | 1610 | if (err) |
1285 | goto unlock; | 1611 | return err; |
1286 | } | 1612 | } |
1287 | 1613 | ||
1288 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? | 1614 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
1289 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, | 1615 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
1290 | &flags); | 1616 | &flags); |
1291 | err = rdev->ops->add_virtual_intf(&rdev->wiphy, | 1617 | dev = rdev->ops->add_virtual_intf(&rdev->wiphy, |
1292 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), | 1618 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
1293 | type, err ? NULL : &flags, ¶ms); | 1619 | type, err ? NULL : &flags, ¶ms); |
1620 | if (IS_ERR(dev)) | ||
1621 | return PTR_ERR(dev); | ||
1294 | 1622 | ||
1295 | unlock: | 1623 | if (type == NL80211_IFTYPE_MESH_POINT && |
1296 | cfg80211_unlock_rdev(rdev); | 1624 | info->attrs[NL80211_ATTR_MESH_ID]) { |
1297 | unlock_rtnl: | 1625 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
1298 | rtnl_unlock(); | 1626 | |
1299 | return err; | 1627 | wdev_lock(wdev); |
1628 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | ||
1629 | IEEE80211_MAX_MESH_ID_LEN); | ||
1630 | wdev->mesh_id_up_len = | ||
1631 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | ||
1632 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | ||
1633 | wdev->mesh_id_up_len); | ||
1634 | wdev_unlock(wdev); | ||
1635 | } | ||
1636 | |||
1637 | return 0; | ||
1300 | } | 1638 | } |
1301 | 1639 | ||
1302 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) | 1640 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
1303 | { | 1641 | { |
1304 | struct cfg80211_registered_device *rdev; | 1642 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1305 | int err; | 1643 | struct net_device *dev = info->user_ptr[1]; |
1306 | struct net_device *dev; | ||
1307 | 1644 | ||
1308 | rtnl_lock(); | 1645 | if (!rdev->ops->del_virtual_intf) |
1309 | 1646 | return -EOPNOTSUPP; | |
1310 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | ||
1311 | if (err) | ||
1312 | goto unlock_rtnl; | ||
1313 | |||
1314 | if (!rdev->ops->del_virtual_intf) { | ||
1315 | err = -EOPNOTSUPP; | ||
1316 | goto out; | ||
1317 | } | ||
1318 | |||
1319 | err = rdev->ops->del_virtual_intf(&rdev->wiphy, dev); | ||
1320 | 1647 | ||
1321 | out: | 1648 | return rdev->ops->del_virtual_intf(&rdev->wiphy, dev); |
1322 | cfg80211_unlock_rdev(rdev); | ||
1323 | dev_put(dev); | ||
1324 | unlock_rtnl: | ||
1325 | rtnl_unlock(); | ||
1326 | return err; | ||
1327 | } | 1649 | } |
1328 | 1650 | ||
1329 | struct get_key_cookie { | 1651 | struct get_key_cookie { |
@@ -1376,11 +1698,12 @@ static void get_key_callback(void *c, struct key_params *params) | |||
1376 | 1698 | ||
1377 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) | 1699 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
1378 | { | 1700 | { |
1379 | struct cfg80211_registered_device *rdev; | 1701 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1380 | int err; | 1702 | int err; |
1381 | struct net_device *dev; | 1703 | struct net_device *dev = info->user_ptr[1]; |
1382 | u8 key_idx = 0; | 1704 | u8 key_idx = 0; |
1383 | u8 *mac_addr = NULL; | 1705 | const u8 *mac_addr = NULL; |
1706 | bool pairwise; | ||
1384 | struct get_key_cookie cookie = { | 1707 | struct get_key_cookie cookie = { |
1385 | .error = 0, | 1708 | .error = 0, |
1386 | }; | 1709 | }; |
@@ -1396,30 +1719,28 @@ static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) | |||
1396 | if (info->attrs[NL80211_ATTR_MAC]) | 1719 | if (info->attrs[NL80211_ATTR_MAC]) |
1397 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | 1720 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
1398 | 1721 | ||
1399 | rtnl_lock(); | 1722 | pairwise = !!mac_addr; |
1400 | 1723 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { | |
1401 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | 1724 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); |
1402 | if (err) | 1725 | if (kt >= NUM_NL80211_KEYTYPES) |
1403 | goto unlock_rtnl; | 1726 | return -EINVAL; |
1404 | 1727 | if (kt != NL80211_KEYTYPE_GROUP && | |
1405 | if (!rdev->ops->get_key) { | 1728 | kt != NL80211_KEYTYPE_PAIRWISE) |
1406 | err = -EOPNOTSUPP; | 1729 | return -EINVAL; |
1407 | goto out; | 1730 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; |
1408 | } | 1731 | } |
1409 | 1732 | ||
1733 | if (!rdev->ops->get_key) | ||
1734 | return -EOPNOTSUPP; | ||
1735 | |||
1410 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 1736 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
1411 | if (!msg) { | 1737 | if (!msg) |
1412 | err = -ENOMEM; | 1738 | return -ENOMEM; |
1413 | goto out; | ||
1414 | } | ||
1415 | 1739 | ||
1416 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | 1740 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
1417 | NL80211_CMD_NEW_KEY); | 1741 | NL80211_CMD_NEW_KEY); |
1418 | 1742 | if (IS_ERR(hdr)) | |
1419 | if (IS_ERR(hdr)) { | 1743 | return PTR_ERR(hdr); |
1420 | err = PTR_ERR(hdr); | ||
1421 | goto free_msg; | ||
1422 | } | ||
1423 | 1744 | ||
1424 | cookie.msg = msg; | 1745 | cookie.msg = msg; |
1425 | cookie.idx = key_idx; | 1746 | cookie.idx = key_idx; |
@@ -1429,8 +1750,12 @@ static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) | |||
1429 | if (mac_addr) | 1750 | if (mac_addr) |
1430 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | 1751 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
1431 | 1752 | ||
1432 | err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, mac_addr, | 1753 | if (pairwise && mac_addr && |
1433 | &cookie, get_key_callback); | 1754 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
1755 | return -ENOENT; | ||
1756 | |||
1757 | err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, pairwise, | ||
1758 | mac_addr, &cookie, get_key_callback); | ||
1434 | 1759 | ||
1435 | if (err) | 1760 | if (err) |
1436 | goto free_msg; | 1761 | goto free_msg; |
@@ -1439,30 +1764,21 @@ static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) | |||
1439 | goto nla_put_failure; | 1764 | goto nla_put_failure; |
1440 | 1765 | ||
1441 | genlmsg_end(msg, hdr); | 1766 | genlmsg_end(msg, hdr); |
1442 | err = genlmsg_reply(msg, info); | 1767 | return genlmsg_reply(msg, info); |
1443 | goto out; | ||
1444 | 1768 | ||
1445 | nla_put_failure: | 1769 | nla_put_failure: |
1446 | err = -ENOBUFS; | 1770 | err = -ENOBUFS; |
1447 | free_msg: | 1771 | free_msg: |
1448 | nlmsg_free(msg); | 1772 | nlmsg_free(msg); |
1449 | out: | ||
1450 | cfg80211_unlock_rdev(rdev); | ||
1451 | dev_put(dev); | ||
1452 | unlock_rtnl: | ||
1453 | rtnl_unlock(); | ||
1454 | |||
1455 | return err; | 1773 | return err; |
1456 | } | 1774 | } |
1457 | 1775 | ||
1458 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) | 1776 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
1459 | { | 1777 | { |
1460 | struct cfg80211_registered_device *rdev; | 1778 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1461 | struct key_parse key; | 1779 | struct key_parse key; |
1462 | int err; | 1780 | int err; |
1463 | struct net_device *dev; | 1781 | struct net_device *dev = info->user_ptr[1]; |
1464 | int (*func)(struct wiphy *wiphy, struct net_device *netdev, | ||
1465 | u8 key_index); | ||
1466 | 1782 | ||
1467 | err = nl80211_parse_key(info, &key); | 1783 | err = nl80211_parse_key(info, &key); |
1468 | if (err) | 1784 | if (err) |
@@ -1475,54 +1791,65 @@ static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) | |||
1475 | if (!key.def && !key.defmgmt) | 1791 | if (!key.def && !key.defmgmt) |
1476 | return -EINVAL; | 1792 | return -EINVAL; |
1477 | 1793 | ||
1478 | rtnl_lock(); | 1794 | wdev_lock(dev->ieee80211_ptr); |
1479 | 1795 | ||
1480 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | 1796 | if (key.def) { |
1481 | if (err) | 1797 | if (!rdev->ops->set_default_key) { |
1482 | goto unlock_rtnl; | 1798 | err = -EOPNOTSUPP; |
1799 | goto out; | ||
1800 | } | ||
1483 | 1801 | ||
1484 | if (key.def) | 1802 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
1485 | func = rdev->ops->set_default_key; | 1803 | if (err) |
1486 | else | 1804 | goto out; |
1487 | func = rdev->ops->set_default_mgmt_key; | ||
1488 | 1805 | ||
1489 | if (!func) { | 1806 | err = rdev->ops->set_default_key(&rdev->wiphy, dev, key.idx, |
1490 | err = -EOPNOTSUPP; | 1807 | key.def_uni, key.def_multi); |
1491 | goto out; | ||
1492 | } | ||
1493 | 1808 | ||
1494 | wdev_lock(dev->ieee80211_ptr); | 1809 | if (err) |
1495 | err = nl80211_key_allowed(dev->ieee80211_ptr); | 1810 | goto out; |
1496 | if (!err) | ||
1497 | err = func(&rdev->wiphy, dev, key.idx); | ||
1498 | 1811 | ||
1499 | #ifdef CONFIG_CFG80211_WEXT | 1812 | #ifdef CONFIG_CFG80211_WEXT |
1500 | if (!err) { | 1813 | dev->ieee80211_ptr->wext.default_key = key.idx; |
1501 | if (func == rdev->ops->set_default_key) | ||
1502 | dev->ieee80211_ptr->wext.default_key = key.idx; | ||
1503 | else | ||
1504 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; | ||
1505 | } | ||
1506 | #endif | 1814 | #endif |
1507 | wdev_unlock(dev->ieee80211_ptr); | 1815 | } else { |
1816 | if (key.def_uni || !key.def_multi) { | ||
1817 | err = -EINVAL; | ||
1818 | goto out; | ||
1819 | } | ||
1508 | 1820 | ||
1509 | out: | 1821 | if (!rdev->ops->set_default_mgmt_key) { |
1510 | cfg80211_unlock_rdev(rdev); | 1822 | err = -EOPNOTSUPP; |
1511 | dev_put(dev); | 1823 | goto out; |
1824 | } | ||
1512 | 1825 | ||
1513 | unlock_rtnl: | 1826 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
1514 | rtnl_unlock(); | 1827 | if (err) |
1828 | goto out; | ||
1829 | |||
1830 | err = rdev->ops->set_default_mgmt_key(&rdev->wiphy, | ||
1831 | dev, key.idx); | ||
1832 | if (err) | ||
1833 | goto out; | ||
1834 | |||
1835 | #ifdef CONFIG_CFG80211_WEXT | ||
1836 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; | ||
1837 | #endif | ||
1838 | } | ||
1839 | |||
1840 | out: | ||
1841 | wdev_unlock(dev->ieee80211_ptr); | ||
1515 | 1842 | ||
1516 | return err; | 1843 | return err; |
1517 | } | 1844 | } |
1518 | 1845 | ||
1519 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) | 1846 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
1520 | { | 1847 | { |
1521 | struct cfg80211_registered_device *rdev; | 1848 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1522 | int err; | 1849 | int err; |
1523 | struct net_device *dev; | 1850 | struct net_device *dev = info->user_ptr[1]; |
1524 | struct key_parse key; | 1851 | struct key_parse key; |
1525 | u8 *mac_addr = NULL; | 1852 | const u8 *mac_addr = NULL; |
1526 | 1853 | ||
1527 | err = nl80211_parse_key(info, &key); | 1854 | err = nl80211_parse_key(info, &key); |
1528 | if (err) | 1855 | if (err) |
@@ -1534,43 +1861,42 @@ static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) | |||
1534 | if (info->attrs[NL80211_ATTR_MAC]) | 1861 | if (info->attrs[NL80211_ATTR_MAC]) |
1535 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | 1862 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
1536 | 1863 | ||
1537 | rtnl_lock(); | 1864 | if (key.type == -1) { |
1865 | if (mac_addr) | ||
1866 | key.type = NL80211_KEYTYPE_PAIRWISE; | ||
1867 | else | ||
1868 | key.type = NL80211_KEYTYPE_GROUP; | ||
1869 | } | ||
1538 | 1870 | ||
1539 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | 1871 | /* for now */ |
1540 | if (err) | 1872 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
1541 | goto unlock_rtnl; | 1873 | key.type != NL80211_KEYTYPE_GROUP) |
1874 | return -EINVAL; | ||
1542 | 1875 | ||
1543 | if (!rdev->ops->add_key) { | 1876 | if (!rdev->ops->add_key) |
1544 | err = -EOPNOTSUPP; | 1877 | return -EOPNOTSUPP; |
1545 | goto out; | ||
1546 | } | ||
1547 | 1878 | ||
1548 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, mac_addr)) { | 1879 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
1549 | err = -EINVAL; | 1880 | key.type == NL80211_KEYTYPE_PAIRWISE, |
1550 | goto out; | 1881 | mac_addr)) |
1551 | } | 1882 | return -EINVAL; |
1552 | 1883 | ||
1553 | wdev_lock(dev->ieee80211_ptr); | 1884 | wdev_lock(dev->ieee80211_ptr); |
1554 | err = nl80211_key_allowed(dev->ieee80211_ptr); | 1885 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
1555 | if (!err) | 1886 | if (!err) |
1556 | err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx, | 1887 | err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx, |
1888 | key.type == NL80211_KEYTYPE_PAIRWISE, | ||
1557 | mac_addr, &key.p); | 1889 | mac_addr, &key.p); |
1558 | wdev_unlock(dev->ieee80211_ptr); | 1890 | wdev_unlock(dev->ieee80211_ptr); |
1559 | 1891 | ||
1560 | out: | ||
1561 | cfg80211_unlock_rdev(rdev); | ||
1562 | dev_put(dev); | ||
1563 | unlock_rtnl: | ||
1564 | rtnl_unlock(); | ||
1565 | |||
1566 | return err; | 1892 | return err; |
1567 | } | 1893 | } |
1568 | 1894 | ||
1569 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) | 1895 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
1570 | { | 1896 | { |
1571 | struct cfg80211_registered_device *rdev; | 1897 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1572 | int err; | 1898 | int err; |
1573 | struct net_device *dev; | 1899 | struct net_device *dev = info->user_ptr[1]; |
1574 | u8 *mac_addr = NULL; | 1900 | u8 *mac_addr = NULL; |
1575 | struct key_parse key; | 1901 | struct key_parse key; |
1576 | 1902 | ||
@@ -1581,21 +1907,32 @@ static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) | |||
1581 | if (info->attrs[NL80211_ATTR_MAC]) | 1907 | if (info->attrs[NL80211_ATTR_MAC]) |
1582 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | 1908 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
1583 | 1909 | ||
1584 | rtnl_lock(); | 1910 | if (key.type == -1) { |
1911 | if (mac_addr) | ||
1912 | key.type = NL80211_KEYTYPE_PAIRWISE; | ||
1913 | else | ||
1914 | key.type = NL80211_KEYTYPE_GROUP; | ||
1915 | } | ||
1585 | 1916 | ||
1586 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | 1917 | /* for now */ |
1587 | if (err) | 1918 | if (key.type != NL80211_KEYTYPE_PAIRWISE && |
1588 | goto unlock_rtnl; | 1919 | key.type != NL80211_KEYTYPE_GROUP) |
1920 | return -EINVAL; | ||
1589 | 1921 | ||
1590 | if (!rdev->ops->del_key) { | 1922 | if (!rdev->ops->del_key) |
1591 | err = -EOPNOTSUPP; | 1923 | return -EOPNOTSUPP; |
1592 | goto out; | ||
1593 | } | ||
1594 | 1924 | ||
1595 | wdev_lock(dev->ieee80211_ptr); | 1925 | wdev_lock(dev->ieee80211_ptr); |
1596 | err = nl80211_key_allowed(dev->ieee80211_ptr); | 1926 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
1927 | |||
1928 | if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr && | ||
1929 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) | ||
1930 | err = -ENOENT; | ||
1931 | |||
1597 | if (!err) | 1932 | if (!err) |
1598 | err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx, mac_addr); | 1933 | err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx, |
1934 | key.type == NL80211_KEYTYPE_PAIRWISE, | ||
1935 | mac_addr); | ||
1599 | 1936 | ||
1600 | #ifdef CONFIG_CFG80211_WEXT | 1937 | #ifdef CONFIG_CFG80211_WEXT |
1601 | if (!err) { | 1938 | if (!err) { |
@@ -1607,13 +1944,6 @@ static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) | |||
1607 | #endif | 1944 | #endif |
1608 | wdev_unlock(dev->ieee80211_ptr); | 1945 | wdev_unlock(dev->ieee80211_ptr); |
1609 | 1946 | ||
1610 | out: | ||
1611 | cfg80211_unlock_rdev(rdev); | ||
1612 | dev_put(dev); | ||
1613 | |||
1614 | unlock_rtnl: | ||
1615 | rtnl_unlock(); | ||
1616 | |||
1617 | return err; | 1947 | return err; |
1618 | } | 1948 | } |
1619 | 1949 | ||
@@ -1621,35 +1951,37 @@ static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info) | |||
1621 | { | 1951 | { |
1622 | int (*call)(struct wiphy *wiphy, struct net_device *dev, | 1952 | int (*call)(struct wiphy *wiphy, struct net_device *dev, |
1623 | struct beacon_parameters *info); | 1953 | struct beacon_parameters *info); |
1624 | struct cfg80211_registered_device *rdev; | 1954 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1625 | int err; | 1955 | struct net_device *dev = info->user_ptr[1]; |
1626 | struct net_device *dev; | 1956 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
1627 | struct beacon_parameters params; | 1957 | struct beacon_parameters params; |
1628 | int haveinfo = 0; | 1958 | int haveinfo = 0, err; |
1629 | 1959 | ||
1630 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL])) | 1960 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL])) |
1631 | return -EINVAL; | 1961 | return -EINVAL; |
1632 | 1962 | ||
1633 | rtnl_lock(); | 1963 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
1634 | 1964 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
1635 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | 1965 | return -EOPNOTSUPP; |
1636 | if (err) | ||
1637 | goto unlock_rtnl; | ||
1638 | 1966 | ||
1639 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) { | 1967 | memset(¶ms, 0, sizeof(params)); |
1640 | err = -EOPNOTSUPP; | ||
1641 | goto out; | ||
1642 | } | ||
1643 | 1968 | ||
1644 | switch (info->genlhdr->cmd) { | 1969 | switch (info->genlhdr->cmd) { |
1645 | case NL80211_CMD_NEW_BEACON: | 1970 | case NL80211_CMD_NEW_BEACON: |
1646 | /* these are required for NEW_BEACON */ | 1971 | /* these are required for NEW_BEACON */ |
1647 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || | 1972 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
1648 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || | 1973 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
1649 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) { | 1974 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) |
1650 | err = -EINVAL; | 1975 | return -EINVAL; |
1651 | goto out; | 1976 | |
1652 | } | 1977 | params.interval = |
1978 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | ||
1979 | params.dtim_period = | ||
1980 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | ||
1981 | |||
1982 | err = cfg80211_validate_beacon_int(rdev, params.interval); | ||
1983 | if (err) | ||
1984 | return err; | ||
1653 | 1985 | ||
1654 | call = rdev->ops->add_beacon; | 1986 | call = rdev->ops->add_beacon; |
1655 | break; | 1987 | break; |
@@ -1658,28 +1990,11 @@ static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info) | |||
1658 | break; | 1990 | break; |
1659 | default: | 1991 | default: |
1660 | WARN_ON(1); | 1992 | WARN_ON(1); |
1661 | err = -EOPNOTSUPP; | 1993 | return -EOPNOTSUPP; |
1662 | goto out; | ||
1663 | } | ||
1664 | |||
1665 | if (!call) { | ||
1666 | err = -EOPNOTSUPP; | ||
1667 | goto out; | ||
1668 | } | ||
1669 | |||
1670 | memset(¶ms, 0, sizeof(params)); | ||
1671 | |||
1672 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { | ||
1673 | params.interval = | ||
1674 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | ||
1675 | haveinfo = 1; | ||
1676 | } | 1994 | } |
1677 | 1995 | ||
1678 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { | 1996 | if (!call) |
1679 | params.dtim_period = | 1997 | return -EOPNOTSUPP; |
1680 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | ||
1681 | haveinfo = 1; | ||
1682 | } | ||
1683 | 1998 | ||
1684 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { | 1999 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
1685 | params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); | 2000 | params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
@@ -1695,51 +2010,32 @@ static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info) | |||
1695 | haveinfo = 1; | 2010 | haveinfo = 1; |
1696 | } | 2011 | } |
1697 | 2012 | ||
1698 | if (!haveinfo) { | 2013 | if (!haveinfo) |
1699 | err = -EINVAL; | 2014 | return -EINVAL; |
1700 | goto out; | ||
1701 | } | ||
1702 | 2015 | ||
1703 | err = call(&rdev->wiphy, dev, ¶ms); | 2016 | err = call(&rdev->wiphy, dev, ¶ms); |
1704 | 2017 | if (!err && params.interval) | |
1705 | out: | 2018 | wdev->beacon_interval = params.interval; |
1706 | cfg80211_unlock_rdev(rdev); | ||
1707 | dev_put(dev); | ||
1708 | unlock_rtnl: | ||
1709 | rtnl_unlock(); | ||
1710 | |||
1711 | return err; | 2019 | return err; |
1712 | } | 2020 | } |
1713 | 2021 | ||
1714 | static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info) | 2022 | static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info) |
1715 | { | 2023 | { |
1716 | struct cfg80211_registered_device *rdev; | 2024 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2025 | struct net_device *dev = info->user_ptr[1]; | ||
2026 | struct wireless_dev *wdev = dev->ieee80211_ptr; | ||
1717 | int err; | 2027 | int err; |
1718 | struct net_device *dev; | ||
1719 | 2028 | ||
1720 | rtnl_lock(); | 2029 | if (!rdev->ops->del_beacon) |
1721 | 2030 | return -EOPNOTSUPP; | |
1722 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | ||
1723 | if (err) | ||
1724 | goto unlock_rtnl; | ||
1725 | 2031 | ||
1726 | if (!rdev->ops->del_beacon) { | 2032 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
1727 | err = -EOPNOTSUPP; | 2033 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
1728 | goto out; | 2034 | return -EOPNOTSUPP; |
1729 | } | ||
1730 | 2035 | ||
1731 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) { | ||
1732 | err = -EOPNOTSUPP; | ||
1733 | goto out; | ||
1734 | } | ||
1735 | err = rdev->ops->del_beacon(&rdev->wiphy, dev); | 2036 | err = rdev->ops->del_beacon(&rdev->wiphy, dev); |
1736 | 2037 | if (!err) | |
1737 | out: | 2038 | wdev->beacon_interval = 0; |
1738 | cfg80211_unlock_rdev(rdev); | ||
1739 | dev_put(dev); | ||
1740 | unlock_rtnl: | ||
1741 | rtnl_unlock(); | ||
1742 | |||
1743 | return err; | 2039 | return err; |
1744 | } | 2040 | } |
1745 | 2041 | ||
@@ -1748,6 +2044,7 @@ static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { | |||
1748 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, | 2044 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
1749 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, | 2045 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
1750 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, | 2046 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
2047 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, | ||
1751 | }; | 2048 | }; |
1752 | 2049 | ||
1753 | static int parse_station_flags(struct genl_info *info, | 2050 | static int parse_station_flags(struct genl_info *info, |
@@ -1794,13 +2091,41 @@ static int parse_station_flags(struct genl_info *info, | |||
1794 | return 0; | 2091 | return 0; |
1795 | } | 2092 | } |
1796 | 2093 | ||
2094 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, | ||
2095 | int attr) | ||
2096 | { | ||
2097 | struct nlattr *rate; | ||
2098 | u16 bitrate; | ||
2099 | |||
2100 | rate = nla_nest_start(msg, attr); | ||
2101 | if (!rate) | ||
2102 | goto nla_put_failure; | ||
2103 | |||
2104 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ | ||
2105 | bitrate = cfg80211_calculate_bitrate(info); | ||
2106 | if (bitrate > 0) | ||
2107 | NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate); | ||
2108 | |||
2109 | if (info->flags & RATE_INFO_FLAGS_MCS) | ||
2110 | NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS, info->mcs); | ||
2111 | if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) | ||
2112 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH); | ||
2113 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI) | ||
2114 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI); | ||
2115 | |||
2116 | nla_nest_end(msg, rate); | ||
2117 | return true; | ||
2118 | |||
2119 | nla_put_failure: | ||
2120 | return false; | ||
2121 | } | ||
2122 | |||
1797 | static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, | 2123 | static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, |
1798 | int flags, struct net_device *dev, | 2124 | int flags, struct net_device *dev, |
1799 | const u8 *mac_addr, struct station_info *sinfo) | 2125 | const u8 *mac_addr, struct station_info *sinfo) |
1800 | { | 2126 | { |
1801 | void *hdr; | 2127 | void *hdr; |
1802 | struct nlattr *sinfoattr, *txrate; | 2128 | struct nlattr *sinfoattr, *bss_param; |
1803 | u16 bitrate; | ||
1804 | 2129 | ||
1805 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); | 2130 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
1806 | if (!hdr) | 2131 | if (!hdr) |
@@ -1814,6 +2139,9 @@ static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, | |||
1814 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); | 2139 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
1815 | if (!sinfoattr) | 2140 | if (!sinfoattr) |
1816 | goto nla_put_failure; | 2141 | goto nla_put_failure; |
2142 | if (sinfo->filled & STATION_INFO_CONNECTED_TIME) | ||
2143 | NLA_PUT_U32(msg, NL80211_STA_INFO_CONNECTED_TIME, | ||
2144 | sinfo->connected_time); | ||
1817 | if (sinfo->filled & STATION_INFO_INACTIVE_TIME) | 2145 | if (sinfo->filled & STATION_INFO_INACTIVE_TIME) |
1818 | NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME, | 2146 | NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
1819 | sinfo->inactive_time); | 2147 | sinfo->inactive_time); |
@@ -1835,25 +2163,18 @@ static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, | |||
1835 | if (sinfo->filled & STATION_INFO_SIGNAL) | 2163 | if (sinfo->filled & STATION_INFO_SIGNAL) |
1836 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL, | 2164 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL, |
1837 | sinfo->signal); | 2165 | sinfo->signal); |
2166 | if (sinfo->filled & STATION_INFO_SIGNAL_AVG) | ||
2167 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL_AVG, | ||
2168 | sinfo->signal_avg); | ||
1838 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { | 2169 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
1839 | txrate = nla_nest_start(msg, NL80211_STA_INFO_TX_BITRATE); | 2170 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
1840 | if (!txrate) | 2171 | NL80211_STA_INFO_TX_BITRATE)) |
2172 | goto nla_put_failure; | ||
2173 | } | ||
2174 | if (sinfo->filled & STATION_INFO_RX_BITRATE) { | ||
2175 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, | ||
2176 | NL80211_STA_INFO_RX_BITRATE)) | ||
1841 | goto nla_put_failure; | 2177 | goto nla_put_failure; |
1842 | |||
1843 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ | ||
1844 | bitrate = cfg80211_calculate_bitrate(&sinfo->txrate); | ||
1845 | if (bitrate > 0) | ||
1846 | NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate); | ||
1847 | |||
1848 | if (sinfo->txrate.flags & RATE_INFO_FLAGS_MCS) | ||
1849 | NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS, | ||
1850 | sinfo->txrate.mcs); | ||
1851 | if (sinfo->txrate.flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) | ||
1852 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH); | ||
1853 | if (sinfo->txrate.flags & RATE_INFO_FLAGS_SHORT_GI) | ||
1854 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI); | ||
1855 | |||
1856 | nla_nest_end(msg, txrate); | ||
1857 | } | 2178 | } |
1858 | if (sinfo->filled & STATION_INFO_RX_PACKETS) | 2179 | if (sinfo->filled & STATION_INFO_RX_PACKETS) |
1859 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS, | 2180 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS, |
@@ -1861,6 +2182,31 @@ static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, | |||
1861 | if (sinfo->filled & STATION_INFO_TX_PACKETS) | 2182 | if (sinfo->filled & STATION_INFO_TX_PACKETS) |
1862 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS, | 2183 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS, |
1863 | sinfo->tx_packets); | 2184 | sinfo->tx_packets); |
2185 | if (sinfo->filled & STATION_INFO_TX_RETRIES) | ||
2186 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_RETRIES, | ||
2187 | sinfo->tx_retries); | ||
2188 | if (sinfo->filled & STATION_INFO_TX_FAILED) | ||
2189 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_FAILED, | ||
2190 | sinfo->tx_failed); | ||
2191 | if (sinfo->filled & STATION_INFO_BSS_PARAM) { | ||
2192 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); | ||
2193 | if (!bss_param) | ||
2194 | goto nla_put_failure; | ||
2195 | |||
2196 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) | ||
2197 | NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_CTS_PROT); | ||
2198 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) | ||
2199 | NLA_PUT_FLAG(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE); | ||
2200 | if (sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) | ||
2201 | NLA_PUT_FLAG(msg, | ||
2202 | NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME); | ||
2203 | NLA_PUT_U8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, | ||
2204 | sinfo->bss_param.dtim_period); | ||
2205 | NLA_PUT_U16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, | ||
2206 | sinfo->bss_param.beacon_interval); | ||
2207 | |||
2208 | nla_nest_end(msg, bss_param); | ||
2209 | } | ||
1864 | nla_nest_end(msg, sinfoattr); | 2210 | nla_nest_end(msg, sinfoattr); |
1865 | 2211 | ||
1866 | return genlmsg_end(msg, hdr); | 2212 | return genlmsg_end(msg, hdr); |
@@ -1877,28 +2223,12 @@ static int nl80211_dump_station(struct sk_buff *skb, | |||
1877 | struct cfg80211_registered_device *dev; | 2223 | struct cfg80211_registered_device *dev; |
1878 | struct net_device *netdev; | 2224 | struct net_device *netdev; |
1879 | u8 mac_addr[ETH_ALEN]; | 2225 | u8 mac_addr[ETH_ALEN]; |
1880 | int ifidx = cb->args[0]; | ||
1881 | int sta_idx = cb->args[1]; | 2226 | int sta_idx = cb->args[1]; |
1882 | int err; | 2227 | int err; |
1883 | 2228 | ||
1884 | if (!ifidx) | 2229 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
1885 | ifidx = nl80211_get_ifidx(cb); | 2230 | if (err) |
1886 | if (ifidx < 0) | 2231 | return err; |
1887 | return ifidx; | ||
1888 | |||
1889 | rtnl_lock(); | ||
1890 | |||
1891 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); | ||
1892 | if (!netdev) { | ||
1893 | err = -ENODEV; | ||
1894 | goto out_rtnl; | ||
1895 | } | ||
1896 | |||
1897 | dev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); | ||
1898 | if (IS_ERR(dev)) { | ||
1899 | err = PTR_ERR(dev); | ||
1900 | goto out_rtnl; | ||
1901 | } | ||
1902 | 2232 | ||
1903 | if (!dev->ops->dump_station) { | 2233 | if (!dev->ops->dump_station) { |
1904 | err = -EOPNOTSUPP; | 2234 | err = -EOPNOTSUPP; |
@@ -1928,21 +2258,19 @@ static int nl80211_dump_station(struct sk_buff *skb, | |||
1928 | cb->args[1] = sta_idx; | 2258 | cb->args[1] = sta_idx; |
1929 | err = skb->len; | 2259 | err = skb->len; |
1930 | out_err: | 2260 | out_err: |
1931 | cfg80211_unlock_rdev(dev); | 2261 | nl80211_finish_netdev_dump(dev); |
1932 | out_rtnl: | ||
1933 | rtnl_unlock(); | ||
1934 | 2262 | ||
1935 | return err; | 2263 | return err; |
1936 | } | 2264 | } |
1937 | 2265 | ||
1938 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) | 2266 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
1939 | { | 2267 | { |
1940 | struct cfg80211_registered_device *rdev; | 2268 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
1941 | int err; | 2269 | struct net_device *dev = info->user_ptr[1]; |
1942 | struct net_device *dev; | ||
1943 | struct station_info sinfo; | 2270 | struct station_info sinfo; |
1944 | struct sk_buff *msg; | 2271 | struct sk_buff *msg; |
1945 | u8 *mac_addr = NULL; | 2272 | u8 *mac_addr = NULL; |
2273 | int err; | ||
1946 | 2274 | ||
1947 | memset(&sinfo, 0, sizeof(sinfo)); | 2275 | memset(&sinfo, 0, sizeof(sinfo)); |
1948 | 2276 | ||
@@ -1951,41 +2279,24 @@ static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) | |||
1951 | 2279 | ||
1952 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | 2280 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
1953 | 2281 | ||
1954 | rtnl_lock(); | 2282 | if (!rdev->ops->get_station) |
1955 | 2283 | return -EOPNOTSUPP; | |
1956 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | ||
1957 | if (err) | ||
1958 | goto out_rtnl; | ||
1959 | |||
1960 | if (!rdev->ops->get_station) { | ||
1961 | err = -EOPNOTSUPP; | ||
1962 | goto out; | ||
1963 | } | ||
1964 | 2284 | ||
1965 | err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo); | 2285 | err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo); |
1966 | if (err) | 2286 | if (err) |
1967 | goto out; | 2287 | return err; |
1968 | 2288 | ||
1969 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 2289 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
1970 | if (!msg) | 2290 | if (!msg) |
1971 | goto out; | 2291 | return -ENOMEM; |
1972 | 2292 | ||
1973 | if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0, | 2293 | if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0, |
1974 | dev, mac_addr, &sinfo) < 0) | 2294 | dev, mac_addr, &sinfo) < 0) { |
1975 | goto out_free; | 2295 | nlmsg_free(msg); |
1976 | 2296 | return -ENOBUFS; | |
1977 | err = genlmsg_reply(msg, info); | 2297 | } |
1978 | goto out; | ||
1979 | |||
1980 | out_free: | ||
1981 | nlmsg_free(msg); | ||
1982 | out: | ||
1983 | cfg80211_unlock_rdev(rdev); | ||
1984 | dev_put(dev); | ||
1985 | out_rtnl: | ||
1986 | rtnl_unlock(); | ||
1987 | 2298 | ||
1988 | return err; | 2299 | return genlmsg_reply(msg, info); |
1989 | } | 2300 | } |
1990 | 2301 | ||
1991 | /* | 2302 | /* |
@@ -2015,15 +2326,16 @@ static int get_vlan(struct genl_info *info, | |||
2015 | 2326 | ||
2016 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) | 2327 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
2017 | { | 2328 | { |
2018 | struct cfg80211_registered_device *rdev; | 2329 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2019 | int err; | 2330 | int err; |
2020 | struct net_device *dev; | 2331 | struct net_device *dev = info->user_ptr[1]; |
2021 | struct station_parameters params; | 2332 | struct station_parameters params; |
2022 | u8 *mac_addr = NULL; | 2333 | u8 *mac_addr = NULL; |
2023 | 2334 | ||
2024 | memset(¶ms, 0, sizeof(params)); | 2335 | memset(¶ms, 0, sizeof(params)); |
2025 | 2336 | ||
2026 | params.listen_interval = -1; | 2337 | params.listen_interval = -1; |
2338 | params.plink_state = -1; | ||
2027 | 2339 | ||
2028 | if (info->attrs[NL80211_ATTR_STA_AID]) | 2340 | if (info->attrs[NL80211_ATTR_STA_AID]) |
2029 | return -EINVAL; | 2341 | return -EINVAL; |
@@ -2055,11 +2367,9 @@ static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) | |||
2055 | params.plink_action = | 2367 | params.plink_action = |
2056 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); | 2368 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
2057 | 2369 | ||
2058 | rtnl_lock(); | 2370 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) |
2059 | 2371 | params.plink_state = | |
2060 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | 2372 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
2061 | if (err) | ||
2062 | goto out_rtnl; | ||
2063 | 2373 | ||
2064 | err = get_vlan(info, rdev, ¶ms.vlan); | 2374 | err = get_vlan(info, rdev, ¶ms.vlan); |
2065 | if (err) | 2375 | if (err) |
@@ -2071,10 +2381,12 @@ static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) | |||
2071 | switch (dev->ieee80211_ptr->iftype) { | 2381 | switch (dev->ieee80211_ptr->iftype) { |
2072 | case NL80211_IFTYPE_AP: | 2382 | case NL80211_IFTYPE_AP: |
2073 | case NL80211_IFTYPE_AP_VLAN: | 2383 | case NL80211_IFTYPE_AP_VLAN: |
2384 | case NL80211_IFTYPE_P2P_GO: | ||
2074 | /* disallow mesh-specific things */ | 2385 | /* disallow mesh-specific things */ |
2075 | if (params.plink_action) | 2386 | if (params.plink_action) |
2076 | err = -EINVAL; | 2387 | err = -EINVAL; |
2077 | break; | 2388 | break; |
2389 | case NL80211_IFTYPE_P2P_CLIENT: | ||
2078 | case NL80211_IFTYPE_STATION: | 2390 | case NL80211_IFTYPE_STATION: |
2079 | /* disallow everything but AUTHORIZED flag */ | 2391 | /* disallow everything but AUTHORIZED flag */ |
2080 | if (params.plink_action) | 2392 | if (params.plink_action) |
@@ -2098,9 +2410,10 @@ static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) | |||
2098 | err = -EINVAL; | 2410 | err = -EINVAL; |
2099 | if (params.listen_interval >= 0) | 2411 | if (params.listen_interval >= 0) |
2100 | err = -EINVAL; | 2412 | err = -EINVAL; |
2101 | if (params.supported_rates) | 2413 | if (params.sta_flags_mask & |
2102 | err = -EINVAL; | 2414 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
2103 | if (params.sta_flags_mask) | 2415 | BIT(NL80211_STA_FLAG_MFP) | |
2416 | BIT(NL80211_STA_FLAG_AUTHORIZED))) | ||
2104 | err = -EINVAL; | 2417 | err = -EINVAL; |
2105 | break; | 2418 | break; |
2106 | default: | 2419 | default: |
@@ -2120,19 +2433,15 @@ static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) | |||
2120 | out: | 2433 | out: |
2121 | if (params.vlan) | 2434 | if (params.vlan) |
2122 | dev_put(params.vlan); | 2435 | dev_put(params.vlan); |
2123 | cfg80211_unlock_rdev(rdev); | ||
2124 | dev_put(dev); | ||
2125 | out_rtnl: | ||
2126 | rtnl_unlock(); | ||
2127 | 2436 | ||
2128 | return err; | 2437 | return err; |
2129 | } | 2438 | } |
2130 | 2439 | ||
2131 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) | 2440 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
2132 | { | 2441 | { |
2133 | struct cfg80211_registered_device *rdev; | 2442 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2134 | int err; | 2443 | int err; |
2135 | struct net_device *dev; | 2444 | struct net_device *dev = info->user_ptr[1]; |
2136 | struct station_parameters params; | 2445 | struct station_parameters params; |
2137 | u8 *mac_addr = NULL; | 2446 | u8 *mac_addr = NULL; |
2138 | 2447 | ||
@@ -2166,20 +2475,18 @@ static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) | |||
2166 | params.ht_capa = | 2475 | params.ht_capa = |
2167 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | 2476 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
2168 | 2477 | ||
2478 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) | ||
2479 | params.plink_action = | ||
2480 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); | ||
2481 | |||
2169 | if (parse_station_flags(info, ¶ms)) | 2482 | if (parse_station_flags(info, ¶ms)) |
2170 | return -EINVAL; | 2483 | return -EINVAL; |
2171 | 2484 | ||
2172 | rtnl_lock(); | ||
2173 | |||
2174 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | ||
2175 | if (err) | ||
2176 | goto out_rtnl; | ||
2177 | |||
2178 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | 2485 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
2179 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN) { | 2486 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
2180 | err = -EINVAL; | 2487 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
2181 | goto out; | 2488 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
2182 | } | 2489 | return -EINVAL; |
2183 | 2490 | ||
2184 | err = get_vlan(info, rdev, ¶ms.vlan); | 2491 | err = get_vlan(info, rdev, ¶ms.vlan); |
2185 | if (err) | 2492 | if (err) |
@@ -2193,61 +2500,33 @@ static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) | |||
2193 | goto out; | 2500 | goto out; |
2194 | } | 2501 | } |
2195 | 2502 | ||
2196 | if (!netif_running(dev)) { | ||
2197 | err = -ENETDOWN; | ||
2198 | goto out; | ||
2199 | } | ||
2200 | |||
2201 | err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, ¶ms); | 2503 | err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
2202 | 2504 | ||
2203 | out: | 2505 | out: |
2204 | if (params.vlan) | 2506 | if (params.vlan) |
2205 | dev_put(params.vlan); | 2507 | dev_put(params.vlan); |
2206 | cfg80211_unlock_rdev(rdev); | ||
2207 | dev_put(dev); | ||
2208 | out_rtnl: | ||
2209 | rtnl_unlock(); | ||
2210 | |||
2211 | return err; | 2508 | return err; |
2212 | } | 2509 | } |
2213 | 2510 | ||
2214 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) | 2511 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
2215 | { | 2512 | { |
2216 | struct cfg80211_registered_device *rdev; | 2513 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2217 | int err; | 2514 | struct net_device *dev = info->user_ptr[1]; |
2218 | struct net_device *dev; | ||
2219 | u8 *mac_addr = NULL; | 2515 | u8 *mac_addr = NULL; |
2220 | 2516 | ||
2221 | if (info->attrs[NL80211_ATTR_MAC]) | 2517 | if (info->attrs[NL80211_ATTR_MAC]) |
2222 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | 2518 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
2223 | 2519 | ||
2224 | rtnl_lock(); | ||
2225 | |||
2226 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | ||
2227 | if (err) | ||
2228 | goto out_rtnl; | ||
2229 | |||
2230 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | 2520 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
2231 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && | 2521 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
2232 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { | 2522 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
2233 | err = -EINVAL; | 2523 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
2234 | goto out; | 2524 | return -EINVAL; |
2235 | } | ||
2236 | |||
2237 | if (!rdev->ops->del_station) { | ||
2238 | err = -EOPNOTSUPP; | ||
2239 | goto out; | ||
2240 | } | ||
2241 | |||
2242 | err = rdev->ops->del_station(&rdev->wiphy, dev, mac_addr); | ||
2243 | 2525 | ||
2244 | out: | 2526 | if (!rdev->ops->del_station) |
2245 | cfg80211_unlock_rdev(rdev); | 2527 | return -EOPNOTSUPP; |
2246 | dev_put(dev); | ||
2247 | out_rtnl: | ||
2248 | rtnl_unlock(); | ||
2249 | 2528 | ||
2250 | return err; | 2529 | return rdev->ops->del_station(&rdev->wiphy, dev, mac_addr); |
2251 | } | 2530 | } |
2252 | 2531 | ||
2253 | static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq, | 2532 | static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq, |
@@ -2310,28 +2589,12 @@ static int nl80211_dump_mpath(struct sk_buff *skb, | |||
2310 | struct net_device *netdev; | 2589 | struct net_device *netdev; |
2311 | u8 dst[ETH_ALEN]; | 2590 | u8 dst[ETH_ALEN]; |
2312 | u8 next_hop[ETH_ALEN]; | 2591 | u8 next_hop[ETH_ALEN]; |
2313 | int ifidx = cb->args[0]; | ||
2314 | int path_idx = cb->args[1]; | 2592 | int path_idx = cb->args[1]; |
2315 | int err; | 2593 | int err; |
2316 | 2594 | ||
2317 | if (!ifidx) | 2595 | err = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
2318 | ifidx = nl80211_get_ifidx(cb); | 2596 | if (err) |
2319 | if (ifidx < 0) | 2597 | return err; |
2320 | return ifidx; | ||
2321 | |||
2322 | rtnl_lock(); | ||
2323 | |||
2324 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); | ||
2325 | if (!netdev) { | ||
2326 | err = -ENODEV; | ||
2327 | goto out_rtnl; | ||
2328 | } | ||
2329 | |||
2330 | dev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); | ||
2331 | if (IS_ERR(dev)) { | ||
2332 | err = PTR_ERR(dev); | ||
2333 | goto out_rtnl; | ||
2334 | } | ||
2335 | 2598 | ||
2336 | if (!dev->ops->dump_mpath) { | 2599 | if (!dev->ops->dump_mpath) { |
2337 | err = -EOPNOTSUPP; | 2600 | err = -EOPNOTSUPP; |
@@ -2365,18 +2628,15 @@ static int nl80211_dump_mpath(struct sk_buff *skb, | |||
2365 | cb->args[1] = path_idx; | 2628 | cb->args[1] = path_idx; |
2366 | err = skb->len; | 2629 | err = skb->len; |
2367 | out_err: | 2630 | out_err: |
2368 | cfg80211_unlock_rdev(dev); | 2631 | nl80211_finish_netdev_dump(dev); |
2369 | out_rtnl: | ||
2370 | rtnl_unlock(); | ||
2371 | |||
2372 | return err; | 2632 | return err; |
2373 | } | 2633 | } |
2374 | 2634 | ||
2375 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) | 2635 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
2376 | { | 2636 | { |
2377 | struct cfg80211_registered_device *rdev; | 2637 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2378 | int err; | 2638 | int err; |
2379 | struct net_device *dev; | 2639 | struct net_device *dev = info->user_ptr[1]; |
2380 | struct mpath_info pinfo; | 2640 | struct mpath_info pinfo; |
2381 | struct sk_buff *msg; | 2641 | struct sk_buff *msg; |
2382 | u8 *dst = NULL; | 2642 | u8 *dst = NULL; |
@@ -2389,53 +2649,33 @@ static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) | |||
2389 | 2649 | ||
2390 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | 2650 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
2391 | 2651 | ||
2392 | rtnl_lock(); | 2652 | if (!rdev->ops->get_mpath) |
2393 | 2653 | return -EOPNOTSUPP; | |
2394 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | ||
2395 | if (err) | ||
2396 | goto out_rtnl; | ||
2397 | |||
2398 | if (!rdev->ops->get_mpath) { | ||
2399 | err = -EOPNOTSUPP; | ||
2400 | goto out; | ||
2401 | } | ||
2402 | 2654 | ||
2403 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { | 2655 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
2404 | err = -EOPNOTSUPP; | 2656 | return -EOPNOTSUPP; |
2405 | goto out; | ||
2406 | } | ||
2407 | 2657 | ||
2408 | err = rdev->ops->get_mpath(&rdev->wiphy, dev, dst, next_hop, &pinfo); | 2658 | err = rdev->ops->get_mpath(&rdev->wiphy, dev, dst, next_hop, &pinfo); |
2409 | if (err) | 2659 | if (err) |
2410 | goto out; | 2660 | return err; |
2411 | 2661 | ||
2412 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 2662 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2413 | if (!msg) | 2663 | if (!msg) |
2414 | goto out; | 2664 | return -ENOMEM; |
2415 | 2665 | ||
2416 | if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0, | 2666 | if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0, |
2417 | dev, dst, next_hop, &pinfo) < 0) | 2667 | dev, dst, next_hop, &pinfo) < 0) { |
2418 | goto out_free; | 2668 | nlmsg_free(msg); |
2419 | 2669 | return -ENOBUFS; | |
2420 | err = genlmsg_reply(msg, info); | 2670 | } |
2421 | goto out; | ||
2422 | |||
2423 | out_free: | ||
2424 | nlmsg_free(msg); | ||
2425 | out: | ||
2426 | cfg80211_unlock_rdev(rdev); | ||
2427 | dev_put(dev); | ||
2428 | out_rtnl: | ||
2429 | rtnl_unlock(); | ||
2430 | 2671 | ||
2431 | return err; | 2672 | return genlmsg_reply(msg, info); |
2432 | } | 2673 | } |
2433 | 2674 | ||
2434 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) | 2675 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
2435 | { | 2676 | { |
2436 | struct cfg80211_registered_device *rdev; | 2677 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2437 | int err; | 2678 | struct net_device *dev = info->user_ptr[1]; |
2438 | struct net_device *dev; | ||
2439 | u8 *dst = NULL; | 2679 | u8 *dst = NULL; |
2440 | u8 *next_hop = NULL; | 2680 | u8 *next_hop = NULL; |
2441 | 2681 | ||
@@ -2448,42 +2688,19 @@ static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) | |||
2448 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | 2688 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
2449 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | 2689 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
2450 | 2690 | ||
2451 | rtnl_lock(); | 2691 | if (!rdev->ops->change_mpath) |
2452 | 2692 | return -EOPNOTSUPP; | |
2453 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | ||
2454 | if (err) | ||
2455 | goto out_rtnl; | ||
2456 | |||
2457 | if (!rdev->ops->change_mpath) { | ||
2458 | err = -EOPNOTSUPP; | ||
2459 | goto out; | ||
2460 | } | ||
2461 | |||
2462 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { | ||
2463 | err = -EOPNOTSUPP; | ||
2464 | goto out; | ||
2465 | } | ||
2466 | |||
2467 | if (!netif_running(dev)) { | ||
2468 | err = -ENETDOWN; | ||
2469 | goto out; | ||
2470 | } | ||
2471 | |||
2472 | err = rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop); | ||
2473 | 2693 | ||
2474 | out: | 2694 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
2475 | cfg80211_unlock_rdev(rdev); | 2695 | return -EOPNOTSUPP; |
2476 | dev_put(dev); | ||
2477 | out_rtnl: | ||
2478 | rtnl_unlock(); | ||
2479 | 2696 | ||
2480 | return err; | 2697 | return rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop); |
2481 | } | 2698 | } |
2699 | |||
2482 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) | 2700 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
2483 | { | 2701 | { |
2484 | struct cfg80211_registered_device *rdev; | 2702 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2485 | int err; | 2703 | struct net_device *dev = info->user_ptr[1]; |
2486 | struct net_device *dev; | ||
2487 | u8 *dst = NULL; | 2704 | u8 *dst = NULL; |
2488 | u8 *next_hop = NULL; | 2705 | u8 *next_hop = NULL; |
2489 | 2706 | ||
@@ -2496,75 +2713,34 @@ static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) | |||
2496 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | 2713 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
2497 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | 2714 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
2498 | 2715 | ||
2499 | rtnl_lock(); | 2716 | if (!rdev->ops->add_mpath) |
2500 | 2717 | return -EOPNOTSUPP; | |
2501 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | ||
2502 | if (err) | ||
2503 | goto out_rtnl; | ||
2504 | |||
2505 | if (!rdev->ops->add_mpath) { | ||
2506 | err = -EOPNOTSUPP; | ||
2507 | goto out; | ||
2508 | } | ||
2509 | |||
2510 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { | ||
2511 | err = -EOPNOTSUPP; | ||
2512 | goto out; | ||
2513 | } | ||
2514 | |||
2515 | if (!netif_running(dev)) { | ||
2516 | err = -ENETDOWN; | ||
2517 | goto out; | ||
2518 | } | ||
2519 | |||
2520 | err = rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop); | ||
2521 | 2718 | ||
2522 | out: | 2719 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
2523 | cfg80211_unlock_rdev(rdev); | 2720 | return -EOPNOTSUPP; |
2524 | dev_put(dev); | ||
2525 | out_rtnl: | ||
2526 | rtnl_unlock(); | ||
2527 | 2721 | ||
2528 | return err; | 2722 | return rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop); |
2529 | } | 2723 | } |
2530 | 2724 | ||
2531 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) | 2725 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
2532 | { | 2726 | { |
2533 | struct cfg80211_registered_device *rdev; | 2727 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2534 | int err; | 2728 | struct net_device *dev = info->user_ptr[1]; |
2535 | struct net_device *dev; | ||
2536 | u8 *dst = NULL; | 2729 | u8 *dst = NULL; |
2537 | 2730 | ||
2538 | if (info->attrs[NL80211_ATTR_MAC]) | 2731 | if (info->attrs[NL80211_ATTR_MAC]) |
2539 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | 2732 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
2540 | 2733 | ||
2541 | rtnl_lock(); | 2734 | if (!rdev->ops->del_mpath) |
2542 | 2735 | return -EOPNOTSUPP; | |
2543 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | ||
2544 | if (err) | ||
2545 | goto out_rtnl; | ||
2546 | |||
2547 | if (!rdev->ops->del_mpath) { | ||
2548 | err = -EOPNOTSUPP; | ||
2549 | goto out; | ||
2550 | } | ||
2551 | |||
2552 | err = rdev->ops->del_mpath(&rdev->wiphy, dev, dst); | ||
2553 | |||
2554 | out: | ||
2555 | cfg80211_unlock_rdev(rdev); | ||
2556 | dev_put(dev); | ||
2557 | out_rtnl: | ||
2558 | rtnl_unlock(); | ||
2559 | 2736 | ||
2560 | return err; | 2737 | return rdev->ops->del_mpath(&rdev->wiphy, dev, dst); |
2561 | } | 2738 | } |
2562 | 2739 | ||
2563 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) | 2740 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
2564 | { | 2741 | { |
2565 | struct cfg80211_registered_device *rdev; | 2742 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2566 | int err; | 2743 | struct net_device *dev = info->user_ptr[1]; |
2567 | struct net_device *dev; | ||
2568 | struct bss_parameters params; | 2744 | struct bss_parameters params; |
2569 | 2745 | ||
2570 | memset(¶ms, 0, sizeof(params)); | 2746 | memset(¶ms, 0, sizeof(params)); |
@@ -2573,6 +2749,7 @@ static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) | |||
2573 | params.use_short_preamble = -1; | 2749 | params.use_short_preamble = -1; |
2574 | params.use_short_slot_time = -1; | 2750 | params.use_short_slot_time = -1; |
2575 | params.ap_isolate = -1; | 2751 | params.ap_isolate = -1; |
2752 | params.ht_opmode = -1; | ||
2576 | 2753 | ||
2577 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) | 2754 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
2578 | params.use_cts_prot = | 2755 | params.use_cts_prot = |
@@ -2591,32 +2768,18 @@ static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) | |||
2591 | } | 2768 | } |
2592 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) | 2769 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
2593 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); | 2770 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); |
2771 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) | ||
2772 | params.ht_opmode = | ||
2773 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); | ||
2594 | 2774 | ||
2595 | rtnl_lock(); | 2775 | if (!rdev->ops->change_bss) |
2596 | 2776 | return -EOPNOTSUPP; | |
2597 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | ||
2598 | if (err) | ||
2599 | goto out_rtnl; | ||
2600 | |||
2601 | if (!rdev->ops->change_bss) { | ||
2602 | err = -EOPNOTSUPP; | ||
2603 | goto out; | ||
2604 | } | ||
2605 | |||
2606 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) { | ||
2607 | err = -EOPNOTSUPP; | ||
2608 | goto out; | ||
2609 | } | ||
2610 | |||
2611 | err = rdev->ops->change_bss(&rdev->wiphy, dev, ¶ms); | ||
2612 | 2777 | ||
2613 | out: | 2778 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
2614 | cfg80211_unlock_rdev(rdev); | 2779 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
2615 | dev_put(dev); | 2780 | return -EOPNOTSUPP; |
2616 | out_rtnl: | ||
2617 | rtnl_unlock(); | ||
2618 | 2781 | ||
2619 | return err; | 2782 | return rdev->ops->change_bss(&rdev->wiphy, dev, ¶ms); |
2620 | } | 2783 | } |
2621 | 2784 | ||
2622 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { | 2785 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
@@ -2692,45 +2855,45 @@ static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) | |||
2692 | return r; | 2855 | return r; |
2693 | } | 2856 | } |
2694 | 2857 | ||
2695 | static int nl80211_get_mesh_params(struct sk_buff *skb, | 2858 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
2696 | struct genl_info *info) | 2859 | struct genl_info *info) |
2697 | { | 2860 | { |
2698 | struct cfg80211_registered_device *rdev; | 2861 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2862 | struct net_device *dev = info->user_ptr[1]; | ||
2863 | struct wireless_dev *wdev = dev->ieee80211_ptr; | ||
2699 | struct mesh_config cur_params; | 2864 | struct mesh_config cur_params; |
2700 | int err; | 2865 | int err = 0; |
2701 | struct net_device *dev; | ||
2702 | void *hdr; | 2866 | void *hdr; |
2703 | struct nlattr *pinfoattr; | 2867 | struct nlattr *pinfoattr; |
2704 | struct sk_buff *msg; | 2868 | struct sk_buff *msg; |
2705 | 2869 | ||
2706 | rtnl_lock(); | 2870 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
2871 | return -EOPNOTSUPP; | ||
2707 | 2872 | ||
2708 | /* Look up our device */ | 2873 | if (!rdev->ops->get_mesh_config) |
2709 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | 2874 | return -EOPNOTSUPP; |
2710 | if (err) | ||
2711 | goto out_rtnl; | ||
2712 | 2875 | ||
2713 | if (!rdev->ops->get_mesh_params) { | 2876 | wdev_lock(wdev); |
2714 | err = -EOPNOTSUPP; | 2877 | /* If not connected, get default parameters */ |
2715 | goto out; | 2878 | if (!wdev->mesh_id_len) |
2716 | } | 2879 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); |
2880 | else | ||
2881 | err = rdev->ops->get_mesh_config(&rdev->wiphy, dev, | ||
2882 | &cur_params); | ||
2883 | wdev_unlock(wdev); | ||
2717 | 2884 | ||
2718 | /* Get the mesh params */ | ||
2719 | err = rdev->ops->get_mesh_params(&rdev->wiphy, dev, &cur_params); | ||
2720 | if (err) | 2885 | if (err) |
2721 | goto out; | 2886 | return err; |
2722 | 2887 | ||
2723 | /* Draw up a netlink message to send back */ | 2888 | /* Draw up a netlink message to send back */ |
2724 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 2889 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2725 | if (!msg) { | 2890 | if (!msg) |
2726 | err = -ENOBUFS; | 2891 | return -ENOMEM; |
2727 | goto out; | ||
2728 | } | ||
2729 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | 2892 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
2730 | NL80211_CMD_GET_MESH_PARAMS); | 2893 | NL80211_CMD_GET_MESH_CONFIG); |
2731 | if (!hdr) | 2894 | if (!hdr) |
2732 | goto nla_put_failure; | 2895 | goto out; |
2733 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_PARAMS); | 2896 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
2734 | if (!pinfoattr) | 2897 | if (!pinfoattr) |
2735 | goto nla_put_failure; | 2898 | goto nla_put_failure; |
2736 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); | 2899 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
@@ -2746,6 +2909,8 @@ static int nl80211_get_mesh_params(struct sk_buff *skb, | |||
2746 | cur_params.dot11MeshMaxRetries); | 2909 | cur_params.dot11MeshMaxRetries); |
2747 | NLA_PUT_U8(msg, NL80211_MESHCONF_TTL, | 2910 | NLA_PUT_U8(msg, NL80211_MESHCONF_TTL, |
2748 | cur_params.dot11MeshTTL); | 2911 | cur_params.dot11MeshTTL); |
2912 | NLA_PUT_U8(msg, NL80211_MESHCONF_ELEMENT_TTL, | ||
2913 | cur_params.element_ttl); | ||
2749 | NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | 2914 | NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
2750 | cur_params.auto_open_plinks); | 2915 | cur_params.auto_open_plinks); |
2751 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, | 2916 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
@@ -2764,31 +2929,15 @@ static int nl80211_get_mesh_params(struct sk_buff *skb, | |||
2764 | cur_params.dot11MeshHWMPRootMode); | 2929 | cur_params.dot11MeshHWMPRootMode); |
2765 | nla_nest_end(msg, pinfoattr); | 2930 | nla_nest_end(msg, pinfoattr); |
2766 | genlmsg_end(msg, hdr); | 2931 | genlmsg_end(msg, hdr); |
2767 | err = genlmsg_reply(msg, info); | 2932 | return genlmsg_reply(msg, info); |
2768 | goto out; | ||
2769 | 2933 | ||
2770 | nla_put_failure: | 2934 | nla_put_failure: |
2771 | genlmsg_cancel(msg, hdr); | 2935 | genlmsg_cancel(msg, hdr); |
2772 | nlmsg_free(msg); | ||
2773 | err = -EMSGSIZE; | ||
2774 | out: | 2936 | out: |
2775 | /* Cleanup */ | 2937 | nlmsg_free(msg); |
2776 | cfg80211_unlock_rdev(rdev); | 2938 | return -ENOBUFS; |
2777 | dev_put(dev); | ||
2778 | out_rtnl: | ||
2779 | rtnl_unlock(); | ||
2780 | |||
2781 | return err; | ||
2782 | } | 2939 | } |
2783 | 2940 | ||
2784 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ | ||
2785 | do {\ | ||
2786 | if (table[attr_num]) {\ | ||
2787 | cfg.param = nla_fn(table[attr_num]); \ | ||
2788 | mask |= (1 << (attr_num - 1)); \ | ||
2789 | } \ | ||
2790 | } while (0);\ | ||
2791 | |||
2792 | static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { | 2941 | static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
2793 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, | 2942 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
2794 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, | 2943 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
@@ -2796,6 +2945,7 @@ static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_A | |||
2796 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, | 2945 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
2797 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, | 2946 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
2798 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, | 2947 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
2948 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, | ||
2799 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, | 2949 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
2800 | 2950 | ||
2801 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, | 2951 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
@@ -2806,40 +2956,44 @@ static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_A | |||
2806 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, | 2956 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
2807 | }; | 2957 | }; |
2808 | 2958 | ||
2809 | static int nl80211_set_mesh_params(struct sk_buff *skb, struct genl_info *info) | 2959 | static const struct nla_policy |
2960 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { | ||
2961 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, | ||
2962 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, | ||
2963 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, | ||
2964 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, | ||
2965 | .len = IEEE80211_MAX_DATA_LEN }, | ||
2966 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, | ||
2967 | }; | ||
2968 | |||
2969 | static int nl80211_parse_mesh_config(struct genl_info *info, | ||
2970 | struct mesh_config *cfg, | ||
2971 | u32 *mask_out) | ||
2810 | { | 2972 | { |
2811 | int err; | ||
2812 | u32 mask; | ||
2813 | struct cfg80211_registered_device *rdev; | ||
2814 | struct net_device *dev; | ||
2815 | struct mesh_config cfg; | ||
2816 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; | 2973 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
2817 | struct nlattr *parent_attr; | 2974 | u32 mask = 0; |
2975 | |||
2976 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ | ||
2977 | do {\ | ||
2978 | if (table[attr_num]) {\ | ||
2979 | cfg->param = nla_fn(table[attr_num]); \ | ||
2980 | mask |= (1 << (attr_num - 1)); \ | ||
2981 | } \ | ||
2982 | } while (0);\ | ||
2818 | 2983 | ||
2819 | parent_attr = info->attrs[NL80211_ATTR_MESH_PARAMS]; | 2984 | |
2820 | if (!parent_attr) | 2985 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
2821 | return -EINVAL; | 2986 | return -EINVAL; |
2822 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, | 2987 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
2823 | parent_attr, nl80211_meshconf_params_policy)) | 2988 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
2989 | nl80211_meshconf_params_policy)) | ||
2824 | return -EINVAL; | 2990 | return -EINVAL; |
2825 | 2991 | ||
2826 | rtnl_lock(); | ||
2827 | |||
2828 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | ||
2829 | if (err) | ||
2830 | goto out_rtnl; | ||
2831 | |||
2832 | if (!rdev->ops->set_mesh_params) { | ||
2833 | err = -EOPNOTSUPP; | ||
2834 | goto out; | ||
2835 | } | ||
2836 | |||
2837 | /* This makes sure that there aren't more than 32 mesh config | 2992 | /* This makes sure that there aren't more than 32 mesh config |
2838 | * parameters (otherwise our bitfield scheme would not work.) */ | 2993 | * parameters (otherwise our bitfield scheme would not work.) */ |
2839 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); | 2994 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
2840 | 2995 | ||
2841 | /* Fill in the params struct */ | 2996 | /* Fill in the params struct */ |
2842 | mask = 0; | ||
2843 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, | 2997 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, |
2844 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); | 2998 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); |
2845 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, | 2999 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, |
@@ -2852,6 +3006,8 @@ static int nl80211_set_mesh_params(struct sk_buff *skb, struct genl_info *info) | |||
2852 | mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); | 3006 | mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); |
2853 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, | 3007 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, |
2854 | mask, NL80211_MESHCONF_TTL, nla_get_u8); | 3008 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
3009 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, | ||
3010 | mask, NL80211_MESHCONF_ELEMENT_TTL, nla_get_u8); | ||
2855 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, | 3011 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, |
2856 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8); | 3012 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8); |
2857 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, | 3013 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, |
@@ -2876,21 +3032,85 @@ static int nl80211_set_mesh_params(struct sk_buff *skb, struct genl_info *info) | |||
2876 | dot11MeshHWMPRootMode, mask, | 3032 | dot11MeshHWMPRootMode, mask, |
2877 | NL80211_MESHCONF_HWMP_ROOTMODE, | 3033 | NL80211_MESHCONF_HWMP_ROOTMODE, |
2878 | nla_get_u8); | 3034 | nla_get_u8); |
3035 | if (mask_out) | ||
3036 | *mask_out = mask; | ||
2879 | 3037 | ||
2880 | /* Apply changes */ | 3038 | return 0; |
2881 | err = rdev->ops->set_mesh_params(&rdev->wiphy, dev, &cfg, mask); | ||
2882 | 3039 | ||
2883 | out: | 3040 | #undef FILL_IN_MESH_PARAM_IF_SET |
2884 | /* cleanup */ | 3041 | } |
2885 | cfg80211_unlock_rdev(rdev); | ||
2886 | dev_put(dev); | ||
2887 | out_rtnl: | ||
2888 | rtnl_unlock(); | ||
2889 | 3042 | ||
2890 | return err; | 3043 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
3044 | struct mesh_setup *setup) | ||
3045 | { | ||
3046 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; | ||
3047 | |||
3048 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) | ||
3049 | return -EINVAL; | ||
3050 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, | ||
3051 | info->attrs[NL80211_ATTR_MESH_SETUP], | ||
3052 | nl80211_mesh_setup_params_policy)) | ||
3053 | return -EINVAL; | ||
3054 | |||
3055 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) | ||
3056 | setup->path_sel_proto = | ||
3057 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? | ||
3058 | IEEE80211_PATH_PROTOCOL_VENDOR : | ||
3059 | IEEE80211_PATH_PROTOCOL_HWMP; | ||
3060 | |||
3061 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) | ||
3062 | setup->path_metric = | ||
3063 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? | ||
3064 | IEEE80211_PATH_METRIC_VENDOR : | ||
3065 | IEEE80211_PATH_METRIC_AIRTIME; | ||
3066 | |||
3067 | |||
3068 | if (tb[NL80211_MESH_SETUP_IE]) { | ||
3069 | struct nlattr *ieattr = | ||
3070 | tb[NL80211_MESH_SETUP_IE]; | ||
3071 | if (!is_valid_ie_attr(ieattr)) | ||
3072 | return -EINVAL; | ||
3073 | setup->ie = nla_data(ieattr); | ||
3074 | setup->ie_len = nla_len(ieattr); | ||
3075 | } | ||
3076 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); | ||
3077 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); | ||
3078 | |||
3079 | return 0; | ||
2891 | } | 3080 | } |
2892 | 3081 | ||
2893 | #undef FILL_IN_MESH_PARAM_IF_SET | 3082 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
3083 | struct genl_info *info) | ||
3084 | { | ||
3085 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | ||
3086 | struct net_device *dev = info->user_ptr[1]; | ||
3087 | struct wireless_dev *wdev = dev->ieee80211_ptr; | ||
3088 | struct mesh_config cfg; | ||
3089 | u32 mask; | ||
3090 | int err; | ||
3091 | |||
3092 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) | ||
3093 | return -EOPNOTSUPP; | ||
3094 | |||
3095 | if (!rdev->ops->update_mesh_config) | ||
3096 | return -EOPNOTSUPP; | ||
3097 | |||
3098 | err = nl80211_parse_mesh_config(info, &cfg, &mask); | ||
3099 | if (err) | ||
3100 | return err; | ||
3101 | |||
3102 | wdev_lock(wdev); | ||
3103 | if (!wdev->mesh_id_len) | ||
3104 | err = -ENOLINK; | ||
3105 | |||
3106 | if (!err) | ||
3107 | err = rdev->ops->update_mesh_config(&rdev->wiphy, dev, | ||
3108 | mask, &cfg); | ||
3109 | |||
3110 | wdev_unlock(wdev); | ||
3111 | |||
3112 | return err; | ||
3113 | } | ||
2894 | 3114 | ||
2895 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) | 3115 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
2896 | { | 3116 | { |
@@ -2914,7 +3134,7 @@ static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) | |||
2914 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | 3134 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
2915 | NL80211_CMD_GET_REG); | 3135 | NL80211_CMD_GET_REG); |
2916 | if (!hdr) | 3136 | if (!hdr) |
2917 | goto nla_put_failure; | 3137 | goto put_failure; |
2918 | 3138 | ||
2919 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, | 3139 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, |
2920 | cfg80211_regdomain->alpha2); | 3140 | cfg80211_regdomain->alpha2); |
@@ -2961,6 +3181,7 @@ static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) | |||
2961 | 3181 | ||
2962 | nla_put_failure: | 3182 | nla_put_failure: |
2963 | genlmsg_cancel(msg, hdr); | 3183 | genlmsg_cancel(msg, hdr); |
3184 | put_failure: | ||
2964 | nlmsg_free(msg); | 3185 | nlmsg_free(msg); |
2965 | err = -EMSGSIZE; | 3186 | err = -EMSGSIZE; |
2966 | out: | 3187 | out: |
@@ -3070,11 +3291,9 @@ static int validate_scan_freqs(struct nlattr *freqs) | |||
3070 | 3291 | ||
3071 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) | 3292 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
3072 | { | 3293 | { |
3073 | struct cfg80211_registered_device *rdev; | 3294 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3074 | struct net_device *dev; | 3295 | struct net_device *dev = info->user_ptr[1]; |
3075 | struct cfg80211_scan_request *request; | 3296 | struct cfg80211_scan_request *request; |
3076 | struct cfg80211_ssid *ssid; | ||
3077 | struct ieee80211_channel *channel; | ||
3078 | struct nlattr *attr; | 3297 | struct nlattr *attr; |
3079 | struct wiphy *wiphy; | 3298 | struct wiphy *wiphy; |
3080 | int err, tmp, n_ssids = 0, n_channels, i; | 3299 | int err, tmp, n_ssids = 0, n_channels, i; |
@@ -3084,36 +3303,178 @@ static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) | |||
3084 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | 3303 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
3085 | return -EINVAL; | 3304 | return -EINVAL; |
3086 | 3305 | ||
3087 | rtnl_lock(); | 3306 | wiphy = &rdev->wiphy; |
3088 | 3307 | ||
3089 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | 3308 | if (!rdev->ops->scan) |
3090 | if (err) | 3309 | return -EOPNOTSUPP; |
3091 | goto out_rtnl; | ||
3092 | 3310 | ||
3093 | wiphy = &rdev->wiphy; | 3311 | if (rdev->scan_req) |
3312 | return -EBUSY; | ||
3094 | 3313 | ||
3095 | if (!rdev->ops->scan) { | 3314 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
3096 | err = -EOPNOTSUPP; | 3315 | n_channels = validate_scan_freqs( |
3097 | goto out; | 3316 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
3317 | if (!n_channels) | ||
3318 | return -EINVAL; | ||
3319 | } else { | ||
3320 | n_channels = 0; | ||
3321 | |||
3322 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) | ||
3323 | if (wiphy->bands[band]) | ||
3324 | n_channels += wiphy->bands[band]->n_channels; | ||
3098 | } | 3325 | } |
3099 | 3326 | ||
3100 | if (!netif_running(dev)) { | 3327 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
3101 | err = -ENETDOWN; | 3328 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
3102 | goto out; | 3329 | n_ssids++; |
3330 | |||
3331 | if (n_ssids > wiphy->max_scan_ssids) | ||
3332 | return -EINVAL; | ||
3333 | |||
3334 | if (info->attrs[NL80211_ATTR_IE]) | ||
3335 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | ||
3336 | else | ||
3337 | ie_len = 0; | ||
3338 | |||
3339 | if (ie_len > wiphy->max_scan_ie_len) | ||
3340 | return -EINVAL; | ||
3341 | |||
3342 | request = kzalloc(sizeof(*request) | ||
3343 | + sizeof(*request->ssids) * n_ssids | ||
3344 | + sizeof(*request->channels) * n_channels | ||
3345 | + ie_len, GFP_KERNEL); | ||
3346 | if (!request) | ||
3347 | return -ENOMEM; | ||
3348 | |||
3349 | if (n_ssids) | ||
3350 | request->ssids = (void *)&request->channels[n_channels]; | ||
3351 | request->n_ssids = n_ssids; | ||
3352 | if (ie_len) { | ||
3353 | if (request->ssids) | ||
3354 | request->ie = (void *)(request->ssids + n_ssids); | ||
3355 | else | ||
3356 | request->ie = (void *)(request->channels + n_channels); | ||
3103 | } | 3357 | } |
3104 | 3358 | ||
3105 | if (rdev->scan_req) { | 3359 | i = 0; |
3106 | err = -EBUSY; | 3360 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
3107 | goto out; | 3361 | /* user specified, bail out if channel not found */ |
3362 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { | ||
3363 | struct ieee80211_channel *chan; | ||
3364 | |||
3365 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | ||
3366 | |||
3367 | if (!chan) { | ||
3368 | err = -EINVAL; | ||
3369 | goto out_free; | ||
3370 | } | ||
3371 | |||
3372 | /* ignore disabled channels */ | ||
3373 | if (chan->flags & IEEE80211_CHAN_DISABLED) | ||
3374 | continue; | ||
3375 | |||
3376 | request->channels[i] = chan; | ||
3377 | i++; | ||
3378 | } | ||
3379 | } else { | ||
3380 | /* all channels */ | ||
3381 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | ||
3382 | int j; | ||
3383 | if (!wiphy->bands[band]) | ||
3384 | continue; | ||
3385 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | ||
3386 | struct ieee80211_channel *chan; | ||
3387 | |||
3388 | chan = &wiphy->bands[band]->channels[j]; | ||
3389 | |||
3390 | if (chan->flags & IEEE80211_CHAN_DISABLED) | ||
3391 | continue; | ||
3392 | |||
3393 | request->channels[i] = chan; | ||
3394 | i++; | ||
3395 | } | ||
3396 | } | ||
3397 | } | ||
3398 | |||
3399 | if (!i) { | ||
3400 | err = -EINVAL; | ||
3401 | goto out_free; | ||
3402 | } | ||
3403 | |||
3404 | request->n_channels = i; | ||
3405 | |||
3406 | i = 0; | ||
3407 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | ||
3408 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { | ||
3409 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { | ||
3410 | err = -EINVAL; | ||
3411 | goto out_free; | ||
3412 | } | ||
3413 | request->ssids[i].ssid_len = nla_len(attr); | ||
3414 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); | ||
3415 | i++; | ||
3416 | } | ||
3417 | } | ||
3418 | |||
3419 | if (info->attrs[NL80211_ATTR_IE]) { | ||
3420 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | ||
3421 | memcpy((void *)request->ie, | ||
3422 | nla_data(info->attrs[NL80211_ATTR_IE]), | ||
3423 | request->ie_len); | ||
3108 | } | 3424 | } |
3109 | 3425 | ||
3426 | request->dev = dev; | ||
3427 | request->wiphy = &rdev->wiphy; | ||
3428 | |||
3429 | rdev->scan_req = request; | ||
3430 | err = rdev->ops->scan(&rdev->wiphy, dev, request); | ||
3431 | |||
3432 | if (!err) { | ||
3433 | nl80211_send_scan_start(rdev, dev); | ||
3434 | dev_hold(dev); | ||
3435 | } else { | ||
3436 | out_free: | ||
3437 | rdev->scan_req = NULL; | ||
3438 | kfree(request); | ||
3439 | } | ||
3440 | |||
3441 | return err; | ||
3442 | } | ||
3443 | |||
3444 | static int nl80211_start_sched_scan(struct sk_buff *skb, | ||
3445 | struct genl_info *info) | ||
3446 | { | ||
3447 | struct cfg80211_sched_scan_request *request; | ||
3448 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | ||
3449 | struct net_device *dev = info->user_ptr[1]; | ||
3450 | struct nlattr *attr; | ||
3451 | struct wiphy *wiphy; | ||
3452 | int err, tmp, n_ssids = 0, n_channels, i; | ||
3453 | u32 interval; | ||
3454 | enum ieee80211_band band; | ||
3455 | size_t ie_len; | ||
3456 | |||
3457 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | ||
3458 | !rdev->ops->sched_scan_start) | ||
3459 | return -EOPNOTSUPP; | ||
3460 | |||
3461 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | ||
3462 | return -EINVAL; | ||
3463 | |||
3464 | if (!info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) | ||
3465 | return -EINVAL; | ||
3466 | |||
3467 | interval = nla_get_u32(info->attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); | ||
3468 | if (interval == 0) | ||
3469 | return -EINVAL; | ||
3470 | |||
3471 | wiphy = &rdev->wiphy; | ||
3472 | |||
3110 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | 3473 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
3111 | n_channels = validate_scan_freqs( | 3474 | n_channels = validate_scan_freqs( |
3112 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | 3475 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
3113 | if (!n_channels) { | 3476 | if (!n_channels) |
3114 | err = -EINVAL; | 3477 | return -EINVAL; |
3115 | goto out; | ||
3116 | } | ||
3117 | } else { | 3478 | } else { |
3118 | n_channels = 0; | 3479 | n_channels = 0; |
3119 | 3480 | ||
@@ -3123,27 +3484,31 @@ static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) | |||
3123 | } | 3484 | } |
3124 | 3485 | ||
3125 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | 3486 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
3126 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) | 3487 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
3488 | tmp) | ||
3127 | n_ssids++; | 3489 | n_ssids++; |
3128 | 3490 | ||
3129 | if (n_ssids > wiphy->max_scan_ssids) { | 3491 | if (n_ssids > wiphy->max_scan_ssids) |
3130 | err = -EINVAL; | 3492 | return -EINVAL; |
3131 | goto out; | ||
3132 | } | ||
3133 | 3493 | ||
3134 | if (info->attrs[NL80211_ATTR_IE]) | 3494 | if (info->attrs[NL80211_ATTR_IE]) |
3135 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | 3495 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
3136 | else | 3496 | else |
3137 | ie_len = 0; | 3497 | ie_len = 0; |
3138 | 3498 | ||
3139 | if (ie_len > wiphy->max_scan_ie_len) { | 3499 | if (ie_len > wiphy->max_scan_ie_len) |
3140 | err = -EINVAL; | 3500 | return -EINVAL; |
3501 | |||
3502 | mutex_lock(&rdev->sched_scan_mtx); | ||
3503 | |||
3504 | if (rdev->sched_scan_req) { | ||
3505 | err = -EINPROGRESS; | ||
3141 | goto out; | 3506 | goto out; |
3142 | } | 3507 | } |
3143 | 3508 | ||
3144 | request = kzalloc(sizeof(*request) | 3509 | request = kzalloc(sizeof(*request) |
3145 | + sizeof(*ssid) * n_ssids | 3510 | + sizeof(*request->ssids) * n_ssids |
3146 | + sizeof(channel) * n_channels | 3511 | + sizeof(*request->channels) * n_channels |
3147 | + ie_len, GFP_KERNEL); | 3512 | + ie_len, GFP_KERNEL); |
3148 | if (!request) { | 3513 | if (!request) { |
3149 | err = -ENOMEM; | 3514 | err = -ENOMEM; |
@@ -3163,7 +3528,9 @@ static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) | |||
3163 | i = 0; | 3528 | i = 0; |
3164 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | 3529 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
3165 | /* user specified, bail out if channel not found */ | 3530 | /* user specified, bail out if channel not found */ |
3166 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { | 3531 | nla_for_each_nested(attr, |
3532 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], | ||
3533 | tmp) { | ||
3167 | struct ieee80211_channel *chan; | 3534 | struct ieee80211_channel *chan; |
3168 | 3535 | ||
3169 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | 3536 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
@@ -3209,13 +3576,15 @@ static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) | |||
3209 | 3576 | ||
3210 | i = 0; | 3577 | i = 0; |
3211 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | 3578 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
3212 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { | 3579 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], |
3213 | if (request->ssids[i].ssid_len > IEEE80211_MAX_SSID_LEN) { | 3580 | tmp) { |
3581 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { | ||
3214 | err = -EINVAL; | 3582 | err = -EINVAL; |
3215 | goto out_free; | 3583 | goto out_free; |
3216 | } | 3584 | } |
3217 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); | ||
3218 | request->ssids[i].ssid_len = nla_len(attr); | 3585 | request->ssids[i].ssid_len = nla_len(attr); |
3586 | memcpy(request->ssids[i].ssid, nla_data(attr), | ||
3587 | nla_len(attr)); | ||
3219 | i++; | 3588 | i++; |
3220 | } | 3589 | } |
3221 | } | 3590 | } |
@@ -3229,25 +3598,36 @@ static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) | |||
3229 | 3598 | ||
3230 | request->dev = dev; | 3599 | request->dev = dev; |
3231 | request->wiphy = &rdev->wiphy; | 3600 | request->wiphy = &rdev->wiphy; |
3601 | request->interval = interval; | ||
3232 | 3602 | ||
3233 | rdev->scan_req = request; | 3603 | err = rdev->ops->sched_scan_start(&rdev->wiphy, dev, request); |
3234 | err = rdev->ops->scan(&rdev->wiphy, dev, request); | ||
3235 | |||
3236 | if (!err) { | 3604 | if (!err) { |
3237 | nl80211_send_scan_start(rdev, dev); | 3605 | rdev->sched_scan_req = request; |
3238 | dev_hold(dev); | 3606 | nl80211_send_sched_scan(rdev, dev, |
3607 | NL80211_CMD_START_SCHED_SCAN); | ||
3608 | goto out; | ||
3239 | } | 3609 | } |
3240 | 3610 | ||
3241 | out_free: | 3611 | out_free: |
3242 | if (err) { | 3612 | kfree(request); |
3243 | rdev->scan_req = NULL; | 3613 | out: |
3244 | kfree(request); | 3614 | mutex_unlock(&rdev->sched_scan_mtx); |
3245 | } | 3615 | return err; |
3246 | out: | 3616 | } |
3247 | cfg80211_unlock_rdev(rdev); | 3617 | |
3248 | dev_put(dev); | 3618 | static int nl80211_stop_sched_scan(struct sk_buff *skb, |
3249 | out_rtnl: | 3619 | struct genl_info *info) |
3250 | rtnl_unlock(); | 3620 | { |
3621 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | ||
3622 | int err; | ||
3623 | |||
3624 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | ||
3625 | !rdev->ops->sched_scan_stop) | ||
3626 | return -EOPNOTSUPP; | ||
3627 | |||
3628 | mutex_lock(&rdev->sched_scan_mtx); | ||
3629 | err = __cfg80211_stop_sched_scan(rdev, false); | ||
3630 | mutex_unlock(&rdev->sched_scan_mtx); | ||
3251 | 3631 | ||
3252 | return err; | 3632 | return err; |
3253 | } | 3633 | } |
@@ -3306,6 +3686,7 @@ static int nl80211_send_bss(struct sk_buff *msg, u32 pid, u32 seq, int flags, | |||
3306 | } | 3686 | } |
3307 | 3687 | ||
3308 | switch (wdev->iftype) { | 3688 | switch (wdev->iftype) { |
3689 | case NL80211_IFTYPE_P2P_CLIENT: | ||
3309 | case NL80211_IFTYPE_STATION: | 3690 | case NL80211_IFTYPE_STATION: |
3310 | if (intbss == wdev->current_bss) | 3691 | if (intbss == wdev->current_bss) |
3311 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, | 3692 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
@@ -3343,25 +3724,12 @@ static int nl80211_dump_scan(struct sk_buff *skb, | |||
3343 | struct net_device *dev; | 3724 | struct net_device *dev; |
3344 | struct cfg80211_internal_bss *scan; | 3725 | struct cfg80211_internal_bss *scan; |
3345 | struct wireless_dev *wdev; | 3726 | struct wireless_dev *wdev; |
3346 | int ifidx = cb->args[0]; | ||
3347 | int start = cb->args[1], idx = 0; | 3727 | int start = cb->args[1], idx = 0; |
3348 | int err; | 3728 | int err; |
3349 | 3729 | ||
3350 | if (!ifidx) | 3730 | err = nl80211_prepare_netdev_dump(skb, cb, &rdev, &dev); |
3351 | ifidx = nl80211_get_ifidx(cb); | 3731 | if (err) |
3352 | if (ifidx < 0) | 3732 | return err; |
3353 | return ifidx; | ||
3354 | cb->args[0] = ifidx; | ||
3355 | |||
3356 | dev = dev_get_by_index(sock_net(skb->sk), ifidx); | ||
3357 | if (!dev) | ||
3358 | return -ENODEV; | ||
3359 | |||
3360 | rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); | ||
3361 | if (IS_ERR(rdev)) { | ||
3362 | err = PTR_ERR(rdev); | ||
3363 | goto out_put_netdev; | ||
3364 | } | ||
3365 | 3733 | ||
3366 | wdev = dev->ieee80211_ptr; | 3734 | wdev = dev->ieee80211_ptr; |
3367 | 3735 | ||
@@ -3377,21 +3745,17 @@ static int nl80211_dump_scan(struct sk_buff *skb, | |||
3377 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | 3745 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
3378 | rdev, wdev, scan) < 0) { | 3746 | rdev, wdev, scan) < 0) { |
3379 | idx--; | 3747 | idx--; |
3380 | goto out; | 3748 | break; |
3381 | } | 3749 | } |
3382 | } | 3750 | } |
3383 | 3751 | ||
3384 | out: | ||
3385 | spin_unlock_bh(&rdev->bss_lock); | 3752 | spin_unlock_bh(&rdev->bss_lock); |
3386 | wdev_unlock(wdev); | 3753 | wdev_unlock(wdev); |
3387 | 3754 | ||
3388 | cb->args[1] = idx; | 3755 | cb->args[1] = idx; |
3389 | err = skb->len; | 3756 | nl80211_finish_netdev_dump(rdev); |
3390 | cfg80211_unlock_rdev(rdev); | ||
3391 | out_put_netdev: | ||
3392 | dev_put(dev); | ||
3393 | 3757 | ||
3394 | return err; | 3758 | return skb->len; |
3395 | } | 3759 | } |
3396 | 3760 | ||
3397 | static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq, | 3761 | static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq, |
@@ -3421,6 +3785,23 @@ static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq, | |||
3421 | if (survey->filled & SURVEY_INFO_NOISE_DBM) | 3785 | if (survey->filled & SURVEY_INFO_NOISE_DBM) |
3422 | NLA_PUT_U8(msg, NL80211_SURVEY_INFO_NOISE, | 3786 | NLA_PUT_U8(msg, NL80211_SURVEY_INFO_NOISE, |
3423 | survey->noise); | 3787 | survey->noise); |
3788 | if (survey->filled & SURVEY_INFO_IN_USE) | ||
3789 | NLA_PUT_FLAG(msg, NL80211_SURVEY_INFO_IN_USE); | ||
3790 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME) | ||
3791 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME, | ||
3792 | survey->channel_time); | ||
3793 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) | ||
3794 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY, | ||
3795 | survey->channel_time_busy); | ||
3796 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) | ||
3797 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY, | ||
3798 | survey->channel_time_ext_busy); | ||
3799 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) | ||
3800 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX, | ||
3801 | survey->channel_time_rx); | ||
3802 | if (survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) | ||
3803 | NLA_PUT_U64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX, | ||
3804 | survey->channel_time_tx); | ||
3424 | 3805 | ||
3425 | nla_nest_end(msg, infoattr); | 3806 | nla_nest_end(msg, infoattr); |
3426 | 3807 | ||
@@ -3437,29 +3818,12 @@ static int nl80211_dump_survey(struct sk_buff *skb, | |||
3437 | struct survey_info survey; | 3818 | struct survey_info survey; |
3438 | struct cfg80211_registered_device *dev; | 3819 | struct cfg80211_registered_device *dev; |
3439 | struct net_device *netdev; | 3820 | struct net_device *netdev; |
3440 | int ifidx = cb->args[0]; | ||
3441 | int survey_idx = cb->args[1]; | 3821 | int survey_idx = cb->args[1]; |
3442 | int res; | 3822 | int res; |
3443 | 3823 | ||
3444 | if (!ifidx) | 3824 | res = nl80211_prepare_netdev_dump(skb, cb, &dev, &netdev); |
3445 | ifidx = nl80211_get_ifidx(cb); | 3825 | if (res) |
3446 | if (ifidx < 0) | 3826 | return res; |
3447 | return ifidx; | ||
3448 | cb->args[0] = ifidx; | ||
3449 | |||
3450 | rtnl_lock(); | ||
3451 | |||
3452 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); | ||
3453 | if (!netdev) { | ||
3454 | res = -ENODEV; | ||
3455 | goto out_rtnl; | ||
3456 | } | ||
3457 | |||
3458 | dev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); | ||
3459 | if (IS_ERR(dev)) { | ||
3460 | res = PTR_ERR(dev); | ||
3461 | goto out_rtnl; | ||
3462 | } | ||
3463 | 3827 | ||
3464 | if (!dev->ops->dump_survey) { | 3828 | if (!dev->ops->dump_survey) { |
3465 | res = -EOPNOTSUPP; | 3829 | res = -EOPNOTSUPP; |
@@ -3487,10 +3851,7 @@ static int nl80211_dump_survey(struct sk_buff *skb, | |||
3487 | cb->args[1] = survey_idx; | 3851 | cb->args[1] = survey_idx; |
3488 | res = skb->len; | 3852 | res = skb->len; |
3489 | out_err: | 3853 | out_err: |
3490 | cfg80211_unlock_rdev(dev); | 3854 | nl80211_finish_netdev_dump(dev); |
3491 | out_rtnl: | ||
3492 | rtnl_unlock(); | ||
3493 | |||
3494 | return res; | 3855 | return res; |
3495 | } | 3856 | } |
3496 | 3857 | ||
@@ -3523,8 +3884,8 @@ static bool nl80211_valid_cipher_suite(u32 cipher) | |||
3523 | 3884 | ||
3524 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) | 3885 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
3525 | { | 3886 | { |
3526 | struct cfg80211_registered_device *rdev; | 3887 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3527 | struct net_device *dev; | 3888 | struct net_device *dev = info->user_ptr[1]; |
3528 | struct ieee80211_channel *chan; | 3889 | struct ieee80211_channel *chan; |
3529 | const u8 *bssid, *ssid, *ie = NULL; | 3890 | const u8 *bssid, *ssid, *ie = NULL; |
3530 | int err, ssid_len, ie_len = 0; | 3891 | int err, ssid_len, ie_len = 0; |
@@ -3552,6 +3913,8 @@ static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) | |||
3552 | return err; | 3913 | return err; |
3553 | 3914 | ||
3554 | if (key.idx >= 0) { | 3915 | if (key.idx >= 0) { |
3916 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) | ||
3917 | return -EINVAL; | ||
3555 | if (!key.p.key || !key.p.key_len) | 3918 | if (!key.p.key || !key.p.key_len) |
3556 | return -EINVAL; | 3919 | return -EINVAL; |
3557 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || | 3920 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
@@ -3566,34 +3929,31 @@ static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) | |||
3566 | key.p.key = NULL; | 3929 | key.p.key = NULL; |
3567 | } | 3930 | } |
3568 | 3931 | ||
3569 | rtnl_lock(); | 3932 | if (key.idx >= 0) { |
3570 | 3933 | int i; | |
3571 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | 3934 | bool ok = false; |
3572 | if (err) | 3935 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
3573 | goto unlock_rtnl; | 3936 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { |
3574 | 3937 | ok = true; | |
3575 | if (!rdev->ops->auth) { | 3938 | break; |
3576 | err = -EOPNOTSUPP; | 3939 | } |
3577 | goto out; | 3940 | } |
3941 | if (!ok) | ||
3942 | return -EINVAL; | ||
3578 | } | 3943 | } |
3579 | 3944 | ||
3580 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) { | 3945 | if (!rdev->ops->auth) |
3581 | err = -EOPNOTSUPP; | 3946 | return -EOPNOTSUPP; |
3582 | goto out; | ||
3583 | } | ||
3584 | 3947 | ||
3585 | if (!netif_running(dev)) { | 3948 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
3586 | err = -ENETDOWN; | 3949 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
3587 | goto out; | 3950 | return -EOPNOTSUPP; |
3588 | } | ||
3589 | 3951 | ||
3590 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | 3952 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
3591 | chan = ieee80211_get_channel(&rdev->wiphy, | 3953 | chan = ieee80211_get_channel(&rdev->wiphy, |
3592 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | 3954 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
3593 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) { | 3955 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
3594 | err = -EINVAL; | 3956 | return -EINVAL; |
3595 | goto out; | ||
3596 | } | ||
3597 | 3957 | ||
3598 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | 3958 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
3599 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | 3959 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
@@ -3604,27 +3964,19 @@ static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) | |||
3604 | } | 3964 | } |
3605 | 3965 | ||
3606 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | 3966 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
3607 | if (!nl80211_valid_auth_type(auth_type)) { | 3967 | if (!nl80211_valid_auth_type(auth_type)) |
3608 | err = -EINVAL; | 3968 | return -EINVAL; |
3609 | goto out; | ||
3610 | } | ||
3611 | 3969 | ||
3612 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; | 3970 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
3613 | 3971 | ||
3614 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, | 3972 | return cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
3615 | ssid, ssid_len, ie, ie_len, | 3973 | ssid, ssid_len, ie, ie_len, |
3616 | key.p.key, key.p.key_len, key.idx, | 3974 | key.p.key, key.p.key_len, key.idx, |
3617 | local_state_change); | 3975 | local_state_change); |
3618 | |||
3619 | out: | ||
3620 | cfg80211_unlock_rdev(rdev); | ||
3621 | dev_put(dev); | ||
3622 | unlock_rtnl: | ||
3623 | rtnl_unlock(); | ||
3624 | return err; | ||
3625 | } | 3976 | } |
3626 | 3977 | ||
3627 | static int nl80211_crypto_settings(struct genl_info *info, | 3978 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
3979 | struct genl_info *info, | ||
3628 | struct cfg80211_crypto_settings *settings, | 3980 | struct cfg80211_crypto_settings *settings, |
3629 | int cipher_limit) | 3981 | int cipher_limit) |
3630 | { | 3982 | { |
@@ -3632,6 +3984,19 @@ static int nl80211_crypto_settings(struct genl_info *info, | |||
3632 | 3984 | ||
3633 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; | 3985 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
3634 | 3986 | ||
3987 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { | ||
3988 | u16 proto; | ||
3989 | proto = nla_get_u16( | ||
3990 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); | ||
3991 | settings->control_port_ethertype = cpu_to_be16(proto); | ||
3992 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | ||
3993 | proto != ETH_P_PAE) | ||
3994 | return -EINVAL; | ||
3995 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) | ||
3996 | settings->control_port_no_encrypt = true; | ||
3997 | } else | ||
3998 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); | ||
3999 | |||
3635 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { | 4000 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
3636 | void *data; | 4001 | void *data; |
3637 | int len, i; | 4002 | int len, i; |
@@ -3691,8 +4056,8 @@ static int nl80211_crypto_settings(struct genl_info *info, | |||
3691 | 4056 | ||
3692 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) | 4057 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
3693 | { | 4058 | { |
3694 | struct cfg80211_registered_device *rdev; | 4059 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3695 | struct net_device *dev; | 4060 | struct net_device *dev = info->user_ptr[1]; |
3696 | struct cfg80211_crypto_settings crypto; | 4061 | struct cfg80211_crypto_settings crypto; |
3697 | struct ieee80211_channel *chan; | 4062 | struct ieee80211_channel *chan; |
3698 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; | 4063 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
@@ -3707,35 +4072,19 @@ static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) | |||
3707 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | 4072 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
3708 | return -EINVAL; | 4073 | return -EINVAL; |
3709 | 4074 | ||
3710 | rtnl_lock(); | 4075 | if (!rdev->ops->assoc) |
3711 | 4076 | return -EOPNOTSUPP; | |
3712 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | ||
3713 | if (err) | ||
3714 | goto unlock_rtnl; | ||
3715 | |||
3716 | if (!rdev->ops->assoc) { | ||
3717 | err = -EOPNOTSUPP; | ||
3718 | goto out; | ||
3719 | } | ||
3720 | |||
3721 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) { | ||
3722 | err = -EOPNOTSUPP; | ||
3723 | goto out; | ||
3724 | } | ||
3725 | 4077 | ||
3726 | if (!netif_running(dev)) { | 4078 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
3727 | err = -ENETDOWN; | 4079 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
3728 | goto out; | 4080 | return -EOPNOTSUPP; |
3729 | } | ||
3730 | 4081 | ||
3731 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | 4082 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
3732 | 4083 | ||
3733 | chan = ieee80211_get_channel(&rdev->wiphy, | 4084 | chan = ieee80211_get_channel(&rdev->wiphy, |
3734 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | 4085 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
3735 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) { | 4086 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) |
3736 | err = -EINVAL; | 4087 | return -EINVAL; |
3737 | goto out; | ||
3738 | } | ||
3739 | 4088 | ||
3740 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | 4089 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
3741 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | 4090 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
@@ -3750,35 +4099,28 @@ static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) | |||
3750 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); | 4099 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
3751 | if (mfp == NL80211_MFP_REQUIRED) | 4100 | if (mfp == NL80211_MFP_REQUIRED) |
3752 | use_mfp = true; | 4101 | use_mfp = true; |
3753 | else if (mfp != NL80211_MFP_NO) { | 4102 | else if (mfp != NL80211_MFP_NO) |
3754 | err = -EINVAL; | 4103 | return -EINVAL; |
3755 | goto out; | ||
3756 | } | ||
3757 | } | 4104 | } |
3758 | 4105 | ||
3759 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) | 4106 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
3760 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); | 4107 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
3761 | 4108 | ||
3762 | err = nl80211_crypto_settings(info, &crypto, 1); | 4109 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
3763 | if (!err) | 4110 | if (!err) |
3764 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, | 4111 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
3765 | ssid, ssid_len, ie, ie_len, use_mfp, | 4112 | ssid, ssid_len, ie, ie_len, use_mfp, |
3766 | &crypto); | 4113 | &crypto); |
3767 | 4114 | ||
3768 | out: | ||
3769 | cfg80211_unlock_rdev(rdev); | ||
3770 | dev_put(dev); | ||
3771 | unlock_rtnl: | ||
3772 | rtnl_unlock(); | ||
3773 | return err; | 4115 | return err; |
3774 | } | 4116 | } |
3775 | 4117 | ||
3776 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) | 4118 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
3777 | { | 4119 | { |
3778 | struct cfg80211_registered_device *rdev; | 4120 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3779 | struct net_device *dev; | 4121 | struct net_device *dev = info->user_ptr[1]; |
3780 | const u8 *ie = NULL, *bssid; | 4122 | const u8 *ie = NULL, *bssid; |
3781 | int err, ie_len = 0; | 4123 | int ie_len = 0; |
3782 | u16 reason_code; | 4124 | u16 reason_code; |
3783 | bool local_state_change; | 4125 | bool local_state_change; |
3784 | 4126 | ||
@@ -3791,34 +4133,19 @@ static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) | |||
3791 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | 4133 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
3792 | return -EINVAL; | 4134 | return -EINVAL; |
3793 | 4135 | ||
3794 | rtnl_lock(); | 4136 | if (!rdev->ops->deauth) |
3795 | 4137 | return -EOPNOTSUPP; | |
3796 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | ||
3797 | if (err) | ||
3798 | goto unlock_rtnl; | ||
3799 | |||
3800 | if (!rdev->ops->deauth) { | ||
3801 | err = -EOPNOTSUPP; | ||
3802 | goto out; | ||
3803 | } | ||
3804 | |||
3805 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) { | ||
3806 | err = -EOPNOTSUPP; | ||
3807 | goto out; | ||
3808 | } | ||
3809 | 4138 | ||
3810 | if (!netif_running(dev)) { | 4139 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
3811 | err = -ENETDOWN; | 4140 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
3812 | goto out; | 4141 | return -EOPNOTSUPP; |
3813 | } | ||
3814 | 4142 | ||
3815 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | 4143 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
3816 | 4144 | ||
3817 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | 4145 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
3818 | if (reason_code == 0) { | 4146 | if (reason_code == 0) { |
3819 | /* Reason Code 0 is reserved */ | 4147 | /* Reason Code 0 is reserved */ |
3820 | err = -EINVAL; | 4148 | return -EINVAL; |
3821 | goto out; | ||
3822 | } | 4149 | } |
3823 | 4150 | ||
3824 | if (info->attrs[NL80211_ATTR_IE]) { | 4151 | if (info->attrs[NL80211_ATTR_IE]) { |
@@ -3828,23 +4155,16 @@ static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) | |||
3828 | 4155 | ||
3829 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; | 4156 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
3830 | 4157 | ||
3831 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, | 4158 | return cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, |
3832 | local_state_change); | 4159 | local_state_change); |
3833 | |||
3834 | out: | ||
3835 | cfg80211_unlock_rdev(rdev); | ||
3836 | dev_put(dev); | ||
3837 | unlock_rtnl: | ||
3838 | rtnl_unlock(); | ||
3839 | return err; | ||
3840 | } | 4160 | } |
3841 | 4161 | ||
3842 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) | 4162 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
3843 | { | 4163 | { |
3844 | struct cfg80211_registered_device *rdev; | 4164 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3845 | struct net_device *dev; | 4165 | struct net_device *dev = info->user_ptr[1]; |
3846 | const u8 *ie = NULL, *bssid; | 4166 | const u8 *ie = NULL, *bssid; |
3847 | int err, ie_len = 0; | 4167 | int ie_len = 0; |
3848 | u16 reason_code; | 4168 | u16 reason_code; |
3849 | bool local_state_change; | 4169 | bool local_state_change; |
3850 | 4170 | ||
@@ -3857,34 +4177,19 @@ static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) | |||
3857 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | 4177 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
3858 | return -EINVAL; | 4178 | return -EINVAL; |
3859 | 4179 | ||
3860 | rtnl_lock(); | 4180 | if (!rdev->ops->disassoc) |
3861 | 4181 | return -EOPNOTSUPP; | |
3862 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | ||
3863 | if (err) | ||
3864 | goto unlock_rtnl; | ||
3865 | |||
3866 | if (!rdev->ops->disassoc) { | ||
3867 | err = -EOPNOTSUPP; | ||
3868 | goto out; | ||
3869 | } | ||
3870 | |||
3871 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) { | ||
3872 | err = -EOPNOTSUPP; | ||
3873 | goto out; | ||
3874 | } | ||
3875 | 4182 | ||
3876 | if (!netif_running(dev)) { | 4183 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
3877 | err = -ENETDOWN; | 4184 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
3878 | goto out; | 4185 | return -EOPNOTSUPP; |
3879 | } | ||
3880 | 4186 | ||
3881 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | 4187 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
3882 | 4188 | ||
3883 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | 4189 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
3884 | if (reason_code == 0) { | 4190 | if (reason_code == 0) { |
3885 | /* Reason Code 0 is reserved */ | 4191 | /* Reason Code 0 is reserved */ |
3886 | err = -EINVAL; | 4192 | return -EINVAL; |
3887 | goto out; | ||
3888 | } | 4193 | } |
3889 | 4194 | ||
3890 | if (info->attrs[NL80211_ATTR_IE]) { | 4195 | if (info->attrs[NL80211_ATTR_IE]) { |
@@ -3894,21 +4199,42 @@ static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) | |||
3894 | 4199 | ||
3895 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; | 4200 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
3896 | 4201 | ||
3897 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, | 4202 | return cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, |
3898 | local_state_change); | 4203 | local_state_change); |
4204 | } | ||
3899 | 4205 | ||
3900 | out: | 4206 | static bool |
3901 | cfg80211_unlock_rdev(rdev); | 4207 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, |
3902 | dev_put(dev); | 4208 | int mcast_rate[IEEE80211_NUM_BANDS], |
3903 | unlock_rtnl: | 4209 | int rateval) |
3904 | rtnl_unlock(); | 4210 | { |
3905 | return err; | 4211 | struct wiphy *wiphy = &rdev->wiphy; |
4212 | bool found = false; | ||
4213 | int band, i; | ||
4214 | |||
4215 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | ||
4216 | struct ieee80211_supported_band *sband; | ||
4217 | |||
4218 | sband = wiphy->bands[band]; | ||
4219 | if (!sband) | ||
4220 | continue; | ||
4221 | |||
4222 | for (i = 0; i < sband->n_bitrates; i++) { | ||
4223 | if (sband->bitrates[i].bitrate == rateval) { | ||
4224 | mcast_rate[band] = i + 1; | ||
4225 | found = true; | ||
4226 | break; | ||
4227 | } | ||
4228 | } | ||
4229 | } | ||
4230 | |||
4231 | return found; | ||
3906 | } | 4232 | } |
3907 | 4233 | ||
3908 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) | 4234 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
3909 | { | 4235 | { |
3910 | struct cfg80211_registered_device *rdev; | 4236 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3911 | struct net_device *dev; | 4237 | struct net_device *dev = info->user_ptr[1]; |
3912 | struct cfg80211_ibss_params ibss; | 4238 | struct cfg80211_ibss_params ibss; |
3913 | struct wiphy *wiphy; | 4239 | struct wiphy *wiphy; |
3914 | struct cfg80211_cached_keys *connkeys = NULL; | 4240 | struct cfg80211_cached_keys *connkeys = NULL; |
@@ -3933,26 +4259,11 @@ static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) | |||
3933 | return -EINVAL; | 4259 | return -EINVAL; |
3934 | } | 4260 | } |
3935 | 4261 | ||
3936 | rtnl_lock(); | 4262 | if (!rdev->ops->join_ibss) |
3937 | 4263 | return -EOPNOTSUPP; | |
3938 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | ||
3939 | if (err) | ||
3940 | goto unlock_rtnl; | ||
3941 | |||
3942 | if (!rdev->ops->join_ibss) { | ||
3943 | err = -EOPNOTSUPP; | ||
3944 | goto out; | ||
3945 | } | ||
3946 | |||
3947 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) { | ||
3948 | err = -EOPNOTSUPP; | ||
3949 | goto out; | ||
3950 | } | ||
3951 | 4264 | ||
3952 | if (!netif_running(dev)) { | 4265 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
3953 | err = -ENETDOWN; | 4266 | return -EOPNOTSUPP; |
3954 | goto out; | ||
3955 | } | ||
3956 | 4267 | ||
3957 | wiphy = &rdev->wiphy; | 4268 | wiphy = &rdev->wiphy; |
3958 | 4269 | ||
@@ -3970,24 +4281,12 @@ static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) | |||
3970 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | 4281 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
3971 | if (!ibss.channel || | 4282 | if (!ibss.channel || |
3972 | ibss.channel->flags & IEEE80211_CHAN_NO_IBSS || | 4283 | ibss.channel->flags & IEEE80211_CHAN_NO_IBSS || |
3973 | ibss.channel->flags & IEEE80211_CHAN_DISABLED) { | 4284 | ibss.channel->flags & IEEE80211_CHAN_DISABLED) |
3974 | err = -EINVAL; | 4285 | return -EINVAL; |
3975 | goto out; | ||
3976 | } | ||
3977 | 4286 | ||
3978 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; | 4287 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
3979 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; | 4288 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
3980 | 4289 | ||
3981 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { | ||
3982 | connkeys = nl80211_parse_connkeys(rdev, | ||
3983 | info->attrs[NL80211_ATTR_KEYS]); | ||
3984 | if (IS_ERR(connkeys)) { | ||
3985 | err = PTR_ERR(connkeys); | ||
3986 | connkeys = NULL; | ||
3987 | goto out; | ||
3988 | } | ||
3989 | } | ||
3990 | |||
3991 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { | 4290 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
3992 | u8 *rates = | 4291 | u8 *rates = |
3993 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | 4292 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
@@ -3997,10 +4296,8 @@ static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) | |||
3997 | wiphy->bands[ibss.channel->band]; | 4296 | wiphy->bands[ibss.channel->band]; |
3998 | int i, j; | 4297 | int i, j; |
3999 | 4298 | ||
4000 | if (n_rates == 0) { | 4299 | if (n_rates == 0) |
4001 | err = -EINVAL; | 4300 | return -EINVAL; |
4002 | goto out; | ||
4003 | } | ||
4004 | 4301 | ||
4005 | for (i = 0; i < n_rates; i++) { | 4302 | for (i = 0; i < n_rates; i++) { |
4006 | int rate = (rates[i] & 0x7f) * 5; | 4303 | int rate = (rates[i] & 0x7f) * 5; |
@@ -4013,77 +4310,41 @@ static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) | |||
4013 | break; | 4310 | break; |
4014 | } | 4311 | } |
4015 | } | 4312 | } |
4016 | if (!found) { | 4313 | if (!found) |
4017 | err = -EINVAL; | 4314 | return -EINVAL; |
4018 | goto out; | ||
4019 | } | ||
4020 | } | ||
4021 | } else { | ||
4022 | /* | ||
4023 | * If no rates were explicitly configured, | ||
4024 | * use the mandatory rate set for 11b or | ||
4025 | * 11a for maximum compatibility. | ||
4026 | */ | ||
4027 | struct ieee80211_supported_band *sband = | ||
4028 | wiphy->bands[ibss.channel->band]; | ||
4029 | int j; | ||
4030 | u32 flag = ibss.channel->band == IEEE80211_BAND_5GHZ ? | ||
4031 | IEEE80211_RATE_MANDATORY_A : | ||
4032 | IEEE80211_RATE_MANDATORY_B; | ||
4033 | |||
4034 | for (j = 0; j < sband->n_bitrates; j++) { | ||
4035 | if (sband->bitrates[j].flags & flag) | ||
4036 | ibss.basic_rates |= BIT(j); | ||
4037 | } | 4315 | } |
4038 | } | 4316 | } |
4039 | 4317 | ||
4040 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); | 4318 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
4319 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, | ||
4320 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | ||
4321 | return -EINVAL; | ||
4041 | 4322 | ||
4042 | out: | 4323 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
4043 | cfg80211_unlock_rdev(rdev); | 4324 | connkeys = nl80211_parse_connkeys(rdev, |
4044 | dev_put(dev); | 4325 | info->attrs[NL80211_ATTR_KEYS]); |
4045 | unlock_rtnl: | 4326 | if (IS_ERR(connkeys)) |
4327 | return PTR_ERR(connkeys); | ||
4328 | } | ||
4329 | |||
4330 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); | ||
4046 | if (err) | 4331 | if (err) |
4047 | kfree(connkeys); | 4332 | kfree(connkeys); |
4048 | rtnl_unlock(); | ||
4049 | return err; | 4333 | return err; |
4050 | } | 4334 | } |
4051 | 4335 | ||
4052 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) | 4336 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
4053 | { | 4337 | { |
4054 | struct cfg80211_registered_device *rdev; | 4338 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4055 | struct net_device *dev; | 4339 | struct net_device *dev = info->user_ptr[1]; |
4056 | int err; | ||
4057 | 4340 | ||
4058 | rtnl_lock(); | 4341 | if (!rdev->ops->leave_ibss) |
4059 | 4342 | return -EOPNOTSUPP; | |
4060 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | ||
4061 | if (err) | ||
4062 | goto unlock_rtnl; | ||
4063 | |||
4064 | if (!rdev->ops->leave_ibss) { | ||
4065 | err = -EOPNOTSUPP; | ||
4066 | goto out; | ||
4067 | } | ||
4068 | |||
4069 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) { | ||
4070 | err = -EOPNOTSUPP; | ||
4071 | goto out; | ||
4072 | } | ||
4073 | |||
4074 | if (!netif_running(dev)) { | ||
4075 | err = -ENETDOWN; | ||
4076 | goto out; | ||
4077 | } | ||
4078 | 4343 | ||
4079 | err = cfg80211_leave_ibss(rdev, dev, false); | 4344 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
4345 | return -EOPNOTSUPP; | ||
4080 | 4346 | ||
4081 | out: | 4347 | return cfg80211_leave_ibss(rdev, dev, false); |
4082 | cfg80211_unlock_rdev(rdev); | ||
4083 | dev_put(dev); | ||
4084 | unlock_rtnl: | ||
4085 | rtnl_unlock(); | ||
4086 | return err; | ||
4087 | } | 4348 | } |
4088 | 4349 | ||
4089 | #ifdef CONFIG_NL80211_TESTMODE | 4350 | #ifdef CONFIG_NL80211_TESTMODE |
@@ -4093,20 +4354,12 @@ static struct genl_multicast_group nl80211_testmode_mcgrp = { | |||
4093 | 4354 | ||
4094 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) | 4355 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
4095 | { | 4356 | { |
4096 | struct cfg80211_registered_device *rdev; | 4357 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4097 | int err; | 4358 | int err; |
4098 | 4359 | ||
4099 | if (!info->attrs[NL80211_ATTR_TESTDATA]) | 4360 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
4100 | return -EINVAL; | 4361 | return -EINVAL; |
4101 | 4362 | ||
4102 | rtnl_lock(); | ||
4103 | |||
4104 | rdev = cfg80211_get_dev_from_info(info); | ||
4105 | if (IS_ERR(rdev)) { | ||
4106 | err = PTR_ERR(rdev); | ||
4107 | goto unlock_rtnl; | ||
4108 | } | ||
4109 | |||
4110 | err = -EOPNOTSUPP; | 4363 | err = -EOPNOTSUPP; |
4111 | if (rdev->ops->testmode_cmd) { | 4364 | if (rdev->ops->testmode_cmd) { |
4112 | rdev->testmode_info = info; | 4365 | rdev->testmode_info = info; |
@@ -4116,10 +4369,6 @@ static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) | |||
4116 | rdev->testmode_info = NULL; | 4369 | rdev->testmode_info = NULL; |
4117 | } | 4370 | } |
4118 | 4371 | ||
4119 | cfg80211_unlock_rdev(rdev); | ||
4120 | |||
4121 | unlock_rtnl: | ||
4122 | rtnl_unlock(); | ||
4123 | return err; | 4372 | return err; |
4124 | } | 4373 | } |
4125 | 4374 | ||
@@ -4210,8 +4459,8 @@ EXPORT_SYMBOL(cfg80211_testmode_event); | |||
4210 | 4459 | ||
4211 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) | 4460 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
4212 | { | 4461 | { |
4213 | struct cfg80211_registered_device *rdev; | 4462 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4214 | struct net_device *dev; | 4463 | struct net_device *dev = info->user_ptr[1]; |
4215 | struct cfg80211_connect_params connect; | 4464 | struct cfg80211_connect_params connect; |
4216 | struct wiphy *wiphy; | 4465 | struct wiphy *wiphy; |
4217 | struct cfg80211_cached_keys *connkeys = NULL; | 4466 | struct cfg80211_cached_keys *connkeys = NULL; |
@@ -4236,25 +4485,14 @@ static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) | |||
4236 | 4485 | ||
4237 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; | 4486 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
4238 | 4487 | ||
4239 | err = nl80211_crypto_settings(info, &connect.crypto, | 4488 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
4240 | NL80211_MAX_NR_CIPHER_SUITES); | 4489 | NL80211_MAX_NR_CIPHER_SUITES); |
4241 | if (err) | 4490 | if (err) |
4242 | return err; | 4491 | return err; |
4243 | rtnl_lock(); | ||
4244 | |||
4245 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | ||
4246 | if (err) | ||
4247 | goto unlock_rtnl; | ||
4248 | |||
4249 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) { | ||
4250 | err = -EOPNOTSUPP; | ||
4251 | goto out; | ||
4252 | } | ||
4253 | 4492 | ||
4254 | if (!netif_running(dev)) { | 4493 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4255 | err = -ENETDOWN; | 4494 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
4256 | goto out; | 4495 | return -EOPNOTSUPP; |
4257 | } | ||
4258 | 4496 | ||
4259 | wiphy = &rdev->wiphy; | 4497 | wiphy = &rdev->wiphy; |
4260 | 4498 | ||
@@ -4273,39 +4511,27 @@ static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) | |||
4273 | ieee80211_get_channel(wiphy, | 4511 | ieee80211_get_channel(wiphy, |
4274 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | 4512 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
4275 | if (!connect.channel || | 4513 | if (!connect.channel || |
4276 | connect.channel->flags & IEEE80211_CHAN_DISABLED) { | 4514 | connect.channel->flags & IEEE80211_CHAN_DISABLED) |
4277 | err = -EINVAL; | 4515 | return -EINVAL; |
4278 | goto out; | ||
4279 | } | ||
4280 | } | 4516 | } |
4281 | 4517 | ||
4282 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { | 4518 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
4283 | connkeys = nl80211_parse_connkeys(rdev, | 4519 | connkeys = nl80211_parse_connkeys(rdev, |
4284 | info->attrs[NL80211_ATTR_KEYS]); | 4520 | info->attrs[NL80211_ATTR_KEYS]); |
4285 | if (IS_ERR(connkeys)) { | 4521 | if (IS_ERR(connkeys)) |
4286 | err = PTR_ERR(connkeys); | 4522 | return PTR_ERR(connkeys); |
4287 | connkeys = NULL; | ||
4288 | goto out; | ||
4289 | } | ||
4290 | } | 4523 | } |
4291 | 4524 | ||
4292 | err = cfg80211_connect(rdev, dev, &connect, connkeys); | 4525 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
4293 | |||
4294 | out: | ||
4295 | cfg80211_unlock_rdev(rdev); | ||
4296 | dev_put(dev); | ||
4297 | unlock_rtnl: | ||
4298 | if (err) | 4526 | if (err) |
4299 | kfree(connkeys); | 4527 | kfree(connkeys); |
4300 | rtnl_unlock(); | ||
4301 | return err; | 4528 | return err; |
4302 | } | 4529 | } |
4303 | 4530 | ||
4304 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) | 4531 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
4305 | { | 4532 | { |
4306 | struct cfg80211_registered_device *rdev; | 4533 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4307 | struct net_device *dev; | 4534 | struct net_device *dev = info->user_ptr[1]; |
4308 | int err; | ||
4309 | u16 reason; | 4535 | u16 reason; |
4310 | 4536 | ||
4311 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | 4537 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
@@ -4316,35 +4542,16 @@ static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) | |||
4316 | if (reason == 0) | 4542 | if (reason == 0) |
4317 | return -EINVAL; | 4543 | return -EINVAL; |
4318 | 4544 | ||
4319 | rtnl_lock(); | 4545 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4320 | 4546 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) | |
4321 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | 4547 | return -EOPNOTSUPP; |
4322 | if (err) | ||
4323 | goto unlock_rtnl; | ||
4324 | |||
4325 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) { | ||
4326 | err = -EOPNOTSUPP; | ||
4327 | goto out; | ||
4328 | } | ||
4329 | |||
4330 | if (!netif_running(dev)) { | ||
4331 | err = -ENETDOWN; | ||
4332 | goto out; | ||
4333 | } | ||
4334 | |||
4335 | err = cfg80211_disconnect(rdev, dev, reason, true); | ||
4336 | 4548 | ||
4337 | out: | 4549 | return cfg80211_disconnect(rdev, dev, reason, true); |
4338 | cfg80211_unlock_rdev(rdev); | ||
4339 | dev_put(dev); | ||
4340 | unlock_rtnl: | ||
4341 | rtnl_unlock(); | ||
4342 | return err; | ||
4343 | } | 4550 | } |
4344 | 4551 | ||
4345 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) | 4552 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
4346 | { | 4553 | { |
4347 | struct cfg80211_registered_device *rdev; | 4554 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4348 | struct net *net; | 4555 | struct net *net; |
4349 | int err; | 4556 | int err; |
4350 | u32 pid; | 4557 | u32 pid; |
@@ -4354,43 +4561,26 @@ static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) | |||
4354 | 4561 | ||
4355 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); | 4562 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
4356 | 4563 | ||
4357 | rtnl_lock(); | ||
4358 | |||
4359 | rdev = cfg80211_get_dev_from_info(info); | ||
4360 | if (IS_ERR(rdev)) { | ||
4361 | err = PTR_ERR(rdev); | ||
4362 | goto out_rtnl; | ||
4363 | } | ||
4364 | |||
4365 | net = get_net_ns_by_pid(pid); | 4564 | net = get_net_ns_by_pid(pid); |
4366 | if (IS_ERR(net)) { | 4565 | if (IS_ERR(net)) |
4367 | err = PTR_ERR(net); | 4566 | return PTR_ERR(net); |
4368 | goto out; | ||
4369 | } | ||
4370 | 4567 | ||
4371 | err = 0; | 4568 | err = 0; |
4372 | 4569 | ||
4373 | /* check if anything to do */ | 4570 | /* check if anything to do */ |
4374 | if (net_eq(wiphy_net(&rdev->wiphy), net)) | 4571 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
4375 | goto out_put_net; | 4572 | err = cfg80211_switch_netns(rdev, net); |
4376 | 4573 | ||
4377 | err = cfg80211_switch_netns(rdev, net); | ||
4378 | out_put_net: | ||
4379 | put_net(net); | 4574 | put_net(net); |
4380 | out: | ||
4381 | cfg80211_unlock_rdev(rdev); | ||
4382 | out_rtnl: | ||
4383 | rtnl_unlock(); | ||
4384 | return err; | 4575 | return err; |
4385 | } | 4576 | } |
4386 | 4577 | ||
4387 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) | 4578 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
4388 | { | 4579 | { |
4389 | struct cfg80211_registered_device *rdev; | 4580 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4390 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, | 4581 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
4391 | struct cfg80211_pmksa *pmksa) = NULL; | 4582 | struct cfg80211_pmksa *pmksa) = NULL; |
4392 | int err; | 4583 | struct net_device *dev = info->user_ptr[1]; |
4393 | struct net_device *dev; | ||
4394 | struct cfg80211_pmksa pmksa; | 4584 | struct cfg80211_pmksa pmksa; |
4395 | 4585 | ||
4396 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); | 4586 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); |
@@ -4401,19 +4591,12 @@ static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) | |||
4401 | if (!info->attrs[NL80211_ATTR_PMKID]) | 4591 | if (!info->attrs[NL80211_ATTR_PMKID]) |
4402 | return -EINVAL; | 4592 | return -EINVAL; |
4403 | 4593 | ||
4404 | rtnl_lock(); | ||
4405 | |||
4406 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | ||
4407 | if (err) | ||
4408 | goto out_rtnl; | ||
4409 | |||
4410 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); | 4594 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
4411 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | 4595 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
4412 | 4596 | ||
4413 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) { | 4597 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4414 | err = -EOPNOTSUPP; | 4598 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
4415 | goto out; | 4599 | return -EOPNOTSUPP; |
4416 | } | ||
4417 | 4600 | ||
4418 | switch (info->genlhdr->cmd) { | 4601 | switch (info->genlhdr->cmd) { |
4419 | case NL80211_CMD_SET_PMKSA: | 4602 | case NL80211_CMD_SET_PMKSA: |
@@ -4427,61 +4610,32 @@ static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) | |||
4427 | break; | 4610 | break; |
4428 | } | 4611 | } |
4429 | 4612 | ||
4430 | if (!rdev_ops) { | 4613 | if (!rdev_ops) |
4431 | err = -EOPNOTSUPP; | 4614 | return -EOPNOTSUPP; |
4432 | goto out; | ||
4433 | } | ||
4434 | |||
4435 | err = rdev_ops(&rdev->wiphy, dev, &pmksa); | ||
4436 | |||
4437 | out: | ||
4438 | cfg80211_unlock_rdev(rdev); | ||
4439 | dev_put(dev); | ||
4440 | out_rtnl: | ||
4441 | rtnl_unlock(); | ||
4442 | 4615 | ||
4443 | return err; | 4616 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
4444 | } | 4617 | } |
4445 | 4618 | ||
4446 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) | 4619 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) |
4447 | { | 4620 | { |
4448 | struct cfg80211_registered_device *rdev; | 4621 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4449 | int err; | 4622 | struct net_device *dev = info->user_ptr[1]; |
4450 | struct net_device *dev; | ||
4451 | |||
4452 | rtnl_lock(); | ||
4453 | |||
4454 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | ||
4455 | if (err) | ||
4456 | goto out_rtnl; | ||
4457 | |||
4458 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) { | ||
4459 | err = -EOPNOTSUPP; | ||
4460 | goto out; | ||
4461 | } | ||
4462 | |||
4463 | if (!rdev->ops->flush_pmksa) { | ||
4464 | err = -EOPNOTSUPP; | ||
4465 | goto out; | ||
4466 | } | ||
4467 | |||
4468 | err = rdev->ops->flush_pmksa(&rdev->wiphy, dev); | ||
4469 | 4623 | ||
4470 | out: | 4624 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4471 | cfg80211_unlock_rdev(rdev); | 4625 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
4472 | dev_put(dev); | 4626 | return -EOPNOTSUPP; |
4473 | out_rtnl: | ||
4474 | rtnl_unlock(); | ||
4475 | 4627 | ||
4476 | return err; | 4628 | if (!rdev->ops->flush_pmksa) |
4629 | return -EOPNOTSUPP; | ||
4477 | 4630 | ||
4631 | return rdev->ops->flush_pmksa(&rdev->wiphy, dev); | ||
4478 | } | 4632 | } |
4479 | 4633 | ||
4480 | static int nl80211_remain_on_channel(struct sk_buff *skb, | 4634 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
4481 | struct genl_info *info) | 4635 | struct genl_info *info) |
4482 | { | 4636 | { |
4483 | struct cfg80211_registered_device *rdev; | 4637 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4484 | struct net_device *dev; | 4638 | struct net_device *dev = info->user_ptr[1]; |
4485 | struct ieee80211_channel *chan; | 4639 | struct ieee80211_channel *chan; |
4486 | struct sk_buff *msg; | 4640 | struct sk_buff *msg; |
4487 | void *hdr; | 4641 | void *hdr; |
@@ -4500,24 +4654,12 @@ static int nl80211_remain_on_channel(struct sk_buff *skb, | |||
4500 | * We should be on that channel for at least one jiffie, | 4654 | * We should be on that channel for at least one jiffie, |
4501 | * and more than 5 seconds seems excessive. | 4655 | * and more than 5 seconds seems excessive. |
4502 | */ | 4656 | */ |
4503 | if (!duration || !msecs_to_jiffies(duration) || duration > 5000) | 4657 | if (!duration || !msecs_to_jiffies(duration) || |
4658 | duration > rdev->wiphy.max_remain_on_channel_duration) | ||
4504 | return -EINVAL; | 4659 | return -EINVAL; |
4505 | 4660 | ||
4506 | rtnl_lock(); | 4661 | if (!rdev->ops->remain_on_channel) |
4507 | 4662 | return -EOPNOTSUPP; | |
4508 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | ||
4509 | if (err) | ||
4510 | goto unlock_rtnl; | ||
4511 | |||
4512 | if (!rdev->ops->remain_on_channel) { | ||
4513 | err = -EOPNOTSUPP; | ||
4514 | goto out; | ||
4515 | } | ||
4516 | |||
4517 | if (!netif_running(dev)) { | ||
4518 | err = -ENETDOWN; | ||
4519 | goto out; | ||
4520 | } | ||
4521 | 4663 | ||
4522 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { | 4664 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
4523 | channel_type = nla_get_u32( | 4665 | channel_type = nla_get_u32( |
@@ -4525,24 +4667,18 @@ static int nl80211_remain_on_channel(struct sk_buff *skb, | |||
4525 | if (channel_type != NL80211_CHAN_NO_HT && | 4667 | if (channel_type != NL80211_CHAN_NO_HT && |
4526 | channel_type != NL80211_CHAN_HT20 && | 4668 | channel_type != NL80211_CHAN_HT20 && |
4527 | channel_type != NL80211_CHAN_HT40PLUS && | 4669 | channel_type != NL80211_CHAN_HT40PLUS && |
4528 | channel_type != NL80211_CHAN_HT40MINUS) { | 4670 | channel_type != NL80211_CHAN_HT40MINUS) |
4529 | err = -EINVAL; | 4671 | return -EINVAL; |
4530 | goto out; | ||
4531 | } | ||
4532 | } | 4672 | } |
4533 | 4673 | ||
4534 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | 4674 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
4535 | chan = rdev_freq_to_chan(rdev, freq, channel_type); | 4675 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
4536 | if (chan == NULL) { | 4676 | if (chan == NULL) |
4537 | err = -EINVAL; | 4677 | return -EINVAL; |
4538 | goto out; | ||
4539 | } | ||
4540 | 4678 | ||
4541 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 4679 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4542 | if (!msg) { | 4680 | if (!msg) |
4543 | err = -ENOMEM; | 4681 | return -ENOMEM; |
4544 | goto out; | ||
4545 | } | ||
4546 | 4682 | ||
4547 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | 4683 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
4548 | NL80211_CMD_REMAIN_ON_CHANNEL); | 4684 | NL80211_CMD_REMAIN_ON_CHANNEL); |
@@ -4561,58 +4697,32 @@ static int nl80211_remain_on_channel(struct sk_buff *skb, | |||
4561 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); | 4697 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
4562 | 4698 | ||
4563 | genlmsg_end(msg, hdr); | 4699 | genlmsg_end(msg, hdr); |
4564 | err = genlmsg_reply(msg, info); | 4700 | |
4565 | goto out; | 4701 | return genlmsg_reply(msg, info); |
4566 | 4702 | ||
4567 | nla_put_failure: | 4703 | nla_put_failure: |
4568 | err = -ENOBUFS; | 4704 | err = -ENOBUFS; |
4569 | free_msg: | 4705 | free_msg: |
4570 | nlmsg_free(msg); | 4706 | nlmsg_free(msg); |
4571 | out: | ||
4572 | cfg80211_unlock_rdev(rdev); | ||
4573 | dev_put(dev); | ||
4574 | unlock_rtnl: | ||
4575 | rtnl_unlock(); | ||
4576 | return err; | 4707 | return err; |
4577 | } | 4708 | } |
4578 | 4709 | ||
4579 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, | 4710 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, |
4580 | struct genl_info *info) | 4711 | struct genl_info *info) |
4581 | { | 4712 | { |
4582 | struct cfg80211_registered_device *rdev; | 4713 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4583 | struct net_device *dev; | 4714 | struct net_device *dev = info->user_ptr[1]; |
4584 | u64 cookie; | 4715 | u64 cookie; |
4585 | int err; | ||
4586 | 4716 | ||
4587 | if (!info->attrs[NL80211_ATTR_COOKIE]) | 4717 | if (!info->attrs[NL80211_ATTR_COOKIE]) |
4588 | return -EINVAL; | 4718 | return -EINVAL; |
4589 | 4719 | ||
4590 | rtnl_lock(); | 4720 | if (!rdev->ops->cancel_remain_on_channel) |
4591 | 4721 | return -EOPNOTSUPP; | |
4592 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | ||
4593 | if (err) | ||
4594 | goto unlock_rtnl; | ||
4595 | |||
4596 | if (!rdev->ops->cancel_remain_on_channel) { | ||
4597 | err = -EOPNOTSUPP; | ||
4598 | goto out; | ||
4599 | } | ||
4600 | |||
4601 | if (!netif_running(dev)) { | ||
4602 | err = -ENETDOWN; | ||
4603 | goto out; | ||
4604 | } | ||
4605 | 4722 | ||
4606 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | 4723 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
4607 | 4724 | ||
4608 | err = rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie); | 4725 | return rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie); |
4609 | |||
4610 | out: | ||
4611 | cfg80211_unlock_rdev(rdev); | ||
4612 | dev_put(dev); | ||
4613 | unlock_rtnl: | ||
4614 | rtnl_unlock(); | ||
4615 | return err; | ||
4616 | } | 4726 | } |
4617 | 4727 | ||
4618 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, | 4728 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
@@ -4648,26 +4758,18 @@ static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, | |||
4648 | struct genl_info *info) | 4758 | struct genl_info *info) |
4649 | { | 4759 | { |
4650 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; | 4760 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; |
4651 | struct cfg80211_registered_device *rdev; | 4761 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4652 | struct cfg80211_bitrate_mask mask; | 4762 | struct cfg80211_bitrate_mask mask; |
4653 | int err, rem, i; | 4763 | int rem, i; |
4654 | struct net_device *dev; | 4764 | struct net_device *dev = info->user_ptr[1]; |
4655 | struct nlattr *tx_rates; | 4765 | struct nlattr *tx_rates; |
4656 | struct ieee80211_supported_band *sband; | 4766 | struct ieee80211_supported_band *sband; |
4657 | 4767 | ||
4658 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) | 4768 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) |
4659 | return -EINVAL; | 4769 | return -EINVAL; |
4660 | 4770 | ||
4661 | rtnl_lock(); | 4771 | if (!rdev->ops->set_bitrate_mask) |
4662 | 4772 | return -EOPNOTSUPP; | |
4663 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | ||
4664 | if (err) | ||
4665 | goto unlock_rtnl; | ||
4666 | |||
4667 | if (!rdev->ops->set_bitrate_mask) { | ||
4668 | err = -EOPNOTSUPP; | ||
4669 | goto unlock; | ||
4670 | } | ||
4671 | 4773 | ||
4672 | memset(&mask, 0, sizeof(mask)); | 4774 | memset(&mask, 0, sizeof(mask)); |
4673 | /* Default to all rates enabled */ | 4775 | /* Default to all rates enabled */ |
@@ -4684,15 +4786,11 @@ static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, | |||
4684 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) | 4786 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) |
4685 | { | 4787 | { |
4686 | enum ieee80211_band band = nla_type(tx_rates); | 4788 | enum ieee80211_band band = nla_type(tx_rates); |
4687 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { | 4789 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
4688 | err = -EINVAL; | 4790 | return -EINVAL; |
4689 | goto unlock; | ||
4690 | } | ||
4691 | sband = rdev->wiphy.bands[band]; | 4791 | sband = rdev->wiphy.bands[band]; |
4692 | if (sband == NULL) { | 4792 | if (sband == NULL) |
4693 | err = -EINVAL; | 4793 | return -EINVAL; |
4694 | goto unlock; | ||
4695 | } | ||
4696 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), | 4794 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
4697 | nla_len(tx_rates), nl80211_txattr_policy); | 4795 | nla_len(tx_rates), nl80211_txattr_policy); |
4698 | if (tb[NL80211_TXRATE_LEGACY]) { | 4796 | if (tb[NL80211_TXRATE_LEGACY]) { |
@@ -4700,68 +4798,49 @@ static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, | |||
4700 | sband, | 4798 | sband, |
4701 | nla_data(tb[NL80211_TXRATE_LEGACY]), | 4799 | nla_data(tb[NL80211_TXRATE_LEGACY]), |
4702 | nla_len(tb[NL80211_TXRATE_LEGACY])); | 4800 | nla_len(tb[NL80211_TXRATE_LEGACY])); |
4703 | if (mask.control[band].legacy == 0) { | 4801 | if (mask.control[band].legacy == 0) |
4704 | err = -EINVAL; | 4802 | return -EINVAL; |
4705 | goto unlock; | ||
4706 | } | ||
4707 | } | 4803 | } |
4708 | } | 4804 | } |
4709 | 4805 | ||
4710 | err = rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask); | 4806 | return rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask); |
4711 | |||
4712 | unlock: | ||
4713 | dev_put(dev); | ||
4714 | cfg80211_unlock_rdev(rdev); | ||
4715 | unlock_rtnl: | ||
4716 | rtnl_unlock(); | ||
4717 | return err; | ||
4718 | } | 4807 | } |
4719 | 4808 | ||
4720 | static int nl80211_register_action(struct sk_buff *skb, struct genl_info *info) | 4809 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
4721 | { | 4810 | { |
4722 | struct cfg80211_registered_device *rdev; | 4811 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4723 | struct net_device *dev; | 4812 | struct net_device *dev = info->user_ptr[1]; |
4724 | int err; | 4813 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
4725 | 4814 | ||
4726 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) | 4815 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) |
4727 | return -EINVAL; | 4816 | return -EINVAL; |
4728 | 4817 | ||
4729 | if (nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]) < 1) | 4818 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
4730 | return -EINVAL; | 4819 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); |
4731 | |||
4732 | rtnl_lock(); | ||
4733 | |||
4734 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | ||
4735 | if (err) | ||
4736 | goto unlock_rtnl; | ||
4737 | 4820 | ||
4738 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && | 4821 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4739 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) { | 4822 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
4740 | err = -EOPNOTSUPP; | 4823 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
4741 | goto out; | 4824 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
4742 | } | 4825 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
4826 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && | ||
4827 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | ||
4828 | return -EOPNOTSUPP; | ||
4743 | 4829 | ||
4744 | /* not much point in registering if we can't reply */ | 4830 | /* not much point in registering if we can't reply */ |
4745 | if (!rdev->ops->action) { | 4831 | if (!rdev->ops->mgmt_tx) |
4746 | err = -EOPNOTSUPP; | 4832 | return -EOPNOTSUPP; |
4747 | goto out; | ||
4748 | } | ||
4749 | 4833 | ||
4750 | err = cfg80211_mlme_register_action(dev->ieee80211_ptr, info->snd_pid, | 4834 | return cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid, |
4835 | frame_type, | ||
4751 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), | 4836 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
4752 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); | 4837 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); |
4753 | out: | ||
4754 | cfg80211_unlock_rdev(rdev); | ||
4755 | dev_put(dev); | ||
4756 | unlock_rtnl: | ||
4757 | rtnl_unlock(); | ||
4758 | return err; | ||
4759 | } | 4838 | } |
4760 | 4839 | ||
4761 | static int nl80211_action(struct sk_buff *skb, struct genl_info *info) | 4840 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
4762 | { | 4841 | { |
4763 | struct cfg80211_registered_device *rdev; | 4842 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4764 | struct net_device *dev; | 4843 | struct net_device *dev = info->user_ptr[1]; |
4765 | struct ieee80211_channel *chan; | 4844 | struct ieee80211_channel *chan; |
4766 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; | 4845 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
4767 | bool channel_type_valid = false; | 4846 | bool channel_type_valid = false; |
@@ -4770,31 +4849,29 @@ static int nl80211_action(struct sk_buff *skb, struct genl_info *info) | |||
4770 | void *hdr; | 4849 | void *hdr; |
4771 | u64 cookie; | 4850 | u64 cookie; |
4772 | struct sk_buff *msg; | 4851 | struct sk_buff *msg; |
4852 | unsigned int wait = 0; | ||
4853 | bool offchan; | ||
4773 | 4854 | ||
4774 | if (!info->attrs[NL80211_ATTR_FRAME] || | 4855 | if (!info->attrs[NL80211_ATTR_FRAME] || |
4775 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | 4856 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
4776 | return -EINVAL; | 4857 | return -EINVAL; |
4777 | 4858 | ||
4778 | rtnl_lock(); | 4859 | if (!rdev->ops->mgmt_tx) |
4779 | 4860 | return -EOPNOTSUPP; | |
4780 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | ||
4781 | if (err) | ||
4782 | goto unlock_rtnl; | ||
4783 | |||
4784 | if (!rdev->ops->action) { | ||
4785 | err = -EOPNOTSUPP; | ||
4786 | goto out; | ||
4787 | } | ||
4788 | 4861 | ||
4789 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && | 4862 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4790 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) { | 4863 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
4791 | err = -EOPNOTSUPP; | 4864 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
4792 | goto out; | 4865 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
4793 | } | 4866 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
4867 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && | ||
4868 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | ||
4869 | return -EOPNOTSUPP; | ||
4794 | 4870 | ||
4795 | if (!netif_running(dev)) { | 4871 | if (info->attrs[NL80211_ATTR_DURATION]) { |
4796 | err = -ENETDOWN; | 4872 | if (!rdev->ops->mgmt_tx_cancel_wait) |
4797 | goto out; | 4873 | return -EINVAL; |
4874 | wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | ||
4798 | } | 4875 | } |
4799 | 4876 | ||
4800 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { | 4877 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
@@ -4803,147 +4880,131 @@ static int nl80211_action(struct sk_buff *skb, struct genl_info *info) | |||
4803 | if (channel_type != NL80211_CHAN_NO_HT && | 4880 | if (channel_type != NL80211_CHAN_NO_HT && |
4804 | channel_type != NL80211_CHAN_HT20 && | 4881 | channel_type != NL80211_CHAN_HT20 && |
4805 | channel_type != NL80211_CHAN_HT40PLUS && | 4882 | channel_type != NL80211_CHAN_HT40PLUS && |
4806 | channel_type != NL80211_CHAN_HT40MINUS) { | 4883 | channel_type != NL80211_CHAN_HT40MINUS) |
4807 | err = -EINVAL; | 4884 | return -EINVAL; |
4808 | goto out; | ||
4809 | } | ||
4810 | channel_type_valid = true; | 4885 | channel_type_valid = true; |
4811 | } | 4886 | } |
4812 | 4887 | ||
4888 | offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; | ||
4889 | |||
4813 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | 4890 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
4814 | chan = rdev_freq_to_chan(rdev, freq, channel_type); | 4891 | chan = rdev_freq_to_chan(rdev, freq, channel_type); |
4815 | if (chan == NULL) { | 4892 | if (chan == NULL) |
4816 | err = -EINVAL; | 4893 | return -EINVAL; |
4817 | goto out; | ||
4818 | } | ||
4819 | 4894 | ||
4820 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 4895 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4821 | if (!msg) { | 4896 | if (!msg) |
4822 | err = -ENOMEM; | 4897 | return -ENOMEM; |
4823 | goto out; | ||
4824 | } | ||
4825 | 4898 | ||
4826 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | 4899 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
4827 | NL80211_CMD_ACTION); | 4900 | NL80211_CMD_FRAME); |
4828 | 4901 | ||
4829 | if (IS_ERR(hdr)) { | 4902 | if (IS_ERR(hdr)) { |
4830 | err = PTR_ERR(hdr); | 4903 | err = PTR_ERR(hdr); |
4831 | goto free_msg; | 4904 | goto free_msg; |
4832 | } | 4905 | } |
4833 | err = cfg80211_mlme_action(rdev, dev, chan, channel_type, | 4906 | err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, offchan, channel_type, |
4834 | channel_type_valid, | 4907 | channel_type_valid, wait, |
4835 | nla_data(info->attrs[NL80211_ATTR_FRAME]), | 4908 | nla_data(info->attrs[NL80211_ATTR_FRAME]), |
4836 | nla_len(info->attrs[NL80211_ATTR_FRAME]), | 4909 | nla_len(info->attrs[NL80211_ATTR_FRAME]), |
4837 | &cookie); | 4910 | &cookie); |
4838 | if (err) | 4911 | if (err) |
4839 | goto free_msg; | 4912 | goto free_msg; |
4840 | 4913 | ||
4841 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); | 4914 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); |
4842 | 4915 | ||
4843 | genlmsg_end(msg, hdr); | 4916 | genlmsg_end(msg, hdr); |
4844 | err = genlmsg_reply(msg, info); | 4917 | return genlmsg_reply(msg, info); |
4845 | goto out; | ||
4846 | 4918 | ||
4847 | nla_put_failure: | 4919 | nla_put_failure: |
4848 | err = -ENOBUFS; | 4920 | err = -ENOBUFS; |
4849 | free_msg: | 4921 | free_msg: |
4850 | nlmsg_free(msg); | 4922 | nlmsg_free(msg); |
4851 | out: | ||
4852 | cfg80211_unlock_rdev(rdev); | ||
4853 | dev_put(dev); | ||
4854 | unlock_rtnl: | ||
4855 | rtnl_unlock(); | ||
4856 | return err; | 4923 | return err; |
4857 | } | 4924 | } |
4858 | 4925 | ||
4926 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) | ||
4927 | { | ||
4928 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | ||
4929 | struct net_device *dev = info->user_ptr[1]; | ||
4930 | u64 cookie; | ||
4931 | |||
4932 | if (!info->attrs[NL80211_ATTR_COOKIE]) | ||
4933 | return -EINVAL; | ||
4934 | |||
4935 | if (!rdev->ops->mgmt_tx_cancel_wait) | ||
4936 | return -EOPNOTSUPP; | ||
4937 | |||
4938 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && | ||
4939 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && | ||
4940 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && | ||
4941 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | ||
4942 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && | ||
4943 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | ||
4944 | return -EOPNOTSUPP; | ||
4945 | |||
4946 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | ||
4947 | |||
4948 | return rdev->ops->mgmt_tx_cancel_wait(&rdev->wiphy, dev, cookie); | ||
4949 | } | ||
4950 | |||
4859 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) | 4951 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
4860 | { | 4952 | { |
4861 | struct cfg80211_registered_device *rdev; | 4953 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4862 | struct wireless_dev *wdev; | 4954 | struct wireless_dev *wdev; |
4863 | struct net_device *dev; | 4955 | struct net_device *dev = info->user_ptr[1]; |
4864 | u8 ps_state; | 4956 | u8 ps_state; |
4865 | bool state; | 4957 | bool state; |
4866 | int err; | 4958 | int err; |
4867 | 4959 | ||
4868 | if (!info->attrs[NL80211_ATTR_PS_STATE]) { | 4960 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
4869 | err = -EINVAL; | 4961 | return -EINVAL; |
4870 | goto out; | ||
4871 | } | ||
4872 | 4962 | ||
4873 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); | 4963 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); |
4874 | 4964 | ||
4875 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) { | 4965 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
4876 | err = -EINVAL; | 4966 | return -EINVAL; |
4877 | goto out; | ||
4878 | } | ||
4879 | |||
4880 | rtnl_lock(); | ||
4881 | |||
4882 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | ||
4883 | if (err) | ||
4884 | goto unlock_rdev; | ||
4885 | 4967 | ||
4886 | wdev = dev->ieee80211_ptr; | 4968 | wdev = dev->ieee80211_ptr; |
4887 | 4969 | ||
4888 | if (!rdev->ops->set_power_mgmt) { | 4970 | if (!rdev->ops->set_power_mgmt) |
4889 | err = -EOPNOTSUPP; | 4971 | return -EOPNOTSUPP; |
4890 | goto unlock_rdev; | ||
4891 | } | ||
4892 | 4972 | ||
4893 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; | 4973 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; |
4894 | 4974 | ||
4895 | if (state == wdev->ps) | 4975 | if (state == wdev->ps) |
4896 | goto unlock_rdev; | 4976 | return 0; |
4897 | |||
4898 | wdev->ps = state; | ||
4899 | |||
4900 | if (rdev->ops->set_power_mgmt(wdev->wiphy, dev, wdev->ps, | ||
4901 | wdev->ps_timeout)) | ||
4902 | /* assume this means it's off */ | ||
4903 | wdev->ps = false; | ||
4904 | |||
4905 | unlock_rdev: | ||
4906 | cfg80211_unlock_rdev(rdev); | ||
4907 | dev_put(dev); | ||
4908 | rtnl_unlock(); | ||
4909 | 4977 | ||
4910 | out: | 4978 | err = rdev->ops->set_power_mgmt(wdev->wiphy, dev, state, |
4979 | wdev->ps_timeout); | ||
4980 | if (!err) | ||
4981 | wdev->ps = state; | ||
4911 | return err; | 4982 | return err; |
4912 | } | 4983 | } |
4913 | 4984 | ||
4914 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) | 4985 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) |
4915 | { | 4986 | { |
4916 | struct cfg80211_registered_device *rdev; | 4987 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4917 | enum nl80211_ps_state ps_state; | 4988 | enum nl80211_ps_state ps_state; |
4918 | struct wireless_dev *wdev; | 4989 | struct wireless_dev *wdev; |
4919 | struct net_device *dev; | 4990 | struct net_device *dev = info->user_ptr[1]; |
4920 | struct sk_buff *msg; | 4991 | struct sk_buff *msg; |
4921 | void *hdr; | 4992 | void *hdr; |
4922 | int err; | 4993 | int err; |
4923 | 4994 | ||
4924 | rtnl_lock(); | ||
4925 | |||
4926 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | ||
4927 | if (err) | ||
4928 | goto unlock_rtnl; | ||
4929 | |||
4930 | wdev = dev->ieee80211_ptr; | 4995 | wdev = dev->ieee80211_ptr; |
4931 | 4996 | ||
4932 | if (!rdev->ops->set_power_mgmt) { | 4997 | if (!rdev->ops->set_power_mgmt) |
4933 | err = -EOPNOTSUPP; | 4998 | return -EOPNOTSUPP; |
4934 | goto out; | ||
4935 | } | ||
4936 | 4999 | ||
4937 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | 5000 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4938 | if (!msg) { | 5001 | if (!msg) |
4939 | err = -ENOMEM; | 5002 | return -ENOMEM; |
4940 | goto out; | ||
4941 | } | ||
4942 | 5003 | ||
4943 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | 5004 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
4944 | NL80211_CMD_GET_POWER_SAVE); | 5005 | NL80211_CMD_GET_POWER_SAVE); |
4945 | if (!hdr) { | 5006 | if (!hdr) { |
4946 | err = -ENOMEM; | 5007 | err = -ENOBUFS; |
4947 | goto free_msg; | 5008 | goto free_msg; |
4948 | } | 5009 | } |
4949 | 5010 | ||
@@ -4955,22 +5016,12 @@ static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) | |||
4955 | NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state); | 5016 | NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state); |
4956 | 5017 | ||
4957 | genlmsg_end(msg, hdr); | 5018 | genlmsg_end(msg, hdr); |
4958 | err = genlmsg_reply(msg, info); | 5019 | return genlmsg_reply(msg, info); |
4959 | goto out; | ||
4960 | 5020 | ||
4961 | nla_put_failure: | 5021 | nla_put_failure: |
4962 | err = -ENOBUFS; | 5022 | err = -ENOBUFS; |
4963 | 5023 | free_msg: | |
4964 | free_msg: | ||
4965 | nlmsg_free(msg); | 5024 | nlmsg_free(msg); |
4966 | |||
4967 | out: | ||
4968 | cfg80211_unlock_rdev(rdev); | ||
4969 | dev_put(dev); | ||
4970 | |||
4971 | unlock_rtnl: | ||
4972 | rtnl_unlock(); | ||
4973 | |||
4974 | return err; | 5025 | return err; |
4975 | } | 5026 | } |
4976 | 5027 | ||
@@ -4984,41 +5035,24 @@ nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { | |||
4984 | static int nl80211_set_cqm_rssi(struct genl_info *info, | 5035 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
4985 | s32 threshold, u32 hysteresis) | 5036 | s32 threshold, u32 hysteresis) |
4986 | { | 5037 | { |
4987 | struct cfg80211_registered_device *rdev; | 5038 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4988 | struct wireless_dev *wdev; | 5039 | struct wireless_dev *wdev; |
4989 | struct net_device *dev; | 5040 | struct net_device *dev = info->user_ptr[1]; |
4990 | int err; | ||
4991 | 5041 | ||
4992 | if (threshold > 0) | 5042 | if (threshold > 0) |
4993 | return -EINVAL; | 5043 | return -EINVAL; |
4994 | 5044 | ||
4995 | rtnl_lock(); | ||
4996 | |||
4997 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | ||
4998 | if (err) | ||
4999 | goto unlock_rdev; | ||
5000 | |||
5001 | wdev = dev->ieee80211_ptr; | 5045 | wdev = dev->ieee80211_ptr; |
5002 | 5046 | ||
5003 | if (!rdev->ops->set_cqm_rssi_config) { | 5047 | if (!rdev->ops->set_cqm_rssi_config) |
5004 | err = -EOPNOTSUPP; | 5048 | return -EOPNOTSUPP; |
5005 | goto unlock_rdev; | ||
5006 | } | ||
5007 | |||
5008 | if (wdev->iftype != NL80211_IFTYPE_STATION) { | ||
5009 | err = -EOPNOTSUPP; | ||
5010 | goto unlock_rdev; | ||
5011 | } | ||
5012 | |||
5013 | err = rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev, | ||
5014 | threshold, hysteresis); | ||
5015 | 5049 | ||
5016 | unlock_rdev: | 5050 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
5017 | cfg80211_unlock_rdev(rdev); | 5051 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
5018 | dev_put(dev); | 5052 | return -EOPNOTSUPP; |
5019 | rtnl_unlock(); | ||
5020 | 5053 | ||
5021 | return err; | 5054 | return rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev, |
5055 | threshold, hysteresis); | ||
5022 | } | 5056 | } |
5023 | 5057 | ||
5024 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) | 5058 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) |
@@ -5052,6 +5086,297 @@ out: | |||
5052 | return err; | 5086 | return err; |
5053 | } | 5087 | } |
5054 | 5088 | ||
5089 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) | ||
5090 | { | ||
5091 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | ||
5092 | struct net_device *dev = info->user_ptr[1]; | ||
5093 | struct mesh_config cfg; | ||
5094 | struct mesh_setup setup; | ||
5095 | int err; | ||
5096 | |||
5097 | /* start with default */ | ||
5098 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); | ||
5099 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); | ||
5100 | |||
5101 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { | ||
5102 | /* and parse parameters if given */ | ||
5103 | err = nl80211_parse_mesh_config(info, &cfg, NULL); | ||
5104 | if (err) | ||
5105 | return err; | ||
5106 | } | ||
5107 | |||
5108 | if (!info->attrs[NL80211_ATTR_MESH_ID] || | ||
5109 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) | ||
5110 | return -EINVAL; | ||
5111 | |||
5112 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); | ||
5113 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | ||
5114 | |||
5115 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { | ||
5116 | /* parse additional setup parameters if given */ | ||
5117 | err = nl80211_parse_mesh_setup(info, &setup); | ||
5118 | if (err) | ||
5119 | return err; | ||
5120 | } | ||
5121 | |||
5122 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); | ||
5123 | } | ||
5124 | |||
5125 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) | ||
5126 | { | ||
5127 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | ||
5128 | struct net_device *dev = info->user_ptr[1]; | ||
5129 | |||
5130 | return cfg80211_leave_mesh(rdev, dev); | ||
5131 | } | ||
5132 | |||
5133 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) | ||
5134 | { | ||
5135 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | ||
5136 | struct sk_buff *msg; | ||
5137 | void *hdr; | ||
5138 | |||
5139 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) | ||
5140 | return -EOPNOTSUPP; | ||
5141 | |||
5142 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | ||
5143 | if (!msg) | ||
5144 | return -ENOMEM; | ||
5145 | |||
5146 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | ||
5147 | NL80211_CMD_GET_WOWLAN); | ||
5148 | if (!hdr) | ||
5149 | goto nla_put_failure; | ||
5150 | |||
5151 | if (rdev->wowlan) { | ||
5152 | struct nlattr *nl_wowlan; | ||
5153 | |||
5154 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | ||
5155 | if (!nl_wowlan) | ||
5156 | goto nla_put_failure; | ||
5157 | |||
5158 | if (rdev->wowlan->any) | ||
5159 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_ANY); | ||
5160 | if (rdev->wowlan->disconnect) | ||
5161 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_DISCONNECT); | ||
5162 | if (rdev->wowlan->magic_pkt) | ||
5163 | NLA_PUT_FLAG(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT); | ||
5164 | if (rdev->wowlan->n_patterns) { | ||
5165 | struct nlattr *nl_pats, *nl_pat; | ||
5166 | int i, pat_len; | ||
5167 | |||
5168 | nl_pats = nla_nest_start(msg, | ||
5169 | NL80211_WOWLAN_TRIG_PKT_PATTERN); | ||
5170 | if (!nl_pats) | ||
5171 | goto nla_put_failure; | ||
5172 | |||
5173 | for (i = 0; i < rdev->wowlan->n_patterns; i++) { | ||
5174 | nl_pat = nla_nest_start(msg, i + 1); | ||
5175 | if (!nl_pat) | ||
5176 | goto nla_put_failure; | ||
5177 | pat_len = rdev->wowlan->patterns[i].pattern_len; | ||
5178 | NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_MASK, | ||
5179 | DIV_ROUND_UP(pat_len, 8), | ||
5180 | rdev->wowlan->patterns[i].mask); | ||
5181 | NLA_PUT(msg, NL80211_WOWLAN_PKTPAT_PATTERN, | ||
5182 | pat_len, | ||
5183 | rdev->wowlan->patterns[i].pattern); | ||
5184 | nla_nest_end(msg, nl_pat); | ||
5185 | } | ||
5186 | nla_nest_end(msg, nl_pats); | ||
5187 | } | ||
5188 | |||
5189 | nla_nest_end(msg, nl_wowlan); | ||
5190 | } | ||
5191 | |||
5192 | genlmsg_end(msg, hdr); | ||
5193 | return genlmsg_reply(msg, info); | ||
5194 | |||
5195 | nla_put_failure: | ||
5196 | nlmsg_free(msg); | ||
5197 | return -ENOBUFS; | ||
5198 | } | ||
5199 | |||
5200 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) | ||
5201 | { | ||
5202 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | ||
5203 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; | ||
5204 | struct cfg80211_wowlan no_triggers = {}; | ||
5205 | struct cfg80211_wowlan new_triggers = {}; | ||
5206 | struct wiphy_wowlan_support *wowlan = &rdev->wiphy.wowlan; | ||
5207 | int err, i; | ||
5208 | |||
5209 | if (!rdev->wiphy.wowlan.flags && !rdev->wiphy.wowlan.n_patterns) | ||
5210 | return -EOPNOTSUPP; | ||
5211 | |||
5212 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) | ||
5213 | goto no_triggers; | ||
5214 | |||
5215 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, | ||
5216 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | ||
5217 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | ||
5218 | nl80211_wowlan_policy); | ||
5219 | if (err) | ||
5220 | return err; | ||
5221 | |||
5222 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { | ||
5223 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) | ||
5224 | return -EINVAL; | ||
5225 | new_triggers.any = true; | ||
5226 | } | ||
5227 | |||
5228 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { | ||
5229 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) | ||
5230 | return -EINVAL; | ||
5231 | new_triggers.disconnect = true; | ||
5232 | } | ||
5233 | |||
5234 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { | ||
5235 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) | ||
5236 | return -EINVAL; | ||
5237 | new_triggers.magic_pkt = true; | ||
5238 | } | ||
5239 | |||
5240 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { | ||
5241 | struct nlattr *pat; | ||
5242 | int n_patterns = 0; | ||
5243 | int rem, pat_len, mask_len; | ||
5244 | struct nlattr *pat_tb[NUM_NL80211_WOWLAN_PKTPAT]; | ||
5245 | |||
5246 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | ||
5247 | rem) | ||
5248 | n_patterns++; | ||
5249 | if (n_patterns > wowlan->n_patterns) | ||
5250 | return -EINVAL; | ||
5251 | |||
5252 | new_triggers.patterns = kcalloc(n_patterns, | ||
5253 | sizeof(new_triggers.patterns[0]), | ||
5254 | GFP_KERNEL); | ||
5255 | if (!new_triggers.patterns) | ||
5256 | return -ENOMEM; | ||
5257 | |||
5258 | new_triggers.n_patterns = n_patterns; | ||
5259 | i = 0; | ||
5260 | |||
5261 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | ||
5262 | rem) { | ||
5263 | nla_parse(pat_tb, MAX_NL80211_WOWLAN_PKTPAT, | ||
5264 | nla_data(pat), nla_len(pat), NULL); | ||
5265 | err = -EINVAL; | ||
5266 | if (!pat_tb[NL80211_WOWLAN_PKTPAT_MASK] || | ||
5267 | !pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]) | ||
5268 | goto error; | ||
5269 | pat_len = nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]); | ||
5270 | mask_len = DIV_ROUND_UP(pat_len, 8); | ||
5271 | if (nla_len(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]) != | ||
5272 | mask_len) | ||
5273 | goto error; | ||
5274 | if (pat_len > wowlan->pattern_max_len || | ||
5275 | pat_len < wowlan->pattern_min_len) | ||
5276 | goto error; | ||
5277 | |||
5278 | new_triggers.patterns[i].mask = | ||
5279 | kmalloc(mask_len + pat_len, GFP_KERNEL); | ||
5280 | if (!new_triggers.patterns[i].mask) { | ||
5281 | err = -ENOMEM; | ||
5282 | goto error; | ||
5283 | } | ||
5284 | new_triggers.patterns[i].pattern = | ||
5285 | new_triggers.patterns[i].mask + mask_len; | ||
5286 | memcpy(new_triggers.patterns[i].mask, | ||
5287 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_MASK]), | ||
5288 | mask_len); | ||
5289 | new_triggers.patterns[i].pattern_len = pat_len; | ||
5290 | memcpy(new_triggers.patterns[i].pattern, | ||
5291 | nla_data(pat_tb[NL80211_WOWLAN_PKTPAT_PATTERN]), | ||
5292 | pat_len); | ||
5293 | i++; | ||
5294 | } | ||
5295 | } | ||
5296 | |||
5297 | if (memcmp(&new_triggers, &no_triggers, sizeof(new_triggers))) { | ||
5298 | struct cfg80211_wowlan *ntrig; | ||
5299 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), | ||
5300 | GFP_KERNEL); | ||
5301 | if (!ntrig) { | ||
5302 | err = -ENOMEM; | ||
5303 | goto error; | ||
5304 | } | ||
5305 | cfg80211_rdev_free_wowlan(rdev); | ||
5306 | rdev->wowlan = ntrig; | ||
5307 | } else { | ||
5308 | no_triggers: | ||
5309 | cfg80211_rdev_free_wowlan(rdev); | ||
5310 | rdev->wowlan = NULL; | ||
5311 | } | ||
5312 | |||
5313 | return 0; | ||
5314 | error: | ||
5315 | for (i = 0; i < new_triggers.n_patterns; i++) | ||
5316 | kfree(new_triggers.patterns[i].mask); | ||
5317 | kfree(new_triggers.patterns); | ||
5318 | return err; | ||
5319 | } | ||
5320 | |||
5321 | #define NL80211_FLAG_NEED_WIPHY 0x01 | ||
5322 | #define NL80211_FLAG_NEED_NETDEV 0x02 | ||
5323 | #define NL80211_FLAG_NEED_RTNL 0x04 | ||
5324 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 | ||
5325 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ | ||
5326 | NL80211_FLAG_CHECK_NETDEV_UP) | ||
5327 | |||
5328 | static int nl80211_pre_doit(struct genl_ops *ops, struct sk_buff *skb, | ||
5329 | struct genl_info *info) | ||
5330 | { | ||
5331 | struct cfg80211_registered_device *rdev; | ||
5332 | struct net_device *dev; | ||
5333 | int err; | ||
5334 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; | ||
5335 | |||
5336 | if (rtnl) | ||
5337 | rtnl_lock(); | ||
5338 | |||
5339 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { | ||
5340 | rdev = cfg80211_get_dev_from_info(info); | ||
5341 | if (IS_ERR(rdev)) { | ||
5342 | if (rtnl) | ||
5343 | rtnl_unlock(); | ||
5344 | return PTR_ERR(rdev); | ||
5345 | } | ||
5346 | info->user_ptr[0] = rdev; | ||
5347 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { | ||
5348 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | ||
5349 | if (err) { | ||
5350 | if (rtnl) | ||
5351 | rtnl_unlock(); | ||
5352 | return err; | ||
5353 | } | ||
5354 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && | ||
5355 | !netif_running(dev)) { | ||
5356 | cfg80211_unlock_rdev(rdev); | ||
5357 | dev_put(dev); | ||
5358 | if (rtnl) | ||
5359 | rtnl_unlock(); | ||
5360 | return -ENETDOWN; | ||
5361 | } | ||
5362 | info->user_ptr[0] = rdev; | ||
5363 | info->user_ptr[1] = dev; | ||
5364 | } | ||
5365 | |||
5366 | return 0; | ||
5367 | } | ||
5368 | |||
5369 | static void nl80211_post_doit(struct genl_ops *ops, struct sk_buff *skb, | ||
5370 | struct genl_info *info) | ||
5371 | { | ||
5372 | if (info->user_ptr[0]) | ||
5373 | cfg80211_unlock_rdev(info->user_ptr[0]); | ||
5374 | if (info->user_ptr[1]) | ||
5375 | dev_put(info->user_ptr[1]); | ||
5376 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) | ||
5377 | rtnl_unlock(); | ||
5378 | } | ||
5379 | |||
5055 | static struct genl_ops nl80211_ops[] = { | 5380 | static struct genl_ops nl80211_ops[] = { |
5056 | { | 5381 | { |
5057 | .cmd = NL80211_CMD_GET_WIPHY, | 5382 | .cmd = NL80211_CMD_GET_WIPHY, |
@@ -5059,12 +5384,14 @@ static struct genl_ops nl80211_ops[] = { | |||
5059 | .dumpit = nl80211_dump_wiphy, | 5384 | .dumpit = nl80211_dump_wiphy, |
5060 | .policy = nl80211_policy, | 5385 | .policy = nl80211_policy, |
5061 | /* can be retrieved by unprivileged users */ | 5386 | /* can be retrieved by unprivileged users */ |
5387 | .internal_flags = NL80211_FLAG_NEED_WIPHY, | ||
5062 | }, | 5388 | }, |
5063 | { | 5389 | { |
5064 | .cmd = NL80211_CMD_SET_WIPHY, | 5390 | .cmd = NL80211_CMD_SET_WIPHY, |
5065 | .doit = nl80211_set_wiphy, | 5391 | .doit = nl80211_set_wiphy, |
5066 | .policy = nl80211_policy, | 5392 | .policy = nl80211_policy, |
5067 | .flags = GENL_ADMIN_PERM, | 5393 | .flags = GENL_ADMIN_PERM, |
5394 | .internal_flags = NL80211_FLAG_NEED_RTNL, | ||
5068 | }, | 5395 | }, |
5069 | { | 5396 | { |
5070 | .cmd = NL80211_CMD_GET_INTERFACE, | 5397 | .cmd = NL80211_CMD_GET_INTERFACE, |
@@ -5072,90 +5399,119 @@ static struct genl_ops nl80211_ops[] = { | |||
5072 | .dumpit = nl80211_dump_interface, | 5399 | .dumpit = nl80211_dump_interface, |
5073 | .policy = nl80211_policy, | 5400 | .policy = nl80211_policy, |
5074 | /* can be retrieved by unprivileged users */ | 5401 | /* can be retrieved by unprivileged users */ |
5402 | .internal_flags = NL80211_FLAG_NEED_NETDEV, | ||
5075 | }, | 5403 | }, |
5076 | { | 5404 | { |
5077 | .cmd = NL80211_CMD_SET_INTERFACE, | 5405 | .cmd = NL80211_CMD_SET_INTERFACE, |
5078 | .doit = nl80211_set_interface, | 5406 | .doit = nl80211_set_interface, |
5079 | .policy = nl80211_policy, | 5407 | .policy = nl80211_policy, |
5080 | .flags = GENL_ADMIN_PERM, | 5408 | .flags = GENL_ADMIN_PERM, |
5409 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | ||
5410 | NL80211_FLAG_NEED_RTNL, | ||
5081 | }, | 5411 | }, |
5082 | { | 5412 | { |
5083 | .cmd = NL80211_CMD_NEW_INTERFACE, | 5413 | .cmd = NL80211_CMD_NEW_INTERFACE, |
5084 | .doit = nl80211_new_interface, | 5414 | .doit = nl80211_new_interface, |
5085 | .policy = nl80211_policy, | 5415 | .policy = nl80211_policy, |
5086 | .flags = GENL_ADMIN_PERM, | 5416 | .flags = GENL_ADMIN_PERM, |
5417 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | ||
5418 | NL80211_FLAG_NEED_RTNL, | ||
5087 | }, | 5419 | }, |
5088 | { | 5420 | { |
5089 | .cmd = NL80211_CMD_DEL_INTERFACE, | 5421 | .cmd = NL80211_CMD_DEL_INTERFACE, |
5090 | .doit = nl80211_del_interface, | 5422 | .doit = nl80211_del_interface, |
5091 | .policy = nl80211_policy, | 5423 | .policy = nl80211_policy, |
5092 | .flags = GENL_ADMIN_PERM, | 5424 | .flags = GENL_ADMIN_PERM, |
5425 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | ||
5426 | NL80211_FLAG_NEED_RTNL, | ||
5093 | }, | 5427 | }, |
5094 | { | 5428 | { |
5095 | .cmd = NL80211_CMD_GET_KEY, | 5429 | .cmd = NL80211_CMD_GET_KEY, |
5096 | .doit = nl80211_get_key, | 5430 | .doit = nl80211_get_key, |
5097 | .policy = nl80211_policy, | 5431 | .policy = nl80211_policy, |
5098 | .flags = GENL_ADMIN_PERM, | 5432 | .flags = GENL_ADMIN_PERM, |
5433 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | ||
5434 | NL80211_FLAG_NEED_RTNL, | ||
5099 | }, | 5435 | }, |
5100 | { | 5436 | { |
5101 | .cmd = NL80211_CMD_SET_KEY, | 5437 | .cmd = NL80211_CMD_SET_KEY, |
5102 | .doit = nl80211_set_key, | 5438 | .doit = nl80211_set_key, |
5103 | .policy = nl80211_policy, | 5439 | .policy = nl80211_policy, |
5104 | .flags = GENL_ADMIN_PERM, | 5440 | .flags = GENL_ADMIN_PERM, |
5441 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | ||
5442 | NL80211_FLAG_NEED_RTNL, | ||
5105 | }, | 5443 | }, |
5106 | { | 5444 | { |
5107 | .cmd = NL80211_CMD_NEW_KEY, | 5445 | .cmd = NL80211_CMD_NEW_KEY, |
5108 | .doit = nl80211_new_key, | 5446 | .doit = nl80211_new_key, |
5109 | .policy = nl80211_policy, | 5447 | .policy = nl80211_policy, |
5110 | .flags = GENL_ADMIN_PERM, | 5448 | .flags = GENL_ADMIN_PERM, |
5449 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | ||
5450 | NL80211_FLAG_NEED_RTNL, | ||
5111 | }, | 5451 | }, |
5112 | { | 5452 | { |
5113 | .cmd = NL80211_CMD_DEL_KEY, | 5453 | .cmd = NL80211_CMD_DEL_KEY, |
5114 | .doit = nl80211_del_key, | 5454 | .doit = nl80211_del_key, |
5115 | .policy = nl80211_policy, | 5455 | .policy = nl80211_policy, |
5116 | .flags = GENL_ADMIN_PERM, | 5456 | .flags = GENL_ADMIN_PERM, |
5457 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | ||
5458 | NL80211_FLAG_NEED_RTNL, | ||
5117 | }, | 5459 | }, |
5118 | { | 5460 | { |
5119 | .cmd = NL80211_CMD_SET_BEACON, | 5461 | .cmd = NL80211_CMD_SET_BEACON, |
5120 | .policy = nl80211_policy, | 5462 | .policy = nl80211_policy, |
5121 | .flags = GENL_ADMIN_PERM, | 5463 | .flags = GENL_ADMIN_PERM, |
5122 | .doit = nl80211_addset_beacon, | 5464 | .doit = nl80211_addset_beacon, |
5465 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | ||
5466 | NL80211_FLAG_NEED_RTNL, | ||
5123 | }, | 5467 | }, |
5124 | { | 5468 | { |
5125 | .cmd = NL80211_CMD_NEW_BEACON, | 5469 | .cmd = NL80211_CMD_NEW_BEACON, |
5126 | .policy = nl80211_policy, | 5470 | .policy = nl80211_policy, |
5127 | .flags = GENL_ADMIN_PERM, | 5471 | .flags = GENL_ADMIN_PERM, |
5128 | .doit = nl80211_addset_beacon, | 5472 | .doit = nl80211_addset_beacon, |
5473 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | ||
5474 | NL80211_FLAG_NEED_RTNL, | ||
5129 | }, | 5475 | }, |
5130 | { | 5476 | { |
5131 | .cmd = NL80211_CMD_DEL_BEACON, | 5477 | .cmd = NL80211_CMD_DEL_BEACON, |
5132 | .policy = nl80211_policy, | 5478 | .policy = nl80211_policy, |
5133 | .flags = GENL_ADMIN_PERM, | 5479 | .flags = GENL_ADMIN_PERM, |
5134 | .doit = nl80211_del_beacon, | 5480 | .doit = nl80211_del_beacon, |
5481 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | ||
5482 | NL80211_FLAG_NEED_RTNL, | ||
5135 | }, | 5483 | }, |
5136 | { | 5484 | { |
5137 | .cmd = NL80211_CMD_GET_STATION, | 5485 | .cmd = NL80211_CMD_GET_STATION, |
5138 | .doit = nl80211_get_station, | 5486 | .doit = nl80211_get_station, |
5139 | .dumpit = nl80211_dump_station, | 5487 | .dumpit = nl80211_dump_station, |
5140 | .policy = nl80211_policy, | 5488 | .policy = nl80211_policy, |
5489 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | ||
5490 | NL80211_FLAG_NEED_RTNL, | ||
5141 | }, | 5491 | }, |
5142 | { | 5492 | { |
5143 | .cmd = NL80211_CMD_SET_STATION, | 5493 | .cmd = NL80211_CMD_SET_STATION, |
5144 | .doit = nl80211_set_station, | 5494 | .doit = nl80211_set_station, |
5145 | .policy = nl80211_policy, | 5495 | .policy = nl80211_policy, |
5146 | .flags = GENL_ADMIN_PERM, | 5496 | .flags = GENL_ADMIN_PERM, |
5497 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | ||
5498 | NL80211_FLAG_NEED_RTNL, | ||
5147 | }, | 5499 | }, |
5148 | { | 5500 | { |
5149 | .cmd = NL80211_CMD_NEW_STATION, | 5501 | .cmd = NL80211_CMD_NEW_STATION, |
5150 | .doit = nl80211_new_station, | 5502 | .doit = nl80211_new_station, |
5151 | .policy = nl80211_policy, | 5503 | .policy = nl80211_policy, |
5152 | .flags = GENL_ADMIN_PERM, | 5504 | .flags = GENL_ADMIN_PERM, |
5505 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | ||
5506 | NL80211_FLAG_NEED_RTNL, | ||
5153 | }, | 5507 | }, |
5154 | { | 5508 | { |
5155 | .cmd = NL80211_CMD_DEL_STATION, | 5509 | .cmd = NL80211_CMD_DEL_STATION, |
5156 | .doit = nl80211_del_station, | 5510 | .doit = nl80211_del_station, |
5157 | .policy = nl80211_policy, | 5511 | .policy = nl80211_policy, |
5158 | .flags = GENL_ADMIN_PERM, | 5512 | .flags = GENL_ADMIN_PERM, |
5513 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | ||
5514 | NL80211_FLAG_NEED_RTNL, | ||
5159 | }, | 5515 | }, |
5160 | { | 5516 | { |
5161 | .cmd = NL80211_CMD_GET_MPATH, | 5517 | .cmd = NL80211_CMD_GET_MPATH, |
@@ -5163,30 +5519,40 @@ static struct genl_ops nl80211_ops[] = { | |||
5163 | .dumpit = nl80211_dump_mpath, | 5519 | .dumpit = nl80211_dump_mpath, |
5164 | .policy = nl80211_policy, | 5520 | .policy = nl80211_policy, |
5165 | .flags = GENL_ADMIN_PERM, | 5521 | .flags = GENL_ADMIN_PERM, |
5522 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | ||
5523 | NL80211_FLAG_NEED_RTNL, | ||
5166 | }, | 5524 | }, |
5167 | { | 5525 | { |
5168 | .cmd = NL80211_CMD_SET_MPATH, | 5526 | .cmd = NL80211_CMD_SET_MPATH, |
5169 | .doit = nl80211_set_mpath, | 5527 | .doit = nl80211_set_mpath, |
5170 | .policy = nl80211_policy, | 5528 | .policy = nl80211_policy, |
5171 | .flags = GENL_ADMIN_PERM, | 5529 | .flags = GENL_ADMIN_PERM, |
5530 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | ||
5531 | NL80211_FLAG_NEED_RTNL, | ||
5172 | }, | 5532 | }, |
5173 | { | 5533 | { |
5174 | .cmd = NL80211_CMD_NEW_MPATH, | 5534 | .cmd = NL80211_CMD_NEW_MPATH, |
5175 | .doit = nl80211_new_mpath, | 5535 | .doit = nl80211_new_mpath, |
5176 | .policy = nl80211_policy, | 5536 | .policy = nl80211_policy, |
5177 | .flags = GENL_ADMIN_PERM, | 5537 | .flags = GENL_ADMIN_PERM, |
5538 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | ||
5539 | NL80211_FLAG_NEED_RTNL, | ||
5178 | }, | 5540 | }, |
5179 | { | 5541 | { |
5180 | .cmd = NL80211_CMD_DEL_MPATH, | 5542 | .cmd = NL80211_CMD_DEL_MPATH, |
5181 | .doit = nl80211_del_mpath, | 5543 | .doit = nl80211_del_mpath, |
5182 | .policy = nl80211_policy, | 5544 | .policy = nl80211_policy, |
5183 | .flags = GENL_ADMIN_PERM, | 5545 | .flags = GENL_ADMIN_PERM, |
5546 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | ||
5547 | NL80211_FLAG_NEED_RTNL, | ||
5184 | }, | 5548 | }, |
5185 | { | 5549 | { |
5186 | .cmd = NL80211_CMD_SET_BSS, | 5550 | .cmd = NL80211_CMD_SET_BSS, |
5187 | .doit = nl80211_set_bss, | 5551 | .doit = nl80211_set_bss, |
5188 | .policy = nl80211_policy, | 5552 | .policy = nl80211_policy, |
5189 | .flags = GENL_ADMIN_PERM, | 5553 | .flags = GENL_ADMIN_PERM, |
5554 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | ||
5555 | NL80211_FLAG_NEED_RTNL, | ||
5190 | }, | 5556 | }, |
5191 | { | 5557 | { |
5192 | .cmd = NL80211_CMD_GET_REG, | 5558 | .cmd = NL80211_CMD_GET_REG, |
@@ -5207,22 +5573,28 @@ static struct genl_ops nl80211_ops[] = { | |||
5207 | .flags = GENL_ADMIN_PERM, | 5573 | .flags = GENL_ADMIN_PERM, |
5208 | }, | 5574 | }, |
5209 | { | 5575 | { |
5210 | .cmd = NL80211_CMD_GET_MESH_PARAMS, | 5576 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
5211 | .doit = nl80211_get_mesh_params, | 5577 | .doit = nl80211_get_mesh_config, |
5212 | .policy = nl80211_policy, | 5578 | .policy = nl80211_policy, |
5213 | /* can be retrieved by unprivileged users */ | 5579 | /* can be retrieved by unprivileged users */ |
5580 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | ||
5581 | NL80211_FLAG_NEED_RTNL, | ||
5214 | }, | 5582 | }, |
5215 | { | 5583 | { |
5216 | .cmd = NL80211_CMD_SET_MESH_PARAMS, | 5584 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
5217 | .doit = nl80211_set_mesh_params, | 5585 | .doit = nl80211_update_mesh_config, |
5218 | .policy = nl80211_policy, | 5586 | .policy = nl80211_policy, |
5219 | .flags = GENL_ADMIN_PERM, | 5587 | .flags = GENL_ADMIN_PERM, |
5588 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | ||
5589 | NL80211_FLAG_NEED_RTNL, | ||
5220 | }, | 5590 | }, |
5221 | { | 5591 | { |
5222 | .cmd = NL80211_CMD_TRIGGER_SCAN, | 5592 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
5223 | .doit = nl80211_trigger_scan, | 5593 | .doit = nl80211_trigger_scan, |
5224 | .policy = nl80211_policy, | 5594 | .policy = nl80211_policy, |
5225 | .flags = GENL_ADMIN_PERM, | 5595 | .flags = GENL_ADMIN_PERM, |
5596 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | ||
5597 | NL80211_FLAG_NEED_RTNL, | ||
5226 | }, | 5598 | }, |
5227 | { | 5599 | { |
5228 | .cmd = NL80211_CMD_GET_SCAN, | 5600 | .cmd = NL80211_CMD_GET_SCAN, |
@@ -5230,40 +5602,68 @@ static struct genl_ops nl80211_ops[] = { | |||
5230 | .dumpit = nl80211_dump_scan, | 5602 | .dumpit = nl80211_dump_scan, |
5231 | }, | 5603 | }, |
5232 | { | 5604 | { |
5605 | .cmd = NL80211_CMD_START_SCHED_SCAN, | ||
5606 | .doit = nl80211_start_sched_scan, | ||
5607 | .policy = nl80211_policy, | ||
5608 | .flags = GENL_ADMIN_PERM, | ||
5609 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | ||
5610 | NL80211_FLAG_NEED_RTNL, | ||
5611 | }, | ||
5612 | { | ||
5613 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, | ||
5614 | .doit = nl80211_stop_sched_scan, | ||
5615 | .policy = nl80211_policy, | ||
5616 | .flags = GENL_ADMIN_PERM, | ||
5617 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | ||
5618 | NL80211_FLAG_NEED_RTNL, | ||
5619 | }, | ||
5620 | { | ||
5233 | .cmd = NL80211_CMD_AUTHENTICATE, | 5621 | .cmd = NL80211_CMD_AUTHENTICATE, |
5234 | .doit = nl80211_authenticate, | 5622 | .doit = nl80211_authenticate, |
5235 | .policy = nl80211_policy, | 5623 | .policy = nl80211_policy, |
5236 | .flags = GENL_ADMIN_PERM, | 5624 | .flags = GENL_ADMIN_PERM, |
5625 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | ||
5626 | NL80211_FLAG_NEED_RTNL, | ||
5237 | }, | 5627 | }, |
5238 | { | 5628 | { |
5239 | .cmd = NL80211_CMD_ASSOCIATE, | 5629 | .cmd = NL80211_CMD_ASSOCIATE, |
5240 | .doit = nl80211_associate, | 5630 | .doit = nl80211_associate, |
5241 | .policy = nl80211_policy, | 5631 | .policy = nl80211_policy, |
5242 | .flags = GENL_ADMIN_PERM, | 5632 | .flags = GENL_ADMIN_PERM, |
5633 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | ||
5634 | NL80211_FLAG_NEED_RTNL, | ||
5243 | }, | 5635 | }, |
5244 | { | 5636 | { |
5245 | .cmd = NL80211_CMD_DEAUTHENTICATE, | 5637 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
5246 | .doit = nl80211_deauthenticate, | 5638 | .doit = nl80211_deauthenticate, |
5247 | .policy = nl80211_policy, | 5639 | .policy = nl80211_policy, |
5248 | .flags = GENL_ADMIN_PERM, | 5640 | .flags = GENL_ADMIN_PERM, |
5641 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | ||
5642 | NL80211_FLAG_NEED_RTNL, | ||
5249 | }, | 5643 | }, |
5250 | { | 5644 | { |
5251 | .cmd = NL80211_CMD_DISASSOCIATE, | 5645 | .cmd = NL80211_CMD_DISASSOCIATE, |
5252 | .doit = nl80211_disassociate, | 5646 | .doit = nl80211_disassociate, |
5253 | .policy = nl80211_policy, | 5647 | .policy = nl80211_policy, |
5254 | .flags = GENL_ADMIN_PERM, | 5648 | .flags = GENL_ADMIN_PERM, |
5649 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | ||
5650 | NL80211_FLAG_NEED_RTNL, | ||
5255 | }, | 5651 | }, |
5256 | { | 5652 | { |
5257 | .cmd = NL80211_CMD_JOIN_IBSS, | 5653 | .cmd = NL80211_CMD_JOIN_IBSS, |
5258 | .doit = nl80211_join_ibss, | 5654 | .doit = nl80211_join_ibss, |
5259 | .policy = nl80211_policy, | 5655 | .policy = nl80211_policy, |
5260 | .flags = GENL_ADMIN_PERM, | 5656 | .flags = GENL_ADMIN_PERM, |
5657 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | ||
5658 | NL80211_FLAG_NEED_RTNL, | ||
5261 | }, | 5659 | }, |
5262 | { | 5660 | { |
5263 | .cmd = NL80211_CMD_LEAVE_IBSS, | 5661 | .cmd = NL80211_CMD_LEAVE_IBSS, |
5264 | .doit = nl80211_leave_ibss, | 5662 | .doit = nl80211_leave_ibss, |
5265 | .policy = nl80211_policy, | 5663 | .policy = nl80211_policy, |
5266 | .flags = GENL_ADMIN_PERM, | 5664 | .flags = GENL_ADMIN_PERM, |
5665 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | ||
5666 | NL80211_FLAG_NEED_RTNL, | ||
5267 | }, | 5667 | }, |
5268 | #ifdef CONFIG_NL80211_TESTMODE | 5668 | #ifdef CONFIG_NL80211_TESTMODE |
5269 | { | 5669 | { |
@@ -5271,6 +5671,8 @@ static struct genl_ops nl80211_ops[] = { | |||
5271 | .doit = nl80211_testmode_do, | 5671 | .doit = nl80211_testmode_do, |
5272 | .policy = nl80211_policy, | 5672 | .policy = nl80211_policy, |
5273 | .flags = GENL_ADMIN_PERM, | 5673 | .flags = GENL_ADMIN_PERM, |
5674 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | ||
5675 | NL80211_FLAG_NEED_RTNL, | ||
5274 | }, | 5676 | }, |
5275 | #endif | 5677 | #endif |
5276 | { | 5678 | { |
@@ -5278,18 +5680,24 @@ static struct genl_ops nl80211_ops[] = { | |||
5278 | .doit = nl80211_connect, | 5680 | .doit = nl80211_connect, |
5279 | .policy = nl80211_policy, | 5681 | .policy = nl80211_policy, |
5280 | .flags = GENL_ADMIN_PERM, | 5682 | .flags = GENL_ADMIN_PERM, |
5683 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | ||
5684 | NL80211_FLAG_NEED_RTNL, | ||
5281 | }, | 5685 | }, |
5282 | { | 5686 | { |
5283 | .cmd = NL80211_CMD_DISCONNECT, | 5687 | .cmd = NL80211_CMD_DISCONNECT, |
5284 | .doit = nl80211_disconnect, | 5688 | .doit = nl80211_disconnect, |
5285 | .policy = nl80211_policy, | 5689 | .policy = nl80211_policy, |
5286 | .flags = GENL_ADMIN_PERM, | 5690 | .flags = GENL_ADMIN_PERM, |
5691 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | ||
5692 | NL80211_FLAG_NEED_RTNL, | ||
5287 | }, | 5693 | }, |
5288 | { | 5694 | { |
5289 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, | 5695 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
5290 | .doit = nl80211_wiphy_netns, | 5696 | .doit = nl80211_wiphy_netns, |
5291 | .policy = nl80211_policy, | 5697 | .policy = nl80211_policy, |
5292 | .flags = GENL_ADMIN_PERM, | 5698 | .flags = GENL_ADMIN_PERM, |
5699 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | ||
5700 | NL80211_FLAG_NEED_RTNL, | ||
5293 | }, | 5701 | }, |
5294 | { | 5702 | { |
5295 | .cmd = NL80211_CMD_GET_SURVEY, | 5703 | .cmd = NL80211_CMD_GET_SURVEY, |
@@ -5301,72 +5709,144 @@ static struct genl_ops nl80211_ops[] = { | |||
5301 | .doit = nl80211_setdel_pmksa, | 5709 | .doit = nl80211_setdel_pmksa, |
5302 | .policy = nl80211_policy, | 5710 | .policy = nl80211_policy, |
5303 | .flags = GENL_ADMIN_PERM, | 5711 | .flags = GENL_ADMIN_PERM, |
5712 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | ||
5713 | NL80211_FLAG_NEED_RTNL, | ||
5304 | }, | 5714 | }, |
5305 | { | 5715 | { |
5306 | .cmd = NL80211_CMD_DEL_PMKSA, | 5716 | .cmd = NL80211_CMD_DEL_PMKSA, |
5307 | .doit = nl80211_setdel_pmksa, | 5717 | .doit = nl80211_setdel_pmksa, |
5308 | .policy = nl80211_policy, | 5718 | .policy = nl80211_policy, |
5309 | .flags = GENL_ADMIN_PERM, | 5719 | .flags = GENL_ADMIN_PERM, |
5720 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | ||
5721 | NL80211_FLAG_NEED_RTNL, | ||
5310 | }, | 5722 | }, |
5311 | { | 5723 | { |
5312 | .cmd = NL80211_CMD_FLUSH_PMKSA, | 5724 | .cmd = NL80211_CMD_FLUSH_PMKSA, |
5313 | .doit = nl80211_flush_pmksa, | 5725 | .doit = nl80211_flush_pmksa, |
5314 | .policy = nl80211_policy, | 5726 | .policy = nl80211_policy, |
5315 | .flags = GENL_ADMIN_PERM, | 5727 | .flags = GENL_ADMIN_PERM, |
5728 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | ||
5729 | NL80211_FLAG_NEED_RTNL, | ||
5316 | }, | 5730 | }, |
5317 | { | 5731 | { |
5318 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, | 5732 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, |
5319 | .doit = nl80211_remain_on_channel, | 5733 | .doit = nl80211_remain_on_channel, |
5320 | .policy = nl80211_policy, | 5734 | .policy = nl80211_policy, |
5321 | .flags = GENL_ADMIN_PERM, | 5735 | .flags = GENL_ADMIN_PERM, |
5736 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | ||
5737 | NL80211_FLAG_NEED_RTNL, | ||
5322 | }, | 5738 | }, |
5323 | { | 5739 | { |
5324 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | 5740 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
5325 | .doit = nl80211_cancel_remain_on_channel, | 5741 | .doit = nl80211_cancel_remain_on_channel, |
5326 | .policy = nl80211_policy, | 5742 | .policy = nl80211_policy, |
5327 | .flags = GENL_ADMIN_PERM, | 5743 | .flags = GENL_ADMIN_PERM, |
5744 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | ||
5745 | NL80211_FLAG_NEED_RTNL, | ||
5328 | }, | 5746 | }, |
5329 | { | 5747 | { |
5330 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, | 5748 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, |
5331 | .doit = nl80211_set_tx_bitrate_mask, | 5749 | .doit = nl80211_set_tx_bitrate_mask, |
5332 | .policy = nl80211_policy, | 5750 | .policy = nl80211_policy, |
5333 | .flags = GENL_ADMIN_PERM, | 5751 | .flags = GENL_ADMIN_PERM, |
5752 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | ||
5753 | NL80211_FLAG_NEED_RTNL, | ||
5334 | }, | 5754 | }, |
5335 | { | 5755 | { |
5336 | .cmd = NL80211_CMD_REGISTER_ACTION, | 5756 | .cmd = NL80211_CMD_REGISTER_FRAME, |
5337 | .doit = nl80211_register_action, | 5757 | .doit = nl80211_register_mgmt, |
5338 | .policy = nl80211_policy, | 5758 | .policy = nl80211_policy, |
5339 | .flags = GENL_ADMIN_PERM, | 5759 | .flags = GENL_ADMIN_PERM, |
5760 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | ||
5761 | NL80211_FLAG_NEED_RTNL, | ||
5340 | }, | 5762 | }, |
5341 | { | 5763 | { |
5342 | .cmd = NL80211_CMD_ACTION, | 5764 | .cmd = NL80211_CMD_FRAME, |
5343 | .doit = nl80211_action, | 5765 | .doit = nl80211_tx_mgmt, |
5344 | .policy = nl80211_policy, | 5766 | .policy = nl80211_policy, |
5345 | .flags = GENL_ADMIN_PERM, | 5767 | .flags = GENL_ADMIN_PERM, |
5768 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | ||
5769 | NL80211_FLAG_NEED_RTNL, | ||
5770 | }, | ||
5771 | { | ||
5772 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, | ||
5773 | .doit = nl80211_tx_mgmt_cancel_wait, | ||
5774 | .policy = nl80211_policy, | ||
5775 | .flags = GENL_ADMIN_PERM, | ||
5776 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | ||
5777 | NL80211_FLAG_NEED_RTNL, | ||
5346 | }, | 5778 | }, |
5347 | { | 5779 | { |
5348 | .cmd = NL80211_CMD_SET_POWER_SAVE, | 5780 | .cmd = NL80211_CMD_SET_POWER_SAVE, |
5349 | .doit = nl80211_set_power_save, | 5781 | .doit = nl80211_set_power_save, |
5350 | .policy = nl80211_policy, | 5782 | .policy = nl80211_policy, |
5351 | .flags = GENL_ADMIN_PERM, | 5783 | .flags = GENL_ADMIN_PERM, |
5784 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | ||
5785 | NL80211_FLAG_NEED_RTNL, | ||
5352 | }, | 5786 | }, |
5353 | { | 5787 | { |
5354 | .cmd = NL80211_CMD_GET_POWER_SAVE, | 5788 | .cmd = NL80211_CMD_GET_POWER_SAVE, |
5355 | .doit = nl80211_get_power_save, | 5789 | .doit = nl80211_get_power_save, |
5356 | .policy = nl80211_policy, | 5790 | .policy = nl80211_policy, |
5357 | /* can be retrieved by unprivileged users */ | 5791 | /* can be retrieved by unprivileged users */ |
5792 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | ||
5793 | NL80211_FLAG_NEED_RTNL, | ||
5358 | }, | 5794 | }, |
5359 | { | 5795 | { |
5360 | .cmd = NL80211_CMD_SET_CQM, | 5796 | .cmd = NL80211_CMD_SET_CQM, |
5361 | .doit = nl80211_set_cqm, | 5797 | .doit = nl80211_set_cqm, |
5362 | .policy = nl80211_policy, | 5798 | .policy = nl80211_policy, |
5363 | .flags = GENL_ADMIN_PERM, | 5799 | .flags = GENL_ADMIN_PERM, |
5800 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | ||
5801 | NL80211_FLAG_NEED_RTNL, | ||
5364 | }, | 5802 | }, |
5365 | { | 5803 | { |
5366 | .cmd = NL80211_CMD_SET_CHANNEL, | 5804 | .cmd = NL80211_CMD_SET_CHANNEL, |
5367 | .doit = nl80211_set_channel, | 5805 | .doit = nl80211_set_channel, |
5368 | .policy = nl80211_policy, | 5806 | .policy = nl80211_policy, |
5369 | .flags = GENL_ADMIN_PERM, | 5807 | .flags = GENL_ADMIN_PERM, |
5808 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | ||
5809 | NL80211_FLAG_NEED_RTNL, | ||
5810 | }, | ||
5811 | { | ||
5812 | .cmd = NL80211_CMD_SET_WDS_PEER, | ||
5813 | .doit = nl80211_set_wds_peer, | ||
5814 | .policy = nl80211_policy, | ||
5815 | .flags = GENL_ADMIN_PERM, | ||
5816 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | ||
5817 | NL80211_FLAG_NEED_RTNL, | ||
5818 | }, | ||
5819 | { | ||
5820 | .cmd = NL80211_CMD_JOIN_MESH, | ||
5821 | .doit = nl80211_join_mesh, | ||
5822 | .policy = nl80211_policy, | ||
5823 | .flags = GENL_ADMIN_PERM, | ||
5824 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | ||
5825 | NL80211_FLAG_NEED_RTNL, | ||
5826 | }, | ||
5827 | { | ||
5828 | .cmd = NL80211_CMD_LEAVE_MESH, | ||
5829 | .doit = nl80211_leave_mesh, | ||
5830 | .policy = nl80211_policy, | ||
5831 | .flags = GENL_ADMIN_PERM, | ||
5832 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | ||
5833 | NL80211_FLAG_NEED_RTNL, | ||
5834 | }, | ||
5835 | { | ||
5836 | .cmd = NL80211_CMD_GET_WOWLAN, | ||
5837 | .doit = nl80211_get_wowlan, | ||
5838 | .policy = nl80211_policy, | ||
5839 | /* can be retrieved by unprivileged users */ | ||
5840 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | ||
5841 | NL80211_FLAG_NEED_RTNL, | ||
5842 | }, | ||
5843 | { | ||
5844 | .cmd = NL80211_CMD_SET_WOWLAN, | ||
5845 | .doit = nl80211_set_wowlan, | ||
5846 | .policy = nl80211_policy, | ||
5847 | .flags = GENL_ADMIN_PERM, | ||
5848 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | ||
5849 | NL80211_FLAG_NEED_RTNL, | ||
5370 | }, | 5850 | }, |
5371 | }; | 5851 | }; |
5372 | 5852 | ||
@@ -5463,6 +5943,28 @@ static int nl80211_send_scan_msg(struct sk_buff *msg, | |||
5463 | return -EMSGSIZE; | 5943 | return -EMSGSIZE; |
5464 | } | 5944 | } |
5465 | 5945 | ||
5946 | static int | ||
5947 | nl80211_send_sched_scan_msg(struct sk_buff *msg, | ||
5948 | struct cfg80211_registered_device *rdev, | ||
5949 | struct net_device *netdev, | ||
5950 | u32 pid, u32 seq, int flags, u32 cmd) | ||
5951 | { | ||
5952 | void *hdr; | ||
5953 | |||
5954 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); | ||
5955 | if (!hdr) | ||
5956 | return -1; | ||
5957 | |||
5958 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | ||
5959 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | ||
5960 | |||
5961 | return genlmsg_end(msg, hdr); | ||
5962 | |||
5963 | nla_put_failure: | ||
5964 | genlmsg_cancel(msg, hdr); | ||
5965 | return -EMSGSIZE; | ||
5966 | } | ||
5967 | |||
5466 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, | 5968 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
5467 | struct net_device *netdev) | 5969 | struct net_device *netdev) |
5468 | { | 5970 | { |
@@ -5520,6 +6022,43 @@ void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, | |||
5520 | nl80211_scan_mcgrp.id, GFP_KERNEL); | 6022 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
5521 | } | 6023 | } |
5522 | 6024 | ||
6025 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, | ||
6026 | struct net_device *netdev) | ||
6027 | { | ||
6028 | struct sk_buff *msg; | ||
6029 | |||
6030 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | ||
6031 | if (!msg) | ||
6032 | return; | ||
6033 | |||
6034 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, | ||
6035 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { | ||
6036 | nlmsg_free(msg); | ||
6037 | return; | ||
6038 | } | ||
6039 | |||
6040 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | ||
6041 | nl80211_scan_mcgrp.id, GFP_KERNEL); | ||
6042 | } | ||
6043 | |||
6044 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, | ||
6045 | struct net_device *netdev, u32 cmd) | ||
6046 | { | ||
6047 | struct sk_buff *msg; | ||
6048 | |||
6049 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); | ||
6050 | if (!msg) | ||
6051 | return; | ||
6052 | |||
6053 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { | ||
6054 | nlmsg_free(msg); | ||
6055 | return; | ||
6056 | } | ||
6057 | |||
6058 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | ||
6059 | nl80211_scan_mcgrp.id, GFP_KERNEL); | ||
6060 | } | ||
6061 | |||
5523 | /* | 6062 | /* |
5524 | * This can happen on global regulatory changes or device specific settings | 6063 | * This can happen on global regulatory changes or device specific settings |
5525 | * based on custom world regulatory domains. | 6064 | * based on custom world regulatory domains. |
@@ -5646,6 +6185,22 @@ void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, | |||
5646 | NL80211_CMD_DISASSOCIATE, gfp); | 6185 | NL80211_CMD_DISASSOCIATE, gfp); |
5647 | } | 6186 | } |
5648 | 6187 | ||
6188 | void nl80211_send_unprot_deauth(struct cfg80211_registered_device *rdev, | ||
6189 | struct net_device *netdev, const u8 *buf, | ||
6190 | size_t len, gfp_t gfp) | ||
6191 | { | ||
6192 | nl80211_send_mlme_event(rdev, netdev, buf, len, | ||
6193 | NL80211_CMD_UNPROT_DEAUTHENTICATE, gfp); | ||
6194 | } | ||
6195 | |||
6196 | void nl80211_send_unprot_disassoc(struct cfg80211_registered_device *rdev, | ||
6197 | struct net_device *netdev, const u8 *buf, | ||
6198 | size_t len, gfp_t gfp) | ||
6199 | { | ||
6200 | nl80211_send_mlme_event(rdev, netdev, buf, len, | ||
6201 | NL80211_CMD_UNPROT_DISASSOCIATE, gfp); | ||
6202 | } | ||
6203 | |||
5649 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, | 6204 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
5650 | struct net_device *netdev, int cmd, | 6205 | struct net_device *netdev, int cmd, |
5651 | const u8 *addr, gfp_t gfp) | 6206 | const u8 *addr, gfp_t gfp) |
@@ -5859,6 +6414,44 @@ void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, | |||
5859 | nlmsg_free(msg); | 6414 | nlmsg_free(msg); |
5860 | } | 6415 | } |
5861 | 6416 | ||
6417 | void nl80211_send_new_peer_candidate(struct cfg80211_registered_device *rdev, | ||
6418 | struct net_device *netdev, | ||
6419 | const u8 *macaddr, const u8* ie, u8 ie_len, | ||
6420 | gfp_t gfp) | ||
6421 | { | ||
6422 | struct sk_buff *msg; | ||
6423 | void *hdr; | ||
6424 | |||
6425 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | ||
6426 | if (!msg) | ||
6427 | return; | ||
6428 | |||
6429 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); | ||
6430 | if (!hdr) { | ||
6431 | nlmsg_free(msg); | ||
6432 | return; | ||
6433 | } | ||
6434 | |||
6435 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | ||
6436 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | ||
6437 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, macaddr); | ||
6438 | if (ie_len && ie) | ||
6439 | NLA_PUT(msg, NL80211_ATTR_IE, ie_len , ie); | ||
6440 | |||
6441 | if (genlmsg_end(msg, hdr) < 0) { | ||
6442 | nlmsg_free(msg); | ||
6443 | return; | ||
6444 | } | ||
6445 | |||
6446 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | ||
6447 | nl80211_mlme_mcgrp.id, gfp); | ||
6448 | return; | ||
6449 | |||
6450 | nla_put_failure: | ||
6451 | genlmsg_cancel(msg, hdr); | ||
6452 | nlmsg_free(msg); | ||
6453 | } | ||
6454 | |||
5862 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, | 6455 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
5863 | struct net_device *netdev, const u8 *addr, | 6456 | struct net_device *netdev, const u8 *addr, |
5864 | enum nl80211_key_type key_type, int key_id, | 6457 | enum nl80211_key_type key_type, int key_id, |
@@ -5882,7 +6475,8 @@ void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, | |||
5882 | if (addr) | 6475 | if (addr) |
5883 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); | 6476 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
5884 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type); | 6477 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type); |
5885 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id); | 6478 | if (key_id != -1) |
6479 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id); | ||
5886 | if (tsc) | 6480 | if (tsc) |
5887 | NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc); | 6481 | NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc); |
5888 | 6482 | ||
@@ -6040,9 +6634,43 @@ void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, | |||
6040 | nl80211_mlme_mcgrp.id, gfp); | 6634 | nl80211_mlme_mcgrp.id, gfp); |
6041 | } | 6635 | } |
6042 | 6636 | ||
6043 | int nl80211_send_action(struct cfg80211_registered_device *rdev, | 6637 | void nl80211_send_sta_del_event(struct cfg80211_registered_device *rdev, |
6044 | struct net_device *netdev, u32 nlpid, | 6638 | struct net_device *dev, const u8 *mac_addr, |
6045 | int freq, const u8 *buf, size_t len, gfp_t gfp) | 6639 | gfp_t gfp) |
6640 | { | ||
6641 | struct sk_buff *msg; | ||
6642 | void *hdr; | ||
6643 | |||
6644 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | ||
6645 | if (!msg) | ||
6646 | return; | ||
6647 | |||
6648 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION); | ||
6649 | if (!hdr) { | ||
6650 | nlmsg_free(msg); | ||
6651 | return; | ||
6652 | } | ||
6653 | |||
6654 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); | ||
6655 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | ||
6656 | |||
6657 | if (genlmsg_end(msg, hdr) < 0) { | ||
6658 | nlmsg_free(msg); | ||
6659 | return; | ||
6660 | } | ||
6661 | |||
6662 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | ||
6663 | nl80211_mlme_mcgrp.id, gfp); | ||
6664 | return; | ||
6665 | |||
6666 | nla_put_failure: | ||
6667 | genlmsg_cancel(msg, hdr); | ||
6668 | nlmsg_free(msg); | ||
6669 | } | ||
6670 | |||
6671 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, | ||
6672 | struct net_device *netdev, u32 nlpid, | ||
6673 | int freq, const u8 *buf, size_t len, gfp_t gfp) | ||
6046 | { | 6674 | { |
6047 | struct sk_buff *msg; | 6675 | struct sk_buff *msg; |
6048 | void *hdr; | 6676 | void *hdr; |
@@ -6052,7 +6680,7 @@ int nl80211_send_action(struct cfg80211_registered_device *rdev, | |||
6052 | if (!msg) | 6680 | if (!msg) |
6053 | return -ENOMEM; | 6681 | return -ENOMEM; |
6054 | 6682 | ||
6055 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ACTION); | 6683 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
6056 | if (!hdr) { | 6684 | if (!hdr) { |
6057 | nlmsg_free(msg); | 6685 | nlmsg_free(msg); |
6058 | return -ENOMEM; | 6686 | return -ENOMEM; |
@@ -6080,10 +6708,10 @@ int nl80211_send_action(struct cfg80211_registered_device *rdev, | |||
6080 | return -ENOBUFS; | 6708 | return -ENOBUFS; |
6081 | } | 6709 | } |
6082 | 6710 | ||
6083 | void nl80211_send_action_tx_status(struct cfg80211_registered_device *rdev, | 6711 | void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev, |
6084 | struct net_device *netdev, u64 cookie, | 6712 | struct net_device *netdev, u64 cookie, |
6085 | const u8 *buf, size_t len, bool ack, | 6713 | const u8 *buf, size_t len, bool ack, |
6086 | gfp_t gfp) | 6714 | gfp_t gfp) |
6087 | { | 6715 | { |
6088 | struct sk_buff *msg; | 6716 | struct sk_buff *msg; |
6089 | void *hdr; | 6717 | void *hdr; |
@@ -6092,7 +6720,7 @@ void nl80211_send_action_tx_status(struct cfg80211_registered_device *rdev, | |||
6092 | if (!msg) | 6720 | if (!msg) |
6093 | return; | 6721 | return; |
6094 | 6722 | ||
6095 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ACTION_TX_STATUS); | 6723 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
6096 | if (!hdr) { | 6724 | if (!hdr) { |
6097 | nlmsg_free(msg); | 6725 | nlmsg_free(msg); |
6098 | return; | 6726 | return; |
@@ -6164,6 +6792,51 @@ nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, | |||
6164 | nlmsg_free(msg); | 6792 | nlmsg_free(msg); |
6165 | } | 6793 | } |
6166 | 6794 | ||
6795 | void | ||
6796 | nl80211_send_cqm_pktloss_notify(struct cfg80211_registered_device *rdev, | ||
6797 | struct net_device *netdev, const u8 *peer, | ||
6798 | u32 num_packets, gfp_t gfp) | ||
6799 | { | ||
6800 | struct sk_buff *msg; | ||
6801 | struct nlattr *pinfoattr; | ||
6802 | void *hdr; | ||
6803 | |||
6804 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | ||
6805 | if (!msg) | ||
6806 | return; | ||
6807 | |||
6808 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | ||
6809 | if (!hdr) { | ||
6810 | nlmsg_free(msg); | ||
6811 | return; | ||
6812 | } | ||
6813 | |||
6814 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | ||
6815 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | ||
6816 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, peer); | ||
6817 | |||
6818 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | ||
6819 | if (!pinfoattr) | ||
6820 | goto nla_put_failure; | ||
6821 | |||
6822 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets); | ||
6823 | |||
6824 | nla_nest_end(msg, pinfoattr); | ||
6825 | |||
6826 | if (genlmsg_end(msg, hdr) < 0) { | ||
6827 | nlmsg_free(msg); | ||
6828 | return; | ||
6829 | } | ||
6830 | |||
6831 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | ||
6832 | nl80211_mlme_mcgrp.id, gfp); | ||
6833 | return; | ||
6834 | |||
6835 | nla_put_failure: | ||
6836 | genlmsg_cancel(msg, hdr); | ||
6837 | nlmsg_free(msg); | ||
6838 | } | ||
6839 | |||
6167 | static int nl80211_netlink_notify(struct notifier_block * nb, | 6840 | static int nl80211_netlink_notify(struct notifier_block * nb, |
6168 | unsigned long state, | 6841 | unsigned long state, |
6169 | void *_notify) | 6842 | void *_notify) |
@@ -6179,7 +6852,7 @@ static int nl80211_netlink_notify(struct notifier_block * nb, | |||
6179 | 6852 | ||
6180 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) | 6853 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) |
6181 | list_for_each_entry_rcu(wdev, &rdev->netdev_list, list) | 6854 | list_for_each_entry_rcu(wdev, &rdev->netdev_list, list) |
6182 | cfg80211_mlme_unregister_actions(wdev, notify->pid); | 6855 | cfg80211_mlme_unregister_socket(wdev, notify->pid); |
6183 | 6856 | ||
6184 | rcu_read_unlock(); | 6857 | rcu_read_unlock(); |
6185 | 6858 | ||