~ubuntu-branches/ubuntu/lucid/ndiswrapper/lucid

« back to all changes in this revision

Viewing changes to utils/ndiswrapper

  • Committer: Bazaar Package Importer
  • Author(s): Andres Salomon
  • Date: 2005-01-09 19:40:16 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050109194016-q0wfc6kf43uog0bb
Tags: 0.12+1.0rc2-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
my %version;
23
23
my $driver_name;
24
24
my $confdir = "/etc/ndiswrapper";
 
25
my $hotplug_conf = "modules.ndiswrapper";
25
26
my $instdir;
26
27
my %fuzzlist;
27
28
 
28
 
#Backlist of files not to install.
29
 
my @copy_blacklist = ("prismusb.sys");
 
29
#Blacklist of files not to install.
 
30
my @copy_blacklist;
30
31
 
31
32
#Fixup list for parameters. 
32
33
my %param_fixlist = ("EnableRadio|0" => "EnableRadio|1",
33
 
                     "PrivacyMode|0" => "PrivacyMode|1"); 
34
 
 
35
 
print <<EOF;
36
 
WARNING:
37
 
This tool allows you to use a driver written for the Windows operating
38
 
system on Ubuntu. Please note that the use of such drivers is entirely
39
 
unsupportable by the Ubuntu team, and not recommended, even if it is
40
 
theoretically possible with this tool.
41
 
 
42
 
EOF
 
34
                     "IBSSGMode|0" => "IBSSGMode|2",
 
35
                     "PrivacyMode|0" => "PrivacyMode|2",
 
36
                     "RadioState|0" => "RadioState|1"); 
43
37
 
44
38
if(@ARGV < 1)
45
39
{
52
46
{
53
47
        $res = install($ARGV[1]);
54
48
}
 
49
elsif($ARGV[0] eq "-d" and @ARGV == 3)
 
50
{
 
51
        $res = pciid_driver($ARGV[1], $ARGV[2]);
 
52
}
55
53
elsif($ARGV[0] eq "-e" and @ARGV == 2)
56
54
{
57
55
        $res = remove($ARGV[1]);
64
62
{
65
63
        $res = modconf();
66
64
}
 
65
elsif($ARGV[0] eq "-hotplug" and @ARGV == 1)
 
66
{
 
67
        $res = hotplug_conf();
 
68
}
67
69
else
68
70
{
69
71
        usage();
77
79
        print "Usage: ndiswrapper OPTION\n".
78
80
              "\n".
79
81
              "Manage ndis drivers for ndiswrapper.\n".
80
 
              "-i inffile   Install driver described by inffile\n".
81
 
              "-e driver    Remove driver\n".
82
 
              "-l           List installed drivers\n".
83
 
              "-m           Write configuration for modprobe\n";
 
82
              "-i inffile        Install driver described by 'inffile'\n".
 
83
              "-d pciid driver   Use installed 'driver' for 'pciid'\n".
 
84
              "-e driver         Remove 'driver'\n".
 
85
              "-l                List installed drivers\n".
 
86
              "-m                Write configuration for modprobe\n".
 
87
              "-hotplug          (Re)Generate hotplug information\n";
84
88
}
85
89
 
86
90
 
156
160
        `rm -rf $confdir/$name`;
157
161
}
158
162
 
 
163
sub pciid_driver
 
164
{
 
165
        my $pciid = shift;
 
166
        my $driver = shift;
 
167
        my $done = 0;
 
168
 
 
169
        $pciid = uc($pciid);
 
170
        if (!($pciid =~ /[0-9A-Z]{4}:[0-9A-Z]{4}/))
 
171
        {
 
172
                print "'$pciid' is not a valid PCIID\n";
 
173
                return;
 
174
        }
 
175
        open(LS, "ls -1 $confdir/$driver/ |");
 
176
        while(my $f = <LS>)
 
177
        {
 
178
                chomp($f);
 
179
                if ($f =~ /\.conf$/)
 
180
                {
 
181
                        `ln -s $f $confdir/$driver/$pciid.conf`;
 
182
                        print "Driver '$driver' is used for PCIID '$pciid'\n";
 
183
                        $done = 1;
 
184
                        last;
 
185
                }
 
186
        }
 
187
        close(LS);      
 
188
        if ($done == 0)
 
189
        {
 
190
                print "Driver '$driver' is not installed properly!\n";
 
191
        }
 
192
        return;
 
193
}
 
194
 
 
195
sub hotplug_conf
 
196
{
 
197
        my $vendor;
 
198
        my $device;
 
199
        my $subvendor;
 
200
        my $subdevice;
 
201
        if(!open(CONF, ">$confdir/$hotplug_conf")) {
 
202
                print "Unable to create file hotplug modules configuration file";
 
203
                return -1;
 
204
        }
 
205
        printf CONF "# pci module         vendor     device     subvendor  subdevice  class      class_mask driver_data";
 
206
 
 
207
        open(LS, "ls -1 $confdir|");
 
208
        while(my $driver = <LS>) {
 
209
                chomp($driver);
 
210
                my $mode = (stat("$confdir/$driver"))[2];
 
211
                if(S_ISDIR($mode)) {
 
212
                        open(LS2, "ls -1 $confdir/$driver/ |");
 
213
                        while (my $file = <LS2>) {
 
214
                                chomp ($file);
 
215
                                if ($file =~ s/.conf//) {
 
216
                                        $file = lc($file);
 
217
                                        if($file =~ /(.{4}):(.{4}):(.{4}):(.{4})/) {
 
218
                                                $vendor = "0x0000$1";
 
219
                                                $device = "0x0000$2";
 
220
                                                $subvendor = "0x0000$3";
 
221
                                                $subdevice = "0x0000$4";
 
222
                                        }
 
223
                                        elsif($file =~ /(.{4}):(.{4})/) {
 
224
                                                $vendor = "0x0000$1";
 
225
                                                $device = "0x0000$2";
 
226
                                                $subvendor = "0xffffffff";
 
227
                                                $subdevice = "0xffffffff";
 
228
                                        }
 
229
                                        printf CONF "ndiswrapper    $vendor $device $subvendor $subdevice 0x00000000 0x00000000 0x0\n";
 
230
                                }
 
231
                        }
 
232
                        close(LS2);
 
233
                }
 
234
        }
 
235
 
 
236
        close(CONF);
 
237
        close(LS);
 
238
        return 0;
 
239
}
 
240
 
159
241
sub list
160
242
{
161
243
        my $s;
164
246
 
165
247
        if(!$cards)
166
248
        {
167
 
                print "WARNING: Cannot locate lspci. Unable to see if hardware is present.\n";
 
249
                print "WARNING: Cannot locate lspci and lsusb. Unable to see if hardware is present.\n";
168
250
        }
169
251
 
170
252
        open(LS, "ls -1 $confdir|");
316
398
                                }
317
399
                                        
318
400
                        }
