summaryrefslogtreecommitdiffstats
path: root/perl-install/share
ModeNameSize
-rw-r--r--base.png234logstatsplain
-rw-r--r--diskdrake.css1864logstatsplain
-rw-r--r--floppy.png306logstatsplain
-rw-r--r--ftin.png212logstatsplain
-rw-r--r--ftout.png217logstatsplain
-rw-r--r--help.png1353logstatsplain
-rw-r--r--installed.png477logstatsplain
-rw-r--r--left-background-filler.png763logstatsplain
d---------po2657logstatsplain
-rw-r--r--themes-galaxy.css749logstatsplain
-rw-r--r--themes-galaxy.rc726logstatsplain
>279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133
package network::connection::wireless;

use base qw(network::connection::ethernet);

use strict;
use common;
use log;
use network::network;

#- class attributes:
#-   network: ID of the selected network

sub get_type_name() { N("Wireless") }
sub get_type_description() { N("Wireless (Wi-Fi)") }
sub _get_type_icon() { 'wireless' }
sub get_devices {
    my ($_class, %options) = @_;
    require detect_devices;
    my @devices = detect_devices::probe_category('network/wireless');
    my @wireless = grep { detect_devices::is_wireless_interface($_) } detect_devices::get_lan_interfaces();
    my @all_devices = (@devices, network::connection::ethernet::get_unlisted_devices(\@wireless, \@devices));
    foreach (@all_devices) {
        my $interface = $_->{interface} || network::connection::ethernet::device_to_interface($_) or next;
        my $driver = network::connection::ethernet::interface_to_driver($interface) or next;
        $_->{driver} = $driver if $driver;
    }
    @all_devices,
    if_(!$options{automatic_only}, {
        driver => 'ndiswrapper',
        description => N("Use a Windows driver (with ndiswrapper)"),
    });
}

sub handles_ifcfg {
    my ($_class, $ifcfg) = @_;
    require detect_devices;
    detect_devices::is_wireless_interface($ifcfg->{DEVICE}) || exists $ifcfg->{WIRELESS_MODE};
}

sub get_metric { 35 }

#- http://www.linux-wireless.org/Install-HOWTO/WL/WEP-Key-HOWTO.txt
my $wpa_supplicant_max_wep_key_len = 32;

our %wireless_enc_modes = (
    none => N_("None"),
    open => N_("Open WEP"),
    restricted => N_("Restricted WEP"),
    'wpa-psk' => N_("WPA/WPA2 Pre-Shared Key"),
    'wpa-eap' => N_("WPA/WPA2 Enterprise"),
);
#define the eap related variables we handle
#0 means we preserve value if found
#1 means we save without quotes
#2 save with quotes
my %eap_vars = (
	ssid => 2,
	scan_ssid => 1,
	identity => 2,
	password => 2,
	key_mgmt => 1,
	eap => 1,
	pairwise => 1,
	group => 1,
	proto => 1,
	ca_cert => 2,
	client_cert => 2,
	phase2 => 2,
	anonymous_identity => 2,
	subject_match => 2,
	disabled => 0,
	id_str => 0,
	bssid => 0,
	priority => 0,
	auth_alg => 0,
	eapol_flags => 0,
	proactive_key_caching => 0,
	peerkey => 0,
	ca_path => 0,
	private_key => 0,
	private_key_passwd => 0,
	dh_file => 0,
	altsubject_match => 0,
	phase1 => 0,
	fragment_size => 0,
	eap_workaround => 0,
);

