1 """PCSCReader: concrete reader class for PCSC Readers
2
3 __author__ = "gemalto http://www.gemalto.com"
4
5 Copyright 2001-2012 gemalto
6 Author: Jean-Daniel Aussel, mailto:jean-daniel.aussel@gemalto.com
7
8 This file is part of pyscard.
9
10 pyscard is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14
15 pyscard is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public License
21 along with pyscard; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 """
24
25 from __future__ import print_function
26 from smartcard.CardConnectionDecorator import CardConnectionDecorator
27 from smartcard.reader.Reader import Reader
28 from smartcard.pcsc.PCSCContext import PCSCContext
29 from smartcard.pcsc.PCSCCardConnection import PCSCCardConnection
30 from smartcard.Exceptions import *
31 from smartcard.pcsc.PCSCExceptions import *
32 from smartcard.scard import *
33
34
52
53
55 """PCSC reader class."""
56
58 """Constructs a new PCSC reader."""
59 Reader.__init__(self, readername)
60
78
95
99
105
113 readers = staticmethod(readers)
114
115 if __name__ == '__main__':
116 from smartcard.util import *
117 SELECT = [0xA0, 0xA4, 0x00, 0x00, 0x02]
118 DF_TELECOM = [0x7F, 0x10]
119
120 creaders = PCSCReader.readers()
121 for reader in creaders:
122 try:
123 print(reader.name)
124 connection = reader.createConnection()
125 connection.connect()
126 print(toHexString(connection.getATR()))
127 data, sw1, sw2 = connection.transmit(SELECT + DF_TELECOM)
128 print("%02X %02X" % (sw1, sw2))
129 except NoCardException:
130 print('no card in reader')
131