summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOlivier Blin <oblin@mandriva.org>2005-04-20 11:24:30 +0000
committerOlivier Blin <oblin@mandriva.org>2005-04-20 11:24:30 +0000
commit644d8807c270ae8e85e1b06ed15b76a717e2427c (patch)
treebca149f813e56395ba6f71933b156afb607f2a33
parent743ca434f43293e3701fa2671305800d0dedf877 (diff)
downloaddrakx-backup-do-not-use-644d8807c270ae8e85e1b06ed15b76a717e2427c.tar
drakx-backup-do-not-use-644d8807c270ae8e85e1b06ed15b76a717e2427c.tar.gz
drakx-backup-do-not-use-644d8807c270ae8e85e1b06ed15b76a717e2427c.tar.bz2
drakx-backup-do-not-use-644d8807c270ae8e85e1b06ed15b76a717e2427c.tar.xz
drakx-backup-do-not-use-644d8807c270ae8e85e1b06ed15b76a717e2427c.zip
allow to choose the wireless encryption mode between "None", "Open WEP", "Restricted WEP" and "WPA Pre-Shared Key"
move ndiswrapper stuff in network::ndiswrapper
-rw-r--r--perl-install/network/ndiswrapper.pm108
-rw-r--r--perl-install/network/netconnect.pm57
-rw-r--r--perl-install/network/wireless.pm111
3 files changed, 150 insertions, 126 deletions
diff --git a/perl-install/network/ndiswrapper.pm b/perl-install/network/ndiswrapper.pm
new file mode 100644
index 000000000..cedb03321
--- /dev/null
+++ b/perl-install/network/ndiswrapper.pm
@@ -0,0 +1,108 @@
+package network::ndiswrapper;
+
+use strict;
+use common;
+use modules;
+use detect_devices;
+
+my $ndiswrapper_prefix = "$::prefix/etc/ndiswrapper";
+
+sub installed_drivers() {
+ grep { -d "$ndiswrapper_prefix/$_" } all($ndiswrapper_prefix);
+}
+
+sub present_devices {
+ my ($driver) = @_;
+ my @supported_devices;
+ foreach (all("$ndiswrapper_prefix/$driver")) {
+ my ($ids) = /^([0-9A-Z]{4}:[0-9A-Z]{4})\.[05]\.conf$/;
+ $ids and push @supported_devices, $ids;
+ }
+ grep { member(uc(sprintf("%04x:%04x", $_->{vendor}, $_->{id})), @supported_devices) } detect_devices::probeall();
+}
+
+sub get_devices {
+ my ($in, $driver) = @_;
+ my @devices = present_devices($driver);
+ @devices or $in->ask_warn(N("Error"), N("No device supporting the %s ndiswrapper driver is present!", $driver));
+ @devices;
+}
+
+sub ask_driver {
+ my ($in) = @_;
+ if (my $inf_file = $in->ask_file(N("Please select the Windows driver (.inf file)"), "/mnt/cdrom")) {
+ my $driver = basename(lc($inf_file));
+ $driver =~ s/\.inf$//;
+
+ #- first uninstall the driver if present, may solve issues if it is corrupted
+ -d "$ndiswrapper_prefix/$driver" and system('ndiswrapper', '-e', $driver);
+
+ unless (system('ndiswrapper', '-i', $inf_file) == 0) {
+ $in->ask_warn(N("Error"), N("Unable to install the %s ndiswrapper driver!", $driver));
+ return undef;
+ }
+
+ return $driver;
+ }
+ undef;
+}
+
+sub find_matching_devices {
+ my ($device) = @_;
+ my $net_path = '/sys/class/net';
+ my @devices;
+
+ foreach my $interface (all($net_path)) {
+ my $dev_path = "$net_path/$interface/device";
+ -l $dev_path or next;
+
+ my %map = (vendor => 'vendor', device => 'id');
+ if (every { hex(chomp_(cat_("$dev_path/$_"))) eq $device->{$map{$_}} } keys %map) {
+ my $driver = readlink("$net_path/$interface/driver");
+ $driver =~ s!.*/!!;
+ push @devices, [ $interface, $driver ];
+ }
+ }
+
+ @devices;
+}
+
+sub find_conflicting_devices {
+ my ($device) = @_;
+ grep { $_->[1] ne "ndiswrapper" } find_matching_devices($device);
+}
+
+sub find_interface {
+ my ($device) = @_;
+ my $dev = find { $_->[1] eq "ndiswrapper" } find_matching_devices($device);
+ $dev->[0];
+}
+
+sub setup_device {
+ my ($in, $device) = @_;
+
+ eval { modules::unload("ndiswrapper") };
+ #- unload ndiswrapper first so that the newly installed .inf files will be read
+ eval { modules::load("ndiswrapper") };
+
+ if ($@) {
+ $in->ask_warn(N("Error"), N("Unable to load the ndiswrapper module!"));
+ return;
+ }
+
+ my @conflicts = find_conflicting_devices($device);
+ if (@conflicts) {
+ $in->ask_yesorno(N("Warning"), N("The selected device has already been configured with the %s driver.
+Do you really want to use a ndiswrapper driver ?", $conflicts[0][1])) or return;
+ }
+
+ my $interface = find_interface($device);
+ unless ($interface) {
+ $in->ask_warn(N("Error"), N("Unable to find the ndiswrapper interface!"));
+ return;
+ }
+
+ $interface;
+}
+
+1;
diff --git a/perl-install/network/netconnect.pm b/perl-install/network/netconnect.pm
index e623cad3e..5a62b71be 100644
--- a/perl-install/network/netconnect.pm
+++ b/perl-install/network/netconnect.pm
@@ -90,7 +90,7 @@ sub real_main {
my ($isdn, $isdn_name, $isdn_type, %isdn_cards, @isdn_dial_methods);
my $my_isdn = join('', N("Manual choice"), " (", N("Internal ISDN card"), ")");
my (@ndiswrapper_drivers, $ndiswrapper_driver, $ndiswrapper_device);
- my ($is_wireless, $wireless_key, $wireless_use_wpa);
+ my ($is_wireless, $wireless_enc_mode, $wireless_enc_key);
my ($module, $auto_ip, $protocol, $onboot, $needhostname, $peerdns, $peeryp, $peerntpd, $hotplug, $track_network_id); # lan config
my $success = 1;
my $ethntf = {};
@@ -177,6 +177,13 @@ sub real_main {
4 => N("PAP/CHAP"),
);
+ my %wireless_enc_modes = (
+ none => N("None"),
+ open => N("Open WEP"),
+ restricted => N("Restricted WEP"),
+ 'wpa-psk' => N("WPA Pre-Shared Key"),
+ );
+
my $offer_to_connect = sub {
return "ask_connect_now" if $netc->{internet_cnx_choice} eq 'adsl' && !member($adsl_type, qw(manual dhcp));
return "ask_connect_now" if member($netc->{internet_cnx_choice}, qw(modem isdn isdn_external));
@@ -234,7 +241,7 @@ sub real_main {
};
my $ndiswrapper_do_device_selection = sub {
- $ntf_name = network::wireless::ndiswrapper_setup_device($in, $ndiswrapper_device);
+ $ntf_name = network::ndiswrapper::setup_device($in, $ndiswrapper_device);
unless ($ntf_name) {
undef $ndiswrapper_device;
return;
@@ -249,7 +256,7 @@ sub real_main {
};
my $ndiswrapper_do_driver_selection = sub {
- my @devices = network::wireless::ndiswrapper_get_devices($in, $ndiswrapper_driver);
+ my @devices = network::ndiswrapper::get_devices($in, $ndiswrapper_driver);
if (!@devices) {
undef $ndiswrapper_driver;
@@ -989,15 +996,15 @@ You can find a driver on http://eciadsl.flashtux.org/"),
},
complete => sub {
if ($ntf_name eq "Use a Windows driver (with ndiswrapper)") {
- require network::wireless;
+ require network::ndiswrapper;
unless ($in->do_pkgs->ensure_is_installed('ndiswrapper', '/usr/sbin/ndiswrapper')) {
$in->ask_warn(N("Error"), N("Could not install the %s package!", 'ndiswrapper'));
return 1;
}
undef $ndiswrapper_driver;
undef $ndiswrapper_device;
- unless (network::wireless::ndiswrapper_installed_drivers()) {
- $ndiswrapper_driver = network::wireless::ndiswrapper_ask_driver($in) or return 1;
+ unless (network::ndiswrapper::installed_drivers()) {
+ $ndiswrapper_driver = network::ndiswrapper::ask_driver($in) or return 1;
return !$ndiswrapper_do_driver_selection->();
}
}
@@ -1163,7 +1170,7 @@ notation (for example, 1.2.3.4).")),
ndiswrapper_select_driver =>
{
pre => sub {
- @ndiswrapper_drivers = network::wireless::ndiswrapper_installed_drivers();
+ @ndiswrapper_drivers = network::ndiswrapper::installed_drivers();
$ndiswrapper_driver ||= first(@ndiswrapper_drivers);
},
data => sub {
@@ -1172,7 +1179,7 @@ notation (for example, 1.2.3.4).")),
format => sub { defined $_[0] ? N("Use the ndiswrapper driver %s", $_[0]) : N("Install a new driver") } } ];
},
complete => sub {
- $ndiswrapper_driver ||= network::wireless::ndiswrapper_ask_driver($in) or return 1;
+ $ndiswrapper_driver ||= network::ndiswrapper::ask_driver($in) or return 1;
!$ndiswrapper_do_driver_selection->();
},
post => $ndiswrapper_next_step,
@@ -1182,7 +1189,7 @@ notation (for example, 1.2.3.4).")),
{
data => sub {
[ { label => N("Select a device:"), type => "list", val => \$ndiswrapper_device, allow_empty_list => 1,
- list => [ network::wireless::ndiswrapper_present_devices($ndiswrapper_driver) ],
+ list => [ network::ndiswrapper::present_devices($ndiswrapper_driver) ],
format => sub { $_[0]{description} } } ];
},
complete => sub {
@@ -1199,8 +1206,12 @@ notation (for example, 1.2.3.4).")),
$netc->{wireless_eth} = 1;
$ethntf->{WIRELESS_MODE} ||= "Managed";
$ethntf->{WIRELESS_ESSID} ||= "any";
- $wireless_use_wpa = exists $ethntf->{WIRELESS_WPA_DRIVER};
- $wireless_use_wpa or $wireless_key = network::wireless::convert_wep_key_for_iwconfig($ethntf->{WIRELESS_ENC_KEY});
+ ($wireless_enc_key, my $restricted) = network::wireless::get_wep_key_from_iwconfig($ethntf->{WIRELESS_ENC_KEY});
+ $wireless_enc_mode =
+ exists $ethntf->{WIRELESS_WPA_DRIVER} ? 'wpa-psk' :
+ !$wireless_enc_key ? 'none' :
+ $restricted ? 'restricted' :
+ 'open';
},
name => N("Please enter the wireless parameters for this card:"),
data => sub {
@@ -1213,9 +1224,10 @@ notation (for example, 1.2.3.4).")),
{ label => N("Operating frequency"), val => \$ethntf->{WIRELESS_FREQ}, advanced => 1 },
{ label => N("Sensitivity threshold"), val => \$ethntf->{WIRELESS_SENS}, advanced => 1 },
{ label => N("Bitrate (in b/s)"), val => \$ethntf->{WIRELESS_RATE}, advanced => 1 },
- { label => N("Encryption key"), val => \$wireless_key },
- #- FIXME: ask if the access point is open or restricted
- { text => N("Use Wi-Fi Protected Access (WPA)"), val => \$wireless_use_wpa, type => "bool" },
+ { label => N("Encryption mode"), val => \$wireless_enc_mode,
+ list => [ sort { $wireless_enc_modes{$a} cmp $wireless_enc_modes{$b} } keys %wireless_enc_modes ],
+ format => sub { $wireless_enc_modes{$_[0]} } },
+ { label => N("Encryption key"), val => \$wireless_enc_key, disabled => sub { $wireless_enc_mode eq 'none' } },
{ label => N("RTS/CTS"), val => \$ethntf->{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
@@ -1267,14 +1279,19 @@ See iwpriv(8) man page for further information."),
}
},
post => sub {
- $module =~ /^prism2_/ and network::wireless::wlan_ng_configure($in, $ethntf, $module);
- if ($wireless_use_wpa) {
- $ethntf->{WIRELESS_WPA_DRIVER} = network::wireless::wpa_supplicant_get_driver($module);
- network::wireless::wpa_supplicant_configure($in, $ethntf);
+ if ($wireless_enc_mode eq 'none') {
+ delete $ethntf->{WIRELESS_ENC_KEY};
} else {
- $ethntf->{WIRELESS_ENC_KEY} = network::wireless::get_wep_key_from_iwconfig($wireless_key);
- delete $ethntf->{WIRELESS_WPA_DRIVER};
+ #- keep the key even for WPA, so that drakconnect remembers it
+ $ethntf->{WIRELESS_ENC_KEY} = network::wireless::convert_wep_key_for_iwconfig($wireless_enc_key, $wireless_enc_mode eq 'restricted');
+ if ($wireless_enc_mode eq 'wpa-psk') {
+ $ethntf->{WIRELESS_WPA_DRIVER} = network::wireless::wpa_supplicant_get_driver($module);
+ network::wireless::wpa_supplicant_configure($in, $ethntf);
+ } else {
+ delete $ethntf->{WIRELESS_WPA_DRIVER};
+ }
}
+ $module =~ /^prism2_/ and network::wireless::wlan_ng_configure($in, $ethntf, $module);
return "static_hostname";
},
},
diff --git a/perl-install/network/wireless.pm b/perl-install/network/wireless.pm
index 564cafb9b..27f06971b 100644
--- a/perl-install/network/wireless.pm
+++ b/perl-install/network/wireless.pm
@@ -2,16 +2,14 @@ package network::wireless;
use strict;
use common;
-use modules;
-use detect_devices;
-use c;
sub convert_wep_key_for_iwconfig {
#- 5 or 13 characters, consider the key as ASCII and prepend "s:"
#- else consider the key as hexadecimal, do not strip dashes
#- always quote the key as string
- my ($key) = @_;
- member(length($key), (5, 13)) ? "s:$key" : $key;
+ my ($real_key, $restricted) = @_;
+ my $key = member(length($real_key), (5, 13)) ? "s:$real_key" : $real_key;
+ $restricted ? "restricted $key" : "open $key";
}
sub get_wep_key_from_iwconfig {
@@ -19,7 +17,8 @@ sub get_wep_key_from_iwconfig {
#- else the key as hexadecimal, do not modify
my ($key) = @_;
$key =~ s/^s:// if member(length($key), (7,15));
- $key;
+ my ($mode, $real_key) = $key =~ /^(?:(open|restricted)\s+)?(.*)$/;
+ ($real_key, $mode eq 'restricted');
}
sub convert_key_for_wpa_supplicant {
@@ -170,104 +169,4 @@ sub wpa_supplicant_add_network {
chmod 0600, $wpa_supplicant_conf;
}
-my $ndiswrapper_prefix = "$::prefix/etc/ndiswrapper";
-
-sub ndiswrapper_installed_drivers() {
- grep { -d "$ndiswrapper_prefix/$_" } all($ndiswrapper_prefix);
-}
-
-sub ndiswrapper_present_devices {
- my ($driver) = @_;
- my @supported_devices;
- foreach (all("$ndiswrapper_prefix/$driver")) {
- my ($ids) = /^([0-9A-Z]{4}:[0-9A-Z]{4})\.[05]\.conf$/;
- $ids and push @supported_devices, $ids;
- }
- grep { member(uc(sprintf("%04x:%04x", $_->{vendor}, $_->{id})), @supported_devices) } detect_devices::probeall();
-}
-
-sub ndiswrapper_get_devices {
- my ($in, $driver) = @_;
- my @devices = ndiswrapper_present_devices($driver);
- @devices or $in->ask_warn(N("Error"), N("No device supporting the %s ndiswrapper driver is present!", $driver));
- @devices;
-}
-
-sub ndiswrapper_ask_driver {
- my ($in) = @_;
- if (my $inf_file = $in->ask_file(N("Please select the Windows driver (.inf file)"), "/mnt/cdrom")) {
- my $driver = basename(lc($inf_file));
- $driver =~ s/\.inf$//;
-
- #- first uninstall the driver if present, may solve issues if it is corrupted
- -d "$ndiswrapper_prefix/$driver" and system('ndiswrapper', '-e', $driver);
-
- unless (system('ndiswrapper', '-i', $inf_file) == 0) {
- $in->ask_warn(N("Error"), N("Unable to install the %s ndiswrapper driver!", $driver));
- return undef;
- }
-
- return $driver;
- }
- undef;
-}
-
-sub ndiswrapper_find_matching_devices {
- my ($device) = @_;
- my $net_path = '/sys/class/net';
- my @devices;
-
- foreach my $interface (all($net_path)) {
- my $dev_path = "$net_path/$interface/device";
- -l $dev_path or next;
-
- my %map = (vendor => 'vendor', device => 'id');
- if (every { hex(chomp_(cat_("$dev_path/$_"))) eq $device->{$map{$_}} } keys %map) {
- my $driver = readlink("$net_path/$interface/driver");
- $driver =~ s!.*/!!;
- push @devices, [ $interface, $driver ];
- }
- }
-
- @devices;
-}
-
-sub ndiswrapper_find_conflicting_devices {
- my ($device) = @_;
- grep { $_->[1] ne "ndiswrapper" } ndiswrapper_find_matching_devices($device);
-}
-
-sub ndiswrapper_find_interface {
- my ($device) = @_;
- my $dev = find { $_->[1] eq "ndiswrapper" } ndiswrapper_find_matching_devices($device);
- $dev->[0];
-}
-
-sub ndiswrapper_setup_device {
- my ($in, $device) = @_;
-
- eval { modules::unload("ndiswrapper") };
- #- unload ndiswrapper first so that the newly installed .inf files will be read
- eval { modules::load("ndiswrapper") };
-
- if ($@) {
- $in->ask_warn(N("Error"), N("Unable to load the ndiswrapper module!"));
- return;
- }
-
- my @ndiswrapper_conflicts = ndiswrapper_find_conflicting_devices($device);
- if (@ndiswrapper_conflicts) {
- $in->ask_yesorno(N("Warning"), N("The selected device has already been configured with the %s driver.
-Do you really want to use a ndiswrapper driver ?", $ndiswrapper_conflicts[0][1])) or return;
- }
-
- my $interface = ndiswrapper_find_interface($device);
- unless ($interface) {
- $in->ask_warn(N("Error"), N("Unable to find the ndiswrapper interface!"));
- return;
- }
-
- $interface;
-}
-
1;