my @thirdparty_settings = (
    {
        name => 'zd1201',
        description => 'ZyDAS ZD1201',
        url => 'http://linux-lc100020.sourceforge.net/',
        firmware => {
            test_file => 'zd1201*.fw',
        },
    },

    (map {
        {
            name => "ipw${_}",
            description => "Intel(R) PRO/Wireless ${_}",
            url => "http://ipw${_}.sourceforge.net/",
            firmware => {
                url => "http://ipw${_}.sourceforge.net/firmware.php",
                test_file => "ipw$_-*.fw",
            },
        };
    } (2100, 2200)),

    {
        name => "ipw3945",
        description => "Intel(R) PRO/Wireless 3945",
        url => "http://ipw3945.sourceforge.net/",
        firmware => {
            package => "ipw3945-ucode",
            test_file => "ipw3945.ucode",
        },
        tools => {
            package => "ipw3945d",
            test_file => '/usr/sbin/ipw3945d',
        },
    },

    (map {
        my ($version, $ucode_api, $ucode_version, $package) = @$_;
        $ucode_version ||= $version;
        $package ||= $version;
        {
            name => "iwl${version}",
            description => "Intel(R) PRO/Wireless ${package}",
            url => "http://intellinuxwireless.org/",
            firmware => {
                package => "iwlwifi-${package}-ucode",
                test_file => "iwlwifi-${ucode_version}${ucode_api}.ucode",
            },
            sleep => 1,
        };
    } ([ 3945, '-2' ], [ 4965, '-2' ], [ 'wifi', '-5', 5000, 'agn' ])),

    {
        name => 'p54pci',
        description => 'PCI adaptors based on the Intersil Prism54 chip series',
        url => 'http://wireless.kernel.org/en/users/Drivers/p54',
        firmware => {
            url => 'http://wireless.kernel.org/en/users/Drivers/p54#firmware',
            test_file => "isl3886pci",
        },
    },

    {
        name => 'p54usb',
        description => 'USB adaptors based on the Intersil Prism54 chip series',
        url => 'http://wireless.kernel.org/en/users/Drivers/p54',
        firmware => {
            url => 'http://wireless.kernel.org/en/users/Drivers/p54#firmware',
            test_file => "isl388*usb",
        },
    },

    {
        name => 'atmel',
        matching => [ qw(at76_usb atmel_cs atmel_pci) ],
        description => 'Atmel at76c50x cards',
        url => 'http://thekelleys.org.uk/atmel/',
        firmware => {
            test_file => 'atmel_at76c50*',
        },
        links => 'http://at76c503a.berlios.de/',
    },

    {
        name => 'madwifi',
        matching => 'ath_pci',
        description => 'Multiband Atheros Driver for WiFi',
        url => 'http://madwifi.org/',
        kernel_module => 1,
        tools => {
            optional => 1,
            test_file => '/usr/bin/athstats',
        },
    },

    {
        name => 'prism2',
        matching => qr/^prism2_/,
        description => 'Prism2 based cards',
        tools => {
            package => 'prism2-utils',
            test_file => '/sbin/wlanctl-ng',
        },
    },

    {
        name => 'zd1211',
        matching => 'zd1211rw',
        description => 'ZD1211 chip',
        firmware => {
            url => 'http://sourceforge.net/projects/zd1211/',
            test_file => 'zd1211/zd1211_*',
        },
    },

    {
        name => 'bcm43xx',
        description => 'Broadcom bcm43xx wireless chips',
        url => 'http://bcm43xx.berlios.de/',
        firmware => {
            test_file => 'bcm43xx_microcode*.fw',
            no_package => 1,
            extract => {
                name => 'bcm43xx-fwcutter',
                test_file => '/usr/bin/bcm43xx-fwcutter',
                windows_source => 'bcmwl5.sys',
                default_source => 'bcmwl5.sys',
                run => sub {
                    my ($file) = @_;
                    run_program::rooted($::prefix, '/usr/bin/bcm43xx-fwcutter',
                                        '-w', $network::thirdparty::firmware_directory, $file);
                },
            },
        },
    },

    {
        name => 'b43',
        description => 'Broadcom B43 wireless chips',
        firmware => {
            package => 'b43-openfwwf',
            url => 'http://www.ing-unibs.it/~openfwwf/',
            test_file => 'b43/ucode5.fw',
        },
    },

    (map {
      +{
        name => $_,
        description => "Broadcom $_ wireless chips",
        url => 'http://wireless.kernel.org/en/users/Drivers/b43',
        firmware => {
            test_file => $_ . "/ucode*.fw",
            no_package => 1,
            extract => {
                name => 'b43-fwcutter',
                test_file => '/usr/bin/b43-fwcutter',
                windows_source => 'bcmwl5.sys',
                default_source => 'bcmwl5.sys',
                run => sub {
                    my ($file) = @_;
                    run_program::rooted($::prefix, '/usr/bin/b43-fwcutter',
                                        '-w', $network::thirdparty::firmware_directory, $file);
                },
            },
        },
      };
    } qw(b43legacy)),

    {
        name => 'acx100',
        matching => [ qw(acx_pci acx_usb) ],
        description => 'ACX100/ACX111/TNETW1450',
        firmware => {
            url => 'http://acx100.sourceforge.net/wiki/Firmware',
            test_file => 'tiacx1*',
            no_distro_package => 1,
        },
    },

    {
        name => 'ndiswrapper',
        description => 'Wireless device using ndiswrapper (windows drivers)',
        tools => {
            test_file => '/usr/sbin/ndiswrapper',
        },
        firmware => {
            user_install => sub {
                my ($settings, $in) = @_;
                require network::ndiswrapper;
                $settings->{device} = network::ndiswrapper::select_device($in) or return;
                network::ndiswrapper::setup_device($in, $settings->{device});
                $settings->{device}{driver} = $settings->{name};
            },
            url => 'http://ndiswrapper.sourceforge.net/mediawiki/index.php/List',
            component_name => N_("Windows driver"),
            no_package => 1,
        },
        no_module_reload => 1,
    },

    (map {
      my ($version, $suffix) = @$_;
      $suffix ||= $version;
      +{
        name => "rt${version}",
        matching => qr/^rt${version}(|pci|usb)$/,
        description => "Ralink RT${version} WiFi",
        kernel_module => 1,
        firmware => {
            package => 'ralink-firmware',
            url => 'http://www.ralinktech.com/',
            test_file => "rt${suffix}.bin",
        },
      };
    } ([ 2800, 2860 ], [ 61, 2661 ], [ 73 ])),

    {
        name => 'rtlwifi',
        matching => qr/^(rtl8192|r8712u$)/,
        description => 'Realtek WiFi',
        url => 'http://www.realtek.com.tw/',
        firmware => {
            test_file => 'rtlwifi/rtl8192sefw.bin',
        },
    },
);

