Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Watchdata Usb Key not working #9

Closed
giroberto opened this issue Aug 26, 2015 · 4 comments
Closed

Watchdata Usb Key not working #9

giroberto opened this issue Aug 26, 2015 · 4 comments

Comments

@giroberto
Copy link

Tried with latest ccid 1.4.20 on archlinux

pcsc_scan log:

04677683 hotplug_libudev.c:614:HPEstablishUSBNotifications() USB Device add
00000230 hotplug_libudev.c:296:get_driver() Looking for a driver for VID: 0x163C, PID: 0x0407, path: /dev/bus/usb/004/003
00000013 hotplug_libudev.c:435:HPAddDevice() Adding USB device: Watchdata USB Key
00000111 readerfactory.c:1012:RFInitializeReader() Attempting startup of Watchdata USB Key [USB CD-ROM] 00 00 using /usr/lib/pcsc/drivers/ifd-ccid.bundle/Contents/Linux/libccid.so
00000223 readerfactory.c:897:RFBindFunctions() Loading IFD Handler 3.0
00000028 ifdhandler.c:1927:init_driver() Driver version: 1.4.20
00000627 ifdhandler.c:1944:init_driver() LogLevel: 0x0003
00000008 ifdhandler.c:1955:init_driver() DriverOptions: 0x0000
00000161 ifdhandler.c:96:CreateChannelByNameOrChannel() Lun: 0, device: usb:163c/0407:libudev:0:/dev/bus/usb/004/003
00000019 ccid_usb.c:283:OpenUSBByName() Using: /usr/lib/pcsc/drivers/ifd-ccid.bundle/Contents/Info.plist
00000581 ccid_usb.c:301:OpenUSBByName() ifdManufacturerString: Ludovic Rousseau ([email protected])
00000007 ccid_usb.c:302:OpenUSBByName() ifdProductString: Generic CCID driver
00000005 ccid_usb.c:303:OpenUSBByName() Copyright: This driver is protected by terms of the GNU Lesser General Public License version 2.1, or (at your option) any later version.
00005850 ccid_usb.c:573:OpenUSBByName() Found interface 0 but expecting 1
00000025 ccid_usb.c:575:OpenUSBByName() Wrong interface for USB device 4/3. Checking next one.
00000049 ccid_usb.c:190:close_libusb_if_needed() libusb_exit
00000276 ccid_usb.c:702:OpenUSBByName() Device not found?
00000015 ifdhandler.c:130:CreateChannelByNameOrChannel() failed
00000008 readerfactory.c:1043:RFInitializeReader() Open Port 0x200000 Failed (usb:163c/0407:libudev:0:/dev/bus/usb/004/003)
00000005 readerfactory.c:335:RFAddReader() Watchdata USB Key [USB CD-ROM] init failed.
00000008 readerfactory.c:558:RFRemoveReader() UnrefReader() count was: 1
00000005 readerfactory.c:1063:RFUnInitializeReader() Attempting shutdown of Watchdata USB Key [USB CD-ROM] 00 00.
00000003 readerfactory.c:934:RFUnloadReader() Unloading reader driver.
00000103 hotplug_libudev.c:614:HPEstablishUSBNotifications() USB Device add
00000157 hotplug_libudev.c:296:get_driver() Looking for a driver for VID: 0x163C, PID: 0x0407, path: /dev/bus/usb/004/003
00000009 hotplug_libudev.c:435:HPAddDevice() Adding USB device: Watchdata USB Key
00000058 readerfactory.c:1012:RFInitializeReader() Attempting startup of Watchdata USB Key [USB CCID Key] 00 00 using /usr/lib/pcsc/drivers/ifd-ccid.bundle/Contents/Linux/libccid.so
00000175 readerfactory.c:897:RFBindFunctions() Loading IFD Handler 3.0
00000025 ifdhandler.c:1927:init_driver() Driver version: 1.4.20
00000563 ifdhandler.c:1944:init_driver() LogLevel: 0x0003
00000008 ifdhandler.c:1955:init_driver() DriverOptions: 0x0000
00000164 ifdhandler.c:96:CreateChannelByNameOrChannel() Lun: 0, device: usb:163c/0407:libudev:1:/dev/bus/usb/004/003
00000012 ccid_usb.c:283:OpenUSBByName() Using: /usr/lib/pcsc/drivers/ifd-ccid.bundle/Contents/Info.plist
00000615 ccid_usb.c:301:OpenUSBByName() ifdManufacturerString: Ludovic Rousseau ([email protected])
00000006 ccid_usb.c:302:OpenUSBByName() ifdProductString: Generic CCID driver
00000005 ccid_usb.c:303:OpenUSBByName() Copyright: This driver is protected by terms of the GNU Lesser General Public License version 2.1, or (at your option) any later version.
00005086 ccid_usb.c:588:OpenUSBByName() Can't claim interface 4/3: -6
00000028 ccid_usb.c:190:close_libusb_if_needed() libusb_exit
00000094 ifdhandler.c:130:CreateChannelByNameOrChannel() failed
00000013 readerfactory.c:1043:RFInitializeReader() Open Port 0x200001 Failed (usb:163c/0407:libudev:1:/dev/bus/usb/004/003)
00000005 readerfactory.c:335:RFAddReader() Watchdata USB Key [USB CCID Key] init failed.
00000005 readerfactory.c:558:RFRemoveReader() UnrefReader() count was: 1
00000004 readerfactory.c:1063:RFUnInitializeReader() Attempting shutdown of Watchdata USB Key [USB CCID Key] 00 00.
00000004 readerfactory.c:934:RFUnloadReader() Unloading reader driver.
00000047 hotplug_libudev.c:501:HPAddDevice() Failed adding USB device: Watchdata USB Key
@LudovicRousseau
Copy link
Owner