319
 
                        return \@cards;
320
 
                }
321
 
        }
 
401
                        last;
 
402
                }
 
403
        }
 
404
 
 
405
        my @lsusb = ("/sbin/lsusb", "/usr/sbin/lsusb", "lsusb");
 
406
        for(my $i = 0; $i < @lsusb; $i++)
 
407
        {
 
408
                if(open(LSUSB, "$lsusb[$i] |"))
 
409
                {
 
410
                        my $card;
 
411
                        while(my $line = <LSUSB>)
 
412
                        {
 
413
                                if($line =~ /.*: ID\s(.{4}):(.{4}).*/)
 
414
                                {
 
415
                                        my %c;
 
416
                                        $card = \%c;
 
417
                                        $card->{vendor} = $1;
 
418
                                        $card->{device} = $2;
 
419
 
 
420
                                        push(@cards, $card);
 
421
                                }
 
422
                        }
 
423
                        last;
 
424
                }
 
425
        }
 
426
 
 
427
        return \@cards;
322
428
}
323
429
 
324
430
 
327
433
        my $cards = shift; 
328
434
        my $driver = shift;     
329
435
 
 
436
        my $sys = 0;
 
437
        my $conf = 0;
 
438
        my $inf = 0;
 
439
 
330
440
        if(!$cards)
331
441
        {
332
442
                return;
333
443
        }
334
444
 
335
445
        open(LS2, "ls -1 $confdir/$driver|");
336
 
        my $ret = "hardware NOT present";
337
446
 
338
447
        while(my $device = <LS2>)
339
448
        {
340
449
                chomp($device);
341
450
                my $d = $device;
 
451
 
 
452
                $sys = 1 if $d =~ /\.sys$/;
 
453
                $inf = 1 if $d =~ /\.inf$/;
 
454
                $conf = 1 if $conf eq 0 and $d =~ /\.conf$/;
342
455
                $d =~ s/.conf//;
343
456
                if($d =~ /(.{4}):(.{4}):(.{4}):(.{4})/)
344
457
                {
349
462
                                   $$cards[$i]->{subvendor} == $3 and
350
463
                                   $$cards[$i]->{subdevice} == $4)
351
464
                                {
352
 
                                        close(LS2);     
353
 
                                        return "hardware present";
 
465
                                        $conf = 3;
 
466
                                        last;
354
467
                                }
355
468
                        }
