/[pcsclite]/trunk/pcsc-tools/trunk/scriptor
ViewVC logotype

Diff of /trunk/pcsc-tools/trunk/scriptor

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3648 by rousseau, Sat May 24 22:10:34 2003 UTC revision 3649 by rousseau, Fri Oct 17 21:28:29 2003 UTC
# Line 18  Line 18 
18  #    along with this program; if not, write to the Free Software  #    along with this program; if not, write to the Free Software
19  #    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA  #    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20    
21  # $Id: scriptor,v 1.8 2003-05-24 22:10:34 rousseau Exp $  # $Id: scriptor,v 1.9 2003-10-17 21:28:29 rousseau Exp $
22    
23  use Getopt::Std;  use Getopt::Std;
24  use Chipcard::PCSC;  use Chipcard::PCSC;
25  use Chipcard::PCSC::Card;  use Chipcard::PCSC::Card;
26    
27  use strict;  use strict;
28    use warnings;
29    
30  my %options;  my %options;
31    
# Line 35  my $in_buffer; Line 36  my $in_buffer;
36    
37  die ("Could not create Chipcard::PCSC object: $Chipcard::PCSC::errno\n") unless defined $hContext;  die ("Could not create Chipcard::PCSC object: $Chipcard::PCSC::errno\n") unless defined $hContext;
38    
39  getopt ("r:", \%options);  getopt ("r:p:" , \%options);
40    
41  if ($options{h}) {  if ($options{h}) {
42          print "Usage: $0 [-h] [-r reader] [file]\n";          print "Usage: $0 [-h] [-r reader] [-p protocol] [file]\n";
43          print "         -h: this help\n";          print "          -h: this help\n";
44          print "  -r reader: specify to use the PCSC smart card reader named reader\n";          print "   -r reader: specify to use the PCSC smart card reader named reader\n";
45          print "             By defaults the first one found is used so you\n";          print "              By defaults the first one found is used so you\n";
46          print "             don't have to specify anything if you just have\n";          print "              don't have to specify anything if you just have\n";
47          print "             one reader\n";          print "              one reader\n";
48          print "       file: file containing APDUs\n";          print " -p protocol: protocol to use among T=0 and T=1. Default is T=0\n";
49            print "        file: file containing APDUs\n";
50          exit (0);          exit (0);
51  }  }
52    
53    # protocol option
54    if ($options{p}) {
55            if ($options{p} =~ m/T=0/) {
56                    print STDERR "Using T=0 protocol\n";
57                    $options{p} = $Chipcard::PCSC::SCARD_PROTOCOL_T0;
58            } else {
59                    if ($options{p} =~ m/T=1/) {
60                            print STDERR "Using T=1 protocol\n";
61                            $options{p} = $Chipcard::PCSC::SCARD_PROTOCOL_T1;
62                    } else {
63                            die "unknown protocol: $options{p}\n";
64                    }
65            }
66    } else {
67            print STDERR "No protocol given: using T=0\n";
68            $options{p} = $Chipcard::PCSC::SCARD_PROTOCOL_T0;
69    }
70    
71    # reader option
72  if ($options{r}) {  if ($options{r}) {
         $hCard = new Chipcard::PCSC::Card ($hContext, $options{r});  
         die ("Can't allocate Chipcard::PCSC::Card object: $Chipcard::PCSC::errno\n") unless defined $hCard;  
73          print STDERR "Using given card reader: $options{r}\n";          print STDERR "Using given card reader: $options{r}\n";
74  } else {  } else {
75          my @readers_list = $hContext->ListReaders ();          my @readers_list = $hContext->ListReaders ();
76          die ("Can't get readers list: $Chipcard::PCSC::errno\n") unless defined $readers_list[0];          die ("Can't get readers list: $Chipcard::PCSC::errno\n") unless defined $readers_list[0];
77          print STDERR "No reader given: using $readers_list[0]\n";          print STDERR "No reader given: using $readers_list[0]\n";
78          $hCard = new Chipcard::PCSC::Card ($hContext, $readers_list[0]);          $options{r} = $readers_list[0];
         die ("Can't allocate Chipcard::PCSC::Card object: $Chipcard::PCSC::errno\n") unless defined $hCard;  
79  }  }
80    
81    $hCard = new Chipcard::PCSC::Card ($hContext, $options{r}, $Chipcard::PCSC::SCARD_SHARE_EXCLUSIVE, $options{p});
82    die ("Can't allocate Chipcard::PCSC::Card object: $Chipcard::PCSC::errno\n") unless defined $hCard;
83    
84    # file option
85  if ($ARGV[0]) {  if ($ARGV[0]) {
86          open (IN_FILEHANDLE, "<$ARGV[0]") or die ("Can't open $ARGV[0]: $!\n");          open (IN_FILEHANDLE, "<$ARGV[0]") or die ("Can't open $ARGV[0]: $!\n");
87          print STDERR "Using given file: $ARGV[0]\n";          print STDERR "Using given file: $ARGV[0]\n";
# Line 81  while (<IN_FILEHANDLE>) { Line 103  while (<IN_FILEHANDLE>) {
103          if (/reset/i) {          if (/reset/i) {
104                  print OUT_FILEHANDLE "> RESET\n";                  print OUT_FILEHANDLE "> RESET\n";
105                  if (defined $hCard->Reconnect ($Chipcard::PCSC::SCARD_SHARE_EXCLUSIVE,                  if (defined $hCard->Reconnect ($Chipcard::PCSC::SCARD_SHARE_EXCLUSIVE,
106                                     $Chipcard::PCSC::SCARD_PROTOCOL_T0,                                     $options{p},
107                                                     $Chipcard::PCSC::SCARD_RESET_CARD)) {                                                     $Chipcard::PCSC::SCARD_RESET_CARD)) {
108                          print OUT_FILEHANDLE "< OK\n";                          print OUT_FILEHANDLE "< OK\n";
109                  } else {                  } else {

Legend:
Removed from v.3648  
changed lines
  Added in v.3649

  ViewVC Help
Powered by ViewVC 1.1.5