sub get_packages { 'wireless-tools' }

sub get_thirdparty_settings() {
    \@thirdparty_settings;
}

sub setup_thirdparty {
    my ($self, $in) = @_;
    require network::rfswitch;
    network::rfswitch::configure();
    if ($self->get_driver eq 'ndiswrapper') {
        require network::ndiswrapper;
        my @devices = map { network::ndiswrapper::present_devices($_) } network::ndiswrapper::installed_drivers();
        return {} if member($self->{device}, @devices) && network::ndiswrapper::find_interface($self->{device});
    }
    my $thirdparty = $self->SUPER::setup_thirdparty($in);
    my $driver = $self->get_driver;
    if ($self->{thirdparty} && $driver eq 'ipw3945' && !$self->rf_killed && !$self->SUPER::check_device) {
        log::explanations("Reloading module $driver");
        eval { modules::unload($driver) };
        eval { modules::load($driver) };
    }
    $thirdparty;
}

sub rf_killed {
    my ($self) = @_;
    if ($self->{device}{sysfs_device}) {
        my $rf_kill_path = $self->{device}{sysfs_device} . "/rf_kill";
        if (-e $rf_kill_path) {
            my $rf_kill = chomp_(cat_($rf_kill_path));
            #- for ipw drivers, 0 means no RF kill switch
            return $rf_kill != 0;
        }
    }
    undef;
}

sub check_device {
    my ($self) = @_;
    if ($self->rf_killed) {
        $self->{device}{error} = N("Your wireless card is disabled, please enable the wireless switch (RF kill switch) first.");
        return 0;
    }
    return $self->SUPER::check_device;
}

sub load_interface_settings {
    my ($self) = @_;
    $self->network::connection::load_interface_settings;
    $self->{hide_passwords} = 1;
    # override ifcfg with network-specific settings if available
    my $network = $self->get_selected_network;
    $self->{ifcfg} = $network ?
      get_network_ifcfg($network->{ap}) || get_network_ifcfg($network->{essid}) :
      $self->{ifcfg};

    $self->SUPER::map_ifcfg2config_settings;
}

sub get_networks {
    my ($self, $o_net) = @_;
    require network::monitor;
    ($self->{networks}, $self->{control}{roaming}) = network::monitor::list_wireless($o_net && $o_net->{monitor}, $self->get_interface);
    $self->probed_networks;
    $self->{networks};
}

