1 """PyroReaderClient: concrete reader class for Remote Readers
2
3 __author__ = "gemalto http://www.gemalto.com"
4
5 Copyright 2001-2011 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 import Pyro.core
26 import Pyro.naming
27
28 from smartcard.Exceptions import CardConnectionException, NoCardException
29 from smartcard.reader.Reader import Reader
30 from smartcard.reader.ReaderFactory import ReaderFactory
31
32
34 """Remote reader class."""
36 """Constructs a new Remote Reader client implementation from a
37 Pyro URI."""
38 ns = Pyro.naming.NameServerLocator().getNS()
39 self.uri = ns.resolve(':pyscard.smartcard.readers.' + readername)
40 self.reader = Pyro.core.getAttrProxyForURI(self.uri)
41 self.name = self.reader.name
42
46
50
52 """Return a card connection thru a remote reader."""
53 uri = self.reader.createConnection()
54 return Pyro.core.getAttrProxyForURI(uri)
55
60
62 readernames = []
63 try:
64 ns = Pyro.naming.NameServerLocator().getNS()
65 readernames = ns.list(':pyscard.smartcard.readers')
66 except Pyro.errors.NamingError:
67 print 'Warning: pyro name server not found'
68
69 remotereaders = []
70 for readername in readernames:
71 remotereaders.append(PyroReader.Factory.create(readername[0]))
72
73 return remotereaders
74 readers = staticmethod(readers)
75
76 if __name__ == '__main__':
77 SELECT = [0xA0, 0xA4, 0x00, 0x00, 0x02]
78 DF_TELECOM = [0x7F, 0x10]
79 from smartcard.util import *
80
81 remotereaders = PyroReader.readers()
82 for reader in remotereaders:
83 try:
84 print reader.name, ', uri: ', reader.uri
85 connection = reader.createConnection()
86 connection.connect()
87 print toHexString(connection.getATR())
88 data, sw1, sw2 = connection.transmit(SELECT + DF_TELECOM)
89 print "%X %X" % (sw1, sw2)
90 except NoCardException, x:
91 print 'no card in reader'
92