LudovicRousseau/pyscard

Unplug cardreader break monitoring

uralbash opened this issue · 6 comments

Your system information

  • Operating system used: Ubuntu 20.04
  • pyscard version: 2.0.3
  • Python version: 3.8

Please describe your issue in as much detail as possible:

Describe what you expected should happen.

Describe what did happen.
Monitoring does not work after this error

Traceback (most recent call last):
  File "/home/user/test/.env3_pyside6/lib/python3.8/site-packages/smartcard/CardMonitoring.py", line 163, in run
    currentcards = self.cardrequest.waitforcardevent()
  File "/home/user/test/.env3_pyside6/lib/python3.8/site-packages/smartcard/CardRequest.py", line 72, in waitforcardevent
    return self.pcsccardrequest.waitforcardevent()
  File "/home/user/test/.env3_pyside6/lib/python3.8/site-packages/smartcard/pcsc/PCSCCardRequest.py", line 296, in waitforcardevent
    readernames = self.getReaderNames()
  File "/home/user/test/.env3_pyside6/lib/python3.8/site-packages/smartcard/pcsc/PCSCCardRequest.py", line 98, in getReaderNames
    raise ListReadersException(hresult)
smartcard.Exceptions.ListReadersException: Failed to list readers: RPC transport error. (0x80100013)

Steps for reproducing this issue:

  1. Start app with monitoring
  2. Unplug cardreader
  3. get error

It looks like the communication with pcscd disapeared: RPC transport error. (0x80100013)
I guess pcscd crashed.

Please add the information as detailed in https://pcsclite.apdu.fr/#support

I have not received the requestion log.
I can't help you if you do not participate.

$ pcscd --version
pcsc-lite version 1.8.26.

$ uname -a
Linux localhost902 5.4.0-107-generic #121-Ubuntu SMP Thu Mar 24 16:04:27 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Model: OMNIKEY 5427 CK

Log: log.txt

I can't find any error or problem in the pcscd log.
Can you reproduce the problem with one of the examples in https://github.com/LudovicRousseau/pyscard/tree/master/smartcard/Examples/framework ?

Test1

log_test1.txt

Attached card

 $  python sample_apduTracerInterpreter.py
