ifd-gempc-1.0.7/ 0000755 0001750 0001750 00000000000 11740401711 013644 5 ustar rousseau rousseau ifd-gempc-1.0.7/MANIFEST 0000644 0001750 0001750 00000002031 11146613715 015002 0 ustar rousseau rousseau Changelog
check
common/COPYING.BSD
common/COPYING.GPL
common/.dependencies
common/GCCmds.c
common/GCCmds.h
common/GCdebug.c
common/GCdebug.h
common/GCTransport.h
common/GCUtils.c
common/GCUtils.h
common/GemCore.h
common/gempc_ifdhandler.h
common/ifdhandler.c
common/Makefile
create_distrib.sh
GemPC410/Config.h
GemPC410/COPYING.GPL
GemPC410/.dependencies
GemPC410/gbpserial.c
GemPC410/gbpserial.h
GemPC410/GCGBPTransport.c
GemPC410/GemPC410Utils.c
GemPC410/GemPC410Utils.h
GemPC410/main.c
GemPC410/Makefile
GemPC410/resetGemPC410.c
GemPC410/TODO.txt
GemPC430/Config.h
GemPC430/COPYING
GemPC430/.dependencies
GemPC430/GCUSBTransport.c
GemPC430/GemPC430Utils.c
GemPC430/GemPC430Utils.h
GemPC430/Info.plist
GemPC430/libusb_wrap.c
GemPC430/libusb_wrap.h
GemPC430/Makefile
GemPC430/TODO.txt
GemPC430/usbserial.h
GemPC430/usbserial_mosx.c
MacOSXbuild/debuglog.h
MacOSXbuild/ifd-GemPC430/English.lproj/InfoPlist.strings
MacOSXbuild/ifd-GemPC430/ifd-GemPC430.xcodeproj/project.pbxproj
MacOSXbuild/ifdhandler.h
Makefile
MANIFEST
README
README.410
README.430
ifd-gempc-1.0.7/README.430 0000644 0001750 0001750 00000002547 10561621046 015046 0 ustar rousseau rousseau Gemplus GemPC 430 reader driver README
======================================
Compilation under Unix (Linux, xBSD) except MacOSX
==================================================
The libgempc430 driver uses a library to access USB devices. This
library is libusb [1] and is available for Linux, NetBSD, FreeBSD,
OpenBSD, Darwin, MacOSX.
The MacOSX driver DO NOT use this library (even if it could).
You need to install this library and in particular its usb.h file to
compile the driver under GNU/Linux.
[1] http://libusb.sourceforge.net/
USB support under Linux
=======================
In order to use the USB ports your kernel needs to support usbdevfs.
You should have the following results:
$ grep usb /proc/devices
180 usb
$ grep usb /proc/filesystems
nodev usbdevfs
nodev usbfs
If it is not the case consult [2]. You may have to recompile your
kernel.
[2] http://www.linux-usb.org/
/proc/bus/usb/ directory under Linux
====================================
The driver accesses directly the devices in /proc/bus/usb/*. So this
directory /proc/bus/usb/ MUST exists.
You have at least two solutions to create this virtual directory:
- use the hotplug package from http://linux-hotplug.sourceforge.net/
- add a line to your /etc/fstab, see [3]
[3] /usr/src/linux/Documentation/usb/proc_usb_info.txt
$Id: README.430,v 1.4 2003-04-12 20:18:51 rousseau Exp $
ifd-gempc-1.0.7/README 0000644 0001750 0001750 00000041062 11740401707 014534 0 ustar rousseau rousseau Gemplus GemPC 410 and GemPC 430 IFD Handler
===========================================
This package provides the source code for the GemPC 410 (serial) and
GemPC 430 (usb) smart card familly readers PC/SC ifd handler.
Both readers use a GemCore chip and the same set of commands. Only the
low level transport layer is different.
See README.410 for GemPC410 specific comments.
See README.430 for GemPC430 specific comments.
Authors:
========
- David Corcoran for the original headers and empty ifdhandler.c file
- Jean-Luc Giraud for the main part of GemPC430/ and half of common/
- Ludovic Rousseau for the main part of GemPC410/ and half of common/
Supported readers:
==================
- GemPC 410
. normal GemPC 410 (GemCore-R1.21-GM)
. IBM 410p (v1.21)
. GemPC 410-SL (GemCore-R1.21-GM)
- GemPC 412
. GCR412 FirstUSA (GemCore-R1.21-GM)
- GemPC 413
. EMV complient (GemCore-R1.32-GK)
- GemPC 415
. VISA and American Express 415 (unkown)
- GemPC 430
. normal GemPC 430 (GemUsb-R1.04-GM)
- GemPC 432
. target.com (GemUsb-R1.04-WM)
- GemPC 435
. American Express Blue Card reader (GemUsb-R1.04-A)
The number in () is the GemCore version as seen in the logs generated by
the driver. Like in "(GemPC430) OS string: GemUsb-R1.04-GM" or
"(GemPC410) OS string: GemCore-R1.21-I"
Unsupported GemCore based readers:
==================================
- GCR400
Very old version of the GemPC410.
- GCR410
Old version of the GemPC410. This reader uses a GemCore version 1.118
or 1.10. With this firmware the case 4 commands (both input and output
data) will not work.
Licences:
=========
The files in GemPC410/ are under GNU General Public Licence.
The files in GemPC430/ are under a BSD-like licence (except main.c which
is under GPL but is not needed to build the driver).
The files in common/ are under a double licence BSD-like and GNU General
Public Licence. except the files ifdhandler.c, ifdhandler.h and
pcscdefines.h which are originally written by David Corcoran and are
under the BSD-like licence.
That means that the GemPC 410 driver is under GNU General Public
Licence, and that the GemPC 430 driver is the BSD-like licence or the
GNU General Public Licence at your choice.
Supported pcsc-lite versions
============================
pcsc-lite 1.1.2beta4 and later
You can get the latest pcsc-lite version from
http://linuxnet.com/middle.html or from
http://pcsclite.alioth.debian.org/
Get pcsc-lite higher than 1.2.0 if you want to use /etc/reader.conf
DEVICENAME fields managed by the new API IFDHCreateChannelByName()
History:
========
1.0.7 - 8 April 2012, Ludovic Rousseau
- add GemPC430/50-pcscd-ifd-gempc.rules udev file
- Use CFLAGS and LDFLAGS in Makefile (Debian bug #667931)
1.0.6 - 16 June 2010, Ludovic Rousseau
- fix an error in opening a serial port
Thanks to Joerg Hartenberger for the patch
- fix spelling error
1.0.5 - 12 April 2009, Ludovic Rousseau
- correctly manage LDFLAGS
Thanks to Arfrever Frehtes Taifersar Arahesis for the patch
- correct compilation warnings
1.0.4 - 15 October 2008, Ludovic Rousseau
- Allow the header to be read in several calls
Previously, if the header was not read in a single read() calls,
there was an error. This is an issue because some commands return
the two first bytes, then a small pause, then the rest of the
header ...
At least this happens on a gci410emv connected thru an usb adapter
... Now it works fine.
Patch from Sylvain Munaut
- Fix powerup sequence when switching to ISO mode
If somehow the reader/card was in EMV mode, we need to switch it
to ISO. This was done but the final attemp to powerup tried to
power it up in EMV mode ... most likely a typo.
Patch from Sylvain Munaut
1.0.3 - 14 August 2007, Ludovic Rousseau
- correct a big bug unnoticed for many years and declared on PowerPC
with gcc 4.x (Debian bug #428323)
- do not strip the library so we have debug symbols if needed.
strip should be called by the package build process (if needed)
1.0.2 - 29 June 2007, Ludovic Rousseau
- correctly handle empty response from the GemPC410 reader
1.0.1 - 9 February 2006, Ludovic Rousseau
- remove a useless "POUET" debug message
- allow compilation with pcsc-lite-1.2.9-beta10. The check script
was buggy for beta > 9
- fix some compilation warnings with gcc 4.0
1.0.0 - 17 June 2005, Ludovic Rousseau
- use new pcscd log function with dynamic level
- use `pkg-config libpcsclite --variable=usbdropdir` to know where
to install the driver
0.9.3 - 8 August 2004, Ludovic Rousseau
- maintainance release to make it compile using gcc-3.4
0.9.2 - 25 July 2004, Ludovic Rousseau
- use the header files provided by pcsc-lite 1.2.9-beta
- use pkg-config to know the where to find the pcsc-lite include
files
- minium pcsc-lite version is 1.2.9-beta5
0.9.1 - 27 February 2004, Ludovic Rousseau
- add a compilation flag AUTOMATIC_PPS to activate automatic PPS
negociation by the reader firmware. I received many bug reports
with some cards. The card works until some APDU returns a
"invalid procedure byte" error. By default the automatic PPS
negociation is now NOT performed. Uncomment a line in
GemPC4?0/Config.h to revert to the previous behavior and choose
speed versus safety
- GemPC430/libusb_wrap.c: use pcsc-lite new
IFDHCreateChannelByName() scheme: usb:vendor/product
In 0.9.0 the driver failed when used with a CVS version of
pcsc-lite. Thanks to Dr Russel Winder for the bug report
- common/GCCmds.h: the GemCore error message now contains the file,
function and line number of the command with error and not of the
error printing function
- add two GemCore error code descriptions: 0x15 and 0xE4
0.9.0 - 22 January 2004, Ludovic Rousseau
- add support of IFDHCreateChannelByName() (from pcsc-lite > 1.2.0)
- GemPC430/libusb_wrap.c: reset the reader in case of timeout on
write (reader freeze?). Thanks to Patrick Valsecchi for the patch.
- use asymetric timeout for USB read and write. The reader/card may
be busy when we read (long timeout) but should be OK when we write
(short timeout)
0.8.2 - 22 Octobre 2003, Ludovic Rousseau
- Remove support for multi slot. The code was never used and is now
broken under revent pcsc-lite versions. The error under pcsc-lite is:
readerfactory.c:1391 RFInitializeReader: Attempting startup of GemPC430 0 0.
readerfactory.c:1133 RFBindFunctions: Loading IFD Handler 2.0
ifdhandler.c:87 (GemPC43x) Entering IFDHCreateChannel (lun: 0)
GCCmds.c:394 (GemPC43x) GCCmdSetMode
GCCmds.c:319 (GemPC43x) GCCmdGetOSVersion
GemPC430Utils.c:51 (GemPC43x) OS string: GemUsb-R1.04-GM
ifdhandler.c:158 (GemPC43x) entering IFDHGetCapabilities (lun: 0)
ifdhandler.c:158 (GemPC43x) entering IFDHGetCapabilities (lun: 0)
readerfactory.c:1391 RFInitializeReader: Attempting startup of GemPC430 0 1.
readerfactory.c:925 RFLoadReader: Warning library pointer not NULL
readerfactory.c:1133 RFBindFunctions: Loading IFD Handler 2.0
ifdhandler.c:87 (GemPC43x) Entering IFDHCreateChannel (lun: 1)
libusb_wrap.c:106 (GemPC43x) USB driver with lun 1 already in use
GemPC430Utils.c:30 (GemPC43x) OpenUSB failed
ifdhandler.c:102 (GemPC43x) OpenReader failed
readerfactory.c:1428 RFInitializeReader: Open Port 200000 Failed
readerfactory.c:423 RFAddReader: GemPC430 init failed.
hotplug_libusb.c:344 Adding USB device: 002:002
readerfactory.c:119 RFAddReader: Duplicate reader found.
hotplug_libusb.c:344 Adding USB device: 002:002
readerfactory.c:119 RFAddReader: Duplicate reader found.
[...]
The reader told pcsc-lite that it supported two slots and
pcsc-lite wanted to start two readers (one for each slot).
- add support for 7 new GemCore error codes
- check: Explain how to tell check to look elsewhere than just /usr/
and /usr/local/
0.8.1 - 2 Septembre 2003, Ludovic Rousseau
- ./check: uses paths defined in the Makefiles (if libusb is not
installed in /usr or /usr/local)
- common/GCCmds.c: add support of GemCore "Parity error during
exchange"
- GemPC410/devfs/libgempc410.devfsd.conf: use $devpath instead of
$devname otherwise we have /dev/pcsc/1 -> tts/0 instead of
/dev/pcsc/1 -> /dev/tts/0
- GemPC430/Info.plist: use new style
- common/ifdhandler.c: FDHGetCapabilities() add support of tag
TAG_IFD_SLOTS_NUMBER. All the readers I have/know have only one
slot so this does not bring any new real functionnality.
- Makefiles: do not exit with failure if makedepend(1) does not
exist
- update build and distclean rules.
0.8.0 - 12 April 2003, Ludovic Rousseau
- Add support for GemPC 413 reader. That reader uses GemCore 2000
and is EMV complient (different powerup sequence).
- Add support for driver aliasing for USB drivers. Allows to connect
different readers like a 430 and a 432 at the same time. You will
need pcsc-lite-1.1.2beta4 for that.
- change USB timeout from 10 to 60 seconds.
- check: do not use /usr/local/include by default since cpp will
warning on some systems (recent RedHat systems).
- optimize Makefile to limit restarting unnecessary check and building.
- driver filename for USB is now versioned (ie libGemPC430.so.0.8.0).
0.7.4 - 20 November 2002, Ludovic Rousseau
- add comment on how to compile the USB driver (install libusb, etc.)
- add the ./check script (MacOS X is not concerned here).
Many users add problems with a "undefined symbol: debug_msg" error
when starting pcscd. It will now NOT be possible to compile the
drivers unless the _minimum_ versions of libusb and pcsc-lite are
installed.
0.7.3 - 18 October 2002, Ludovic Rousseau
- The GemPC430 driver under Linux now support hotplug. With the
previous versions the reader(s) needed to be plugged _before_
pcscd is started.
0.7.2 - 15 October 2002, Ludovic Rousseau
- very very small modification. The previous compilation problem was
not corrected.
0.7.1 - 15 October 2002, Ludovic Rousseau
- very small modification to ease or allow compilation on some
platforms (all 11 Debian supported platforms except i386)
0.7.0 - 13 October 2002, Jean-Luc Giraud, Ludovic Rousseau
- the drivers are now shipped with low level debug messages OFF
- do not depend on makedepend(1) anymore. Use it if present only.
- GemPC410:
- retry the last command if GBP returns a wrong first byte (NAD).
This will help some GemPC410 to work. Before pcscd had to be
started a second time.
- add support for GemCore Repeat requests
- GemPC410/devfs/ contains configuration files for devfs Linux systems
- README.430: add a note about /proc/bus/usb/ directory under Linux
- usbserial_mosx.c:
- better stability and multiple reader support
- the productId is now read from the Info.plist. This allow to
support readers like the 432 and 435 without recompiling the
library
- libusb_wrap.[c|h] new files to use libusb under Linux and other
systems supported by libusb. The USB driver _should_ work under
FreeBSD and OpenBSD but in fact does not.
0.6.5 - 16 August 2002, Ludovic Rousseau
- update README with the new readers supported (412, 415, 432, 435)
- we now use the debug facilities from pcscd. see "Supported
pcsc-lite" section
- GemPC410/gbpserial.c: the serial initialisation should work
- GemPC430/usbserial_linux.c: support for 432 and 435 readers
0.6.4 - 21 May 2002, Ludovic Rousseau
- common/GCCmds.c: perform a powerup without PPS managment if the
powerup with PPS managment failed
- */Makefile: correctly remove .dependencies files
- change sys_errlist[errno] to strerror(errno) to be (more) ready
for the Hurd
0.6.3 - 9 May 2002, Ludovic Rousseau
- README.410: Add info on /dev/pcsc/ for OpenBSD and FreeBSD
- Case1 APDUs are converted in ISO IN commands (with length=0)
instead of ISO OUT commands
- some code cleanup
0.6.2 - 01 Apr 2002, Ludovic Rousseau, Jean-Luc Giraud
- Add support for TAG_IFD_SIMULTANEOUS_ACCESS in IFDHGetCapabilities
- Restore automatic PPS management compatible with Cyberflex
- GemPC430/usbserial_mosx.c: fixes for multi-reader support
- GemPC410/gbpserial.c: complete reimplementation of serial port
configuration
0.6.1 - 11 Mar 2002, Ludovic Rousseau
- GemPC410/gbpserial.c:
. modified again the port BAUDS setting during open().
0.6.0 - 7 Mar 2002, Ludovic Rousseau
- GemPC410/gbpserial.c:
. modified the port BAUDS setting during open().
. Changed the timeout delay from 2 to 10 seconds
- common/ifdhandler.c: IFDHTransmitToICC: now manages case 1 APDU
(only CLA, INS, P1, P2) as an outgoing APDU (CLA, INS, P1, P2, 0)
- add a debug level: PERIODIC for... periodic calls. Do not define
DEBUG_LEVEL_PERIODIC in GemPC4?0/Config.h if you don't want to see
periodic logs from GCCmdCardStatus(), IFDHSetCapabilities() and
IFDHICCPresence()
- add a note about support of the IBM-410p reader.
0.5.10 - 3 Mar 2002, Ludovic Rousseau, Jean-Luc Giraud
- fix bug with some kind of Cyberflex Access cards:
. disable PPS management
. the reader stays at 9600 bauds in all cases
- fix bug when more than 252 output bytes are expected and less than
that are available (which is the case when the card sends an error)
- modify install: rule to include release version number in
filename, create symlinks, remove execution right on the .so lib
- README.410: Add a script to create the /dev/pcsc/? links
- GemPC430/GemPC430Utils.c, GemPC410/GemPC410Utils.c,
common/GCCmds.c: guarantee that the os_string is \0 terminated
- GemPC410/resetGemPC410.c, GemPC410/gbpserial.c: use
cfgetospeed()/cfsetospeed() instead of accessing directly the
termios structure
. the driver now works under OpenBSD
- common/ifdhandler.c: also log APDU results
0.5.9 - 30 Nov 2001, Jean-Luc Giraud
- fix bug in GCUtils.c/gemcore_ISO_EXCHANGE_processing()
- added ProjectBuilder folder for MacOS X
0.5.8 - 27 Nov 2001, Ludovic Rousseau
- MANIFEST: do not contain non existing files
include create_distrib.sh
- create_distrib.sh: exit in case of error
mkdir creates the parents directories if needed,
0.5.7 - 27 Nov 2001, Ludovic Rousseau
- GemPC430/usblinux.c: crashed with two readers and no root
priviledges
- GemPC410/main.c: test code now support ISO 7816 case 1, 2, 3 and 4
using Jean-Luc ReaderTest Java applet (not included here)
- common/GCUtils.c: add support for IFD_ICC_NOT_PRESENT GemCore
error status
- GemPC410/gbpserial.c: prepare to support multi serial readers
- GemPC430/usbserial_mosx.c: prepare to support multi USB readers
- GemPC410/gbpserial.c: use explain_gbp() to log a descriptive GBP
level error message
- MANIFEST: add README.410
- GemPC410/GemPC410Utils.c: log "OS string" at CRITICAL level to
always have it the logs
- GemPC430/GemPC430Utils.c: log "OS string" at CRITICAL level to
always have it the logs
- common/ifdhandler.c: Add APDU logging
- common/GCdebug.h: add DEBUG_COMM3() and DEBUG_CRITICAL3() which is
typically used to log error messages like "blabla /foo/bar: file not
found"
0.5.6 - 15 Nov 2001, Ludovic Rousseau
- all: migrate the type return value from RESPONSECODE to ifd_t,
status_t or gcore_t
- GCCmds.c: migrate from low level GCSendCommand() use to higer
level and simpler GCMakeCommand()
- libGemPC410 now supports long commands
0.5.5 - 7 Nov 2001, Ludovic Rousseau
include Jean-Luc modifications to add a new protocol layer
patch GemPC410 to support this layer
include patches from the Debian package
0.5.4 - 28 Oct 2001, Ludovic Rousseau
first public release
I clarified the licences
0.5.3 - 26 Oct 2001, Ludovic Rousseau
GemPC 410 and GemPC 430 compiles and runs
0.5.2bis - 23 Oct 2001, Jean-Luc Giraud
Jean-Luc starts to dispatch ifdhandler.c
0.5.2 - 22 Oct 2001, Ludovic Rousseau
first release containing GemPC410/ GemPC430/ and common/
0.5 - 14 Oct 2001, Jean-Luc Giraud
complete release containing the code for the GemPC 430
?.? - 25 Sep 2001, Jean-Luc Giraud
release of ifdhandler.{c,h} and GemCore.h
$Id: README,v 1.41 2012-04-08 21:31:51 rousseau Exp $
vim:ts=20
ifd-gempc-1.0.7/README.410 0000644 0001750 0001750 00000001713 10561621046 015036 0 ustar rousseau rousseau Gemplus GemPC 410 reader driver README
======================================
/etc/reader.conf
================
The /etc/reader.conf should contain something like:
FRIENDLYNAME "GemPC410"
DEVICENAME /dev/ttyS0
LIBPATH /usr/local/pcsc/drivers/serial/libGemPC410.so.0
CHANNELID 1
Note that CHANNELID may be anything since it is not used by recent
versions of pcscd (> 1.2.0) anymore and is deprecated. Be sure that
DEVICENAME is really the device name you use.
Under *BSD the serial ports are named /dev/cuaa* instead of /dev/ttyS*.
/dev/pcsc/ directory
====================
/dev/pcsc/ is deprecated since pcscd now uses DEVICENAME instead of
CHANNELID since the driver implement the ifdhandler API version 3.0.
The driver does not use /dev/ttyS? (the serial port device) directly but
uses /dev/pcsc/{1,2,3,4} which should be symbolic links to the real
serial port devices.
$Id: README.410,v 1.8 2004-01-20 14:34:39 rousseau Exp $
ifd-gempc-1.0.7/GemPC430/ 0000755 0001750 0001750 00000000000 11740401711 015026 5 ustar rousseau rousseau ifd-gempc-1.0.7/GemPC430/TODO.txt 0000644 0001750 0001750 00000001120 10561621210 016324 0 ustar rousseau rousseau GemPC430 todo list
==================
- Add management of memory cards
- Add PTS management (store it in set capabilities, send it in RESET/POWER_UP)
- Implement IFDHSetCapabilities
- Implement IFDHSetProtocolParameters
- Implement IFDHControl
- If receive buffer is too small for Data + SW, truncate data and always include SW
- investigate the issue with 2 programs communicating with one reader.
DONE
====
- Test T=1 mode
- Check all GemCore possible status in status management functions
- 3V cards are not currently supported.
$Id: TODO.txt,v 1.3 2004-02-25 13:24:59 rousseau Exp $
ifd-gempc-1.0.7/GemPC430/usbserial.h 0000644 0001750 0001750 00000001103 11740360155 017171 0 ustar rousseau rousseau /**************************************************************
/ Title: usbserial.h
/ Author: David Corcoran
/ Purpose: Abstracts usb API to serial like calls
/ $Id: usbserial.h,v 1.8 2012/04/08 19:01:01 rousseau Exp $
***************************************************************/
#ifndef _USBSERIAL_H_
#define _USBSERIAL_H_
status_t OpenUSB( DWORD lun, DWORD channel );
status_t WriteUSB( DWORD lun, DWORD length, unsigned char *Buffer );
status_t ReadUSB( DWORD lun, DWORD *length, unsigned char *Buffer );
status_t CloseUSB( DWORD lun );
#endif
ifd-gempc-1.0.7/GemPC430/.dependencies 0000644 0001750 0001750 00000000000 11740401711 017443 0 ustar rousseau rousseau ifd-gempc-1.0.7/GemPC430/libusb_wrap.h 0000644 0001750 0001750 00000000704 10561621310 017510 0 ustar rousseau rousseau /*
* libusb_wrap.h
* Id$
* USB access routines using the libusb library
*
* Author: Ludovic Rousseau
* Copyright (c) 2002 Ludovic Rousseau
* License: See file COPYING.GPL
*/
#ifndef _LIBUSB_WRAP_
#define _LIBUSB_WRAP_
status_t OpenUSB( DWORD lun, LPSTR device );
status_t WriteUSB( DWORD lun, DWORD length, unsigned char *Buffer );
status_t ReadUSB( DWORD lun, DWORD *length, unsigned char *Buffer );
status_t CloseUSB( DWORD lun );
#endif
ifd-gempc-1.0.7/GemPC430/GemPC430Utils.c 0000644 0001750 0001750 00000003164 11170331326 017402 0 ustar rousseau rousseau /*
* GemPC430Utils.c
* $Id: GemPC430Utils.c,v 1.20 2009-04-12 09:22:30 rousseau Exp $
* GemPC430 dedicated functions
*
* Created by giraud on Sat Oct 20 2001.
* Copyright (c) 2001 Jean-Luc Giraud.
* 2001-2004 Ludovic Rousseau
* License: See file COPYING
*
*/
#include
#include "gempc_ifdhandler.h"
#include "Config.h"
#include "GemPC430Utils.h"
#include "GemCore.h"
#include "GCCmds.h"
#include "libusb_wrap.h"
#include "GCdebug.h"
#include "GCTransport.h"
ifd_t OpenGemPC430ByName(DWORD lun, LPSTR dev_name)
{
UCHAR os_version[IFD_LEN_VERSION+2];
DWORD length;
if (OpenUSB(lun, dev_name) != STATUS_SUCCESS)
{
DEBUG_CRITICAL("OpenUSB failed");
return IFD_COMMUNICATION_ERROR;
}
/* Set the mode to ROS but no TLP (ATR should then be fine) */
if ( GCCmdSetMode(lun, IFD_MODE_ROSNOTLP) != IFD_SUCCESS )
{
DEBUG_CRITICAL("Setmode failed");
CloseUSB(lun);
return IFD_COMMUNICATION_ERROR;
}
/* Get the GemCore OS version */
length = sizeof(os_version);
if (GCCmdGetOSVersion(lun, &length, os_version) != IFD_SUCCESS)
{
DEBUG_CRITICAL("GCCmdGetOSVersion failed");
return IFD_COMMUNICATION_ERROR;
}
/* Not really critical but shall be logged */
DEBUG_CRITICAL2("OS string: %s", os_version);
return IFD_SUCCESS;
} /* OpenGemPC430ByName */
ifd_t OpenGemPC430(DWORD lun, DWORD channel)
{
(void)channel;
return OpenGemPC430ByName(lun, NULL);
} /* OpenGemPC430 */
ifd_t CloseGemPC430(DWORD lun)
{
if ( CloseUSB(lun) != STATUS_SUCCESS)
return IFD_COMMUNICATION_ERROR;
return IFD_SUCCESS;
} /* CloseGemPC430 */
ifd-gempc-1.0.7/GemPC430/libusb_wrap.c 0000644 0001750 0001750 00000020275 11740361172 017517 0 ustar rousseau rousseau /*
* libusb_wrap.c
* $Id: libusb_wrap.c,v 1.24 2012/04/08 19:09:46 rousseau Exp $
* USB access routines using the libusb library
*
* Created by Ludovic Rousseau on Sep 27 2002
* Copyright (c) 2002 Ludovic Rousseau
* License: See file COPYING.GPL
*/
#include
#include
#include
#include
#include "gempc_ifdhandler.h"
#include "Config.h"
#include "GCdebug.h"
#include "GCUtils.h"
#include "GemCore.h"
#include "libusb_wrap.h"
#define USB_INEP 0
#define USB_OUTEP 1
/* read timeout
* we must wait enough so that the card can finish its calculation */
#define USB_READ_TIMEOUT 60000 /* 1 minute timeout */
/* write timeout
* we don't have to wait a long time since the card was doing nothing */
#define USB_WRITE_TIMEOUT 5000 /* 5 seconds timeout */
typedef struct
{
int kMyVendorID;
int kMyProductID;
} _usbID;
/*
* Add an entry to match your reader.
*/
static _usbID UsbIDs[] =
{
{ 0x08E6, 0x0430 }, /* GemPC 430 */
{ 0x08E6, 0x0432 }, /* GemPC 432 */
{ 0x08E6, 0x0435 } /* GemPC 435 */
};
/* used to store string %s/%s (dirname/filename) like:
* (/proc/bus/usb/) 001/002 (Linux)
* /dev/usb0//dev/ (FreeBSD)
* /dev/usb0//dev/ugen0 (OpenBSD)
*/
#define BUS_DEVICE_STRSIZE 32
typedef struct
{
usb_dev_handle *handle;
struct usb_device *dev;
int interface;
/*
* Endpoints
*/
int bulk_in;
int bulk_out;
} _usbDevice;
#if (PCSCLITE_MAX_READERS-16)
#error Edit this file and set the number of initialiser to PCSCLITE_MAX_READERS (default was 16 but it has changed)
#endif
static _usbDevice usbDevice[PCSCLITE_MAX_READERS] = {
[ 0 ... (PCSCLITE_MAX_READERS-1) ] = { NULL, NULL, 0, 0, 0 }
};
/*****************************************************************************
*
* OpenUSB
*
****************************************************************************/
status_t OpenUSB(DWORD lun, LPSTR device)
{
static struct usb_bus *busses = NULL;
int id, id_number;
int reader = LunToReaderIndex(lun);
struct usb_bus *bus;
struct usb_dev_handle *dev_handle;
int device_vendor, device_product;
DEBUG_COMM3("Lun: %lX, Device: %s", lun, device);
/* device name specified */
if (device)
{
if (strncmp("usb:", device, 4) != 0)
{
DEBUG_CRITICAL2("device name does not start with \"usb:\": %s",
device);
return STATUS_UNSUCCESSFUL;
}
if (sscanf(device, "usb:%x/%x", &device_vendor, &device_product) != 2)
{
DEBUG_CRITICAL2("device name can't be parsed: %s", device);
return STATUS_UNSUCCESSFUL;
}
}
if (busses == NULL)
usb_init();
usb_find_busses();
usb_find_devices();
busses = usb_get_busses();
if (busses == NULL)
{
DEBUG_CRITICAL("No USB busses found");
return STATUS_UNSUCCESSFUL;
}
/* is the lun already used? */
if (usbDevice[reader].handle != NULL)
{
DEBUG_CRITICAL2("USB driver with lun %lX already in use", lun);
return STATUS_UNSUCCESSFUL;
}
/* find any devide corresponding to a UsbIDs entry */
id_number = sizeof(UsbIDs)/sizeof(UsbIDs[0]);
/* for any supported reader */
for (id=0; idnext)
{
struct usb_device *dev;
/* any device on this bus */
for (dev = bus->devices; dev; dev = dev->next)
{
if (dev->descriptor.idVendor == UsbIDs[id].kMyVendorID
&& dev->descriptor.idProduct == UsbIDs[id].kMyProductID)
{
int r, already_used;
int interface;
/* is it already opened? */
already_used = FALSE;
for (r=0; rdirname, dev->filename);
if (strcmp(usbDevice[r].dev->bus->dirname, bus->dirname) == 0 && strcmp(usbDevice[r].dev->filename, dev->filename) == 0)
already_used = TRUE;
}
}
/* this reader is already managed by us */
if (already_used)
{
DEBUG_INFO3("USB device %s/%s already in use. Checking next one.",
bus->dirname, dev->filename);
continue;
}
DEBUG_COMM3("Trying to open USB device: %s/%s",
bus->dirname, dev->filename);
dev_handle = usb_open(dev);
if (dev_handle == NULL)
{
DEBUG_CRITICAL4("Can't usb_open(%s/%s): %s",
bus->dirname, dev->filename, strerror(errno));
continue;
}
/* now we found a free reader and we try to use it */
if (dev->config == NULL)
{
DEBUG_CRITICAL3("No dev->config found for %s/%s",
bus->dirname, dev->filename);
return STATUS_UNSUCCESSFUL;
}
interface = dev->config->interface->altsetting->bInterfaceNumber;
if (usb_claim_interface(dev_handle, interface) < 0)
{
DEBUG_CRITICAL4("Can't claim interface %s/%s: %s",
bus->dirname, dev->filename, strerror(errno));
return STATUS_UNSUCCESSFUL;
}
DEBUG_COMM3("Using USB device: %s/%s",
bus->dirname, dev->filename);
/* store device information */
usbDevice[reader].handle = dev_handle;
usbDevice[reader].dev = dev;
usbDevice[reader].interface = interface;
usbDevice[reader].bulk_in = usbDevice[reader].dev->config->interface->altsetting->endpoint[USB_INEP].bEndpointAddress;
usbDevice[reader].bulk_out = usbDevice[reader].dev->config->interface->altsetting->endpoint[USB_OUTEP].bEndpointAddress;
goto end;
}
}
}
}
if (usbDevice[reader].handle == NULL)
return STATUS_UNSUCCESSFUL;
end:
return STATUS_SUCCESS;
} /* OpenUSB */
/*****************************************************************************
*
* WriteUSB
*
****************************************************************************/
status_t WriteUSB(DWORD lun, DWORD length, unsigned char *buffer)
{
int rv;
int reader = LunToReaderIndex(lun);
char debug_header[] = "-> 121234 ";
sprintf(debug_header, "-> %06X ", (int)lun);
DEBUG_XXD(debug_header, buffer, length);
rv = usb_bulk_write(usbDevice[reader].handle, usbDevice[reader].bulk_out,
(char *)buffer, length, USB_WRITE_TIMEOUT);
if (rv < 0)
{
if (usbDevice[reader].dev->bus)
{
DEBUG_CRITICAL4("%s/%s: %s", usbDevice[reader].dev->bus->dirname,
usbDevice[reader].dev->filename, strerror(errno));
/* reset in case of timeout (usually means a reader freeze)
* The application will receive an error but can try to reconnect.
* Without the patch the reader must be physically
* unpluged-repluged */
if (errno == ETIMEDOUT)
{
DEBUG_CRITICAL3("Reseting the reader: %s/%s",
usbDevice[reader].dev->bus->dirname,
usbDevice[reader].dev->filename);
usb_reset(usbDevice[reader].handle);
}
}
else
DEBUG_CRITICAL2("usb_bulk_write(no device): %s", strerror(errno));
return STATUS_UNSUCCESSFUL;
}
return STATUS_SUCCESS;
} /* WriteUSB */
/*****************************************************************************
*
* ReadUSB
*
****************************************************************************/
status_t ReadUSB(DWORD lun, DWORD * length, unsigned char *buffer)
{
int rv;
int reader = LunToReaderIndex(lun);
char debug_header[] = "<- 121234 ";
sprintf(debug_header, "<- %06X ", (int)lun);
rv = usb_bulk_read(usbDevice[reader].handle, usbDevice[reader].bulk_in,
(char *)buffer, *length, USB_READ_TIMEOUT);
*length = rv;
if (rv < 0)
{
DEBUG_CRITICAL4("%s/%s: %s", usbDevice[reader].dev->bus->dirname,
usbDevice[reader].dev->filename, strerror(errno));
return STATUS_UNSUCCESSFUL;
}
DEBUG_XXD(debug_header, buffer, *length);
return STATUS_SUCCESS;
} /* ReadUSB */
/*****************************************************************************
*
* CloseUSB
*
****************************************************************************/
status_t CloseUSB(DWORD lun)
{
int reader = LunToReaderIndex(lun);
DEBUG_COMM3("device: %s/%s", usbDevice[reader].dev->bus->dirname,
usbDevice[reader].dev->filename);
usb_release_interface(usbDevice[reader].handle,
usbDevice[reader].interface);
usb_close(usbDevice[reader].handle);
/* mark the resource unused */
usbDevice[reader].handle = NULL;
usbDevice[reader].dev = NULL;
return STATUS_SUCCESS;
} /* CloseUSB */
ifd-gempc-1.0.7/GemPC430/GCUSBTransport.c 0000644 0001750 0001750 00000003501 11740361172 017757 0 ustar rousseau rousseau /*
* $Id: GCUSBTransport.c,v 1.6 2012/04/08 19:09:46 rousseau Exp $
* ifd-GemPC
*
* Created by JL Giraud on Sun Nov 19 2000.
* Updated by Ludovic Rousseau , Oct 2001
*
* Transport level for the GemPC430 of Gemplus.
*
* License: See file COPYING
*
*/
#include
#include "gempc_ifdhandler.h"
#include "Config.h"
#include "GCTransport.h"
#include "usbserial.h"
status_t GCSendCommand(DWORD Lun, DWORD nLengthIn,
const UCHAR pcBufferCmd[], PDWORD pnLengthOut, UCHAR pcBufferOut[])
{
UCHAR pctr_to_card_buffer[GC_TR_BUF_SIZE];
status_t creturn_value;
DWORD nlength;
creturn_value = STATUS_SUCCESS;
if (GC_TR_BUF_SIZE <= nLengthIn)
{
/* Buffer is too small (should not happen) */
creturn_value = STATUS_DEVICE_PROTOCOL_ERROR;
goto finally;
}
memcpy(pctr_to_card_buffer+1, pcBufferCmd, nLengthIn);
pctr_to_card_buffer[TR_OFFSET_LNG] = nLengthIn;
if (WriteUSB(Lun, nLengthIn+1, pctr_to_card_buffer) != STATUS_SUCCESS)
{
creturn_value = STATUS_DEVICE_PROTOCOL_ERROR;
goto finally;
}
nlength = sizeof(pctr_to_card_buffer);
if (ReadUSB(Lun, &nlength, pctr_to_card_buffer) != STATUS_SUCCESS)
{
creturn_value = STATUS_DEVICE_PROTOCOL_ERROR;
goto finally;
}
if ( nlength < 1 )
{
/* length byte not received */
creturn_value = STATUS_DEVICE_PROTOCOL_ERROR;
goto finally;
}
nlength--;
*pnLengthOut = (*pnLengthOut