sub refresh_roaming_ids {
    my ($self) = @_;
    #- needed when switching from non-roaming to roaming
    #- or after restarting wpa_supplicant
    #- to get fresh wpa_supplicant network IDs
    get_networks($self) if $self->{control}{roaming};
}

sub selected_network_is_configured {
    my ($self) = @_;
    $self->refresh_roaming_ids;
    $self->SUPER::selected_network_is_configured;
}

sub guess_network {
    my ($_self) = @_;
    #- FIXME: try to find the AP matching $self->{ifcfg}{WIRELESS_ESSID};
}

sub get_network_ifcfg {
    my ($ssid) = @_;
    require network::network;
    my $file = $::prefix . $network::network::wireless_d . '/' . $ssid;
    -f $file && { getVarsFromSh($file) };
}

sub guess_network_access_settings {
    my ($self) = @_;

    my $network = $self->get_selected_network;
    my $ifcfg = $self->{ifcfg};
    $ifcfg ||= {};

    $self->{access}{network}{bssid} = $network && $network->{hidden} && $network->{ap};
    $self->{access}{network}{essid} = $network && $network->{essid} || $ifcfg->{WIRELESS_ESSID} || !$network && "any";
    ($self->{access}{network}{key}, my $restricted, $self->{access}{network}{force_ascii_key}) =
      get_wep_key_from_iwconfig($ifcfg->{WIRELESS_ENC_KEY});

    $self->{access}{network}{encryption} =
      $network && $network->{flags} =~ /eap/i ?
        'wpa-eap' :
      $network && $network->{flags} =~ /wpa/i ?
        'wpa-psk' :
      $network && $network->{flags} =~ /wep/i || $self->{access}{network}{key} ?
        $ifcfg->{WIRELESS_ENC_MODE} || ($restricted ? 'restricted' : 'open') :
        'none';

    undef $self->{ifcfg}{WIRELESS_IWPRIV} if is_old_rt2x00($self->get_driver) && $self->{ifcfg}{WIRELESS_IWPRIV} =~ /WPAPSK/;

    my $system_file = '/etc/sysconfig/drakx-net';
    my %global_settings = getVarsFromSh($system_file);
    $self->{control}{roaming} =
      (exists $self->{ifcfg}{WIRELESS_WPA_DRIVER} || text2bool($global_settings{ROAMING}))
        && !is_old_rt2x00($self->get_driver);

    $self->{access}{network}{mode} =
        $network && $network->{mode} ||
        $ifcfg->{WIRELESS_MODE} ||
        'Managed';

    wpa_supplicant_load_eap_settings($self->{access}{network}) if $self->need_wpa_supplicant;
}

sub get_network_access_settings_label { N("Wireless settings") }

