1 |
/************************************/ |
/* |
2 |
/* Smart Card support for RDesktop. */ |
rdesktop: A Remote Desktop Protocol client. |
3 |
/* Copyright (C) by Alexi Volkov */ |
Smart Card support |
4 |
/* e-mail: alexi@myrealbox.com */ |
Copyright (C) Alexi Volkov <alexi@myrealbox.com> 2006 |
5 |
/* ICQ: 264679502 */ |
|
6 |
/************************************/ |
This program is free software; you can redistribute it and/or modify |
7 |
|
it under the terms of the GNU General Public License as published by |
8 |
|
the Free Software Foundation; either version 2 of the License, or |
9 |
|
(at your option) any later version. |
10 |
|
|
11 |
|
This program is distributed in the hope that it will be useful, |
12 |
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
GNU General Public License for more details. |
15 |
|
|
16 |
|
You should have received a copy of the GNU General Public License |
17 |
|
along with this program; if not, write to the Free Software |
18 |
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 |
|
*/ |
20 |
|
|
21 |
#include <stdio.h> |
#include <stdio.h> |
22 |
#include "rdesktop.h" |
#include "rdesktop.h" |
26 |
#include <sys/types.h> |
#include <sys/types.h> |
27 |
#include <time.h> |
#include <time.h> |
28 |
#ifndef MAKE_PROTO |
#ifndef MAKE_PROTO |
29 |
|
#ifdef PCSC_OSX |
30 |
|
#include <PCSC/pcsclite.h> |
31 |
|
#include <PCSC/winscard.h> |
32 |
|
#else |
33 |
#include <pcsclite.h> |
#include <pcsclite.h> |
34 |
#include <winscard.h> |
#include <winscard.h> |
35 |
|
#endif /* PCSC_OSX */ |
36 |
#include "scard.h" |
#include "scard.h" |
37 |
|
|
38 |
/* variable segment */ |
/* variable segment */ |
54 |
static pthread_mutex_t queueAccess; |
static pthread_mutex_t queueAccess; |
55 |
static pthread_mutex_t queueEmpty; |
static pthread_mutex_t queueEmpty; |
56 |
static pthread_mutex_t hcardAccess; |
static pthread_mutex_t hcardAccess; |
57 |
/* static pthread_mutex_t sendControl; */ |
static pthread_mutex_t sendControl; |
58 |
|
|
59 |
static PMEM_HANDLE threadListHandle = NULL; |
static PMEM_HANDLE threadListHandle = NULL; |
60 |
static PThreadListElement threadList = NULL; |
static PThreadListElement threadList = NULL; |
126 |
rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); |
rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); |
127 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
128 |
{ |
{ |
129 |
printf("[SMART CARD: PCSC service not available]\n"); |
error("[SMART CARD: PCSC service not available]\n"); |
130 |
return 0; |
return 0; |
131 |
} |
} |
132 |
else |
else |
136 |
|
|
137 |
if (0 != pthread_mutex_init(&queueAccess, NULL)) |
if (0 != pthread_mutex_init(&queueAccess, NULL)) |
138 |
{ |
{ |
139 |
printf("[SMART CARD: Can't initialize queue access mutex]\n"); |
error("[SMART CARD: Can't initialize queue access mutex]\n"); |
140 |
return 0; |
return 0; |
141 |
} |
} |
142 |
|
|
143 |
if (0 != pthread_mutex_init(&queueEmpty, NULL)) |
if (0 != pthread_mutex_init(&queueEmpty, NULL)) |
144 |
{ |
{ |
145 |
printf("[SMART CARD: Can't initialize queue control mutex]\n"); |
error("[SMART CARD: Can't initialize queue control mutex]\n"); |
146 |
return 0; |
return 0; |
147 |
} |
} |
148 |
|
|
149 |
if (0 != pthread_mutex_init(&hcardAccess, NULL)) |
if (0 != pthread_mutex_init(&hcardAccess, NULL)) |
150 |
{ |
{ |
151 |
printf("[SMART CARD: Can't initialize hcard list access mutex]\n"); |
error("[SMART CARD: Can't initialize hcard list access mutex]\n"); |
152 |
return 0; |
return 0; |
153 |
} |
} |
154 |
|
|
|
#if 0 |
|
155 |
if (0 != pthread_mutex_init(&sendControl, NULL)) |
if (0 != pthread_mutex_init(&sendControl, NULL)) |
156 |
{ |
{ |
157 |
printf("[SMART CARD: Can't initialize send control mutex]\n"); |
error("[SMART CARD: Can't initialize send control mutex]\n"); |
158 |
return 0; |
return 0; |
159 |
} |
} |
|
#endif |
|
|
|
|
160 |
|
|
161 |
if (0 != |
if (0 != |
162 |
pthread_create(&queueHandler, NULL, (void *(*)(void *)) queue_handler_function, NULL)) |
pthread_create(&queueHandler, NULL, (void *(*)(void *)) queue_handler_function, NULL)) |
163 |
{ |
{ |
164 |
printf("[SMART CARD: Can't create queue handling Thread]\n"); |
error("[SMART CARD: Can't create queue handling Thread]\n"); |
165 |
return 0; |
return 0; |
166 |
} |
} |
167 |
|
|
230 |
} |
} |
231 |
} |
} |
232 |
|
|
|
|
|
|
printf("******************************************************\n"); |
|
|
printf("* Smart Card support for RDesktop is initialized. *\n"); |
|
|
printf("* Copyright (C) by Alexi Volkov, alexi@myrealbox.com *\n"); |
|
|
printf("******************************************************\n"); |
|
|
|
|
233 |
return count; |
return count; |
234 |
} |
} |
235 |
|
|
488 |
} |
} |
489 |
|
|
490 |
static void |
static void |
491 |
outForceAllignment(STREAM out, unsigned int seed) |
outForceAlignment(STREAM out, unsigned int seed) |
492 |
{ |
{ |
493 |
SERVER_DWORD add = (seed - (out->p - out->data) % seed) % seed; |
SERVER_DWORD add = (seed - (out->p - out->data) % seed) % seed; |
494 |
if (add > 0) |
if (add > 0) |
|
{ |
|
495 |
out_uint8s(out, add); |
out_uint8s(out, add); |
|
} |
|
496 |
} |
} |
497 |
|
|
498 |
static unsigned int |
static unsigned int |
609 |
MYPCSC_SCARDCONTEXT hContext; |
MYPCSC_SCARDCONTEXT hContext; |
610 |
/* code segment */ |
/* code segment */ |
611 |
|
|
612 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("Establishing PC/SC Context... \n")); |
|
printf("Establishing PC/SC Context... \n"); |
|
|
#endif |
|
613 |
rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); |
rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); |
|
#ifdef WITH_SCARD_DEBUG |
|
614 |
if (rv) |
if (rv) |
615 |
printf("<--ERROR SCardEstablishContext Code=0x%.8x]-->\n", (unsigned int) rv); |
{ |
616 |
|
DEBUG_SCARD(("<--ERROR SCardEstablishContext Code=0x%.8x]-->\n", |
617 |
|
(unsigned int) rv)); |
618 |
|
} |
619 |
else |
else |
620 |
printf("<--SUCCESS SCardEstablishContext-->\n"); |
{ |
621 |
#endif |
DEBUG_SCARD(("<--SUCCESS SCardEstablishContext-->\n")); |
622 |
|
} |
623 |
|
|
624 |
out_uint32_le(out, 0x00000004); |
out_uint32_le(out, 0x00000004); |
625 |
out_uint32_le(out, (SERVER_DWORD) hContext); /* must not be 0 (Seems to be pointer), don't know what is this (I use hContext as value) */ |
out_uint32_le(out, (SERVER_DWORD) hContext); /* must not be 0 (Seems to be pointer), don't know what is this (I use hContext as value) */ |
637 |
|
|
638 |
in->p += 0x1C; |
in->p += 0x1C; |
639 |
in_uint32_le(in, hContext); |
in_uint32_le(in, hContext); |
640 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[CONTEXT 0x%.8x]\n", (unsigned int) hContext)); |
641 |
printf("[CONTEXT 0x%.8x]\n", (unsigned int) hContext); |
DEBUG_SCARD(("Releasing context... \n")); |
|
printf("Releasing context... \n"); |
|
|
#endif |
|
642 |
rv = SCardReleaseContext((MYPCSC_SCARDCONTEXT) hContext); |
rv = SCardReleaseContext((MYPCSC_SCARDCONTEXT) hContext); |
643 |
#ifdef WITH_SCARD_DEBUG |
|
644 |
if (rv) |
if (rv) |
645 |
printf("<--ERROR SCardReleaseContext Code=0x%.8x-->\n", (unsigned int) rv); |
{ |
646 |
|
DEBUG_SCARD(("<--ERROR SCardReleaseContext Code=0x%.8x-->\n", (unsigned int) rv)); |
647 |
|
} |
648 |
else |
else |
649 |
printf("<--SUCCESS SCardReleaseContext-->\n"); |
{ |
650 |
#endif |
DEBUG_SCARD(("<--SUCCESS SCardReleaseContext-->\n")); |
651 |
|
} |
652 |
|
|
653 |
return rv; |
return rv; |
654 |
} |
} |
655 |
|
|
664 |
|
|
665 |
in->p += 0x1C; |
in->p += 0x1C; |
666 |
in_uint32_le(in, hContext); |
in_uint32_le(in, hContext); |
667 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[CONTEXT 0x%.8x]\n", (unsigned int) hContext)); |
668 |
printf("[CONTEXT 0x%.8x]\n", (unsigned int) hContext); |
DEBUG_SCARD(("Checking... \n")); |
|
printf("Checking... \n"); |
|
|
#endif |
|
669 |
/* There is no realization of SCardIsValidContext in PC/SC Lite so we call SCardListReaders */ |
/* There is no realization of SCardIsValidContext in PC/SC Lite so we call SCardListReaders */ |
670 |
|
|
671 |
readers = SC_xmalloc(&lcHandle, 1024); |
readers = SC_xmalloc(&lcHandle, 1024); |
673 |
return SC_returnNoMemoryError(&lcHandle, in, out); |
return SC_returnNoMemoryError(&lcHandle, in, out); |
674 |
|
|
675 |
rv = SCardListReaders((MYPCSC_SCARDCONTEXT) hContext, NULL, readers, &readerCount); |
rv = SCardListReaders((MYPCSC_SCARDCONTEXT) hContext, NULL, readers, &readerCount); |
676 |
|
|
677 |
if (rv) |
if (rv) |
678 |
{ |
{ |
679 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<--ERROR SCardListReaders (no SCardIsValidContext) Code=0x%.8x-->\n", |
680 |
printf("<--ERROR SCardListReaders (no SCardIsValidContext) Code=0x%.8x-->\n", |
(unsigned int) rv)); |
|
(unsigned int) rv); |
|
|
#endif |
|
681 |
rv = SCARD_E_INVALID_HANDLE; |
rv = SCARD_E_INVALID_HANDLE; |
682 |
} |
} |
|
#ifdef WITH_SCARD_DEBUG |
|
683 |
else |
else |
684 |
printf("<--SUCCESS SCardListReaders (no SCardIsValidContext)-->\n"); |
{ |
685 |
#endif |
DEBUG_SCARD(("<--SUCCESS SCardListReaders (no SCardIsValidContext)-->\n")); |
686 |
outForceAllignment(out, 8); |
} |
687 |
|
|
688 |
|
outForceAlignment(out, 8); |
689 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
690 |
return rv; |
return rv; |
691 |
} |
} |
705 |
|
|
706 |
in->p += 0x2C; |
in->p += 0x2C; |
707 |
in_uint32_le(in, hContext); |
in_uint32_le(in, hContext); |
708 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[CONTEXT 0x%.8x]\n", (unsigned int) hContext)); |
|
printf("[CONTEXT 0x%.8x]\n", (unsigned int) hContext); |
|
|
#endif |
|
709 |
plen1 = out->p; |
plen1 = out->p; |
710 |
out_uint32_le(out, 0x00000000); /* Temp value for data length as 0x0 */ |
out_uint32_le(out, 0x00000000); /* Temp value for data length as 0x0 */ |
711 |
out_uint32_le(out, 0x01760650); |
out_uint32_le(out, 0x01760650); |
726 |
{ |
{ |
727 |
int i; |
int i; |
728 |
PSCNameMapRec tmpMap; |
PSCNameMapRec tmpMap; |
729 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
730 |
printf("[CALL RESULT of SCardListReaders 0x%.8x]\n", (unsigned int) rv); |
DEBUG_SCARD(("[CALL RESULT of SCardListReaders 0x%.8x]\n", (unsigned int) rv)); |
731 |
hexdump((void *) readers, cchReaders); |
hexdump((void *) readers, cchReaders); |
732 |
#endif |
#endif |
733 |
for (i = 0, tmpMap = nameMapList; i < nameMapCount; i++, tmpMap++) |
for (i = 0, tmpMap = nameMapList; i < nameMapCount; i++, tmpMap++) |
758 |
out_uint32_le(out, dataLength); |
out_uint32_le(out, dataLength); |
759 |
out->p = pend; |
out->p = pend; |
760 |
|
|
761 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
762 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
763 |
return rv; |
return rv; |
764 |
} |
} |
781 |
in->p += 0x1C; |
in->p += 0x1C; |
782 |
in_uint32_le(in, dwShareMode); |
in_uint32_le(in, dwShareMode); |
783 |
in_uint32_le(in, dwPreferredProtocol); |
in_uint32_le(in, dwPreferredProtocol); |
784 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[SHARE %8x]\n", (unsigned int) dwShareMode)); |
785 |
printf("[SHARE %8x]\n", (unsigned int) dwShareMode); |
DEBUG_SCARD(("[PROTO %8x]\n", (unsigned int) dwPreferredProtocol)); |
|
printf("[PROTO %8x]\n", (unsigned int) dwPreferredProtocol); |
|
|
#endif |
|
786 |
inReaderName(&lcHandle, in, &szReader, wide); |
inReaderName(&lcHandle, in, &szReader, wide); |
787 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[CONNECT TO READER \"%s\"\n", (szReader != NULL) ? (szReader) : ("NULL"))); |
|
printf("[CONNECT TO READER \"%s\"\n", (szReader != NULL) ? (szReader) : ("NULL")); |
|
|
#endif |
|
788 |
in->p += 0x04; |
in->p += 0x04; |
789 |
in_uint32_le(in, hContext); |
in_uint32_le(in, hContext); |
790 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[CONTEXT 0x%.8x]\n", (unsigned int) hContext)); |
|
printf("[CONTEXT 0x%.8x]\n", (unsigned int) hContext); |
|
|
#endif |
|
791 |
rv = SCardConnect(hContext, szReader, (MYPCSC_DWORD) dwShareMode, |
rv = SCardConnect(hContext, szReader, (MYPCSC_DWORD) dwShareMode, |
792 |
(MYPCSC_DWORD) dwPreferredProtocol, &myHCard, &dwActiveProtocol); |
(MYPCSC_DWORD) dwPreferredProtocol, &myHCard, &dwActiveProtocol); |
793 |
hCard = scHandleToServer(myHCard); |
hCard = scHandleToServer(myHCard); |
794 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[RECEIVED HCARD 0x%016lx]\n", (unsigned long) myHCard)); |
795 |
printf("[RECEIVED HCARD 0x%016lx]\n", myHCard); |
DEBUG_SCARD(("[MANGLED HCARD 0x%08x]\n", hCard)); |
|
printf("[MANGLED HCARD 0x%08x]\n", hCard); |
|
|
#endif |
|
796 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
797 |
{ |
{ |
798 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<--ERROR SCardConnect Code=0x%.8x-->\n", (unsigned int) rv)); |
|
printf("<--ERROR SCardConnect Code=0x%.8x-->\n", (unsigned int) rv); |
|
|
#endif |
|
799 |
} |
} |
800 |
else |
else |
801 |
{ |
{ |
802 |
char *szVendor = getVendor(szReader); |
char *szVendor = getVendor(szReader); |
803 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<--SUCCESS ScardConnect-->\n")); |
|
printf("<--SUCCESS ScardConnect-->\n"); |
|
|
#endif |
|
804 |
if (szVendor && (strlen(szVendor) > 0)) |
if (szVendor && (strlen(szVendor) > 0)) |
805 |
{ |
{ |
806 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("Set Attribute ATTR_VENDOR_NAME\n")); |
|
printf("Set Attribute ATTR_VENDOR_NAME\n"); |
|
|
#endif |
|
807 |
pthread_mutex_lock(&hcardAccess); |
pthread_mutex_lock(&hcardAccess); |
808 |
PSCHCardRec hcard = xmalloc(sizeof(TSCHCardRec)); |
PSCHCardRec hcard = xmalloc(sizeof(TSCHCardRec)); |
809 |
if (hcard) |
if (hcard) |
833 |
out_uint32_le(out, 0x00000004); |
out_uint32_le(out, 0x00000004); |
834 |
out_uint32_le(out, hCard); |
out_uint32_le(out, hCard); |
835 |
|
|
836 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
837 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
838 |
return rv; |
return rv; |
839 |
} |
} |
859 |
in->p += 0x04; |
in->p += 0x04; |
860 |
in_uint32_le(in, hCard); |
in_uint32_le(in, hCard); |
861 |
myHCard = scHandleToMyPCSC(hCard); |
myHCard = scHandleToMyPCSC(hCard); |
862 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[SHARE = 0x%.8x]\n", (unsigned int) dwShareMode)); |
863 |
printf("[SHARE = 0x%.8x]\n", (unsigned int) dwShareMode); |
DEBUG_SCARD(("[PROTO = 0x%.8x]\n", (unsigned int) dwPreferredProtocol)); |
864 |
printf("[PROTO = 0x%.8x]\n", (unsigned int) dwPreferredProtocol); |
DEBUG_SCARD(("[INIT = 0x%.8x]\n", (unsigned int) dwInitialization)); |
865 |
printf("[INIT = 0x%.8x]\n", (unsigned int) dwInitialization); |
DEBUG_SCARD(("[hContext = 0x%.8x]\n", (unsigned int) hContext)); |
866 |
printf("[hContext = 0x%.8x]\n", (unsigned int) hContext); |
DEBUG_SCARD(("[hCard = 0x%.8x]\n", (unsigned int) hCard)); |
867 |
printf("[hCard = 0x%.8x]\n", (unsigned int) hCard); |
DEBUG_SCARD(("[myHCard = 0x%016lx]\n", (unsigned long) myHCard)); |
|
printf("[myHCard = 0x%016lx]\n", myHCard); |
|
|
#endif |
|
868 |
rv = SCardReconnect(myHCard, (MYPCSC_DWORD) dwShareMode, (MYPCSC_DWORD) dwPreferredProtocol, |
rv = SCardReconnect(myHCard, (MYPCSC_DWORD) dwShareMode, (MYPCSC_DWORD) dwPreferredProtocol, |
869 |
(MYPCSC_DWORD) dwInitialization, &dwActiveProtocol); |
(MYPCSC_DWORD) dwInitialization, &dwActiveProtocol); |
|
#ifdef WITH_SCARD_DEBUG |
|
870 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
871 |
printf("<--ERROR SCardReconnect Code=0x%.8x-->\n", (unsigned int) rv); |
{ |
872 |
|
DEBUG_SCARD(("<--ERROR SCardReconnect Code=0x%.8x-->\n", (unsigned int) rv)); |
873 |
|
} |
874 |
else |
else |
875 |
printf("<--SUCCESS SCardReconnect-->\n"); |
{ |
876 |
#endif |
DEBUG_SCARD(("<--SUCCESS SCardReconnect-->\n")); |
877 |
|
} |
878 |
|
|
879 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
880 |
out_uint32_le(out, (SERVER_DWORD) dwActiveProtocol); |
out_uint32_le(out, (SERVER_DWORD) dwActiveProtocol); |
881 |
return rv; |
return rv; |
882 |
} |
} |
897 |
in->p += 0x04; |
in->p += 0x04; |
898 |
in_uint32_le(in, hCard); |
in_uint32_le(in, hCard); |
899 |
|
|
900 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[hContext = 0x%.8x]\n", (unsigned int) hContext)); |
901 |
printf("[hContext = 0x%.8x]\n", (unsigned int) hContext); |
DEBUG_SCARD(("[hCard = 0x%.8x]\n", (unsigned int) hCard)); |
902 |
printf("[hCard = 0x%.8x]\n", (unsigned int) hCard); |
DEBUG_SCARD(("[dwDisposition = 0x%.8x]\n", (unsigned int) dwDisposition)); |
|
printf("[dwDisposition = 0x%.8x]\n", (unsigned int) dwDisposition); |
|
|
#endif |
|
903 |
|
|
904 |
pthread_mutex_lock(&hcardAccess); |
pthread_mutex_lock(&hcardAccess); |
905 |
PSCHCardRec hcard = hcardFirst; |
PSCHCardRec hcard = hcardFirst; |
923 |
myHCard = scHandleToMyPCSC(hCard); |
myHCard = scHandleToMyPCSC(hCard); |
924 |
rv = SCardDisconnect(myHCard, (MYPCSC_DWORD) dwDisposition); |
rv = SCardDisconnect(myHCard, (MYPCSC_DWORD) dwDisposition); |
925 |
|
|
|
#ifdef WITH_SCARD_DEBUG |
|
926 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
927 |
printf("<--ERROR SCardDisconnect Code=0x%.8x-->\n", (unsigned int) rv); |
{ |
928 |
|
DEBUG_SCARD(("<--ERROR SCardDisconnect Code=0x%.8x-->\n", (unsigned int) rv)); |
929 |
|
} |
930 |
else |
else |
931 |
printf("<--SUCCESS SCardDisconnect-->\n"); |
{ |
932 |
#endif |
DEBUG_SCARD(("<--SUCCESS SCardDisconnect-->\n")); |
933 |
outForceAllignment(out, 8); |
} |
934 |
|
|
935 |
|
outForceAlignment(out, 8); |
936 |
return rv; |
return rv; |
937 |
} |
} |
938 |
|
|
1039 |
in->p += 0x08; |
in->p += 0x08; |
1040 |
in_uint32_le(in, hContext); |
in_uint32_le(in, hContext); |
1041 |
in->p += 0x04; |
in->p += 0x04; |
1042 |
#ifdef WITH_SCARD_DEBUG |
|
1043 |
printf("[CONTEXT 0x%.8x]\n", (unsigned int) hContext); |
DEBUG_SCARD(("[CONTEXT 0x%.8x]\n", (unsigned int) hContext)); |
1044 |
printf("[dwTimeout 0x%.8x]\n", (unsigned int) dwTimeout); |
DEBUG_SCARD(("[dwTimeout 0x%.8x]\n", (unsigned int) dwTimeout)); |
1045 |
printf("[COUNT %d]\n", (unsigned int) dwCount); |
DEBUG_SCARD(("[COUNT %d]\n", (unsigned int) dwCount)); |
1046 |
printf("[TYPE SIZE %d]\n", (unsigned int) sizeof(SERVER_SCARD_READERSTATE_A)); |
DEBUG_SCARD(("[TYPE SIZE %d]\n", (unsigned int) sizeof(SERVER_SCARD_READERSTATE_A))); |
1047 |
#endif |
|
1048 |
if (dwCount > 0) |
if (dwCount > 0) |
1049 |
{ |
{ |
1050 |
rsArray = SC_xmalloc(&lcHandle, dwCount * sizeof(SERVER_SCARD_READERSTATE_A)); |
rsArray = SC_xmalloc(&lcHandle, dwCount * sizeof(SERVER_SCARD_READERSTATE_A)); |
1061 |
in->p += 0x04; |
in->p += 0x04; |
1062 |
in_uint8a(in, cur, SERVER_SCARDSTATESIZE); |
in_uint8a(in, cur, SERVER_SCARDSTATESIZE); |
1063 |
} |
} |
1064 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
1065 |
printf("[READERS DUMP 1]------------------\n"); |
DEBUG_SCARD(("[READERS DUMP 1]------------------\n")); |
1066 |
hexdump((void *) rsArray, dwCount * sizeof(SERVER_SCARD_READERSTATE_A)); |
hexdump((void *) rsArray, dwCount * sizeof(SERVER_SCARD_READERSTATE_A)); |
1067 |
#endif |
#endif |
1068 |
|
|
1099 |
|
|
1100 |
in->p += 0x08; |
in->p += 0x08; |
1101 |
in_uint32_le(in, dataLength); |
in_uint32_le(in, dataLength); |
1102 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[%d] Data Length %d]\n", (unsigned int) i, dataLength)); |
|
printf("[%d] Data Length %d]\n", (unsigned int) i, dataLength); |
|
|
#endif |
|
1103 |
inRepos(in, |
inRepos(in, |
1104 |
inString(&lcHandle, in, (char **) &(cur->szReader), dataLength, |
inString(&lcHandle, in, (char **) &(cur->szReader), dataLength, |
1105 |
wide)); |
wide)); |
1107 |
if (strcmp(cur->szReader, "\\\\?PnP?\\Notification") == 0) |
if (strcmp(cur->szReader, "\\\\?PnP?\\Notification") == 0) |
1108 |
cur->dwCurrentState |= SCARD_STATE_IGNORE; |
cur->dwCurrentState |= SCARD_STATE_IGNORE; |
1109 |
} |
} |
1110 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
1111 |
printf("[READERS DUMP 2]------------------\n"); |
DEBUG_SCARD(("[READERS DUMP 2]------------------\n")); |
1112 |
hexdump((void *) rsArray, dwCount * sizeof(SERVER_SCARD_READERSTATE_A)); |
hexdump((void *) rsArray, dwCount * sizeof(SERVER_SCARD_READERSTATE_A)); |
1113 |
#endif |
#endif |
1114 |
} |
} |
1118 |
stateArray = NULL; |
stateArray = NULL; |
1119 |
} |
} |
1120 |
|
|
1121 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("\nCalling SCardGetStatusChange...\n")); |
|
printf("\nCalling SCardGetStatusChange...\n"); |
|
|
#endif |
|
1122 |
|
|
1123 |
|
|
1124 |
myRsArray = SC_xmalloc(&lcHandle, dwCount * sizeof(MYPCSC_SCARD_READERSTATE_A)); |
myRsArray = SC_xmalloc(&lcHandle, dwCount * sizeof(MYPCSC_SCARD_READERSTATE_A)); |
1126 |
return SC_returnNoMemoryError(&lcHandle, in, out); |
return SC_returnNoMemoryError(&lcHandle, in, out); |
1127 |
memset(myRsArray, 0, dwCount * sizeof(SERVER_SCARD_READERSTATE_A)); |
memset(myRsArray, 0, dwCount * sizeof(SERVER_SCARD_READERSTATE_A)); |
1128 |
copyReaderState_ServerToMyPCSC(rsArray, myRsArray, (SERVER_DWORD) dwCount); |
copyReaderState_ServerToMyPCSC(rsArray, myRsArray, (SERVER_DWORD) dwCount); |
1129 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
1130 |
printf("[TRANSLATION OF READERS]--------------------\n"); |
DEBUG_SCARD(("[TRANSLATION OF READERS]--------------------\n")); |
1131 |
hexdump((void *) myRsArray, dwCount * sizeof(MYPCSC_SCARD_READERSTATE_A)); |
hexdump((void *) myRsArray, dwCount * sizeof(MYPCSC_SCARD_READERSTATE_A)); |
1132 |
#endif |
#endif |
1133 |
|
|
1135 |
myRsArray, (MYPCSC_DWORD) dwCount); |
myRsArray, (MYPCSC_DWORD) dwCount); |
1136 |
copyReaderState_MyPCSCToServer(myRsArray, rsArray, (MYPCSC_DWORD) dwCount); |
copyReaderState_MyPCSCToServer(myRsArray, rsArray, (MYPCSC_DWORD) dwCount); |
1137 |
|
|
|
#ifdef WITH_SCARD_DEBUG |
|
1138 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
1139 |
printf("<--ERROR SCardGetStatusChange Code=0x%.8x-->\n", (unsigned int) rv); |
{ |
1140 |
|
DEBUG_SCARD(("<--ERROR SCardGetStatusChange Code=0x%.8x-->\n", (unsigned int) rv)); |
1141 |
|
} |
1142 |
else |
else |
1143 |
printf("<--SUCCESS SCardGetStatusChange-->\n"); |
{ |
1144 |
|
DEBUG_SCARD(("<--SUCCESS SCardGetStatusChange-->\n")); |
1145 |
|
} |
1146 |
|
|
1147 |
|
#ifdef WITH_DEBUG_SCARD |
1148 |
if (dwCount > 0) |
if (dwCount > 0) |
1149 |
{ |
{ |
1150 |
printf("[READERS DUMP]------------------\n"); |
DEBUG_SCARD(("[READERS DUMP]------------------\n")); |
1151 |
hexdump((void *) rsArray, dwCount * sizeof(SERVER_SCARD_READERSTATE_A)); |
hexdump((void *) rsArray, dwCount * sizeof(SERVER_SCARD_READERSTATE_A)); |
1152 |
} |
} |
1153 |
#endif |
#endif |
1189 |
out_uint8p(out, (void *) ((unsigned char **) cur + 2), |
out_uint8p(out, (void *) ((unsigned char **) cur + 2), |
1190 |
sizeof(SERVER_SCARD_READERSTATE_A) - 2 * sizeof(unsigned char *)); |
sizeof(SERVER_SCARD_READERSTATE_A) - 2 * sizeof(unsigned char *)); |
1191 |
} |
} |
1192 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
1193 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
1194 |
return rv; |
return rv; |
1195 |
} |
} |
1202 |
|
|
1203 |
in->p += 0x1C; |
in->p += 0x1C; |
1204 |
in_uint32_le(in, hContext); |
in_uint32_le(in, hContext); |
1205 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[CONTEXT 0x%.8x]\n", (unsigned int) hContext)); |
1206 |
printf("[CONTEXT 0x%.8x]\n", (unsigned int) hContext); |
DEBUG_SCARD(("Canceling... \n")); |
|
printf("Canceling... \n"); |
|
|
#endif |
|
1207 |
rv = SCardCancel((MYPCSC_SCARDCONTEXT) hContext); |
rv = SCardCancel((MYPCSC_SCARDCONTEXT) hContext); |
|
#ifdef WITH_SCARD_DEBUG |
|
1208 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
1209 |
printf("<--ERROR SCardCancel Code=0x%.8x-->\n", (unsigned int) rv); |
{ |
1210 |
|
DEBUG_SCARD(("<--ERROR SCardCancel Code=0x%.8x-->\n", (unsigned int) rv)); |
1211 |
|
} |
1212 |
else |
else |
1213 |
printf("<--SUCCESS SCardCancel-->\n"); |
{ |
1214 |
#endif |
DEBUG_SCARD(("<--SUCCESS SCardCancel-->\n")); |
1215 |
outForceAllignment(out, 8); |
} |
1216 |
|
outForceAlignment(out, 8); |
1217 |
return rv; |
return rv; |
1218 |
} |
} |
1219 |
|
|
1234 |
|
|
1235 |
in->p += 0x2C; |
in->p += 0x2C; |
1236 |
in_uint32_le(in, hContext); |
in_uint32_le(in, hContext); |
1237 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[CONTEXT 0x%.8x]\n", (unsigned int) hContext)); |
|
printf("[CONTEXT 0x%.8x]\n", (unsigned int) hContext); |
|
|
#endif |
|
1238 |
in_uint32_le(in, atrMaskCount); |
in_uint32_le(in, atrMaskCount); |
1239 |
pAtrMasks = SC_xmalloc(&lcHandle, atrMaskCount * sizeof(SCARD_ATRMASK_L)); |
pAtrMasks = SC_xmalloc(&lcHandle, atrMaskCount * sizeof(SCARD_ATRMASK_L)); |
1240 |
if (!pAtrMasks) |
if (!pAtrMasks) |
1262 |
for (i = 0, rsCur = rsArray; i < readerCount; i++, rsCur++) |
for (i = 0, rsCur = rsArray; i < readerCount; i++, rsCur++) |
1263 |
{ |
{ |
1264 |
inReaderName(&lcHandle, in, (char **) &rsCur->szReader, wide); |
inReaderName(&lcHandle, in, (char **) &rsCur->szReader, wide); |
1265 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[CHECK READER %s]\n", |
1266 |
printf("[CHECK READER %s]\n", (rsCur->szReader) ? (rsCur->szReader) : ("NULL")); |
(rsCur->szReader) ? (rsCur->szReader) : ("NULL"))); |
|
#endif |
|
1267 |
} |
} |
1268 |
|
|
1269 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[CALL subfunction \"SCardGetStatusChange\"]\n")); |
|
printf("[CALL subfunction \"SCardGetStatusChange\"]\n"); |
|
|
#endif |
|
1270 |
/* FIXME segfault here. */ |
/* FIXME segfault here. */ |
1271 |
myRsArray = SC_xmalloc(&lcHandle, readerCount * sizeof(MYPCSC_SCARD_READERSTATE_A)); |
myRsArray = SC_xmalloc(&lcHandle, readerCount * sizeof(MYPCSC_SCARD_READERSTATE_A)); |
1272 |
if (!myRsArray) |
if (!myRsArray) |
1276 |
copyReaderState_MyPCSCToServer(myRsArray, rsArray, readerCount); |
copyReaderState_MyPCSCToServer(myRsArray, rsArray, readerCount); |
1277 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
1278 |
{ |
{ |
1279 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<--ERROR SCardGetStatusChange (no SCardLocateCardsByATR) Code=0x%.8x-->\n", (unsigned int) rv)); |
|
printf("<--ERROR SCardGetStatusChange (no SCardLocateCardsByATR) Code=0x%.8x-->\n", |
|
|
(unsigned int) rv); |
|
|
#endif |
|
1280 |
} |
} |
1281 |
else |
else |
1282 |
{ |
{ |
1283 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<--SUCCESS SCardGetStatusChange (no SCardLocateCardsByATR)-->\n")); |
|
printf("<--SUCCESS SCardGetStatusChange (no SCardLocateCardsByATR)-->\n"); |
|
|
#endif |
|
1284 |
cur = pAtrMasks; |
cur = pAtrMasks; |
1285 |
for (i = 0, cur = pAtrMasks; i < atrMaskCount; i++, cur++) |
for (i = 0, cur = pAtrMasks; i < atrMaskCount; i++, cur++) |
1286 |
{ |
{ |
1300 |
} |
} |
1301 |
if (equal) |
if (equal) |
1302 |
{ |
{ |
1303 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[FOUND]\n")); |
|
printf("[FOUND]\n"); |
|
|
#endif |
|
1304 |
rsCur->dwEventState |= 0x00000040; /* SCARD_STATE_ATRMATCH 0x00000040 */ |
rsCur->dwEventState |= 0x00000040; /* SCARD_STATE_ATRMATCH 0x00000040 */ |
1305 |
memcpy(ResArray + j, rsCur, sizeof(SCARD_READERSTATE_A)); |
memcpy(ResArray + j, rsCur, sizeof(SCARD_READERSTATE_A)); |
1306 |
} |
} |
1318 |
sizeof(SCARD_READERSTATE_A) - 2 * sizeof(unsigned char *)); |
sizeof(SCARD_READERSTATE_A) - 2 * sizeof(unsigned char *)); |
1319 |
} |
} |
1320 |
|
|
1321 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
1322 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
1323 |
return rv; |
return rv; |
1324 |
} |
} |
1333 |
in->p += 0x30; |
in->p += 0x30; |
1334 |
in_uint32_le(in, hCard); |
in_uint32_le(in, hCard); |
1335 |
myHCard = scHandleToMyPCSC(hCard); |
myHCard = scHandleToMyPCSC(hCard); |
1336 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[hCard = 0x%.8x]\n", (unsigned int) hCard)); |
1337 |
printf("[hCard = 0x%.8x]\n", (unsigned int) hCard); |
DEBUG_SCARD(("[myHCard = 0x%016lx]\n", (unsigned long) myHCard)); |
|
printf("[myHCard = 0x%016lx]\n", myHCard); |
|
|
#endif |
|
1338 |
rv = SCardBeginTransaction(myHCard); |
rv = SCardBeginTransaction(myHCard); |
|
#ifdef WITH_SCARD_DEBUG |
|
1339 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
1340 |
printf("<--ERROR SCardBeginTransaction Code=0x%.8x-->\n", (unsigned int) rv); |
{ |
1341 |
|
DEBUG_SCARD(("<--ERROR SCardBeginTransaction Code=0x%.8x-->\n", (unsigned int) rv)); |
1342 |
|
} |
1343 |
else |
else |
1344 |
printf("<--SUCCESS SCardBeginTransaction-->\n"); |
{ |
1345 |
#endif |
DEBUG_SCARD(("<--SUCCESS SCardBeginTransaction-->\n")); |
1346 |
outForceAllignment(out, 8); |
} |
1347 |
|
outForceAlignment(out, 8); |
1348 |
return rv; |
return rv; |
1349 |
} |
} |
1350 |
|
|
1361 |
in->p += 0x0C; |
in->p += 0x0C; |
1362 |
in_uint32_le(in, hCard); |
in_uint32_le(in, hCard); |
1363 |
myHCard = scHandleToMyPCSC(hCard); |
myHCard = scHandleToMyPCSC(hCard); |
1364 |
#ifdef WITH_SCARD_DEBUG |
|
1365 |
printf("[hCard = 0x%.8x]\n", (unsigned int) hCard); |
DEBUG_SCARD(("[hCard = 0x%.8x]\n", (unsigned int) hCard)); |
1366 |
printf("[myHCard = 0x%016lx]\n", myHCard); |
DEBUG_SCARD(("[myHCard = 0x%016lx]\n", (unsigned long) myHCard)); |
1367 |
printf("[dwDisposition = 0x%.8x]\n", (unsigned int) dwDisposition); |
DEBUG_SCARD(("[dwDisposition = 0x%.8x]\n", (unsigned int) dwDisposition)); |
1368 |
#endif |
|
1369 |
rv = SCardEndTransaction(myHCard, (MYPCSC_DWORD) dwDisposition); |
rv = SCardEndTransaction(myHCard, (MYPCSC_DWORD) dwDisposition); |
|
#ifdef WITH_SCARD_DEBUG |
|
1370 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
1371 |
printf("<--ERROR SCardEndTransaction Code=0x%.8x-->\n", (unsigned int) rv); |
{ |
1372 |
|
DEBUG_SCARD(("<--ERROR SCardEndTransaction Code=0x%.8x-->\n", (unsigned int) rv)); |
1373 |
|
} |
1374 |
else |
else |
1375 |
printf("<--SUCCESS SCardEndTransaction-->\n"); |
{ |
1376 |
#endif |
DEBUG_SCARD(("<--SUCCESS SCardEndTransaction-->\n")); |
1377 |
outForceAllignment(out, 8); |
} |
1378 |
|
outForceAlignment(out, 8); |
1379 |
return rv; |
return rv; |
1380 |
} |
} |
1381 |
|
|
1474 |
|
|
1475 |
if (cbRecvLength) |
if (cbRecvLength) |
1476 |
{ |
{ |
|
/* FIXME: handle responses with length > 448 bytes */ |
|
|
if (cbRecvLength > 448) |
|
|
{ |
|
|
#ifdef WITH_SCARD_DEBUG |
|
|
printf("[RECV LEN %d -> %d]\n", (unsigned int) cbRecvLength, 400); |
|
|
#endif |
|
|
cbRecvLength = 448; |
|
|
} |
|
|
|
|
|
|
|
1477 |
recvBuf = SC_xmalloc(&lcHandle, cbRecvLength); |
recvBuf = SC_xmalloc(&lcHandle, cbRecvLength); |
1478 |
if (!recvBuf) |
if (!recvBuf) |
1479 |
return SC_returnNoMemoryError(&lcHandle, in, out); |
return SC_returnNoMemoryError(&lcHandle, in, out); |
1507 |
else |
else |
1508 |
pioRecvPci = NULL; |
pioRecvPci = NULL; |
1509 |
|
|
1510 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
1511 |
printf("++++++++++\n"); |
DEBUG_SCARD(("++++++++++\n")); |
1512 |
printf("[SEND LEN = %d]\n", (unsigned int) cbSendLength); |
DEBUG_SCARD(("[SEND LEN = %d]\n", (unsigned int) cbSendLength)); |
1513 |
printf("[RECV LEN = %d]\n", (unsigned int) cbRecvLength); |
DEBUG_SCARD(("[RECV LEN = %d]\n", (unsigned int) cbRecvLength)); |
1514 |
printf("[hCard = 0x%.8x]\n", (unsigned int) hCard); |
DEBUG_SCARD(("[hCard = 0x%.8x]\n", (unsigned int) hCard)); |
1515 |
printf("[myHCard = 0x%016lx]\n", myHCard); |
DEBUG_SCARD(("[myHCard = 0x%016lx]\n", (unsigned long) myHCard)); |
1516 |
printf("[pioSendPci]\n"); |
DEBUG_SCARD(("[pioSendPci]\n")); |
1517 |
if (pioSendPci == NULL) |
if (pioSendPci == NULL) |
1518 |
printf("NULL\n"); |
{ |
1519 |
|
DEBUG_SCARD(("NULL\n")); |
1520 |
|
} |
1521 |
else |
else |
1522 |
|
{ |
1523 |
hexdump((void *) pioSendPci, pioSendPci->cbPciLength); |
hexdump((void *) pioSendPci, pioSendPci->cbPciLength); |
1524 |
printf("[pioRecvPci]\n"); |
} |
1525 |
|
|
1526 |
|
DEBUG_SCARD(("[pioRecvPci]\n")); |
1527 |
if (pioRecvPci == NULL) |
if (pioRecvPci == NULL) |
1528 |
printf("NULL\n"); |
{ |
1529 |
|
DEBUG_SCARD(("NULL\n")); |
1530 |
|
} |
1531 |
else |
else |
1532 |
|
{ |
1533 |
hexdump((void *) pioRecvPci, pioRecvPci->cbPciLength); |
hexdump((void *) pioRecvPci, pioRecvPci->cbPciLength); |
1534 |
printf("[sendBuf]\n"); |
} |
1535 |
|
DEBUG_SCARD(("[sendBuf]\n")); |
1536 |
hexdump(sendBuf, cbSendLength); |
hexdump(sendBuf, cbSendLength); |
1537 |
printf("++++++++++\n"); |
DEBUG_SCARD(("++++++++++\n")); |
1538 |
#endif |
#endif |
1539 |
|
|
1540 |
myCbRecvLength = cbRecvLength; |
myCbRecvLength = cbRecvLength; |
1562 |
rv = SCardTransmit(myHCard, myPioSendPci, sendBuf, (MYPCSC_DWORD) cbSendLength, |
rv = SCardTransmit(myHCard, myPioSendPci, sendBuf, (MYPCSC_DWORD) cbSendLength, |
1563 |
myPioRecvPci, recvBuf, &myCbRecvLength); |
myPioRecvPci, recvBuf, &myCbRecvLength); |
1564 |
cbRecvLength = myCbRecvLength; |
cbRecvLength = myCbRecvLength; |
1565 |
|
|
1566 |
|
/* FIXME: handle responses with length > 448 bytes */ |
1567 |
|
if (cbRecvLength > 448) |
1568 |
|
{ |
1569 |
|
warning("Card response limited from %d to 448 bytes!\n", cbRecvLength); |
1570 |
|
DEBUG_SCARD(("[RECV LEN %d -> %d]\n", (unsigned int) cbRecvLength, 400)); |
1571 |
|
cbRecvLength = 448; |
1572 |
|
} |
1573 |
|
|
1574 |
if (pioRecvPci) |
if (pioRecvPci) |
1575 |
{ |
{ |
1576 |
copyIORequest_MyPCSCToServer(myPioRecvPci, pioRecvPci); |
copyIORequest_MyPCSCToServer(myPioRecvPci, pioRecvPci); |
1578 |
|
|
1579 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
1580 |
{ |
{ |
1581 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<--ERROR SCardTransmit Code=0x%.8x-->\n", (unsigned int) rv)); |
|
printf("<--ERROR SCardTransmit Code=0x%.8x-->\n", (unsigned int) rv); |
|
|
#endif |
|
1582 |
} |
} |
1583 |
else |
else |
1584 |
{ |
{ |
1585 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
1586 |
printf("<--SUCCESS SCardTransmit-->\n"); |
DEBUG_SCARD(("<--SUCCESS SCardTransmit-->\n")); |
1587 |
printf("RESULT %d\n", (unsigned int) cbRecvLength); |
DEBUG_SCARD(("RESULT %d\n", (unsigned int) cbRecvLength)); |
1588 |
hexdump(recvBuf, cbRecvLength); |
hexdump(recvBuf, cbRecvLength); |
1589 |
if (myPioRecvPci) |
if (myPioRecvPci) |
1590 |
{ |
{ |
1591 |
printf("--- myPioRecvPci ---\n"); |
DEBUG_SCARD(("--- myPioRecvPci ---\n")); |
1592 |
hexdump((void *) myPioRecvPci, myPioRecvPci->cbPciLength); |
hexdump((void *) myPioRecvPci, myPioRecvPci->cbPciLength); |
1593 |
} |
} |
1594 |
printf("------------------\n"); |
DEBUG_SCARD(("------------------\n")); |
1595 |
#endif |
#endif |
1596 |
#if 0 |
#if 0 |
1597 |
if ((pioRecvPci != NULL) && (pioRecvPci->cbPciLength > 0)) |
if ((pioRecvPci != NULL) && (pioRecvPci->cbPciLength > 0)) |
1618 |
|
|
1619 |
outBufferFinish(out, (char *) recvBuf, cbRecvLength); |
outBufferFinish(out, (char *) recvBuf, cbRecvLength); |
1620 |
} |
} |
1621 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
1622 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
1623 |
return rv; |
return rv; |
1624 |
} |
} |
1643 |
in_uint32_le(in, hCard); |
in_uint32_le(in, hCard); |
1644 |
in->p += 0x04; |
in->p += 0x04; |
1645 |
myHCard = scHandleToMyPCSC(hCard); |
myHCard = scHandleToMyPCSC(hCard); |
1646 |
#ifdef WITH_SCARD_DEBUG |
|
1647 |
printf("[hCard 0x%.8x]\n", (unsigned int) hCard); |
DEBUG_SCARD(("[hCard 0x%.8x]\n", (unsigned int) hCard)); |
1648 |
printf("[myHCard 0x%016lx]\n", myHCard); |
DEBUG_SCARD(("[myHCard 0x%016lx]\n", (unsigned long) myHCard)); |
1649 |
printf("[dwReaderLen %d]\n", (unsigned int) dwReaderLen); |
DEBUG_SCARD(("[dwReaderLen %d]\n", (unsigned int) dwReaderLen)); |
1650 |
printf("[dwAtrLen %d]\n", (unsigned int) dwAtrLen); |
DEBUG_SCARD(("[dwAtrLen %d]\n", (unsigned int) dwAtrLen)); |
|
#endif |
|
1651 |
|
|
1652 |
if (dwReaderLen <= 0 || dwReaderLen == SCARD_AUTOALLOCATE || dwReaderLen > SCARD_MAX_MEM) |
if (dwReaderLen <= 0 || dwReaderLen == SCARD_AUTOALLOCATE || dwReaderLen > SCARD_MAX_MEM) |
1653 |
dwReaderLen = SCARD_MAX_MEM; |
dwReaderLen = SCARD_MAX_MEM; |
1675 |
|
|
1676 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
1677 |
{ |
{ |
1678 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<--ERROR SCardStatus Code=0x%.8x-->\n", (unsigned int) rv)); |
|
printf("<--ERROR SCardStatus Code=0x%.8x-->\n", (unsigned int) rv); |
|
|
#endif |
|
1679 |
return SC_returnCode(rv, &lcHandle, in, out); |
return SC_returnCode(rv, &lcHandle, in, out); |
1680 |
} |
} |
1681 |
else |
else |
1682 |
{ |
{ |
1683 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
1684 |
printf("<--SUCCESS SCardStatus-->\n"); |
DEBUG_SCARD(("<--SUCCESS SCardStatus-->\n")); |
1685 |
printf("[dwState 0x%.8x]\n", (unsigned int) dwState); |
DEBUG_SCARD(("[dwState 0x%.8x]\n", (unsigned int) dwState)); |
1686 |
printf("[dwProtocol 0x%.8x]\n", (unsigned int) dwProtocol); |
DEBUG_SCARD(("[dwProtocol 0x%.8x]\n", (unsigned int) dwProtocol)); |
1687 |
printf("[Reader Name]\n"); |
DEBUG_SCARD(("[Reader Name]\n")); |
1688 |
hexdump((unsigned char *) readerName, dwReaderLen); |
hexdump((unsigned char *) readerName, dwReaderLen); |
1689 |
printf("[Atr]\n"); |
DEBUG_SCARD(("[Atr]\n")); |
1690 |
hexdump(atr, dwAtrLen); |
hexdump(atr, dwAtrLen); |
1691 |
#endif |
#endif |
1692 |
if (dwState & (SCARD_SPECIFIC | SCARD_NEGOTIABLE)) |
if (dwState & (SCARD_SPECIFIC | SCARD_NEGOTIABLE)) |
1734 |
out_uint32_le(out, dataLength); |
out_uint32_le(out, dataLength); |
1735 |
out->p = psave; |
out->p = psave; |
1736 |
} |
} |
1737 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
1738 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
1739 |
return rv; |
return rv; |
1740 |
} |
} |
1757 |
in_uint32_le(in, hCard); |
in_uint32_le(in, hCard); |
1758 |
in->p += 0x04; |
in->p += 0x04; |
1759 |
myHCard = scHandleToMyPCSC(hCard); |
myHCard = scHandleToMyPCSC(hCard); |
|
#ifdef WITH_SCARD_DEBUG |
|
|
printf("[hCard 0x%.8x]\n", (unsigned int) hCard); |
|
|
printf("[myHCard 0x%.8x]\n", (unsigned int) myHCard); |
|
|
printf("[dwAtrLen %d]\n", (unsigned int) dwAtrLen); |
|
|
#endif |
|
1760 |
|
|
1761 |
|
DEBUG_SCARD(("[hCard 0x%.8x]\n", (unsigned int) hCard)); |
1762 |
|
DEBUG_SCARD(("[myHCard 0x%.8x]\n", (unsigned int) myHCard)); |
1763 |
|
DEBUG_SCARD(("[dwAtrLen %d]\n", (unsigned int) dwAtrLen)); |
1764 |
|
|
1765 |
dwReaderLen = SCARD_MAX_MEM; |
dwReaderLen = SCARD_MAX_MEM; |
1766 |
if (dwAtrLen <= 0 || dwAtrLen == SCARD_AUTOALLOCATE || dwAtrLen > SCARD_MAX_MEM) |
if (dwAtrLen <= 0 || dwAtrLen == SCARD_AUTOALLOCATE || dwAtrLen > SCARD_MAX_MEM) |
1786 |
|
|
1787 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
1788 |
{ |
{ |
1789 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<--ERROR SCardStatus (no ScardState) Code=0x%.8x-->\n", |
1790 |
printf("<--ERROR SCardStatus (no ScardState) Code=0x%.8x-->\n", (unsigned int) rv); |
(unsigned int) rv)); |
|
#endif |
|
1791 |
return SC_returnCode(rv, &lcHandle, in, out); |
return SC_returnCode(rv, &lcHandle, in, out); |
1792 |
} |
} |
1793 |
else |
else |
1794 |
{ |
{ |
1795 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
1796 |
printf("<--SUCCESS SCardStatus (no ScardState)-->\n"); |
DEBUG_SCARD(("<--SUCCESS SCardStatus (no ScardState)-->\n")); |
1797 |
printf("[dwState 0x%.8x]\n", (unsigned int) dwState); |
DEBUG_SCARD(("[dwState 0x%.8x]\n", (unsigned int) dwState)); |
1798 |
printf("[dwProtocol 0x%.8x]\n", (unsigned int) dwProtocol); |
DEBUG_SCARD(("[dwProtocol 0x%.8x]\n", (unsigned int) dwProtocol)); |
1799 |
printf("[Atr]\n"); |
DEBUG_SCARD(("[Atr]\n")); |
1800 |
hexdump(atr, dwAtrLen); |
hexdump(atr, dwAtrLen); |
1801 |
#endif |
#endif |
1802 |
if (dwState & (SCARD_SPECIFIC | SCARD_NEGOTIABLE)) |
if (dwState & (SCARD_SPECIFIC | SCARD_NEGOTIABLE)) |
1828 |
out_uint8p(out, atr, dwAtrLen); |
out_uint8p(out, atr, dwAtrLen); |
1829 |
outRepos(out, dwAtrLen); |
outRepos(out, dwAtrLen); |
1830 |
} |
} |
1831 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
1832 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
1833 |
return rv; |
return rv; |
1834 |
} |
} |
1864 |
dwGroups = groups; |
dwGroups = groups; |
1865 |
|
|
1866 |
if (rv) |
if (rv) |
|
#ifdef WITH_SCARD_DEBUG |
|
1867 |
{ |
{ |
1868 |
printf("<--ERROR SCardListReaderGroups Code=0x%.8x-->\n", (unsigned int) rv); |
DEBUG_SCARD(("<--ERROR SCardListReaderGroups Code=0x%.8x-->\n", (unsigned int) rv)); |
|
#endif |
|
1869 |
return SC_returnCode(rv, &lcHandle, in, out); |
return SC_returnCode(rv, &lcHandle, in, out); |
|
#ifdef WITH_SCARD_DEBUG |
|
1870 |
} |
} |
1871 |
else |
else |
1872 |
{ |
{ |
1873 |
printf("<--SUCCESS SCardListReaderGroups-->\n"); |
DEBUG_SCARD(("<--SUCCESS SCardListReaderGroups-->\n")); |
1874 |
} |
} |
|
#endif |
|
1875 |
|
|
1876 |
|
|
1877 |
out_uint32_le(out, dwGroups); |
out_uint32_le(out, dwGroups); |
1881 |
outRepos(out, dwGroups); |
outRepos(out, dwGroups); |
1882 |
out_uint32_le(out, 0x00000000); |
out_uint32_le(out, 0x00000000); |
1883 |
|
|
1884 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
1885 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
1886 |
return rv; |
return rv; |
1887 |
} |
} |
1907 |
|
|
1908 |
dwAttrId = dwAttrId & 0x0000FFFF; |
dwAttrId = dwAttrId & 0x0000FFFF; |
1909 |
|
|
1910 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[hCard = 0x%.8x]\n", (unsigned int) hCard)); |
1911 |
printf("[hCard = 0x%.8x]\n", (unsigned int) hCard); |
DEBUG_SCARD(("[myHCard 0x%.8x]\n", (unsigned int) myHCard)); |
1912 |
printf("[myHCard 0x%.8x]\n", (unsigned int) myHCard); |
DEBUG_SCARD(("[dwAttrId = 0x%.8x]\n", (unsigned int) dwAttrId)); |
1913 |
printf("[dwAttrId = 0x%.8x]\n", (unsigned int) dwAttrId); |
DEBUG_SCARD(("[dwAttrLen = 0x%.8x]\n", (unsigned int) dwAttrLen)); |
|
printf("[dwAttrLen = 0x%.8x]\n", (unsigned int) dwAttrLen); |
|
|
#endif |
|
1914 |
|
|
1915 |
if (dwAttrLen > MAX_BUFFER_SIZE) |
if (dwAttrLen > MAX_BUFFER_SIZE) |
1916 |
dwAttrLen = MAX_BUFFER_SIZE; |
dwAttrLen = MAX_BUFFER_SIZE; |
1936 |
|
|
1937 |
if (dwAttrId == 0x00000100 && rv != SCARD_S_SUCCESS) |
if (dwAttrId == 0x00000100 && rv != SCARD_S_SUCCESS) |
1938 |
{ |
{ |
1939 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("Get Attribute ATTR_VENDOR_NAME\n")); |
|
printf("Get Attribute ATTR_VENDOR_NAME\n"); |
|
|
#endif |
|
1940 |
pthread_mutex_lock(&hcardAccess); |
pthread_mutex_lock(&hcardAccess); |
1941 |
PSCHCardRec hcard = hcardFirst; |
PSCHCardRec hcard = hcardFirst; |
1942 |
while (hcard) |
while (hcard) |
1951 |
hcard = hcard->next; |
hcard = hcard->next; |
1952 |
} |
} |
1953 |
pthread_mutex_unlock(&hcardAccess); |
pthread_mutex_unlock(&hcardAccess); |
1954 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[0x%.8x]\n", (unsigned int) rv)); |
|
printf("[0x%.8x]\n", (unsigned int) rv); |
|
|
#endif |
|
1955 |
} |
} |
1956 |
|
|
1957 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
1958 |
{ |
{ |
1959 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<--ERROR SCardGetAttrib Code=0x%.8x-->\n", (unsigned int) rv)); |
|
printf("<--ERROR SCardGetAttrib Code=0x%.8x-->\n", (unsigned int) rv); |
|
|
#endif |
|
1960 |
return SC_returnCode(rv, &lcHandle, in, out); |
return SC_returnCode(rv, &lcHandle, in, out); |
1961 |
} |
} |
1962 |
else |
else |
1963 |
{ |
{ |
1964 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
1965 |
printf("<--SUCCESS SCardGetAttrib-->\n"); |
DEBUG_SCARD(("<--SUCCESS SCardGetAttrib-->\n")); |
1966 |
printf("[LENGTH %d]\n", (unsigned int) dwAttrLen); |
DEBUG_SCARD(("[LENGTH %d]\n", (unsigned int) dwAttrLen)); |
1967 |
printf("+++++++++++++++++++++\n"); |
DEBUG_SCARD(("+++++++++++++++++++++\n")); |
1968 |
hexdump(pbAttr, dwAttrLen); |
hexdump(pbAttr, dwAttrLen); |
1969 |
printf("+++++++++++++++++++++\n"); |
DEBUG_SCARD(("+++++++++++++++++++++\n")); |
1970 |
#endif |
#endif |
1971 |
out_uint32_le(out, dwAttrLen); |
out_uint32_le(out, dwAttrLen); |
1972 |
out_uint32_le(out, 0x00000200); |
out_uint32_le(out, 0x00000200); |
1982 |
outRepos(out, dwAttrLen); |
outRepos(out, dwAttrLen); |
1983 |
out_uint32_le(out, 0x00000000); |
out_uint32_le(out, 0x00000000); |
1984 |
} |
} |
1985 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
1986 |
return rv; |
return rv; |
1987 |
} |
} |
1988 |
|
|
2007 |
|
|
2008 |
dwAttrId = dwAttrId & 0x0000FFFF; |
dwAttrId = dwAttrId & 0x0000FFFF; |
2009 |
|
|
2010 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[hCard = 0x%.8x]\n", (unsigned int) hCard)); |
2011 |
printf("[hCard = 0x%.8x]\n", (unsigned int) hCard); |
DEBUG_SCARD(("[myHCard 0x%.8x]\n", (unsigned int) myHCard)); |
2012 |
printf("[myHCard 0x%.8x]\n", (unsigned int) myHCard); |
DEBUG_SCARD(("[dwAttrId = 0x%.8x]\n", (unsigned int) dwAttrId)); |
2013 |
printf("[dwAttrId = 0x%.8x]\n", (unsigned int) dwAttrId); |
DEBUG_SCARD(("[dwAttrLen = 0x%.8x]\n", (unsigned int) dwAttrLen)); |
|
printf("[dwAttrLen = 0x%.8x]\n", (unsigned int) dwAttrLen); |
|
|
#endif |
|
2014 |
|
|
2015 |
if (dwAttrLen > MAX_BUFFER_SIZE) |
if (dwAttrLen > MAX_BUFFER_SIZE) |
2016 |
dwAttrLen = MAX_BUFFER_SIZE; |
dwAttrLen = MAX_BUFFER_SIZE; |
2022 |
in_uint8a(in, pbAttr, dwAttrLen); |
in_uint8a(in, pbAttr, dwAttrLen); |
2023 |
rv = SCardSetAttrib(myHCard, (MYPCSC_DWORD) dwAttrId, pbAttr, (MYPCSC_DWORD) dwAttrLen); |
rv = SCardSetAttrib(myHCard, (MYPCSC_DWORD) dwAttrId, pbAttr, (MYPCSC_DWORD) dwAttrLen); |
2024 |
|
|
|
#ifdef WITH_SCARD_DEBUG |
|
2025 |
if (rv) |
if (rv) |
2026 |
printf("<--ERROR SCardSetAttrib Code=0x%.8x-->\n", (unsigned int) rv); |
{ |
2027 |
|
DEBUG_SCARD(("<--ERROR SCardSetAttrib Code=0x%.8x-->\n", (unsigned int) rv)); |
2028 |
|
} |
2029 |
else |
else |
2030 |
printf("<--SUCCESS SCardSetAttrib-->\n"); |
{ |
2031 |
#endif |
DEBUG_SCARD(("<--SUCCESS SCardSetAttrib-->\n")); |
2032 |
|
} |
2033 |
|
|
2034 |
out_uint32_le(out, 0x00000000); |
out_uint32_le(out, 0x00000000); |
2035 |
out_uint32_le(out, 0x00000200); |
out_uint32_le(out, 0x00000200); |
2036 |
out_uint32_le(out, 0x00000000); |
out_uint32_le(out, 0x00000000); |
2037 |
out_uint32_le(out, 0x00000000); |
out_uint32_le(out, 0x00000000); |
2038 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
2039 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
2040 |
return rv; |
return rv; |
2041 |
} |
} |
2051 |
MYPCSC_SCARDHANDLE myHCard; |
MYPCSC_SCARDHANDLE myHCard; |
2052 |
SERVER_DWORD map[3]; |
SERVER_DWORD map[3]; |
2053 |
SERVER_DWORD dwControlCode; |
SERVER_DWORD dwControlCode; |
2054 |
char *pInBuffer, *pOutBuffer; |
unsigned char *pInBuffer, *pOutBuffer; |
2055 |
SERVER_DWORD nInBufferSize, nOutBufferSize, nOutBufferRealSize, nBytesReturned; |
SERVER_DWORD nInBufferSize, nOutBufferSize, nOutBufferRealSize, nBytesReturned; |
2056 |
MYPCSC_DWORD sc_nBytesReturned; |
MYPCSC_DWORD sc_nBytesReturned; |
2057 |
PMEM_HANDLE lcHandle = NULL; |
PMEM_HANDLE lcHandle = NULL; |
2098 |
if (!pOutBuffer) |
if (!pOutBuffer) |
2099 |
return SC_returnNoMemoryError(&lcHandle, in, out); |
return SC_returnNoMemoryError(&lcHandle, in, out); |
2100 |
|
|
2101 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
2102 |
printf("[hContext = 0x%.8x]\n", (unsigned int) hContext); |
DEBUG_SCARD(("[hContext = 0x%.8x]\n", (unsigned int) hContext)); |
2103 |
printf("[hCard = 0x%.8x]\n", (unsigned int) hCard); |
DEBUG_SCARD(("[hCard = 0x%.8x]\n", (unsigned int) hCard)); |
2104 |
printf("[dwControlCode = 0x%.8x]\n", (unsigned int) dwControlCode); |
DEBUG_SCARD(("[dwControlCode = 0x%.8x]\n", (unsigned int) dwControlCode)); |
2105 |
printf("[nInBufferSize = %d]\n", (unsigned int) nInBufferSize); |
DEBUG_SCARD(("[nInBufferSize = %d]\n", (unsigned int) nInBufferSize)); |
2106 |
printf("[nOutBufferSize = %d]\n", (unsigned int) nOutBufferSize); |
DEBUG_SCARD(("[nOutBufferSize = %d]\n", (unsigned int) nOutBufferSize)); |
2107 |
if (nInBufferSize > 0) |
if (nInBufferSize > 0) |
2108 |
{ |
{ |
2109 |
printf("[In buffer]\n"); |
DEBUG_SCARD(("[In buffer]\n")); |
2110 |
hexdump((unsigned char *) pInBuffer, nInBufferSize); |
hexdump((unsigned char *) pInBuffer, nInBufferSize); |
2111 |
} |
} |
2112 |
printf("---> Calling SCardControl\n"); |
DEBUG_SCARD(("---> Calling SCardControl\n")); |
2113 |
#endif |
#endif |
2114 |
|
|
|
#ifdef WITH_PCSC120 |
|
2115 |
sc_nBytesReturned = nBytesReturned; |
sc_nBytesReturned = nBytesReturned; |
2116 |
myHCard = scHandleToMyPCSC(hCard); |
myHCard = scHandleToMyPCSC(hCard); |
2117 |
|
#ifdef WITH_PCSC120 |
2118 |
rv = SCardControl(myHCard, pInBuffer, (MYPCSC_DWORD) nInBufferSize, pOutBuffer, |
rv = SCardControl(myHCard, pInBuffer, (MYPCSC_DWORD) nInBufferSize, pOutBuffer, |
2119 |
&sc_nBytesReturned); |
&sc_nBytesReturned); |
|
nBytesReturned = sc_nBytesReturned; |
|
2120 |
#else |
#else |
|
sc_nBytesReturned = nBytesReturned; |
|
|
myHCard = scHandleToMyPCSC(hCard); |
|
2121 |
rv = SCardControl(myHCard, (MYPCSC_DWORD) dwControlCode, pInBuffer, |
rv = SCardControl(myHCard, (MYPCSC_DWORD) dwControlCode, pInBuffer, |
2122 |
(MYPCSC_DWORD) nInBufferSize, pOutBuffer, |
(MYPCSC_DWORD) nInBufferSize, pOutBuffer, |
2123 |
(MYPCSC_DWORD) nOutBufferRealSize, &sc_nBytesReturned); |
(MYPCSC_DWORD) nOutBufferRealSize, &sc_nBytesReturned); |
|
nBytesReturned = sc_nBytesReturned; |
|
2124 |
#endif |
#endif |
2125 |
|
nBytesReturned = sc_nBytesReturned; |
2126 |
|
|
2127 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
2128 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
2129 |
printf("<--ERROR SCardControl Code=0x%.8x-->\n", (unsigned int) rv); |
{ |
2130 |
|
DEBUG_SCARD(("<--ERROR SCardControl Code=0x%.8x-->\n", (unsigned int) rv)); |
2131 |
|
} |
2132 |
else |
else |
2133 |
{ |
{ |
2134 |
printf("<--SUCCESS SCardControl-->\n"); |
DEBUG_SCARD(("<--SUCCESS SCardControl-->\n")); |
2135 |
printf("[LENGTH %d]\n", (unsigned int) nBytesReturned); |
DEBUG_SCARD(("[LENGTH %d]\n", (unsigned int) nBytesReturned)); |
2136 |
printf("+++++++++++++++++++++\n"); |
DEBUG_SCARD(("+++++++++++++++++++++\n")); |
2137 |
hexdump((unsigned char *) pOutBuffer, nBytesReturned); |
hexdump((unsigned char *) pOutBuffer, nBytesReturned); |
2138 |
printf("+++++++++++++++++++++\n"); |
DEBUG_SCARD(("+++++++++++++++++++++\n")); |
2139 |
} |
} |
2140 |
#endif |
#endif |
2141 |
|
|
2148 |
outRepos(out, nBytesReturned); |
outRepos(out, nBytesReturned); |
2149 |
} |
} |
2150 |
|
|
2151 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
2152 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
2153 |
return rv; |
return rv; |
2154 |
} |
} |
2167 |
SERVER_DWORD Result = 0x00000000; |
SERVER_DWORD Result = 0x00000000; |
2168 |
unsigned char *psize, *pend, *pStatusCode; |
unsigned char *psize, *pend, *pStatusCode; |
2169 |
SERVER_DWORD addToEnd = 0; |
SERVER_DWORD addToEnd = 0; |
2170 |
|
#ifdef WITH_DEBUG_SCARD |
|
#ifdef WITH_SCARD_DEBUG |
|
2171 |
unsigned char *pbeg = out->p; |
unsigned char *pbeg = out->p; |
2172 |
printf("--------------------------------\n"); |
|
2173 |
printf("[NTHANDLE %08X]\n", handle); |
DEBUG_SCARD(("--------------------------------\n")); |
2174 |
printf("[REQUEST %08X]\n", request); |
DEBUG_SCARD(("[NTHANDLE %08X]\n", handle)); |
2175 |
printf("[INPUT DUMP]--------------------\n"); |
DEBUG_SCARD(("[REQUEST %08X]\n", request)); |
2176 |
|
DEBUG_SCARD(("[INPUT DUMP]--------------------\n")); |
2177 |
hexdump(in->p, in->end - in->p); |
hexdump(in->p, in->end - in->p); |
2178 |
#endif |
#endif |
2179 |
/* Processing request */ |
/* Processing request */ |
2191 |
/* SCardEstablishContext */ |
/* SCardEstablishContext */ |
2192 |
case SC_ESTABLISH_CONTEXT: |
case SC_ESTABLISH_CONTEXT: |
2193 |
{ |
{ |
2194 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardEstablishContext--->\n")); |
|
printf("<---SCardEstablishContext--->\n"); |
|
|
#endif |
|
2195 |
Result = (SERVER_DWORD) TS_SCardEstablishContext(in, out); |
Result = (SERVER_DWORD) TS_SCardEstablishContext(in, out); |
2196 |
break; |
break; |
2197 |
} |
} |
2198 |
/* SCardReleaseContext */ |
/* SCardReleaseContext */ |
2199 |
case SC_RELEASE_CONTEXT: |
case SC_RELEASE_CONTEXT: |
2200 |
{ |
{ |
2201 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardReleaseContext--->\n")); |
|
printf("<---SCardReleaseContext--->\n"); |
|
|
#endif |
|
2202 |
Result = (SERVER_DWORD) TS_SCardReleaseContext(in, out); |
Result = (SERVER_DWORD) TS_SCardReleaseContext(in, out); |
2203 |
break; |
break; |
2204 |
} |
} |
2205 |
/* SCardIsValidContext */ |
/* SCardIsValidContext */ |
2206 |
case SC_IS_VALID_CONTEXT: |
case SC_IS_VALID_CONTEXT: |
2207 |
{ |
{ |
2208 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardIsValidContext--->\n")); |
|
printf("<---SCardIsValidContext--->\n"); |
|
|
#endif |
|
2209 |
Result = (SERVER_DWORD) TS_SCardIsValidContext(in, out); |
Result = (SERVER_DWORD) TS_SCardIsValidContext(in, out); |
2210 |
break; |
break; |
2211 |
} |
} |
2214 |
case SC_LIST_READERS + 4: /* SCardListReadersW */ |
case SC_LIST_READERS + 4: /* SCardListReadersW */ |
2215 |
{ |
{ |
2216 |
BOOL wide = request != SC_LIST_READERS; |
BOOL wide = request != SC_LIST_READERS; |
2217 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardListReaders---> (%s)\n", |
2218 |
printf("<---SCardListReaders---> (%s)\n", |
(wide) ? ("WIDE") : ("ASCII"))); |
|
(wide) ? ("WIDE") : ("ASCII")); |
|
|
#endif |
|
2219 |
Result = (SERVER_DWORD) TS_SCardListReaders(in, out, wide); |
Result = (SERVER_DWORD) TS_SCardListReaders(in, out, wide); |
2220 |
break; |
break; |
2221 |
} |
} |
2224 |
case SC_CONNECT + 4: /* SCardConnectW */ |
case SC_CONNECT + 4: /* SCardConnectW */ |
2225 |
{ |
{ |
2226 |
BOOL wide = request != SC_CONNECT; |
BOOL wide = request != SC_CONNECT; |
2227 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardConnect---> (%s)\n", |
2228 |
printf("<---SCardConnect---> (%s)\n", |
(wide) ? ("WIDE") : ("ASCII"))); |
|
(wide) ? ("WIDE") : ("ASCII")); |
|
|
#endif |
|
2229 |
Result = (SERVER_DWORD) TS_SCardConnect(in, out, wide); |
Result = (SERVER_DWORD) TS_SCardConnect(in, out, wide); |
2230 |
break; |
break; |
2231 |
} |
} |
2232 |
/* ScardReconnect */ |
/* ScardReconnect */ |
2233 |
case SC_RECONNECT: |
case SC_RECONNECT: |
2234 |
{ |
{ |
2235 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardReconnect--->\n")); |
|
printf("<---SCardReconnect--->\n"); |
|
|
#endif |
|
2236 |
Result = (SERVER_DWORD) TS_SCardReconnect(in, out); |
Result = (SERVER_DWORD) TS_SCardReconnect(in, out); |
2237 |
break; |
break; |
2238 |
} |
} |
2239 |
/* ScardDisconnect */ |
/* ScardDisconnect */ |
2240 |
case SC_DISCONNECT: |
case SC_DISCONNECT: |
2241 |
{ |
{ |
2242 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardDisconnect--->\n")); |
|
printf("<---SCardDisconnect--->\n"); |
|
|
#endif |
|
2243 |
Result = (SERVER_DWORD) TS_SCardDisconnect(in, out); |
Result = (SERVER_DWORD) TS_SCardDisconnect(in, out); |
2244 |
break; |
break; |
2245 |
} |
} |
2248 |
case SC_GET_STATUS_CHANGE + 4: /* SCardGetStatusChangeW */ |
case SC_GET_STATUS_CHANGE + 4: /* SCardGetStatusChangeW */ |
2249 |
{ |
{ |
2250 |
BOOL wide = request != SC_GET_STATUS_CHANGE; |
BOOL wide = request != SC_GET_STATUS_CHANGE; |
2251 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardGetStatusChange---> (%s)\n", |
2252 |
printf("<---SCardGetStatusChange---> (%s)\n", |
(wide) ? ("WIDE") : ("ASCII"))); |
|
(wide) ? ("WIDE") : ("ASCII")); |
|
|
#endif |
|
2253 |
Result = (SERVER_DWORD) TS_SCardGetStatusChange(in, out, wide); |
Result = (SERVER_DWORD) TS_SCardGetStatusChange(in, out, wide); |
2254 |
break; |
break; |
2255 |
} |
} |
2256 |
/* SCardCancel */ |
/* SCardCancel */ |
2257 |
case SC_CANCEL: |
case SC_CANCEL: |
2258 |
{ |
{ |
2259 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardCancel--->\n")); |
|
printf("<---SCardCancel--->\n"); |
|
|
#endif |
|
2260 |
Result = (SERVER_DWORD) TS_SCardCancel(in, out); |
Result = (SERVER_DWORD) TS_SCardCancel(in, out); |
2261 |
break; |
break; |
2262 |
} |
} |
2265 |
case SC_LOCATE_CARDS_BY_ATR + 4: /* SCardLocateCardsByATRW */ |
case SC_LOCATE_CARDS_BY_ATR + 4: /* SCardLocateCardsByATRW */ |
2266 |
{ |
{ |
2267 |
BOOL wide = request != SC_LOCATE_CARDS_BY_ATR; |
BOOL wide = request != SC_LOCATE_CARDS_BY_ATR; |
2268 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardLocateCardsByATR---> (%s)\n", |
2269 |
printf("<---SCardLocateCardsByATR---> (%s)\n", |
(wide) ? ("WIDE") : ("ASCII"))); |
|
(wide) ? ("WIDE") : ("ASCII")); |
|
|
#endif |
|
2270 |
Result = (SERVER_DWORD) TS_SCardLocateCardsByATR(in, out, wide); |
Result = (SERVER_DWORD) TS_SCardLocateCardsByATR(in, out, wide); |
2271 |
break; |
break; |
2272 |
} |
} |
2273 |
/* SCardBeginTransaction */ |
/* SCardBeginTransaction */ |
2274 |
case SC_BEGIN_TRANSACTION: |
case SC_BEGIN_TRANSACTION: |
2275 |
{ |
{ |
2276 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardBeginTransaction--->\n")); |
|
printf("<---SCardBeginTransaction--->\n"); |
|
|
#endif |
|
2277 |
Result = (SERVER_DWORD) TS_SCardBeginTransaction(in, out); |
Result = (SERVER_DWORD) TS_SCardBeginTransaction(in, out); |
2278 |
break; |
break; |
2279 |
} |
} |
2280 |
/* SCardBeginTransaction */ |
/* SCardBeginTransaction */ |
2281 |
case SC_END_TRANSACTION: |
case SC_END_TRANSACTION: |
2282 |
{ |
{ |
2283 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardEndTransaction--->\n")); |
|
printf("<---SCardEndTransaction--->\n"); |
|
|
#endif |
|
2284 |
Result = (SERVER_DWORD) TS_SCardEndTransaction(in, out); |
Result = (SERVER_DWORD) TS_SCardEndTransaction(in, out); |
2285 |
break; |
break; |
2286 |
} |
} |
2287 |
/* ScardTransmit */ |
/* ScardTransmit */ |
2288 |
case SC_TRANSMIT: |
case SC_TRANSMIT: |
2289 |
{ |
{ |
2290 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardTransmit--->\n")); |
|
printf("<---SCardTransmit--->\n"); |
|
|
#endif |
|
2291 |
Result = (SERVER_DWORD) TS_SCardTransmit(in, out); |
Result = (SERVER_DWORD) TS_SCardTransmit(in, out); |
2292 |
break; |
break; |
2293 |
} |
} |
2294 |
/* SCardControl */ |
/* SCardControl */ |
2295 |
case SC_CONTROL: |
case SC_CONTROL: |
2296 |
{ |
{ |
2297 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardControl--->\n")); |
|
printf("<---SCardControl--->\n"); |
|
|
#endif |
|
2298 |
Result = (SERVER_DWORD) TS_SCardControl(in, out); |
Result = (SERVER_DWORD) TS_SCardControl(in, out); |
2299 |
break; |
break; |
2300 |
} |
} |
2302 |
#ifndef WITH_PCSC120 |
#ifndef WITH_PCSC120 |
2303 |
case SC_GETATTRIB: |
case SC_GETATTRIB: |
2304 |
{ |
{ |
2305 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardGetAttrib--->\n")); |
|
printf("<---SCardGetAttrib--->\n"); |
|
|
#endif |
|
2306 |
Result = (SERVER_DWORD) TS_SCardGetAttrib(in, out); |
Result = (SERVER_DWORD) TS_SCardGetAttrib(in, out); |
2307 |
break; |
break; |
2308 |
} |
} |
2309 |
#endif |
#endif |
2310 |
case SC_ACCESS_STARTED_EVENT: |
case SC_ACCESS_STARTED_EVENT: |
2311 |
{ |
{ |
2312 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardAccessStartedEvent-->\n")); |
|
printf("<---SCardAccessStartedEvent-->\n"); |
|
|
#endif |
|
2313 |
Result = (SERVER_DWORD) TS_SCardAccessStartedEvent(in, out); |
Result = (SERVER_DWORD) TS_SCardAccessStartedEvent(in, out); |
2314 |
break; |
break; |
2315 |
} |
} |
2317 |
case SC_STATUS + 4: /* SCardStatusW */ |
case SC_STATUS + 4: /* SCardStatusW */ |
2318 |
{ |
{ |
2319 |
BOOL wide = request != SC_STATUS; |
BOOL wide = request != SC_STATUS; |
2320 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardStatus---> (%s)\n", |
2321 |
printf("<---SCardStatus---> (%s)\n", (wide) ? ("WIDE") : ("ASCII")); |
(wide) ? ("WIDE") : ("ASCII"))); |
|
#endif |
|
2322 |
Result = (SERVER_DWORD) TS_SCardStatus(in, out, wide); |
Result = (SERVER_DWORD) TS_SCardStatus(in, out, wide); |
2323 |
break; |
break; |
2324 |
} |
} |
2325 |
case SC_STATE: /* SCardState */ |
case SC_STATE: /* SCardState */ |
2326 |
{ |
{ |
2327 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardState--->")); |
|
printf("<---SCardState--->"); |
|
|
#endif |
|
2328 |
Result = (SERVER_DWORD) TS_SCardState(in, out); |
Result = (SERVER_DWORD) TS_SCardState(in, out); |
2329 |
break; |
break; |
2330 |
} |
} |
2331 |
default: |
default: |
2332 |
{ |
{ |
2333 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---UNSUPPORTED-FUNC--->\n")); |
|
printf("<---UNSUPPORTED-FUNC--->\n"); |
|
|
#endif |
|
2334 |
Result = 0x80100014; |
Result = 0x80100014; |
2335 |
out_uint8s(out, 256); |
out_uint8s(out, 256); |
2336 |
break; |
break; |
2357 |
out_uint8s(out, addToEnd); |
out_uint8s(out, addToEnd); |
2358 |
} |
} |
2359 |
|
|
2360 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
2361 |
printf("[OUTPUT DUMP]-------------------\n"); |
DEBUG_SCARD(("[OUTPUT DUMP]-------------------\n")); |
2362 |
hexdump(pbeg, (size_t) (out->p) - (size_t) pbeg); |
hexdump(pbeg, (size_t) (out->p) - (size_t) pbeg); |
2363 |
printf("--------------------------------\n"); |
DEBUG_SCARD(("--------------------------------\n")); |
2364 |
#endif |
#endif |
2365 |
return STATUS_SUCCESS; |
return STATUS_SUCCESS; |
2366 |
} |
} |
2497 |
size_t buffer_len = 0; |
size_t buffer_len = 0; |
2498 |
scard_device_control(data->handle, data->request, data->in, data->out); |
scard_device_control(data->handle, data->request, data->in, data->out); |
2499 |
buffer_len = (size_t) data->out->p - (size_t) data->out->data; |
buffer_len = (size_t) data->out->p - (size_t) data->out->data; |
|
#if 0 |
|
2500 |
pthread_mutex_lock(&sendControl); |
pthread_mutex_lock(&sendControl); |
|
#endif |
|
2501 |
rdpdr_send_completion(data->device, data->id, 0, buffer_len, data->out->data, buffer_len); |
rdpdr_send_completion(data->device, data->id, 0, buffer_len, data->out->data, buffer_len); |
|
#if 0 |
|
2502 |
pthread_mutex_unlock(&sendControl); |
pthread_mutex_unlock(&sendControl); |
|
#endif |
|
2503 |
SC_destroyThreadData(data); |
SC_destroyThreadData(data); |
2504 |
} |
} |
2505 |
|
|
2507 |
static void * |
static void * |
2508 |
thread_function(PThreadListElement listElement) |
thread_function(PThreadListElement listElement) |
2509 |
{ |
{ |
2510 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
2511 |
long sTime = 0; |
long sTime = 0; |
2512 |
#endif |
#endif |
2513 |
if ((listElement != NULL) && (listElement->data != NULL)) |
if ((listElement != NULL) && (listElement->data != NULL)) |
2514 |
{ |
{ |
2515 |
while (1) |
while (1) |
2516 |
{ |
{ |
2517 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
2518 |
sTime = time(NULL); |
sTime = time(NULL); |
2519 |
#endif |
#endif |
2520 |
pthread_mutex_lock(&listElement->nodata); |
pthread_mutex_lock(&listElement->nodata); |
2521 |
SC_deviceControl(listElement->data); |
SC_deviceControl(listElement->data); |
2522 |
listElement->data = NULL; |
listElement->data = NULL; |
2523 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[HANDLING TIME %d]\n", (int) (time(NULL) - sTime))); |
|
printf("[HANDLING TIME %d]\n", (int) (time(NULL) - sTime)); |
|
|
#endif |
|
2524 |
pthread_mutex_unlock(&listElement->busy); |
pthread_mutex_unlock(&listElement->busy); |
2525 |
} |
} |
2526 |
} |
} |
2534 |
int Result = 0; |
int Result = 0; |
2535 |
PThreadListElement cur = threadList, last = threadList; |
PThreadListElement cur = threadList, last = threadList; |
2536 |
|
|
2537 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[THREAD COUNT %d]\n", threadCount)); |
|
printf("[THREAD COUNT %d]\n", threadCount); |
|
|
#endif |
|
2538 |
|
|
2539 |
while (cur) |
while (cur) |
2540 |
{ |
{ |
2567 |
Result = pthread_create(&cur->thread, NULL, (void *(*)(void *)) thread_function, cur); |
Result = pthread_create(&cur->thread, NULL, (void *(*)(void *)) thread_function, cur); |
2568 |
if (0 != Result) |
if (0 != Result) |
2569 |
{ |
{ |
2570 |
printf("[THREAD CREATE ERROR 0x%.8x]\n", Result); |
error("[THREAD CREATE ERROR 0x%.8x]\n", Result); |
2571 |
SC_xfree(&threadListHandle, cur); |
SC_xfree(&threadListHandle, cur); |
2572 |
SC_destroyThreadData(data); |
SC_destroyThreadData(data); |
2573 |
data = NULL; |
data = NULL; |
2632 |
{ |
{ |
2633 |
if (!tcp_sendcontrol_mutex) |
if (!tcp_sendcontrol_mutex) |
2634 |
{ |
{ |
2635 |
tcp_sendcontrol_mutex = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t)); |
tcp_sendcontrol_mutex = (pthread_mutex_t *) xmalloc(sizeof(pthread_mutex_t)); |
2636 |
pthread_mutex_init(tcp_sendcontrol_mutex, NULL); |
pthread_mutex_init(tcp_sendcontrol_mutex, NULL); |
2637 |
} |
} |
2638 |
|
|