transport/pcsc: explicitly specify T0 protocol
From pyscard user's guide [1]:
== Selecting the card communication protocol ==
By defaults, the connect() method of the CardConnection object
will try to connect using either the T=0 or T=1 protocol.
To force a connection protocol, you can pass the required
protocol to the connect() method.
This means that a PC/SC ifd handler may automatically choose T=1
as the highest protocol if the card indicates both in its ATR [2].
Since pySim only supports T=0, let's select it explicitly.
[1] https://pyscard.sourceforge.io/user-guide.html
[2] https://github.com/acshk/acsccid/issues/16#issuecomment-501101972
Change-Id: Ifed4574aab98a86c3ebbeb191f36a8282103e775
diff --git a/pySim/transport/pcsc.py b/pySim/transport/pcsc.py
index 7fa922f..380c8fd 100644
--- a/pySim/transport/pcsc.py
+++ b/pySim/transport/pcsc.py
@@ -22,6 +22,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+from smartcard.CardConnection import CardConnection
from smartcard.CardRequest import CardRequest
from smartcard.Exceptions import NoCardException, CardRequestTimeoutException
from smartcard.System import readers
@@ -52,7 +53,10 @@
def connect(self):
try:
- self._con.connect()
+ # Explicitly select T=0 communication protocol
+ self._con.connect(CardConnection.T0_protocol)
+ except CardConnectionException:
+ raise ProtocolError()
except NoCardException:
raise NoCardError()