.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Interface handling |
---|
3 | 4 | * |
---|
.. | .. |
---|
8 | 9 | * Copyright 2013-2014 Intel Mobile Communications GmbH |
---|
9 | 10 | * Copyright (c) 2016 Intel Deutschland GmbH |
---|
10 | 11 | * Copyright (C) 2018-2021 Intel Corporation |
---|
11 | | - * |
---|
12 | | - * This program is free software; you can redistribute it and/or modify |
---|
13 | | - * it under the terms of the GNU General Public License version 2 as |
---|
14 | | - * published by the Free Software Foundation. |
---|
15 | 12 | */ |
---|
16 | 13 | #include <linux/slab.h> |
---|
17 | 14 | #include <linux/kernel.h> |
---|
.. | .. |
---|
351 | 348 | return 0; |
---|
352 | 349 | } |
---|
353 | 350 | |
---|
354 | | -void ieee80211_adjust_monitor_flags(struct ieee80211_sub_if_data *sdata, |
---|
355 | | - const int offset) |
---|
356 | | -{ |
---|
357 | | - struct ieee80211_local *local = sdata->local; |
---|
358 | | - u32 flags = sdata->u.mntr.flags; |
---|
359 | | - |
---|
360 | | -#define ADJUST(_f, _s) do { \ |
---|
361 | | - if (flags & MONITOR_FLAG_##_f) \ |
---|
362 | | - local->fif_##_s += offset; \ |
---|
363 | | - } while (0) |
---|
364 | | - |
---|
365 | | - ADJUST(FCSFAIL, fcsfail); |
---|
366 | | - ADJUST(PLCPFAIL, plcpfail); |
---|
367 | | - ADJUST(CONTROL, control); |
---|
368 | | - ADJUST(CONTROL, pspoll); |
---|
369 | | - ADJUST(OTHER_BSS, other_bss); |
---|
370 | | - |
---|
371 | | -#undef ADJUST |
---|
372 | | -} |
---|
373 | | - |
---|
374 | | -static void ieee80211_set_default_queues(struct ieee80211_sub_if_data *sdata) |
---|
375 | | -{ |
---|
376 | | - struct ieee80211_local *local = sdata->local; |
---|
377 | | - int i; |
---|
378 | | - |
---|
379 | | - for (i = 0; i < IEEE80211_NUM_ACS; i++) { |
---|
380 | | - if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL)) |
---|
381 | | - sdata->vif.hw_queue[i] = IEEE80211_INVAL_HW_QUEUE; |
---|
382 | | - else if (local->hw.queues >= IEEE80211_NUM_ACS) |
---|
383 | | - sdata->vif.hw_queue[i] = i; |
---|
384 | | - else |
---|
385 | | - sdata->vif.hw_queue[i] = 0; |
---|
386 | | - } |
---|
387 | | - sdata->vif.cab_queue = IEEE80211_INVAL_HW_QUEUE; |
---|
388 | | -} |
---|
389 | | - |
---|
390 | | -int ieee80211_add_virtual_monitor(struct ieee80211_local *local) |
---|
391 | | -{ |
---|
392 | | - struct ieee80211_sub_if_data *sdata; |
---|
393 | | - int ret; |
---|
394 | | - |
---|
395 | | - if (!ieee80211_hw_check(&local->hw, WANT_MONITOR_VIF)) |
---|
396 | | - return 0; |
---|
397 | | - |
---|
398 | | - ASSERT_RTNL(); |
---|
399 | | - |
---|
400 | | - if (local->monitor_sdata) |
---|
401 | | - return 0; |
---|
402 | | - |
---|
403 | | - sdata = kzalloc(sizeof(*sdata) + local->hw.vif_data_size, GFP_KERNEL); |
---|
404 | | - if (!sdata) |
---|
405 | | - return -ENOMEM; |
---|
406 | | - |
---|
407 | | - /* set up data */ |
---|
408 | | - sdata->local = local; |
---|
409 | | - sdata->vif.type = NL80211_IFTYPE_MONITOR; |
---|
410 | | - snprintf(sdata->name, IFNAMSIZ, "%s-monitor", |
---|
411 | | - wiphy_name(local->hw.wiphy)); |
---|
412 | | - sdata->wdev.iftype = NL80211_IFTYPE_MONITOR; |
---|
413 | | - |
---|
414 | | - sdata->encrypt_headroom = IEEE80211_ENCRYPT_HEADROOM; |
---|
415 | | - |
---|
416 | | - ieee80211_set_default_queues(sdata); |
---|
417 | | - |
---|
418 | | - ret = drv_add_interface(local, sdata); |
---|
419 | | - if (WARN_ON(ret)) { |
---|
420 | | - /* ok .. stupid driver, it asked for this! */ |
---|
421 | | - kfree(sdata); |
---|
422 | | - return ret; |
---|
423 | | - } |
---|
424 | | - |
---|
425 | | - ret = ieee80211_check_queues(sdata, NL80211_IFTYPE_MONITOR); |
---|
426 | | - if (ret) { |
---|
427 | | - kfree(sdata); |
---|
428 | | - return ret; |
---|
429 | | - } |
---|
430 | | - |
---|
431 | | - mutex_lock(&local->iflist_mtx); |
---|
432 | | - rcu_assign_pointer(local->monitor_sdata, sdata); |
---|
433 | | - mutex_unlock(&local->iflist_mtx); |
---|
434 | | - |
---|
435 | | - mutex_lock(&local->mtx); |
---|
436 | | - ret = ieee80211_vif_use_channel(sdata, &local->monitor_chandef, |
---|
437 | | - IEEE80211_CHANCTX_EXCLUSIVE); |
---|
438 | | - mutex_unlock(&local->mtx); |
---|
439 | | - if (ret) { |
---|
440 | | - mutex_lock(&local->iflist_mtx); |
---|
441 | | - RCU_INIT_POINTER(local->monitor_sdata, NULL); |
---|
442 | | - mutex_unlock(&local->iflist_mtx); |
---|
443 | | - synchronize_net(); |
---|
444 | | - drv_remove_interface(local, sdata); |
---|
445 | | - kfree(sdata); |
---|
446 | | - return ret; |
---|
447 | | - } |
---|
448 | | - |
---|
449 | | - skb_queue_head_init(&sdata->skb_queue); |
---|
450 | | - INIT_WORK(&sdata->work, ieee80211_iface_work); |
---|
451 | | - |
---|
452 | | - return 0; |
---|
453 | | -} |
---|
454 | | - |
---|
455 | | -void ieee80211_del_virtual_monitor(struct ieee80211_local *local) |
---|
456 | | -{ |
---|
457 | | - struct ieee80211_sub_if_data *sdata; |
---|
458 | | - |
---|
459 | | - if (!ieee80211_hw_check(&local->hw, WANT_MONITOR_VIF)) |
---|
460 | | - return; |
---|
461 | | - |
---|
462 | | - ASSERT_RTNL(); |
---|
463 | | - |
---|
464 | | - mutex_lock(&local->iflist_mtx); |
---|
465 | | - |
---|
466 | | - sdata = rcu_dereference_protected(local->monitor_sdata, |
---|
467 | | - lockdep_is_held(&local->iflist_mtx)); |
---|
468 | | - if (!sdata) { |
---|
469 | | - mutex_unlock(&local->iflist_mtx); |
---|
470 | | - return; |
---|
471 | | - } |
---|
472 | | - |
---|
473 | | - RCU_INIT_POINTER(local->monitor_sdata, NULL); |
---|
474 | | - mutex_unlock(&local->iflist_mtx); |
---|
475 | | - |
---|
476 | | - synchronize_net(); |
---|
477 | | - |
---|
478 | | - mutex_lock(&local->mtx); |
---|
479 | | - ieee80211_vif_release_channel(sdata); |
---|
480 | | - mutex_unlock(&local->mtx); |
---|
481 | | - |
---|
482 | | - drv_remove_interface(local, sdata); |
---|
483 | | - |
---|
484 | | - kfree(sdata); |
---|
485 | | -} |
---|
486 | | - |
---|
487 | | -/* |
---|
488 | | - * NOTE: Be very careful when changing this function, it must NOT return |
---|
489 | | - * an error on interface type changes that have been pre-checked, so most |
---|
490 | | - * checks should be in ieee80211_check_concurrent_iface. |
---|
491 | | - */ |
---|
492 | | -int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up) |
---|
493 | | -{ |
---|
494 | | - struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); |
---|
495 | | - struct net_device *dev = wdev->netdev; |
---|
496 | | - struct ieee80211_local *local = sdata->local; |
---|
497 | | - struct sta_info *sta; |
---|
498 | | - u32 changed = 0; |
---|
499 | | - int res; |
---|
500 | | - u32 hw_reconf_flags = 0; |
---|
501 | | - |
---|
502 | | - switch (sdata->vif.type) { |
---|
503 | | - case NL80211_IFTYPE_WDS: |
---|
504 | | - if (!is_valid_ether_addr(sdata->u.wds.remote_addr)) |
---|
505 | | - return -ENOLINK; |
---|
506 | | - break; |
---|
507 | | - case NL80211_IFTYPE_AP_VLAN: { |
---|
508 | | - struct ieee80211_sub_if_data *master; |
---|
509 | | - |
---|
510 | | - if (!sdata->bss) |
---|
511 | | - return -ENOLINK; |
---|
512 | | - |
---|
513 | | - mutex_lock(&local->mtx); |
---|
514 | | - list_add(&sdata->u.vlan.list, &sdata->bss->vlans); |
---|
515 | | - mutex_unlock(&local->mtx); |
---|
516 | | - |
---|
517 | | - master = container_of(sdata->bss, |
---|
518 | | - struct ieee80211_sub_if_data, u.ap); |
---|
519 | | - sdata->control_port_protocol = |
---|
520 | | - master->control_port_protocol; |
---|
521 | | - sdata->control_port_no_encrypt = |
---|
522 | | - master->control_port_no_encrypt; |
---|
523 | | - sdata->control_port_over_nl80211 = |
---|
524 | | - master->control_port_over_nl80211; |
---|
525 | | - sdata->vif.cab_queue = master->vif.cab_queue; |
---|
526 | | - memcpy(sdata->vif.hw_queue, master->vif.hw_queue, |
---|
527 | | - sizeof(sdata->vif.hw_queue)); |
---|
528 | | - sdata->vif.bss_conf.chandef = master->vif.bss_conf.chandef; |
---|
529 | | - |
---|
530 | | - mutex_lock(&local->key_mtx); |
---|
531 | | - sdata->crypto_tx_tailroom_needed_cnt += |
---|
532 | | - master->crypto_tx_tailroom_needed_cnt; |
---|
533 | | - mutex_unlock(&local->key_mtx); |
---|
534 | | - |
---|
535 | | - break; |
---|
536 | | - } |
---|
537 | | - case NL80211_IFTYPE_AP: |
---|
538 | | - sdata->bss = &sdata->u.ap; |
---|
539 | | - break; |
---|
540 | | - case NL80211_IFTYPE_MESH_POINT: |
---|
541 | | - case NL80211_IFTYPE_STATION: |
---|
542 | | - case NL80211_IFTYPE_MONITOR: |
---|
543 | | - case NL80211_IFTYPE_ADHOC: |
---|
544 | | - case NL80211_IFTYPE_P2P_DEVICE: |
---|
545 | | - case NL80211_IFTYPE_OCB: |
---|
546 | | - case NL80211_IFTYPE_NAN: |
---|
547 | | - /* no special treatment */ |
---|
548 | | - break; |
---|
549 | | - case NL80211_IFTYPE_UNSPECIFIED: |
---|
550 | | - case NUM_NL80211_IFTYPES: |
---|
551 | | - case NL80211_IFTYPE_P2P_CLIENT: |
---|
552 | | - case NL80211_IFTYPE_P2P_GO: |
---|
553 | | - /* cannot happen */ |
---|
554 | | - WARN_ON(1); |
---|
555 | | - break; |
---|
556 | | - } |
---|
557 | | - |
---|
558 | | - if (local->open_count == 0) { |
---|
559 | | - res = drv_start(local); |
---|
560 | | - if (res) |
---|
561 | | - goto err_del_bss; |
---|
562 | | - /* we're brought up, everything changes */ |
---|
563 | | - hw_reconf_flags = ~0; |
---|
564 | | - ieee80211_led_radio(local, true); |
---|
565 | | - ieee80211_mod_tpt_led_trig(local, |
---|
566 | | - IEEE80211_TPT_LEDTRIG_FL_RADIO, 0); |
---|
567 | | - } |
---|
568 | | - |
---|
569 | | - /* |
---|
570 | | - * Copy the hopefully now-present MAC address to |
---|
571 | | - * this interface, if it has the special null one. |
---|
572 | | - */ |
---|
573 | | - if (dev && is_zero_ether_addr(dev->dev_addr)) { |
---|
574 | | - memcpy(dev->dev_addr, |
---|
575 | | - local->hw.wiphy->perm_addr, |
---|
576 | | - ETH_ALEN); |
---|
577 | | - memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN); |
---|
578 | | - |
---|
579 | | - if (!is_valid_ether_addr(dev->dev_addr)) { |
---|
580 | | - res = -EADDRNOTAVAIL; |
---|
581 | | - goto err_stop; |
---|
582 | | - } |
---|
583 | | - } |
---|
584 | | - |
---|
585 | | - switch (sdata->vif.type) { |
---|
586 | | - case NL80211_IFTYPE_AP_VLAN: |
---|
587 | | - /* no need to tell driver, but set carrier and chanctx */ |
---|
588 | | - if (rtnl_dereference(sdata->bss->beacon)) { |
---|
589 | | - ieee80211_vif_vlan_copy_chanctx(sdata); |
---|
590 | | - netif_carrier_on(dev); |
---|
591 | | - } else { |
---|
592 | | - netif_carrier_off(dev); |
---|
593 | | - } |
---|
594 | | - break; |
---|
595 | | - case NL80211_IFTYPE_MONITOR: |
---|
596 | | - if (sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES) { |
---|
597 | | - local->cooked_mntrs++; |
---|
598 | | - break; |
---|
599 | | - } |
---|
600 | | - |
---|
601 | | - if (sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE) { |
---|
602 | | - res = drv_add_interface(local, sdata); |
---|
603 | | - if (res) |
---|
604 | | - goto err_stop; |
---|
605 | | - } else if (local->monitors == 0 && local->open_count == 0) { |
---|
606 | | - res = ieee80211_add_virtual_monitor(local); |
---|
607 | | - if (res) |
---|
608 | | - goto err_stop; |
---|
609 | | - } |
---|
610 | | - |
---|
611 | | - /* must be before the call to ieee80211_configure_filter */ |
---|
612 | | - local->monitors++; |
---|
613 | | - if (local->monitors == 1) { |
---|
614 | | - local->hw.conf.flags |= IEEE80211_CONF_MONITOR; |
---|
615 | | - hw_reconf_flags |= IEEE80211_CONF_CHANGE_MONITOR; |
---|
616 | | - } |
---|
617 | | - |
---|
618 | | - ieee80211_adjust_monitor_flags(sdata, 1); |
---|
619 | | - ieee80211_configure_filter(local); |
---|
620 | | - mutex_lock(&local->mtx); |
---|
621 | | - ieee80211_recalc_idle(local); |
---|
622 | | - mutex_unlock(&local->mtx); |
---|
623 | | - |
---|
624 | | - netif_carrier_on(dev); |
---|
625 | | - break; |
---|
626 | | - default: |
---|
627 | | - if (coming_up) { |
---|
628 | | - ieee80211_del_virtual_monitor(local); |
---|
629 | | - |
---|
630 | | - res = drv_add_interface(local, sdata); |
---|
631 | | - if (res) |
---|
632 | | - goto err_stop; |
---|
633 | | - res = ieee80211_check_queues(sdata, |
---|
634 | | - ieee80211_vif_type_p2p(&sdata->vif)); |
---|
635 | | - if (res) |
---|
636 | | - goto err_del_interface; |
---|
637 | | - } |
---|
638 | | - |
---|
639 | | - if (sdata->vif.type == NL80211_IFTYPE_AP) { |
---|
640 | | - local->fif_pspoll++; |
---|
641 | | - local->fif_probe_req++; |
---|
642 | | - |
---|
643 | | - ieee80211_configure_filter(local); |
---|
644 | | - } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) { |
---|
645 | | - local->fif_probe_req++; |
---|
646 | | - } |
---|
647 | | - |
---|
648 | | - if (sdata->vif.type != NL80211_IFTYPE_P2P_DEVICE && |
---|
649 | | - sdata->vif.type != NL80211_IFTYPE_NAN) |
---|
650 | | - changed |= ieee80211_reset_erp_info(sdata); |
---|
651 | | - ieee80211_bss_info_change_notify(sdata, changed); |
---|
652 | | - |
---|
653 | | - switch (sdata->vif.type) { |
---|
654 | | - case NL80211_IFTYPE_STATION: |
---|
655 | | - case NL80211_IFTYPE_ADHOC: |
---|
656 | | - case NL80211_IFTYPE_AP: |
---|
657 | | - case NL80211_IFTYPE_MESH_POINT: |
---|
658 | | - case NL80211_IFTYPE_OCB: |
---|
659 | | - netif_carrier_off(dev); |
---|
660 | | - break; |
---|
661 | | - case NL80211_IFTYPE_WDS: |
---|
662 | | - case NL80211_IFTYPE_P2P_DEVICE: |
---|
663 | | - case NL80211_IFTYPE_NAN: |
---|
664 | | - break; |
---|
665 | | - default: |
---|
666 | | - /* not reached */ |
---|
667 | | - WARN_ON(1); |
---|
668 | | - } |
---|
669 | | - |
---|
670 | | - /* |
---|
671 | | - * Set default queue parameters so drivers don't |
---|
672 | | - * need to initialise the hardware if the hardware |
---|
673 | | - * doesn't start up with sane defaults. |
---|
674 | | - * Enable QoS for anything but station interfaces. |
---|
675 | | - */ |
---|
676 | | - ieee80211_set_wmm_default(sdata, true, |
---|
677 | | - sdata->vif.type != NL80211_IFTYPE_STATION); |
---|
678 | | - } |
---|
679 | | - |
---|
680 | | - set_bit(SDATA_STATE_RUNNING, &sdata->state); |
---|
681 | | - |
---|
682 | | - switch (sdata->vif.type) { |
---|
683 | | - case NL80211_IFTYPE_WDS: |
---|
684 | | - /* Create STA entry for the WDS peer */ |
---|
685 | | - sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr, |
---|
686 | | - GFP_KERNEL); |
---|
687 | | - if (!sta) { |
---|
688 | | - res = -ENOMEM; |
---|
689 | | - goto err_del_interface; |
---|
690 | | - } |
---|
691 | | - |
---|
692 | | - sta_info_pre_move_state(sta, IEEE80211_STA_AUTH); |
---|
693 | | - sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC); |
---|
694 | | - sta_info_pre_move_state(sta, IEEE80211_STA_AUTHORIZED); |
---|
695 | | - |
---|
696 | | - res = sta_info_insert(sta); |
---|
697 | | - if (res) { |
---|
698 | | - /* STA has been freed */ |
---|
699 | | - goto err_del_interface; |
---|
700 | | - } |
---|
701 | | - |
---|
702 | | - rate_control_rate_init(sta); |
---|
703 | | - netif_carrier_on(dev); |
---|
704 | | - break; |
---|
705 | | - case NL80211_IFTYPE_P2P_DEVICE: |
---|
706 | | - rcu_assign_pointer(local->p2p_sdata, sdata); |
---|
707 | | - break; |
---|
708 | | - case NL80211_IFTYPE_MONITOR: |
---|
709 | | - if (sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES) |
---|
710 | | - break; |
---|
711 | | - list_add_tail_rcu(&sdata->u.mntr.list, &local->mon_list); |
---|
712 | | - break; |
---|
713 | | - default: |
---|
714 | | - break; |
---|
715 | | - } |
---|
716 | | - |
---|
717 | | - /* |
---|
718 | | - * set_multicast_list will be invoked by the networking core |
---|
719 | | - * which will check whether any increments here were done in |
---|
720 | | - * error and sync them down to the hardware as filter flags. |
---|
721 | | - */ |
---|
722 | | - if (sdata->flags & IEEE80211_SDATA_ALLMULTI) |
---|
723 | | - atomic_inc(&local->iff_allmultis); |
---|
724 | | - |
---|
725 | | - if (coming_up) |
---|
726 | | - local->open_count++; |
---|
727 | | - |
---|
728 | | - if (hw_reconf_flags) |
---|
729 | | - ieee80211_hw_config(local, hw_reconf_flags); |
---|
730 | | - |
---|
731 | | - ieee80211_recalc_ps(local); |
---|
732 | | - |
---|
733 | | - if (sdata->vif.type == NL80211_IFTYPE_MONITOR || |
---|
734 | | - sdata->vif.type == NL80211_IFTYPE_AP_VLAN || |
---|
735 | | - local->ops->wake_tx_queue) { |
---|
736 | | - /* XXX: for AP_VLAN, actually track AP queues */ |
---|
737 | | - if (dev) |
---|
738 | | - netif_tx_start_all_queues(dev); |
---|
739 | | - } else if (dev) { |
---|
740 | | - unsigned long flags; |
---|
741 | | - int n_acs = IEEE80211_NUM_ACS; |
---|
742 | | - int ac; |
---|
743 | | - |
---|
744 | | - if (local->hw.queues < IEEE80211_NUM_ACS) |
---|
745 | | - n_acs = 1; |
---|
746 | | - |
---|
747 | | - spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
---|
748 | | - if (sdata->vif.cab_queue == IEEE80211_INVAL_HW_QUEUE || |
---|
749 | | - (local->queue_stop_reasons[sdata->vif.cab_queue] == 0 && |
---|
750 | | - skb_queue_empty(&local->pending[sdata->vif.cab_queue]))) { |
---|
751 | | - for (ac = 0; ac < n_acs; ac++) { |
---|
752 | | - int ac_queue = sdata->vif.hw_queue[ac]; |
---|
753 | | - |
---|
754 | | - if (local->queue_stop_reasons[ac_queue] == 0 && |
---|
755 | | - skb_queue_empty(&local->pending[ac_queue])) |
---|
756 | | - netif_start_subqueue(dev, ac); |
---|
757 | | - } |
---|
758 | | - } |
---|
759 | | - spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
---|
760 | | - } |
---|
761 | | - |
---|
762 | | - return 0; |
---|
763 | | - err_del_interface: |
---|
764 | | - drv_remove_interface(local, sdata); |
---|
765 | | - err_stop: |
---|
766 | | - if (!local->open_count) |
---|
767 | | - drv_stop(local); |
---|
768 | | - err_del_bss: |
---|
769 | | - sdata->bss = NULL; |
---|
770 | | - if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) { |
---|
771 | | - mutex_lock(&local->mtx); |
---|
772 | | - list_del(&sdata->u.vlan.list); |
---|
773 | | - mutex_unlock(&local->mtx); |
---|
774 | | - } |
---|
775 | | - /* might already be clear but that doesn't matter */ |
---|
776 | | - clear_bit(SDATA_STATE_RUNNING, &sdata->state); |
---|
777 | | - return res; |
---|
778 | | -} |
---|
779 | | - |
---|
780 | 351 | static int ieee80211_open(struct net_device *dev) |
---|
781 | 352 | { |
---|
782 | 353 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
---|
.. | .. |
---|
826 | 397 | break; |
---|
827 | 398 | case NL80211_IFTYPE_ADHOC: |
---|
828 | 399 | ieee80211_ibss_stop(sdata); |
---|
829 | | - break; |
---|
830 | | - case NL80211_IFTYPE_AP: |
---|
831 | | - cancel_work_sync(&sdata->u.ap.request_smps_work); |
---|
832 | 400 | break; |
---|
833 | 401 | case NL80211_IFTYPE_MONITOR: |
---|
834 | 402 | if (sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES) |
---|
.. | .. |
---|
977 | 545 | case NL80211_IFTYPE_P2P_DEVICE: |
---|
978 | 546 | /* relies on synchronize_rcu() below */ |
---|
979 | 547 | RCU_INIT_POINTER(local->p2p_sdata, NULL); |
---|
980 | | - /* fall through */ |
---|
| 548 | + fallthrough; |
---|
981 | 549 | default: |
---|
982 | 550 | cancel_work_sync(&sdata->work); |
---|
983 | 551 | /* |
---|
.. | .. |
---|
1047 | 615 | if (!(sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE)) |
---|
1048 | 616 | break; |
---|
1049 | 617 | |
---|
1050 | | - /* fall through */ |
---|
| 618 | + fallthrough; |
---|
1051 | 619 | default: |
---|
1052 | 620 | if (going_down) |
---|
1053 | 621 | drv_remove_interface(local, sdata); |
---|
.. | .. |
---|
1129 | 697 | |
---|
1130 | 698 | static u16 ieee80211_netdev_select_queue(struct net_device *dev, |
---|
1131 | 699 | struct sk_buff *skb, |
---|
1132 | | - struct net_device *sb_dev, |
---|
1133 | | - select_queue_fallback_t fallback) |
---|
| 700 | + struct net_device *sb_dev) |
---|
1134 | 701 | { |
---|
1135 | 702 | return ieee80211_select_queue(IEEE80211_DEV_TO_SUB_IF(dev), skb); |
---|
1136 | 703 | } |
---|
.. | .. |
---|
1138 | 705 | static void |
---|
1139 | 706 | ieee80211_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats) |
---|
1140 | 707 | { |
---|
1141 | | - int i; |
---|
1142 | | - |
---|
1143 | | - for_each_possible_cpu(i) { |
---|
1144 | | - const struct pcpu_sw_netstats *tstats; |
---|
1145 | | - u64 rx_packets, rx_bytes, tx_packets, tx_bytes; |
---|
1146 | | - unsigned int start; |
---|
1147 | | - |
---|
1148 | | - tstats = per_cpu_ptr(dev->tstats, i); |
---|
1149 | | - |
---|
1150 | | - do { |
---|
1151 | | - start = u64_stats_fetch_begin_irq(&tstats->syncp); |
---|
1152 | | - rx_packets = tstats->rx_packets; |
---|
1153 | | - tx_packets = tstats->tx_packets; |
---|
1154 | | - rx_bytes = tstats->rx_bytes; |
---|
1155 | | - tx_bytes = tstats->tx_bytes; |
---|
1156 | | - } while (u64_stats_fetch_retry_irq(&tstats->syncp, start)); |
---|
1157 | | - |
---|
1158 | | - stats->rx_packets += rx_packets; |
---|
1159 | | - stats->tx_packets += tx_packets; |
---|
1160 | | - stats->rx_bytes += rx_bytes; |
---|
1161 | | - stats->tx_bytes += tx_bytes; |
---|
1162 | | - } |
---|
| 708 | + dev_fetch_sw_netstats(stats, dev->tstats); |
---|
1163 | 709 | } |
---|
1164 | 710 | |
---|
1165 | 711 | static const struct net_device_ops ieee80211_dataif_ops = { |
---|
.. | .. |
---|
1175 | 721 | |
---|
1176 | 722 | static u16 ieee80211_monitor_select_queue(struct net_device *dev, |
---|
1177 | 723 | struct sk_buff *skb, |
---|
1178 | | - struct net_device *sb_dev, |
---|
1179 | | - select_queue_fallback_t fallback) |
---|
| 724 | + struct net_device *sb_dev) |
---|
1180 | 725 | { |
---|
1181 | 726 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
---|
1182 | 727 | struct ieee80211_local *local = sdata->local; |
---|
| 728 | + struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
---|
1183 | 729 | struct ieee80211_hdr *hdr; |
---|
1184 | | - struct ieee80211_radiotap_header *rtap = (void *)skb->data; |
---|
| 730 | + int len_rthdr; |
---|
1185 | 731 | |
---|
1186 | 732 | if (local->hw.queues < IEEE80211_NUM_ACS) |
---|
1187 | 733 | return 0; |
---|
1188 | 734 | |
---|
1189 | | - if (skb->len < 4 || |
---|
1190 | | - skb->len < le16_to_cpu(rtap->it_len) + 2 /* frame control */) |
---|
| 735 | + /* reset flags and info before parsing radiotap header */ |
---|
| 736 | + memset(info, 0, sizeof(*info)); |
---|
| 737 | + |
---|
| 738 | + if (!ieee80211_parse_tx_radiotap(skb, dev)) |
---|
1191 | 739 | return 0; /* doesn't matter, frame will be dropped */ |
---|
1192 | 740 | |
---|
1193 | | - hdr = (void *)((u8 *)skb->data + le16_to_cpu(rtap->it_len)); |
---|
| 741 | + len_rthdr = ieee80211_get_radiotap_len(skb->data); |
---|
| 742 | + hdr = (struct ieee80211_hdr *)(skb->data + len_rthdr); |
---|
| 743 | + if (skb->len < len_rthdr + 2 || |
---|
| 744 | + skb->len < len_rthdr + ieee80211_hdrlen(hdr->frame_control)) |
---|
| 745 | + return 0; /* doesn't matter, frame will be dropped */ |
---|
1194 | 746 | |
---|
1195 | 747 | return ieee80211_select_queue_80211(sdata, skb, hdr); |
---|
1196 | 748 | } |
---|
.. | .. |
---|
1205 | 757 | .ndo_select_queue = ieee80211_monitor_select_queue, |
---|
1206 | 758 | .ndo_get_stats64 = ieee80211_get_stats64, |
---|
1207 | 759 | }; |
---|
| 760 | + |
---|
| 761 | +static const struct net_device_ops ieee80211_dataif_8023_ops = { |
---|
| 762 | + .ndo_open = ieee80211_open, |
---|
| 763 | + .ndo_stop = ieee80211_stop, |
---|
| 764 | + .ndo_uninit = ieee80211_uninit, |
---|
| 765 | + .ndo_start_xmit = ieee80211_subif_start_xmit_8023, |
---|
| 766 | + .ndo_set_rx_mode = ieee80211_set_multicast_list, |
---|
| 767 | + .ndo_set_mac_address = ieee80211_change_mac, |
---|
| 768 | + .ndo_select_queue = ieee80211_netdev_select_queue, |
---|
| 769 | + .ndo_get_stats64 = ieee80211_get_stats64, |
---|
| 770 | +}; |
---|
| 771 | + |
---|
| 772 | +static bool ieee80211_iftype_supports_encap_offload(enum nl80211_iftype iftype) |
---|
| 773 | +{ |
---|
| 774 | + switch (iftype) { |
---|
| 775 | + /* P2P GO and client are mapped to AP/STATION types */ |
---|
| 776 | + case NL80211_IFTYPE_AP: |
---|
| 777 | + case NL80211_IFTYPE_STATION: |
---|
| 778 | + return true; |
---|
| 779 | + default: |
---|
| 780 | + return false; |
---|
| 781 | + } |
---|
| 782 | +} |
---|
| 783 | + |
---|
| 784 | +static bool ieee80211_set_sdata_offload_flags(struct ieee80211_sub_if_data *sdata) |
---|
| 785 | +{ |
---|
| 786 | + struct ieee80211_local *local = sdata->local; |
---|
| 787 | + u32 flags; |
---|
| 788 | + |
---|
| 789 | + flags = sdata->vif.offload_flags; |
---|
| 790 | + |
---|
| 791 | + if (ieee80211_hw_check(&local->hw, SUPPORTS_TX_ENCAP_OFFLOAD) && |
---|
| 792 | + ieee80211_iftype_supports_encap_offload(sdata->vif.type)) { |
---|
| 793 | + flags |= IEEE80211_OFFLOAD_ENCAP_ENABLED; |
---|
| 794 | + |
---|
| 795 | + if (!ieee80211_hw_check(&local->hw, SUPPORTS_TX_FRAG) && |
---|
| 796 | + local->hw.wiphy->frag_threshold != (u32)-1) |
---|
| 797 | + flags &= ~IEEE80211_OFFLOAD_ENCAP_ENABLED; |
---|
| 798 | + |
---|
| 799 | + if (local->monitors) |
---|
| 800 | + flags &= ~IEEE80211_OFFLOAD_ENCAP_ENABLED; |
---|
| 801 | + } else { |
---|
| 802 | + flags &= ~IEEE80211_OFFLOAD_ENCAP_ENABLED; |
---|
| 803 | + } |
---|
| 804 | + |
---|
| 805 | + if (sdata->vif.offload_flags == flags) |
---|
| 806 | + return false; |
---|
| 807 | + |
---|
| 808 | + sdata->vif.offload_flags = flags; |
---|
| 809 | + return true; |
---|
| 810 | +} |
---|
| 811 | + |
---|
| 812 | +static void ieee80211_set_vif_encap_ops(struct ieee80211_sub_if_data *sdata) |
---|
| 813 | +{ |
---|
| 814 | + struct ieee80211_local *local = sdata->local; |
---|
| 815 | + struct ieee80211_sub_if_data *bss = sdata; |
---|
| 816 | + bool enabled; |
---|
| 817 | + |
---|
| 818 | + if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) { |
---|
| 819 | + if (!sdata->bss) |
---|
| 820 | + return; |
---|
| 821 | + |
---|
| 822 | + bss = container_of(sdata->bss, struct ieee80211_sub_if_data, u.ap); |
---|
| 823 | + } |
---|
| 824 | + |
---|
| 825 | + if (!ieee80211_hw_check(&local->hw, SUPPORTS_TX_ENCAP_OFFLOAD) || |
---|
| 826 | + !ieee80211_iftype_supports_encap_offload(bss->vif.type)) |
---|
| 827 | + return; |
---|
| 828 | + |
---|
| 829 | + enabled = bss->vif.offload_flags & IEEE80211_OFFLOAD_ENCAP_ENABLED; |
---|
| 830 | + if (sdata->wdev.use_4addr && |
---|
| 831 | + !(bss->vif.offload_flags & IEEE80211_OFFLOAD_ENCAP_4ADDR)) |
---|
| 832 | + enabled = false; |
---|
| 833 | + |
---|
| 834 | + sdata->dev->netdev_ops = enabled ? &ieee80211_dataif_8023_ops : |
---|
| 835 | + &ieee80211_dataif_ops; |
---|
| 836 | +} |
---|
| 837 | + |
---|
| 838 | +static void ieee80211_recalc_sdata_offload(struct ieee80211_sub_if_data *sdata) |
---|
| 839 | +{ |
---|
| 840 | + struct ieee80211_local *local = sdata->local; |
---|
| 841 | + struct ieee80211_sub_if_data *vsdata; |
---|
| 842 | + |
---|
| 843 | + if (ieee80211_set_sdata_offload_flags(sdata)) { |
---|
| 844 | + drv_update_vif_offload(local, sdata); |
---|
| 845 | + ieee80211_set_vif_encap_ops(sdata); |
---|
| 846 | + } |
---|
| 847 | + |
---|
| 848 | + list_for_each_entry(vsdata, &local->interfaces, list) { |
---|
| 849 | + if (vsdata->vif.type != NL80211_IFTYPE_AP_VLAN || |
---|
| 850 | + vsdata->bss != &sdata->u.ap) |
---|
| 851 | + continue; |
---|
| 852 | + |
---|
| 853 | + ieee80211_set_vif_encap_ops(vsdata); |
---|
| 854 | + } |
---|
| 855 | +} |
---|
| 856 | + |
---|
| 857 | +void ieee80211_recalc_offload(struct ieee80211_local *local) |
---|
| 858 | +{ |
---|
| 859 | + struct ieee80211_sub_if_data *sdata; |
---|
| 860 | + |
---|
| 861 | + if (!ieee80211_hw_check(&local->hw, SUPPORTS_TX_ENCAP_OFFLOAD)) |
---|
| 862 | + return; |
---|
| 863 | + |
---|
| 864 | + mutex_lock(&local->iflist_mtx); |
---|
| 865 | + |
---|
| 866 | + list_for_each_entry(sdata, &local->interfaces, list) { |
---|
| 867 | + if (!ieee80211_sdata_running(sdata)) |
---|
| 868 | + continue; |
---|
| 869 | + |
---|
| 870 | + ieee80211_recalc_sdata_offload(sdata); |
---|
| 871 | + } |
---|
| 872 | + |
---|
| 873 | + mutex_unlock(&local->iflist_mtx); |
---|
| 874 | +} |
---|
| 875 | + |
---|
| 876 | +void ieee80211_adjust_monitor_flags(struct ieee80211_sub_if_data *sdata, |
---|
| 877 | + const int offset) |
---|
| 878 | +{ |
---|
| 879 | + struct ieee80211_local *local = sdata->local; |
---|
| 880 | + u32 flags = sdata->u.mntr.flags; |
---|
| 881 | + |
---|
| 882 | +#define ADJUST(_f, _s) do { \ |
---|
| 883 | + if (flags & MONITOR_FLAG_##_f) \ |
---|
| 884 | + local->fif_##_s += offset; \ |
---|
| 885 | + } while (0) |
---|
| 886 | + |
---|
| 887 | + ADJUST(FCSFAIL, fcsfail); |
---|
| 888 | + ADJUST(PLCPFAIL, plcpfail); |
---|
| 889 | + ADJUST(CONTROL, control); |
---|
| 890 | + ADJUST(CONTROL, pspoll); |
---|
| 891 | + ADJUST(OTHER_BSS, other_bss); |
---|
| 892 | + |
---|
| 893 | +#undef ADJUST |
---|
| 894 | +} |
---|
| 895 | + |
---|
| 896 | +static void ieee80211_set_default_queues(struct ieee80211_sub_if_data *sdata) |
---|
| 897 | +{ |
---|
| 898 | + struct ieee80211_local *local = sdata->local; |
---|
| 899 | + int i; |
---|
| 900 | + |
---|
| 901 | + for (i = 0; i < IEEE80211_NUM_ACS; i++) { |
---|
| 902 | + if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL)) |
---|
| 903 | + sdata->vif.hw_queue[i] = IEEE80211_INVAL_HW_QUEUE; |
---|
| 904 | + else if (local->hw.queues >= IEEE80211_NUM_ACS) |
---|
| 905 | + sdata->vif.hw_queue[i] = i; |
---|
| 906 | + else |
---|
| 907 | + sdata->vif.hw_queue[i] = 0; |
---|
| 908 | + } |
---|
| 909 | + sdata->vif.cab_queue = IEEE80211_INVAL_HW_QUEUE; |
---|
| 910 | +} |
---|
| 911 | + |
---|
| 912 | +int ieee80211_add_virtual_monitor(struct ieee80211_local *local) |
---|
| 913 | +{ |
---|
| 914 | + struct ieee80211_sub_if_data *sdata; |
---|
| 915 | + int ret; |
---|
| 916 | + |
---|
| 917 | + if (!ieee80211_hw_check(&local->hw, WANT_MONITOR_VIF)) |
---|
| 918 | + return 0; |
---|
| 919 | + |
---|
| 920 | + ASSERT_RTNL(); |
---|
| 921 | + |
---|
| 922 | + if (local->monitor_sdata) |
---|
| 923 | + return 0; |
---|
| 924 | + |
---|
| 925 | + sdata = kzalloc(sizeof(*sdata) + local->hw.vif_data_size, GFP_KERNEL); |
---|
| 926 | + if (!sdata) |
---|
| 927 | + return -ENOMEM; |
---|
| 928 | + |
---|
| 929 | + /* set up data */ |
---|
| 930 | + sdata->local = local; |
---|
| 931 | + sdata->vif.type = NL80211_IFTYPE_MONITOR; |
---|
| 932 | + snprintf(sdata->name, IFNAMSIZ, "%s-monitor", |
---|
| 933 | + wiphy_name(local->hw.wiphy)); |
---|
| 934 | + sdata->wdev.iftype = NL80211_IFTYPE_MONITOR; |
---|
| 935 | + |
---|
| 936 | + sdata->encrypt_headroom = IEEE80211_ENCRYPT_HEADROOM; |
---|
| 937 | + |
---|
| 938 | + ieee80211_set_default_queues(sdata); |
---|
| 939 | + |
---|
| 940 | + ret = drv_add_interface(local, sdata); |
---|
| 941 | + if (WARN_ON(ret)) { |
---|
| 942 | + /* ok .. stupid driver, it asked for this! */ |
---|
| 943 | + kfree(sdata); |
---|
| 944 | + return ret; |
---|
| 945 | + } |
---|
| 946 | + |
---|
| 947 | + set_bit(SDATA_STATE_RUNNING, &sdata->state); |
---|
| 948 | + |
---|
| 949 | + ret = ieee80211_check_queues(sdata, NL80211_IFTYPE_MONITOR); |
---|
| 950 | + if (ret) { |
---|
| 951 | + kfree(sdata); |
---|
| 952 | + return ret; |
---|
| 953 | + } |
---|
| 954 | + |
---|
| 955 | + mutex_lock(&local->iflist_mtx); |
---|
| 956 | + rcu_assign_pointer(local->monitor_sdata, sdata); |
---|
| 957 | + mutex_unlock(&local->iflist_mtx); |
---|
| 958 | + |
---|
| 959 | + mutex_lock(&local->mtx); |
---|
| 960 | + ret = ieee80211_vif_use_channel(sdata, &local->monitor_chandef, |
---|
| 961 | + IEEE80211_CHANCTX_EXCLUSIVE); |
---|
| 962 | + mutex_unlock(&local->mtx); |
---|
| 963 | + if (ret) { |
---|
| 964 | + mutex_lock(&local->iflist_mtx); |
---|
| 965 | + RCU_INIT_POINTER(local->monitor_sdata, NULL); |
---|
| 966 | + mutex_unlock(&local->iflist_mtx); |
---|
| 967 | + synchronize_net(); |
---|
| 968 | + drv_remove_interface(local, sdata); |
---|
| 969 | + kfree(sdata); |
---|
| 970 | + return ret; |
---|
| 971 | + } |
---|
| 972 | + |
---|
| 973 | + skb_queue_head_init(&sdata->skb_queue); |
---|
| 974 | + INIT_WORK(&sdata->work, ieee80211_iface_work); |
---|
| 975 | + |
---|
| 976 | + return 0; |
---|
| 977 | +} |
---|
| 978 | + |
---|
| 979 | +void ieee80211_del_virtual_monitor(struct ieee80211_local *local) |
---|
| 980 | +{ |
---|
| 981 | + struct ieee80211_sub_if_data *sdata; |
---|
| 982 | + |
---|
| 983 | + if (!ieee80211_hw_check(&local->hw, WANT_MONITOR_VIF)) |
---|
| 984 | + return; |
---|
| 985 | + |
---|
| 986 | + ASSERT_RTNL(); |
---|
| 987 | + |
---|
| 988 | + mutex_lock(&local->iflist_mtx); |
---|
| 989 | + |
---|
| 990 | + sdata = rcu_dereference_protected(local->monitor_sdata, |
---|
| 991 | + lockdep_is_held(&local->iflist_mtx)); |
---|
| 992 | + if (!sdata) { |
---|
| 993 | + mutex_unlock(&local->iflist_mtx); |
---|
| 994 | + return; |
---|
| 995 | + } |
---|
| 996 | + |
---|
| 997 | + RCU_INIT_POINTER(local->monitor_sdata, NULL); |
---|
| 998 | + mutex_unlock(&local->iflist_mtx); |
---|
| 999 | + |
---|
| 1000 | + synchronize_net(); |
---|
| 1001 | + |
---|
| 1002 | + mutex_lock(&local->mtx); |
---|
| 1003 | + ieee80211_vif_release_channel(sdata); |
---|
| 1004 | + mutex_unlock(&local->mtx); |
---|
| 1005 | + |
---|
| 1006 | + drv_remove_interface(local, sdata); |
---|
| 1007 | + |
---|
| 1008 | + kfree(sdata); |
---|
| 1009 | +} |
---|
| 1010 | + |
---|
| 1011 | +/* |
---|
| 1012 | + * NOTE: Be very careful when changing this function, it must NOT return |
---|
| 1013 | + * an error on interface type changes that have been pre-checked, so most |
---|
| 1014 | + * checks should be in ieee80211_check_concurrent_iface. |
---|
| 1015 | + */ |
---|
| 1016 | +int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up) |
---|
| 1017 | +{ |
---|
| 1018 | + struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); |
---|
| 1019 | + struct net_device *dev = wdev->netdev; |
---|
| 1020 | + struct ieee80211_local *local = sdata->local; |
---|
| 1021 | + struct sta_info *sta; |
---|
| 1022 | + u32 changed = 0; |
---|
| 1023 | + int res; |
---|
| 1024 | + u32 hw_reconf_flags = 0; |
---|
| 1025 | + |
---|
| 1026 | + switch (sdata->vif.type) { |
---|
| 1027 | + case NL80211_IFTYPE_WDS: |
---|
| 1028 | + if (!is_valid_ether_addr(sdata->u.wds.remote_addr)) |
---|
| 1029 | + return -ENOLINK; |
---|
| 1030 | + break; |
---|
| 1031 | + case NL80211_IFTYPE_AP_VLAN: { |
---|
| 1032 | + struct ieee80211_sub_if_data *master; |
---|
| 1033 | + |
---|
| 1034 | + if (!sdata->bss) |
---|
| 1035 | + return -ENOLINK; |
---|
| 1036 | + |
---|
| 1037 | + mutex_lock(&local->mtx); |
---|
| 1038 | + list_add(&sdata->u.vlan.list, &sdata->bss->vlans); |
---|
| 1039 | + mutex_unlock(&local->mtx); |
---|
| 1040 | + |
---|
| 1041 | + master = container_of(sdata->bss, |
---|
| 1042 | + struct ieee80211_sub_if_data, u.ap); |
---|
| 1043 | + sdata->control_port_protocol = |
---|
| 1044 | + master->control_port_protocol; |
---|
| 1045 | + sdata->control_port_no_encrypt = |
---|
| 1046 | + master->control_port_no_encrypt; |
---|
| 1047 | + sdata->control_port_over_nl80211 = |
---|
| 1048 | + master->control_port_over_nl80211; |
---|
| 1049 | + sdata->control_port_no_preauth = |
---|
| 1050 | + master->control_port_no_preauth; |
---|
| 1051 | + sdata->vif.cab_queue = master->vif.cab_queue; |
---|
| 1052 | + memcpy(sdata->vif.hw_queue, master->vif.hw_queue, |
---|
| 1053 | + sizeof(sdata->vif.hw_queue)); |
---|
| 1054 | + sdata->vif.bss_conf.chandef = master->vif.bss_conf.chandef; |
---|
| 1055 | + |
---|
| 1056 | + mutex_lock(&local->key_mtx); |
---|
| 1057 | + sdata->crypto_tx_tailroom_needed_cnt += |
---|
| 1058 | + master->crypto_tx_tailroom_needed_cnt; |
---|
| 1059 | + mutex_unlock(&local->key_mtx); |
---|
| 1060 | + |
---|
| 1061 | + break; |
---|
| 1062 | + } |
---|
| 1063 | + case NL80211_IFTYPE_AP: |
---|
| 1064 | + sdata->bss = &sdata->u.ap; |
---|
| 1065 | + break; |
---|
| 1066 | + case NL80211_IFTYPE_MESH_POINT: |
---|
| 1067 | + case NL80211_IFTYPE_STATION: |
---|
| 1068 | + case NL80211_IFTYPE_MONITOR: |
---|
| 1069 | + case NL80211_IFTYPE_ADHOC: |
---|
| 1070 | + case NL80211_IFTYPE_P2P_DEVICE: |
---|
| 1071 | + case NL80211_IFTYPE_OCB: |
---|
| 1072 | + case NL80211_IFTYPE_NAN: |
---|
| 1073 | + /* no special treatment */ |
---|
| 1074 | + break; |
---|
| 1075 | + case NL80211_IFTYPE_UNSPECIFIED: |
---|
| 1076 | + case NUM_NL80211_IFTYPES: |
---|
| 1077 | + case NL80211_IFTYPE_P2P_CLIENT: |
---|
| 1078 | + case NL80211_IFTYPE_P2P_GO: |
---|
| 1079 | + /* cannot happen */ |
---|
| 1080 | + WARN_ON(1); |
---|
| 1081 | + break; |
---|
| 1082 | + } |
---|
| 1083 | + |
---|
| 1084 | + if (local->open_count == 0) { |
---|
| 1085 | + res = drv_start(local); |
---|
| 1086 | + if (res) |
---|
| 1087 | + goto err_del_bss; |
---|
| 1088 | + /* we're brought up, everything changes */ |
---|
| 1089 | + hw_reconf_flags = ~0; |
---|
| 1090 | + ieee80211_led_radio(local, true); |
---|
| 1091 | + ieee80211_mod_tpt_led_trig(local, |
---|
| 1092 | + IEEE80211_TPT_LEDTRIG_FL_RADIO, 0); |
---|
| 1093 | + } |
---|
| 1094 | + |
---|
| 1095 | + /* |
---|
| 1096 | + * Copy the hopefully now-present MAC address to |
---|
| 1097 | + * this interface, if it has the special null one. |
---|
| 1098 | + */ |
---|
| 1099 | + if (dev && is_zero_ether_addr(dev->dev_addr)) { |
---|
| 1100 | + memcpy(dev->dev_addr, |
---|
| 1101 | + local->hw.wiphy->perm_addr, |
---|
| 1102 | + ETH_ALEN); |
---|
| 1103 | + memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN); |
---|
| 1104 | + |
---|
| 1105 | + if (!is_valid_ether_addr(dev->dev_addr)) { |
---|
| 1106 | + res = -EADDRNOTAVAIL; |
---|
| 1107 | + goto err_stop; |
---|
| 1108 | + } |
---|
| 1109 | + } |
---|
| 1110 | + |
---|
| 1111 | + switch (sdata->vif.type) { |
---|
| 1112 | + case NL80211_IFTYPE_AP_VLAN: |
---|
| 1113 | + /* no need to tell driver, but set carrier and chanctx */ |
---|
| 1114 | + if (rtnl_dereference(sdata->bss->beacon)) { |
---|
| 1115 | + ieee80211_vif_vlan_copy_chanctx(sdata); |
---|
| 1116 | + netif_carrier_on(dev); |
---|
| 1117 | + ieee80211_set_vif_encap_ops(sdata); |
---|
| 1118 | + } else { |
---|
| 1119 | + netif_carrier_off(dev); |
---|
| 1120 | + } |
---|
| 1121 | + break; |
---|
| 1122 | + case NL80211_IFTYPE_MONITOR: |
---|
| 1123 | + if (sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES) { |
---|
| 1124 | + local->cooked_mntrs++; |
---|
| 1125 | + break; |
---|
| 1126 | + } |
---|
| 1127 | + |
---|
| 1128 | + if (sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE) { |
---|
| 1129 | + res = drv_add_interface(local, sdata); |
---|
| 1130 | + if (res) |
---|
| 1131 | + goto err_stop; |
---|
| 1132 | + } else if (local->monitors == 0 && local->open_count == 0) { |
---|
| 1133 | + res = ieee80211_add_virtual_monitor(local); |
---|
| 1134 | + if (res) |
---|
| 1135 | + goto err_stop; |
---|
| 1136 | + } |
---|
| 1137 | + |
---|
| 1138 | + /* must be before the call to ieee80211_configure_filter */ |
---|
| 1139 | + local->monitors++; |
---|
| 1140 | + if (local->monitors == 1) { |
---|
| 1141 | + local->hw.conf.flags |= IEEE80211_CONF_MONITOR; |
---|
| 1142 | + hw_reconf_flags |= IEEE80211_CONF_CHANGE_MONITOR; |
---|
| 1143 | + } |
---|
| 1144 | + |
---|
| 1145 | + ieee80211_adjust_monitor_flags(sdata, 1); |
---|
| 1146 | + ieee80211_configure_filter(local); |
---|
| 1147 | + ieee80211_recalc_offload(local); |
---|
| 1148 | + mutex_lock(&local->mtx); |
---|
| 1149 | + ieee80211_recalc_idle(local); |
---|
| 1150 | + mutex_unlock(&local->mtx); |
---|
| 1151 | + |
---|
| 1152 | + netif_carrier_on(dev); |
---|
| 1153 | + break; |
---|
| 1154 | + default: |
---|
| 1155 | + if (coming_up) { |
---|
| 1156 | + ieee80211_del_virtual_monitor(local); |
---|
| 1157 | + ieee80211_set_sdata_offload_flags(sdata); |
---|
| 1158 | + |
---|
| 1159 | + res = drv_add_interface(local, sdata); |
---|
| 1160 | + if (res) |
---|
| 1161 | + goto err_stop; |
---|
| 1162 | + |
---|
| 1163 | + ieee80211_set_vif_encap_ops(sdata); |
---|
| 1164 | + res = ieee80211_check_queues(sdata, |
---|
| 1165 | + ieee80211_vif_type_p2p(&sdata->vif)); |
---|
| 1166 | + if (res) |
---|
| 1167 | + goto err_del_interface; |
---|
| 1168 | + } |
---|
| 1169 | + |
---|
| 1170 | + if (sdata->vif.type == NL80211_IFTYPE_AP) { |
---|
| 1171 | + local->fif_pspoll++; |
---|
| 1172 | + local->fif_probe_req++; |
---|
| 1173 | + |
---|
| 1174 | + ieee80211_configure_filter(local); |
---|
| 1175 | + } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) { |
---|
| 1176 | + local->fif_probe_req++; |
---|
| 1177 | + } |
---|
| 1178 | + |
---|
| 1179 | + if (sdata->vif.probe_req_reg) |
---|
| 1180 | + drv_config_iface_filter(local, sdata, |
---|
| 1181 | + FIF_PROBE_REQ, |
---|
| 1182 | + FIF_PROBE_REQ); |
---|
| 1183 | + |
---|
| 1184 | + if (sdata->vif.type != NL80211_IFTYPE_P2P_DEVICE && |
---|
| 1185 | + sdata->vif.type != NL80211_IFTYPE_NAN) |
---|
| 1186 | + changed |= ieee80211_reset_erp_info(sdata); |
---|
| 1187 | + ieee80211_bss_info_change_notify(sdata, changed); |
---|
| 1188 | + |
---|
| 1189 | + switch (sdata->vif.type) { |
---|
| 1190 | + case NL80211_IFTYPE_STATION: |
---|
| 1191 | + case NL80211_IFTYPE_ADHOC: |
---|
| 1192 | + case NL80211_IFTYPE_AP: |
---|
| 1193 | + case NL80211_IFTYPE_MESH_POINT: |
---|
| 1194 | + case NL80211_IFTYPE_OCB: |
---|
| 1195 | + netif_carrier_off(dev); |
---|
| 1196 | + break; |
---|
| 1197 | + case NL80211_IFTYPE_WDS: |
---|
| 1198 | + case NL80211_IFTYPE_P2P_DEVICE: |
---|
| 1199 | + case NL80211_IFTYPE_NAN: |
---|
| 1200 | + break; |
---|
| 1201 | + default: |
---|
| 1202 | + /* not reached */ |
---|
| 1203 | + WARN_ON(1); |
---|
| 1204 | + } |
---|
| 1205 | + |
---|
| 1206 | + /* |
---|
| 1207 | + * Set default queue parameters so drivers don't |
---|
| 1208 | + * need to initialise the hardware if the hardware |
---|
| 1209 | + * doesn't start up with sane defaults. |
---|
| 1210 | + * Enable QoS for anything but station interfaces. |
---|
| 1211 | + */ |
---|
| 1212 | + ieee80211_set_wmm_default(sdata, true, |
---|
| 1213 | + sdata->vif.type != NL80211_IFTYPE_STATION); |
---|
| 1214 | + } |
---|
| 1215 | + |
---|
| 1216 | + set_bit(SDATA_STATE_RUNNING, &sdata->state); |
---|
| 1217 | + |
---|
| 1218 | + switch (sdata->vif.type) { |
---|
| 1219 | + case NL80211_IFTYPE_WDS: |
---|
| 1220 | + /* Create STA entry for the WDS peer */ |
---|
| 1221 | + sta = sta_info_alloc(sdata, sdata->u.wds.remote_addr, |
---|
| 1222 | + GFP_KERNEL); |
---|
| 1223 | + if (!sta) { |
---|
| 1224 | + res = -ENOMEM; |
---|
| 1225 | + goto err_del_interface; |
---|
| 1226 | + } |
---|
| 1227 | + |
---|
| 1228 | + sta_info_pre_move_state(sta, IEEE80211_STA_AUTH); |
---|
| 1229 | + sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC); |
---|
| 1230 | + sta_info_pre_move_state(sta, IEEE80211_STA_AUTHORIZED); |
---|
| 1231 | + |
---|
| 1232 | + res = sta_info_insert(sta); |
---|
| 1233 | + if (res) { |
---|
| 1234 | + /* STA has been freed */ |
---|
| 1235 | + goto err_del_interface; |
---|
| 1236 | + } |
---|
| 1237 | + |
---|
| 1238 | + rate_control_rate_init(sta); |
---|
| 1239 | + netif_carrier_on(dev); |
---|
| 1240 | + break; |
---|
| 1241 | + case NL80211_IFTYPE_P2P_DEVICE: |
---|
| 1242 | + rcu_assign_pointer(local->p2p_sdata, sdata); |
---|
| 1243 | + break; |
---|
| 1244 | + case NL80211_IFTYPE_MONITOR: |
---|
| 1245 | + if (sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES) |
---|
| 1246 | + break; |
---|
| 1247 | + list_add_tail_rcu(&sdata->u.mntr.list, &local->mon_list); |
---|
| 1248 | + break; |
---|
| 1249 | + default: |
---|
| 1250 | + break; |
---|
| 1251 | + } |
---|
| 1252 | + |
---|
| 1253 | + /* |
---|
| 1254 | + * set_multicast_list will be invoked by the networking core |
---|
| 1255 | + * which will check whether any increments here were done in |
---|
| 1256 | + * error and sync them down to the hardware as filter flags. |
---|
| 1257 | + */ |
---|
| 1258 | + if (sdata->flags & IEEE80211_SDATA_ALLMULTI) |
---|
| 1259 | + atomic_inc(&local->iff_allmultis); |
---|
| 1260 | + |
---|
| 1261 | + if (coming_up) |
---|
| 1262 | + local->open_count++; |
---|
| 1263 | + |
---|
| 1264 | + if (hw_reconf_flags) |
---|
| 1265 | + ieee80211_hw_config(local, hw_reconf_flags); |
---|
| 1266 | + |
---|
| 1267 | + ieee80211_recalc_ps(local); |
---|
| 1268 | + |
---|
| 1269 | + if (sdata->vif.type == NL80211_IFTYPE_MONITOR || |
---|
| 1270 | + sdata->vif.type == NL80211_IFTYPE_AP_VLAN || |
---|
| 1271 | + local->ops->wake_tx_queue) { |
---|
| 1272 | + /* XXX: for AP_VLAN, actually track AP queues */ |
---|
| 1273 | + if (dev) |
---|
| 1274 | + netif_tx_start_all_queues(dev); |
---|
| 1275 | + } else if (dev) { |
---|
| 1276 | + unsigned long flags; |
---|
| 1277 | + int n_acs = IEEE80211_NUM_ACS; |
---|
| 1278 | + int ac; |
---|
| 1279 | + |
---|
| 1280 | + if (local->hw.queues < IEEE80211_NUM_ACS) |
---|
| 1281 | + n_acs = 1; |
---|
| 1282 | + |
---|
| 1283 | + spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
---|
| 1284 | + if (sdata->vif.cab_queue == IEEE80211_INVAL_HW_QUEUE || |
---|
| 1285 | + (local->queue_stop_reasons[sdata->vif.cab_queue] == 0 && |
---|
| 1286 | + skb_queue_empty(&local->pending[sdata->vif.cab_queue]))) { |
---|
| 1287 | + for (ac = 0; ac < n_acs; ac++) { |
---|
| 1288 | + int ac_queue = sdata->vif.hw_queue[ac]; |
---|
| 1289 | + |
---|
| 1290 | + if (local->queue_stop_reasons[ac_queue] == 0 && |
---|
| 1291 | + skb_queue_empty(&local->pending[ac_queue])) |
---|
| 1292 | + netif_start_subqueue(dev, ac); |
---|
| 1293 | + } |
---|
| 1294 | + } |
---|
| 1295 | + spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
---|
| 1296 | + } |
---|
| 1297 | + |
---|
| 1298 | + return 0; |
---|
| 1299 | + err_del_interface: |
---|
| 1300 | + drv_remove_interface(local, sdata); |
---|
| 1301 | + err_stop: |
---|
| 1302 | + if (!local->open_count) |
---|
| 1303 | + drv_stop(local); |
---|
| 1304 | + err_del_bss: |
---|
| 1305 | + sdata->bss = NULL; |
---|
| 1306 | + if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) { |
---|
| 1307 | + mutex_lock(&local->mtx); |
---|
| 1308 | + list_del(&sdata->u.vlan.list); |
---|
| 1309 | + mutex_unlock(&local->mtx); |
---|
| 1310 | + } |
---|
| 1311 | + /* might already be clear but that doesn't matter */ |
---|
| 1312 | + clear_bit(SDATA_STATE_RUNNING, &sdata->state); |
---|
| 1313 | + return res; |
---|
| 1314 | +} |
---|
1208 | 1315 | |
---|
1209 | 1316 | static void ieee80211_if_free(struct net_device *dev) |
---|
1210 | 1317 | { |
---|
.. | .. |
---|
1303 | 1410 | WARN_ON(1); |
---|
1304 | 1411 | break; |
---|
1305 | 1412 | } |
---|
| 1413 | + } else if (ieee80211_is_ext(mgmt->frame_control)) { |
---|
| 1414 | + if (sdata->vif.type == NL80211_IFTYPE_STATION) |
---|
| 1415 | + ieee80211_sta_rx_queued_ext(sdata, skb); |
---|
| 1416 | + else |
---|
| 1417 | + WARN_ON(1); |
---|
1306 | 1418 | } else if (ieee80211_is_data_qos(mgmt->frame_control)) { |
---|
1307 | 1419 | struct ieee80211_hdr *hdr = (void *)mgmt; |
---|
1308 | 1420 | /* |
---|
.. | .. |
---|
1401 | 1513 | |
---|
1402 | 1514 | sdata->control_port_protocol = cpu_to_be16(ETH_P_PAE); |
---|
1403 | 1515 | sdata->control_port_no_encrypt = false; |
---|
| 1516 | + sdata->control_port_over_nl80211 = false; |
---|
| 1517 | + sdata->control_port_no_preauth = false; |
---|
1404 | 1518 | sdata->encrypt_headroom = IEEE80211_ENCRYPT_HEADROOM; |
---|
1405 | 1519 | sdata->vif.bss_conf.idle = true; |
---|
| 1520 | + sdata->vif.bss_conf.txpower = INT_MIN; /* unset */ |
---|
1406 | 1521 | |
---|
1407 | 1522 | sdata->noack_map = 0; |
---|
1408 | 1523 | |
---|
.. | .. |
---|
1424 | 1539 | type = NL80211_IFTYPE_AP; |
---|
1425 | 1540 | sdata->vif.type = type; |
---|
1426 | 1541 | sdata->vif.p2p = true; |
---|
1427 | | - /* fall through */ |
---|
| 1542 | + fallthrough; |
---|
1428 | 1543 | case NL80211_IFTYPE_AP: |
---|
1429 | 1544 | skb_queue_head_init(&sdata->u.ap.ps.bc_buf); |
---|
1430 | 1545 | INIT_LIST_HEAD(&sdata->u.ap.vlans); |
---|
1431 | | - INIT_WORK(&sdata->u.ap.request_smps_work, |
---|
1432 | | - ieee80211_request_smps_ap_work); |
---|
1433 | 1546 | sdata->vif.bss_conf.bssid = sdata->vif.addr; |
---|
1434 | | - sdata->u.ap.req_smps = IEEE80211_SMPS_OFF; |
---|
1435 | 1547 | break; |
---|
1436 | 1548 | case NL80211_IFTYPE_P2P_CLIENT: |
---|
1437 | 1549 | type = NL80211_IFTYPE_STATION; |
---|
1438 | 1550 | sdata->vif.type = type; |
---|
1439 | 1551 | sdata->vif.p2p = true; |
---|
1440 | | - /* fall through */ |
---|
| 1552 | + fallthrough; |
---|
1441 | 1553 | case NL80211_IFTYPE_STATION: |
---|
1442 | 1554 | sdata->vif.bss_conf.bssid = sdata->u.mgd.bssid; |
---|
1443 | 1555 | ieee80211_sta_setup_sdata(sdata); |
---|
.. | .. |
---|
1546 | 1658 | |
---|
1547 | 1659 | ieee80211_teardown_sdata(sdata); |
---|
1548 | 1660 | |
---|
| 1661 | + ieee80211_set_sdata_offload_flags(sdata); |
---|
1549 | 1662 | ret = drv_change_interface(local, sdata, internal_type, p2p); |
---|
1550 | 1663 | if (ret) |
---|
1551 | 1664 | type = ieee80211_vif_type_p2p(&sdata->vif); |
---|
.. | .. |
---|
1558 | 1671 | ieee80211_check_queues(sdata, type); |
---|
1559 | 1672 | |
---|
1560 | 1673 | ieee80211_setup_sdata(sdata, type); |
---|
| 1674 | + ieee80211_set_vif_encap_ops(sdata); |
---|
1561 | 1675 | |
---|
1562 | 1676 | err = ieee80211_do_open(&sdata->wdev, false); |
---|
1563 | 1677 | WARN(err, "type change: do_open returned %d", err); |
---|
.. | .. |
---|
1639 | 1753 | goto out_unlock; |
---|
1640 | 1754 | } |
---|
1641 | 1755 | } |
---|
1642 | | - /* fall through */ |
---|
| 1756 | + fallthrough; |
---|
1643 | 1757 | default: |
---|
1644 | 1758 | /* assign a new address if possible -- try n_addresses first */ |
---|
1645 | 1759 | for (i = 0; i < local->hw.wiphy->n_addresses; i++) { |
---|
.. | .. |
---|
1766 | 1880 | txq_size += sizeof(struct txq_info) + |
---|
1767 | 1881 | local->hw.txq_data_size; |
---|
1768 | 1882 | |
---|
1769 | | - if (local->ops->wake_tx_queue) |
---|
| 1883 | + if (local->ops->wake_tx_queue) { |
---|
1770 | 1884 | if_setup = ieee80211_if_setup_no_queue; |
---|
1771 | | - else |
---|
| 1885 | + } else { |
---|
1772 | 1886 | if_setup = ieee80211_if_setup; |
---|
1773 | | - |
---|
1774 | | - if (local->hw.queues >= IEEE80211_NUM_ACS) |
---|
1775 | | - txqs = IEEE80211_NUM_ACS; |
---|
| 1887 | + if (local->hw.queues >= IEEE80211_NUM_ACS) |
---|
| 1888 | + txqs = IEEE80211_NUM_ACS; |
---|
| 1889 | + } |
---|
1776 | 1890 | |
---|
1777 | 1891 | ndev = alloc_netdev_mqs(size + txq_size, |
---|
1778 | 1892 | name, name_assign_type, |
---|
1779 | 1893 | if_setup, txqs, 1); |
---|
1780 | 1894 | if (!ndev) |
---|
1781 | 1895 | return -ENOMEM; |
---|
| 1896 | + |
---|
| 1897 | + if (!local->ops->wake_tx_queue && local->hw.wiphy->tx_queue_len) |
---|
| 1898 | + ndev->tx_queue_len = local->hw.wiphy->tx_queue_len; |
---|
| 1899 | + |
---|
1782 | 1900 | dev_net_set(ndev, wiphy_net(local->hw.wiphy)); |
---|
1783 | 1901 | |
---|
1784 | 1902 | ndev->tstats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats); |
---|
.. | .. |
---|
1804 | 1922 | } |
---|
1805 | 1923 | |
---|
1806 | 1924 | ieee80211_assign_perm_addr(local, ndev->perm_addr, type); |
---|
1807 | | - if (params && is_valid_ether_addr(params->macaddr)) |
---|
| 1925 | + if (is_valid_ether_addr(params->macaddr)) |
---|
1808 | 1926 | memcpy(ndev->dev_addr, params->macaddr, ETH_ALEN); |
---|
1809 | 1927 | else |
---|
1810 | 1928 | memcpy(ndev->dev_addr, ndev->perm_addr, ETH_ALEN); |
---|
.. | .. |
---|
1872 | 1990 | ieee80211_setup_sdata(sdata, type); |
---|
1873 | 1991 | |
---|
1874 | 1992 | if (ndev) { |
---|
1875 | | - if (params) { |
---|
1876 | | - ndev->ieee80211_ptr->use_4addr = params->use_4addr; |
---|
1877 | | - if (type == NL80211_IFTYPE_STATION) |
---|
1878 | | - sdata->u.mgd.use_4addr = params->use_4addr; |
---|
1879 | | - } |
---|
| 1993 | + ndev->ieee80211_ptr->use_4addr = params->use_4addr; |
---|
| 1994 | + if (type == NL80211_IFTYPE_STATION) |
---|
| 1995 | + sdata->u.mgd.use_4addr = params->use_4addr; |
---|
1880 | 1996 | |
---|
1881 | 1997 | ndev->features |= local->hw.netdev_features; |
---|
| 1998 | + ndev->hw_features |= ndev->features & |
---|
| 1999 | + MAC80211_SUPPORTED_FEATURES_TX; |
---|
1882 | 2000 | |
---|
1883 | 2001 | netdev_set_default_ethtool_ops(ndev, &ieee80211_ethtool_ops); |
---|
1884 | 2002 | |
---|
1885 | | - /* MTU range: 256 - 2304 */ |
---|
| 2003 | + /* MTU range is normally 256 - 2304, where the upper limit is |
---|
| 2004 | + * the maximum MSDU size. Monitor interfaces send and receive |
---|
| 2005 | + * MPDU and A-MSDU frames which may be much larger so we do |
---|
| 2006 | + * not impose an upper limit in that case. |
---|
| 2007 | + */ |
---|
1886 | 2008 | ndev->min_mtu = 256; |
---|
1887 | | - ndev->max_mtu = IEEE80211_MAX_DATA_LEN; |
---|
| 2009 | + if (type == NL80211_IFTYPE_MONITOR) |
---|
| 2010 | + ndev->max_mtu = 0; |
---|
| 2011 | + else |
---|
| 2012 | + ndev->max_mtu = local->hw.max_mtu; |
---|
1888 | 2013 | |
---|
1889 | 2014 | ret = register_netdevice(ndev); |
---|
1890 | 2015 | if (ret) { |
---|