sub get_network_access_settings {
    my ($self) = @_;
    [
        { label => N("Operating Mode"), val => \$self->{access}{network}{mode},
          list => [ N_("Ad-hoc"), N_("Managed"), N_("Master"), N_("Repeater"), N_("Secondary"), N_("Auto") ],
          format => \&translate,
        },
        { label => N("Network name (ESSID)"), val => \$self->{access}{network}{essid},
          disabled => sub { my $network = $self->get_selected_network; $network && $network->{essid} } },
        { label => N("Encryption mode"), val => \$self->{access}{network}{encryption}, list => [ keys %wireless_enc_modes ],
          sort => 1, format => sub { translate($wireless_enc_modes{$_[0]}) } },
        { label => N("Encryption key"), val => \$self->{access}{network}{key},
          hidden => sub { $self->{hide_passwords} },
          disabled => sub { member($self->{access}{network}{encryption}, qw(none wpa-eap)) } },
        { text => N("Hide password"),
          type => "bool", val => \$self->{hide_passwords} },
        { text => N("Force using this key as ASCII string (e.g. for Livebox)"),
          type => "bool", val => \$self->{access}{network}{force_ascii_key},
          disabled => sub {
              #- only for WEP keys looking like hexadecimal
              !member($self->{access}{network}{encryption}, qw(open restricted)) ||
              !get_hex_key($self->{access}{network}{key});
          } },
        { label => N("EAP Login/Username"), val => \$self->{access}{network}{eap_identity},
          disabled => sub { $self->{access}{network}{encryption} ne 'wpa-eap' },
	  help => N("The login or username. Format is plain text. If you
need to specify domain then try the untested syntax
  DOMAIN\\username") },
        { label => N("EAP Password"), val => \$self->{access}{network}{eap_password},
          hidden => sub { $self->{hide_passwords} },
          disabled => sub { $self->{access}{network}{encryption} ne 'wpa-eap' },
	  help => N(" Password: A string.
Note that this is not the same thing as a psk.
____________________________________________________
RELATED ADDITIONAL INFORMATION:
In the Advanced Page, you can select which EAP mode
is used for authentication. For the eap mode setting
   Auto Detect: implies all possible modes are tried.

If Auto Detect fails, try the PEAP TTLS combo bofore others
Note:
	The settings MD5, MSCHAPV2, OTP and GTC imply
automatically PEAP and TTLS modes.
  TLS mode is completely certificate based and may ignore
the username and password values specified here.") },
        { label => N("EAP client certificate"), val => \$self->{access}{network}{eap_client_cert},
          disabled => sub { $self->{access}{network}{encryption} ne 'wpa-eap' },
          help => N("The complete path and filename of client certificate. This is
only used for EAP certificate based authentication. It could be
considered as the alternative to username/password combo.
 Note: other related settings are shown on the Advanced page.")  },
	{ label => N("EAP client private key"), val => \$self->{access}{network}{eap_private_key},
          disabled => sub { $self->{access}{network}{encryption} ne 'wpa-eap' },
          help => N("The complete path and filename of client private key. This is
only used for EAP certificate based authentication. It could be
considered as the alternative to username/password combo.
 Note: other related settings are shown on the Advanced page.")  },
	{ label => N("EAP client private key password"), val => \$self->{access}{network}{eap_private_key_passwd},
          disabled => sub { $self->{access}{network}{encryption} ne 'wpa-eap' },
          help => N("The complete password for the client private key. This is
only used for EAP certificate based authentication. This password 
is used for protected client private keys only. It can be optional.
 Note: other related settings are shown on the Advanced page.")  },
        { label => N("Network ID"), val => \$self->{ifcfg}{WIRELESS_NWID}, advanced => 1 },
        { label => N("Operating frequency"), val => \$self->{ifcfg}{WIRELESS_FREQ}, advanced => 1 },
        { label => N("Sensitivity threshold"), val => \$self->{ifcfg}{WIRELESS_SENS}, advanced => 1 },
        { label => N("Bitrate (in b/s)"), val => \$self->{ifcfg}{WIRELESS_RATE}, advanced => 1 },
        { label => N("RTS/CTS"), val => \$self->{ifcfg}{WIRELESS_RTS}, advanced => 1,
          help => N("RTS/CTS adds a handshake before each packet transmission to make sure that the
channel is clear. This adds overhead, but increase performance in case of hidden
nodes or large number of active nodes. This parameter sets the size of the
smallest packet for which the node sends RTS, a value equal to the maximum
packet size disable the scheme. You may also set this parameter to auto, fixed
or off.")
      },
        { label => N("Fragmentation"), val => \$self->{ifcfg}{WIRELESS_FRAG}, advanced => 1 },
        { label => N("iwconfig command extra arguments"), val => \$self->{ifcfg}{WIRELESS_IWCONFIG}, advanced => 1,
          help => N("Here, one can configure some extra wireless parameters such as:
ap, channel, commit, enc, power, retry, sens, txpower (nick is already set as the hostname).

See iwconfig(8) man page for further information."),
      },
        { label =>
            #-PO: split the "xyz command extra argument" translated string into two lines if it's bigger than the english one
            N("iwspy command extra arguments"), val => \$self->{ifcfg}{WIRELESS_IWSPY}, advanced => 1,
          help => N("iwspy is used to set a list of addresses in a wireless network
interface and to read back quality of link information for each of those.

This information is the same as the one available in /proc/net/wireless :
quality of the link, signal strength and noise level.

See iwpspy(8) man page for further information."),
 },
        { label => N("iwpriv command extra arguments"), val => \$self->{ifcfg}{WIRELESS_IWPRIV}, advanced => 1,
          disabled => sub { $self->need_rt2x00_iwpriv },
          help => N("iwpriv enable to set up optionals (private) parameters of a wireless network
interface.

iwpriv deals with parameters and setting specific to each driver (as opposed to
iwconfig which deals with generic ones).

In theory, the documentation of each device driver should indicate how to use
those interface specific commands and their effect.

See iwpriv(8) man page for further information."),
          },
        { label => N("EAP Protocol"), val => \$self->{access}{network}{forceeap},
          list => [ N_("Auto Detect"), N_("WPA2"), N_("WPA") ],
          sort => 1, format => \&translate, advanced => 1,
	  help => N("Auto Detect is recommended as it first tries WPA version 2 with
a fallback to WPA version 1") },
        { label => N("EAP Mode"), val => \$self->{access}{network}{eap_eap},
          list => [ N_("Auto Detect"), N_("PEAP"), N_("TTLS"), N_("TLS"), N_("MSCHAPV2"), N_("MD5"), N_("OTP"), N_("GTC"), N_("LEAP") , N_("PEAP TTLS"), N_("TTLS TLS") ],
          sort => 1, format => \&translate, advanced => 1, },
        { label => N("EAP key_mgmt"), val => \$self->{access}{network}{eap_key_mgmt}, advanced => 1,
          disabled => sub { $self->{access}{network}{encryption} ne 'wpa-eap' },
          help => N("list of accepted authenticated key management protocols.
possible values are WPA-EAP, IEEE8021X, NONE") },
        { label => N("EAP outer identity"), val => \$self->{access}{network}{eap_anonymous_identity}, advanced => 1,
          disabled => sub { $self->{access}{network}{encryption} ne 'wpa-eap' },
          help => N("Anonymous identity string for EAP: to be used as the
unencrypted identity with EAP types that support different
tunnelled identity, e.g., TTLS") },
        { label => N("EAP phase2"), val => \$self->{access}{network}{eap_phase2}, advanced => 1,
          disabled => sub { $self->{access}{network}{encryption} ne 'wpa-eap' } ,
          help => N("Inner authentication with TLS tunnel parameters.
input is string with field-value pairs, Examples:
auth=MSCHAPV2 for PEAP or
autheap=MSCHAPV2 autheap=MD5 for TTLS") },
        { label => N("EAP CA certificate"), val => \$self->{access}{network}{eap_ca_cert}, advanced => 1,
          disabled => sub { $self->{access}{network}{encryption} ne 'wpa-eap' },
          help => N("Full file path to CA certificate file (PEM/DER). This file
can have one or more trusted CA certificates. If ca_cert are not
included, server certificate will not be verified. If possible,
a trusted CA certificate should always be configured
when using TLS or TTLS or PEAP.") },
        { label => N("EAP certificate subject match"), val => \$self->{access}{network}{eap_subject_match}, advanced => 1,
          disabled => sub { $self->{access}{network}{encryption} ne 'wpa-eap' },
          help => N(" Substring to be matched against the subject of
the authentication server certificate. If this string is set,
the server certificate is only accepted if it contains this
string in the subject.  The subject string is in following format:
/C=US/ST=CA/L=San Francisco/CN=Test AS/emailAddress=as\@example.com") },
        { label => N("Extra directives"), val => \$self->{access}{network}{extra}, advanced => 1,
          help => N("Here one can pass extra settings to wpa_supplicant
The expected format is a string field=value pair. Multiple values
maybe specified, separating each value with the # character.
Note: directives are passed unchecked and may cause the wpa
negotiation to fail silently. Supported directives are preserved
across editing.
Supported directives are :
	disabled, id_str, bssid, priority, auth_alg, eapol_flags,
	proactive_key_caching, peerkey, ca_path, private_key,
	private_key_passwd, dh_file, altsubject_match, phase1,
	fragment_size and eap_workaround, pairwise, group
	Others such as key_mgmt, eap maybe used to force
	special settings different from the U.I settings.") },
    ];
}

sub check_network_access_settings {
    my ($self) = @_;

    if (!member($self->{access}{network}{encryption}, qw(none wpa-eap)) && !$self->{access}{network}{key}) {
        $self->{network_access}{error}{message} = N("An encryption key is required.");
        $self->{network_access}{error}{field} =  \$self->{access}{network}{key};
        return 0;
    }

    if ($self->{access}{network}{encryption} eq 'wpa-psk' &&
          !convert_psk_key_for_wpa_supplicant($self->{access}{network}{key})) {
        $self->{network_access}{error}{message} = N("The pre-shared key should have between 8 and 63 ASCII characters, or 64 hexadecimal characters.");
        $self->{network_access}{error}{field} =  \$self->{access}{network}{key};
        return 0;
    }
    if (member($self->{access}{network}{encryption}, qw(open restricted)) &&
          !convert_wep_key_for_wpa_supplicant($self->{access}{network}{key}, $self->{access}{network}{force_ascii_key})) {
        $self->{network_access}{error}{message} = N("The WEP key should have at most %d ASCII characters or %d hexadecimal characters.",
                                                    $wpa_supplicant_max_wep_key_len, $wpa_supplicant_max_wep_key_len * 2);
        $self->{network_access}{error}{field} =  \$self->{access}{network}{key};
        return 0;
    }

    if ($self->{ifcfg}{WIRELESS_FREQ} && $self->{ifcfg}{WIRELESS_FREQ} !~ /[0-9.]*[kGM]/) {
        $self->{network_access}{error}{message} = N("Freq should have the suffix k, M or G (for example, \"2.46G\" for 2.46 GHz frequency), or add enough '0' (zeroes).");
        $self->{network_access}{error}{field} = \$self->{ifcfg}{WIRELESS_FREQ};
        return 0;
    }

    if ($self->{ifcfg}{WIRELESS_RATE} && $self->{ifcfg}{WIRELESS_RATE} !~ /[0-9.]*[kGM]/) {
        $self->{network_access}{error}{message} = N("Rate should have the suffix k, M or G (for example, \"11M\" for 11M), or add enough '0' (zeroes).");
        $self->{network_access}{error}{field} = \$self->{ifcfg}{WIRELESS_RATE};
        return 0;
    }

    return 1;
}

sub get_control_settings {
    my ($self) = @_;
    [
        @{$self->SUPER::get_control_settings},
        { text => N("Allow access point roaming"), val => \$self->{control}{roaming}, type => "bool",
          disabled => sub { is_wpa_supplicant_blacklisted($self->get_driver) } },
    ];
}

sub need_wpa_supplicant {
    my ($self) = @_;
    ($self->{control}{roaming} || $self->{access}{network}{encryption} =~ /^wpa-/) && !is_old_rt2x00($self->get_driver);
}

sub install_packages {
    my ($self, $in) = @_;
    if ($self->need_wpa_supplicant) {
        $in->do_pkgs->ensure_is_installed('wpa_supplicant', '/usr/sbin/wpa_supplicant') or return;
        $in->do_pkgs->ensure_is_installed('mandi', '/usr/sbin/mandi');
    }
    $self->SUPER::install_packages($in);
}


sub build_ifcfg_settings {
    my ($self) = @_;

    # if we are not using WEP, the key is always ASCII (#52128)
    $self->{access}{network}{force_ascii_key} = 1 unless member($self->{access}{network}{encryption}, qw(open restricted));

    my $settings = {
        WIRELESS_MODE => $self->{access}{network}{mode},
        if_($self->need_wpa_supplicant,
            WIRELESS_WPA_DRIVER => wpa_supplicant_get_driver($self->get_driver),
            WIRELESS_WPA_REASSOCIATE => bool2yesno($self->need_wpa_supplicant_reassociate),
            MII_NOT_SUPPORTED => 'no',
        ),
        WIRELESS_ESSID => $self->{access}{network}{essid},
        if_($self->{access}{network}{encryption} ne 'none',
            WIRELESS_ENC_KEY => convert_wep_key_for_iwconfig($self->{access}{network}{key}, $self->{access}{network}{force_ascii_key})),
        if_(member($self->{access}{network}{encryption}, qw(open restricted)),
            WIRELESS_ENC_MODE =>  $self->{access}{network}{encryption}),
        if_($self->need_rt2x00_iwpriv,
            #- use iwpriv for WPA with rt2400/rt2500 drivers, they don't plan to support wpa_supplicant
            WIRELESS_IWPRIV => qq(set AuthMode=WPAPSK
set EncrypType=TKIP
set SSID=$self->{access}{network}{essid}
set WPAPSK="$self->{access}{network}{key}"
set TxRate=0)),
        (map { $_ => $self->{ifcfg}{$_} }
           qw(WIRELESS_NWID WIRELESS_FREQ WIRELESS_SENS WIRELESS_RATE WIRELESS_RTS WIRELESS_FRAG WIRELESS_IWCONFIG WIRELESS_IWSPY), if_(!$self->need_rt2x00_iwpriv, 'WIRELESS_IWPRIV')),
    };
    $self->SUPER::build_ifcfg_settings($settings);
}

sub add_network_to_wpa_supplicant {
    my ($self) = @_;
    if ($self->{access}{network}{encryption} eq 'wpa-eap') {
        wpa_supplicant_add_eap_network($self->{access}{network});
    } else {
        wpa_supplicant_add_network($self->{access}{network});
    }
    #- this should be handled by the monitoring daemon instead
    run_program::run('/usr/sbin/wpa_cli', 'reconfigure');
}

sub write_settings {
    my ($self, $o_net, $o_modules_conf) = @_;

    my $network = $self->get_selected_network;
    network::network::write_wireless_conf($_, $self->build_ifcfg_settings) foreach
        grep { $_ } ($network ? $network->{ap} : ()), $self->{access}{network}{essid};

    $self->add_network_to_wpa_supplicant if $self->need_wpa_supplicant;

    wlan_ng_configure($self->{access}{network}{essid}, $self->{access}{network}{key}, $self->get_interface, $self->get_driver) if $self->{thirdparty}{name} eq 'prism2';

    $self->SUPER::write_settings($o_net, $o_modules_conf);
}

sub apply_network_selection {
    my ($self) = @_;
    require network::network;
    my $file = network::network::get_ifcfg_file($self->get_interface);
    network::network::write_interface_settings($self->build_ifcfg_settings, $file);

    $self->add_network_to_wpa_supplicant if $self->need_wpa_supplicant;
}

sub network_is_configured {
    my ($self, $network) = @_;
    if ($self->{control}{roaming}) {
        return defined $network->{id};
    } else {
        my $wireless_ifcfg = get_network_ifcfg($network->{ap}) || defined $network->{essid} && get_network_ifcfg($network->{essid});
        return $wireless_ifcfg;
    }
}

sub connect {
    my ($self, $_in, $net) = @_;

    $self->SUPER::connect;

    if ($self->{control}{roaming}) {
        my $network_id;
        foreach (0 .. 1) {
            $self->refresh_roaming_ids if $_;
            my $network = $self->get_selected_network;
            $network_id = $network->{id} if $network && defined $network->{id};
        }
        if (defined $network_id) {
            if ($net->{monitor}) {
                log::explanations("selecting wpa_supplicant network $network_id through network monitor");
                eval { $net->{monitor}->select_network($network_id) };
                return !$@;
            } else {
                run_program::run('/usr/sbin/wpa_cli', 'select_network', $network_id);
            }
        }
    }
}

sub get_status_message {
    my ($self, $status) = @_;
    my $interface = $self->get_interface;
    my ($current_essid, $current_ap) = get_access_point($interface);
    my $network = $current_essid || $current_ap && "[$current_ap]";
    {
        link_up => N("Associated to wireless network \"%s\" on interface %s", $network, $interface),
        link_down => N("Lost association to wireless network on interface %s", $interface),
    }->{$status} || $self->SUPER::get_status_message($status);
}



my $wpa_supplicant_conf = "/etc/wpa_supplicant.conf";

sub get_access_point {
    my ($intf) = @_;
    (chomp_(`/sbin/iwgetid -r $intf 2>/dev/null`), lc(chomp_(`/sbin/iwgetid -r -a $intf 2>/dev/null`)));
}

sub is_old_rt2x00 {
    my ($module) = @_;
    member($module, qw(rt2400 rt2500 rt2570 rt61 rt73));
}

sub is_wpa_supplicant_blacklisted {
    my ($module) = @_;
    is_old_rt2x00($module);
}

sub need_wpa_supplicant_reassociate {
       my ($self) = @_;
       $self->get_driver eq 'rt61pci';
}

sub need_rt2x00_iwpriv {
    my ($self) = @_;