connecting to HID OMNIKEY 5427 CK (010100533246353330011E0F38134730) 00 00
> SELECT 7F 10
Traceback (most recent call last):
  File "sample_apduTracerInterpreter.py", line 80, in <module>
    response, sw1, sw2 = cardservice.connection.transmit(apdu)
  File "/tmp/test_pyscard/.env/lib/python3.8/site-packages/smartcard/CardConnectionDecorator.py", line 86, in transmit
    return self.component.transmit(bytes, protocol)
  File "/tmp/test_pyscard/.env/lib/python3.8/site-packages/smartcard/CardConnection.py", line 161, in transmit
    data, sw1, sw2 = self.doTransmit(bytes, protocol)
  File "/tmp/test_pyscard/.env/lib/python3.8/site-packages/smartcard/pcsc/PCSCCardConnection.py", line 247, in doTransmit
    raise CardConnectionException(
smartcard.Exceptions.CardConnectionException: Failed to transmit with protocol T1. Transaction failed.
disconnecting from HID OMNIKEY 5427 CK (010100533246353330011E0F38134730) 00 00
disconnecting from HID OMNIKEY 5427 CK (010100533246353330011E0F38134730) 00 00

Test2

log_test2.txt

Turned off then turned on the reader.
pcscd crashed.

 $  python sample_apduTracerInterpreter.py
Traceback (most recent call last):
  File "sample_apduTracerInterpreter.py", line 68, in <module>
    cardservice = cardrequest.waitforcard()
  File "/tmp/test_pyscard/.env/lib/python3.8/site-packages/smartcard/CardRequest.py", line 68, in waitforcard
    return self.pcsccardrequest.waitforcard()
  File "/tmp/test_pyscard/.env/lib/python3.8/site-packages/smartcard/pcsc/PCSCCardRequest.py", line 195, in waitforcard
    readernames = self.getReaderNames()
  File "/tmp/test_pyscard/.env/lib/python3.8/site-packages/smartcard/pcsc/PCSCCardRequest.py", line 98, in getReaderNames
    raise ListReadersException(hresult)
smartcard.Exceptions.ListReadersException: Failed to list readers: RPC transport error. (0x80100013)

Test3

log_test3.txt

Turned off then turned on the reader.
pcscd crashed.

 $  python sample_MonitorCardsAndTransmit.py 
Insert or remove a SIM card in the system.
This program will exit in 60 seconds

Traceback (most recent call last):
  File "/tmp/test_pyscard/.env/lib/python3.8/site-packages/smartcard/CardMonitoring.py", line 163, in run
    currentcards = self.cardrequest.waitforcardevent()
  File "/tmp/test_pyscard/.env/lib/python3.8/site-packages/smartcard/CardRequest.py", line 72, in waitforcardevent
    return self.pcsccardrequest.waitforcardevent()
  File "/tmp/test_pyscard/.env/lib/python3.8/site-packages/smartcard/pcsc/PCSCCardRequest.py", line 296, in waitforcardevent
    readernames = self.getReaderNames()
  File "/tmp/test_pyscard/.env/lib/python3.8/site-packages/smartcard/pcsc/PCSCCardRequest.py", line 98, in getReaderNames
    raise ListReadersException(hresult)
smartcard.Exceptions.ListReadersException: Failed to list readers: RPC transport error. (0x80100013)
Traceback (most recent call last):
  File "/tmp/test_pyscard/.env/lib/python3.8/site-packages/smartcard/CardMonitoring.py", line 163, in run
    currentcards = self.cardrequest.waitforcardevent()
  File "/tmp/test_pyscard/.env/lib/python3.8/site-packages/smartcard/CardRequest.py", line 72, in waitforcardevent
    return self.pcsccardrequest.waitforcardevent()
  File "/tmp/test_pyscard/.env/lib/python3.8/site-packages/smartcard/pcsc/PCSCCardRequest.py", line 296, in waitforcardevent
    readernames = self.getReaderNames()
  File "/tmp/test_pyscard/.env/lib/python3.8/site-packages/smartcard/pcsc/PCSCCardRequest.py", line 98, in getReaderNames
    raise ListReadersException(hresult)
smartcard.Exceptions.ListReadersException: Failed to list readers: Service not available. (0x8010001D)

dmesg log

[2586255.893048] Code: Bad RIP value.
[2586343.184754] sh (4077910): drop_caches: 3
[2586445.838399] cdc_eem 3-11.4.3:1.1 usb0: unregister 'cdc_eem' usb-0000:00:14.0-11.4.3, CDC EEM Device
[2586446.068077] usb 3-11.4.3: reset full-speed USB device number 118 using xhci_hcd
[2586446.293372] cdc_eem 3-11.4.3:1.1 usb0: register 'cdc_eem' at usb-0000:00:14.0-11.4.3, CDC EEM Device, 76:9a:c1:f3:a2:9d
[2586456.744529] usb 3-11.4.3: USB disconnect, device number 118
[2586456.746660] cdc_eem 3-11.4.3:1.1 usb0: unregister 'cdc_eem' usb-0000:00:14.0-11.4.3, CDC EEM Device
[2586462.976086] usb 3-11.4.3: new full-speed USB device number 119 using xhci_hcd
[2586466.560195] usb 3-11.4.3: new full-speed USB device number 120 using xhci_hcd
[2586466.785983] usb 3-11.4.3: New USB device found, idVendor=076b, idProduct=5427, bcdDevice= 1.00
[2586466.785989] usb 3-11.4.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[2586466.785993] usb 3-11.4.3: Product: 5427 CK
[2586466.785996] usb 3-11.4.3: Manufacturer: HID OMNIKEY
[2586466.785998] usb 3-11.4.3: SerialNumber: 010100533246353330011E0F38134730
[2586466.801514] cdc_eem 3-11.4.3:1.1 usb0: register 'cdc_eem' at usb-0000:00:14.0-11.4.3, CDC EEM Device, 76:9a:c1:f3:a2:9d
[2586466.831535] pcscd[4078174]: segfault at 7fb1b48451a2 ip 00007fb1b48451a2 sp 00007fb1b2669e30 error 14
[2586466.831539] Code: Bad RIP value.
[2586514.600618] usb 3-11.4.3: USB disconnect, device number 120
[2586514.602748] cdc_eem 3-11.4.3:1.1 usb0: unregister 'cdc_eem' usb-0000:00:14.0-11.4.3, CDC EEM Device
[2586518.781218] usb 3-11.4.3: new full-speed USB device number 121 using xhci_hcd
[2586519.007179] usb 3-11.4.3: New USB device found, idVendor=076b, idProduct=5427, bcdDevice= 1.00
[2586519.007182] usb 3-11.4.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[2586519.007183] usb 3-11.4.3: Product: 5427 CK
[2586519.007185] usb 3-11.4.3: Manufacturer: HID OMNIKEY
[2586519.007186] usb 3-11.4.3: SerialNumber: 010100533246353330011E0F38134730
[2586519.021695] cdc_eem 3-11.4.3:1.1 usb0: register 'cdc_eem' at usb-0000:00:14.0-11.4.3, CDC EEM Device, 76:9a:c1:f3:a2:9d
[2586519.049123] pcscd[4078391]: segfault at 7f2ef54fa1a2 ip 00007f2ef54fa1a2 sp 00007f2ef331ee30 error 14
[2586519.049128] Code: Bad RIP value.
[2586545.320640] usb 3-11.4.3: USB disconnect, device number 121
[2586545.322765] cdc_eem 3-11.4.3:1.1 usb0: unregister 'cdc_eem' usb-0000:00:14.0-11.4.3, CDC EEM Device
[2586548.477750] usb 3-11.4.3: new full-speed USB device number 122 using xhci_hcd
[2586548.703417] usb 3-11.4.3: New USB device found, idVendor=076b, idProduct=5427, bcdDevice= 1.00
[2586548.703420] usb 3-11.4.3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[2586548.703421] usb 3-11.4.3: Product: 5427 CK
[2586548.703422] usb 3-11.4.3: Manufacturer: HID OMNIKEY
[2586548.703424] usb 3-11.4.3: SerialNumber: 010100533246353330011E0F38134730
[2586548.717584] cdc_eem 3-11.4.3:1.1 usb0: register 'cdc_eem' at usb-0000:00:14.0-11.4.3, CDC EEM Device, 76:9a:c1:f3:a2:9d
[2586548.740755] pcscd[4078616]: segfault at 7f7bdd99a1a2 ip 00007f7bdd99a1a2 sp 00007f7bdb7bee30 error 14
[2586548.740760] Code: Bad RIP value.

From your previous pcscd log I see you are using the HID Global (proprietary?) driver: ha0ulx64_lnx_1_0_1_2

00000051 [140118560020416] readerfactory.c:1074:RFInitializeReader() Attempting startup of HID OMNIKEY 5427 CK (010100533246353330011E0F38134730) 00 00 using /usr/lib/pcsc/drivers/ha0ulx64_lnx_1_0_1_2.bundle/Contents/Linux/ha0ulx64.so

I bet the problem comes from a crash in the driver. Contact HID Global for support.

If you can reproduce the problem with the HID driver REMOVED then I will reopen this ticket.