00005086 ccid_usb.c:588:OpenUSBByName() Can't claim interface 4/3: -6

-6 is LIBUSB_ERROR_BUSY

Your device CCID interface is already used by another program. You have to stop this other program first.

@giroberto
Copy link
Author

Thank you! The wdtoken module still was on my system, now i got this

PC/SC device scanner
V 1.4.23 (c) 2001-2011, Ludovic Rousseau <[email protected]>
Compiled with PC/SC lite version: 1.8.12
Using reader plug'n play mechanism
Scanning present readers...
0: Watchdata USB Key [USB CCID Key] 00 00

Thu Aug 27 10:19:02 2015
Reader 0: Watchdata USB Key [USB CCID Key] 00 00
  Card state: Card inserted, 
  ATR: 3B 6E 00 00 57 44 36 19 69 86 93 02 21 18 15 50 0E 2B

ATR: 3B 6E 00 00 57 44 36 19 69 86 93 02 21 18 15 50 0E 2B
+ TS = 3B --> Direct Convention
+ T0 = 6E, Y(1): 0110, K: 14 (historical bytes)
  TB(1) = 00 --> VPP is not electrically connected
  TC(1) = 00 --> Extra guard time: 0
+ Historical bytes: 57 44 36 19 69 86 93 02 21 18 15 50 0E 2B
  Category indicator byte: 57 (proprietary format)

Possibly identified card (using /home/user/.cache/smartcard_list.txt):
        NONE

Updating /home/user/.cache/smartcard_list.txt using http://ludovic.rousseau.free.fr/softwares/pcsc-tools/smartcard_list.txt
--2015-08-27 10:19:02--  http://ludovic.rousseau.free.fr/softwares/pcsc-tools/smartcard_list.txt
Resolvendo ludovic.rousseau.free.fr (ludovic.rousseau.free.fr)... 212.27.63.159
Conectando-se a ludovic.rousseau.free.fr (ludovic.rousseau.free.fr)|212.27.63.159|:80... conectado.
A requisição HTTP foi enviada, aguardando resposta... 200 OK
Tamanho: 228069 (223K) [text/plain]
Salvando em: “/home/user/.cache/smartcard_list.txt”

/home/user/.cache/smartcard_list.txt      100%[=============================================================================================>] 222,72K  --.-KB/s   em 0,02s  

2015-08-27 10:19:04 (9,65 MB/s) - “/home/user/.cache/smartcard_list.txt” salvo [228069/228069]


Possibly identified card (using /home/user/.cache/smartcard_list.txt):
        NONE

