?? ndiswrapper
字號:
#!/usr/bin/perl#/*#* This program is free software; you can redistribute it and/or modify#* it under the terms of the GNU General Public License as published by#* the Free Software Foundation; either version 2 of the License, or#* (at your option) any later version.#*#* This program is distributed in the hope that it will be useful,#* but WITHOUT ANY WARRANTY; without even the implied warranty of#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the#* GNU General Public License for more details.#*#*/use strict;use Fcntl ':mode';my @sections;my %strings;my %version;my $driver_name;my $confdir = "/etc/ndiswrapper";my $hotplug_conf = "modules.ndiswrapper";my $instdir;my %fuzzlist;my $bustype;#Blacklist of files not to install.my @copy_blacklist;#Fixup list for parameters. my %param_fixlist = ("EnableRadio|0" => "EnableRadio|1", "IBSSGMode|0" => "IBSSGMode|2", "PrivacyMode|0" => "PrivacyMode|2");if(@ARGV < 1){ usage(); exit();}my $res;if($ARGV[0] eq "-i" and @ARGV == 2){ $res = install($ARGV[1]);}elsif($ARGV[0] eq "-d" and @ARGV == 3){ $res = devid_driver($ARGV[1], $ARGV[2]);}elsif($ARGV[0] eq "-e" and @ARGV == 2){ $res = remove($ARGV[1]);}elsif($ARGV[0] eq "-l" and @ARGV == 1){ $res = list();}elsif($ARGV[0] eq "-m" and @ARGV == 1){ $res = modconf();}elsif($ARGV[0] eq "-hotplug" and @ARGV == 1){ $res = hotplug_conf();}else{ usage(); exit();}exit $res;sub usage{ print "Usage: ndiswrapper OPTION\n". "\n". "Manage ndis drivers for ndiswrapper.\n". "-i inffile Install driver described by 'inffile'\n". "-d devid driver Use installed 'driver' for 'devid'\n". "-e driver Remove 'driver'\n". "-l List installed drivers\n". "-m Write configuration for modprobe\n". "-hotplug (Re)Generate hotplug information\n". "\n\nwhere 'devid' is either PCIID or USBID of the form ". "XXXX:XXXX\n"; }sub install{ my $inf = shift; $driver_name = lc($inf); $driver_name =~ s/\.inf//; $driver_name = `basename $driver_name`; $instdir = `dirname $inf`; chomp($instdir); chomp($driver_name); if(isInstalled($driver_name)) { print "$driver_name is already installed. Use -e to remove it\n"; return -1; } if(!opendir(DH, $confdir)) { mkdir($confdir); } else { close(DH); } print "Installing $driver_name\n"; if(!mkdir("$confdir/$driver_name")) { print "Unable to create directory $confdir/$driver_name. Make sure you are running as root\n"; return -1; } loadinf($inf); initStrings(); parseVersion(); `cp -u $inf $confdir/$driver_name/$driver_name.inf`; processPCIFuzz();}sub isInstalled{ my $installed; my $name = shift; my $mode = (stat("$confdir"))[2]; if (!S_ISDIR($mode)) { return 0; } open(LS, "ls -1 $confdir|"); while(my $f = <LS>) { chomp($f); $mode = (stat("$confdir/$f"))[2]; if(S_ISDIR($mode) and $name eq $f) { $installed = 1; } } close(LS); return $installed;}sub remove{ my $name = shift; if(!isInstalled($name)) { print "Driver $name is not installed. Use -l to list installed drivers\n"; return; } `rm -rf $confdir/$name`;}sub devid_driver{ my $devid = shift; my $driver = shift; my $done = 0; $devid = uc($devid); if (!($devid =~ /[0-9A-Z]{4}:[0-9A-Z]{4}/)) { print "'$devid' is not a valid device ID\n"; return; } open(LS, "ls -1 $confdir/$driver/ |"); while(my $f = <LS>) { chomp($f); if ($f =~ /\.([05]).conf$/) { `ln -s $f $confdir/$driver/$devid.$1.conf`; print "Driver '$driver' is used for '$devid'\n"; $done = 1; last; } } close(LS); if ($done == 0) { print "Driver '$driver' is not installed properly!\n"; } return;}sub hotplug_conf{ my $vendor; my $device; my $subvendor; my $subdevice; if(!open(CONF, ">$confdir/$hotplug_conf")) { print "Unable to create file hotplug modules configuration file"; return -1; } printf CONF "# pci module vendor device subvendor subdevice class class_mask driver_data"; open(LS, "ls -1 $confdir|"); while(my $driver = <LS>) { chomp($driver); my $mode = (stat("$confdir/$driver"))[2]; if(S_ISDIR($mode)) { open(LS2, "ls -1 $confdir/$driver/ |"); while (my $file = <LS2>) { chomp ($file); if ($file =~ s/.conf//) { $file = lc($file); if($file =~ /(.{4}):(.{4}):(.{4}):(.{4})/) { $vendor = "0x0000$1"; $device = "0x0000$2"; $subvendor = "0x0000$3"; $subdevice = "0x0000$4"; } elsif($file =~ /(.{4}):(.{4})/) { $vendor = "0x0000$1"; $device = "0x0000$2"; $subvendor = "0xffffffff"; $subdevice = "0xffffffff"; } printf CONF "ndiswrapper $vendor $device $subvendor $subdevice 0x00000000 0x00000000 0x0\n"; } } close(LS2); } } close(CONF); close(LS); return 0;}sub list{ my $s; my $cards = getPresentCards(); if(!$cards) { print "WARNING: Cannot locate lspci and lsusb. Unable to see if hardware is present.\n"; } my $mode = (stat("$confdir"))[2]; if (!S_ISDIR($mode)) { print "No drivers installed\n$s"; return; } open(LS, "ls -1 $confdir|"); while(my $f = <LS>) { chomp($f); my $mode = (stat("$confdir/$f"))[2]; if(S_ISDIR($mode)) { $s .= "$f\t".installStatus($cards, $f)."\n"; } } if($s) { print "Installed ndis drivers:\n$s"; } else { print "No drivers installed\n$s"; } close(LS); }sub modconf{ my $alias = 0; my $err = 0; my @modprobe = ("/sbin/modprobe", "/usr/sbin/modprobe", "modprobe"); my $ok = 0; for(my $i = 0; $i < @modprobe; $i++) { if(open(MODPROBE, "$modprobe[$i] -c|")) { $ok = 1; $i = @modprobe; } } if(!$ok) { return -1; } while(my $line = <MODPROBE>) { if($line =~ /^alias\s.+\sndiswrapper/) { print "modprobe config already contains alias directive\n\n"; $alias = 1; } elsif($line =~ /^install\s.*ndiswrapper/) { print "You should not need an install directive in you modprobe config file.\n"; modconf_err($line); $err = 1; } elsif($line =~ /^post-install\s+ndiswrapper/) { print "You should not need a post-install directive in you modprobe config file.\n"; modconf_err($line); $err = 1; } } close(MODPROBE); if($alias) { return; } my $v = `uname -r`; $v =~ /(\d+)\.(\d+)\.(\d+)/; my $major = $1; my $minor = $2; my $rev = $3; my $modconf; if($minor > 4) { if(-d "/etc/modprobe.d") { $modconf = "/etc/modprobe.d/ndiswrapper" } else { $modconf = "/etc/modprobe.conf" } } else { if(-d "/etc/modutils") { $modconf = "/etc/modutils/ndiswrapper"; } else { $modconf = "/etc/modules.conf"; } } print "Adding \"alias wlan0 ndiswrapper\" to $modconf\n"; system("echo \"alias wlan0 ndiswrapper\" >>$modconf"); if(-x "/sbin/update-modules") { system("/sbin/update-modules"); }}sub modconf_err{ my $line = shift; print "Please remove the line saying:\n\n"; print "$line\n"; print "unless you are 100% sure of what you are doing.\n"; }sub getPresentCards{#01:00.0 Class 0300: 1002:4c66 (rev 01)# Subsystem: 1043:1732 my @cards; my @lspci = ("/sbin/lspci", "/usr/sbin/lspci", "lspci"); for(my $i = 0; $i < @lspci; $i++) { if(open(LSPCI, "$lspci[$i] -vn|")) { my $card; while(my $line = <LSPCI>) { if($line =~ /^[0-9]+.*:\s(.{4}):(.{4}).*/) { my %c; $card = \%c; $card->{vendor} = $1; $card->{device} = $2; } if($line =~ /.+Subsystem:\s*(.{4}):(.{4}).*/) { $card->{subvendor} = $1; $card->{subdevice} = $2; push(@cards, $card); } } last; } } my @lsusb = ("/sbin/lsusb", "/usr/sbin/lsusb", "lsusb"); for(my $i = 0; $i < @lsusb; $i++) { if(open(LSUSB, "$lsusb[$i] |")) { my $card; while(my $line = <LSUSB>) { if($line =~ /.*: ID\s(.{4}):(.{4}).*/) { my %c; $card = \%c; $card->{vendor} = $1; $card->{device} = $2; push(@cards, $card); } } last; } } return \@cards;}sub installStatus{ my $cards = shift; my $driver = shift; my $sys = 0; my $conf = 0; my $inf = 0; if(!$cards) { return; } open(LS2, "ls -1 $confdir/$driver|"); while(my $device = <LS2>) { chomp($device); my $d = $device; $sys = 1 if $d =~ /\.sys$/; $inf = 1 if $d =~ /\.inf$/; $conf = 1 if $conf eq 0 and $d =~ /\.conf$/; $d =~ s/.conf//; if($d =~ /(.{4}):(.{4}):(.{4}):(.{4})/) { for(my $i = 0; $$cards[$i]; $i++) { if($$cards[$i]->{vendor} == $1 and $$cards[$i]->{device} == $2 and $$cards[$i]->{subvendor} == $3 and $$cards[$i]->{subdevice} == $4) { $conf = 3; last; } } } elsif($d =~ /(.{4}):(.{4})/) { for(my $i = 0; $$cards[$i]; $i++) { if($$cards[$i]->{vendor} == $1 and $$cards[$i]->{device} == $2) { my $mode = (lstat("$confdir/$driver/$device"))[2]; if(S_ISLNK($mode)) { $conf = 2; } else { $conf = 3; } last; } } } } close(LS2); my $ret; if ($sys eq 0 || $inf eq 0 || $conf eq 0) { $ret = "invalid driver!"; } else { $ret = $ret . "driver present " if $conf eq 1; $ret = $ret . "driver present, hardware present " if $conf eq 2; $ret = $ret . "driver present, hardware present " if $conf eq 3; } return $ret;}## Create symlink for PCI general device if not existing#sub processPCIFuzz{ my @devs = keys(%fuzzlist); for(my $i = 0; $i < @devs; $i++) { my $dev = $devs[$i]; if($dev ne $fuzzlist{$dev}) { `ln -s $confdir/$driver_name/$fuzzlist{$dev}.$bustype.conf $confdir/$driver_name/$dev.$bustype.conf`; } }}## Collect a list of supported PCI-Id's so we can add fuzzy entries if needed.#sub addPCIFuzzEntry{ my $vendor = shift; my $device = shift; my $subvendor = shift; my $subdevice = shift; my $s = "$vendor:$device"; if(!$subvendor or !$fuzzlist{$s}) { my $s2 = $s; if($subvendor) { $s2 .= ":$subvendor:$subdevice"; } $fuzzlist{$s} = $s2; }}sub parseVersion{ my $s = getSection("version"); if(!$s) { return; } my @lines = split("\n", $s->{data}); for(my $i = 0; $i < @lines; $i++) { (my $key, my $val) = getKeyVal($lines[$i]); if($key eq "Provider") { $val =~ s/"(.+)"/$1/; $version{$key} = $val; } if($key eq "DriverVer") { $val =~ s/"(.+)"/$1/; $version{$key} = $val; } } parseManu();}## Parse the [Manufacturer] section.#sub parseManu{
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -