|
From: <lu...@us...> - 2009-06-14 12:04:36
|
Revision: 291
http://pyscard.svn.sourceforge.net/pyscard/?rev=291&view=rev
Author: ludov
Date: 2009-06-14 12:04:25 +0000 (Sun, 14 Jun 2009)
Log Message:
-----------
add CardConnection.control() method (high level SCardControl)
Modified Paths:
--------------
trunk/pyscard/src/smartcard/CardConnection.py
trunk/pyscard/src/smartcard/CardConnectionDecorator.py
trunk/pyscard/src/smartcard/pcsc/PCSCCardConnection.py
Modified: trunk/pyscard/src/smartcard/CardConnection.py
===================================================================
--- trunk/pyscard/src/smartcard/CardConnection.py 2009-06-14 11:38:34 UTC (rev 290)
+++ trunk/pyscard/src/smartcard/CardConnection.py 2009-06-14 12:04:25 UTC (rev 291)
@@ -139,3 +139,27 @@
Subclasses must override this method for implementing apdu transmission."""
pass
+ def control( self, controlCode, bytes = [] ):
+ """Send a control command and buffer. Internally calls doControl()
+ class method and notify observers upon command/response events.
+ Subclasses must override the doControl() class method.
+
+ controlCode: command code
+
+ bytes: list of bytes to transmit
+ """
+ Observable.setChanged( self )
+ Observable.notifyObservers( self, CardConnectionEvent('command', [controlCode, bytes] ) )
+ data = self.doControl( controlCode, bytes )
+ Observable.setChanged( self )
+ Observable.notifyObservers( self, CardConnectionEvent( 'response', data ) )
+ if None!=self.errorcheckingchain:
+ self.errorcheckingchain[0]( data )
+ return data
+
+ def doControl( self, controlCode, bytes ):
+ """Performs the command control.
+
+ Subclasses must override this method for implementing control."""
+ pass
+
Modified: trunk/pyscard/src/smartcard/CardConnectionDecorator.py
===================================================================
--- trunk/pyscard/src/smartcard/CardConnectionDecorator.py 2009-06-14 11:38:34 UTC (rev 290)
+++ trunk/pyscard/src/smartcard/CardConnectionDecorator.py 2009-06-14 12:04:25 UTC (rev 291)
@@ -80,3 +80,7 @@
"""call inner component transmit"""
return self.component.transmit( bytes, protocol )
+ def control( self, controlCode, bytes=[] ):
+ """call inner component control"""
+ return self.component.control( controlCode, bytes )
+
Modified: trunk/pyscard/src/smartcard/pcsc/PCSCCardConnection.py
===================================================================
--- trunk/pyscard/src/smartcard/pcsc/PCSCCardConnection.py 2009-06-14 11:38:34 UTC (rev 290)
+++ trunk/pyscard/src/smartcard/pcsc/PCSCCardConnection.py 2009-06-14 12:04:25 UTC (rev 291)
@@ -160,6 +160,23 @@
data = map(lambda x: (x+256)%256, response[:-2])
return data, sw1, sw2
+ def doControl( self, controlCode, bytes=[] ):
+ """Transmit a control command to the reader and return response.
+
+ controlCode: control command
+
+ bytes: command data to transmit (list of bytes)
+
+ return: response are the response bytes (if any)
+ """
+ CardConnection.doControl( self, controlCode, bytes )
+ hresult, response = SCardControl( self.hcard, controlCode, bytes )
+ if hresult!=0:
+ raise CardConnectionException( 'Failed to control ' + SCardGetErrorMessage(hresult) )
+
+ data = map(lambda x: (x+256)%256, response)
+ return data
+
if __name__ == '__main__':
"""Small sample illustrating the use of CardConnection."""
SELECT = [0xA0, 0xA4, 0x00, 0x00, 0x02]
@@ -169,3 +186,4 @@
cc.connect()
print "%r %x %x" % cc.transmit( SELECT + DF_TELECOM )
+ print cc.control( 0, [] )
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|