@LudovicRousseau
Copy link
Owner

Bug was on the user configuration.

LudovicRousseau added a commit that referenced this issue Nov 13, 2015
If the creation of a channel fails then call FreeChannel() instead of
IFDHCloseChannel().
The ressources are unalocated but with no access at the lower layer.

Since the creation failed the channel is not correctly created and
only part of the reader stucture is initialised.

The problem was discovered with the folowing problem:
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff6fe2700 (LWP 6120)]
0x00007ffff5dca8f2 in CmdPowerOff (reader_index=0) at commands.c:1076
1076		cmd[6] = (*ccid_descriptor->pbSeq)++;
(gdb) print ccid_descriptor
$1 = (_ccid_descriptor *) 0x7ffff5fe0468 <usbDevice+40>
(gdb) print ccid_descriptor->pbSeq
$2 = (unsigned char *) 0x0

The pbSeq pointer is NULL and can't be dereferenced.

(gdb) bt
 #0  0x00007ffff5dca8f2 in CmdPowerOff (reader_index=0) at commands.c:1076
 #1  0x00007ffff5dce556 in IFDHCloseChannel (Lun=0) at ifdhandler.c:269
 #2  0x00007ffff5dce773 in CreateChannelByNameOrChannel (Lun=0,
     lpcDevice=0x269 <error: Cannot access memory at address 0x269>, Channel=0)
     at ifdhandler.c:194
 #3  0x000000000040673a in IFDOpenIFD (rContext=rContext@entry=0x61e010)
     at ifdwrapper.c:136
 #4  0x0000000000408151 in RFInitializeReader (rContext=0x61e010)
     at readerfactory.c:1036
 #5  0x0000000000408a93 in RFAddReader (readerNameLong=<optimized out>,
     port=2097152, library=<optimized out>,
     device=0x7ffff6fe1d30 "usb:08e6/3437:libusb-1.0:1:2:0")
     at readerfactory.c:329
 #6  0x000000000040d9d4 in HPAddHotPluggable (dev=0x0,
     bus_device=0x61d660 <readerTracker+32> "", interface=0,
     driver=<optimized out>, driver=<optimized out>, desc=...)
     at hotplug_libusb.c:608
 #7  0x000000000040dd2a in HPRescanUsbBus () at hotplug_libusb.c:373
 #8  0x000000000040dfa1 in HPEstablishUSBNotifications (pipefd=0x7fffffffe440)
     at hotplug_libusb.c:429
 #9  0x00007ffff75a30a4 in start_thread (arg=0x7ffff6fe2700)
     at pthread_create.c:309
 #10 0x00007ffff72d804d in clone ()
     at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111
@YogeshSeralia
Copy link

Its possibly be pn533 which blocks the access to reader for pcscd.

what I done was

  1. check if pn533 is loaded by :
    lsmod | grep pn533

if your output is like :

pn533                  40960  0 
nfc                   102400  1 pn533

  1. If output is similar to above then unload pn533 from kernel :

sudo modprobe -r pn533 pn533

  1. Now start your pcscd and then start pcsc_scan , it should now show your card status.

LudovicRousseau added a commit that referenced this issue Oct 23, 2023
Declare ReaderIndex[] as _Atomic as it can be accessed from 2 different
threads.

