├── NEWS ├── MacOSX ├── wintypes.h ├── pcsclite.h ├── winscard.h ├── convert_reader_h.pl ├── configure └── debuglog.h ├── AUTHORS ├── readers └── Makefile.am ├── contrib ├── Makefile.am ├── RSA_SecurID │ ├── Makefile.am │ ├── RSA_SecurID_getpasswd.1 │ └── RSA_SecurID_getpasswd.c └── Kobil_mIDentity_switch │ ├── Makefile.am │ ├── Kobil_mIDentity_switch.8 │ ├── Kobil_mIDentity_switch.c │ └── README_Kobil_mIDentity_switch.txt ├── bootstrap ├── examples ├── Makefile.am ├── PCSCv2part10.c └── PCSCv2part10.h ├── src ├── reader.conf.in ├── towitoko │ ├── README │ ├── defines.h │ ├── pps.h │ ├── pps.c │ ├── atr.h │ └── atr.c ├── 92_pcscd_ccid.rules ├── openct │ ├── buffer.h │ ├── checksum.h │ ├── buffer.c │ ├── LICENSE │ ├── proto-t1.h │ └── checksum.c ├── utils.h ├── convert_version.pl ├── ccid_serial.h ├── strlcpy.c ├── ccid_usb.h ├── strlcpycat.h ├── parser.h ├── utils.c ├── ccid_ifdhandler.h ├── commands.h ├── create_Info_plist.pl ├── defs.h ├── misc.h ├── Makefile.am ├── Info.plist.src ├── debug.h ├── debug.c ├── tokenparser.l └── ccid.h ├── m4 ├── ltversion.m4 ├── as-ac-expand.m4 ├── ltsugar.m4 └── lt~obsolete.m4 ├── Makefile.am ├── Android.mk ├── SCARDGETATTRIB.txt ├── config.h.in ├── config.h ├── INSTALL ├── ar-lib ├── missing ├── ylwrap ├── compile └── configure.ac /NEWS: -------------------------------------------------------------------------------- 1 | Read the README file for news. 2 | -------------------------------------------------------------------------------- /MacOSX/wintypes.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Ludovic Rousseau 2 | -------------------------------------------------------------------------------- /MacOSX/pcsclite.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | -------------------------------------------------------------------------------- /MacOSX/winscard.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | -------------------------------------------------------------------------------- /readers/Makefile.am: -------------------------------------------------------------------------------- 1 | # $Id: Makefile.am 4747 2010-02-09 21:23:49Z rousseau $ 2 | 3 | EXTRA_DIST = supported_readers.txt 4 | -------------------------------------------------------------------------------- /contrib/Makefile.am: -------------------------------------------------------------------------------- 1 | if WITH_LIBUSB 2 | SUBDIRS = Kobil_mIDentity_switch RSA_SecurID 3 | else 4 | SUBDIRS = RSA_SecurID 5 | endif 6 | -------------------------------------------------------------------------------- /bootstrap: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | # $Id:$ 4 | 5 | set -x 6 | 7 | aclocal -I m4 8 | libtoolize --copy --force --automake 9 | autoheader --force 10 | autoconf --force 11 | automake --add-missing --copy --force --foreign 12 | -------------------------------------------------------------------------------- /contrib/RSA_SecurID/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_PROGRAMS = RSA_SecurID_getpasswd 2 | RSA_SecurID_getpasswd_SOURCES = RSA_SecurID_getpasswd.c 3 | 4 | RSA_SecurID_getpasswd_CFLAGS = $(PCSC_CFLAGS) 5 | RSA_SecurID_getpasswd_LDADD = $(PCSC_LIBS) 6 | 7 | noinst_MANS = RSA_SecurID_getpasswd.1 8 | 9 | EXTRA_DIST = $(noinst_MANS) 10 | -------------------------------------------------------------------------------- /examples/Makefile.am: -------------------------------------------------------------------------------- 1 | # Process this file with automake to create Makefile.in. 2 | 3 | noinst_PROGRAMS = scardcontrol 4 | scardcontrol_SOURCES = scardcontrol.c PCSCv2part10.c PCSCv2part10.h 5 | scardcontrol_CFLAGS = $(PCSC_CFLAGS) $(PTHREAD_CFLAGS) 6 | scardcontrol_LDADD = $(PCSC_LIBS) $(PTHREAD_LIBS) 7 | 8 | EXTRA_DIST = GPL-2 9 | -------------------------------------------------------------------------------- /contrib/Kobil_mIDentity_switch/Makefile.am: -------------------------------------------------------------------------------- 1 | noinst_PROGRAMS = Kobil_mIDentity_switch 2 | Kobil_mIDentity_switch_SOURCES = Kobil_mIDentity_switch.c 3 | Kobil_mIDentity_switch_CFLAGS = $(LIBUSB_CFLAGS) 4 | Kobil_mIDentity_switch_LDADD = $(LIBUSB_LIBS) 5 | 6 | noinst_DATA = README_Kobil_mIDentity_switch.txt 7 | 8 | noinst_MANS = Kobil_mIDentity_switch.8 9 | 10 | EXTRA_DIST = $(noinst_DATA) $(noinst_MANS) 11 | -------------------------------------------------------------------------------- /contrib/RSA_SecurID/RSA_SecurID_getpasswd.1: -------------------------------------------------------------------------------- 1 | .TH RSA_SecurID_getpasswd 1 "February 2008" 2 | .SH NAME 3 | RSA_SecurID_getpasswd \- get the one-use password from a RSA sid-800 4 | token 5 | . 6 | .SH SYNOPSIS 7 | .B RSA_SecurID_getpasswd 8 | . 9 | .SH DESCRIPTION 10 | RSA_SecurID_getpasswd sends to stdout the one-use password also 11 | displayed on the screen of a RSA sid-800 USB token. 12 | . 13 | .SH AUTHOR 14 | Ludovic Rousseau 15 | -------------------------------------------------------------------------------- /src/reader.conf.in: -------------------------------------------------------------------------------- 1 | # Gemalto reader with serial communication 2 | # - n is the serial port to use n in [0..3] 3 | # - reader is the reader name. It is needed for multi-slot readers. 4 | # Possible reader values are: 5 | # GemCorePOSPro 6 | # GemCoreSIMPro 7 | # GemCoreSIMPro2 8 | # GemPCPinPad 9 | # GemPCTwin (default value) 10 | # example: /dev/ttyS0:GemPCPinPad 11 | #DEVICENAME /dev/ttySn[:reader] 12 | #FRIENDLYNAME "GemPCTwin serial" 13 | #LIBPATH TARGET 14 | -------------------------------------------------------------------------------- /src/towitoko/README: -------------------------------------------------------------------------------- 1 | All the files in the src/protocol_t1/ directory comes from Carlos 2 | Prados Towitoko smartcard readers driver. 3 | 4 | I (Ludovic Rousseau) hacked the source files a bit to include them in my 5 | CCID driver. So bugs are mine and not Carlos' fault. As indicated in 6 | the source files headers this code is protected by the GNU Lesser 7 | General Public License. 8 | 9 | I used version 2.0.7 of Carlos driver available at 10 | http://www.geocities.com/cprados/ 11 | 12 | I added the function ATR_GetDefaultProtocol() in towitoko/atr.c 13 | 14 | $Id: README 1001 2004-06-30 13:49:38Z rousseau $ 15 | -------------------------------------------------------------------------------- /contrib/Kobil_mIDentity_switch/Kobil_mIDentity_switch.8: -------------------------------------------------------------------------------- 1 | .TH Kobil_mIDentity_switch 8 "February 2008" 2 | .SH NAME 3 | Kobil_mIDentity_switch \- activate mIDentity CCID reader 4 | . 5 | .SH SYNOPSIS 6 | .B Kobil_mIDentity_switch 7 | . 8 | .SH DESCRIPTION 9 | Kobil_mIDentity_switch is used to activate the CCID reader of the Kobil 10 | mIDentity device. 11 | .PP 12 | The USB device is by default: 13 | ID 0d46:4081 Kobil Systems GmbH mIDentity Basic/Classic (installationless) 14 | and will be switched to: 15 | ID 0d46:4001 Kobil Systems GmbH mIDentity Basic/Classic (composite device) 16 | . 17 | .SH AUTHORS 18 | Norbert Federa wrote the tool. 19 | Ludovic Rousseau wrote this manpage. 20 | -------------------------------------------------------------------------------- /m4/ltversion.m4: -------------------------------------------------------------------------------- 1 | # ltversion.m4 -- version numbers -*- Autoconf -*- 2 | # 3 | # Copyright (C) 2004 Free Software Foundation, Inc. 4 | # Written by Scott James Remnant, 2004 5 | # 6 | # This file is free software; the Free Software Foundation gives 7 | # unlimited permission to copy and/or distribute it, with or without 8 | # modifications, as long as this notice is preserved. 9 | 10 | # @configure_input@ 11 | 12 | # serial 3337 ltversion.m4 13 | # This file is part of GNU Libtool 14 | 15 | m4_define([LT_PACKAGE_VERSION], [2.4.2]) 16 | m4_define([LT_PACKAGE_REVISION], [1.3337]) 17 | 18 | AC_DEFUN([LTVERSION_VERSION], 19 | [macro_version='2.4.2' 20 | macro_revision='1.3337' 21 | _LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?]) 22 | _LT_DECL(, macro_revision, 0) 23 | ]) 24 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | ACLOCAL_AMFLAGS = -I m4 2 | 3 | SUBDIRS = readers examples contrib src 4 | 5 | EXTRA_DIST = bootstrap ChangeLog SCARDGETATTRIB.txt \ 6 | $(AUX_DIST) \ 7 | m4/ax_pthread.m4 \ 8 | MacOSX/configure \ 9 | MacOSX/convert_reader_h.pl \ 10 | MacOSX/debuglog.h \ 11 | MacOSX/ifdhandler.h \ 12 | MacOSX/pcsclite.h \ 13 | MacOSX/reader.h \ 14 | MacOSX/winscard.h \ 15 | MacOSX/wintypes.h 16 | 17 | MAINTAINERCLEANFILES = $(AUX_DIST) 18 | DISTCLEANFILES = ChangeLog 19 | 20 | # Automatically update the libtool script if it becomes out-of-date. 21 | LIBTOOL_DEPS = @LIBTOOL_DEPS@ 22 | libtool: $(LIBTOOL_DEPS) 23 | $(SHELL) ./config.status --recheck 24 | 25 | ChangeLog: 26 | svn2cl --group-by-day --stdout --include-rev --reparagraph \ 27 | | perl -pe 's/ rousseau/ Ludovic Rousseau/; \ 28 | s+trunk/Drivers/ccid/++g;' > $@ 29 | 30 | -------------------------------------------------------------------------------- /src/92_pcscd_ccid.rules: -------------------------------------------------------------------------------- 1 | # udev rules for CCID devices 2 | 3 | # $Id: 92_pcscd_ccid.rules 6623 2013-05-07 09:11:26Z rousseau $ 4 | 5 | # Gemplus PCMCIA Card 6 | #SUBSYSTEMS=="pcmcia", DRIVERS=="serial_cs", ACTION=="add", ATTRS{prod_id1}=="Gemplus", ATTRS{prod_id2}=="SerialPort", ATTRS{prod_id3}=="GemPC Card", RUN+="/usr/sbin/pcscd --hotplug" 7 | 8 | # If not adding the device, go away 9 | ACTION!="add", GOTO="pcscd_ccid_rules_end" 10 | SUBSYSTEM!="usb", GOTO="pcscd_ccid_rules_end" 11 | ENV{DEVTYPE}!="usb_device", GOTO="pcscd_ccid_rules_end" 12 | 13 | # Kobil mIDentity 14 | ATTRS{idVendor}=="0d46", ATTRS{idProduct}=="4081", RUN+="/usr/sbin/Kobil_mIDentity_switch" 15 | 16 | # set USB power management to auto. 17 | ENV{ID_USB_INTERFACES}==":0b0000:", RUN+="/bin/sh -c 'echo auto > /sys/$devpath/power/control'" 18 | 19 | # All done 20 | LABEL="pcscd_ccid_rules_end" 21 | -------------------------------------------------------------------------------- /src/openct/buffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Buffer handling functions of the IFD handler library 3 | * 4 | * Copyright (C) 2003, Olaf Kirch 5 | */ 6 | 7 | #ifndef OPENCT_BUFFER_H 8 | #define OPENCT_BUFFER_H 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif 13 | 14 | #include 15 | 16 | typedef struct ct_buf { 17 | unsigned char * base; 18 | unsigned int head, tail, size; 19 | unsigned int overrun; 20 | } ct_buf_t; 21 | 22 | extern void ct_buf_init(ct_buf_t *, void *, size_t); 23 | extern void ct_buf_set(ct_buf_t *, void *, size_t); 24 | extern int ct_buf_get(ct_buf_t *, void *, size_t); 25 | extern int ct_buf_put(ct_buf_t *, const void *, size_t); 26 | extern int ct_buf_putc(ct_buf_t *, int); 27 | extern unsigned int ct_buf_avail(ct_buf_t *); 28 | extern void * ct_buf_head(ct_buf_t *); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #endif /* OPENCT_BUFFER_H */ 35 | -------------------------------------------------------------------------------- /src/utils.h: -------------------------------------------------------------------------------- 1 | /* 2 | utils.c: 3 | Copyright (C) 2003-2009 Ludovic Rousseau 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | 20 | /* 21 | * $Id: utils.h 4973 2010-06-01 09:43:29Z rousseau $ 22 | */ 23 | 24 | #ifndef TRUE 25 | #define FALSE 0 26 | #define TRUE 1 27 | #endif 28 | 29 | void InitReaderIndex(void); 30 | int GetNewReaderIndex(const int Lun); 31 | int LunToReaderIndex(int Lun); 32 | void ReleaseReaderIndex(const int idx); 33 | 34 | -------------------------------------------------------------------------------- /m4/as-ac-expand.m4: -------------------------------------------------------------------------------- 1 | dnl as-ac-expand.m4 0.2.0 2 | dnl autostars m4 macro for expanding directories using configure's prefix 3 | dnl thomas@apestaart.org 4 | 5 | dnl AS_AC_EXPAND(VAR, CONFIGURE_VAR) 6 | dnl example 7 | dnl AS_AC_EXPAND(SYSCONFDIR, $sysconfdir) 8 | dnl will set SYSCONFDIR to /usr/local/etc if prefix=/usr/local 9 | 10 | AC_DEFUN([AS_AC_EXPAND], 11 | [ 12 | EXP_VAR=[$1] 13 | FROM_VAR=[$2] 14 | 15 | dnl first expand prefix and exec_prefix if necessary 16 | prefix_save=$prefix 17 | exec_prefix_save=$exec_prefix 18 | 19 | dnl if no prefix given, then use /usr/local, the default prefix 20 | if test "x$prefix" = "xNONE"; then 21 | prefix="$ac_default_prefix" 22 | fi 23 | dnl if no exec_prefix given, then use prefix 24 | if test "x$exec_prefix" = "xNONE"; then 25 | exec_prefix=$prefix 26 | fi 27 | 28 | full_var="$FROM_VAR" 29 | dnl loop until it doesn't change anymore 30 | while true; do 31 | new_full_var="`eval echo $full_var`" 32 | if test "x$new_full_var" = "x$full_var"; then break; fi 33 | full_var=$new_full_var 34 | done 35 | 36 | dnl clean up 37 | full_var=$new_full_var 38 | AC_SUBST([$1], "$full_var") 39 | 40 | dnl restore prefix and exec_prefix 41 | prefix=$prefix_save 42 | exec_prefix=$exec_prefix_save 43 | ]) 44 | -------------------------------------------------------------------------------- /src/convert_version.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | # convert_version.pl: generate a version integer from a version text 4 | # 5 | # Copyright (C) 2006-2008 Ludovic Rousseau 6 | # 7 | # This program is free software; you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation; either version 2 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program; if not, write to the Free Software 19 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 20 | # 02110-1301 USA. 21 | 22 | use warnings; 23 | use strict; 24 | 25 | # convert "1.2.3-svn-xyz" in "0x01020003" 26 | my ($major, $minor, $patch) = split /\./, $ARGV[0]; 27 | 28 | # remove the -svn-xyz part if any 29 | $patch =~ s/-.*//; 30 | 31 | printf "0x%02X%02X%04X\n", $major, $minor, $patch; 32 | 33 | -------------------------------------------------------------------------------- /src/openct/checksum.h: -------------------------------------------------------------------------------- 1 | /* 2 | proto-t1.h: header file for proto-t1.c 3 | Copyright (C) 2004 Ludovic Rousseau 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | 20 | /* $Id: checksum.h 2974 2008-05-28 18:32:52Z rousseau $ */ 21 | 22 | #ifndef __CHECKSUM_H__ 23 | #define __CHECKSUM_H__ 24 | 25 | #include "config.h" 26 | #ifdef HAVE_STDINT_H 27 | #include 28 | #endif 29 | #include 30 | 31 | extern unsigned int csum_lrc_compute(const uint8_t *, size_t, unsigned char *); 32 | extern unsigned int csum_crc_compute(const uint8_t *, size_t, unsigned char *); 33 | 34 | #endif 35 | 36 | -------------------------------------------------------------------------------- /src/openct/buffer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Buffer handling functions 3 | * 4 | * Copyright (C) 2003, Olaf Kirch 5 | */ 6 | 7 | #ifdef HAVE_CONFIG_H 8 | #include 9 | #endif 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | void 16 | ct_buf_init(ct_buf_t *bp, void *mem, size_t len) 17 | { 18 | memset(bp, 0, sizeof(*bp)); 19 | bp->base = (unsigned char *) mem; 20 | bp->size = len; 21 | } 22 | 23 | void 24 | ct_buf_set(ct_buf_t *bp, void *mem, size_t len) 25 | { 26 | ct_buf_init(bp, mem, len); 27 | bp->tail = len; 28 | } 29 | 30 | int 31 | ct_buf_get(ct_buf_t *bp, void *mem, size_t len) 32 | { 33 | if (len > bp->tail - bp->head) 34 | return -1; 35 | if (mem) 36 | memcpy(mem, bp->base + bp->head, len); 37 | bp->head += len; 38 | return len; 39 | } 40 | 41 | int 42 | ct_buf_put(ct_buf_t *bp, const void *mem, size_t len) 43 | { 44 | if (len > bp->size - bp->tail) { 45 | bp->overrun = 1; 46 | return -1; 47 | } 48 | if (mem) 49 | memcpy(bp->base + bp->tail, mem, len); 50 | bp->tail += len; 51 | return len; 52 | } 53 | 54 | int 55 | ct_buf_putc(ct_buf_t *bp, int byte) 56 | { 57 | unsigned char c = byte; 58 | 59 | return ct_buf_put(bp, &c, 1); 60 | } 61 | 62 | unsigned int 63 | ct_buf_avail(ct_buf_t *bp) 64 | { 65 | return bp->tail - bp->head; 66 | } 67 | 68 | void * 69 | ct_buf_head(ct_buf_t *bp) 70 | { 71 | return bp->base + bp->head; 72 | } 73 | 74 | -------------------------------------------------------------------------------- /src/ccid_serial.h: -------------------------------------------------------------------------------- 1 | /* 2 | ccid_serial.h: Serial access routines 3 | Copyright (C) 2003-2008 Ludovic Rousseau 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | 20 | /* 21 | * $Id: ccid_serial.h 4973 2010-06-01 09:43:29Z rousseau $ 22 | */ 23 | 24 | #ifndef __CCID_SERAL_H__ 25 | #define __CCID_SERAL_H__ 26 | 27 | status_t OpenSerial(unsigned int reader_index, int channel); 28 | 29 | status_t OpenSerialByName(unsigned int reader_index, char *dev_name); 30 | 31 | status_t WriteSerial(unsigned int reader_index, unsigned int length, 32 | unsigned char *Buffer); 33 | 34 | status_t ReadSerial(unsigned int reader_index, unsigned int *length, 35 | unsigned char *Buffer); 36 | 37 | status_t CloseSerial(unsigned int reader_index); 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /MacOSX/convert_reader_h.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | # convert_reader_h.pl: convert reader.h.in in reader.h with 4 | # 5 | # Copyright (C) 2008 Ludovic Rousseau 6 | # 7 | # This program is free software; you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation; either version 2 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License along 18 | # with this program; if not, write to the Free Software Foundation, Inc., 19 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | 21 | use warnings; 22 | use strict; 23 | 24 | my $text = 25 | "#ifdef __BIG_ENDIAN__ 26 | #define HOST_TO_CCID_16(x) ((((x) >> 8) & 0xFF) + ((x & 0xFF) << 8)) 27 | #define HOST_TO_CCID_32(x) ((((x) >> 24) & 0xFF) + (((x) >> 8) & 0xFF00) + ((x & 0xFF00) << 8) + (((x) & 0xFF) << 24)) 28 | #else 29 | #define HOST_TO_CCID_16(x) (x) 30 | #define HOST_TO_CCID_32(x) (x) 31 | #endif 32 | "; 33 | 34 | while (<>) 35 | { 36 | if (m/host_to_ccid_16/) 37 | { 38 | print $text; 39 | <>; 40 | next; 41 | } 42 | print; 43 | } 44 | -------------------------------------------------------------------------------- /src/towitoko/defines.h: -------------------------------------------------------------------------------- 1 | /* 2 | defines.h 3 | 4 | This file is part of the Unix driver for Towitoko smartcard readers 5 | Copyright (C) 2000 Carlos Prados 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General Public License 18 | along with this library; if not, write to the Free Software Foundation, 19 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20 | */ 21 | 22 | #ifndef DEFINES_H 23 | #define DEFINES_H 24 | 25 | /* 26 | * Get configuration information 27 | */ 28 | 29 | #ifdef HAVE_CONFIG_H 30 | #include "config.h" 31 | #endif 32 | 33 | /* 34 | * Boolean constants 35 | */ 36 | 37 | #ifndef TRUE 38 | #define TRUE 1 39 | #endif 40 | 41 | #ifndef FALSE 42 | #define FALSE 0 43 | #endif 44 | 45 | /* 46 | * Type definitions 47 | */ 48 | 49 | #include 50 | 51 | #ifndef __cplusplus 52 | typedef int bool; 53 | #endif 54 | 55 | #endif /* DEFINES_H */ 56 | 57 | -------------------------------------------------------------------------------- /Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | common_cflags := \ 4 | -DANDROID \ 5 | -DPCSCD_PATH='"$(PCSCD_PATH)"' \ 6 | -DHAVE_CONFIG_H 7 | 8 | LIBUSB_PATH := $(LOCAL_PATH)/../libusb 9 | 10 | include $(CLEAR_VARS) 11 | LOCAL_C_INCLUDES := \ 12 | $(LOCAL_PATH) \ 13 | $(LOCAL_PATH)/src \ 14 | $(PCSC_PATH)/src/PCSC \ 15 | $(LIBUSB_PATH) \ 16 | 17 | LOCAL_SRC_FILES:= \ 18 | src/ccid.c \ 19 | src/commands.c \ 20 | src/ifdhandler.c \ 21 | src/utils.c \ 22 | src/ccid_usb.c \ 23 | src/towitoko/atr.c \ 24 | src/towitoko/pps.c \ 25 | src/openct/buffer.c \ 26 | src/openct/checksum.c \ 27 | src/openct/proto-t1.c \ 28 | src/tokenparser.c \ 29 | src/strlcpy.c \ 30 | src/simclist.c \ 31 | src/debug.c 32 | 33 | LOCAL_CFLAGS := $(common_cflags) 34 | 35 | LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/ 36 | 37 | LOCAL_MODULE_TAGS = eng 38 | LOCAL_MODULE:= libccid 39 | LOCAL_LDLIBS := -llog -ldl -lc 40 | LOCAL_SHARED_LIBRARIES := libusb 41 | LOCAL_PRELINK_MODULE := false 42 | include $(BUILD_SHARED_LIBRARY) 43 | 44 | 45 | include $(CLEAR_VARS) 46 | 47 | LOCAL_C_INCLUDES := \ 48 | 49 | LOCAL_SRC_FILES:= \ 50 | examples/PCSCv2part10.c \ 51 | examples/scardcontrol.c \ 52 | 53 | LOCAL_CFLAGS := \ 54 | $(common_cflags) \ 55 | -Dmain=scardcontrol_main 56 | 57 | LOCAL_MODULE_TAGS = eng 58 | LOCAL_MODULE:= libscardcontrol 59 | LOCAL_LDLIBS := -llog 60 | LOCAL_SHARED_LIBRARIES := libpcsclite 61 | LOCAL_PRELINK_MODULE := false 62 | include $(BUILD_SHARED_LIBRARY) 63 | 64 | $(call import-module,libusb) 65 | -------------------------------------------------------------------------------- /src/openct/LICENSE: -------------------------------------------------------------------------------- 1 | OpenCT, a middleware framework for smart card terminals. 2 | 3 | Copyright (c) 2003, Olaf Kirch 4 | Copyright (c) 2003, Andreas Jellinghaus 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | * Redistributions of source code must retain the above copyright notice, 11 | this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | * Neither the name of the authors nor the names of its contributors 16 | may be used to endorse or promote products derived from this software 17 | without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 23 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 26 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /src/strlcpy.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: strlcpy.c,v 1.10 2005/08/08 08:05:37 espie Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 1998 Todd C. Miller 5 | * 6 | * Permission to use, copy, modify, and distribute this software for any 7 | * purpose with or without fee is hereby granted, provided that the above 8 | * copyright notice and this permission notice appear in all copies. 9 | * 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 | */ 18 | 19 | #ifdef HAVE_CONFIG_H 20 | #include "config.h" 21 | #endif 22 | 23 | #ifndef HAVE_STRLCPY 24 | 25 | #include 26 | #include 27 | #include "strlcpycat.h" 28 | 29 | /* 30 | * Copy src to string dst of size siz. At most siz-1 characters 31 | * will be copied. Always NUL terminates (unless siz == 0). 32 | * Returns strlen(src); if retval >= siz, truncation occurred. 33 | */ 34 | size_t 35 | strlcpy(char *dst, const char *src, size_t siz) 36 | { 37 | char *d = dst; 38 | const char *s = src; 39 | size_t n = siz; 40 | 41 | /* Copy as many bytes as will fit */ 42 | if (n != 0 && --n != 0) { 43 | do { 44 | if ((*d++ = *s++) == 0) 45 | break; 46 | } while (--n != 0); 47 | } 48 | 49 | /* Not enough room in dst, add NUL and traverse rest of src */ 50 | if (n == 0) { 51 | if (siz != 0) 52 | *d = '\0'; /* NUL-terminate dst */ 53 | while (*s++) 54 | ; 55 | } 56 | 57 | return(s - src - 1); /* count does not include NUL */ 58 | } 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /src/ccid_usb.h: -------------------------------------------------------------------------------- 1 | /* 2 | ccid_usb.h: USB access routines using the libusb library 3 | Copyright (C) 2003-2010 Ludovic Rousseau 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | 20 | /* 21 | * $Id: ccid_usb.h 5473 2011-01-04 09:52:26Z rousseau $ 22 | */ 23 | 24 | #ifndef __CCID_USB_H__ 25 | #define __CCID_USB_H__ 26 | status_t OpenUSB(unsigned int reader_index, int channel); 27 | 28 | status_t OpenUSBByName(unsigned int reader_index, /*@null@*/ char *device); 29 | 30 | status_t WriteUSB(unsigned int reader_index, unsigned int length, 31 | unsigned char *Buffer); 32 | 33 | status_t ReadUSB(unsigned int reader_index, unsigned int *length, 34 | /*@out@*/ unsigned char *Buffer); 35 | 36 | status_t CloseUSB(unsigned int reader_index); 37 | 38 | #include 39 | /*@null@*/ const struct libusb_interface *get_ccid_usb_interface( 40 | struct libusb_config_descriptor *desc, int *num); 41 | 42 | const unsigned char *get_ccid_device_descriptor(const struct libusb_interface *usb_interface); 43 | 44 | int ControlUSB(int reader_index, int requesttype, int request, int value, 45 | unsigned char *bytes, unsigned int size); 46 | 47 | int InterruptRead(int reader_index, int timeout); 48 | void InterruptStop(int reader_index); 49 | #endif 50 | -------------------------------------------------------------------------------- /src/towitoko/pps.h: -------------------------------------------------------------------------------- 1 | /* 2 | pps.h 3 | Protocol Parameters Selection 4 | 5 | This file is part of the Unix driver for Towitoko smartcard readers 6 | Copyright (C) 2000 2001 Carlos Prados 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 2 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public License 19 | along with this library; if not, write to the Free Software Foundation, 20 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 21 | */ 22 | 23 | #ifndef _PPS_ 24 | #define _PPS_ 25 | 26 | #include "defines.h" 27 | 28 | /* 29 | * Exported constants definition 30 | */ 31 | 32 | #define PPS_OK 0 /* Negotiation OK */ 33 | #define PPS_ICC_ERROR 1 /* Comunication error */ 34 | #define PPS_HANDSAKE_ERROR 2 /* Agreement not reached */ 35 | #define PPS_PROTOCOL_ERROR 3 /* Error starting protocol */ 36 | #define PPS_MAX_LENGTH 6 37 | 38 | #define PPS_HAS_PPS1(block) ((block[1] & 0x10) == 0x10) 39 | #define PPS_HAS_PPS2(block) ((block[1] & 0x20) == 0x20) 40 | #define PPS_HAS_PPS3(block) ((block[1] & 0x40) == 0x40) 41 | 42 | /* 43 | * Exported data types definition 44 | */ 45 | 46 | typedef struct 47 | { 48 | double f; 49 | double d; 50 | double n; 51 | BYTE t; 52 | } 53 | PPS_ProtocolParameters; 54 | 55 | typedef struct 56 | { 57 | int icc; 58 | void *protocol; 59 | PPS_ProtocolParameters parameters; 60 | } 61 | PPS; 62 | 63 | /* 64 | * Exported functions declaration 65 | */ 66 | 67 | int PPS_Exchange (int lun, BYTE * params, /*@out@*/ unsigned *length, 68 | unsigned char *pps1); 69 | 70 | #endif /* _PPS_ */ 71 | 72 | -------------------------------------------------------------------------------- /src/strlcpycat.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MUSCLE SmartCard Development ( http://pcsclite.alioth.debian.org/pcsclite.html ) 3 | * 4 | * Copyright (C) 2004-2010 5 | * Ludovic Rousseau 6 | * 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions 9 | are met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 2. Redistributions in binary form must reproduce the above copyright 14 | notice, this list of conditions and the following disclaimer in the 15 | documentation and/or other materials provided with the distribution. 16 | 3. The name of the author may not be used to endorse or promote products 17 | derived from this software without specific prior written permission. 18 | 19 | Changes to this license can be made only by the copyright author with 20 | explicit written consent. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 26 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 | * 33 | * $Id: strlcpycat.h 6851 2014-02-14 15:43:32Z rousseau $ 34 | */ 35 | 36 | /** 37 | * @file 38 | * @brief prototypes of strlcpy()/strlcat() imported from OpenBSD 39 | */ 40 | 41 | #ifdef HAVE_STRLCPY 42 | #include 43 | #else 44 | size_t strlcpy(char *dst, const char *src, size_t siz); 45 | #endif 46 | 47 | #ifndef HAVE_STRLCAT 48 | size_t strlcat(char *dst, const char *src, size_t siz); 49 | #endif 50 | 51 | -------------------------------------------------------------------------------- /src/parser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MUSCLE SmartCard Development ( http://pcsclite.alioth.debian.org/pcsclite.html ) 3 | * 4 | * Copyright (C) 2003 5 | * Toni Andjelkovic 6 | * Copyright (C) 2003-2009 7 | * Ludovic Rousseau 8 | * 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are permitted provided that the following conditions 11 | are met: 12 | 13 | 1. Redistributions of source code must retain the above copyright 14 | notice, this list of conditions and the following disclaimer. 15 | 2. Redistributions in binary form must reproduce the above copyright 16 | notice, this list of conditions and the following disclaimer in the 17 | documentation and/or other materials provided with the distribution. 18 | 3. The name of the author may not be used to endorse or promote products 19 | derived from this software without specific prior written permission. 20 | 21 | Changes to this license can be made only by the copyright author with 22 | explicit written consent. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 25 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 26 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 27 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 28 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 29 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 33 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | * $Id: parser.h 6851 2014-02-14 15:43:32Z rousseau $ 36 | */ 37 | 38 | /** 39 | * @file 40 | * @brief Reads lexical config files and updates database. 41 | */ 42 | 43 | #ifndef __parser_h__ 44 | #define __parser_h__ 45 | 46 | #include "simclist.h" 47 | 48 | struct bundleElt 49 | { 50 | char *key; 51 | list_t values; 52 | }; 53 | 54 | int LTPBundleFindValueWithKey(list_t *l, const char *key, list_t **values); 55 | int bundleParse(const char *fileName, list_t *l); 56 | void bundleRelease(list_t *l); 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /src/utils.c: -------------------------------------------------------------------------------- 1 | /* 2 | utils.c: 3 | Copyright (C) 2003-2008 Ludovic Rousseau 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | 20 | /* 21 | * $Id: utils.c 5185 2010-08-26 08:58:06Z rousseau $ 22 | */ 23 | 24 | #include 25 | 26 | #include "config.h" 27 | #include "ccid.h" 28 | #include "defs.h" 29 | #include "ccid_ifdhandler.h" 30 | #include "utils.h" 31 | #include "debug.h" 32 | 33 | int ReaderIndex[CCID_DRIVER_MAX_READERS]; 34 | 35 | void InitReaderIndex(void) 36 | { 37 | int i; 38 | 39 | for (i=0; i 28 | #endif 29 | #include 30 | 31 | #include "buffer.h" 32 | 33 | /* T=1 protocol constants */ 34 | #define T1_I_BLOCK 0x00 35 | #define T1_R_BLOCK 0x80 36 | #define T1_S_BLOCK 0xC0 37 | #define T1_MORE_BLOCKS 0x20 38 | 39 | enum { 40 | IFD_PROTOCOL_RECV_TIMEOUT = 0x0000, 41 | IFD_PROTOCOL_T1_BLOCKSIZE, 42 | IFD_PROTOCOL_T1_CHECKSUM_CRC, 43 | IFD_PROTOCOL_T1_CHECKSUM_LRC, 44 | IFD_PROTOCOL_T1_IFSC, 45 | IFD_PROTOCOL_T1_IFSD, 46 | IFD_PROTOCOL_T1_STATE, 47 | IFD_PROTOCOL_T1_MORE 48 | }; 49 | 50 | #define T1_BUFFER_SIZE (3 + 254 + 2) 51 | 52 | /* see /usr/include/PCSC/ifdhandler.h for other values 53 | * this one is for internal use only */ 54 | #define IFD_PARITY_ERROR 699 55 | 56 | typedef struct { 57 | int lun; 58 | int state; 59 | 60 | unsigned char ns; /* reader side */ 61 | unsigned char nr; /* card side */ 62 | unsigned int ifsc; 63 | unsigned int ifsd; 64 | 65 | unsigned char wtx; 66 | unsigned int retries; 67 | unsigned int rc_bytes; 68 | 69 | unsigned int (*checksum)(const uint8_t *, size_t, unsigned char *); 70 | 71 | char more; /* more data bit */ 72 | unsigned char previous_block[4]; /* to store the last R-block */ 73 | } t1_state_t; 74 | 75 | int t1_transceive(t1_state_t *t1, unsigned int dad, 76 | const void *snd_buf, size_t snd_len, 77 | void *rcv_buf, size_t rcv_len); 78 | int t1_init(t1_state_t *t1, int lun); 79 | void t1_release(t1_state_t *t1); 80 | int t1_set_param(t1_state_t *t1, int type, long value); 81 | int t1_negotiate_ifsd(t1_state_t *t1, unsigned int dad, int ifsd); 82 | unsigned int t1_build(t1_state_t *, unsigned char *, 83 | unsigned char, unsigned char, ct_buf_t *, size_t *); 84 | 85 | #endif 86 | 87 | -------------------------------------------------------------------------------- /src/create_Info_plist.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | 3 | # create_Info_plist.pl: generate Infor.plist from a template and a 4 | # list of suported readers 5 | # 6 | # Copyright (C) 2004-2009 Ludovic Rousseau 7 | # 8 | # This program is free software; you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation; either version 2 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # This program is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with this program; if not, write to the Free Software 20 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 21 | # 02110-1301 USA. 22 | 23 | use warnings; 24 | use strict; 25 | use Getopt::Long; 26 | 27 | my (@manuf, @product, @name); 28 | my ($manuf, $product, $name); 29 | my $target = "libccid.so"; 30 | my $version = "1.0.0"; 31 | my $class = "CFBundleName 32 | CCIDCLASSDRIVER"; 33 | my $noclass = 0; 34 | 35 | GetOptions( 36 | "target=s" => \$target, 37 | "version=s" => \$version, 38 | "no-class" => \$noclass); 39 | 40 | if ($#ARGV < 1) 41 | { 42 | print "usage: $0 supported_readers.txt Info.plist 43 | --target=$target 44 | --version=$version\n"; 45 | exit; 46 | } 47 | 48 | open IN, "< $ARGV[0]" or die "Can't open $ARGV[0]: $!"; 49 | while () 50 | { 51 | next if (m/^#/); 52 | next if (m/^$/); 53 | 54 | chomp; 55 | ($manuf, $product, $name) = split /:/; 56 | # print "m: $manuf, p: $product, n: $name\n"; 57 | push @manuf, $manuf; 58 | push @product, $product; 59 | $name =~ s/&/&/g; 60 | push @name, $name 61 | } 62 | close IN; 63 | 64 | map { $_ = "\t\t$_\n" } @manuf; 65 | map { $_ = "\t\t$_\n" } @product; 66 | map { $_ = "\t\t$_\n" } @name; 67 | 68 | open IN, "< $ARGV[1]" or die "Can't open $ARGV[1]: $!"; 69 | 70 | while () 71 | { 72 | if (m/MAGIC_VENDOR/) 73 | { 74 | print @manuf; 75 | next; 76 | } 77 | if (m/MAGIC_PRODUCT/) 78 | { 79 | print @product; 80 | next; 81 | } 82 | if (m/MAGIC_FRIENDLYNAME/) 83 | { 84 | print @name; 85 | next; 86 | } 87 | if (m/MAGIC_TARGET/) 88 | { 89 | s/MAGIC_TARGET/$target/; 90 | print; 91 | next; 92 | } 93 | if (m/MAGIC_VERSION/) 94 | { 95 | s/MAGIC_VERSION/$version/; 96 | print; 97 | next; 98 | } 99 | if (m/MAGIC_CLASS/) 100 | { 101 | next if ($noclass); 102 | 103 | s/MAGIC_CLASS/$class/; 104 | print; 105 | next; 106 | } 107 | print; 108 | } 109 | 110 | close IN; 111 | 112 | -------------------------------------------------------------------------------- /SCARDGETATTRIB.txt: -------------------------------------------------------------------------------- 1 | List of SCardGetAttrib() commands supported by the CCID driver 2 | ============================================================== 3 | 4 | PC/SC provides the SCardGetAttrib() function to request some attributes from 5 | the driver. 6 | 7 | 8 | PC/SC function prototype 9 | """"""""""""""""""""""""" 10 | 11 | LONG SCardGetAttrib(SCARDHANDLE hCard, 12 | DWORD dwAttrId, 13 | LPBYTE pbAttr, 14 | LPDWORD pcbAttrLen); 15 | 16 | Parameters: 17 | 18 | hCard IN Connection made from SCardConnect 19 | dwAttrId IN Identifier for the attribute to get 20 | pbAttr OUT Pointer to a buffer that receives the attribute 21 | pcbAttrLen IN/OUT Length of the pbAttr buffer in bytes 22 | 23 | If the attribute is not supported the applications receive the error 24 | SCARD_E_UNSUPPORTED_FEATURE (or SCARD_E_NOT_TRANSACTED for pcsc-lite 25 | version < 1.3.3) 26 | 27 | 28 | supported attributes 29 | """""""""""""""""""" 30 | 31 | SCARD_ATTR_ATR_STRING 32 | ATR of the card 33 | 34 | SCARD_ATTR_ICC_INTERFACE_STATUS 35 | Single byte. Zero if smart card electrical contact is not active; 36 | nonzero if contact is active. 37 | 38 | SCARD_ATTR_ICC_PRESENCE 39 | Single byte indicating smart card presence: 40 | 0 = not present 41 | 1 = card present but not swallowed (applies only if reader supports 42 | smart card swallowing) 43 | 2 = card present (and swallowed if reader supports smart card swallowing) 44 | 4 = card confiscated. 45 | 46 | SCARD_ATTR_VENDOR_IFD_VERSION 47 | Vendor-supplied interface device version 48 | DWORD in the form 0xMMmmbbbb where 49 | MM = major version, 50 | mm = minor version, 51 | and bbbb = build number 52 | It is the bcdDevice USB field. 53 | 54 | SCARD_ATTR_VENDOR_NAME 55 | name of the IFD (reader) vendor. It is the iManufacturer USB field 56 | (if any). 57 | 58 | SCARD_ATTR_MAXINPUT 59 | maximum size of an APDU supported by the reader. 60 | format is unsigned 32-bit unsing the byte order of the platform. 61 | Correct readers should support up to 261 bytes (CLA + INS + P1 + P2 + 62 | Lc + 255 bytes of data) but some readers support less (253 bytes only 63 | for example). It is a problem for T=1 cards when the reader works in 64 | APDU mode instead of TPDU and for T=0 cards. 65 | 66 | SCARD_ATTR_VENDOR_IFD_SERIAL_NO 67 | reader serial number (if available). 68 | 69 | 70 | Sample code 71 | =========== 72 | 73 | #include 74 | 75 | { 76 | [...] 77 | 78 | unsigned char pbAtr[MAX_ATR_SIZE]; 79 | DWORD dwAtrLen; 80 | 81 | /* use a NULL buffer to just get the needed length */ 82 | rv = SCardGetAttrib(hCard, SCARD_ATTR_ATR_STRING, NULL, &dwAtrLen); 83 | if (rv == SCARD_S_SUCCESS) 84 | printf("ATR length: %ld\n", dwAtrLen); 85 | 86 | dwAtrLen = sizeof(pbAtr); 87 | rv = SCardGetAttrib(hCard, SCARD_ATTR_ATR_STRING, pbAtr, &dwAtrLen); 88 | if (rv == SCARD_S_SUCCESS) 89 | { 90 | for (i = 0; i < dwAtrLen; i++) 91 | printf("%02X ", pbAtr[i]); 92 | printf("\n"); 93 | } 94 | } 95 | 96 | -------------------------------------------------------------------------------- /src/defs.h: -------------------------------------------------------------------------------- 1 | /* 2 | defs.h: 3 | Copyright (C) 2003-2010 Ludovic Rousseau 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | 20 | /* 21 | * $Id: defs.h 6305 2012-05-19 08:10:08Z rousseau $ 22 | */ 23 | 24 | #include 25 | 26 | #include "openct/proto-t1.h" 27 | 28 | typedef struct CCID_DESC 29 | { 30 | /* 31 | * ATR 32 | */ 33 | int nATRLength; 34 | UCHAR pcATRBuffer[MAX_ATR_SIZE]; 35 | 36 | /* 37 | * Card state 38 | */ 39 | UCHAR bPowerFlags; 40 | 41 | /* 42 | * T=1 Protocol context 43 | */ 44 | t1_state_t t1; 45 | 46 | /* reader name passed to IFDHCreateChannelByName() */ 47 | char *readerName; 48 | } CcidDesc; 49 | 50 | typedef enum { 51 | STATUS_NO_SUCH_DEVICE = 0xF9, 52 | STATUS_SUCCESS = 0xFA, 53 | STATUS_UNSUCCESSFUL = 0xFB, 54 | STATUS_COMM_ERROR = 0xFC, 55 | STATUS_DEVICE_PROTOCOL_ERROR = 0xFD, 56 | STATUS_COMM_NAK = 0xFE, 57 | STATUS_SECONDARY_SLOT = 0xFF 58 | } status_t; 59 | 60 | /* Powerflag (used to detect quick insertion removals unnoticed by the 61 | * resource manager) */ 62 | /* Initial value */ 63 | #define POWERFLAGS_RAZ 0x00 64 | /* Flag set when a power up has been requested */ 65 | #define MASK_POWERFLAGS_PUP 0x01 66 | /* Flag set when a power down is requested */ 67 | #define MASK_POWERFLAGS_PDWN 0x02 68 | 69 | /* Communication buffer size (max=adpu+Lc+data+Le) 70 | * we use a 64kB for extended APDU on APDU mode readers */ 71 | #define CMD_BUF_SIZE (4 +3 +64*1024 +3) 72 | 73 | /* Protocols */ 74 | #define T_0 0 75 | #define T_1 1 76 | 77 | /* Default communication read timeout in milliseconds */ 78 | #define DEFAULT_COM_READ_TIMEOUT (3*1000) 79 | 80 | /* DWORD type formating */ 81 | #ifdef __APPLE__ 82 | /* Apple defines DWORD as uint32_t */ 83 | #define DWORD_X "%X" 84 | #define DWORD_D "%d" 85 | #else 86 | /* pcsc-lite defines DWORD as unsigned long */ 87 | #define DWORD_X "%lX" 88 | #define DWORD_D "%ld" 89 | #endif 90 | 91 | /* 92 | * communication ports abstraction 93 | */ 94 | #ifdef TWIN_SERIAL 95 | 96 | #define OpenPortByName OpenSerialByName 97 | #define OpenPort OpenSerial 98 | #define ClosePort CloseSerial 99 | #define ReadPort ReadSerial 100 | #define WritePort WriteSerial 101 | #include "ccid_serial.h" 102 | 103 | #else 104 | 105 | #define OpenPortByName OpenUSBByName 106 | #define OpenPort OpenUSB 107 | #define ClosePort CloseUSB 108 | #define ReadPort ReadUSB 109 | #define WritePort WriteUSB 110 | #include "ccid_usb.h" 111 | 112 | #endif 113 | 114 | -------------------------------------------------------------------------------- /src/openct/checksum.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Checksum handling 3 | * 4 | * Copyright Matthias Bruestle 1999-2002 5 | * For licensing, see the file LICENCE 6 | */ 7 | 8 | #include "config.h" 9 | #ifdef HAVE_STDINT_H 10 | #include 11 | #endif 12 | #include 13 | #include "checksum.h" 14 | 15 | #define min( a, b ) ( ( ( a ) < ( b ) ) ? ( a ) : ( b ) ) 16 | 17 | /* ISO STD 3309 */ 18 | /* From: medin@catbyte.b30.ingr.com (Dave Medin) 19 | * Subject: CCITT checksums 20 | * Newsgroups: sci.electronics 21 | * Date: Mon, 7 Dec 1992 17:33:39 GMT 22 | */ 23 | 24 | /* Correct Table? */ 25 | 26 | static unsigned short crctab[256] = { 27 | 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf, 28 | 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7, 29 | 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e, 30 | 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876, 31 | 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd, 32 | 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5, 33 | 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c, 34 | 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974, 35 | 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb, 36 | 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3, 37 | 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a, 38 | 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72, 39 | 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9, 40 | 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1, 41 | 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738, 42 | 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70, 43 | 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7, 44 | 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff, 45 | 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036, 46 | 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e, 47 | 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5, 48 | 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd, 49 | 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134, 50 | 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c, 51 | 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3, 52 | 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb, 53 | 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232, 54 | 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a, 55 | 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1, 56 | 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9, 57 | 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330, 58 | 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78 59 | }; 60 | 61 | /* 62 | * Returns LRC of data. 63 | */ 64 | unsigned int 65 | csum_lrc_compute(const uint8_t *in, size_t len, unsigned char *rc) 66 | { 67 | unsigned char lrc = 0; 68 | 69 | while (len--) 70 | lrc ^= *in++; 71 | 72 | if (rc) 73 | *rc = lrc; 74 | return 1; 75 | } 76 | 77 | /* 78 | * Compute CRC of data. 79 | */ 80 | unsigned int 81 | csum_crc_compute(const uint8_t * data, size_t len, unsigned char *rc) 82 | { 83 | unsigned short v = 0xFFFF; 84 | 85 | while (len--) { 86 | v = ((v >> 8) & 0xFF) ^ crctab[(v ^ *data++) & 0xFF]; 87 | } 88 | 89 | if (rc) { 90 | rc[0] = (v >> 8) & 0xFF; 91 | rc[1] = v & 0xFF; 92 | } 93 | 94 | return 2; 95 | } 96 | 97 | -------------------------------------------------------------------------------- /src/misc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * This handles GCC attributes 3 | * 4 | * MUSCLE SmartCard Development ( http://pcsclite.alioth.debian.org/pcsclite.html ) 5 | * 6 | * Copyright (C) 2005-2010 7 | * Ludovic Rousseau 8 | * 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are permitted provided that the following conditions 11 | are met: 12 | 13 | 1. Redistributions of source code must retain the above copyright 14 | notice, this list of conditions and the following disclaimer. 15 | 2. Redistributions in binary form must reproduce the above copyright 16 | notice, this list of conditions and the following disclaimer in the 17 | documentation and/or other materials provided with the distribution. 18 | 3. The name of the author may not be used to endorse or promote products 19 | derived from this software without specific prior written permission. 20 | 21 | Changes to this license can be made only by the copyright author with 22 | explicit written consent. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 25 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 26 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 27 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 28 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 29 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 33 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | * $Id: misc.h 6851 2014-02-14 15:43:32Z rousseau $ 36 | */ 37 | 38 | #ifndef __misc_h__ 39 | #define __misc_h__ 40 | 41 | /* 42 | * Declare the function as internal to the library: the function name is 43 | * not exported and can't be used by a program linked to the library 44 | * 45 | * see http://gcc.gnu.org/onlinedocs/gcc-3.3.5/gcc/Function-Attributes.html#Function-Attributes 46 | * see http://www.nedprod.com/programs/gccvisibility.html 47 | */ 48 | #if defined __GNUC__ && (! defined (__sun)) && (__GNUC__ >= 4 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) 49 | #define INTERNAL __attribute__ ((visibility("hidden"))) 50 | #define PCSC_API __attribute__ ((visibility("default"))) 51 | #elif (! defined __GNUC__ ) && defined (__sun) 52 | /* http://wikis.sun.com/display/SunStudio/Macros+for+Shared+Library+Symbol+Visibility */ 53 | #define INTERNAL __hidden 54 | #define PCSC_API __global 55 | #else 56 | #define INTERNAL 57 | #define PCSC_API 58 | #endif 59 | #define EXTERNAL PCSC_API 60 | 61 | #if defined __GNUC__ 62 | 63 | /* GNU Compiler Collection (GCC) */ 64 | #define CONSTRUCTOR __attribute__ ((constructor)) 65 | #define DESTRUCTOR __attribute__ ((destructor)) 66 | 67 | #else 68 | 69 | /* SUN C compiler does not use __attribute__ but #pragma init (function) 70 | * We can't use a # inside a #define so it is not possible to use 71 | * #define CONSTRUCTOR_DECLARATION(x) #pragma init (x) 72 | * The #pragma is used directly where needed */ 73 | 74 | /* any other */ 75 | #define CONSTRUCTOR 76 | #define DESTRUCTOR 77 | 78 | #endif 79 | 80 | #ifndef min 81 | #define min(a,b) (((a) < (b)) ? (a) : (b)) 82 | #endif 83 | 84 | #ifndef COUNT_OF 85 | #define COUNT_OF(arr) (sizeof(arr)/sizeof(arr[0])) 86 | #endif 87 | 88 | #endif /* __misc_h__ */ 89 | -------------------------------------------------------------------------------- /examples/PCSCv2part10.c: -------------------------------------------------------------------------------- 1 | /* 2 | PCSCv2part10.c: helper functions for PC/SC v2 part 10 services 3 | Copyright (C) 2012 Ludovic Rousseau 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | /* 21 | * $Id: PCSCv2part10.c 6559 2013-03-06 14:18:24Z rousseau $ 22 | */ 23 | 24 | #include 25 | #include 26 | 27 | #ifdef __APPLE__ 28 | #include 29 | #include 30 | #else 31 | #include 32 | #endif 33 | 34 | #include "PCSCv2part10.h" 35 | 36 | int PCSCv2Part10_find_TLV_property_by_tag_from_buffer( 37 | unsigned char *buffer, int length, int property, int * value_int) 38 | { 39 | unsigned char *p; 40 | int found = 0, len; 41 | int value = -1; 42 | int ret = -1; /* not found by default */ 43 | 44 | p = buffer; 45 | while (p-buffer < length) 46 | { 47 | if (*p++ == property) 48 | { 49 | found = 1; 50 | break; 51 | } 52 | 53 | /* go to next tag */ 54 | len = *p++; 55 | p += len; 56 | } 57 | 58 | if (found) 59 | { 60 | len = *p++; 61 | ret = 0; 62 | 63 | switch(len) 64 | { 65 | case 1: 66 | value = *p; 67 | break; 68 | case 2: 69 | value = *p + (*(p+1)<<8); 70 | break; 71 | case 4: 72 | value = *p + (*(p+1)<<8) + (*(p+2)<<16) + (*(p+3)<<24); 73 | break; 74 | default: 75 | /* wrong length for an integer */ 76 | ret = -2; 77 | } 78 | } 79 | 80 | if (value_int) 81 | *value_int = value; 82 | 83 | return ret; 84 | } /* PCSCv2Part10_find_TLV_property_by_tag_from_buffer */ 85 | 86 | int PCSCv2Part10_find_TLV_property_by_tag_from_hcard(SCARDHANDLE hCard, 87 | int property, int * value) 88 | { 89 | unsigned char buffer[MAX_BUFFER_SIZE]; 90 | LONG rv; 91 | DWORD length; 92 | unsigned int i; 93 | PCSC_TLV_STRUCTURE *pcsc_tlv; 94 | DWORD properties_in_tlv_ioctl; 95 | int found; 96 | 97 | rv = SCardControl(hCard, CM_IOCTL_GET_FEATURE_REQUEST, NULL, 0, 98 | buffer, sizeof buffer, &length); 99 | if (rv != SCARD_S_SUCCESS) 100 | return -1; 101 | 102 | /* get the number of elements instead of the complete size */ 103 | length /= sizeof(PCSC_TLV_STRUCTURE); 104 | 105 | pcsc_tlv = (PCSC_TLV_STRUCTURE *)buffer; 106 | found = 0; 107 | for (i = 0; i < length; i++) 108 | { 109 | if (FEATURE_GET_TLV_PROPERTIES == pcsc_tlv[i].tag) 110 | { 111 | properties_in_tlv_ioctl = ntohl(pcsc_tlv[i].value); 112 | found = 1; 113 | } 114 | } 115 | 116 | if (! found) 117 | return -3; 118 | 119 | rv= SCardControl(hCard, properties_in_tlv_ioctl, NULL, 0, 120 | buffer, sizeof buffer, &length); 121 | if (rv != SCARD_S_SUCCESS) 122 | return -1; 123 | 124 | return PCSCv2Part10_find_TLV_property_by_tag_from_buffer(buffer, 125 | length, property, value); 126 | } 127 | 128 | -------------------------------------------------------------------------------- /src/towitoko/pps.c: -------------------------------------------------------------------------------- 1 | /* 2 | pps.c 3 | Protocol Parameters Selection 4 | 5 | This file is part of the Unix driver for Towitoko smartcard readers 6 | Copyright (C) 2000 2001 Carlos Prados 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 2 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public License 19 | along with this library; if not, write to the Free Software Foundation, 20 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 21 | */ 22 | 23 | #include "pps.h" 24 | #include "atr.h" 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include "commands.h" 31 | #include "defs.h" 32 | #include "debug.h" 33 | 34 | /* 35 | * Not exported funtions declaration 36 | */ 37 | 38 | static bool PPS_Match (BYTE * request, unsigned len_request, BYTE * reply, unsigned len_reply); 39 | 40 | static unsigned PPS_GetLength (BYTE * block); 41 | 42 | static BYTE PPS_GetPCK (BYTE * block, unsigned length); 43 | 44 | int 45 | PPS_Exchange (int lun, BYTE * params, unsigned *length, unsigned char *pps1) 46 | { 47 | BYTE confirm[PPS_MAX_LENGTH]; 48 | unsigned len_request, len_confirm; 49 | int ret; 50 | 51 | len_request = PPS_GetLength (params); 52 | params[len_request - 1] = PPS_GetPCK(params, len_request - 1); 53 | 54 | DEBUG_XXD ("PPS: Sending request: ", params, len_request); 55 | 56 | /* Send PPS request */ 57 | if (CCID_Transmit (lun, len_request, params, isCharLevel(lun) ? 4 : 0, 0) 58 | != IFD_SUCCESS) 59 | return PPS_ICC_ERROR; 60 | 61 | /* Get PPS confirm */ 62 | len_confirm = sizeof(confirm); 63 | if (CCID_Receive (lun, &len_confirm, confirm, NULL) != IFD_SUCCESS) 64 | return PPS_ICC_ERROR; 65 | 66 | DEBUG_XXD ("PPS: Receiving confirm: ", confirm, len_confirm); 67 | 68 | if (!PPS_Match (params, len_request, confirm, len_confirm)) 69 | ret = PPS_HANDSAKE_ERROR; 70 | else 71 | ret = PPS_OK; 72 | 73 | *pps1 = 0x11; /* default TA1 */ 74 | 75 | /* if PPS1 is echoed */ 76 | if (PPS_HAS_PPS1 (params) && PPS_HAS_PPS1 (confirm)) 77 | *pps1 = confirm[2]; 78 | 79 | /* Copy PPS handsake */ 80 | memcpy (params, confirm, len_confirm); 81 | (*length) = len_confirm; 82 | 83 | return ret; 84 | } 85 | 86 | static bool 87 | PPS_Match (BYTE * request, unsigned len_request, BYTE * confirm, unsigned len_confirm) 88 | { 89 | /* See if the reply differs from request */ 90 | if ((len_request == len_confirm) && /* same length */ 91 | memcmp (request, confirm, len_request)) /* different contents */ 92 | return FALSE; 93 | 94 | if (len_request < len_confirm) /* confirm longer than request */ 95 | return FALSE; 96 | 97 | /* See if the card specifies other than default FI and D */ 98 | if ((PPS_HAS_PPS1 (confirm)) && (confirm[2] != request[2])) 99 | return FALSE; 100 | 101 | return TRUE; 102 | } 103 | 104 | static unsigned 105 | PPS_GetLength (BYTE * block) 106 | { 107 | unsigned length = 3; 108 | 109 | if (PPS_HAS_PPS1 (block)) 110 | length++; 111 | 112 | if (PPS_HAS_PPS2 (block)) 113 | length++; 114 | 115 | if (PPS_HAS_PPS3 (block)) 116 | length++; 117 | 118 | return length; 119 | } 120 | 121 | static BYTE 122 | PPS_GetPCK (BYTE * block, unsigned length) 123 | { 124 | BYTE pck; 125 | unsigned i; 126 | 127 | pck = block[0]; 128 | for (i = 1; i < length; i++) 129 | pck ^= block[i]; 130 | 131 | return pck; 132 | } 133 | 134 | -------------------------------------------------------------------------------- /MacOSX/configure: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | # Copyright (C) 2007-2009 Ludovic Rousseau 4 | # 5 | # This program is free software; you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation; either version 2 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program; if not, write to the Free Software 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 18 | # 02110-1301 USA. 19 | 20 | # $Id: configure 6792 2013-11-25 13:03:21Z rousseau $ 21 | 22 | # to use 23 | # ./MacOSX/configure 24 | # make 25 | # make install 26 | # the driver is installed in /usr/libexec/SmartCardServices/drivers 27 | 28 | # Colors 29 | RED="\033[31m" 30 | NORMAL="\033[0m" 31 | 32 | # run this script as ./MacOSX/configure to configure for Mac OS X 33 | if [ ! -d MacOSX ] 34 | then 35 | echo -e $RED 36 | echo "ERROR!" 37 | echo "run ./MacOSX/configure from the source top directory" 38 | echo -e $NORMAL 39 | exit; 40 | fi 41 | 42 | # find pcsc-lite header files in MacOSX/ 43 | # use ${varname:-word} to return word only if varname is not already defined 44 | PCSC_CFLAGS=${PCSC_CFLAGS:--I$(pwd)/MacOSX} 45 | PCSC_LIBS=${PCSC_LIBS:--framework PCSC} 46 | 47 | # use libusb-1.0 (or libusbx-1.0) 48 | LIBUSB_ARCHIVE=$(pkg-config --variable=libdir libusb-1.0)/libusb-1.0.a 49 | LIBUSB_CFLAGS=$(pkg-config --cflags --static libusb-1.0) 50 | LIBUSB_LIBS=$(pkg-config --libs --static libusb-1.0) 51 | 52 | # RESPONSECODE is already defined by PCSC/wintypes.h 53 | # define needed here to compile examples/scardcontrol.c since config.h is 54 | # not included 55 | CFLAGS="$CFLAGS -DRESPONSECODE_DEFINED_IN_WINTYPES_H" 56 | 57 | # Build a Universal Binary 58 | UB=$(file $LIBUSB_ARCHIVE | grep "Mach-O universal binary") 59 | echo $UB 60 | if [ -z "$UB" ] 61 | then 62 | echo -en $RED 63 | echo "*************************" 64 | echo "No Universal Binary build" 65 | echo "*************************" 66 | echo -en $NORMAL 67 | else 68 | echo "Universal Binary build" 69 | CFLAGS="$CFLAGS -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -arch i386 -arch x86_64" 70 | fi 71 | echo 72 | 73 | CONFIGURE_ARGS="--disable-dependency-tracking" 74 | 75 | # do not build a static driver 76 | # (building fails when linking statically with libusb) 77 | CONFIGURE_ARGS="$CONFIGURE_ARGS --disable-static" 78 | 79 | # do not use pcscd debug feature 80 | CONFIGURE_ARGS="$CONFIGURE_ARGS --disable-pcsclite" 81 | 82 | # simulate a composite device as multi slots 83 | CONFIGURE_ARGS="$CONFIGURE_ARGS --enable-composite-as-multislot" 84 | 85 | # set BUNDLE_ID to a specific value for a specific driver 86 | #BUNDLE_ID="vendor-reader" 87 | if [ ! -z "$BUNDLE_ID" ] 88 | then 89 | # do not build a class driver (not yet used by pcsc-lite on Mac OS X) 90 | CONFIGURE_ARGS="$CONFIGURE_ARGS --disable-class" 91 | 92 | # use a specific bundle name to NOT overwrite the official CCID driver 93 | CONFIGURE_ARGS="$CONFIGURE_ARGS --enable-bundle=ifd-ccid-$BUNDLE_ID.bundle" 94 | 95 | # differentiate each libccid library by the dynamic linker 96 | CONFIGURE_ARGS="$CONFIGURE_ARGS --prefix=/fake/$BUNDLE_ID" 97 | fi 98 | 99 | set -x 100 | ./configure \ 101 | CFLAGS="$CFLAGS" \ 102 | PCSC_CFLAGS="$PCSC_CFLAGS" \ 103 | PCSC_LIBS="$PCSC_LIBS" \ 104 | LIBUSB_CFLAGS="$LIBUSB_CFLAGS" \ 105 | LIBUSB_LIBS="$LIBUSB_LIBS" \ 106 | LDFLAGS="$LDFLAGS" \ 107 | --enable-usbdropdir=/usr/libexec/SmartCardServices/drivers \ 108 | $CONFIGURE_ARGS \ 109 | "$@" 110 | 111 | # force a regeneration of Info.plist 112 | rm -f src/Info.plist 113 | 114 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | # $Id: Makefile.am 6752 2013-09-16 18:27:04Z rousseau $ 2 | 3 | CCID_BUNDLE = $(bundle) 4 | CCID_LIB = libccid.$(DYN_LIB_EXT) 5 | CCIDTWIN_LIB = libccidtwin.$(DYN_LIB_EXT) 6 | 7 | CCID_VERSION=CCID_VERSION=`$(srcdir)/convert_version.pl $(PACKAGE_VERSION)` 8 | 9 | lib_LTLIBRARIES = 10 | LIBS_TO_INSTALL = 11 | LIBS_TO_UNINSTALL = 12 | if WITH_LIBUSB 13 | lib_LTLIBRARIES += libccid.la 14 | LIBS_TO_INSTALL += install_ccid 15 | LIBS_TO_UNINSTALL += uninstall_ccid 16 | noinst_PROGRAMS = parse 17 | endif 18 | if WITH_TWIN_SERIAL 19 | lib_LTLIBRARIES += libccidtwin.la 20 | LIBS_TO_INSTALL += install_ccidtwin 21 | LIBS_TO_UNINSTALL += uninstall_ccidtwin 22 | endif 23 | 24 | COMMON = ccid.c \ 25 | ccid.h \ 26 | ccid_ifdhandler.h \ 27 | commands.c \ 28 | commands.h \ 29 | debug.h \ 30 | defs.h \ 31 | ifdhandler.c \ 32 | utils.c \ 33 | utils.h 34 | USB = ccid_usb.c ccid_usb.h 35 | SERIAL = ccid_serial.c ccid_serial.h 36 | T1 = towitoko/atr.c \ 37 | towitoko/atr.h \ 38 | towitoko/defines.h \ 39 | towitoko/pps.c \ 40 | towitoko/pps.h \ 41 | openct/buffer.c \ 42 | openct/buffer.h \ 43 | openct/checksum.c \ 44 | openct/checksum.h \ 45 | openct/proto-t1.c \ 46 | openct/proto-t1.h 47 | TOKEN_PARSER = tokenparser.l parser.h \ 48 | strlcpy.c \ 49 | misc.h \ 50 | strlcpycat.h \ 51 | simclist.c \ 52 | simclist.h 53 | 54 | if WITHOUT_PCSC 55 | PROVIDED_BY_PCSC = debug.c 56 | endif 57 | 58 | libccid_la_SOURCES = $(COMMON) $(USB) $(TOKEN_PARSER) $(PROVIDED_BY_PCSC) $(T1) 59 | libccid_la_LIBADD = $(LEXLIB) $(LIBUSB_LIBS) $(PTHREAD_LIBS) 60 | libccid_la_CFLAGS = $(PCSC_CFLAGS) $(LIBUSB_CFLAGS) $(PTHREAD_CFLAGS) \ 61 | $(SYMBOL_VISIBILITY) -D$(CCID_VERSION) -DSIMCLIST_NO_DUMPRESTORE 62 | libccid_la_LDFLAGS = -avoid-version 63 | 64 | libccidtwin_la_SOURCES = $(COMMON) $(SERIAL) $(TOKEN_PARSER) \ 65 | $(PROVIDED_BY_PCSC) $(T1) 66 | libccidtwin_la_CFLAGS = $(PCSC_CFLAGS) $(PTHREAD_CFLAGS) $(SYMBOL_VISIBILITY) \ 67 | -DTWIN_SERIAL -D$(CCID_VERSION) -DSIMCLIST_NO_DUMPRESTORE 68 | libccidtwin_la_LIBADD = $(PTHREAD_LIBS) 69 | libccidtwin_la_LDFLAGS = -avoid-version 70 | 71 | parse_SOURCES = parse.c debug.c ccid_usb.c $(TOKEN_PARSER) 72 | parse_LDADD = $(LIBUSB_LIBS) 73 | parse_CFLAGS = $(PCSC_CFLAGS) $(LIBUSB_CFLAGS) -DSIMCLIST_NO_DUMPRESTORE 74 | 75 | EXTRA_DIST = Info.plist.src create_Info_plist.pl reader.conf.in \ 76 | towitoko/COPYING towitoko/README openct/LICENSE \ 77 | convert_version.pl 92_pcscd_ccid.rules 78 | 79 | # We can't use install-exec-local since we want to overwrite the install 80 | # rule. We do not want to _add_ files to install 81 | install: $(LIBS_TO_INSTALL) 82 | 83 | INSTALL_UDEV_RULE_FILE=@/bin/echo -e "\n\33[01;31m***************\n" ; echo "copy the src/92_pcscd_ccid.rules file in udev directory (/etc/udev/rules.d/)" ; /bin/echo -e "\n***************\n\33[0m" 84 | 85 | Info.plist: Info.plist.src $(srcdir)/../readers/supported_readers.txt 86 | $(srcdir)/create_Info_plist.pl $(srcdir)/../readers/supported_readers.txt $(srcdir)/Info.plist.src --target=$(CCID_LIB) --version=$(VERSION) $(NOCLASS) > Info.plist 87 | 88 | DISTCLEANFILES = tokenparser.c Info.plist 89 | 90 | install_ccid: libccid.la Info.plist 91 | $(mkinstalldirs) $(DESTDIR)$(usbdropdir)/$(CCID_BUNDLE)/Contents/$(BUNDLE_HOST)/ 92 | cp Info.plist $(DESTDIR)$(usbdropdir)/$(CCID_BUNDLE)/Contents/ 93 | cp .libs/$(CCID_LIB) $(DESTDIR)$(usbdropdir)/$(CCID_BUNDLE)/Contents/$(BUNDLE_HOST)/$(CCID_LIB) 94 | $(INSTALL_UDEV_RULE_FILE) 95 | 96 | install_ccidtwin: libccidtwin.la 97 | $(mkinstalldirs) $(DESTDIR)$(ccidtwindir) 98 | cp .libs/$(CCIDTWIN_LIB) $(DESTDIR)$(ccidtwindir)/$(CCIDTWIN_LIB) 99 | $(mkinstalldirs) $(DESTDIR)/$(serialconfdir) ; \ 100 | perl -ne "s|TARGET|$(ccidtwindir)/$(CCIDTWIN_LIB)| ; print" $(srcdir)/reader.conf.in > $(DESTDIR)/$(serialconfdir)/libccidtwin 101 | 102 | # do not uninstall the serial driver by default 103 | # use explicitely 'make uninstall_ccidtwin' 104 | uninstall: $(LIBS_TO_UNINSTALL) 105 | 106 | uninstall_ccid: 107 | rm -rf $(DESTDIR)$(usbdropdir)/$(CCID_BUNDLE) 108 | 109 | uninstall_ccidtwin: 110 | rm -f $(DESTDIR)$(ccidtwindir)/$(CCIDTWIN_LIB) 111 | rm -f $(DESTDIR)/$(serialconfdir)/libccidtwin 112 | 113 | -------------------------------------------------------------------------------- /config.h.in: -------------------------------------------------------------------------------- 1 | /* config.h.in. Generated from configure.ac by autoheader. */ 2 | 3 | /* bundle directory name */ 4 | #undef BUNDLE 5 | 6 | /* Define to 1 if you have the header file. */ 7 | #undef HAVE_ARPA_INET_H 8 | 9 | /* Define to 1 if you have the header file. */ 10 | #undef HAVE_DLFCN_H 11 | 12 | /* Define to 1 if you have the header file. */ 13 | #undef HAVE_ERRNO_H 14 | 15 | /* Define to 1 if you have the header file. */ 16 | #undef HAVE_FCNTL_H 17 | 18 | /* Define to 1 if you have the header file. */ 19 | #undef HAVE_INTTYPES_H 20 | 21 | /* Define to 1 if you have the header file. */ 22 | #undef HAVE_LIBUSB_H 23 | 24 | /* Define to 1 if you have the `memcpy' function. */ 25 | #undef HAVE_MEMCPY 26 | 27 | /* Define to 1 if you have the header file. */ 28 | #undef HAVE_MEMORY_H 29 | 30 | /* Define if you have POSIX threads libraries and header files. */ 31 | #undef HAVE_PTHREAD 32 | 33 | /* Have PTHREAD_PRIO_INHERIT. */ 34 | #undef HAVE_PTHREAD_PRIO_INHERIT 35 | 36 | /* Define to 1 if you have the `select' function. */ 37 | #undef HAVE_SELECT 38 | 39 | /* Define to 1 if you have the header file. */ 40 | #undef HAVE_STDARG_H 41 | 42 | /* Define to 1 if you have the header file. */ 43 | #undef HAVE_STDINT_H 44 | 45 | /* Define to 1 if you have the header file. */ 46 | #undef HAVE_STDLIB_H 47 | 48 | /* Define to 1 if you have the `strerror' function. */ 49 | #undef HAVE_STRERROR 50 | 51 | /* Define to 1 if you have the header file. */ 52 | #undef HAVE_STRINGS_H 53 | 54 | /* Define to 1 if you have the header file. */ 55 | #undef HAVE_STRING_H 56 | 57 | /* Define to 1 if you have the `strlcat' function. */ 58 | #undef HAVE_STRLCAT 59 | 60 | /* Define to 1 if you have the `strlcpy' function. */ 61 | #undef HAVE_STRLCPY 62 | 63 | /* Define to 1 if you have the `strncpy' function. */ 64 | #undef HAVE_STRNCPY 65 | 66 | /* Define to 1 if you have the header file. */ 67 | #undef HAVE_SYS_STAT_H 68 | 69 | /* Define to 1 if you have the header file. */ 70 | #undef HAVE_SYS_TIME_H 71 | 72 | /* Define to 1 if you have the header file. */ 73 | #undef HAVE_SYS_TYPES_H 74 | 75 | /* Define to 1 if you have the header file. */ 76 | #undef HAVE_TERMIOS_H 77 | 78 | /* Define to 1 if you have the header file. */ 79 | #undef HAVE_UNISTD_H 80 | 81 | /* Define to the sub-directory in which libtool stores uninstalled libraries. 82 | */ 83 | #undef LT_OBJDIR 84 | 85 | /* Disable logging support */ 86 | #undef NO_LOG 87 | 88 | /* Name of package */ 89 | #undef PACKAGE 90 | 91 | /* Define to the address where bug reports for this package should be sent. */ 92 | #undef PACKAGE_BUGREPORT 93 | 94 | /* Define to the full name of this package. */ 95 | #undef PACKAGE_NAME 96 | 97 | /* Define to the full name and version of this package. */ 98 | #undef PACKAGE_STRING 99 | 100 | /* Define to the one symbol short name of this package. */ 101 | #undef PACKAGE_TARNAME 102 | 103 | /* Define to the home page for this package. */ 104 | #undef PACKAGE_URL 105 | 106 | /* Define to the version of this package. */ 107 | #undef PACKAGE_VERSION 108 | 109 | /* directory containing USB drivers */ 110 | #undef PCSCLITE_HP_DROPDIR 111 | 112 | /* Define to necessary symbol if this constant uses a non-standard name on 113 | your system. */ 114 | #undef PTHREAD_CREATE_JOINABLE 115 | 116 | /* Define to 1 if you have the ANSI C header files. */ 117 | #undef STDC_HEADERS 118 | 119 | /* Define to 1 if you can safely include both and . */ 120 | #undef TIME_WITH_SYS_TIME 121 | 122 | /* composite device are seen as multi-slots */ 123 | #undef USE_COMPOSITE_AS_MULTISLOT 124 | 125 | /* Version number of package */ 126 | #undef VERSION 127 | 128 | /* Define to 1 if `lex' declares `yytext' as a `char *' by default, not a 129 | `char[]'. */ 130 | #undef YYTEXT_POINTER 131 | 132 | /* Define to empty if `const' does not conform to ANSI C. */ 133 | #undef const 134 | 135 | /* Define to `unsigned int' if does not define. */ 136 | #undef size_t 137 | -------------------------------------------------------------------------------- /src/towitoko/atr.h: -------------------------------------------------------------------------------- 1 | /* 2 | atr.h 3 | ISO 7816 ICC's answer to reset abstract data type definitions 4 | 5 | This file is part of the Unix driver for Towitoko smartcard readers 6 | Copyright (C) 2000 Carlos Prados 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 2 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public License 19 | along with this library; if not, write to the Free Software Foundation, 20 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 21 | */ 22 | 23 | #ifndef _ATR_ 24 | #define _ATR_ 25 | 26 | #include "defines.h" 27 | 28 | /* 29 | * Exported constants definition 30 | */ 31 | 32 | /* Return values */ 33 | #define ATR_OK 0 /* ATR could be parsed and data returned */ 34 | #define ATR_NOT_FOUND 1 /* Data not present in ATR */ 35 | #define ATR_MALFORMED 2 /* ATR could not be parsed */ 36 | #define ATR_IO_ERROR 3 /* I/O stream error */ 37 | 38 | /* Paramenters */ 39 | #define ATR_MAX_SIZE 33 /* Maximum size of ATR byte array */ 40 | #define ATR_MAX_HISTORICAL 15 /* Maximum number of historical bytes */ 41 | #define ATR_MAX_PROTOCOLS 7 /* Maximun number of protocols */ 42 | #define ATR_MAX_IB 4 /* Maximum number of interface bytes per protocol */ 43 | #define ATR_CONVENTION_DIRECT 0 /* Direct convention */ 44 | #define ATR_CONVENTION_INVERSE 1 /* Inverse convention */ 45 | #define ATR_PROTOCOL_TYPE_T0 0 /* Protocol type T=0 */ 46 | #define ATR_PROTOCOL_TYPE_T1 1 /* Protocol type T=1 */ 47 | #define ATR_PROTOCOL_TYPE_T2 2 /* Protocol type T=2 */ 48 | #define ATR_PROTOCOL_TYPE_T3 3 /* Protocol type T=3 */ 49 | #define ATR_PROTOCOL_TYPE_T14 14 /* Protocol type T=14 */ 50 | #define ATR_INTERFACE_BYTE_TA 0 /* Interface byte TAi */ 51 | #define ATR_INTERFACE_BYTE_TB 1 /* Interface byte TBi */ 52 | #define ATR_INTERFACE_BYTE_TC 2 /* Interface byte TCi */ 53 | #define ATR_INTERFACE_BYTE_TD 3 /* Interface byte TDi */ 54 | #define ATR_PARAMETER_F 0 /* Parameter F */ 55 | #define ATR_PARAMETER_D 1 /* Parameter D */ 56 | #define ATR_PARAMETER_I 2 /* Parameter I */ 57 | #define ATR_PARAMETER_P 3 /* Parameter P */ 58 | #define ATR_PARAMETER_N 4 /* Parameter N */ 59 | #define ATR_INTEGER_VALUE_FI 0 /* Integer value FI */ 60 | #define ATR_INTEGER_VALUE_DI 1 /* Integer value DI */ 61 | #define ATR_INTEGER_VALUE_II 2 /* Integer value II */ 62 | #define ATR_INTEGER_VALUE_PI1 3 /* Integer value PI1 */ 63 | #define ATR_INTEGER_VALUE_N 4 /* Integer value N */ 64 | #define ATR_INTEGER_VALUE_PI2 5 /* Integer value PI2 */ 65 | 66 | /* Default values for paramenters */ 67 | #define ATR_DEFAULT_F 372 68 | #define ATR_DEFAULT_D 1 69 | #define ATR_DEFAULT_I 50 70 | #define ATR_DEFAULT_N 0 71 | #define ATR_DEFAULT_P 5 72 | 73 | /* 74 | * Exported data types definition 75 | */ 76 | 77 | typedef struct 78 | { 79 | unsigned length; 80 | BYTE TS; 81 | BYTE T0; 82 | struct 83 | { 84 | BYTE value; 85 | bool present; 86 | } 87 | ib[ATR_MAX_PROTOCOLS][ATR_MAX_IB], TCK; 88 | unsigned pn; 89 | BYTE hb[ATR_MAX_HISTORICAL]; 90 | unsigned hbn; 91 | } 92 | ATR_t; 93 | 94 | /* 95 | * Exported functions declaraton 96 | */ 97 | 98 | /* Initialization */ 99 | extern int ATR_InitFromArray(ATR_t * atr, const BYTE buffer[ATR_MAX_SIZE], 100 | unsigned length); 101 | 102 | /* General smartcard characteristics */ 103 | extern int ATR_GetConvention(ATR_t * atr, /*@out@*/ int *convention); 104 | extern int ATR_GetDefaultProtocol(ATR_t * atr, /*@out@*/ int *protocol); 105 | 106 | /* ATR parameters and integer values */ 107 | extern int ATR_GetIntegerValue(ATR_t * atr, int name, BYTE * value); 108 | extern int ATR_GetParameter(ATR_t * atr, int name, /*@out@*/ double *parameter); 109 | 110 | #endif /* _ATR_ */ 111 | 112 | -------------------------------------------------------------------------------- /src/Info.plist.src: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | MAGIC_TARGET 9 | CFBundleIdentifier 10 | org.debian.alioth.pcsclite.smartcardccid 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | MAGIC_CLASS 14 | CFBundlePackageType 15 | BNDL 16 | CFBundleShortVersionString 17 | MAGIC_VERSION 18 | CFBundleSignature 19 | ???? 20 | CFBundleVersion 21 | 0.0.1d1 22 | ifdCapabilities 23 | 0x00000001 24 | 25 | 31 | 32 | ifdProtocolSupport 33 | 0x00000001 34 | ifdVersionNumber 35 | 0x00000001 36 | 37 | ifdLogLevel 38 | 0x0003 39 | 40 | 52 | 53 | ifdDriverOptions 54 | 0x0000 55 | 56 | 99 | 100 | ifdManufacturerString 101 | Ludovic Rousseau (ludovic.rousseau@free.fr) 102 | 103 | ifdProductString 104 | Generic CCID driver 105 | 106 | ifdVendorID 107 | 108 | MAGIC_VENDOR 109 | 110 | 111 | ifdProductID 112 | 113 | MAGIC_PRODUCT 114 | 115 | 116 | ifdFriendlyName 117 | 118 | MAGIC_FRIENDLYNAME 119 | 120 | 121 | Copyright 122 | This driver is protected by terms of the GNU Lesser General Public License version 2.1, or (at your option) any later version. 123 | 124 | 125 | 126 | -------------------------------------------------------------------------------- /src/debug.h: -------------------------------------------------------------------------------- 1 | /* 2 | debug.h: log (or not) messages using syslog 3 | Copyright (C) 2003-2008 Ludovic Rousseau 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | 20 | /* 21 | * $Id: debug.h 6798 2013-11-26 13:49:00Z rousseau $ 22 | */ 23 | 24 | /* 25 | * DEBUG_CRITICAL("text"); 26 | * log "text" if (LogLevel & DEBUG_LEVEL_CRITICAL) is TRUE 27 | * 28 | * DEBUG_CRITICAL2("text: %d", 1234); 29 | * log "text: 1234" if (DEBUG_LEVEL_CRITICAL & DEBUG_LEVEL_CRITICAL) is TRUE 30 | * the format string can be anything printf() can understand 31 | * 32 | * same thing for DEBUG_INFO, DEBUG_COMM and DEBUG_PERIODIC 33 | * 34 | * DEBUG_XXD(msg, buffer, size); 35 | * log a dump of buffer if (LogLevel & DEBUG_LEVEL_COMM) is TRUE 36 | * 37 | */ 38 | 39 | #ifndef _GCDEBUG_H_ 40 | #define _GCDEBUG_H_ 41 | 42 | /* You can't do #ifndef __FUNCTION__ */ 43 | #if !defined(__GNUC__) && !defined(__IBMC__) 44 | #define __FUNCTION__ "" 45 | #endif 46 | 47 | extern int LogLevel; 48 | 49 | #define DEBUG_LEVEL_CRITICAL 1 50 | #define DEBUG_LEVEL_INFO 2 51 | #define DEBUG_LEVEL_COMM 4 52 | #define DEBUG_LEVEL_PERIODIC 8 53 | 54 | #include /* from pcsc-lite */ 55 | 56 | /* DEBUG_CRITICAL */ 57 | #define DEBUG_CRITICAL(fmt) if (LogLevel & DEBUG_LEVEL_CRITICAL) Log1(PCSC_LOG_CRITICAL, fmt) 58 | 59 | #define DEBUG_CRITICAL2(fmt, data) if (LogLevel & DEBUG_LEVEL_CRITICAL) Log2(PCSC_LOG_CRITICAL, fmt, data) 60 | 61 | #define DEBUG_CRITICAL3(fmt, data1, data2) if (LogLevel & DEBUG_LEVEL_CRITICAL) Log3(PCSC_LOG_CRITICAL, fmt, data1, data2) 62 | 63 | #define DEBUG_CRITICAL4(fmt, data1, data2, data3) if (LogLevel & DEBUG_LEVEL_CRITICAL) Log4(PCSC_LOG_CRITICAL, fmt, data1, data2, data3) 64 | 65 | #define DEBUG_CRITICAL5(fmt, data1, data2, data3, data4) if (LogLevel & DEBUG_LEVEL_CRITICAL) Log5(PCSC_LOG_CRITICAL, fmt, data1, data2, data3, data4) 66 | 67 | /* DEBUG_INFO */ 68 | #define DEBUG_INFO(fmt) if (LogLevel & DEBUG_LEVEL_INFO) Log1(PCSC_LOG_INFO, fmt) 69 | 70 | #define DEBUG_INFO2(fmt, data) if (LogLevel & DEBUG_LEVEL_INFO) Log2(PCSC_LOG_INFO, fmt, data) 71 | 72 | #define DEBUG_INFO3(fmt, data1, data2) if (LogLevel & DEBUG_LEVEL_INFO) Log3(PCSC_LOG_INFO, fmt, data1, data2) 73 | 74 | #define DEBUG_INFO4(fmt, data1, data2, data3) if (LogLevel & DEBUG_LEVEL_INFO) Log4(PCSC_LOG_INFO, fmt, data1, data2, data3) 75 | 76 | #define DEBUG_INFO5(fmt, data1, data2, data3, data4) if (LogLevel & DEBUG_LEVEL_INFO) Log5(PCSC_LOG_INFO, fmt, data1, data2, data3, data4) 77 | 78 | #define DEBUG_INFO_XXD(msg, buffer, size) if (LogLevel & DEBUG_LEVEL_INFO) log_xxd(PCSC_LOG_INFO, msg, buffer, size) 79 | 80 | /* DEBUG_PERIODIC */ 81 | #define DEBUG_PERIODIC(fmt) if (LogLevel & DEBUG_LEVEL_PERIODIC) Log1(PCSC_LOG_DEBUG, fmt) 82 | 83 | #define DEBUG_PERIODIC2(fmt, data) if (LogLevel & DEBUG_LEVEL_PERIODIC) Log2(PCSC_LOG_DEBUG, fmt, data) 84 | 85 | #define DEBUG_PERIODIC3(fmt, data1, data2) if (LogLevel & DEBUG_LEVEL_PERIODIC) Log3(PCSC_LOG_DEBUG, fmt, data1, data2) 86 | 87 | /* DEBUG_COMM */ 88 | #define DEBUG_COMM(fmt) if (LogLevel & DEBUG_LEVEL_COMM) Log1(PCSC_LOG_DEBUG, fmt) 89 | 90 | #define DEBUG_COMM2(fmt, data) if (LogLevel & DEBUG_LEVEL_COMM) Log2(PCSC_LOG_DEBUG, fmt, data) 91 | 92 | #define DEBUG_COMM3(fmt, data1, data2) if (LogLevel & DEBUG_LEVEL_COMM) Log3(PCSC_LOG_DEBUG, fmt, data1, data2) 93 | 94 | #define DEBUG_COMM4(fmt, data1, data2, data3) if (LogLevel & DEBUG_LEVEL_COMM) Log4(PCSC_LOG_DEBUG, fmt, data1, data2, data3) 95 | 96 | /* DEBUG_XXD */ 97 | #define DEBUG_XXD(msg, buffer, size) if (LogLevel & DEBUG_LEVEL_COMM) log_xxd(PCSC_LOG_DEBUG, msg, buffer, size) 98 | 99 | #endif 100 | 101 | -------------------------------------------------------------------------------- /config.h: -------------------------------------------------------------------------------- 1 | /* config.h. Generated from config.h.in by configure. */ 2 | /* config.h.in. Generated from configure.in by autoheader. */ 3 | 4 | /* bundle directory name */ 5 | #define BUNDLE "ifd-ccid.bundle" 6 | 7 | /* Define to 1 if you have the header file. */ 8 | #define HAVE_ARPA_INET_H 1 9 | 10 | /* Define to 1 if you have the header file. */ 11 | #define HAVE_DLFCN_H 1 12 | 13 | /* Define to 1 if you have the header file. */ 14 | #define HAVE_ERRNO_H 1 15 | 16 | /* Define to 1 if you have the header file. */ 17 | #define HAVE_FCNTL_H 1 18 | 19 | /* Define to 1 if you have the header file. */ 20 | #define HAVE_INTTYPES_H 1 21 | 22 | /* Define to 1 if you have the header file. */ 23 | #define HAVE_LIBUSB_H 1 24 | 25 | /* Define to 1 if you have the `memcpy' function. */ 26 | #define HAVE_MEMCPY 1 27 | 28 | /* Define to 1 if you have the header file. */ 29 | #define HAVE_MEMORY_H 1 30 | 31 | /* Define if you have POSIX threads libraries and header files. */ 32 | #define HAVE_PTHREAD 1 33 | 34 | /* Define to 1 if you have the `select' function. */ 35 | #define HAVE_SELECT 1 36 | 37 | /* Define to 1 if you have the header file. */ 38 | #define HAVE_STDARG_H 1 39 | 40 | /* Define to 1 if you have the header file. */ 41 | #define HAVE_STDINT_H 1 42 | 43 | /* Define to 1 if you have the header file. */ 44 | #define HAVE_STDLIB_H 1 45 | 46 | /* Define to 1 if you have the `strerror' function. */ 47 | #define HAVE_STRERROR 1 48 | 49 | /* Define to 1 if you have the header file. */ 50 | #define HAVE_STRINGS_H 1 51 | 52 | /* Define to 1 if you have the header file. */ 53 | #define HAVE_STRING_H 1 54 | 55 | /* Define to 1 if you have the `strlcat' function. */ 56 | /* #undef HAVE_STRLCAT */ 57 | 58 | /* Define to 1 if you have the `strlcpy' function. */ 59 | /* #undef HAVE_STRLCPY */ 60 | 61 | /* Define to 1 if you have the `strncpy' function. */ 62 | #define HAVE_STRNCPY 1 63 | 64 | /* Define to 1 if you have the header file. */ 65 | #define HAVE_SYS_STAT_H 1 66 | 67 | /* Define to 1 if you have the header file. */ 68 | #define HAVE_SYS_TIME_H 1 69 | 70 | /* Define to 1 if you have the header file. */ 71 | #define HAVE_SYS_TYPES_H 1 72 | 73 | /* Define to 1 if you have the header file. */ 74 | #define HAVE_TERMIOS_H 1 75 | 76 | /* Define to 1 if you have the header file. */ 77 | #define HAVE_UNISTD_H 1 78 | 79 | /* Define to the sub-directory in which libtool stores uninstalled libraries. 80 | */ 81 | #define LT_OBJDIR ".libs/" 82 | 83 | /* Disable logging support */ 84 | /* #undef NO_LOG */ 85 | 86 | /* Define to 1 if your C compiler doesn't accept -c and -o together. */ 87 | /* #undef NO_MINUS_C_MINUS_O */ 88 | 89 | /* Name of package */ 90 | #define PACKAGE "ccid" 91 | 92 | /* Define to the address where bug reports for this package should be sent. */ 93 | #define PACKAGE_BUGREPORT "" 94 | 95 | /* Define to the full name of this package. */ 96 | #define PACKAGE_NAME "ccid" 97 | 98 | /* Define to the full name and version of this package. */ 99 | #define PACKAGE_STRING "ccid 1.4.7" 100 | 101 | /* Define to the one symbol short name of this package. */ 102 | #define PACKAGE_TARNAME "ccid" 103 | 104 | /* Define to the home page for this package. */ 105 | #define PACKAGE_URL "" 106 | 107 | /* Define to the version of this package. */ 108 | #define PACKAGE_VERSION "1.4.7" 109 | 110 | /* directory containing USB drivers */ 111 | #define PCSCLITE_HP_DROPDIR PCSCD_PATH "/usb" 112 | 113 | /* Define to necessary symbol if this constant uses a non-standard name on 114 | your system. */ 115 | /* #undef PTHREAD_CREATE_JOINABLE */ 116 | 117 | /* Define to 1 if you have the ANSI C header files. */ 118 | #define STDC_HEADERS 1 119 | 120 | /* Define to 1 if you can safely include both and . */ 121 | #define TIME_WITH_SYS_TIME 1 122 | 123 | /* composite device are seen as multi-slots */ 124 | /* #undef USE_COMPOSITE_AS_MULTISLOT */ 125 | 126 | /* Version number of package */ 127 | #define VERSION "1.4.7" 128 | 129 | /* Define to 1 if `lex' declares `yytext' as a `char *' by default, not a 130 | `char[]'. */ 131 | #define YYTEXT_POINTER 1 132 | 133 | /* Define to empty if `const' does not conform to ANSI C. */ 134 | /* #undef const */ 135 | 136 | /* Define to `unsigned int' if does not define. */ 137 | /* #undef size_t */ 138 | -------------------------------------------------------------------------------- /src/debug.c: -------------------------------------------------------------------------------- 1 | /* 2 | debug.c: log (or not) messages 3 | Copyright (C) 2003-2011 Ludovic Rousseau 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | 20 | /* 21 | * $Id: debug.c 6760 2013-10-01 12:57:50Z rousseau $ 22 | */ 23 | 24 | 25 | #include "config.h" 26 | #include "misc.h" 27 | #include "debug.h" 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | 35 | #include "strlcpycat.h" 36 | #include 37 | 38 | #undef LOG_TO_STDERR 39 | 40 | #ifdef LOG_TO_STDERR 41 | #define LOG_STREAM stderr 42 | #else 43 | #define LOG_STREAM stdout 44 | #endif 45 | 46 | #ifdef ANDROID 47 | #define TAG "LibUsb" 48 | int printf(const char *format, ...) 49 | { 50 | va_list ap; 51 | va_start(ap, format); 52 | return __android_log_vprint(ANDROID_LOG_DEBUG, TAG, format, ap); 53 | } 54 | 55 | int fprintf(FILE *fd, const char *format, ...) 56 | { 57 | va_list ap; 58 | va_start(ap, format); 59 | return __android_log_vprint(ANDROID_LOG_DEBUG, TAG, format, ap); 60 | } 61 | #endif 62 | 63 | void log_msg(const int priority, const char *fmt, ...) 64 | { 65 | char debug_buffer[320]; /* up to 4 lines of 80 characters */ 66 | va_list argptr; 67 | static struct timeval last_time = { 0, 0 }; 68 | struct timeval new_time = { 0, 0 }; 69 | struct timeval tmp; 70 | int delta; 71 | const char *color_pfx = "", *color_sfx = ""; 72 | const char *time_pfx = "", *time_sfx = ""; 73 | static int initialized = 0; 74 | static int LogDoColor = 0; 75 | 76 | if (!initialized) 77 | { 78 | char *term; 79 | 80 | initialized = 1; 81 | term = getenv("TERM"); 82 | if (term) 83 | { 84 | const char *terms[] = { "linux", "xterm", "xterm-color", "Eterm", "rxvt", "rxvt-unicode", "xterm-256color" }; 85 | unsigned int i; 86 | 87 | /* for each known color terminal */ 88 | for (i = 0; i < COUNT_OF(terms); i++) 89 | { 90 | /* we found a supported term? */ 91 | if (0 == strcmp(terms[i], term)) 92 | { 93 | LogDoColor = 1; 94 | break; 95 | } 96 | } 97 | } 98 | } 99 | 100 | if (LogDoColor) 101 | { 102 | color_sfx = "\33[0m"; 103 | time_sfx = color_sfx; 104 | time_pfx = "\33[36m"; /* Cyan */ 105 | 106 | switch (priority) 107 | { 108 | case PCSC_LOG_CRITICAL: 109 | color_pfx = "\33[01;31m"; /* bright + Red */ 110 | break; 111 | 112 | case PCSC_LOG_ERROR: 113 | color_pfx = "\33[35m"; /* Magenta */ 114 | break; 115 | 116 | case PCSC_LOG_INFO: 117 | color_pfx = "\33[34m"; /* Blue */ 118 | break; 119 | 120 | case PCSC_LOG_DEBUG: 121 | color_pfx = ""; /* normal (black) */ 122 | color_sfx = ""; 123 | break; 124 | } 125 | } 126 | 127 | gettimeofday(&new_time, NULL); 128 | if (0 == last_time.tv_sec) 129 | last_time = new_time; 130 | 131 | tmp.tv_sec = new_time.tv_sec - last_time.tv_sec; 132 | tmp.tv_usec = new_time.tv_usec - last_time.tv_usec; 133 | if (tmp.tv_usec < 0) 134 | { 135 | tmp.tv_sec--; 136 | tmp.tv_usec += 1000000; 137 | } 138 | if (tmp.tv_sec < 100) 139 | delta = tmp.tv_sec * 1000000 + tmp.tv_usec; 140 | else 141 | delta = 99999999; 142 | 143 | last_time = new_time; 144 | 145 | va_start(argptr, fmt); 146 | (void)vsnprintf(debug_buffer, sizeof debug_buffer, fmt, argptr); 147 | va_end(argptr); 148 | 149 | (void)fprintf(LOG_STREAM, "%s%.8d%s %s%s%s\n", time_pfx, delta, time_sfx, 150 | color_pfx, debug_buffer, color_sfx); 151 | fflush(LOG_STREAM); 152 | } /* log_msg */ 153 | 154 | void log_xxd(const int priority, const char *msg, const unsigned char *buffer, 155 | const int len) 156 | { 157 | int i; 158 | char *c, debug_buffer[len*3 + strlen(msg) +1]; 159 | size_t l; 160 | 161 | (void)priority; 162 | 163 | l = strlcpy(debug_buffer, msg, sizeof debug_buffer); 164 | c = debug_buffer + l; 165 | 166 | for (i = 0; i < len; ++i) 167 | { 168 | /* 2 hex characters, 1 space, 1 NUL : total 4 characters */ 169 | (void)snprintf(c, 4, "%02X ", buffer[i]); 170 | c += 3; 171 | } 172 | 173 | (void)fprintf(LOG_STREAM, "%s\n", debug_buffer); 174 | fflush(LOG_STREAM); 175 | } /* log_xxd */ 176 | -------------------------------------------------------------------------------- /m4/ltsugar.m4: -------------------------------------------------------------------------------- 1 | # ltsugar.m4 -- libtool m4 base layer. -*-Autoconf-*- 2 | # 3 | # Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc. 4 | # Written by Gary V. Vaughan, 2004 5 | # 6 | # This file is free software; the Free Software Foundation gives 7 | # unlimited permission to copy and/or distribute it, with or without 8 | # modifications, as long as this notice is preserved. 9 | 10 | # serial 6 ltsugar.m4 11 | 12 | # This is to help aclocal find these macros, as it can't see m4_define. 13 | AC_DEFUN([LTSUGAR_VERSION], [m4_if([0.1])]) 14 | 15 | 16 | # lt_join(SEP, ARG1, [ARG2...]) 17 | # ----------------------------- 18 | # Produce ARG1SEPARG2...SEPARGn, omitting [] arguments and their 19 | # associated separator. 20 | # Needed until we can rely on m4_join from Autoconf 2.62, since all earlier 21 | # versions in m4sugar had bugs. 22 | m4_define([lt_join], 23 | [m4_if([$#], [1], [], 24 | [$#], [2], [[$2]], 25 | [m4_if([$2], [], [], [[$2]_])$0([$1], m4_shift(m4_shift($@)))])]) 26 | m4_define([_lt_join], 27 | [m4_if([$#$2], [2], [], 28 | [m4_if([$2], [], [], [[$1$2]])$0([$1], m4_shift(m4_shift($@)))])]) 29 | 30 | 31 | # lt_car(LIST) 32 | # lt_cdr(LIST) 33 | # ------------ 34 | # Manipulate m4 lists. 35 | # These macros are necessary as long as will still need to support 36 | # Autoconf-2.59 which quotes differently. 37 | m4_define([lt_car], [[$1]]) 38 | m4_define([lt_cdr], 39 | [m4_if([$#], 0, [m4_fatal([$0: cannot be called without arguments])], 40 | [$#], 1, [], 41 | [m4_dquote(m4_shift($@))])]) 42 | m4_define([lt_unquote], $1) 43 | 44 | 45 | # lt_append(MACRO-NAME, STRING, [SEPARATOR]) 46 | # ------------------------------------------ 47 | # Redefine MACRO-NAME to hold its former content plus `SEPARATOR'`STRING'. 48 | # Note that neither SEPARATOR nor STRING are expanded; they are appended 49 | # to MACRO-NAME as is (leaving the expansion for when MACRO-NAME is invoked). 50 | # No SEPARATOR is output if MACRO-NAME was previously undefined (different 51 | # than defined and empty). 52 | # 53 | # This macro is needed until we can rely on Autoconf 2.62, since earlier 54 | # versions of m4sugar mistakenly expanded SEPARATOR but not STRING. 55 | m4_define([lt_append], 56 | [m4_define([$1], 57 | m4_ifdef([$1], [m4_defn([$1])[$3]])[$2])]) 58 | 59 | 60 | 61 | # lt_combine(SEP, PREFIX-LIST, INFIX, SUFFIX1, [SUFFIX2...]) 62 | # ---------------------------------------------------------- 63 | # Produce a SEP delimited list of all paired combinations of elements of 64 | # PREFIX-LIST with SUFFIX1 through SUFFIXn. Each element of the list 65 | # has the form PREFIXmINFIXSUFFIXn. 66 | # Needed until we can rely on m4_combine added in Autoconf 2.62. 67 | m4_define([lt_combine], 68 | [m4_if(m4_eval([$# > 3]), [1], 69 | [m4_pushdef([_Lt_sep], [m4_define([_Lt_sep], m4_defn([lt_car]))])]]dnl 70 | [[m4_foreach([_Lt_prefix], [$2], 71 | [m4_foreach([_Lt_suffix], 72 | ]m4_dquote(m4_dquote(m4_shift(m4_shift(m4_shift($@)))))[, 73 | [_Lt_sep([$1])[]m4_defn([_Lt_prefix])[$3]m4_defn([_Lt_suffix])])])])]) 74 | 75 | 76 | # lt_if_append_uniq(MACRO-NAME, VARNAME, [SEPARATOR], [UNIQ], [NOT-UNIQ]) 77 | # ----------------------------------------------------------------------- 78 | # Iff MACRO-NAME does not yet contain VARNAME, then append it (delimited 79 | # by SEPARATOR if supplied) and expand UNIQ, else NOT-UNIQ. 80 | m4_define([lt_if_append_uniq], 81 | [m4_ifdef([$1], 82 | [m4_if(m4_index([$3]m4_defn([$1])[$3], [$3$2$3]), [-1], 83 | [lt_append([$1], [$2], [$3])$4], 84 | [$5])], 85 | [lt_append([$1], [$2], [$3])$4])]) 86 | 87 | 88 | # lt_dict_add(DICT, KEY, VALUE) 89 | # ----------------------------- 90 | m4_define([lt_dict_add], 91 | [m4_define([$1($2)], [$3])]) 92 | 93 | 94 | # lt_dict_add_subkey(DICT, KEY, SUBKEY, VALUE) 95 | # -------------------------------------------- 96 | m4_define([lt_dict_add_subkey], 97 | [m4_define([$1($2:$3)], [$4])]) 98 | 99 | 100 | # lt_dict_fetch(DICT, KEY, [SUBKEY]) 101 | # ---------------------------------- 102 | m4_define([lt_dict_fetch], 103 | [m4_ifval([$3], 104 | m4_ifdef([$1($2:$3)], [m4_defn([$1($2:$3)])]), 105 | m4_ifdef([$1($2)], [m4_defn([$1($2)])]))]) 106 | 107 | 108 | # lt_if_dict_fetch(DICT, KEY, [SUBKEY], VALUE, IF-TRUE, [IF-FALSE]) 109 | # ----------------------------------------------------------------- 110 | m4_define([lt_if_dict_fetch], 111 | [m4_if(lt_dict_fetch([$1], [$2], [$3]), [$4], 112 | [$5], 113 | [$6])]) 114 | 115 | 116 | # lt_dict_filter(DICT, [SUBKEY], VALUE, [SEPARATOR], KEY, [...]) 117 | # -------------------------------------------------------------- 118 | m4_define([lt_dict_filter], 119 | [m4_if([$5], [], [], 120 | [lt_join(m4_quote(m4_default([$4], [[, ]])), 121 | lt_unquote(m4_split(m4_normalize(m4_foreach(_Lt_key, lt_car([m4_shiftn(4, $@)]), 122 | [lt_if_dict_fetch([$1], _Lt_key, [$2], [$3], [_Lt_key ])])))))])[]dnl 123 | ]) 124 | -------------------------------------------------------------------------------- /examples/PCSCv2part10.h: -------------------------------------------------------------------------------- 1 | /* 2 | PCSCv2part10.h: helper functions for PC/SC v2 part 10 services 3 | Copyright (C) 2012 Ludovic Rousseau 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | /* 21 | * $Id: PCSCv2part10.h 6429 2012-08-10 13:20:29Z rousseau $ 22 | */ 23 | 24 | #ifndef __reader_h__ 25 | 26 | #ifdef HAVE_CONFIG_H 27 | #include "config.h" 28 | #endif 29 | 30 | #ifdef HAVE_READER_H 31 | #include 32 | #else 33 | 34 | /** 35 | * Provide source compatibility on different platforms 36 | */ 37 | #define SCARD_CTL_CODE(code) (0x42000000 + (code)) 38 | 39 | /** 40 | * PC/SC part 10 v2.02.07 March 2010 reader tags 41 | */ 42 | #define CM_IOCTL_GET_FEATURE_REQUEST SCARD_CTL_CODE(3400) 43 | 44 | #define FEATURE_GET_TLV_PROPERTIES 0x12 /**< Get TLV properties */ 45 | 46 | #include 47 | 48 | /* Set structure elements aligment on bytes 49 | * http://gcc.gnu.org/onlinedocs/gcc/Structure_002dPacking-Pragmas.html */ 50 | #if defined(__APPLE__) | defined(sun) 51 | #pragma pack(1) 52 | #else 53 | #pragma pack(push, 1) 54 | #endif 55 | 56 | /** the structure must be 6-bytes long */ 57 | typedef struct 58 | { 59 | uint8_t tag; /**< Tag */ 60 | uint8_t length; /**< Length */ 61 | uint32_t value; /**< This value is always in BIG ENDIAN format as documented in PCSC v2 part 10 ch 2.2 page 2. You can use ntohl() for example */ 62 | } PCSC_TLV_STRUCTURE; 63 | 64 | /* restore default structure elements alignment */ 65 | #if defined(__APPLE__) | defined(sun) 66 | #pragma pack() 67 | #else 68 | #pragma pack(pop) 69 | #endif 70 | 71 | /* properties returned by FEATURE_GET_TLV_PROPERTIES */ 72 | #define PCSCv2_PART10_PROPERTY_wLcdLayout 1 /**< wLcdLayout */ 73 | #define PCSCv2_PART10_PROPERTY_bEntryValidationCondition 2 /**< bEntryValidationCondition */ 74 | #define PCSCv2_PART10_PROPERTY_bTimeOut2 3 /**< bTimeOut2 */ 75 | #define PCSCv2_PART10_PROPERTY_wLcdMaxCharacters 4 /**< wLcdMaxCharacters */ 76 | #define PCSCv2_PART10_PROPERTY_wLcdMaxLines 5 /**< wLcdMaxLines */ 77 | #define PCSCv2_PART10_PROPERTY_bMinPINSize 6 /**< bMinPINSize */ 78 | #define PCSCv2_PART10_PROPERTY_bMaxPINSize 7 /**< bMaxPINSize */ 79 | #define PCSCv2_PART10_PROPERTY_sFirmwareID 8 /**< sFirmwareID */ 80 | #define PCSCv2_PART10_PROPERTY_bPPDUSupport 9 /**< bPPDUSupport */ 81 | #define PCSCv2_PART10_PROPERTY_dwMaxAPDUDataSize 10 /**< dwMaxAPDUDataSize */ 82 | #define PCSCv2_PART10_PROPERTY_wIdVendor 11 /**< wIdVendor */ 83 | #define PCSCv2_PART10_PROPERTY_wIdProduct 12 /**< wIdProduct */ 84 | 85 | #endif 86 | #endif 87 | 88 | /** 89 | * @file 90 | * @defgroup API API 91 | * 92 | * The available PC/SC v2 part 10 tags are (from pcsc-lite 1.8.5): 93 | * 94 | * - \ref PCSCv2_PART10_PROPERTY_wLcdLayout 95 | * - \ref PCSCv2_PART10_PROPERTY_bEntryValidationCondition 96 | * - \ref PCSCv2_PART10_PROPERTY_bTimeOut2 97 | * - \ref PCSCv2_PART10_PROPERTY_wLcdMaxCharacters 98 | * - \ref PCSCv2_PART10_PROPERTY_wLcdMaxLines 99 | * - \ref PCSCv2_PART10_PROPERTY_bMinPINSize 100 | * - \ref PCSCv2_PART10_PROPERTY_bMaxPINSize 101 | * - \ref PCSCv2_PART10_PROPERTY_sFirmwareID 102 | * - \ref PCSCv2_PART10_PROPERTY_bPPDUSupport 103 | * - \ref PCSCv2_PART10_PROPERTY_dwMaxAPDUDataSize 104 | * - \ref PCSCv2_PART10_PROPERTY_wIdVendor 105 | * - \ref PCSCv2_PART10_PROPERTY_wIdProduct 106 | * 107 | * Example of code: 108 | * @include sample.c 109 | */ 110 | 111 | /** 112 | * @brief Find an integer value by tag from TLV buffer 113 | * @ingroup API 114 | * 115 | * @param buffer buffer received from FEATURE_GET_TLV_PROPERTIES 116 | * @param length buffer length 117 | * @param property tag searched 118 | * @param[out] value value found 119 | * @return Error code 120 | * 121 | * @retval 0 success 122 | * @retval -1 not found 123 | * @retval -2 invalid length in the TLV 124 | * 125 | */ 126 | int PCSCv2Part10_find_TLV_property_by_tag_from_buffer( 127 | unsigned char *buffer, int length, int property, int * value); 128 | 129 | /** 130 | * @brief Find a integer value by tag from a PC/SC card handle 131 | * @ingroup API 132 | * 133 | * @param hCard card handle as returned by SCardConnect() 134 | * @param property tag searched 135 | * @param[out] value value found 136 | * @return Error code (see PCSCv2Part10_find_TLV_property_by_tag_from_buffer()) 137 | */ 138 | int PCSCv2Part10_find_TLV_property_by_tag_from_hcard(SCARDHANDLE hCard, 139 | int property, int * value); 140 | 141 | -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | INSTALLATION PROCEDURE 2 | ====================== 3 | 4 | Installation from source: 5 | """"""""""""""""""""""""" 6 | 7 | get the ccid-x.y.z.tar.gz archive and do: 8 | 9 | $ tar xzvf ccid-x.y.z.tar.gz 10 | $ cd ccid-x.y.z 11 | $ ./configure 12 | $ make 13 | $ sudo make install 14 | 15 | By default pcscd and my ccid driver use /usr/local/pcsc/drivers/ as 16 | directory for hotplug drivers. The ./configure script try to get the 17 | directory used by pcscd using 'pkg-config libpcsclite --variable=usbdropdir' 18 | So you should not have to use the --enable-usbdropdir=DIR argument. 19 | 20 | 21 | udev use 22 | ~~~~~~~~ 23 | 24 | It is possible to configure the driver to use udev events so that pcscd 25 | will not poll the USB bus every second. Use: 26 | 27 | $ ./configure --enable-udev 28 | $ make 29 | 30 | You will then have to install the udev rules file in the correct 31 | directory. It could be something like: 32 | 33 | $ sudo cp src/pcscd_ccid.rules /etc/udev/rules.d/ 34 | 35 | 36 | On FreeBSD you can also use --enable-udev and add the following rules to 37 | devd.conf (thanks to Tilman Linneweh for the info) 38 | 39 | attach 100 { 40 | device-name "ugen[0-9]+"; 41 | action "/usr/sbin/pcscd -H"; 42 | }; 43 | 44 | detach 100 { 45 | device-name "ugen[0-9]+"; 46 | action "/usr/sbin/pcscd -H"; 47 | }; 48 | 49 | 50 | libusb not found 51 | ~~~~~~~~~~~~~~~~ 52 | 53 | If the ./configure script says something like: 54 | configure: error: usb.h not found, use --enable-libusb=PATH 55 | You should use --enable-libusb=PATH to tell ./configure where to find 56 | the usb.h and libusb.so files. The ./configure script will use 57 | PATH/include/ to search for usb.h and PATH/lib/ to search for libusb.so 58 | 59 | 60 | building serial reader driver 61 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 62 | 63 | A serial CCID reader can also be connected on a serial port. By default 64 | the serial driver is not built. You must explicitely do: 65 | 66 | $ ./configure --enable-twinserial 67 | $ make 68 | # make install 69 | 70 | 71 | builing serial reader driver only 72 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 73 | 74 | It is possible to generate the driver for the GemPC Twin using serial 75 | communication only (for example on an embedded system without USB). 76 | Just do: 77 | $ ./configure --enable-twinserial --disable-libusb 78 | $ make 79 | # make install 80 | 81 | By default ./configure try to get the directory used by pcscd using 82 | 'pkg-config libpcsclite --variable=usbdropdir' and add '/serial'. 83 | You should not have to use --enable-ccidtwindir=DIR to specify the 84 | target directory to use. 85 | 86 | 87 | configuring the driver for the serial reader 88 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 89 | 90 | You have to create or edit the file /etc/reader.conf. The file should 91 | contain something like: 92 | 93 | # Gemalto reader with serial communication 94 | # - reader is the reader name. It is needed for multi-slot readers. 95 | # Possible reader values are: GemPCPinPad, GemCorePOSPro, GemCoreSIMPro, 96 | # GemPCTwin (default value) 97 | # example: /dev/ttyS0:GemPCPinPad 98 | #FRIENDLYNAME "GemPCTwin serial" 99 | #DEVICENAME /dev/ttySn[:reader] 100 | #LIBPATH TARGET 101 | #CHANNELID 1 102 | 103 | FRIENDLYNAME "GemPC Twin serial" 104 | DEVICENAME /dev/ttyS0 105 | LIBPATH /usr/local/pcsc/drivers/serial/libccidtwin.so.1.2.3 106 | CHANNELID 1 107 | 108 | You will have to adapt the library path to your configuration and library 109 | version. 110 | 111 | By default the GemPC Twin serial reader parameters are loaded by the 112 | driver, if you use a GemPC PinPad, a GemCore POS Pro or a GemCore SIM 113 | Pro you have to indicate it in the DEVICENAME field. You will then have 114 | something like: 115 | DEVICENAME /dev/ttyS0:GemPCPinPad 116 | 117 | /dev/ttyS0 (DEVICENAME field) is the first serial port under Linux 118 | (known as COM1 under DOS/Windows). Of course if your reader is connected 119 | to another serial port you have to adapt that. 120 | 121 | 122 | Binary installation: 123 | """""""""""""""""""" 124 | 125 | Contact your distribution support. 126 | 127 | 128 | Test procedure: 129 | """"""""""""""" 130 | 131 | - check the reader is supported by the driver. 132 | Get your reader USB identification using the lsusb(1) command: 133 | $ lsusb 134 | [...] 135 | Bus 001 Device 048: ID 08e6:4433 Gemplus 136 | 137 | Look for 08E6 (ifdVendorID) and 4433 (ifdProductID) in 138 | /usr/local/pcsc/drivers/ifd-ccid.bundle/Contents/Info.plist 139 | Of course your numbers will be different. 140 | 141 | If you can't find them add them (if you know what you do) and/or mail me. 142 | 143 | - (re)start pcscd with debug on stdout. Simply do 'pcscd --debug stdout' 144 | (you will need to have root priviledges). And look for: 145 | [...] 146 | readerfactory.c:1319 RFInitializeReader: Attempting startup of ReaderName 147 | readerfactory.c:1061 RFBindFunctions: Loading IFD Handler 2.0 148 | ifdhandler.c:76 Entering IFDHCreateChannel (lun: 0) 149 | ccid_usb.c:131 Manufacturer: Ludovic Rousseau (ludovic.rousseau@free.fr) 150 | ccid_usb.c:139 ProductString: Generic CCID reader v0.1.0 151 | ccid_usb.c:143 Copyright: This driver is protected by terms of the GNU General Public License version 2, or (at your option) any later version. 152 | ccid_usb.c:223 Found Vendor/Product: 08E6/4433 (GemPC433 SL) 153 | ccid_usb.c:224 Using USB bus/device: 001/047 154 | 155 | If you don't see this the driver is not installed correctly or your 156 | reader is not yet supported. Read 157 | http://pcsclite.alioth.debian.org/ccid.html#CCID_compliant to know 158 | what to do. 159 | 160 | $Id: INSTALL 4814 2010-03-12 15:42:07Z rousseau $ 161 | -------------------------------------------------------------------------------- /contrib/RSA_SecurID/RSA_SecurID_getpasswd.c: -------------------------------------------------------------------------------- 1 | /* 2 | RSA_SecurID_getpasswd.c: get the one-use password from a RSA sid-800 token 3 | Copyright (C) 2006 Ludovic Rousseau 4 | 5 | This program is free software; you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation; either version 2 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License along 16 | with this program; if not, write to the Free Software Foundation, Inc., 51 17 | Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | /* PCSC error message pretty print */ 26 | #define PCSC_ERROR_EXIT(rv, text) \ 27 | if (rv != SCARD_S_SUCCESS) \ 28 | { \ 29 | printf(text ": %s (0x%lX)\n", pcsc_stringify_error(rv), rv); \ 30 | goto end; \ 31 | } 32 | 33 | int main(void) 34 | { 35 | unsigned char cmd1[] = { 0x00, 0xa4, 0x04, 0x00, 0x0a, 0xa0, 0x00, 0x00, 0x00, 0x63, 0x86, 0x53, 0x49, 0x44, 0x01}; 36 | unsigned char cmd2[] = { 0x80, 0x56, 0x00, 0x00, 0x04 }; 37 | unsigned char cmd3[] = { 0x80, 0x48, 0x00, 0x00, 0x04, 0xff, 0xff, 0xff, 0xff }; 38 | unsigned char cmd4[] = { 0x80, 0x44, 0x00, 0x00, 0x05}; 39 | LONG rv; 40 | SCARDCONTEXT hContext; 41 | DWORD dwReaders; 42 | LPSTR mszReaders = NULL; 43 | char **readers = NULL; 44 | SCARDHANDLE hCard; 45 | DWORD dwActiveProtocol; 46 | unsigned char bRecvBuffer[MAX_BUFFER_SIZE]; 47 | DWORD length; 48 | SCARD_IO_REQUEST pioRecvPci; 49 | SCARD_IO_REQUEST pioSendPci; 50 | 51 | rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); 52 | if (rv != SCARD_S_SUCCESS) 53 | { 54 | printf("SCardEstablishContext: Cannot Connect to Resource Manager %lX\n", rv); 55 | return 1; 56 | } 57 | 58 | /* Retrieve the available readers list */ 59 | rv = SCardListReaders(hContext, NULL, NULL, &dwReaders); 60 | PCSC_ERROR_EXIT(rv, "SCardListReader"); 61 | 62 | if (dwReaders < 4) 63 | { 64 | printf("No reader found!\n"); 65 | return -1; 66 | } 67 | 68 | mszReaders = malloc(sizeof(char)*dwReaders); 69 | if (mszReaders == NULL) 70 | { 71 | printf("malloc: not enough memory\n"); 72 | goto end; 73 | } 74 | 75 | rv = SCardListReaders(hContext, NULL, mszReaders, &dwReaders); 76 | PCSC_ERROR_EXIT(rv, "SCardListReader"); 77 | 78 | /* connect to the first reader */ 79 | dwActiveProtocol = -1; 80 | rv = SCardConnect(hContext, mszReaders, SCARD_SHARE_EXCLUSIVE, 81 | SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, &hCard, &dwActiveProtocol); 82 | PCSC_ERROR_EXIT(rv, "SCardConnect") 83 | 84 | switch(dwActiveProtocol) 85 | { 86 | case SCARD_PROTOCOL_T0: 87 | pioSendPci = *SCARD_PCI_T0; 88 | break; 89 | case SCARD_PROTOCOL_T1: 90 | pioSendPci = *SCARD_PCI_T1; 91 | break; 92 | default: 93 | printf("Unknown protocol\n"); 94 | return -1; 95 | } 96 | 97 | /* APDU select applet */ 98 | length = sizeof(bRecvBuffer); 99 | rv = SCardTransmit(hCard, &pioSendPci, cmd1, sizeof cmd1, 100 | &pioRecvPci, bRecvBuffer, &length); 101 | PCSC_ERROR_EXIT(rv, "SCardTransmit") 102 | if ((length != 2) || (bRecvBuffer[0] != 0x90) || (bRecvBuffer[1] != 0x00)) 103 | { 104 | printf("cmd1 failed (%ld): %02X%02X\n", length, bRecvBuffer[length-2], 105 | bRecvBuffer[length-1]); 106 | goto end; 107 | } 108 | 109 | /* non ISO APDU */ 110 | length = sizeof(bRecvBuffer); 111 | rv = SCardTransmit(hCard, &pioSendPci, cmd2, sizeof cmd2, 112 | &pioRecvPci, bRecvBuffer, &length); 113 | PCSC_ERROR_EXIT(rv, "SCardTransmit") 114 | if ((length != 6) || (bRecvBuffer[4] != 0x90) || (bRecvBuffer[5] != 0x00)) 115 | { 116 | printf("cmd2 failed (%ld) : %02X%02X\n", length, bRecvBuffer[length-2], 117 | bRecvBuffer[length-1]); 118 | goto end; 119 | } 120 | 121 | /* get the argument for cmd3 from result of cmd2 */ 122 | memcpy(cmd3+5, bRecvBuffer, 4); 123 | 124 | /* non ISO APDU */ 125 | length = sizeof(bRecvBuffer); 126 | rv = SCardTransmit(hCard, &pioSendPci, cmd3, sizeof cmd3, 127 | &pioRecvPci, bRecvBuffer, &length); 128 | PCSC_ERROR_EXIT(rv, "SCardTransmit") 129 | if ((length != 2) || (bRecvBuffer[0] != 0x90) || (bRecvBuffer[1] != 0x00)) 130 | { 131 | printf("cmd3 failed (%ld): %02X%02X\n", length, bRecvBuffer[length-2], 132 | bRecvBuffer[length-1]); 133 | goto end; 134 | } 135 | 136 | /* non iSO APDU */ 137 | length = sizeof(bRecvBuffer); 138 | rv = SCardTransmit(hCard, &pioSendPci, cmd4, sizeof cmd4, 139 | &pioRecvPci, bRecvBuffer, &length); 140 | PCSC_ERROR_EXIT(rv, "SCardTransmit") 141 | if ((length != 7) || (bRecvBuffer[5] != 0x90) || (bRecvBuffer[6] != 0x00)) 142 | { 143 | printf("cmd4 failed (%ld): %02X%02X\n", length, bRecvBuffer[length-2], 144 | bRecvBuffer[length-1]); 145 | goto end; 146 | } 147 | 148 | printf("%02X%02X%02X\n", bRecvBuffer[2], bRecvBuffer[3], bRecvBuffer[4]); 149 | 150 | end: 151 | /* We try to leave things as clean as possible */ 152 | rv = SCardReleaseContext(hContext); 153 | if (rv != SCARD_S_SUCCESS) 154 | printf("SCardReleaseContext: %s (0x%lX)\n", pcsc_stringify_error(rv), 155 | rv); 156 | 157 | /* free allocated memory */ 158 | free(mszReaders); 159 | free(readers); 160 | 161 | return 0; 162 | } /* main */ 163 | 164 | -------------------------------------------------------------------------------- /MacOSX/debuglog.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MUSCLE SmartCard Development ( http://pcsclite.alioth.debian.org/pcsclite.html ) 3 | * 4 | * Copyright (C) 1999-2004 5 | * David Corcoran 6 | * Copyright (C) 1999-2011 7 | * Ludovic Rousseau 8 | * 9 | Redistribution and use in source and binary forms, with or without 10 | modification, are permitted provided that the following conditions 11 | are met: 12 | 13 | 1. Redistributions of source code must retain the above copyright 14 | notice, this list of conditions and the following disclaimer. 15 | 2. Redistributions in binary form must reproduce the above copyright 16 | notice, this list of conditions and the following disclaimer in the 17 | documentation and/or other materials provided with the distribution. 18 | 3. The name of the author may not be used to endorse or promote products 19 | derived from this software without specific prior written permission. 20 | 21 | Changes to this license can be made only by the copyright author with 22 | explicit written consent. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 25 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 26 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 27 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 28 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 29 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 31 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 32 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 33 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | * $Id: debuglog.h 6851 2014-02-14 15:43:32Z rousseau $ 36 | */ 37 | 38 | /** 39 | * @file 40 | * @brief This handles debugging. 41 | * 42 | * @note log message is sent to syslog or stderr depending on --foreground 43 | * command line argument 44 | * 45 | * @code 46 | * Log1(priority, "text"); 47 | * log "text" with priority level priority 48 | * Log2(priority, "text: %d", 1234); 49 | * log "text: 1234" 50 | * the format string can be anything printf() can understand 51 | * Log3(priority, "text: %d %d", 1234, 5678); 52 | * log "text: 1234 5678" 53 | * the format string can be anything printf() can understand 54 | * LogXxd(priority, msg, buffer, size); 55 | * log "msg" + a hex dump of size bytes of buffer[] 56 | * @endcode 57 | */ 58 | 59 | #ifndef __debuglog_h__ 60 | #define __debuglog_h__ 61 | 62 | #ifndef PCSC_API 63 | #define PCSC_API 64 | #endif 65 | 66 | enum { 67 | DEBUGLOG_NO_DEBUG = 0, 68 | DEBUGLOG_SYSLOG_DEBUG, 69 | DEBUGLOG_STDOUT_DEBUG, 70 | DEBUGLOG_STDOUT_COLOR_DEBUG 71 | }; 72 | 73 | #define DEBUG_CATEGORY_NOTHING 0 74 | #define DEBUG_CATEGORY_APDU 1 75 | #define DEBUG_CATEGORY_SW 2 76 | 77 | enum { 78 | PCSC_LOG_DEBUG = 0, 79 | PCSC_LOG_INFO, 80 | PCSC_LOG_ERROR, 81 | PCSC_LOG_CRITICAL 82 | }; 83 | 84 | /* You can't do #ifndef __FUNCTION__ */ 85 | #if !defined(__GNUC__) && !defined(__IBMC__) 86 | #define __FUNCTION__ "" 87 | #endif 88 | 89 | #ifndef __GNUC__ 90 | #define __attribute__(x) /*nothing*/ 91 | #endif 92 | 93 | #ifdef NO_LOG 94 | 95 | #define Log0(priority) do { } while(0) 96 | #define Log1(priority, fmt) do { } while(0) 97 | #define Log2(priority, fmt, data) do { } while(0) 98 | #define Log3(priority, fmt, data1, data2) do { } while(0) 99 | #define Log4(priority, fmt, data1, data2, data3) do { } while(0) 100 | #define Log5(priority, fmt, data1, data2, data3, data4) do { } while(0) 101 | #define Log9(priority, fmt, data1, data2, data3, data4, data5, data6, data7, data8) do { } while(0) 102 | #define LogXxd(priority, msg, buffer, size) do { } while(0) 103 | 104 | #define DebugLogA(a) 105 | #define DebugLogB(a, b) 106 | #define DebugLogC(a, b,c) 107 | 108 | #else 109 | 110 | #define Log0(priority) log_msg(priority, "%s:%d:%s()", __FILE__, __LINE__, __FUNCTION__) 111 | #define Log1(priority, fmt) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__) 112 | #define Log2(priority, fmt, data) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__, data) 113 | #define Log3(priority, fmt, data1, data2) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__, data1, data2) 114 | #define Log4(priority, fmt, data1, data2, data3) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__, data1, data2, data3) 115 | #define Log5(priority, fmt, data1, data2, data3, data4) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__, data1, data2, data3, data4) 116 | #define Log9(priority, fmt, data1, data2, data3, data4, data5, data6, data7, data8) log_msg(priority, "%s:%d:%s() " fmt, __FILE__, __LINE__, __FUNCTION__, data1, data2, data3, data4, data5, data6, data7, data8) 117 | #define LogXxd(priority, msg, buffer, size) log_xxd(priority, msg, buffer, size) 118 | 119 | #define DebugLogA(a) Log1(PCSC_LOG_INFO, a) 120 | #define DebugLogB(a, b) Log2(PCSC_LOG_INFO, a, b) 121 | #define DebugLogC(a, b,c) Log3(PCSC_LOG_INFO, a, b, c) 122 | 123 | #endif /* NO_LOG */ 124 | 125 | PCSC_API void log_msg(const int priority, const char *fmt, ...) 126 | __attribute__((format(printf, 2, 3))); 127 | 128 | PCSC_API void log_xxd(const int priority, const char *msg, 129 | const unsigned char *buffer, const int size); 130 | 131 | void DebugLogSuppress(const int); 132 | void DebugLogSetLogType(const int); 133 | int DebugLogSetCategory(const int); 134 | void DebugLogCategory(const int, const unsigned char *, const int); 135 | PCSC_API void DebugLogSetLevel(const int level); 136 | 137 | #endif /* __debuglog_h__ */ 138 | 139 | -------------------------------------------------------------------------------- /m4/lt~obsolete.m4: -------------------------------------------------------------------------------- 1 | # lt~obsolete.m4 -- aclocal satisfying obsolete definitions. -*-Autoconf-*- 2 | # 3 | # Copyright (C) 2004, 2005, 2007, 2009 Free Software Foundation, Inc. 4 | # Written by Scott James Remnant, 2004. 5 | # 6 | # This file is free software; the Free Software Foundation gives 7 | # unlimited permission to copy and/or distribute it, with or without 8 | # modifications, as long as this notice is preserved. 9 | 10 | # serial 5 lt~obsolete.m4 11 | 12 | # These exist entirely to fool aclocal when bootstrapping libtool. 13 | # 14 | # In the past libtool.m4 has provided macros via AC_DEFUN (or AU_DEFUN) 15 | # which have later been changed to m4_define as they aren't part of the 16 | # exported API, or moved to Autoconf or Automake where they belong. 17 | # 18 | # The trouble is, aclocal is a bit thick. It'll see the old AC_DEFUN 19 | # in /usr/share/aclocal/libtool.m4 and remember it, then when it sees us 20 | # using a macro with the same name in our local m4/libtool.m4 it'll 21 | # pull the old libtool.m4 in (it doesn't see our shiny new m4_define 22 | # and doesn't know about Autoconf macros at all.) 23 | # 24 | # So we provide this file, which has a silly filename so it's always 25 | # included after everything else. This provides aclocal with the 26 | # AC_DEFUNs it wants, but when m4 processes it, it doesn't do anything 27 | # because those macros already exist, or will be overwritten later. 28 | # We use AC_DEFUN over AU_DEFUN for compatibility with aclocal-1.6. 29 | # 30 | # Anytime we withdraw an AC_DEFUN or AU_DEFUN, remember to add it here. 31 | # Yes, that means every name once taken will need to remain here until 32 | # we give up compatibility with versions before 1.7, at which point 33 | # we need to keep only those names which we still refer to. 34 | 35 | # This is to help aclocal find these macros, as it can't see m4_define. 36 | AC_DEFUN([LTOBSOLETE_VERSION], [m4_if([1])]) 37 | 38 | m4_ifndef([AC_LIBTOOL_LINKER_OPTION], [AC_DEFUN([AC_LIBTOOL_LINKER_OPTION])]) 39 | m4_ifndef([AC_PROG_EGREP], [AC_DEFUN([AC_PROG_EGREP])]) 40 | m4_ifndef([_LT_AC_PROG_ECHO_BACKSLASH], [AC_DEFUN([_LT_AC_PROG_ECHO_BACKSLASH])]) 41 | m4_ifndef([_LT_AC_SHELL_INIT], [AC_DEFUN([_LT_AC_SHELL_INIT])]) 42 | m4_ifndef([_LT_AC_SYS_LIBPATH_AIX], [AC_DEFUN([_LT_AC_SYS_LIBPATH_AIX])]) 43 | m4_ifndef([_LT_PROG_LTMAIN], [AC_DEFUN([_LT_PROG_LTMAIN])]) 44 | m4_ifndef([_LT_AC_TAGVAR], [AC_DEFUN([_LT_AC_TAGVAR])]) 45 | m4_ifndef([AC_LTDL_ENABLE_INSTALL], [AC_DEFUN([AC_LTDL_ENABLE_INSTALL])]) 46 | m4_ifndef([AC_LTDL_PREOPEN], [AC_DEFUN([AC_LTDL_PREOPEN])]) 47 | m4_ifndef([_LT_AC_SYS_COMPILER], [AC_DEFUN([_LT_AC_SYS_COMPILER])]) 48 | m4_ifndef([_LT_AC_LOCK], [AC_DEFUN([_LT_AC_LOCK])]) 49 | m4_ifndef([AC_LIBTOOL_SYS_OLD_ARCHIVE], [AC_DEFUN([AC_LIBTOOL_SYS_OLD_ARCHIVE])]) 50 | m4_ifndef([_LT_AC_TRY_DLOPEN_SELF], [AC_DEFUN([_LT_AC_TRY_DLOPEN_SELF])]) 51 | m4_ifndef([AC_LIBTOOL_PROG_CC_C_O], [AC_DEFUN([AC_LIBTOOL_PROG_CC_C_O])]) 52 | m4_ifndef([AC_LIBTOOL_SYS_HARD_LINK_LOCKS], [AC_DEFUN([AC_LIBTOOL_SYS_HARD_LINK_LOCKS])]) 53 | m4_ifndef([AC_LIBTOOL_OBJDIR], [AC_DEFUN([AC_LIBTOOL_OBJDIR])]) 54 | m4_ifndef([AC_LTDL_OBJDIR], [AC_DEFUN([AC_LTDL_OBJDIR])]) 55 | m4_ifndef([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH], [AC_DEFUN([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH])]) 56 | m4_ifndef([AC_LIBTOOL_SYS_LIB_STRIP], [AC_DEFUN([AC_LIBTOOL_SYS_LIB_STRIP])]) 57 | m4_ifndef([AC_PATH_MAGIC], [AC_DEFUN([AC_PATH_MAGIC])]) 58 | m4_ifndef([AC_PROG_LD_GNU], [AC_DEFUN([AC_PROG_LD_GNU])]) 59 | m4_ifndef([AC_PROG_LD_RELOAD_FLAG], [AC_DEFUN([AC_PROG_LD_RELOAD_FLAG])]) 60 | m4_ifndef([AC_DEPLIBS_CHECK_METHOD], [AC_DEFUN([AC_DEPLIBS_CHECK_METHOD])]) 61 | m4_ifndef([AC_LIBTOOL_PROG_COMPILER_NO_RTTI], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_NO_RTTI])]) 62 | m4_ifndef([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE], [AC_DEFUN([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE])]) 63 | m4_ifndef([AC_LIBTOOL_PROG_COMPILER_PIC], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_PIC])]) 64 | m4_ifndef([AC_LIBTOOL_PROG_LD_SHLIBS], [AC_DEFUN([AC_LIBTOOL_PROG_LD_SHLIBS])]) 65 | m4_ifndef([AC_LIBTOOL_POSTDEP_PREDEP], [AC_DEFUN([AC_LIBTOOL_POSTDEP_PREDEP])]) 66 | m4_ifndef([LT_AC_PROG_EGREP], [AC_DEFUN([LT_AC_PROG_EGREP])]) 67 | m4_ifndef([LT_AC_PROG_SED], [AC_DEFUN([LT_AC_PROG_SED])]) 68 | m4_ifndef([_LT_CC_BASENAME], [AC_DEFUN([_LT_CC_BASENAME])]) 69 | m4_ifndef([_LT_COMPILER_BOILERPLATE], [AC_DEFUN([_LT_COMPILER_BOILERPLATE])]) 70 | m4_ifndef([_LT_LINKER_BOILERPLATE], [AC_DEFUN([_LT_LINKER_BOILERPLATE])]) 71 | m4_ifndef([_AC_PROG_LIBTOOL], [AC_DEFUN([_AC_PROG_LIBTOOL])]) 72 | m4_ifndef([AC_LIBTOOL_SETUP], [AC_DEFUN([AC_LIBTOOL_SETUP])]) 73 | m4_ifndef([_LT_AC_CHECK_DLFCN], [AC_DEFUN([_LT_AC_CHECK_DLFCN])]) 74 | m4_ifndef([AC_LIBTOOL_SYS_DYNAMIC_LINKER], [AC_DEFUN([AC_LIBTOOL_SYS_DYNAMIC_LINKER])]) 75 | m4_ifndef([_LT_AC_TAGCONFIG], [AC_DEFUN([_LT_AC_TAGCONFIG])]) 76 | m4_ifndef([AC_DISABLE_FAST_INSTALL], [AC_DEFUN([AC_DISABLE_FAST_INSTALL])]) 77 | m4_ifndef([_LT_AC_LANG_CXX], [AC_DEFUN([_LT_AC_LANG_CXX])]) 78 | m4_ifndef([_LT_AC_LANG_F77], [AC_DEFUN([_LT_AC_LANG_F77])]) 79 | m4_ifndef([_LT_AC_LANG_GCJ], [AC_DEFUN([_LT_AC_LANG_GCJ])]) 80 | m4_ifndef([AC_LIBTOOL_LANG_C_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_C_CONFIG])]) 81 | m4_ifndef([_LT_AC_LANG_C_CONFIG], [AC_DEFUN([_LT_AC_LANG_C_CONFIG])]) 82 | m4_ifndef([AC_LIBTOOL_LANG_CXX_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_CXX_CONFIG])]) 83 | m4_ifndef([_LT_AC_LANG_CXX_CONFIG], [AC_DEFUN([_LT_AC_LANG_CXX_CONFIG])]) 84 | m4_ifndef([AC_LIBTOOL_LANG_F77_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_F77_CONFIG])]) 85 | m4_ifndef([_LT_AC_LANG_F77_CONFIG], [AC_DEFUN([_LT_AC_LANG_F77_CONFIG])]) 86 | m4_ifndef([AC_LIBTOOL_LANG_GCJ_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_GCJ_CONFIG])]) 87 | m4_ifndef([_LT_AC_LANG_GCJ_CONFIG], [AC_DEFUN([_LT_AC_LANG_GCJ_CONFIG])]) 88 | m4_ifndef([AC_LIBTOOL_LANG_RC_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_RC_CONFIG])]) 89 | m4_ifndef([_LT_AC_LANG_RC_CONFIG], [AC_DEFUN([_LT_AC_LANG_RC_CONFIG])]) 90 | m4_ifndef([AC_LIBTOOL_CONFIG], [AC_DEFUN([AC_LIBTOOL_CONFIG])]) 91 | m4_ifndef([_LT_AC_FILE_LTDLL_C], [AC_DEFUN([_LT_AC_FILE_LTDLL_C])]) 92 | m4_ifndef([_LT_REQUIRED_DARWIN_CHECKS], [AC_DEFUN([_LT_REQUIRED_DARWIN_CHECKS])]) 93 | m4_ifndef([_LT_AC_PROG_CXXCPP], [AC_DEFUN([_LT_AC_PROG_CXXCPP])]) 94 | m4_ifndef([_LT_PREPARE_SED_QUOTE_VARS], [AC_DEFUN([_LT_PREPARE_SED_QUOTE_VARS])]) 95 | m4_ifndef([_LT_PROG_ECHO_BACKSLASH], [AC_DEFUN([_LT_PROG_ECHO_BACKSLASH])]) 96 | m4_ifndef([_LT_PROG_F77], [AC_DEFUN([_LT_PROG_F77])]) 97 | m4_ifndef([_LT_PROG_FC], [AC_DEFUN([_LT_PROG_FC])]) 98 | m4_ifndef([_LT_PROG_CXX], [AC_DEFUN([_LT_PROG_CXX])]) 99 | -------------------------------------------------------------------------------- /contrib/Kobil_mIDentity_switch/Kobil_mIDentity_switch.c: -------------------------------------------------------------------------------- 1 | /* 2 | Activate the smartcard interface on the kobil midentity usb device 3 | Copyright (C) 2006 Norbert Federa 4 | 5 | This program is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 | 19 | Author: Norbert Federa 20 | Date: 2006-04-06 21 | 22 | 23 | Description: 24 | 25 | This tool is needed to activate the smartcard interface on the kobil midentity 26 | usb device (vendor 0x04D6 id 0x4081) 27 | 28 | Kobil's own implementation was a kernel usb driver which did just send a 29 | libusb_control_transfer in the probe routine. 30 | 31 | We do the same via libusb and call this program from our /sbin/hotblug script 32 | if the mIDentity gets added. 33 | 34 | The kobil switcher driver was found inside this zip ... 35 | http://www.kobil.com/download/partner/KOBIL_mIDentity_SDK_Build_20060320_RELEASE.zip 36 | ... under Interfaces/Linux/module_with_binary_final.tar.gz. 37 | 38 | Here the interesting part of the kernel driver inside the probe function: 39 | 40 | if (dev->descriptor.idVendor == KOBIL_VENDOR_ID){ 41 | printk("!!!!! DEVICE FOUND !!! !\n"); 42 | ret = libusb_control_transfer(dev, 43 | send_pipe, 44 | 0x09, 45 | 0x22, 46 | 0x0200, 47 | 0x0001, 48 | switchCmd, 49 | sizeof(switchCmd), 50 | 5000); 51 | } 52 | 53 | Initally the it did not work with libusb because the ioctl gets ignored with 54 | the used RequestType of 0x22 in combination with index 0x0001, but index 0x0002 55 | worked. See usb/devio.c functions proc_control() -> check_ctrlrecip() -> 56 | findintfep() in order to understand why. 57 | */ 58 | 59 | #include 60 | #include 61 | #include 62 | #include 63 | #include 64 | #include 65 | 66 | #include "config.h" 67 | 68 | #define KOBIL_VENDOR_ID 0x0D46 69 | #define MID_DEVICE_ID 0x4081 70 | #define KOBIL_TIMEOUT 5000 71 | #define VAL_STARTUP_4080 1 72 | #define VAL_STARTUP_4000 2 73 | #define VAL_STARTUP_4020 3 74 | #define VAL_STARTUP_40A0 4 75 | #define HIDCMD_SWITCH_DEVICE 0x0004 76 | 77 | #define bmRequestType 0x22 78 | #define bRequest 0x09 79 | #define wValue 0x0200 80 | #define wIndex 0x0002 /* this was originally 0x0001 */ 81 | 82 | 83 | static int kobil_midentity_control_msg(libusb_device_handle *usb) 84 | { 85 | int ret; 86 | 87 | unsigned char switchCmd[10]; 88 | 89 | unsigned char Sleep = 1; 90 | unsigned char hardDisk = 1; 91 | 92 | unsigned char param = ((hardDisk) << 4) | (Sleep); 93 | 94 | memset(switchCmd, 0x0, sizeof(switchCmd)); 95 | switchCmd[0] = HIDCMD_SWITCH_DEVICE >> 8; 96 | switchCmd[1] = HIDCMD_SWITCH_DEVICE; 97 | switchCmd[5] = VAL_STARTUP_4000; 98 | switchCmd[9] = param; 99 | 100 | ret = libusb_control_transfer(usb, bmRequestType, bRequest, wValue, wIndex, 101 | switchCmd, sizeof(switchCmd), KOBIL_TIMEOUT); 102 | 103 | return(!(ret==sizeof(switchCmd))); 104 | } 105 | 106 | 107 | static int kobil_midentity_claim_interface(libusb_device_handle *usb, int ifnum) 108 | { 109 | int rv; 110 | 111 | printf("claiming interface #%d ... ", ifnum); 112 | rv = libusb_claim_interface(usb, ifnum); 113 | if (rv == 0) 114 | { 115 | printf("success\n"); 116 | return rv; 117 | } 118 | else 119 | printf("failed\n"); 120 | 121 | printf("failed with error %d, trying to detach kernel driver ....\n", rv); 122 | rv = libusb_detach_kernel_driver(usb, ifnum); 123 | if (rv == 0) 124 | { 125 | printf("success, claiming interface again ..."); 126 | rv = libusb_claim_interface(usb, ifnum); 127 | if (rv == 0) 128 | { 129 | printf("success\n"); 130 | return rv; 131 | } 132 | else 133 | printf("failed\n"); 134 | } 135 | 136 | printf("failed with error %d, giving up.\n", rv); 137 | return rv; 138 | } 139 | 140 | 141 | int main(int argc, char *argv[]) 142 | { 143 | libusb_device **devs, *dev; 144 | libusb_device *found_dev = NULL; 145 | struct libusb_device_handle *usb = NULL; 146 | int rv, i; 147 | ssize_t cnt; 148 | 149 | (void)argc; 150 | (void)argv; 151 | 152 | rv = libusb_init(NULL); 153 | if (rv < 0) 154 | { 155 | (void)printf("libusb_init() failed\n"); 156 | return rv; 157 | } 158 | 159 | cnt = libusb_get_device_list(NULL, &devs); 160 | if (cnt < 0) 161 | { 162 | (void)printf("libusb_get_device_list() failed\n"); 163 | return (int)cnt; 164 | } 165 | 166 | /* for every device */ 167 | i = 0; 168 | while ((dev = devs[i++]) != NULL) 169 | { 170 | struct libusb_device_descriptor desc; 171 | 172 | rv = libusb_get_device_descriptor(dev, &desc); 173 | if (rv < 0) { 174 | (void)printf("failed to get device descriptor\n"); 175 | continue; 176 | } 177 | 178 | printf("vendor/product: %04X %04X\n", desc.idVendor, desc.idProduct); 179 | if (desc.idVendor == KOBIL_VENDOR_ID && desc.idProduct == MID_DEVICE_ID) 180 | found_dev = dev; 181 | } 182 | 183 | if (found_dev == NULL) 184 | { 185 | printf("device not found. aborting.\n"); 186 | if (0 != geteuid()) 187 | printf("Try to rerun this program as root.\n"); 188 | exit(1); 189 | } 190 | 191 | printf("Device found, opening ... "); 192 | rv = libusb_open(found_dev, &usb); 193 | if (rv < 0) 194 | { 195 | printf("failed, aborting.\n"); 196 | exit(2); 197 | } 198 | printf("success\n"); 199 | 200 | rv = kobil_midentity_claim_interface(usb, 0); 201 | if (rv < 0) 202 | { 203 | libusb_close(usb); 204 | exit(3); 205 | } 206 | 207 | rv = kobil_midentity_claim_interface(usb, 1); 208 | if (rv < 0) 209 | { 210 | libusb_close(usb); 211 | exit(3); 212 | } 213 | 214 | printf("Activating the CCID configuration .... "); 215 | rv = kobil_midentity_control_msg(usb); 216 | if (rv == 0) 217 | printf("success\n"); 218 | else 219 | printf("failed with error %d, giving up.\n", rv); 220 | 221 | libusb_close(usb); 222 | 223 | return 0; 224 | } 225 | 226 | -------------------------------------------------------------------------------- /ar-lib: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # Wrapper for Microsoft lib.exe 3 | 4 | me=ar-lib 5 | scriptversion=2012-03-01.08; # UTC 6 | 7 | # Copyright (C) 2010-2013 Free Software Foundation, Inc. 8 | # Written by Peter Rosin . 9 | # 10 | # This program is free software; you can redistribute it and/or modify 11 | # it under the terms of the GNU General Public License as published by 12 | # the Free Software Foundation; either version 2, or (at your option) 13 | # any later version. 14 | # 15 | # This program is distributed in the hope that it will be useful, 16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | # GNU General Public License for more details. 19 | # 20 | # You should have received a copy of the GNU General Public License 21 | # along with this program. If not, see . 22 | 23 | # As a special exception to the GNU General Public License, if you 24 | # distribute this file as part of a program that contains a 25 | # configuration script generated by Autoconf, you may include it under 26 | # the same distribution terms that you use for the rest of that program. 27 | 28 | # This file is maintained in Automake, please report 29 | # bugs to or send patches to 30 | # . 31 | 32 | 33 | # func_error message 34 | func_error () 35 | { 36 | echo "$me: $1" 1>&2 37 | exit 1 38 | } 39 | 40 | file_conv= 41 | 42 | # func_file_conv build_file 43 | # Convert a $build file to $host form and store it in $file 44 | # Currently only supports Windows hosts. 45 | func_file_conv () 46 | { 47 | file=$1 48 | case $file in 49 | / | /[!/]*) # absolute file, and not a UNC file 50 | if test -z "$file_conv"; then 51 | # lazily determine how to convert abs files 52 | case `uname -s` in 53 | MINGW*) 54 | file_conv=mingw 55 | ;; 56 | CYGWIN*) 57 | file_conv=cygwin 58 | ;; 59 | *) 60 | file_conv=wine 61 | ;; 62 | esac 63 | fi 64 | case $file_conv in 65 | mingw) 66 | file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 67 | ;; 68 | cygwin) 69 | file=`cygpath -m "$file" || echo "$file"` 70 | ;; 71 | wine) 72 | file=`winepath -w "$file" || echo "$file"` 73 | ;; 74 | esac 75 | ;; 76 | esac 77 | } 78 | 79 | # func_at_file at_file operation archive 80 | # Iterate over all members in AT_FILE performing OPERATION on ARCHIVE 81 | # for each of them. 82 | # When interpreting the content of the @FILE, do NOT use func_file_conv, 83 | # since the user would need to supply preconverted file names to 84 | # binutils ar, at least for MinGW. 85 | func_at_file () 86 | { 87 | operation=$2 88 | archive=$3 89 | at_file_contents=`cat "$1"` 90 | eval set x "$at_file_contents" 91 | shift 92 | 93 | for member 94 | do 95 | $AR -NOLOGO $operation:"$member" "$archive" || exit $? 96 | done 97 | } 98 | 99 | case $1 in 100 | '') 101 | func_error "no command. Try '$0 --help' for more information." 102 | ;; 103 | -h | --h*) 104 | cat < 8 | * Copyright (C) 2003-2010 9 | * Ludovic Rousseau 10 | * 11 | Redistribution and use in source and binary forms, with or without 12 | modification, are permitted provided that the following conditions 13 | are met: 14 | 15 | 1. Redistributions of source code must retain the above copyright 16 | notice, this list of conditions and the following disclaimer. 17 | 2. Redistributions in binary form must reproduce the above copyright 18 | notice, this list of conditions and the following disclaimer in the 19 | documentation and/or other materials provided with the distribution. 20 | 3. The name of the author may not be used to endorse or promote products 21 | derived from this software without specific prior written permission. 22 | 23 | Changes to this license can be made only by the copyright author with 24 | explicit written consent. 25 | 26 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 27 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 28 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 29 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 30 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 31 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 35 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | * 37 | * $Id: tokenparser.l 6851 2014-02-14 15:43:32Z rousseau $ 38 | */ 39 | 40 | /** 41 | * @file 42 | * @brief provides parsing functions for Info.plist files 43 | * platforms 44 | */ 45 | 46 | %{ 47 | 48 | #include "config.h" 49 | #include 50 | #include 51 | #include 52 | #ifndef NDEBUG 53 | #define NDEBUG 54 | #endif 55 | #include 56 | 57 | #include "simclist.h" 58 | #include "debuglog.h" 59 | #include "parser.h" 60 | #include "strlcpycat.h" 61 | 62 | static void eval_key(char *pcToken, list_t *list_key); 63 | static void eval_value(char *pcToken, list_t *list_values); 64 | void tperrorCheck (char *pcToken_error); 65 | 66 | static list_t *ListKeys; 67 | static list_t *ListValues; 68 | 69 | %} 70 | 71 | %option nounput 72 | %option noinput 73 | %option noyywrap 74 | 75 | %% 76 | 77 | #.* {} 78 | "\n" {} 79 | \([A-Z]|[a-z]|[0-9]|[ \t])+\<\/key\> { eval_key(yytext, ListKeys); } 80 | [ \t] {} 81 | \([A-Z]|[a-z]|[0-9]|[ \t]|[!@#$%^&*()\-+/_\:?.,=~'";\[\]])+\<\/string\> { eval_value(yytext, ListValues); } 82 | . { tperrorCheck(yytext); } 83 | %% 84 | 85 | 86 | static void eval_key(char *pcToken, list_t *list_key) 87 | { 88 | struct bundleElt *elt; 89 | int r; 90 | size_t len; 91 | 92 | /* create a new list element */ 93 | elt = malloc(sizeof(*elt)); 94 | assert(elt); 95 | 96 | /* foobar 97 | * 012345 : 5 is the first key character index */ 98 | 99 | /* calculate the argument length */ 100 | for (len=0; pcToken[len+5] != '<'; len++) 101 | ; 102 | len++; /* final NULL byte */ 103 | 104 | elt->key = malloc(len); 105 | (void)strlcpy(elt->key, &pcToken[5], len); 106 | 107 | r = list_init(&elt->values); 108 | assert(r >= 0); 109 | (void)r; 110 | 111 | /* add the key/values */ 112 | list_append(list_key, elt); 113 | 114 | /* set the list to store the values */ 115 | ListValues = &elt->values; 116 | } 117 | 118 | static void eval_value(char *pcToken, list_t *list_values) 119 | { 120 | int r; 121 | size_t len; 122 | char *value; 123 | char *amp; 124 | 125 | /* foobar 126 | * 012345678 : 8 is the first string character index */ 127 | 128 | /* calculate the argument length */ 129 | for (len=0; pcToken[len+8] != '<'; len++) 130 | ; 131 | len++; /* final NULL byte */ 132 | 133 | value = malloc(len); 134 | assert(value); 135 | 136 | (void)strlcpy(value, &pcToken[8], len); 137 | 138 | /* for all & in the string */ 139 | amp = value; 140 | while ((amp = strstr(amp, "&")) != NULL) 141 | { 142 | char *p; 143 | 144 | /* just skip "amp;" substring (4 letters) */ 145 | for (p = amp+1; *(p+4); p++) 146 | { 147 | *p = *(p+4); 148 | } 149 | /* terminate the now shorter string */ 150 | *p = '\0'; 151 | 152 | /* skip the & and continue */ 153 | amp++; 154 | } 155 | 156 | r = list_append(list_values, value); 157 | assert(r >= 0); 158 | (void)r; 159 | } 160 | 161 | void tperrorCheck (char *token_error) 162 | { 163 | (void)token_error; 164 | } 165 | 166 | /** 167 | * Find an optional key in a configuration file 168 | * No error is logged if the key is not found 169 | * 170 | * @param l list generated by bundleParse() 171 | * @param key searched key 172 | * @param[out] values list of token value (if key found) 173 | * @retval 0 OK 174 | * @retval 1 key not found 175 | */ 176 | int LTPBundleFindValueWithKey(list_t *l, const char *key, list_t **values) 177 | { 178 | unsigned int i; 179 | int ret = 1; 180 | 181 | for (i=0; i < list_size(l); i++) 182 | { 183 | struct bundleElt *elt; 184 | 185 | elt = list_get_at(l, i); 186 | assert(elt); 187 | 188 | if (0 == strcmp(elt->key, key)) 189 | { 190 | *values = &elt->values; 191 | ret = 0; 192 | } 193 | } 194 | 195 | return ret; 196 | } 197 | 198 | 199 | /** 200 | * Parse a Info.plist file and file a list 201 | * 202 | * @param fileName file name 203 | * @param l list containing the results 204 | * @retval -1 configuration file not found 205 | * @retval 0 OK 206 | */ 207 | int bundleParse(const char *fileName, list_t *l) 208 | { 209 | FILE *file = NULL; 210 | int r; 211 | #ifndef NDEBUG 212 | int i; 213 | #endif 214 | 215 | file = fopen(fileName, "r"); 216 | if (!file) 217 | { 218 | Log3(PCSC_LOG_CRITICAL, "Could not open bundle file %s: %s", 219 | fileName, strerror(errno)); 220 | return 1; 221 | } 222 | 223 | r = list_init(l); 224 | assert(r >= 0); 225 | (void)r; 226 | 227 | ListKeys = l; 228 | yyin = file; 229 | 230 | do 231 | { 232 | (void)yylex(); 233 | } while (!feof(file)); 234 | yylex_destroy(); 235 | 236 | (void)fclose(file); 237 | 238 | #ifndef NDEBUG 239 | printf("size: %d\n", list_size(l)); 240 | for (i=0; i < list_size(l); i++) 241 | { 242 | struct bundleElt *elt; 243 | unsigned int j; 244 | 245 | elt = list_get_at(l, i); 246 | assert(elt); 247 | printf("Key: %s\n", elt->key); 248 | 249 | for (j=0; jvalues); j++) 250 | { 251 | char *v = list_get_at(&elt->values, j); 252 | printf(" value: %s\n", v); 253 | } 254 | } 255 | #endif 256 | 257 | return 0; 258 | } 259 | 260 | /** 261 | * Free the list created by bundleParse() 262 | * 263 | * @param l list containing the results 264 | */ 265 | void bundleRelease(list_t *l) 266 | { 267 | unsigned int i; 268 | 269 | for (i=0; i < list_size(l); i++) 270 | { 271 | struct bundleElt *elt; 272 | unsigned int j; 273 | 274 | elt = list_get_at(l, i); 275 | assert(elt); 276 | 277 | /* free all the values */ 278 | for (j=0; jvalues); j++) 279 | free(list_get_at(&elt->values, j)); 280 | list_destroy(&elt->values); 281 | 282 | /* free the key */ 283 | free(elt->key); 284 | free(elt); 285 | } 286 | 287 | list_destroy(l); 288 | } 289 | -------------------------------------------------------------------------------- /missing: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # Common wrapper for a few potentially missing GNU programs. 3 | 4 | scriptversion=2013-10-28.13; # UTC 5 | 6 | # Copyright (C) 1996-2013 Free Software Foundation, Inc. 7 | # Originally written by Fran,cois Pinard , 1996. 8 | 9 | # This program is free software; you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation; either version 2, or (at your option) 12 | # any later version. 13 | 14 | # This program is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | 19 | # You should have received a copy of the GNU General Public License 20 | # along with this program. If not, see . 21 | 22 | # As a special exception to the GNU General Public License, if you 23 | # distribute this file as part of a program that contains a 24 | # configuration script generated by Autoconf, you may include it under 25 | # the same distribution terms that you use for the rest of that program. 26 | 27 | if test $# -eq 0; then 28 | echo 1>&2 "Try '$0 --help' for more information" 29 | exit 1 30 | fi 31 | 32 | case $1 in 33 | 34 | --is-lightweight) 35 | # Used by our autoconf macros to check whether the available missing 36 | # script is modern enough. 37 | exit 0 38 | ;; 39 | 40 | --run) 41 | # Back-compat with the calling convention used by older automake. 42 | shift 43 | ;; 44 | 45 | -h|--h|--he|--hel|--help) 46 | echo "\ 47 | $0 [OPTION]... PROGRAM [ARGUMENT]... 48 | 49 | Run 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due 50 | to PROGRAM being missing or too old. 51 | 52 | Options: 53 | -h, --help display this help and exit 54 | -v, --version output version information and exit 55 | 56 | Supported PROGRAM values: 57 | aclocal autoconf autoheader autom4te automake makeinfo 58 | bison yacc flex lex help2man 59 | 60 | Version suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and 61 | 'g' are ignored when checking the name. 62 | 63 | Send bug reports to ." 64 | exit $? 65 | ;; 66 | 67 | -v|--v|--ve|--ver|--vers|--versi|--versio|--version) 68 | echo "missing $scriptversion (GNU Automake)" 69 | exit $? 70 | ;; 71 | 72 | -*) 73 | echo 1>&2 "$0: unknown '$1' option" 74 | echo 1>&2 "Try '$0 --help' for more information" 75 | exit 1 76 | ;; 77 | 78 | esac 79 | 80 | # Run the given program, remember its exit status. 81 | "$@"; st=$? 82 | 83 | # If it succeeded, we are done. 84 | test $st -eq 0 && exit 0 85 | 86 | # Also exit now if we it failed (or wasn't found), and '--version' was 87 | # passed; such an option is passed most likely to detect whether the 88 | # program is present and works. 89 | case $2 in --version|--help) exit $st;; esac 90 | 91 | # Exit code 63 means version mismatch. This often happens when the user 92 | # tries to use an ancient version of a tool on a file that requires a 93 | # minimum version. 94 | if test $st -eq 63; then 95 | msg="probably too old" 96 | elif test $st -eq 127; then 97 | # Program was missing. 98 | msg="missing on your system" 99 | else 100 | # Program was found and executed, but failed. Give up. 101 | exit $st 102 | fi 103 | 104 | perl_URL=http://www.perl.org/ 105 | flex_URL=http://flex.sourceforge.net/ 106 | gnu_software_URL=http://www.gnu.org/software 107 | 108 | program_details () 109 | { 110 | case $1 in 111 | aclocal|automake) 112 | echo "The '$1' program is part of the GNU Automake package:" 113 | echo "<$gnu_software_URL/automake>" 114 | echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:" 115 | echo "<$gnu_software_URL/autoconf>" 116 | echo "<$gnu_software_URL/m4/>" 117 | echo "<$perl_URL>" 118 | ;; 119 | autoconf|autom4te|autoheader) 120 | echo "The '$1' program is part of the GNU Autoconf package:" 121 | echo "<$gnu_software_URL/autoconf/>" 122 | echo "It also requires GNU m4 and Perl in order to run:" 123 | echo "<$gnu_software_URL/m4/>" 124 | echo "<$perl_URL>" 125 | ;; 126 | esac 127 | } 128 | 129 | give_advice () 130 | { 131 | # Normalize program name to check for. 132 | normalized_program=`echo "$1" | sed ' 133 | s/^gnu-//; t 134 | s/^gnu//; t 135 | s/^g//; t'` 136 | 137 | printf '%s\n' "'$1' is $msg." 138 | 139 | configure_deps="'configure.ac' or m4 files included by 'configure.ac'" 140 | case $normalized_program in 141 | autoconf*) 142 | echo "You should only need it if you modified 'configure.ac'," 143 | echo "or m4 files included by it." 144 | program_details 'autoconf' 145 | ;; 146 | autoheader*) 147 | echo "You should only need it if you modified 'acconfig.h' or" 148 | echo "$configure_deps." 149 | program_details 'autoheader' 150 | ;; 151 | automake*) 152 | echo "You should only need it if you modified 'Makefile.am' or" 153 | echo "$configure_deps." 154 | program_details 'automake' 155 | ;; 156 | aclocal*) 157 | echo "You should only need it if you modified 'acinclude.m4' or" 158 | echo "$configure_deps." 159 | program_details 'aclocal' 160 | ;; 161 | autom4te*) 162 | echo "You might have modified some maintainer files that require" 163 | echo "the 'autom4te' program to be rebuilt." 164 | program_details 'autom4te' 165 | ;; 166 | bison*|yacc*) 167 | echo "You should only need it if you modified a '.y' file." 168 | echo "You may want to install the GNU Bison package:" 169 | echo "<$gnu_software_URL/bison/>" 170 | ;; 171 | lex*|flex*) 172 | echo "You should only need it if you modified a '.l' file." 173 | echo "You may want to install the Fast Lexical Analyzer package:" 174 | echo "<$flex_URL>" 175 | ;; 176 | help2man*) 177 | echo "You should only need it if you modified a dependency" \ 178 | "of a man page." 179 | echo "You may want to install the GNU Help2man package:" 180 | echo "<$gnu_software_URL/help2man/>" 181 | ;; 182 | makeinfo*) 183 | echo "You should only need it if you modified a '.texi' file, or" 184 | echo "any other file indirectly affecting the aspect of the manual." 185 | echo "You might want to install the Texinfo package:" 186 | echo "<$gnu_software_URL/texinfo/>" 187 | echo "The spurious makeinfo call might also be the consequence of" 188 | echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might" 189 | echo "want to install GNU make:" 190 | echo "<$gnu_software_URL/make/>" 191 | ;; 192 | *) 193 | echo "You might have modified some files without having the proper" 194 | echo "tools for further handling them. Check the 'README' file, it" 195 | echo "often tells you about the needed prerequisites for installing" 196 | echo "this package. You may also peek at any GNU archive site, in" 197 | echo "case some other package contains this missing '$1' program." 198 | ;; 199 | esac 200 | } 201 | 202 | give_advice "$1" | sed -e '1s/^/WARNING: /' \ 203 | -e '2,$s/^/ /' >&2 204 | 205 | # Propagate the correct exit status (expected to be 127 for a program 206 | # not found, 63 for a program that failed due to version mismatch). 207 | exit $st 208 | 209 | # Local variables: 210 | # eval: (add-hook 'write-file-hooks 'time-stamp) 211 | # time-stamp-start: "scriptversion=" 212 | # time-stamp-format: "%:y-%02m-%02d.%02H" 213 | # time-stamp-time-zone: "UTC" 214 | # time-stamp-end: "; # UTC" 215 | # End: 216 | -------------------------------------------------------------------------------- /ylwrap: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # ylwrap - wrapper for lex/yacc invocations. 3 | 4 | scriptversion=2013-01-12.17; # UTC 5 | 6 | # Copyright (C) 1996-2013 Free Software Foundation, Inc. 7 | # 8 | # Written by Tom Tromey . 9 | # 10 | # This program is free software; you can redistribute it and/or modify 11 | # it under the terms of the GNU General Public License as published by 12 | # the Free Software Foundation; either version 2, or (at your option) 13 | # any later version. 14 | # 15 | # This program is distributed in the hope that it will be useful, 16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 | # GNU General Public License for more details. 19 | # 20 | # You should have received a copy of the GNU General Public License 21 | # along with this program. If not, see . 22 | 23 | # As a special exception to the GNU General Public License, if you 24 | # distribute this file as part of a program that contains a 25 | # configuration script generated by Autoconf, you may include it under 26 | # the same distribution terms that you use for the rest of that program. 27 | 28 | # This file is maintained in Automake, please report 29 | # bugs to or send patches to 30 | # . 31 | 32 | get_dirname () 33 | { 34 | case $1 in 35 | */*|*\\*) printf '%s\n' "$1" | sed -e 's|\([\\/]\)[^\\/]*$|\1|';; 36 | # Otherwise, we want the empty string (not "."). 37 | esac 38 | } 39 | 40 | # guard FILE 41 | # ---------- 42 | # The CPP macro used to guard inclusion of FILE. 43 | guard () 44 | { 45 | printf '%s\n' "$1" \ 46 | | sed \ 47 | -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/' \ 48 | -e 's/[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]/_/g' \ 49 | -e 's/__*/_/g' 50 | } 51 | 52 | # quote_for_sed [STRING] 53 | # ---------------------- 54 | # Return STRING (or stdin) quoted to be used as a sed pattern. 55 | quote_for_sed () 56 | { 57 | case $# in 58 | 0) cat;; 59 | 1) printf '%s\n' "$1";; 60 | esac \ 61 | | sed -e 's|[][\\.*]|\\&|g' 62 | } 63 | 64 | case "$1" in 65 | '') 66 | echo "$0: No files given. Try '$0 --help' for more information." 1>&2 67 | exit 1 68 | ;; 69 | --basedir) 70 | basedir=$2 71 | shift 2 72 | ;; 73 | -h|--h*) 74 | cat <<\EOF 75 | Usage: ylwrap [--help|--version] INPUT [OUTPUT DESIRED]... -- PROGRAM [ARGS]... 76 | 77 | Wrapper for lex/yacc invocations, renaming files as desired. 78 | 79 | INPUT is the input file 80 | OUTPUT is one file PROG generates 81 | DESIRED is the file we actually want instead of OUTPUT 82 | PROGRAM is program to run 83 | ARGS are passed to PROG 84 | 85 | Any number of OUTPUT,DESIRED pairs may be used. 86 | 87 | Report bugs to . 88 | EOF 89 | exit $? 90 | ;; 91 | -v|--v*) 92 | echo "ylwrap $scriptversion" 93 | exit $? 94 | ;; 95 | esac 96 | 97 | 98 | # The input. 99 | input=$1 100 | shift 101 | # We'll later need for a correct munging of "#line" directives. 102 | input_sub_rx=`get_dirname "$input" | quote_for_sed` 103 | case $input in 104 | [\\/]* | ?:[\\/]*) 105 | # Absolute path; do nothing. 106 | ;; 107 | *) 108 | # Relative path. Make it absolute. 109 | input=`pwd`/$input 110 | ;; 111 | esac 112 | input_rx=`get_dirname "$input" | quote_for_sed` 113 | 114 | # Since DOS filename conventions don't allow two dots, 115 | # the DOS version of Bison writes out y_tab.c instead of y.tab.c 116 | # and y_tab.h instead of y.tab.h. Test to see if this is the case. 117 | y_tab_nodot=false 118 | if test -f y_tab.c || test -f y_tab.h; then 119 | y_tab_nodot=true 120 | fi 121 | 122 | # The parser itself, the first file, is the destination of the .y.c 123 | # rule in the Makefile. 124 | parser=$1 125 | 126 | # A sed program to s/FROM/TO/g for all the FROM/TO so that, for 127 | # instance, we rename #include "y.tab.h" into #include "parse.h" 128 | # during the conversion from y.tab.c to parse.c. 129 | sed_fix_filenames= 130 | 131 | # Also rename header guards, as Bison 2.7 for instance uses its header 132 | # guard in its implementation file. 133 | sed_fix_header_guards= 134 | 135 | while test $# -ne 0; do 136 | if test x"$1" = x"--"; then 137 | shift 138 | break 139 | fi 140 | from=$1 141 | # Handle y_tab.c and y_tab.h output by DOS 142 | if $y_tab_nodot; then 143 | case $from in 144 | "y.tab.c") from=y_tab.c;; 145 | "y.tab.h") from=y_tab.h;; 146 | esac 147 | fi 148 | shift 149 | to=$1 150 | shift 151 | sed_fix_filenames="${sed_fix_filenames}s|"`quote_for_sed "$from"`"|$to|g;" 152 | sed_fix_header_guards="${sed_fix_header_guards}s|"`guard "$from"`"|"`guard "$to"`"|g;" 153 | done 154 | 155 | # The program to run. 156 | prog=$1 157 | shift 158 | # Make any relative path in $prog absolute. 159 | case $prog in 160 | [\\/]* | ?:[\\/]*) ;; 161 | *[\\/]*) prog=`pwd`/$prog ;; 162 | esac 163 | 164 | dirname=ylwrap$$ 165 | do_exit="cd '`pwd`' && rm -rf $dirname > /dev/null 2>&1;"' (exit $ret); exit $ret' 166 | trap "ret=129; $do_exit" 1 167 | trap "ret=130; $do_exit" 2 168 | trap "ret=141; $do_exit" 13 169 | trap "ret=143; $do_exit" 15 170 | mkdir $dirname || exit 1 171 | 172 | cd $dirname 173 | 174 | case $# in 175 | 0) "$prog" "$input" ;; 176 | *) "$prog" "$@" "$input" ;; 177 | esac 178 | ret=$? 179 | 180 | if test $ret -eq 0; then 181 | for from in * 182 | do 183 | to=`printf '%s\n' "$from" | sed "$sed_fix_filenames"` 184 | if test -f "$from"; then 185 | # If $2 is an absolute path name, then just use that, 186 | # otherwise prepend '../'. 187 | case $to in 188 | [\\/]* | ?:[\\/]*) target=$to;; 189 | *) target=../$to;; 190 | esac 191 | 192 | # Do not overwrite unchanged header files to avoid useless 193 | # recompilations. Always update the parser itself: it is the 194 | # destination of the .y.c rule in the Makefile. Divert the 195 | # output of all other files to a temporary file so we can 196 | # compare them to existing versions. 197 | if test $from != $parser; then 198 | realtarget=$target 199 | target=tmp-`printf '%s\n' "$target" | sed 's|.*[\\/]||g'` 200 | fi 201 | 202 | # Munge "#line" or "#" directives. Don't let the resulting 203 | # debug information point at an absolute srcdir. Use the real 204 | # output file name, not yy.lex.c for instance. Adjust the 205 | # include guards too. 206 | sed -e "/^#/!b" \ 207 | -e "s|$input_rx|$input_sub_rx|" \ 208 | -e "$sed_fix_filenames" \ 209 | -e "$sed_fix_header_guards" \ 210 | "$from" >"$target" || ret=$? 211 | 212 | # Check whether files must be updated. 213 | if test "$from" != "$parser"; then 214 | if test -f "$realtarget" && cmp -s "$realtarget" "$target"; then 215 | echo "$to is unchanged" 216 | rm -f "$target" 217 | else 218 | echo "updating $to" 219 | mv -f "$target" "$realtarget" 220 | fi 221 | fi 222 | else 223 | # A missing file is only an error for the parser. This is a 224 | # blatant hack to let us support using "yacc -d". If -d is not 225 | # specified, don't fail when the header file is "missing". 226 | if test "$from" = "$parser"; then 227 | ret=1 228 | fi 229 | fi 230 | done 231 | fi 232 | 233 | # Remove the directory. 234 | cd .. 235 | rm -rf $dirname 236 | 237 | exit $ret 238 | 239 | # Local Variables: 240 | # mode: shell-script 241 | # sh-indentation: 2 242 | # eval: (add-hook 'write-file-hooks 'time-stamp) 243 | # time-stamp-start: "scriptversion=" 244 | # time-stamp-format: "%:y-%02m-%02d.%02H" 245 | # time-stamp-time-zone: "UTC" 246 | # time-stamp-end: "; # UTC" 247 | # End: 248 | -------------------------------------------------------------------------------- /compile: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # Wrapper for compilers which do not understand '-c -o'. 3 | 4 | scriptversion=2012-10-14.11; # UTC 5 | 6 | # Copyright (C) 1999-2013 Free Software Foundation, Inc. 7 | # Written by Tom Tromey . 8 | # 9 | # This program is free software; you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation; either version 2, or (at your option) 12 | # any later version. 13 | # 14 | # This program is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | # 19 | # You should have received a copy of the GNU General Public License 20 | # along with this program. If not, see . 21 | 22 | # As a special exception to the GNU General Public License, if you 23 | # distribute this file as part of a program that contains a 24 | # configuration script generated by Autoconf, you may include it under 25 | # the same distribution terms that you use for the rest of that program. 26 | 27 | # This file is maintained in Automake, please report 28 | # bugs to or send patches to 29 | # . 30 | 31 | nl=' 32 | ' 33 | 34 | # We need space, tab and new line, in precisely that order. Quoting is 35 | # there to prevent tools from complaining about whitespace usage. 36 | IFS=" "" $nl" 37 | 38 | file_conv= 39 | 40 | # func_file_conv build_file lazy 41 | # Convert a $build file to $host form and store it in $file 42 | # Currently only supports Windows hosts. If the determined conversion 43 | # type is listed in (the comma separated) LAZY, no conversion will 44 | # take place. 45 | func_file_conv () 46 | { 47 | file=$1 48 | case $file in 49 | / | /[!/]*) # absolute file, and not a UNC file 50 | if test -z "$file_conv"; then 51 | # lazily determine how to convert abs files 52 | case `uname -s` in 53 | MINGW*) 54 | file_conv=mingw 55 | ;; 56 | CYGWIN*) 57 | file_conv=cygwin 58 | ;; 59 | *) 60 | file_conv=wine 61 | ;; 62 | esac 63 | fi 64 | case $file_conv/,$2, in 65 | *,$file_conv,*) 66 | ;; 67 | mingw/*) 68 | file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'` 69 | ;; 70 | cygwin/*) 71 | file=`cygpath -m "$file" || echo "$file"` 72 | ;; 73 | wine/*) 74 | file=`winepath -w "$file" || echo "$file"` 75 | ;; 76 | esac 77 | ;; 78 | esac 79 | } 80 | 81 | # func_cl_dashL linkdir 82 | # Make cl look for libraries in LINKDIR 83 | func_cl_dashL () 84 | { 85 | func_file_conv "$1" 86 | if test -z "$lib_path"; then 87 | lib_path=$file 88 | else 89 | lib_path="$lib_path;$file" 90 | fi 91 | linker_opts="$linker_opts -LIBPATH:$file" 92 | } 93 | 94 | # func_cl_dashl library 95 | # Do a library search-path lookup for cl 96 | func_cl_dashl () 97 | { 98 | lib=$1 99 | found=no 100 | save_IFS=$IFS 101 | IFS=';' 102 | for dir in $lib_path $LIB 103 | do 104 | IFS=$save_IFS 105 | if $shared && test -f "$dir/$lib.dll.lib"; then 106 | found=yes 107 | lib=$dir/$lib.dll.lib 108 | break 109 | fi 110 | if test -f "$dir/$lib.lib"; then 111 | found=yes 112 | lib=$dir/$lib.lib 113 | break 114 | fi 115 | if test -f "$dir/lib$lib.a"; then 116 | found=yes 117 | lib=$dir/lib$lib.a 118 | break 119 | fi 120 | done 121 | IFS=$save_IFS 122 | 123 | if test "$found" != yes; then 124 | lib=$lib.lib 125 | fi 126 | } 127 | 128 | # func_cl_wrapper cl arg... 129 | # Adjust compile command to suit cl 130 | func_cl_wrapper () 131 | { 132 | # Assume a capable shell 133 | lib_path= 134 | shared=: 135 | linker_opts= 136 | for arg 137 | do 138 | if test -n "$eat"; then 139 | eat= 140 | else 141 | case $1 in 142 | -o) 143 | # configure might choose to run compile as 'compile cc -o foo foo.c'. 144 | eat=1 145 | case $2 in 146 | *.o | *.[oO][bB][jJ]) 147 | func_file_conv "$2" 148 | set x "$@" -Fo"$file" 149 | shift 150 | ;; 151 | *) 152 | func_file_conv "$2" 153 | set x "$@" -Fe"$file" 154 | shift 155 | ;; 156 | esac 157 | ;; 158 | -I) 159 | eat=1 160 | func_file_conv "$2" mingw 161 | set x "$@" -I"$file" 162 | shift 163 | ;; 164 | -I*) 165 | func_file_conv "${1#-I}" mingw 166 | set x "$@" -I"$file" 167 | shift 168 | ;; 169 | -l) 170 | eat=1 171 | func_cl_dashl "$2" 172 | set x "$@" "$lib" 173 | shift 174 | ;; 175 | -l*) 176 | func_cl_dashl "${1#-l}" 177 | set x "$@" "$lib" 178 | shift 179 | ;; 180 | -L) 181 | eat=1 182 | func_cl_dashL "$2" 183 | ;; 184 | -L*) 185 | func_cl_dashL "${1#-L}" 186 | ;; 187 | -static) 188 | shared=false 189 | ;; 190 | -Wl,*) 191 | arg=${1#-Wl,} 192 | save_ifs="$IFS"; IFS=',' 193 | for flag in $arg; do 194 | IFS="$save_ifs" 195 | linker_opts="$linker_opts $flag" 196 | done 197 | IFS="$save_ifs" 198 | ;; 199 | -Xlinker) 200 | eat=1 201 | linker_opts="$linker_opts $2" 202 | ;; 203 | -*) 204 | set x "$@" "$1" 205 | shift 206 | ;; 207 | *.cc | *.CC | *.cxx | *.CXX | *.[cC]++) 208 | func_file_conv "$1" 209 | set x "$@" -Tp"$file" 210 | shift 211 | ;; 212 | *.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO]) 213 | func_file_conv "$1" mingw 214 | set x "$@" "$file" 215 | shift 216 | ;; 217 | *) 218 | set x "$@" "$1" 219 | shift 220 | ;; 221 | esac 222 | fi 223 | shift 224 | done 225 | if test -n "$linker_opts"; then 226 | linker_opts="-link$linker_opts" 227 | fi 228 | exec "$@" $linker_opts 229 | exit 1 230 | } 231 | 232 | eat= 233 | 234 | case $1 in 235 | '') 236 | echo "$0: No command. Try '$0 --help' for more information." 1>&2 237 | exit 1; 238 | ;; 239 | -h | --h*) 240 | cat <<\EOF 241 | Usage: compile [--help] [--version] PROGRAM [ARGS] 242 | 243 | Wrapper for compilers which do not understand '-c -o'. 244 | Remove '-o dest.o' from ARGS, run PROGRAM with the remaining 245 | arguments, and rename the output as expected. 246 | 247 | If you are trying to build a whole package this is not the 248 | right script to run: please start by reading the file 'INSTALL'. 249 | 250 | Report bugs to . 251 | EOF 252 | exit $? 253 | ;; 254 | -v | --v*) 255 | echo "compile $scriptversion" 256 | exit $? 257 | ;; 258 | cl | *[/\\]cl | cl.exe | *[/\\]cl.exe ) 259 | func_cl_wrapper "$@" # Doesn't return... 260 | ;; 261 | esac 262 | 263 | ofile= 264 | cfile= 265 | 266 | for arg 267 | do 268 | if test -n "$eat"; then 269 | eat= 270 | else 271 | case $1 in 272 | -o) 273 | # configure might choose to run compile as 'compile cc -o foo foo.c'. 274 | # So we strip '-o arg' only if arg is an object. 275 | eat=1 276 | case $2 in 277 | *.o | *.obj) 278 | ofile=$2 279 | ;; 280 | *) 281 | set x "$@" -o "$2" 282 | shift 283 | ;; 284 | esac 285 | ;; 286 | *.c) 287 | cfile=$1 288 | set x "$@" "$1" 289 | shift 290 | ;; 291 | *) 292 | set x "$@" "$1" 293 | shift 294 | ;; 295 | esac 296 | fi 297 | shift 298 | done 299 | 300 | if test -z "$ofile" || test -z "$cfile"; then 301 | # If no '-o' option was seen then we might have been invoked from a 302 | # pattern rule where we don't need one. That is ok -- this is a 303 | # normal compilation that the losing compiler can handle. If no 304 | # '.c' file was seen then we are probably linking. That is also 305 | # ok. 306 | exec "$@" 307 | fi 308 | 309 | # Name of file we expect compiler to create. 310 | cofile=`echo "$cfile" | sed 's|^.*[\\/]||; s|^[a-zA-Z]:||; s/\.c$/.o/'` 311 | 312 | # Create the lock directory. 313 | # Note: use '[/\\:.-]' here to ensure that we don't use the same name 314 | # that we are using for the .o file. Also, base the name on the expected 315 | # object file name, since that is what matters with a parallel build. 316 | lockdir=`echo "$cofile" | sed -e 's|[/\\:.-]|_|g'`.d 317 | while true; do 318 | if mkdir "$lockdir" >/dev/null 2>&1; then 319 | break 320 | fi 321 | sleep 1 322 | done 323 | # FIXME: race condition here if user kills between mkdir and trap. 324 | trap "rmdir '$lockdir'; exit 1" 1 2 15 325 | 326 | # Run the compile. 327 | "$@" 328 | ret=$? 329 | 330 | if test -f "$cofile"; then 331 | test "$cofile" = "$ofile" || mv "$cofile" "$ofile" 332 | elif test -f "${cofile}bj"; then 333 | test "${cofile}bj" = "$ofile" || mv "${cofile}bj" "$ofile" 334 | fi 335 | 336 | rmdir "$lockdir" 337 | exit $ret 338 | 339 | # Local Variables: 340 | # mode: shell-script 341 | # sh-indentation: 2 342 | # eval: (add-hook 'write-file-hooks 'time-stamp) 343 | # time-stamp-start: "scriptversion=" 344 | # time-stamp-format: "%:y-%02m-%02d.%02H" 345 | # time-stamp-time-zone: "UTC" 346 | # time-stamp-end: "; # UTC" 347 | # End: 348 | -------------------------------------------------------------------------------- /src/towitoko/atr.c: -------------------------------------------------------------------------------- 1 | /* 2 | atr.c 3 | ISO 7816 ICC's answer to reset abstract data type implementation 4 | 5 | This file is part of the Unix driver for Towitoko smartcard readers 6 | Copyright (C) 2000 Carlos Prados 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 2 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public License 19 | along with this library; if not, write to the Free Software Foundation, 20 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 21 | */ 22 | 23 | #include "atr.h" 24 | #include 25 | #include 26 | #include "debug.h" 27 | 28 | /* 29 | * Not exported variables definition 30 | */ 31 | 32 | static unsigned 33 | atr_num_ib_table[16] = 34 | { 35 | 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 36 | }; 37 | 38 | /* 39 | * Exported variables definition 40 | */ 41 | 42 | static unsigned 43 | atr_f_table[16] = 44 | { 45 | 372, 372, 558, 744, 1116, 1488, 1860, 0, 0, 512, 768, 1024, 1536, 2048, 0, 0 46 | }; 47 | 48 | static unsigned 49 | atr_d_table[16] = 50 | { 51 | 0, 1, 2, 4, 8, 16, 32, 64, 12, 20, 0, 0, 0, 0, 0, 0 52 | }; 53 | 54 | static unsigned 55 | atr_i_table[4] = 56 | { 57 | 25, 50, 100, 0 58 | }; 59 | 60 | /* 61 | * Exported functions definition 62 | */ 63 | 64 | int 65 | ATR_InitFromArray (ATR_t * atr, const BYTE atr_buffer[ATR_MAX_SIZE], unsigned length) 66 | { 67 | BYTE TDi; 68 | unsigned pointer = 0, pn = 0; 69 | 70 | /* Check size of buffer */ 71 | if (length < 2) 72 | return (ATR_MALFORMED); 73 | 74 | /* Store T0 and TS */ 75 | atr->TS = atr_buffer[0]; 76 | 77 | atr->T0 = TDi = atr_buffer[1]; 78 | pointer = 1; 79 | 80 | /* Store number of historical bytes */ 81 | atr->hbn = TDi & 0x0F; 82 | 83 | /* TCK is not present by default */ 84 | (atr->TCK).present = FALSE; 85 | 86 | /* Extract interface bytes */ 87 | while (pointer < length) 88 | { 89 | /* Check buffer is long enought */ 90 | if (pointer + atr_num_ib_table[(0xF0 & TDi) >> 4] >= length) 91 | { 92 | return (ATR_MALFORMED); 93 | } 94 | /* Check TAi is present */ 95 | if ((TDi | 0xEF) == 0xFF) 96 | { 97 | pointer++; 98 | atr->ib[pn][ATR_INTERFACE_BYTE_TA].value = atr_buffer[pointer]; 99 | atr->ib[pn][ATR_INTERFACE_BYTE_TA].present = TRUE; 100 | } 101 | else 102 | atr->ib[pn][ATR_INTERFACE_BYTE_TA].present = FALSE; 103 | /* Check TBi is present */ 104 | if ((TDi | 0xDF) == 0xFF) 105 | { 106 | pointer++; 107 | atr->ib[pn][ATR_INTERFACE_BYTE_TB].value = atr_buffer[pointer]; 108 | atr->ib[pn][ATR_INTERFACE_BYTE_TB].present = TRUE; 109 | } 110 | else 111 | atr->ib[pn][ATR_INTERFACE_BYTE_TB].present = FALSE; 112 | 113 | /* Check TCi is present */ 114 | if ((TDi | 0xBF) == 0xFF) 115 | { 116 | pointer++; 117 | atr->ib[pn][ATR_INTERFACE_BYTE_TC].value = atr_buffer[pointer]; 118 | atr->ib[pn][ATR_INTERFACE_BYTE_TC].present = TRUE; 119 | } 120 | else 121 | atr->ib[pn][ATR_INTERFACE_BYTE_TC].present = FALSE; 122 | 123 | /* Read TDi if present */ 124 | if ((TDi | 0x7F) == 0xFF) 125 | { 126 | pointer++; 127 | TDi = atr->ib[pn][ATR_INTERFACE_BYTE_TD].value = atr_buffer[pointer]; 128 | atr->ib[pn][ATR_INTERFACE_BYTE_TD].present = TRUE; 129 | (atr->TCK).present = ((TDi & 0x0F) != ATR_PROTOCOL_TYPE_T0); 130 | pn++; 131 | if (pn >= ATR_MAX_PROTOCOLS) 132 | return (ATR_MALFORMED); 133 | } 134 | else 135 | { 136 | atr->ib[pn][ATR_INTERFACE_BYTE_TD].present = FALSE; 137 | break; 138 | } 139 | } 140 | 141 | /* Store number of protocols */ 142 | atr->pn = pn + 1; 143 | 144 | /* Store historical bytes */ 145 | if (pointer + atr->hbn >= length) 146 | return (ATR_MALFORMED); 147 | 148 | memcpy (atr->hb, atr_buffer + pointer + 1, atr->hbn); 149 | pointer += (atr->hbn); 150 | 151 | /* Store TCK */ 152 | if ((atr->TCK).present) 153 | { 154 | 155 | if (pointer + 1 >= length) 156 | return (ATR_MALFORMED); 157 | 158 | pointer++; 159 | 160 | (atr->TCK).value = atr_buffer[pointer]; 161 | } 162 | 163 | atr->length = pointer + 1; 164 | return (ATR_OK); 165 | } 166 | 167 | int 168 | ATR_GetConvention (ATR_t * atr, int *convention) 169 | { 170 | if (atr->TS == 0x3B) 171 | (*convention) = ATR_CONVENTION_DIRECT; 172 | else if (atr->TS == 0x3F) 173 | (*convention) = ATR_CONVENTION_INVERSE; 174 | else 175 | return (ATR_MALFORMED); 176 | return (ATR_OK); 177 | } 178 | 179 | int 180 | ATR_GetIntegerValue (ATR_t * atr, int name, BYTE * value) 181 | { 182 | int ret; 183 | 184 | if (name == ATR_INTEGER_VALUE_FI) 185 | { 186 | if (atr->ib[0][ATR_INTERFACE_BYTE_TA].present) 187 | { 188 | (*value) = (atr->ib[0][ATR_INTERFACE_BYTE_TA].value & 0xF0) >> 4; 189 | ret = ATR_OK; 190 | } 191 | else 192 | ret = ATR_NOT_FOUND; 193 | } 194 | 195 | else if (name == ATR_INTEGER_VALUE_DI) 196 | { 197 | if (atr->ib[0][ATR_INTERFACE_BYTE_TA].present) 198 | { 199 | (*value) = (atr->ib[0][ATR_INTERFACE_BYTE_TA].value & 0x0F); 200 | ret = ATR_OK; 201 | } 202 | else 203 | ret = ATR_NOT_FOUND; 204 | } 205 | 206 | else if (name == ATR_INTEGER_VALUE_II) 207 | { 208 | if (atr->ib[0][ATR_INTERFACE_BYTE_TB].present) 209 | { 210 | (*value) = (atr->ib[0][ATR_INTERFACE_BYTE_TB].value & 0x60) >> 5; 211 | ret = ATR_OK; 212 | } 213 | else 214 | ret = ATR_NOT_FOUND; 215 | } 216 | 217 | else if (name == ATR_INTEGER_VALUE_PI1) 218 | { 219 | if (atr->ib[0][ATR_INTERFACE_BYTE_TB].present) 220 | { 221 | (*value) = (atr->ib[0][ATR_INTERFACE_BYTE_TB].value & 0x1F); 222 | ret = ATR_OK; 223 | } 224 | else 225 | ret = ATR_NOT_FOUND; 226 | } 227 | 228 | else if (name == ATR_INTEGER_VALUE_PI2) 229 | { 230 | if (atr->ib[1][ATR_INTERFACE_BYTE_TB].present) 231 | { 232 | (*value) = atr->ib[1][ATR_INTERFACE_BYTE_TB].value; 233 | ret = ATR_OK; 234 | } 235 | else 236 | ret = ATR_NOT_FOUND; 237 | } 238 | 239 | else if (name == ATR_INTEGER_VALUE_N) 240 | { 241 | if (atr->ib[0][ATR_INTERFACE_BYTE_TC].present) 242 | { 243 | (*value) = atr->ib[0][ATR_INTERFACE_BYTE_TC].value; 244 | ret = ATR_OK; 245 | } 246 | else 247 | ret = ATR_NOT_FOUND; 248 | } 249 | else 250 | ret = ATR_NOT_FOUND; 251 | 252 | return ret; 253 | } 254 | 255 | int 256 | ATR_GetParameter (ATR_t * atr, int name, double *parameter) 257 | { 258 | BYTE FI, DI, II, PI1, PI2, N; 259 | 260 | if (name == ATR_PARAMETER_F) 261 | { 262 | if (ATR_GetIntegerValue (atr, ATR_INTEGER_VALUE_FI, &FI) == ATR_OK) 263 | (*parameter) = (double) (atr_f_table[FI]); 264 | else 265 | (*parameter) = (double) ATR_DEFAULT_F; 266 | return (ATR_OK); 267 | } 268 | 269 | else if (name == ATR_PARAMETER_D) 270 | { 271 | if (ATR_GetIntegerValue (atr, ATR_INTEGER_VALUE_DI, &DI) == ATR_OK) 272 | (*parameter) = (double) (atr_d_table[DI]); 273 | else 274 | (*parameter) = (double) ATR_DEFAULT_D; 275 | return (ATR_OK); 276 | } 277 | 278 | else if (name == ATR_PARAMETER_I) 279 | { 280 | if (ATR_GetIntegerValue (atr, ATR_INTEGER_VALUE_II, &II) == ATR_OK) 281 | (*parameter) = (double) (atr_i_table[II]); 282 | else 283 | (*parameter) = ATR_DEFAULT_I; 284 | return (ATR_OK); 285 | } 286 | 287 | else if (name == ATR_PARAMETER_P) 288 | { 289 | if (ATR_GetIntegerValue (atr, ATR_INTEGER_VALUE_PI2, &PI2) == ATR_OK) 290 | (*parameter) = (double) PI2; 291 | else if (ATR_GetIntegerValue (atr, ATR_INTEGER_VALUE_PI1, &PI1) == ATR_OK) 292 | (*parameter) = (double) PI1; 293 | else 294 | (*parameter) = (double) ATR_DEFAULT_P; 295 | return (ATR_OK); 296 | } 297 | 298 | else if (name == ATR_PARAMETER_N) 299 | { 300 | if (ATR_GetIntegerValue (atr, ATR_INTEGER_VALUE_N, &N) == ATR_OK) 301 | (*parameter) = (double) N; 302 | else 303 | (*parameter) = (double) ATR_DEFAULT_N; 304 | return (ATR_OK); 305 | } 306 | 307 | return (ATR_NOT_FOUND); 308 | } 309 | 310 | /* 311 | * This function was greatly inspired by ATRDecodeAtr() and 312 | * PHGetDefaultProtocol() from pcsc-lite 313 | * 314 | * It was rewritten by Ludovic Rousseau, 2004 315 | */ 316 | #define PROTOCOL_UNSET -1 317 | int ATR_GetDefaultProtocol(ATR_t * atr, int *protocol) 318 | { 319 | int i; 320 | 321 | /* default value */ 322 | *protocol = PROTOCOL_UNSET; 323 | 324 | for (i=0; iib[i][ATR_INTERFACE_BYTE_TD].present && (PROTOCOL_UNSET == *protocol)) 326 | { 327 | /* set to the first protocol byte found */ 328 | *protocol = atr->ib[i][ATR_INTERFACE_BYTE_TD].value & 0x0F; 329 | DEBUG_COMM2("default protocol: T=%d", *protocol); 330 | } 331 | 332 | /* specific mode if TA2 present */ 333 | if (atr->ib[1][ATR_INTERFACE_BYTE_TA].present) 334 | { 335 | *protocol = atr->ib[1][ATR_INTERFACE_BYTE_TA].value & 0x0F; 336 | DEBUG_COMM2("specific mode found: T=%d", *protocol); 337 | } 338 | 339 | if (PROTOCOL_UNSET == *protocol) 340 | { 341 | DEBUG_INFO("no default protocol found in ATR. Using T=0"); 342 | *protocol = ATR_PROTOCOL_TYPE_T0; 343 | } 344 | 345 | return ATR_OK; 346 | } 347 | 348 | -------------------------------------------------------------------------------- /contrib/Kobil_mIDentity_switch/README_Kobil_mIDentity_switch.txt: -------------------------------------------------------------------------------- 1 | The Kobil_mIDentity_switch program is used to activate the Kobil mIDenty 2 | smart card CCID reader. 3 | 4 | The USB device is by default: 5 | ID 0d46:4081 Kobil Systems GmbH mIDentity Basic/Classic (installationless) 6 | and will be switched to: 7 | ID 0d46:4001 Kobil Systems GmbH mIDentity Basic/Classic (composite device) 8 | 9 | 10 | Bus 005 Device 016: ID 0d46:4081 Kobil Systems GmbH mIDentity Basic/Classic (installationless) 11 | Device Descriptor: 12 | bLength 18 13 | bDescriptorType 1 14 | bcdUSB 2.00 15 | bDeviceClass 0 (Defined at Interface level) 16 | bDeviceSubClass 0 17 | bDeviceProtocol 0 18 | bMaxPacketSize0 64 19 | idVendor 0x0d46 Kobil Systems GmbH 20 | idProduct 0x4081 mIDentity Basic/Classic (installationless) 21 | bcdDevice 0.00 22 | iManufacturer 1 KOBIL Systems 23 | iProduct 2 mIDentity M 24 | iSerial 3 SN_K_05C901085 25 | bNumConfigurations 1 26 | Configuration Descriptor: 27 | bLength 9 28 | bDescriptorType 2 29 | wTotalLength 57 30 | bNumInterfaces 2 31 | bConfigurationValue 1 32 | iConfiguration 0 33 | bmAttributes 0x80 34 | (Bus Powered) 35 | MaxPower 400mA 36 | Interface Descriptor: 37 | bLength 9 38 | bDescriptorType 4 39 | bInterfaceNumber 0 40 | bAlternateSetting 0 41 | bNumEndpoints 2 42 | bInterfaceClass 8 Mass Storage 43 | bInterfaceSubClass 6 SCSI 44 | bInterfaceProtocol 80 Bulk (Zip) 45 | iInterface 0 46 | Endpoint Descriptor: 47 | bLength 7 48 | bDescriptorType 5 49 | bEndpointAddress 0x02 EP 2 OUT 50 | bmAttributes 2 51 | Transfer Type Bulk 52 | Synch Type None 53 | Usage Type Data 54 | wMaxPacketSize 0x0200 1x 512 bytes 55 | bInterval 0 56 | Endpoint Descriptor: 57 | bLength 7 58 | bDescriptorType 5 59 | bEndpointAddress 0x86 EP 6 IN 60 | bmAttributes 2 61 | Transfer Type Bulk 62 | Synch Type None 63 | Usage Type Data 64 | wMaxPacketSize 0x0200 1x 512 bytes 65 | bInterval 0 66 | Interface Descriptor: 67 | bLength 9 68 | bDescriptorType 4 69 | bInterfaceNumber 1 70 | bAlternateSetting 0 71 | bNumEndpoints 1 72 | bInterfaceClass 3 Human Interface Devices 73 | bInterfaceSubClass 1 Boot Interface Subclass 74 | bInterfaceProtocol 0 None 75 | iInterface 0 76 | Endpoint Descriptor: 77 | bLength 7 78 | bDescriptorType 5 79 | bEndpointAddress 0x81 EP 1 IN 80 | bmAttributes 3 81 | Transfer Type Interrupt 82 | Synch Type None 83 | Usage Type Data 84 | wMaxPacketSize 0x0040 1x 64 bytes 85 | bInterval 8 86 | UNRECOGNIZED: 09 21 00 01 00 01 22 22 00 87 | Device Qualifier (for other device speed): 88 | bLength 10 89 | bDescriptorType 6 90 | bcdUSB 2.00 91 | bDeviceClass 0 (Defined at Interface level) 92 | bDeviceSubClass 0 93 | bDeviceProtocol 0 94 | bMaxPacketSize0 64 95 | bNumConfigurations 1 96 | Device Status: 0x0002 97 | (Bus Powered) 98 | Remote Wakeup Enabled 99 | 100 | 101 | Bus 005 Device 015: ID 0d46:4001 Kobil Systems GmbH mIDentity Basic/Classic (composite device) 102 | Device Descriptor: 103 | bLength 18 104 | bDescriptorType 1 105 | bcdUSB 2.00 106 | bDeviceClass 0 (Defined at Interface level) 107 | bDeviceSubClass 0 108 | bDeviceProtocol 0 109 | bMaxPacketSize0 64 110 | idVendor 0x0d46 Kobil Systems GmbH 111 | idProduct 0x4001 mIDentity Basic/Classic (composite device) 112 | bcdDevice 0.00 113 | iManufacturer 1 KOBIL Systems 114 | iProduct 2 mIDentity M 115 | iSerial 3 SN_K_05C901085 116 | bNumConfigurations 1 117 | Configuration Descriptor: 118 | bLength 9 119 | bDescriptorType 2 120 | wTotalLength 134 121 | bNumInterfaces 3 122 | bConfigurationValue 1 123 | iConfiguration 0 124 | bmAttributes 0x80 125 | (Bus Powered) 126 | MaxPower 400mA 127 | Interface Descriptor: 128 | bLength 9 129 | bDescriptorType 4 130 | bInterfaceNumber 0 131 | bAlternateSetting 0 132 | bNumEndpoints 2 133 | bInterfaceClass 8 Mass Storage 134 | bInterfaceSubClass 6 SCSI 135 | bInterfaceProtocol 80 Bulk (Zip) 136 | iInterface 0 137 | Endpoint Descriptor: 138 | bLength 7 139 | bDescriptorType 5 140 | bEndpointAddress 0x02 EP 2 OUT 141 | bmAttributes 2 142 | Transfer Type Bulk 143 | Synch Type None 144 | Usage Type Data 145 | wMaxPacketSize 0x0200 1x 512 bytes 146 | bInterval 0 147 | Endpoint Descriptor: 148 | bLength 7 149 | bDescriptorType 5 150 | bEndpointAddress 0x86 EP 6 IN 151 | bmAttributes 2 152 | Transfer Type Bulk 153 | Synch Type None 154 | Usage Type Data 155 | wMaxPacketSize 0x0200 1x 512 bytes 156 | bInterval 0 157 | Interface Descriptor: 158 | bLength 9 159 | bDescriptorType 4 160 | bInterfaceNumber 1 161 | bAlternateSetting 0 162 | bNumEndpoints 2 163 | bInterfaceClass 11 Chip/SmartCard 164 | bInterfaceSubClass 0 165 | bInterfaceProtocol 0 166 | iInterface 0 167 | ChipCard Interface Descriptor: 168 | bLength 54 169 | bDescriptorType 33 170 | bcdCCID 1.00 171 | nMaxSlotIndex 0 172 | bVoltageSupport 7 5.0V 3.0V 1.8V 173 | dwProtocols 3 T=0 T=1 174 | dwDefaultClock 4000 175 | dwMaxiumumClock 4000 176 | bNumClockSupported 0 177 | dwDataRate 10752 bps 178 | dwMaxDataRate 250000 bps 179 | bNumDataRatesSupp. 0 180 | dwMaxIFSD 254 181 | dwSyncProtocols 00000000 182 | dwMechanical 00000000 183 | dwFeatures 000206BA 184 | Auto configuration based on ATR 185 | Auto voltage selection 186 | Auto clock change 187 | Auto baud rate change 188 | Auto PPS made by CCID 189 | NAD value other than 0x00 accpeted 190 | Auto IFSD exchange 191 | Short APDU level exchange 192 | dwMaxCCIDMsgLen 271 193 | bClassGetResponse echo 194 | bClassEnvelope echo 195 | wlcdLayout none 196 | bPINSupport 0 197 | bMaxCCIDBusySlots 1 198 | Endpoint Descriptor: 199 | bLength 7 200 | bDescriptorType 5 201 | bEndpointAddress 0x04 EP 4 OUT 202 | bmAttributes 2 203 | Transfer Type Bulk 204 | Synch Type None 205 | Usage Type Data 206 | wMaxPacketSize 0x0200 1x 512 bytes 207 | bInterval 0 208 | Endpoint Descriptor: 209 | bLength 7 210 | bDescriptorType 5 211 | bEndpointAddress 0x88 EP 8 IN 212 | bmAttributes 2 213 | Transfer Type Bulk 214 | Synch Type None 215 | Usage Type Data 216 | wMaxPacketSize 0x0200 1x 512 bytes 217 | bInterval 0 218 | Interface Descriptor: 219 | bLength 9 220 | bDescriptorType 4 221 | bInterfaceNumber 2 222 | bAlternateSetting 0 223 | bNumEndpoints 1 224 | bInterfaceClass 3 Human Interface Devices 225 | bInterfaceSubClass 1 Boot Interface Subclass 226 | bInterfaceProtocol 0 None 227 | iInterface 0 228 | Endpoint Descriptor: 229 | bLength 7 230 | bDescriptorType 5 231 | bEndpointAddress 0x81 EP 1 IN 232 | bmAttributes 3 233 | Transfer Type Interrupt 234 | Synch Type None 235 | Usage Type Data 236 | wMaxPacketSize 0x0040 1x 64 bytes 237 | bInterval 10 238 | UNRECOGNIZED: 09 21 00 01 00 01 22 22 00 239 | Device Qualifier (for other device speed): 240 | bLength 10 241 | bDescriptorType 6 242 | bcdUSB 2.00 243 | bDeviceClass 0 (Defined at Interface level) 244 | bDeviceSubClass 0 245 | bDeviceProtocol 0 246 | bMaxPacketSize0 64 247 | bNumConfigurations 1 248 | Device Status: 0x0002 249 | (Bus Powered) 250 | Remote Wakeup Enabled 251 | -------------------------------------------------------------------------------- /src/ccid.h: -------------------------------------------------------------------------------- 1 | /* 2 | ccid.h: CCID structures 3 | Copyright (C) 2003-2010 Ludovic Rousseau 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public License 16 | along with this library; if not, write to the Free Software Foundation, 17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 | */ 19 | 20 | /* 21 | * $Id: ccid.h 6845 2014-02-14 09:16:01Z rousseau $ 22 | */ 23 | 24 | typedef struct 25 | { 26 | /* 27 | * CCID Sequence number 28 | */ 29 | unsigned char *pbSeq; 30 | unsigned char real_bSeq; 31 | 32 | /* 33 | * VendorID << 16 + ProductID 34 | */ 35 | int readerID; 36 | 37 | /* 38 | * Maximum message length 39 | */ 40 | unsigned int dwMaxCCIDMessageLength; 41 | 42 | /* 43 | * Maximum IFSD 44 | */ 45 | int dwMaxIFSD; 46 | 47 | /* 48 | * Features supported by the reader (directly from Class Descriptor) 49 | */ 50 | int dwFeatures; 51 | 52 | /* 53 | * PIN support of the reader (directly from Class Descriptor) 54 | */ 55 | char bPINSupport; 56 | 57 | /* 58 | * Display dimensions of the reader (directly from Class Descriptor) 59 | */ 60 | unsigned int wLcdLayout; 61 | 62 | /* 63 | * Default Clock 64 | */ 65 | int dwDefaultClock; 66 | 67 | /* 68 | * Max Data Rate 69 | */ 70 | unsigned int dwMaxDataRate; 71 | 72 | /* 73 | * Number of available slots 74 | */ 75 | char bMaxSlotIndex; 76 | 77 | /* 78 | * Slot in use 79 | */ 80 | char bCurrentSlotIndex; 81 | 82 | /* 83 | * The array of data rates supported by the reader 84 | */ 85 | unsigned int *arrayOfSupportedDataRates; 86 | 87 | /* 88 | * Read communication port timeout 89 | * value is milliseconds 90 | * this value can evolve dynamically if card request it (time processing). 91 | */ 92 | unsigned int readTimeout; 93 | 94 | /* 95 | * Card protocol 96 | */ 97 | int cardProtocol; 98 | 99 | /* 100 | * bInterfaceProtocol (CCID, ICCD-A, ICCD-B) 101 | */ 102 | int bInterfaceProtocol; 103 | 104 | /* 105 | * bNumEndpoints 106 | */ 107 | int bNumEndpoints; 108 | 109 | /* 110 | * GemCore SIM PRO slot status management 111 | * The reader always reports a card present even if no card is inserted. 112 | * If the Power Up fails the driver will report IFD_ICC_NOT_PRESENT instead 113 | * of IFD_ICC_PRESENT 114 | */ 115 | int dwSlotStatus; 116 | 117 | /* 118 | * bVoltageSupport (bit field) 119 | * 1 = 5.0V 120 | * 2 = 3.0V 121 | * 4 = 1.8V 122 | */ 123 | int bVoltageSupport; 124 | 125 | /* 126 | * USB serial number of the device (if any) 127 | */ 128 | char *sIFD_serial_number; 129 | 130 | /* 131 | * USB iManufacturer string 132 | */ 133 | char *sIFD_iManufacturer; 134 | 135 | /* 136 | * USB bcdDevice 137 | */ 138 | int IFD_bcdDevice; 139 | 140 | /* 141 | * Gemalto extra features, if any 142 | */ 143 | struct GEMALTO_FIRMWARE_FEATURES *gemalto_firmware_features; 144 | 145 | /* 146 | * Zero Length Packet fixup (boolean) 147 | */ 148 | char zlp; 149 | } _ccid_descriptor; 150 | 151 | /* Features from dwFeatures */ 152 | #define CCID_CLASS_AUTO_CONF_ATR 0x00000002 153 | #define CCID_CLASS_AUTO_VOLTAGE 0x00000008 154 | #define CCID_CLASS_AUTO_BAUD 0x00000020 155 | #define CCID_CLASS_AUTO_PPS_PROP 0x00000040 156 | #define CCID_CLASS_AUTO_PPS_CUR 0x00000080 157 | #define CCID_CLASS_AUTO_IFSD 0x00000400 158 | #define CCID_CLASS_CHARACTER 0x00000000 159 | #define CCID_CLASS_TPDU 0x00010000 160 | #define CCID_CLASS_SHORT_APDU 0x00020000 161 | #define CCID_CLASS_EXTENDED_APDU 0x00040000 162 | #define CCID_CLASS_EXCHANGE_MASK 0x00070000 163 | 164 | /* Features from bPINSupport */ 165 | #define CCID_CLASS_PIN_VERIFY 0x01 166 | #define CCID_CLASS_PIN_MODIFY 0x02 167 | 168 | /* See CCID specs ch. 4.2.1 */ 169 | #define CCID_ICC_PRESENT_ACTIVE 0x00 /* 00 0000 00 */ 170 | #define CCID_ICC_PRESENT_INACTIVE 0x01 /* 00 0000 01 */ 171 | #define CCID_ICC_ABSENT 0x02 /* 00 0000 10 */ 172 | #define CCID_ICC_STATUS_MASK 0x03 /* 00 0000 11 */ 173 | 174 | #define CCID_COMMAND_FAILED 0x40 /* 01 0000 00 */ 175 | #define CCID_TIME_EXTENSION 0x80 /* 10 0000 00 */ 176 | 177 | /* bInterfaceProtocol for ICCD */ 178 | #define PROTOCOL_CCID 0 /* plain CCID */ 179 | #define PROTOCOL_ICCD_A 1 /* ICCD Version A */ 180 | #define PROTOCOL_ICCD_B 2 /* ICCD Version B */ 181 | 182 | /* Product identification for special treatments */ 183 | #define GEMPC433 0x08E64433 184 | #define GEMPCKEY 0x08E63438 185 | #define GEMPCTWIN 0x08E63437 186 | #define GEMPCPINPAD 0x08E63478 187 | #define GEMCORESIMPRO 0x08E63480 188 | #define GEMCORESIMPRO2 0x08E60000 /* Does NOT match a real VID/PID as new firmware release exposes same VID/PID */ 189 | #define GEMCOREPOSPRO 0x08E63479 190 | #define GEMALTOPROXDU 0x08E65503 191 | #define GEMALTOPROXSU 0x08E65504 192 | #define GEMALTO_EZIO_CBP 0x08E634C3 193 | #define CARDMAN3121 0x076B3021 194 | #define LTC31 0x07830003 195 | #define SCR331DI 0x04E65111 196 | #define SCR331DINTTCOM 0x04E65120 197 | #define SDI010 0x04E65121 198 | #define CHERRYXX33 0x046A0005 199 | #define CHERRYST2000 0x046A003E 200 | #define OZ776 0x0B977762 201 | #define OZ776_7772 0x0B977772 202 | #define SPR532 0x04E6E003 203 | #define MYSMARTPAD 0x09BE0002 204 | #define CHERRYXX44 0x046a0010 205 | #define CL1356D 0x0B810200 206 | #define REINER_SCT 0x0C4B0300 207 | #define SEG 0x08E68000 208 | #define BLUDRIVEII_CCID 0x1B0E1078 209 | #define DELLSCRK 0x413C2101 210 | #define DELLSK 0x413C2100 211 | #define KOBIL_TRIBANK 0x0D463010 212 | #define KOBIL_MIDENTITY_VISUAL 0x0D460D46 213 | #define VEGAALPHA 0x09820008 214 | #define HPSMARTCARDKEYBOARD 0x03F01024 215 | #define HP_CCIDSMARTCARDKEYBOARD 0x03F00036 216 | #define KOBIL_IDTOKEN 0x0D46301D 217 | #define FUJITSUSMARTKEYB 0x0BF81017 218 | 219 | #define VENDOR_GEMALTO 0x08E6 220 | #define GET_VENDOR(readerID) ((readerID >> 16) & 0xFFFF) 221 | 222 | /* 223 | * The O2Micro OZ776S reader has a wrong USB descriptor 224 | * The extra[] field is associated with the last endpoint instead of the 225 | * main USB descriptor 226 | */ 227 | /* #define O2MICRO_OZ776_PATCH */ 228 | 229 | /* Escape sequence codes */ 230 | #define ESC_GEMPC_SET_ISO_MODE 1 231 | #define ESC_GEMPC_SET_APDU_MODE 2 232 | 233 | /* 234 | * Possible values : 235 | * 3 -> 1.8V, 3V, 5V 236 | * 2 -> 3V, 5V 237 | * 1 -> 5V only 238 | * 0 -> automatic (selection made by the reader) 239 | */ 240 | /* 241 | * To be safe we default to 5V 242 | * otherwise we would have to parse the ATR and get the value of TAi (i>2) when 243 | * in T=15 244 | */ 245 | #define VOLTAGE_AUTO 0 246 | #define VOLTAGE_5V 1 247 | #define VOLTAGE_3V 2 248 | #define VOLTAGE_1_8V 3 249 | 250 | int ccid_open_hack_pre(unsigned int reader_index); 251 | int ccid_open_hack_post(unsigned int reader_index); 252 | void ccid_error(int error, const char *file, int line, const char *function); 253 | _ccid_descriptor *get_ccid_descriptor(unsigned int reader_index); 254 | 255 | /* convert a 4 byte integer in USB format into an int */ 256 | #define dw2i(a, x) (unsigned int)((((((a[x+3] << 8) + a[x+2]) << 8) + a[x+1]) << 8) + a[x]) 257 | 258 | /* all the data rates specified by ISO 7816-3 Fi/Di tables */ 259 | #define ISO_DATA_RATES 10753, 14337, 15625, 17204, \ 260 | 20833, 21505, 23438, 25806, 28674, \ 261 | 31250, 32258, 34409, 39063, 41667, \ 262 | 43011, 46875, 52083, 53763, 57348, \ 263 | 62500, 64516, 68817, 71685, 78125, \ 264 | 83333, 86022, 93750, 104167, 107527, \ 265 | 114695, 125000, 129032, 143369, 156250, \ 266 | 166667, 172043, 215054, 229391, 250000, \ 267 | 344086 268 | 269 | /* data rates supported by the secondary slots on the GemCore Pos Pro & SIM Pro */ 270 | #define GEMPLUS_CUSTOM_DATA_RATES 10753, 21505, 43011, 125000 271 | 272 | /* data rates for GemCore SIM Pro 2 */ 273 | #define SIMPRO2_ISO_DATA_RATES 8709, 10322, 12403, 12500, \ 274 | 12903, 17204, 18750, 20645, 24806, \ 275 | 25000, 25806, 28125, 30967, 34408, \ 276 | 37500, 41290, 46875, 49612, 50000, \ 277 | 51612, 56250, 62500, 64516, 68817, \ 278 | 74418, 75000, 82580, 86021, 93750, \ 279 | 99224, 100000, 103225, 112500, 124031, \ 280 | 125000, 137634, 150000, 154838, 165161, \ 281 | 172043, 187500, 198449, 200000, 206451, \ 282 | 258064, 275268, 300000, 396899, 400000, \ 283 | 412903, 550537, 600000, 825806 284 | 285 | /* Structure returned by Gemalto readers for the CCID Escape command 0x6A */ 286 | struct GEMALTO_FIRMWARE_FEATURES 287 | { 288 | UCHAR bLogicalLCDLineNumber; /* Logical number of LCD lines */ 289 | UCHAR bLogicalLCDRowNumber; /* Logical number of characters per LCD line */ 290 | UCHAR bLcdInfo; /* b0 indicates if scrolling is available */ 291 | UCHAR bEntryValidationCondition; /* See PIN_PROPERTIES */ 292 | 293 | /* Here come the PC/SC bit features to report */ 294 | UCHAR VerifyPinStart:1; 295 | UCHAR VerifyPinFinish:1; 296 | UCHAR ModifyPinStart:1; 297 | UCHAR ModifyPinFinish:1; 298 | UCHAR GetKeyPressed:1; 299 | UCHAR VerifyPinDirect:1; 300 | UCHAR ModifyPinDirect:1; 301 | UCHAR Abort:1; 302 | 303 | UCHAR GetKey:1; 304 | UCHAR WriteDisplay:1; 305 | UCHAR SetSpeMessage:1; 306 | UCHAR RFUb1:5; 307 | 308 | UCHAR RFUb2[2]; 309 | 310 | /* Additional flags */ 311 | UCHAR bTimeOut2:1; 312 | UCHAR bListSupportedLanguages:1; /* Reader is able to indicate 313 | the list of supported languages through CCID-ESC 0x6B */ 314 | UCHAR bNumberMessageFix:1; /* Reader handles correctly shifts 315 | made by bNumberMessage in PIN modification data structure */ 316 | UCHAR bPPDUSupportOverXferBlock:1; /* Reader supports PPDU over 317 | PC_to_RDR_XferBlock command */ 318 | UCHAR bPPDUSupportOverEscape:1; /* Reader supports PPDU over 319 | PC_to_RDR_Escape command with abData[0]=0xFF */ 320 | UCHAR RFUb3:3; 321 | 322 | UCHAR RFUb4[3]; 323 | 324 | UCHAR VersionNumber; /* ?? */ 325 | UCHAR MinimumPINSize; /* for Verify and Modify */ 326 | UCHAR MaximumPINSize; 327 | 328 | /* Miscellaneous reader features */ 329 | UCHAR Firewall:1; 330 | UCHAR RFUb5:7; 331 | 332 | /* The following fields, FirewalledCommand_SW1 and 333 | * FirewalledCommand_SW2 are only valid if Firewall=1 334 | * These fields give the SW1 SW2 value used by the reader to 335 | * indicate a command has been firewalled */ 336 | UCHAR FirewalledCommand_SW1; 337 | UCHAR FirewalledCommand_SW2; 338 | UCHAR RFUb6[3]; 339 | }; 340 | 341 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | # Process this file with autoconf to produce a configure script. 2 | # You may need to use autoconf 2.56 or newer 3 | 4 | # $Id: configure.ac 6880 2014-03-23 15:13:34Z rousseau $ 5 | 6 | # Require autoconf 2.61 7 | AC_PREREQ([2.69]) 8 | 9 | AC_INIT([ccid],[1.4.16]) 10 | AC_CONFIG_SRCDIR(src/ifdhandler.c) 11 | AC_CONFIG_AUX_DIR([.]) 12 | AM_INIT_AUTOMAKE(1.8 dist-bzip2 no-dist-gzip subdir-objects) 13 | AC_CONFIG_MACRO_DIR([m4]) 14 | 15 | # silent build by default 16 | m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) 17 | 18 | # Default install dir 19 | AC_PREFIX_DEFAULT(/usr/local) 20 | 21 | # Automake boilerplate. 22 | AC_CANONICAL_HOST 23 | 24 | # create a config.h file (Automake will add -DHAVE_CONFIG_H) 25 | AC_CONFIG_HEADERS([config.h]) 26 | 27 | # Options 28 | AM_MAINTAINER_MODE 29 | 30 | # Checks for programs. 31 | AC_PROG_CC 32 | AM_PROG_CC_C_O 33 | AC_PROG_CPP 34 | AC_PROG_INSTALL 35 | AC_PROG_MAKE_SET 36 | AC_PROG_LN_S 37 | AM_PROG_LEX 38 | AM_PROG_AR 39 | PKG_PROG_PKG_CONFIG 40 | 41 | # check pcsc-lite version 42 | PCSC_NEEDED_VERSION="1.8.3" 43 | PKG_CHECK_EXISTS([libpcsclite], 44 | [PKG_CHECK_MODULES(PCSC, libpcsclite >= $PCSC_NEEDED_VERSION, [], 45 | [ 46 | if test -f /usr/local/lib/pkgconfig/libpcsclite.pc -a "x$PKG_CONFIG" != x ; then 47 | AC_MSG_ERROR([use PKG_CONFIG_PATH=/usr/local/lib/pkgconfig ./configure]) 48 | else 49 | AC_MSG_WARN([install pcsc-lite $PCSC_NEEDED_VERSION or later]) 50 | fi 51 | ])], 52 | [AC_MSG_WARN([libpcsclite not found by pkg-config])] 53 | ) 54 | 55 | saved_CPPFLAGS="$CPPFLAGS" 56 | CPPFLAGS="$CPPFLAGS $PCSC_CFLAGS" 57 | PCSC_ERROR_MSG="install pcsc-lite $PCSC_NEEDED_VERSION or later, or use ./configure PCSC_CFLAGS=..." 58 | AC_CHECK_HEADER(ifdhandler.h,, [AC_MSG_ERROR([$PCSC_ERROR_MSG])]) 59 | AC_CHECK_HEADER(reader.h,, [AC_MSG_ERROR([$PCSC_ERROR_MSG])]) 60 | CPPFLAGS="$saved_CPPFLAGS" 61 | 62 | # Add libtool support. 63 | # Static lib is disabled by default. Use --enable-static if needed 64 | LT_INIT(disable-static) 65 | LT_INIT 66 | 67 | # Automatically update the libtool script if it becomes out-of-date. 68 | AC_SUBST(LIBTOOL_DEPS) 69 | 70 | # Checks for header files. 71 | AC_HEADER_STDC 72 | AC_CHECK_HEADERS(errno.h fcntl.h stdlib.h unistd.h termios.h string.h sys/time.h sys/types.h stdarg.h arpa/inet.h,, 73 | [AC_MSG_ERROR([some header files not found])]) 74 | 75 | # Checks for typedefs, structures, and compiler characteristics. 76 | AC_C_CONST 77 | AC_TYPE_SIZE_T 78 | AC_HEADER_TIME 79 | 80 | # Checks for library functions. 81 | AC_CHECK_FUNCS(select strerror strncpy memcpy strlcpy strlcat) 82 | 83 | # Select OS specific versions of source files. 84 | AC_SUBST(BUNDLE_HOST) 85 | AC_SUBST(DYN_LIB_EXT) 86 | BUNDLE_HOST=`uname | sed -e s,/,_,` 87 | DYN_LIB_EXT="so" 88 | case "$BUNDLE_HOST" in 89 | Darwin) 90 | BUNDLE_HOST=MacOS 91 | DYN_LIB_EXT="dylib" 92 | ;; 93 | SunOS) 94 | BUNDLE_HOST=Solaris 95 | ;; 96 | esac 97 | 98 | # --disable-libusb 99 | AC_ARG_ENABLE(libusb, 100 | AS_HELP_STRING([--disable-libusb],[do not use libusb]), 101 | [ use_libusb="${enableval}" ], [ use_libusb=yes ] ) 102 | 103 | # check if libusb is used 104 | LIBUSB_NEEDED_VERSION="1.0.8" 105 | if test "x$use_libusb" != xno ; then 106 | PKG_CHECK_EXISTS([libusb-1.0], [ 107 | PKG_CHECK_MODULES(LIBUSB, libusb-1.0 >= $LIBUSB_NEEDED_VERSION, [], 108 | [ 109 | AC_MSG_WARN([install libusb $LIBUSB_NEEDED_VERSION or later]) 110 | PKG_CHECK_MODULES(LIBUSB, libusb-1.0) 111 | ]) 112 | ]) 113 | 114 | saved_CPPFLAGS="$CPPFLAGS" 115 | saved_LIBS="$LIBS" 116 | 117 | CPPFLAGS="$CPPFLAGS $LIBUSB_CFLAGS" 118 | LIBS="$LDFLAGS $LIBUSB_LIBS" 119 | 120 | AC_CHECK_HEADERS(libusb.h, [], 121 | [ AC_MSG_ERROR([libusb.h not found, install libusb or use ./configure LIBUSB_CFLAGS=...]) ]) 122 | 123 | AC_MSG_CHECKING([for libusb_init]) 124 | AC_TRY_LINK_FUNC(libusb_init, [ AC_MSG_RESULT([yes]) ], 125 | [ AC_MSG_ERROR([libusb not found, use ./configure LIBUSB_LIBS=...]) ]) 126 | 127 | CPPFLAGS="$saved_CPPFLAGS" 128 | LIBS="$saved_LIBS" 129 | 130 | use_libusb=yes 131 | fi 132 | AC_SUBST(LIBUSB_CFLAGS) 133 | AC_SUBST(LIBUSB_LIBS) 134 | AM_CONDITIONAL(WITH_LIBUSB, test "${use_libusb}" != "no") 135 | 136 | # --enable-composite-as-multislot 137 | use_composite_as_multislot=no 138 | AC_ARG_ENABLE(composite-as-multislot, 139 | AS_HELP_STRING([--enable-composite-as-multislot],[composite device are seen as multi-slots]), 140 | [ use_composite_as_multislot="${enableval}" ] ) 141 | 142 | if test "x$use_composite_as_multislot" = xyes; then 143 | AC_DEFINE(USE_COMPOSITE_AS_MULTISLOT, 1, [composite device are seen as multi-slots]) 144 | fi 145 | 146 | # check if the compiler support -fvisibility=hidden (GCC >= 4) 147 | saved_CFLAGS="$CFLAGS" 148 | CFLAGS="$CFLAGS -fvisibility=hidden" 149 | AC_MSG_CHECKING([for -fvisibility=hidden]) 150 | AC_COMPILE_IFELSE([AC_LANG_SOURCE([char foo;])], 151 | [ AC_MSG_RESULT([yes]) 152 | SYMBOL_VISIBILITY="-fvisibility=hidden" ], 153 | AC_MSG_RESULT([no])) 154 | CFLAGS="$saved_CFLAGS" 155 | AC_SUBST(SYMBOL_VISIBILITY) 156 | 157 | # --disable-multi-thread 158 | AC_ARG_ENABLE(multi-thread, 159 | AS_HELP_STRING([--disable-multi-thread],[disable multi threading]), 160 | [ multithread="${enableval}" ], [ multithread=yes ] ) 161 | 162 | if test "${multithread}" != no ; then 163 | AX_PTHREAD( 164 | [ AC_DEFINE(HAVE_PTHREAD, 1, 165 | [Define if you have POSIX threads libraries and header files.]) 166 | ], [ AC_MSG_ERROR([POSIX thread support required]) ]) 167 | 168 | multithread=yes 169 | fi 170 | 171 | # --enable-bundle=NAME 172 | AC_ARG_ENABLE(bundle, 173 | AS_HELP_STRING([--enable-bundle=NAME],[bundle directory name 174 | (default ifd-ccid.bundle)]), 175 | [bundle="${enableval}"], [bundle=false]) 176 | if test "${bundle}" = false ; then 177 | bundle="ifd-ccid.bundle" 178 | fi 179 | AC_DEFINE_UNQUOTED(BUNDLE, "$bundle", [bundle directory name]) 180 | 181 | # --enable-usbdropdir=DIR 182 | AC_ARG_ENABLE(usbdropdir, 183 | AS_HELP_STRING([--enable-usbdropdir=DIR],[directory containing USB 184 | drivers (default to pcscd config or $(prefix)/pcsc/drivers)]), 185 | [usbdropdir="${enableval}"], [usbdropdir=false]) 186 | if test "${usbdropdir}" = false ; then 187 | usbdropdir=`$PKG_CONFIG libpcsclite --variable=usbdropdir` 188 | fi 189 | AC_DEFINE_UNQUOTED(PCSCLITE_HP_DROPDIR, "$usbdropdir", [directory containing USB drivers]) 190 | if test "${usbdropdir}" = "" ; then 191 | AC_MSG_ERROR([use --enable-usbdropdir=DIR]) 192 | fi 193 | 194 | # --enable-twinserial 195 | AC_ARG_ENABLE(twinserial, 196 | AS_HELP_STRING([--enable-twinserial],[also compile and install the serial Twin driver]), 197 | [twinserial="${enableval}"], [twinserial=no]) 198 | AM_CONDITIONAL(WITH_TWIN_SERIAL, test "${twinserial}" != "no") 199 | 200 | # --enable-ccidtwindir=DIR 201 | AC_ARG_ENABLE(ccidtwindir, 202 | AS_HELP_STRING([--enable-ccidtwindir=DIR],[directory to install the 203 | serial Twin driver (default to pcscd config or $(prefix)/pcsc/drivers/serial)]), 204 | [ccidtwindir="${enableval}"], [ccidtwindir=false]) 205 | if test "${ccidtwindir}" = false ; then 206 | ccidtwindir=$usbdropdir/serial 207 | fi 208 | 209 | # --enable-serialconfdir=DIR 210 | AC_ARG_ENABLE(serialconfdir, 211 | AS_HELP_STRING([--enable-serialconfdir=dir],[directory containing 212 | serial drivers (default to pcscd config)]), 213 | [serialconfdir="${enableval}"], [serialconfdir=false]) 214 | if test "${serialconfdir}" = false ; then 215 | serialconfdir=`$PKG_CONFIG libpcsclite --variable=serialconfdir` 216 | fi 217 | 218 | # --disable-pcsclite 219 | AC_ARG_ENABLE(pcsclite, 220 | AS_HELP_STRING([--disable-pcsclite],[do not use pcsc-lite debug support]), 221 | [ pcsclite="${enableval}" ], [ pcsclite=yes ] ) 222 | 223 | if test "${pcsclite}" != no ; then 224 | # check that pcsc-lite is installed 225 | OLD_LIBS="$LIBS" 226 | OLD_CFLAGS="$CFLAGS" 227 | LIBS="$LIBS $PCSC_LIBS" 228 | CFLAGS="$CFLAGS $PCSC_CFLAGS" 229 | AC_MSG_CHECKING([for SCardEstablishContext]) 230 | AC_TRY_LINK_FUNC(SCardEstablishContext, 231 | [ AC_MSG_RESULT([yes]) ], 232 | [ AC_MSG_ERROR([SCardEstablishContext() not found, install pcsc-lite 1.2.9-beta9 or later,or use PCSC_LIBS=... ./configure]) ]) 233 | LIBS="$OLD_LIBS" 234 | CFLAGS="$OLD_CFLAGS" 235 | 236 | pcsclite=yes 237 | fi 238 | AM_CONDITIONAL(WITHOUT_PCSC, test "${pcsclite}" != "yes") 239 | 240 | # --disable-class 241 | AC_ARG_ENABLE(class, 242 | AS_HELP_STRING([--disable-class],[remove the CCIDCLASSDRIVER from Info.plist]), 243 | [class="${enableval}"], [class=yes]) 244 | if test "${class}" != yes ; then 245 | NOCLASS="--no-class" 246 | fi 247 | AC_SUBST(NOCLASS) 248 | 249 | # --enable-embedded 250 | AC_ARG_ENABLE(embedded, 251 | AS_HELP_STRING([--enable-embedded],[limit RAM and CPU ressources by disabling features (log)]), 252 | [ use_embedded="${enableval}" ]) 253 | 254 | if test x$use_embedded = xyes; then 255 | AC_DEFINE(NO_LOG, 1, [Disable logging support]) 256 | fi 257 | 258 | # Setup dist stuff 259 | AC_SUBST(ac_aux_dir) 260 | AC_SUBST(bundle) 261 | AC_SUBST(usbdropdir) 262 | AC_SUBST(ccidtwindir) 263 | AC_SUBST(serialconfdir) 264 | AS_AC_EXPAND(bindir_exp,$bindir) 265 | AS_AC_EXPAND(sysconfdir_exp,$sysconfdir) 266 | 267 | cat << EOF 268 | 269 | libccid has been configured with following options: 270 | 271 | Version: ${PACKAGE_VERSION} 272 | User binaries: $(eval eval eval echo "${bindir_exp}") 273 | Configuration files: $(eval eval eval echo "${sysconfdir_exp}") 274 | 275 | 276 | Host: ${host} 277 | Compiler: ${CC} 278 | Preprocessor flags: ${CPPFLAGS} 279 | Compiler flags: ${CFLAGS} 280 | Preprocessor flags: ${CPPFLAGS} 281 | Linker flags: ${LDFLAGS} 282 | Libraries: ${LIBS} 283 | 284 | PCSC_CFLAGS: ${PCSC_CFLAGS} 285 | PCSC_LIBS: ${PCSC_LIBS} 286 | PTHREAD_CFLAGS: ${PTHREAD_CFLAGS} 287 | PTHREAD_LIBS: ${PTHREAD_LIBS} 288 | BUNDLE_HOST: ${BUNDLE_HOST} 289 | DYN_LIB_EXT: ${DYN_LIB_EXT} 290 | LIBUSB_CFLAGS: ${LIBUSB_CFLAGS} 291 | LIBUSB_LIBS: ${LIBUSB_LIBS} 292 | SYMBOL_VISIBILITY: ${SYMBOL_VISIBILITY} 293 | NOCLASS: ${NOCLASS} 294 | 295 | libusb support: ${use_libusb} 296 | composite as multislot: ${use_composite_as_multislot} 297 | multi threading: ${multithread} 298 | bundle directory name: ${bundle} 299 | USB drop directory: ${usbdropdir} 300 | serial Twin support: ${twinserial} 301 | serial twin install dir: ${ccidtwindir} 302 | serial config directory: ${serialconfdir} 303 | compiled for pcsc-lite: ${pcsclite} 304 | class driver: ${class} 305 | 306 | EOF 307 | 308 | # Write Makefiles. 309 | AC_CONFIG_FILES(Makefile 310 | src/Makefile 311 | readers/Makefile 312 | contrib/Makefile 313 | contrib/Kobil_mIDentity_switch/Makefile 314 | contrib/RSA_SecurID/Makefile 315 | examples/Makefile) 316 | 317 | AC_OUTPUT 318 | 319 | --------------------------------------------------------------------------------