356
469
                        
365
478
                                        my $mode = (lstat("$confdir/$driver/$device"))[2];
366
479
                                        if(S_ISLNK($mode))
367
480
                                        {
368
 
                                                $ret = "hardware present,fuzzy";
 
481
                                                $conf = 2;
369
482
                                        }
370
483
                                        else
371
484
                                        {
372
 
                                                close(LS2);     
373
 
                                                return "hardware present";
 
485
                                                $conf = 3;
374
486
                                        }
 
487
                                        last;
375
488
                                }
376
489
                        }
377
490
                }
378
491
        }
379
492
        close(LS2);     
 
493
 
 
494
        my $ret;
 
495
        if ($sys eq 0 || $inf eq 0 || $conf eq 0)
 
496
        {
 
497
                $ret = "invalid driver!";
 
498
        }
 
499
        else
 
500
        {
 
501
                $ret = $ret . "driver present " if $conf eq 1;
 
502
                $ret = $ret . "driver present, hardware present " if
 
503
                        $conf eq 2;
 
504
                $ret = $ret . "driver present, hardware present " if
 
505
                        $conf eq 3;
 
506
        }
380
507
        return $ret;
381
508
}
382
509
 
572
699
        }
573
700
        if(!$dev)
574
701
        {
 
702
                $dev = getSection("$device_sect.NTx86");
 
703
        }
 
704
        if(!$dev)
 
705
        {
575
706
                $dev = getSection("$device_sect");
576
707
        }
577
708
 
623
754
                return -1;
624
755
        }
625
756
 
 
757
        my $ver=$version{"DriverVer"};
 
758
        my $provider=$version{"Provider"};
 
759
        my $providerstring = stripquotes(substStr(trim($provider)));
 
760
 
626
761
        printf CONF "NdisVersion|0x50001\n";
627
762
        printf CONF "Environment|1\n";
628
763
        printf CONF "BusType|$bustype\n";
629
 
        my $ver=$version{"DriverVer"};
630
 
        my $provider=$version{"Provider"};
631
 
        my $providerstring = stripquotes(substStr(trim($provider)));
 
764
        printf CONF "mac_address|XX:XX:XX:XX:XX:XX\n";
632
765
        printf CONF "ndis_version|$providerstring,$ver\n\n";
 
766
        close(CONF);
 
767
 
 
768
        if(!open(CONF, "|sort|uniq >>$confdir/$driver_name/$filename"))
 
769
        {
 
770
                print "Unable to create file $filename";
 
771
                return -1;
 
772
        }
633
773
 
634
774
        my @addregs = split(",", $addreg);
635
775
        for(my $i = 0; $i < @addregs; $i++)
666
806
 
667
807
        for(my $i = 0; $i < @lines; $i++)
668
808
        {
669
 
                my $line = trim(remComment($lines[$i]));
 
809
          my $line = $lines[$i];
 
810
          $line = trim($line);
670
811
 
671
 
                if($line)
672
 
                {
673
 
                        $line =~ s/,+.*//;
674
 
                        $line = trim($line);
675
 
                        my $nocopy = 0;
676
 
                        for(my $j = 0; $j < @copy_blacklist; $j++)
 
812
          last if (!$line);
 
813
          last if ($line =~ /^\[/);
 
814
          my @files = split(",", $line);
 
815
          for (my $j = 0; $j < @files; $j++)
 
816
            {
 
817
              my $file = $files[$j];
 
818
              $file =~ s/^;//;
 
819
              $file = trim(remComment($file));
 
820
              $file =~ s/,+.*//;
 
821
              $file = trim($file);
 
822
              my $nocopy = 0;
 
823
              for(my $k = 0; $k < @copy_blacklist; $k++)
677
824
                        {
678
 
                                if($copy_blacklist[$j] eq lc($line))
 
825
                                if($copy_blacklist[$k] eq lc($file))
679
826
                                {
680
827
                                        $nocopy = 1;
681
828
                                }
682
829
                        }
683
830
 
684
 
                        my $dir = finddir($line);
 
831
                        my $dir = finddir($file);
685
832
                        if($dir)
686
833
                        {
687
834
                                $dir = findfile("", $dir);
688
835
                        }
689
836
 
690
 
                        my $realname = findfile($dir, $line);
 
837
                        my $realname = findfile($dir, $file);
691
838
 
692
839
                        if($realname)
693
840
                        {
703
850
                                }
704
851
                                
705
852
                        }
706
 
                        else
707
 
                        {
708
 
                                print STDERR "Warning: Cannot locate $line\n";
709
 
                        }
710
 
                        
711
853
                }
712
854
        }
713
855
}