Debian Codegraph @

PCSC.pod

raw
1 =head1 NAME
2
3 Chipcard::PCSC - Smart card reader interface library
4
5 =head1 SYNOPSIS
6
7 my $hContext = new Chipcard::PCSC();
8
9 @ReadersList = $hContext->ListReaders ();
10
11 $hContext->GetStatusChange(\@readers_states, $timeout);
12
13 $apdu = Chipcard::PCSC::array_to_ascii(@apdu);
14
15 @apdu = Chipcard::PCSC::ascii_to_array($apdu);
16
17 $hContext = undef;
18
19 =head1 DESCRIPTION
20
21 The PCSC module implements the Chipcard::PCSC class. Objects of this
22 class are used to communicate with the PCSC-lite daemon (see F<pcscd(1)>
23 for more information).
24
25 PC/SC represents an abstraction layer to smart card readers. It provides
26 a communication layer with a wide variety of smart card readers through
27 a standardized API.
28
29 A PCSC object can be used to communicate with more than one reader
30 through Chipcard::PCSC::Card objects. Please read
31 L<Chipcard::PCSC::Card> for extended information on how to talk to a
32 smart card reader.
33
34 A PCSC object uses the following property:
35 C<$pcsc_object-E<gt>{hContext}> the context returned by the pcsc library
36
37 =head1 CONSTRUCTORS
38
39 The following methods can be used to construct a PCSC object:
40
41 =over 4
42
43 =item *
44 B<$hContext = new Chipcard::PCSC($scope, $remote_host);>
45
46 =over 4
47
48 =item *
49
50 C<$scope> is the scope of the connection to the PC/SC daemon. It can be
51 any of the following:
52
53 $Chipcard::PCSC::SCARD_SCOPE_USER (not used by PCSClite);
54 $Chipcard::PCSC::SCARD_SCOPE_TERMINAL (not used by PCSClite);
55 $Chipcard::PCSC::SCARD_SCOPE_SYSTEM Services on the local machine;
56 $Chipcard::PCSC::SCARD_SCOPE_GLOBAL Services on a remote host.
57
58 =item *
59
60 C<$remote_host> is the host name of the remote machine to contact. It is
61 only used when C<$scope> is equal to
62 C<$Chipcard::PCSC::SCARD_SCOPE_GLOBAL>. A null value means F<localhost>.
63
64 =back
65
66 =item *
67 B<$hContext = new Chipcard::PCSC($scope);>
68
69 This method is equivalent to:
70
71 $hContext = new Chipcard::PCSC($scope, 0);
72
73 =item *
74 B<$hContext = new Chipcard::PCSC();>
75
76 This method is equivalent to:
77
78 $hContext = new Chipcard::PCSC($Chipcard::PCSC::SCARD_SCOPE_SYSTEM, 0);
79
80 =back
81
82 =head1 CONSTRUCTION FAILURE
83
84 Chipcard::PCSC constructors return an C<undef> value when the object can
85 not be created. C<$Chipcard::PCSC::errno> can be used to get more
86 information about the error. (See section L<ERROR HANDLING> below for
87 more information)
88
89 =head1 Chipcard::PCSC METHODS
90
91 Here is a list of all the methods that can be used with a PCSC object.
92
93 =over 4
94
95 =item *
96 B<hContext-E<gt>ListReaders( $group );>
97
98 This method returns the available readers in the given C<$group>. If
99 omitted, C<$group> defaults to a null value meaning "all groups". Please
100 note that as of this writing, C<$group> can safely be omitted as it is
101 not used by PCSClite.
102
103 The return value upon successful completion is an array of strings: one
104 string by available reader. If an error occurred, the undef value is
105 returned and C<$Chipcard::PCSC::errno> should be used to get more
106 information about the error. (See section L<ERROR HANDLING> below for
107 more information). The following example describes the use of
108 L<ListReaders>:
109
110 $hContext = new Chipcard::PCSC();
111 die ("Can't create the PCSC object: $Chipcard::PCSC::errno\n")
112 unless (defined $hContext);
113
114 @ReadersList = $hContext->ListReaders ();
115 die ("Can't get readers' list: $Chipcard::PCSC::errno\n")
116 unless (defined($ReadersList[0]));
117
118 $, = "\n ";
119 print @ReadersList . "\n";
120
121 =item *
122 B<$hContext-E<gt>GetStatusChange(\@readers_states, $timeout);>
123
124 The method C<$hContext-E<gt>GetStatusChange(\@readers_states, $timeout)>
125 uses a reference to a list of hashes.
126
127 # create the list or readers to watch
128 map { push @readers_states, ({'reader_name'=>"$_"}) } @ReadersList;
129
130 @StatusResult = $hContext->GetStatusChange(\@readers_states);
131
132 The keys of the hash are: 'reader_name', 'current_state', 'event_state'
133 and 'ATR'.
134
135 To detect a status change you have to first get the status and then copy
136 the 'event_state' in the 'current_state'. The method will return when
137 both states are different or a timeout occurs.
138
139 @StatusResult = $hContext->GetStatusChange(\@readers_states);
140 foreach $reader (@readers_states)
141 {
142 $reader->{current_state} = $reader->{event_state};
143 }
144 @StatusResult = $hContext->GetStatusChange(\@readers_states);
145
146 =item *
147 B<$hContext-E<gt>GetStatusChange(\@readers_states);>
148
149 This method is equivalent to:
150
151 $hContext->GetStatusChange(\@readers_states, 0xFFFFFFFF);
152
153 The timeout is set to infinite.
154
155 =item *
156 B<$apdu_ref = Chipcard::PCSC::ascii_to_array($apdu);>
157
158 The method C<Chipcard::PCSC::Card::Transmit()> uses references to arrays
159 as in and out parameters. The C<Chipcard::PCSC::ascii_to_array()> is used
160 to transform an APDU in ASCII format to a reference to an array in the
161 good format.
162
163 Example:
164
165 $SendData = Chipcard::PCSC::ascii_to_array("00 A4 01 00 02 01 00");
166
167 =item *
168 B<$apdu = Chipcard::PCSC::array_to_ascii($apdu_ref);>
169
170 This method is used to convert the result of a
171 C<Chipcard::PCSC::Card::Transmit()> into ASCII format.
172
173 Example:
174
175 $RecvData = $hCard->Transmit($SendData);
176 print Chipcard::PCSC::array_to_ascii($RecvData);
177
178 =back
179
180 =head1 ERROR HANDLING
181
182 All functions from PCSC objects save the return value in a global
183 variable called C<$Chipcard::PCSC::errno>. This variable therefore holds
184 the latest status of PCSC.
185
186 It is a double-typed magical variable that behaves just like C<$!>. This
187 means that it both holds a numerical value describing the error and the
188 corresponding string. The numerical value may change from a system to
189 another as it depends on the PCSC library...
190
191 Here is a small example of how to use it:
192
193 $hContext = new Chipcard::PCSC();
194 die ("Can't create the PCSC object: $Chipcard::PCSC::errno\n")
195 unless (defined $hContext);
196
197 In case the last call was successful, C<$Chipcard::PCSC::errno> contains
198 the C<SCARD_S_SUCCESS> status. Here is a list of all possible error
199 codes. They are defined as read-only variables with in the PCSC module:
200
201 $Chipcard::PCSC::SCARD_S_SUCCESS
202 $Chipcard::PCSC::SCARD_E_CANCELLED
203 $Chipcard::PCSC::SCARD_E_CANT_DISPOSE
204 $Chipcard::PCSC::SCARD_E_CARD_UNSUPPORTED
205 $Chipcard::PCSC::SCARD_E_DUPLICATE_READER
206 $Chipcard::PCSC::SCARD_E_INSUFFICIENT_BUFFER
207 $Chipcard::PCSC::SCARD_E_INVALID_ATR
208 $Chipcard::PCSC::SCARD_E_INVALID_HANDLE
209 $Chipcard::PCSC::SCARD_E_INVALID_PARAMETER
210 $Chipcard::PCSC::SCARD_E_INVALID_TARGET
211 $Chipcard::PCSC::SCARD_E_INVALID_VALUE
212 $Chipcard::PCSC::SCARD_E_NO_MEMORY
213 $Chipcard::PCSC::SCARD_E_NO_SERVICE
214 $Chipcard::PCSC::SCARD_E_NO_SMARTCARD
215 $Chipcard::PCSC::SCARD_E_NOT_READY
216 $Chipcard::PCSC::SCARD_E_NOT_TRANSACTED
217 $Chipcard::PCSC::SCARD_E_PCI_TOO_SMALL
218 $Chipcard::PCSC::SCARD_E_PROTO_MISMATCH
219 $Chipcard::PCSC::SCARD_E_READER_UNAVAILABLE
220 $Chipcard::PCSC::SCARD_E_READER_UNSUPPORTED
221 $Chipcard::PCSC::SCARD_E_SERVICE_STOPPED
222 $Chipcard::PCSC::SCARD_E_SHARING_VIOLATION
223 $Chipcard::PCSC::SCARD_E_SYSTEM_CANCELLED
224 $Chipcard::PCSC::SCARD_E_TIMEOUT
225 $Chipcard::PCSC::SCARD_E_UNKNOWN_CARD
226 $Chipcard::PCSC::SCARD_E_UNKNOWN_READER
227 $Chipcard::PCSC::SCARD_E_UNSUPPORTED_FEATURE
228
229 $Chipcard::PCSC::SCARD_W_REMOVED_CARD
230 $Chipcard::PCSC::SCARD_W_RESET_CARD
231 $Chipcard::PCSC::SCARD_W_SECURITY_VIOLATION
232 $Chipcard::PCSC::SCARD_W_UNPOWERED_CARD
233 $Chipcard::PCSC::SCARD_W_UNRESPONSIVE_CARD
234 $Chipcard::PCSC::SCARD_W_UNSUPPORTED_CARD
235
236 PCSClite users will also be able to use the following (PCSClite
237 specific) codes:
238
239 $Chipcard::PCSC::SCARD_INSERTED
240 $Chipcard::PCSC::SCARD_REMOVED
241 $Chipcard::PCSC::SCARD_RESET
242 $Chipcard::PCSC::SCARD_SCOPE_GLOBAL
243
244 In addition, the wrapper defines:
245
246 $Chipcard::PCSC::SCARD_P_ALREADY_CONNECTED
247 $Chipcard::PCSC::SCARD_P_NOT_CONNECTED
248
249 =head1 SEE ALSO
250
251 F<pcscd(1)> manpage has useful information about PC/SC lite.
252 L<Chipcard::PCSC::Card> manpage gives information about how to
253 communicate with a reader and the smart card inside it.
254
255 =head1 COPYRIGHT
256
257 (C) Lionel VICTOR & Ludovic ROUSSEAU, 2001-2004, GNU GPL
258 (C) Ludovic ROUSSEAU, 2005-2008, GNU GPL
259
260 =head1 AUTHORS / ACKNOWLEDGEMENT
261
262 Lionel VICTOR <[email protected]>
263 <[email protected]>
264
265 Ludovic ROUSSEAU <[email protected]>
266
267 =cut
268