==================
WARNING: ThreadSanitizer: data race (pid=4017)
  Write of size 4 at 0x7fd1b32be970 by main thread (mutexes: write M0, write M1):
    #0 ReleaseReaderIndex CCID/src/utils.c:81:21 (libccid.so+0xa672) (BuildId: 69b3a74d7af87f05c5edb71935a43b024a0fe968)
    #1 FreeChannel CCID/src/ifdhandler.c:92:2 (libccid.so+0xa672)
    #2 IFDHCloseChannel CCID/src/ifdhandler.c:302:2 (libccid.so+0xa672)
    #3 IFDCloseIFD PCSC/src/ifdwrapper.c:190:7 (pcscd+0xd9e30) (BuildId: 046d0874ce19c882d4f3b8ab5213aa4cd336cd5e)
    #4 RFUnInitializeReader PCSC/src/readerfactory.c:1153:9 (pcscd+0xd9e30)
    #5 removeReader PCSC/src/readerfactory.c:645:2 (pcscd+0xd9e30)
    #6 _UnrefReader PCSC/src/readerfactory.c:120:3 (pcscd+0xd9e30)
    #7 IFDCloseIFD PCSC/src/ifdwrapper.c:190:7 (pcscd+0xd9e30) (BuildId: 046d0874ce19c882d4f3b8ab5213aa4cd336cd5e)
    #8 RFUnInitializeReader PCSC/src/readerfactory.c:1153:9 (pcscd+0xd9e30)
    #9 removeReader PCSC/src/readerfactory.c:645:2 (pcscd+0xd9e30)
    #10 _UnrefReader PCSC/src/readerfactory.c:120:3 (pcscd+0xd9e30)
    #11 RFRemoveReader PCSC/src/readerfactory.c:624:5 (pcscd+0xdd282) (BuildId: 046d0874ce19c882d4f3b8ab5213aa4cd336cd5e)
    #12 RFRemoveReader PCSC/src/readerfactory.c:624:5 (pcscd+0xdd282) (BuildId: 046d0874ce19c882d4f3b8ab5213aa4cd336cd5e)
    #13 RFRemoveReader PCSC/src/readerfactory.c:624:5 (pcscd+0xdd282) (BuildId: 046d0874ce19c882d4f3b8ab5213aa4cd336cd5e)
    #14 RFCleanupReaders PCSC/src/readerfactory.c:1396:9 (pcscd+0xddb9e) (BuildId: 046d0874ce19c882d4f3b8ab5213aa4cd336cd5e)
    #15 SVCServiceRunLoop PCSC/src/pcscdaemon.c:123:4 (pcscd+0xd9574) (BuildId: 046d0874ce19c882d4f3b8ab5213aa4cd336cd5e)
    #16 main PCSC/src/pcscdaemon.c:801:2 (pcscd+0xd8810) (BuildId: 046d0874ce19c882d4f3b8ab5213aa4cd336cd5e)

  Previous read of size 4 at 0x7fd1b32be970 by thread T7:
    #0 LunToReaderIndex CCID/src/utils.c:72:14 (libccid.so+0xf8aa) (BuildId: 69b3a74d7af87f05c5edb71935a43b024a0fe968)
    #1 IFDHPolling CCID/src/ifdhandler.c:313:28 (libccid.so+0xb1bf) (BuildId: 69b3a74d7af87f05c5edb71935a43b024a0fe968)
    #2 EHStatusHandlerThread PCSC/src/eventhandler.c:467:10 (pcscd+0xd6f9b) (BuildId: 046d0874ce19c882d4f3b8ab5213aa4cd336cd5e)

  As if synchronized via sleep:
    #0 nanosleep <null> (pcscd+0x515ed) (BuildId: 046d0874ce19c882d4f3b8ab5213aa4cd336cd5e)
    #1 SYS_Sleep PCSC/src/sys_unix.c:69:9 (pcscd+0xdfbf9) (BuildId: 046d0874ce19c882d4f3b8ab5213aa4cd336cd5e)
    #2 SVCServiceRunLoop PCSC/src/pcscdaemon.c:117:10 (pcscd+0xd956a) (BuildId: 046d0874ce19c882d4f3b8ab5213aa4cd336cd5e)
    #3 main PCSC/src/pcscdaemon.c:801:2 (pcscd+0xd8810) (BuildId: 046d0874ce19c882d4f3b8ab5213aa4cd336cd5e)

  Location is global 'ReaderIndex' of size 64 at 0x7fd1b32be970 (libccid.so+0x22970)

  Mutex M0 (0x7b0c00000ed0) created at:
    #0 pthread_mutex_init <null> (pcscd+0x555cf) (BuildId: 046d0874ce19c882d4f3b8ab5213aa4cd336cd5e)
    #1 RFAddReader PCSC/src/readerfactory.c:355:9 (pcscd+0xdb4b7) (BuildId: 046d0874ce19c882d4f3b8ab5213aa4cd336cd5e)
    #2 HPAddDevice PCSC/src/hotplug_libudev.c:512:8 (pcscd+0xe3409) (BuildId: 046d0874ce19c882d4f3b8ab5213aa4cd336cd5e)
    #3 HPScanUSB PCSC/src/hotplug_libudev.c:579:3 (pcscd+0xe2a1d) (BuildId: 046d0874ce19c882d4f3b8ab5213aa4cd336cd5e)
    #4 HPRegisterForHotplugEvents PCSC/src/hotplug_libudev.c:761:2 (pcscd+0xe2a1d)
    #5 main PCSC/src/pcscdaemon.c:768:7 (pcscd+0xd8717) (BuildId: 046d0874ce19c882d4f3b8ab5213aa4cd336cd5e)

  Mutex M1 (0x7fd1b32be948) created at:
    #0 pthread_mutex_lock <null> (pcscd+0x71ada) (BuildId: 046d0874ce19c882d4f3b8ab5213aa4cd336cd5e)
    #1 CreateChannelByNameOrChannel CCID/src/ifdhandler.c:119:8 (libccid.so+0x82ae) (BuildId: 69b3a74d7af87f05c5edb71935a43b024a0fe968)
    #2 IFDHCreateChannelByName CCID/src/ifdhandler.c:233:9 (libccid.so+0x7e55) (BuildId: 69b3a74d7af87f05c5edb71935a43b024a0fe968)
    #3 IFDOpenIFD PCSC/src/ifdwrapper.c:136:9 (pcscd+0xdd0cb) (BuildId: 046d0874ce19c882d4f3b8ab5213aa4cd336cd5e)
    #4 RFInitializeReader PCSC/src/readerfactory.c:1121:8 (pcscd+0xdd0cb)
    #5 RFAddReader PCSC/src/readerfactory.c:366:7 (pcscd+0xdb52a) (BuildId: 046d0874ce19c882d4f3b8ab5213aa4cd336cd5e)
    #6 RFAddReader PCSC/src/readerfactory.c:366:7 (pcscd+0xdb52a) (BuildId: 046d0874ce19c882d4f3b8ab5213aa4cd336cd5e)
    #7 HPAddDevice PCSC/src/hotplug_libudev.c:512:8 (pcscd+0xe3409) (BuildId: 046d0874ce19c882d4f3b8ab5213aa4cd336cd5e)
    #8 HPScanUSB PCSC/src/hotplug_libudev.c:579:3 (pcscd+0xe2a1d) (BuildId: 046d0874ce19c882d4f3b8ab5213aa4cd336cd5e)
    #9 HPRegisterForHotplugEvents PCSC/src/hotplug_libudev.c:761:2 (pcscd+0xe2a1d)
    #10 main PCSC/src/pcscdaemon.c:768:7 (pcscd+0xd8717) (BuildId: 046d0874ce19c882d4f3b8ab5213aa4cd336cd5e)

  Thread T7 (tid=4049, running) created by thread T4 at:
    #0 pthread_create <null> (pcscd+0x53dfd) (BuildId: 046d0874ce19c882d4f3b8ab5213aa4cd336cd5e)
    #1 ThreadCreate PCSC/src/utils.c:184:8 (pcscd+0xe3cab) (BuildId: 046d0874ce19c882d4f3b8ab5213aa4cd336cd5e)
    #2 EHSpawnEventHandler PCSC/src/eventhandler.c:233:7 (pcscd+0xd6840) (BuildId: 046d0874ce19c882d4f3b8ab5213aa4cd336cd5e)
    #3 RFAddReader PCSC/src/readerfactory.c:397:8 (pcscd+0xdb6ba) (BuildId: 046d0874ce19c882d4f3b8ab5213aa4cd336cd5e)
    #4 HPAddDevice PCSC/src/hotplug_libudev.c:512:8 (pcscd+0xe3409) (BuildId: 046d0874ce19c882d4f3b8ab5213aa4cd336cd5e)
    #5 HPEstablishUSBNotifications PCSC/src/hotplug_libudev.c:646:6 (pcscd+0xe3783) (BuildId: 046d0874ce19c882d4f3b8ab5213aa4cd336cd5e)

SUMMARY: ThreadSanitizer: data race CCID/src/utils.c:81:21 in ReleaseReaderIndex
==================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants