44 |
|
|
45 |
static struct stream out[STREAM_COUNT]; |
static struct stream out[STREAM_COUNT]; |
46 |
static int cur_stream_id = 0; |
static int cur_stream_id = 0; |
47 |
static pthread_mutex_t *tcp_sendcontrol_mutex = NULL; |
static pthread_mutex_t **scard_mutex = NULL; |
48 |
|
|
49 |
static uint32 curDevice = 0, curId = 0, curBytesOut = 0; |
static uint32 curDevice = 0, curId = 0, curBytesOut = 0; |
50 |
static PSCNameMapRec nameMapList = NULL; |
static PSCNameMapRec nameMapList = NULL; |
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; |
|
/* static pthread_mutex_t sendControl; */ |
|
57 |
|
|
58 |
static PMEM_HANDLE threadListHandle = NULL; |
static PMEM_HANDLE threadListHandle = NULL; |
59 |
static PThreadListElement threadList = NULL; |
static PThreadListElement threadList = NULL; |
125 |
rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); |
rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); |
126 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
127 |
{ |
{ |
128 |
printf("[SMART CARD: PCSC service not available]\n"); |
error("[SMART CARD: PCSC service not available]\n"); |
129 |
return 0; |
return 0; |
130 |
} |
} |
131 |
else |
else |
135 |
|
|
136 |
if (0 != pthread_mutex_init(&queueAccess, NULL)) |
if (0 != pthread_mutex_init(&queueAccess, NULL)) |
137 |
{ |
{ |
138 |
printf("[SMART CARD: Can't initialize queue access mutex]\n"); |
error("[SMART CARD: Can't initialize queue access mutex]\n"); |
139 |
return 0; |
return 0; |
140 |
} |
} |
141 |
|
|
142 |
if (0 != pthread_mutex_init(&queueEmpty, NULL)) |
if (0 != pthread_mutex_init(&queueEmpty, NULL)) |
143 |
{ |
{ |
144 |
printf("[SMART CARD: Can't initialize queue control mutex]\n"); |
error("[SMART CARD: Can't initialize queue control mutex]\n"); |
145 |
return 0; |
return 0; |
146 |
} |
} |
147 |
|
|
148 |
if (0 != pthread_mutex_init(&hcardAccess, NULL)) |
if (0 != pthread_mutex_init(&hcardAccess, NULL)) |
149 |
{ |
{ |
150 |
printf("[SMART CARD: Can't initialize hcard list access mutex]\n"); |
error("[SMART CARD: Can't initialize hcard list access mutex]\n"); |
151 |
return 0; |
return 0; |
152 |
} |
} |
153 |
|
|
|
#if 0 |
|
|
if (0 != pthread_mutex_init(&sendControl, NULL)) |
|
|
{ |
|
|
printf("[SMART CARD: Can't initialize send control mutex]\n"); |
|
|
return 0; |
|
|
} |
|
|
#endif |
|
|
|
|
|
|
|
154 |
if (0 != |
if (0 != |
155 |
pthread_create(&queueHandler, NULL, (void *(*)(void *)) queue_handler_function, NULL)) |
pthread_create(&queueHandler, NULL, (void *(*)(void *)) queue_handler_function, NULL)) |
156 |
{ |
{ |
157 |
printf("[SMART CARD: Can't create queue handling Thread]\n"); |
error("[SMART CARD: Can't create queue handling Thread]\n"); |
158 |
return 0; |
return 0; |
159 |
} |
} |
160 |
|
|
223 |
} |
} |
224 |
} |
} |
225 |
|
|
|
|
|
|
printf("******************************************************\n"); |
|
|
printf("* Smart Card support for RDesktop is initialized. *\n"); |
|
|
printf("* Copyright (C) by Alexi Volkov, alexi@myrealbox.com *\n"); |
|
|
printf("******************************************************\n"); |
|
|
|
|
226 |
return count; |
return count; |
227 |
} |
} |
228 |
|
|
481 |
} |
} |
482 |
|
|
483 |
static void |
static void |
484 |
outForceAllignment(STREAM out, unsigned int seed) |
outForceAlignment(STREAM out, unsigned int seed) |
485 |
{ |
{ |
486 |
SERVER_DWORD add = (seed - (out->p - out->data) % seed) % seed; |
SERVER_DWORD add = (seed - (out->p - out->data) % seed) % seed; |
487 |
if (add > 0) |
if (add > 0) |
|
{ |
|
488 |
out_uint8s(out, add); |
out_uint8s(out, add); |
|
} |
|
489 |
} |
} |
490 |
|
|
491 |
static unsigned int |
static unsigned int |
602 |
MYPCSC_SCARDCONTEXT hContext; |
MYPCSC_SCARDCONTEXT hContext; |
603 |
/* code segment */ |
/* code segment */ |
604 |
|
|
605 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("Establishing PC/SC Context... \n")); |
|
printf("Establishing PC/SC Context... \n"); |
|
|
#endif |
|
606 |
rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); |
rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); |
|
#ifdef WITH_SCARD_DEBUG |
|
607 |
if (rv) |
if (rv) |
608 |
printf("<--ERROR SCardEstablishContext Code=0x%.8x]-->\n", (unsigned int) rv); |
{ |
609 |
|
DEBUG_SCARD(("<--ERROR SCardEstablishContext Code=0x%.8x, %s]-->\n", |
610 |
|
(unsigned int) rv, pcsc_stringify_error(rv))); |
611 |
|
} |
612 |
else |
else |
613 |
printf("<--SUCCESS SCardEstablishContext-->\n"); |
{ |
614 |
#endif |
DEBUG_SCARD(("<--SUCCESS SCardEstablishContext-->\n")); |
615 |
|
} |
616 |
|
|
617 |
out_uint32_le(out, 0x00000004); |
out_uint32_le(out, 0x00000004); |
618 |
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) */ |
630 |
|
|
631 |
in->p += 0x1C; |
in->p += 0x1C; |
632 |
in_uint32_le(in, hContext); |
in_uint32_le(in, hContext); |
633 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[CONTEXT 0x%.8x]\n", (unsigned int) hContext)); |
634 |
printf("[CONTEXT 0x%.8x]\n", (unsigned int) hContext); |
DEBUG_SCARD(("Releasing context... \n")); |
|
printf("Releasing context... \n"); |
|
|
#endif |
|
635 |
rv = SCardReleaseContext((MYPCSC_SCARDCONTEXT) hContext); |
rv = SCardReleaseContext((MYPCSC_SCARDCONTEXT) hContext); |
636 |
#ifdef WITH_SCARD_DEBUG |
|
637 |
if (rv) |
if (rv) |
638 |
printf("<--ERROR SCardReleaseContext Code=0x%.8x-->\n", (unsigned int) rv); |
{ |
639 |
|
DEBUG_SCARD(("<--ERROR SCardReleaseContext Code=0x%.8x, %s-->\n", (unsigned int) rv, |
640 |
|
pcsc_stringify_error(rv))); |
641 |
|
} |
642 |
else |
else |
643 |
printf("<--SUCCESS SCardReleaseContext-->\n"); |
{ |
644 |
#endif |
DEBUG_SCARD(("<--SUCCESS SCardReleaseContext-->\n")); |
645 |
|
} |
646 |
|
|
647 |
return rv; |
return rv; |
648 |
} |
} |
649 |
|
|
658 |
|
|
659 |
in->p += 0x1C; |
in->p += 0x1C; |
660 |
in_uint32_le(in, hContext); |
in_uint32_le(in, hContext); |
661 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[CONTEXT 0x%.8x]\n", (unsigned int) hContext)); |
662 |
printf("[CONTEXT 0x%.8x]\n", (unsigned int) hContext); |
DEBUG_SCARD(("Checking... \n")); |
|
printf("Checking... \n"); |
|
|
#endif |
|
663 |
/* 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 */ |
664 |
|
|
665 |
readers = SC_xmalloc(&lcHandle, 1024); |
readers = SC_xmalloc(&lcHandle, 1024); |
667 |
return SC_returnNoMemoryError(&lcHandle, in, out); |
return SC_returnNoMemoryError(&lcHandle, in, out); |
668 |
|
|
669 |
rv = SCardListReaders((MYPCSC_SCARDCONTEXT) hContext, NULL, readers, &readerCount); |
rv = SCardListReaders((MYPCSC_SCARDCONTEXT) hContext, NULL, readers, &readerCount); |
670 |
|
|
671 |
if (rv) |
if (rv) |
672 |
{ |
{ |
673 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<--ERROR SCardListReaders (no SCardIsValidContext) Code=0x%.8x, %s-->\n", (unsigned int) rv, pcsc_stringify_error(rv))); |
|
printf("<--ERROR SCardListReaders (no SCardIsValidContext) Code=0x%.8x-->\n", |
|
|
(unsigned int) rv); |
|
|
#endif |
|
674 |
rv = SCARD_E_INVALID_HANDLE; |
rv = SCARD_E_INVALID_HANDLE; |
675 |
} |
} |
|
#ifdef WITH_SCARD_DEBUG |
|
676 |
else |
else |
677 |
printf("<--SUCCESS SCardListReaders (no SCardIsValidContext)-->\n"); |
{ |
678 |
#endif |
DEBUG_SCARD(("<--SUCCESS SCardListReaders (no SCardIsValidContext)-->\n")); |
679 |
outForceAllignment(out, 8); |
} |
680 |
|
|
681 |
|
outForceAlignment(out, 8); |
682 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
683 |
return rv; |
return rv; |
684 |
} |
} |
698 |
|
|
699 |
in->p += 0x2C; |
in->p += 0x2C; |
700 |
in_uint32_le(in, hContext); |
in_uint32_le(in, hContext); |
701 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[CONTEXT 0x%.8x]\n", (unsigned int) hContext)); |
|
printf("[CONTEXT 0x%.8x]\n", (unsigned int) hContext); |
|
|
#endif |
|
702 |
plen1 = out->p; |
plen1 = out->p; |
703 |
out_uint32_le(out, 0x00000000); /* Temp value for data length as 0x0 */ |
out_uint32_le(out, 0x00000000); /* Temp value for data length as 0x0 */ |
704 |
out_uint32_le(out, 0x01760650); |
out_uint32_le(out, 0x01760650); |
719 |
{ |
{ |
720 |
int i; |
int i; |
721 |
PSCNameMapRec tmpMap; |
PSCNameMapRec tmpMap; |
722 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
723 |
printf("[CALL RESULT of SCardListReaders 0x%.8x]\n", (unsigned int) rv); |
DEBUG_SCARD(("[CALL RESULT of SCardListReaders 0x%.8x]\n", (unsigned int) rv)); |
724 |
hexdump((void *) readers, cchReaders); |
hexdump((void *) readers, cchReaders); |
725 |
#endif |
#endif |
726 |
for (i = 0, tmpMap = nameMapList; i < nameMapCount; i++, tmpMap++) |
for (i = 0, tmpMap = nameMapList; i < nameMapCount; i++, tmpMap++) |
751 |
out_uint32_le(out, dataLength); |
out_uint32_le(out, dataLength); |
752 |
out->p = pend; |
out->p = pend; |
753 |
|
|
754 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
755 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
756 |
return rv; |
return rv; |
757 |
} |
} |
774 |
in->p += 0x1C; |
in->p += 0x1C; |
775 |
in_uint32_le(in, dwShareMode); |
in_uint32_le(in, dwShareMode); |
776 |
in_uint32_le(in, dwPreferredProtocol); |
in_uint32_le(in, dwPreferredProtocol); |
777 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[SHARE %8x]\n", (unsigned int) dwShareMode)); |
778 |
printf("[SHARE %8x]\n", (unsigned int) dwShareMode); |
DEBUG_SCARD(("[PROTO %8x]\n", (unsigned int) dwPreferredProtocol)); |
|
printf("[PROTO %8x]\n", (unsigned int) dwPreferredProtocol); |
|
|
#endif |
|
779 |
inReaderName(&lcHandle, in, &szReader, wide); |
inReaderName(&lcHandle, in, &szReader, wide); |
780 |
#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 |
|
781 |
in->p += 0x04; |
in->p += 0x04; |
782 |
in_uint32_le(in, hContext); |
in_uint32_le(in, hContext); |
783 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[CONTEXT 0x%.8x]\n", (unsigned int) hContext)); |
|
printf("[CONTEXT 0x%.8x]\n", (unsigned int) hContext); |
|
|
#endif |
|
784 |
rv = SCardConnect(hContext, szReader, (MYPCSC_DWORD) dwShareMode, |
rv = SCardConnect(hContext, szReader, (MYPCSC_DWORD) dwShareMode, |
785 |
(MYPCSC_DWORD) dwPreferredProtocol, &myHCard, &dwActiveProtocol); |
(MYPCSC_DWORD) dwPreferredProtocol, &myHCard, &dwActiveProtocol); |
786 |
hCard = scHandleToServer(myHCard); |
hCard = scHandleToServer(myHCard); |
787 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[RECEIVED HCARD 0x%016lx]\n", (unsigned long) myHCard)); |
788 |
printf("[RECEIVED HCARD 0x%016lx]\n", myHCard); |
DEBUG_SCARD(("[MANGLED HCARD 0x%08x]\n", hCard)); |
|
printf("[MANGLED HCARD 0x%08x]\n", hCard); |
|
|
#endif |
|
789 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
790 |
{ |
{ |
791 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<--ERROR SCardConnect Code=0x%.8x, %s-->\n", (unsigned int) rv, |
792 |
printf("<--ERROR SCardConnect Code=0x%.8x-->\n", (unsigned int) rv); |
pcsc_stringify_error(rv))); |
|
#endif |
|
793 |
} |
} |
794 |
else |
else |
795 |
{ |
{ |
796 |
char *szVendor = getVendor(szReader); |
char *szVendor = getVendor(szReader); |
797 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<--SUCCESS ScardConnect-->\n")); |
|
printf("<--SUCCESS ScardConnect-->\n"); |
|
|
#endif |
|
798 |
if (szVendor && (strlen(szVendor) > 0)) |
if (szVendor && (strlen(szVendor) > 0)) |
799 |
{ |
{ |
800 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("Set Attribute ATTR_VENDOR_NAME\n")); |
|
printf("Set Attribute ATTR_VENDOR_NAME\n"); |
|
|
#endif |
|
801 |
pthread_mutex_lock(&hcardAccess); |
pthread_mutex_lock(&hcardAccess); |
802 |
PSCHCardRec hcard = xmalloc(sizeof(TSCHCardRec)); |
PSCHCardRec hcard = xmalloc(sizeof(TSCHCardRec)); |
803 |
if (hcard) |
if (hcard) |
827 |
out_uint32_le(out, 0x00000004); |
out_uint32_le(out, 0x00000004); |
828 |
out_uint32_le(out, hCard); |
out_uint32_le(out, hCard); |
829 |
|
|
830 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
831 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
832 |
return rv; |
return rv; |
833 |
} |
} |
853 |
in->p += 0x04; |
in->p += 0x04; |
854 |
in_uint32_le(in, hCard); |
in_uint32_le(in, hCard); |
855 |
myHCard = scHandleToMyPCSC(hCard); |
myHCard = scHandleToMyPCSC(hCard); |
856 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[SHARE = 0x%.8x]\n", (unsigned int) dwShareMode)); |
857 |
printf("[SHARE = 0x%.8x]\n", (unsigned int) dwShareMode); |
DEBUG_SCARD(("[PROTO = 0x%.8x]\n", (unsigned int) dwPreferredProtocol)); |
858 |
printf("[PROTO = 0x%.8x]\n", (unsigned int) dwPreferredProtocol); |
DEBUG_SCARD(("[INIT = 0x%.8x]\n", (unsigned int) dwInitialization)); |
859 |
printf("[INIT = 0x%.8x]\n", (unsigned int) dwInitialization); |
DEBUG_SCARD(("[hContext = 0x%.8x]\n", (unsigned int) hContext)); |
860 |
printf("[hContext = 0x%.8x]\n", (unsigned int) hContext); |
DEBUG_SCARD(("[hCard = 0x%.8x]\n", (unsigned int) hCard)); |
861 |
printf("[hCard = 0x%.8x]\n", (unsigned int) hCard); |
DEBUG_SCARD(("[myHCard = 0x%016lx]\n", (unsigned long) myHCard)); |
|
printf("[myHCard = 0x%016lx]\n", myHCard); |
|
|
#endif |
|
862 |
rv = SCardReconnect(myHCard, (MYPCSC_DWORD) dwShareMode, (MYPCSC_DWORD) dwPreferredProtocol, |
rv = SCardReconnect(myHCard, (MYPCSC_DWORD) dwShareMode, (MYPCSC_DWORD) dwPreferredProtocol, |
863 |
(MYPCSC_DWORD) dwInitialization, &dwActiveProtocol); |
(MYPCSC_DWORD) dwInitialization, &dwActiveProtocol); |
|
#ifdef WITH_SCARD_DEBUG |
|
864 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
865 |
printf("<--ERROR SCardReconnect Code=0x%.8x-->\n", (unsigned int) rv); |
{ |
866 |
|
DEBUG_SCARD(("<--ERROR SCardReconnect Code=0x%.8x, %s-->\n", (unsigned int) rv, |
867 |
|
pcsc_stringify_error(rv))); |
868 |
|
} |
869 |
else |
else |
870 |
printf("<--SUCCESS SCardReconnect-->\n"); |
{ |
871 |
#endif |
DEBUG_SCARD(("<--SUCCESS SCardReconnect-->\n")); |
872 |
|
} |
873 |
|
|
874 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
875 |
out_uint32_le(out, (SERVER_DWORD) dwActiveProtocol); |
out_uint32_le(out, (SERVER_DWORD) dwActiveProtocol); |
876 |
return rv; |
return rv; |
877 |
} |
} |
892 |
in->p += 0x04; |
in->p += 0x04; |
893 |
in_uint32_le(in, hCard); |
in_uint32_le(in, hCard); |
894 |
|
|
895 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[hContext = 0x%.8x]\n", (unsigned int) hContext)); |
896 |
printf("[hContext = 0x%.8x]\n", (unsigned int) hContext); |
DEBUG_SCARD(("[hCard = 0x%.8x]\n", (unsigned int) hCard)); |
897 |
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 |
|
898 |
|
|
899 |
pthread_mutex_lock(&hcardAccess); |
pthread_mutex_lock(&hcardAccess); |
900 |
PSCHCardRec hcard = hcardFirst; |
PSCHCardRec hcard = hcardFirst; |
918 |
myHCard = scHandleToMyPCSC(hCard); |
myHCard = scHandleToMyPCSC(hCard); |
919 |
rv = SCardDisconnect(myHCard, (MYPCSC_DWORD) dwDisposition); |
rv = SCardDisconnect(myHCard, (MYPCSC_DWORD) dwDisposition); |
920 |
|
|
|
#ifdef WITH_SCARD_DEBUG |
|
921 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
922 |
printf("<--ERROR SCardDisconnect Code=0x%.8x-->\n", (unsigned int) rv); |
{ |
923 |
|
DEBUG_SCARD(("<--ERROR SCardDisconnect Code=0x%.8x, %s-->\n", (unsigned int) rv, |
924 |
|
pcsc_stringify_error(rv))); |
925 |
|
} |
926 |
else |
else |
927 |
printf("<--SUCCESS SCardDisconnect-->\n"); |
{ |
928 |
#endif |
DEBUG_SCARD(("<--SUCCESS SCardDisconnect-->\n")); |
929 |
outForceAllignment(out, 8); |
} |
930 |
|
|
931 |
|
outForceAlignment(out, 8); |
932 |
return rv; |
return rv; |
933 |
} |
} |
934 |
|
|
1035 |
in->p += 0x08; |
in->p += 0x08; |
1036 |
in_uint32_le(in, hContext); |
in_uint32_le(in, hContext); |
1037 |
in->p += 0x04; |
in->p += 0x04; |
1038 |
#ifdef WITH_SCARD_DEBUG |
|
1039 |
printf("[CONTEXT 0x%.8x]\n", (unsigned int) hContext); |
DEBUG_SCARD(("[CONTEXT 0x%.8x]\n", (unsigned int) hContext)); |
1040 |
printf("[dwTimeout 0x%.8x]\n", (unsigned int) dwTimeout); |
DEBUG_SCARD(("[dwTimeout 0x%.8x]\n", (unsigned int) dwTimeout)); |
1041 |
printf("[COUNT %d]\n", (unsigned int) dwCount); |
DEBUG_SCARD(("[COUNT %d]\n", (unsigned int) dwCount)); |
1042 |
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))); |
1043 |
#endif |
|
1044 |
if (dwCount > 0) |
if (dwCount > 0) |
1045 |
{ |
{ |
1046 |
rsArray = SC_xmalloc(&lcHandle, dwCount * sizeof(SERVER_SCARD_READERSTATE_A)); |
rsArray = SC_xmalloc(&lcHandle, dwCount * sizeof(SERVER_SCARD_READERSTATE_A)); |
1057 |
in->p += 0x04; |
in->p += 0x04; |
1058 |
in_uint8a(in, cur, SERVER_SCARDSTATESIZE); |
in_uint8a(in, cur, SERVER_SCARDSTATESIZE); |
1059 |
} |
} |
1060 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
1061 |
printf("[READERS DUMP 1]------------------\n"); |
DEBUG_SCARD(("[READERS DUMP 1]------------------\n")); |
1062 |
hexdump((void *) rsArray, dwCount * sizeof(SERVER_SCARD_READERSTATE_A)); |
hexdump((void *) rsArray, dwCount * sizeof(SERVER_SCARD_READERSTATE_A)); |
1063 |
#endif |
#endif |
1064 |
|
|
1095 |
|
|
1096 |
in->p += 0x08; |
in->p += 0x08; |
1097 |
in_uint32_le(in, dataLength); |
in_uint32_le(in, dataLength); |
1098 |
#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 |
|
1099 |
inRepos(in, |
inRepos(in, |
1100 |
inString(&lcHandle, in, (char **) &(cur->szReader), dataLength, |
inString(&lcHandle, in, (char **) &(cur->szReader), dataLength, |
1101 |
wide)); |
wide)); |
1103 |
if (strcmp(cur->szReader, "\\\\?PnP?\\Notification") == 0) |
if (strcmp(cur->szReader, "\\\\?PnP?\\Notification") == 0) |
1104 |
cur->dwCurrentState |= SCARD_STATE_IGNORE; |
cur->dwCurrentState |= SCARD_STATE_IGNORE; |
1105 |
} |
} |
1106 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
1107 |
printf("[READERS DUMP 2]------------------\n"); |
DEBUG_SCARD(("[READERS DUMP 2]------------------\n")); |
1108 |
hexdump((void *) rsArray, dwCount * sizeof(SERVER_SCARD_READERSTATE_A)); |
hexdump((void *) rsArray, dwCount * sizeof(SERVER_SCARD_READERSTATE_A)); |
1109 |
#endif |
#endif |
1110 |
} |
} |
1114 |
stateArray = NULL; |
stateArray = NULL; |
1115 |
} |
} |
1116 |
|
|
1117 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("\nCalling SCardGetStatusChange...\n")); |
|
printf("\nCalling SCardGetStatusChange...\n"); |
|
|
#endif |
|
1118 |
|
|
1119 |
|
|
1120 |
myRsArray = SC_xmalloc(&lcHandle, dwCount * sizeof(MYPCSC_SCARD_READERSTATE_A)); |
myRsArray = SC_xmalloc(&lcHandle, dwCount * sizeof(MYPCSC_SCARD_READERSTATE_A)); |
1122 |
return SC_returnNoMemoryError(&lcHandle, in, out); |
return SC_returnNoMemoryError(&lcHandle, in, out); |
1123 |
memset(myRsArray, 0, dwCount * sizeof(SERVER_SCARD_READERSTATE_A)); |
memset(myRsArray, 0, dwCount * sizeof(SERVER_SCARD_READERSTATE_A)); |
1124 |
copyReaderState_ServerToMyPCSC(rsArray, myRsArray, (SERVER_DWORD) dwCount); |
copyReaderState_ServerToMyPCSC(rsArray, myRsArray, (SERVER_DWORD) dwCount); |
1125 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
1126 |
printf("[TRANSLATION OF READERS]--------------------\n"); |
DEBUG_SCARD(("[TRANSLATION OF READERS]--------------------\n")); |
1127 |
hexdump((void *) myRsArray, dwCount * sizeof(MYPCSC_SCARD_READERSTATE_A)); |
hexdump((void *) myRsArray, dwCount * sizeof(MYPCSC_SCARD_READERSTATE_A)); |
1128 |
#endif |
#endif |
1129 |
|
|
1131 |
myRsArray, (MYPCSC_DWORD) dwCount); |
myRsArray, (MYPCSC_DWORD) dwCount); |
1132 |
copyReaderState_MyPCSCToServer(myRsArray, rsArray, (MYPCSC_DWORD) dwCount); |
copyReaderState_MyPCSCToServer(myRsArray, rsArray, (MYPCSC_DWORD) dwCount); |
1133 |
|
|
|
#ifdef WITH_SCARD_DEBUG |
|
1134 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
1135 |
printf("<--ERROR SCardGetStatusChange Code=0x%.8x-->\n", (unsigned int) rv); |
{ |
1136 |
|
DEBUG_SCARD(("<--ERROR SCardGetStatusChange Code=0x%.8x, %s-->\n", |
1137 |
|
(unsigned int) rv, pcsc_stringify_error(rv))); |
1138 |
|
} |
1139 |
else |
else |
1140 |
printf("<--SUCCESS SCardGetStatusChange-->\n"); |
{ |
1141 |
|
DEBUG_SCARD(("<--SUCCESS SCardGetStatusChange-->\n")); |
1142 |
|
} |
1143 |
|
|
1144 |
|
#ifdef WITH_DEBUG_SCARD |
1145 |
if (dwCount > 0) |
if (dwCount > 0) |
1146 |
{ |
{ |
1147 |
printf("[READERS DUMP]------------------\n"); |
DEBUG_SCARD(("[READERS DUMP]------------------\n")); |
1148 |
hexdump((void *) rsArray, dwCount * sizeof(SERVER_SCARD_READERSTATE_A)); |
hexdump((void *) rsArray, dwCount * sizeof(SERVER_SCARD_READERSTATE_A)); |
1149 |
} |
} |
1150 |
#endif |
#endif |
1186 |
out_uint8p(out, (void *) ((unsigned char **) cur + 2), |
out_uint8p(out, (void *) ((unsigned char **) cur + 2), |
1187 |
sizeof(SERVER_SCARD_READERSTATE_A) - 2 * sizeof(unsigned char *)); |
sizeof(SERVER_SCARD_READERSTATE_A) - 2 * sizeof(unsigned char *)); |
1188 |
} |
} |
1189 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
1190 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
1191 |
return rv; |
return rv; |
1192 |
} |
} |
1199 |
|
|
1200 |
in->p += 0x1C; |
in->p += 0x1C; |
1201 |
in_uint32_le(in, hContext); |
in_uint32_le(in, hContext); |
1202 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[CONTEXT 0x%.8x]\n", (unsigned int) hContext)); |
1203 |
printf("[CONTEXT 0x%.8x]\n", (unsigned int) hContext); |
DEBUG_SCARD(("Canceling... \n")); |
|
printf("Canceling... \n"); |
|
|
#endif |
|
1204 |
rv = SCardCancel((MYPCSC_SCARDCONTEXT) hContext); |
rv = SCardCancel((MYPCSC_SCARDCONTEXT) hContext); |
|
#ifdef WITH_SCARD_DEBUG |
|
1205 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
1206 |
printf("<--ERROR SCardCancel Code=0x%.8x-->\n", (unsigned int) rv); |
{ |
1207 |
|
DEBUG_SCARD(("<--ERROR SCardCancel Code=0x%.8x, %s-->\n", (unsigned int) rv, |
1208 |
|
pcsc_stringify_error(rv))); |
1209 |
|
} |
1210 |
else |
else |
1211 |
printf("<--SUCCESS SCardCancel-->\n"); |
{ |
1212 |
#endif |
DEBUG_SCARD(("<--SUCCESS SCardCancel-->\n")); |
1213 |
outForceAllignment(out, 8); |
} |
1214 |
|
outForceAlignment(out, 8); |
1215 |
return rv; |
return rv; |
1216 |
} |
} |
1217 |
|
|
1232 |
|
|
1233 |
in->p += 0x2C; |
in->p += 0x2C; |
1234 |
in_uint32_le(in, hContext); |
in_uint32_le(in, hContext); |
1235 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[CONTEXT 0x%.8x]\n", (unsigned int) hContext)); |
|
printf("[CONTEXT 0x%.8x]\n", (unsigned int) hContext); |
|
|
#endif |
|
1236 |
in_uint32_le(in, atrMaskCount); |
in_uint32_le(in, atrMaskCount); |
1237 |
pAtrMasks = SC_xmalloc(&lcHandle, atrMaskCount * sizeof(SCARD_ATRMASK_L)); |
pAtrMasks = SC_xmalloc(&lcHandle, atrMaskCount * sizeof(SCARD_ATRMASK_L)); |
1238 |
if (!pAtrMasks) |
if (!pAtrMasks) |
1260 |
for (i = 0, rsCur = rsArray; i < readerCount; i++, rsCur++) |
for (i = 0, rsCur = rsArray; i < readerCount; i++, rsCur++) |
1261 |
{ |
{ |
1262 |
inReaderName(&lcHandle, in, (char **) &rsCur->szReader, wide); |
inReaderName(&lcHandle, in, (char **) &rsCur->szReader, wide); |
1263 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[CHECK READER %s]\n", |
1264 |
printf("[CHECK READER %s]\n", (rsCur->szReader) ? (rsCur->szReader) : ("NULL")); |
(rsCur->szReader) ? (rsCur->szReader) : ("NULL"))); |
|
#endif |
|
1265 |
} |
} |
1266 |
|
|
1267 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[CALL subfunction \"SCardGetStatusChange\"]\n")); |
|
printf("[CALL subfunction \"SCardGetStatusChange\"]\n"); |
|
|
#endif |
|
1268 |
/* FIXME segfault here. */ |
/* FIXME segfault here. */ |
1269 |
myRsArray = SC_xmalloc(&lcHandle, readerCount * sizeof(MYPCSC_SCARD_READERSTATE_A)); |
myRsArray = SC_xmalloc(&lcHandle, readerCount * sizeof(MYPCSC_SCARD_READERSTATE_A)); |
1270 |
if (!myRsArray) |
if (!myRsArray) |
1274 |
copyReaderState_MyPCSCToServer(myRsArray, rsArray, readerCount); |
copyReaderState_MyPCSCToServer(myRsArray, rsArray, readerCount); |
1275 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
1276 |
{ |
{ |
1277 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<--ERROR SCardGetStatusChange (no SCardLocateCardsByATR) Code=0x%.8x, %s-->\n", (unsigned int) rv, pcsc_stringify_error(rv))); |
|
printf("<--ERROR SCardGetStatusChange (no SCardLocateCardsByATR) Code=0x%.8x-->\n", |
|
|
(unsigned int) rv); |
|
|
#endif |
|
1278 |
} |
} |
1279 |
else |
else |
1280 |
{ |
{ |
1281 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<--SUCCESS SCardGetStatusChange (no SCardLocateCardsByATR)-->\n")); |
|
printf("<--SUCCESS SCardGetStatusChange (no SCardLocateCardsByATR)-->\n"); |
|
|
#endif |
|
1282 |
cur = pAtrMasks; |
cur = pAtrMasks; |
1283 |
for (i = 0, cur = pAtrMasks; i < atrMaskCount; i++, cur++) |
for (i = 0, cur = pAtrMasks; i < atrMaskCount; i++, cur++) |
1284 |
{ |
{ |
1298 |
} |
} |
1299 |
if (equal) |
if (equal) |
1300 |
{ |
{ |
1301 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[FOUND]\n")); |
|
printf("[FOUND]\n"); |
|
|
#endif |
|
1302 |
rsCur->dwEventState |= 0x00000040; /* SCARD_STATE_ATRMATCH 0x00000040 */ |
rsCur->dwEventState |= 0x00000040; /* SCARD_STATE_ATRMATCH 0x00000040 */ |
1303 |
memcpy(ResArray + j, rsCur, sizeof(SCARD_READERSTATE_A)); |
memcpy(ResArray + j, rsCur, sizeof(SCARD_READERSTATE_A)); |
1304 |
} |
} |
1316 |
sizeof(SCARD_READERSTATE_A) - 2 * sizeof(unsigned char *)); |
sizeof(SCARD_READERSTATE_A) - 2 * sizeof(unsigned char *)); |
1317 |
} |
} |
1318 |
|
|
1319 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
1320 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
1321 |
return rv; |
return rv; |
1322 |
} |
} |
1331 |
in->p += 0x30; |
in->p += 0x30; |
1332 |
in_uint32_le(in, hCard); |
in_uint32_le(in, hCard); |
1333 |
myHCard = scHandleToMyPCSC(hCard); |
myHCard = scHandleToMyPCSC(hCard); |
1334 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[hCard = 0x%.8x]\n", (unsigned int) hCard)); |
1335 |
printf("[hCard = 0x%.8x]\n", (unsigned int) hCard); |
DEBUG_SCARD(("[myHCard = 0x%016lx]\n", (unsigned long) myHCard)); |
|
printf("[myHCard = 0x%016lx]\n", myHCard); |
|
|
#endif |
|
1336 |
rv = SCardBeginTransaction(myHCard); |
rv = SCardBeginTransaction(myHCard); |
|
#ifdef WITH_SCARD_DEBUG |
|
1337 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
1338 |
printf("<--ERROR SCardBeginTransaction Code=0x%.8x-->\n", (unsigned int) rv); |
{ |
1339 |
|
DEBUG_SCARD(("<--ERROR SCardBeginTransaction Code=0x%.8x, %s-->\n", |
1340 |
|
(unsigned int) rv, pcsc_stringify_error(rv))); |
1341 |
|
} |
1342 |
else |
else |
1343 |
printf("<--SUCCESS SCardBeginTransaction-->\n"); |
{ |
1344 |
#endif |
DEBUG_SCARD(("<--SUCCESS SCardBeginTransaction-->\n")); |
1345 |
outForceAllignment(out, 8); |
} |
1346 |
|
outForceAlignment(out, 8); |
1347 |
return rv; |
return rv; |
1348 |
} |
} |
1349 |
|
|
1360 |
in->p += 0x0C; |
in->p += 0x0C; |
1361 |
in_uint32_le(in, hCard); |
in_uint32_le(in, hCard); |
1362 |
myHCard = scHandleToMyPCSC(hCard); |
myHCard = scHandleToMyPCSC(hCard); |
1363 |
#ifdef WITH_SCARD_DEBUG |
|
1364 |
printf("[hCard = 0x%.8x]\n", (unsigned int) hCard); |
DEBUG_SCARD(("[hCard = 0x%.8x]\n", (unsigned int) hCard)); |
1365 |
printf("[myHCard = 0x%016lx]\n", myHCard); |
DEBUG_SCARD(("[myHCard = 0x%016lx]\n", (unsigned long) myHCard)); |
1366 |
printf("[dwDisposition = 0x%.8x]\n", (unsigned int) dwDisposition); |
DEBUG_SCARD(("[dwDisposition = 0x%.8x]\n", (unsigned int) dwDisposition)); |
1367 |
#endif |
|
1368 |
rv = SCardEndTransaction(myHCard, (MYPCSC_DWORD) dwDisposition); |
rv = SCardEndTransaction(myHCard, (MYPCSC_DWORD) dwDisposition); |
|
#ifdef WITH_SCARD_DEBUG |
|
1369 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
1370 |
printf("<--ERROR SCardEndTransaction Code=0x%.8x-->\n", (unsigned int) rv); |
{ |
1371 |
|
DEBUG_SCARD(("<--ERROR SCardEndTransaction Code=0x%.8x, %s-->\n", (unsigned int) rv, |
1372 |
|
pcsc_stringify_error(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, %s-->\n", (unsigned int) rv, |
1582 |
printf("<--ERROR SCardTransmit Code=0x%.8x-->\n", (unsigned int) rv); |
pcsc_stringify_error(rv))); |
|
#endif |
|
1583 |
} |
} |
1584 |
else |
else |
1585 |
{ |
{ |
1586 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
1587 |
printf("<--SUCCESS SCardTransmit-->\n"); |
DEBUG_SCARD(("<--SUCCESS SCardTransmit-->\n")); |
1588 |
printf("RESULT %d\n", (unsigned int) cbRecvLength); |
DEBUG_SCARD(("RESULT %d\n", (unsigned int) cbRecvLength)); |
1589 |
hexdump(recvBuf, cbRecvLength); |
hexdump(recvBuf, cbRecvLength); |
1590 |
if (myPioRecvPci) |
if (myPioRecvPci) |
1591 |
{ |
{ |
1592 |
printf("--- myPioRecvPci ---\n"); |
DEBUG_SCARD(("--- myPioRecvPci ---\n")); |
1593 |
hexdump((void *) myPioRecvPci, myPioRecvPci->cbPciLength); |
hexdump((void *) myPioRecvPci, myPioRecvPci->cbPciLength); |
1594 |
} |
} |
1595 |
printf("------------------\n"); |
DEBUG_SCARD(("------------------\n")); |
1596 |
#endif |
#endif |
1597 |
#if 0 |
#if 0 |
1598 |
if ((pioRecvPci != NULL) && (pioRecvPci->cbPciLength > 0)) |
if ((pioRecvPci != NULL) && (pioRecvPci->cbPciLength > 0)) |
1619 |
|
|
1620 |
outBufferFinish(out, (char *) recvBuf, cbRecvLength); |
outBufferFinish(out, (char *) recvBuf, cbRecvLength); |
1621 |
} |
} |
1622 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
1623 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
1624 |
return rv; |
return rv; |
1625 |
} |
} |
1644 |
in_uint32_le(in, hCard); |
in_uint32_le(in, hCard); |
1645 |
in->p += 0x04; |
in->p += 0x04; |
1646 |
myHCard = scHandleToMyPCSC(hCard); |
myHCard = scHandleToMyPCSC(hCard); |
1647 |
#ifdef WITH_SCARD_DEBUG |
|
1648 |
printf("[hCard 0x%.8x]\n", (unsigned int) hCard); |
DEBUG_SCARD(("[hCard 0x%.8x]\n", (unsigned int) hCard)); |
1649 |
printf("[myHCard 0x%016lx]\n", myHCard); |
DEBUG_SCARD(("[myHCard 0x%016lx]\n", (unsigned long) myHCard)); |
1650 |
printf("[dwReaderLen %d]\n", (unsigned int) dwReaderLen); |
DEBUG_SCARD(("[dwReaderLen %d]\n", (unsigned int) dwReaderLen)); |
1651 |
printf("[dwAtrLen %d]\n", (unsigned int) dwAtrLen); |
DEBUG_SCARD(("[dwAtrLen %d]\n", (unsigned int) dwAtrLen)); |
|
#endif |
|
1652 |
|
|
1653 |
if (dwReaderLen <= 0 || dwReaderLen == SCARD_AUTOALLOCATE || dwReaderLen > SCARD_MAX_MEM) |
if (dwReaderLen <= 0 || dwReaderLen == SCARD_AUTOALLOCATE || dwReaderLen > SCARD_MAX_MEM) |
1654 |
dwReaderLen = SCARD_MAX_MEM; |
dwReaderLen = SCARD_MAX_MEM; |
1676 |
|
|
1677 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
1678 |
{ |
{ |
1679 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<--ERROR SCardStatus Code=0x%.8x, %s-->\n", (unsigned int) rv, |
1680 |
printf("<--ERROR SCardStatus Code=0x%.8x-->\n", (unsigned int) rv); |
pcsc_stringify_error(rv))); |
|
#endif |
|
1681 |
return SC_returnCode(rv, &lcHandle, in, out); |
return SC_returnCode(rv, &lcHandle, in, out); |
1682 |
} |
} |
1683 |
else |
else |
1684 |
{ |
{ |
1685 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
1686 |
printf("<--SUCCESS SCardStatus-->\n"); |
DEBUG_SCARD(("<--SUCCESS SCardStatus-->\n")); |
1687 |
printf("[dwState 0x%.8x]\n", (unsigned int) dwState); |
DEBUG_SCARD(("[dwState 0x%.8x]\n", (unsigned int) dwState)); |
1688 |
printf("[dwProtocol 0x%.8x]\n", (unsigned int) dwProtocol); |
DEBUG_SCARD(("[dwProtocol 0x%.8x]\n", (unsigned int) dwProtocol)); |
1689 |
printf("[Reader Name]\n"); |
DEBUG_SCARD(("[Reader Name]\n")); |
1690 |
hexdump((unsigned char *) readerName, dwReaderLen); |
hexdump((unsigned char *) readerName, dwReaderLen); |
1691 |
printf("[Atr]\n"); |
DEBUG_SCARD(("[Atr]\n")); |
1692 |
hexdump(atr, dwAtrLen); |
hexdump(atr, dwAtrLen); |
1693 |
#endif |
#endif |
1694 |
if (dwState & (SCARD_SPECIFIC | SCARD_NEGOTIABLE)) |
if (dwState & (SCARD_SPECIFIC | SCARD_NEGOTIABLE)) |
1736 |
out_uint32_le(out, dataLength); |
out_uint32_le(out, dataLength); |
1737 |
out->p = psave; |
out->p = psave; |
1738 |
} |
} |
1739 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
1740 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
1741 |
return rv; |
return rv; |
1742 |
} |
} |
1759 |
in_uint32_le(in, hCard); |
in_uint32_le(in, hCard); |
1760 |
in->p += 0x04; |
in->p += 0x04; |
1761 |
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 |
|
1762 |
|
|
1763 |
|
DEBUG_SCARD(("[hCard 0x%.8x]\n", (unsigned int) hCard)); |
1764 |
|
DEBUG_SCARD(("[myHCard 0x%.8x]\n", (unsigned int) myHCard)); |
1765 |
|
DEBUG_SCARD(("[dwAtrLen %d]\n", (unsigned int) dwAtrLen)); |
1766 |
|
|
1767 |
dwReaderLen = SCARD_MAX_MEM; |
dwReaderLen = SCARD_MAX_MEM; |
1768 |
if (dwAtrLen <= 0 || dwAtrLen == SCARD_AUTOALLOCATE || dwAtrLen > SCARD_MAX_MEM) |
if (dwAtrLen <= 0 || dwAtrLen == SCARD_AUTOALLOCATE || dwAtrLen > SCARD_MAX_MEM) |
1788 |
|
|
1789 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
1790 |
{ |
{ |
1791 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<--ERROR SCardStatus (no ScardState) Code=0x%.8x, %s-->\n", |
1792 |
printf("<--ERROR SCardStatus (no ScardState) Code=0x%.8x-->\n", (unsigned int) rv); |
(unsigned int) rv, pcsc_stringify_error(rv))); |
|
#endif |
|
1793 |
return SC_returnCode(rv, &lcHandle, in, out); |
return SC_returnCode(rv, &lcHandle, in, out); |
1794 |
} |
} |
1795 |
else |
else |
1796 |
{ |
{ |
1797 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
1798 |
printf("<--SUCCESS SCardStatus (no ScardState)-->\n"); |
DEBUG_SCARD(("<--SUCCESS SCardStatus (no ScardState)-->\n")); |
1799 |
printf("[dwState 0x%.8x]\n", (unsigned int) dwState); |
DEBUG_SCARD(("[dwState 0x%.8x]\n", (unsigned int) dwState)); |
1800 |
printf("[dwProtocol 0x%.8x]\n", (unsigned int) dwProtocol); |
DEBUG_SCARD(("[dwProtocol 0x%.8x]\n", (unsigned int) dwProtocol)); |
1801 |
printf("[Atr]\n"); |
DEBUG_SCARD(("[Atr]\n")); |
1802 |
hexdump(atr, dwAtrLen); |
hexdump(atr, dwAtrLen); |
1803 |
#endif |
#endif |
1804 |
if (dwState & (SCARD_SPECIFIC | SCARD_NEGOTIABLE)) |
if (dwState & (SCARD_SPECIFIC | SCARD_NEGOTIABLE)) |
1830 |
out_uint8p(out, atr, dwAtrLen); |
out_uint8p(out, atr, dwAtrLen); |
1831 |
outRepos(out, dwAtrLen); |
outRepos(out, dwAtrLen); |
1832 |
} |
} |
1833 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
1834 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
1835 |
return rv; |
return rv; |
1836 |
} |
} |
1866 |
dwGroups = groups; |
dwGroups = groups; |
1867 |
|
|
1868 |
if (rv) |
if (rv) |
|
#ifdef WITH_SCARD_DEBUG |
|
1869 |
{ |
{ |
1870 |
printf("<--ERROR SCardListReaderGroups Code=0x%.8x-->\n", (unsigned int) rv); |
DEBUG_SCARD(("<--ERROR SCardListReaderGroups Code=0x%.8x, %s-->\n", |
1871 |
#endif |
(unsigned int) rv, pcsc_stringify_error(rv))); |
1872 |
return SC_returnCode(rv, &lcHandle, in, out); |
return SC_returnCode(rv, &lcHandle, in, out); |
|
#ifdef WITH_SCARD_DEBUG |
|
1873 |
} |
} |
1874 |
else |
else |
1875 |
{ |
{ |
1876 |
printf("<--SUCCESS SCardListReaderGroups-->\n"); |
DEBUG_SCARD(("<--SUCCESS SCardListReaderGroups-->\n")); |
1877 |
} |
} |
|
#endif |
|
1878 |
|
|
1879 |
|
|
1880 |
out_uint32_le(out, dwGroups); |
out_uint32_le(out, dwGroups); |
1884 |
outRepos(out, dwGroups); |
outRepos(out, dwGroups); |
1885 |
out_uint32_le(out, 0x00000000); |
out_uint32_le(out, 0x00000000); |
1886 |
|
|
1887 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
1888 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
1889 |
return rv; |
return rv; |
1890 |
} |
} |
1910 |
|
|
1911 |
dwAttrId = dwAttrId & 0x0000FFFF; |
dwAttrId = dwAttrId & 0x0000FFFF; |
1912 |
|
|
1913 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[hCard = 0x%.8x]\n", (unsigned int) hCard)); |
1914 |
printf("[hCard = 0x%.8x]\n", (unsigned int) hCard); |
DEBUG_SCARD(("[myHCard 0x%.8x]\n", (unsigned int) myHCard)); |
1915 |
printf("[myHCard 0x%.8x]\n", (unsigned int) myHCard); |
DEBUG_SCARD(("[dwAttrId = 0x%.8x]\n", (unsigned int) dwAttrId)); |
1916 |
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 |
|
1917 |
|
|
1918 |
if (dwAttrLen > MAX_BUFFER_SIZE) |
if (dwAttrLen > MAX_BUFFER_SIZE) |
1919 |
dwAttrLen = MAX_BUFFER_SIZE; |
dwAttrLen = MAX_BUFFER_SIZE; |
1939 |
|
|
1940 |
if (dwAttrId == 0x00000100 && rv != SCARD_S_SUCCESS) |
if (dwAttrId == 0x00000100 && rv != SCARD_S_SUCCESS) |
1941 |
{ |
{ |
1942 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("Get Attribute ATTR_VENDOR_NAME\n")); |
|
printf("Get Attribute ATTR_VENDOR_NAME\n"); |
|
|
#endif |
|
1943 |
pthread_mutex_lock(&hcardAccess); |
pthread_mutex_lock(&hcardAccess); |
1944 |
PSCHCardRec hcard = hcardFirst; |
PSCHCardRec hcard = hcardFirst; |
1945 |
while (hcard) |
while (hcard) |
1954 |
hcard = hcard->next; |
hcard = hcard->next; |
1955 |
} |
} |
1956 |
pthread_mutex_unlock(&hcardAccess); |
pthread_mutex_unlock(&hcardAccess); |
1957 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[0x%.8x]\n", (unsigned int) rv)); |
|
printf("[0x%.8x]\n", (unsigned int) rv); |
|
|
#endif |
|
1958 |
} |
} |
1959 |
|
|
1960 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
1961 |
{ |
{ |
1962 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<--ERROR SCardGetAttrib Code=0x%.8x, %s-->\n", (unsigned int) rv, |
1963 |
printf("<--ERROR SCardGetAttrib Code=0x%.8x-->\n", (unsigned int) rv); |
pcsc_stringify_error(rv))); |
|
#endif |
|
1964 |
return SC_returnCode(rv, &lcHandle, in, out); |
return SC_returnCode(rv, &lcHandle, in, out); |
1965 |
} |
} |
1966 |
else |
else |
1967 |
{ |
{ |
1968 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
1969 |
printf("<--SUCCESS SCardGetAttrib-->\n"); |
DEBUG_SCARD(("<--SUCCESS SCardGetAttrib-->\n")); |
1970 |
printf("[LENGTH %d]\n", (unsigned int) dwAttrLen); |
DEBUG_SCARD(("[LENGTH %d]\n", (unsigned int) dwAttrLen)); |
1971 |
printf("+++++++++++++++++++++\n"); |
DEBUG_SCARD(("+++++++++++++++++++++\n")); |
1972 |
hexdump(pbAttr, dwAttrLen); |
hexdump(pbAttr, dwAttrLen); |
1973 |
printf("+++++++++++++++++++++\n"); |
DEBUG_SCARD(("+++++++++++++++++++++\n")); |
1974 |
#endif |
#endif |
1975 |
out_uint32_le(out, dwAttrLen); |
out_uint32_le(out, dwAttrLen); |
1976 |
out_uint32_le(out, 0x00000200); |
out_uint32_le(out, 0x00000200); |
1986 |
outRepos(out, dwAttrLen); |
outRepos(out, dwAttrLen); |
1987 |
out_uint32_le(out, 0x00000000); |
out_uint32_le(out, 0x00000000); |
1988 |
} |
} |
1989 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
1990 |
return rv; |
return rv; |
1991 |
} |
} |
1992 |
|
|
2011 |
|
|
2012 |
dwAttrId = dwAttrId & 0x0000FFFF; |
dwAttrId = dwAttrId & 0x0000FFFF; |
2013 |
|
|
2014 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[hCard = 0x%.8x]\n", (unsigned int) hCard)); |
2015 |
printf("[hCard = 0x%.8x]\n", (unsigned int) hCard); |
DEBUG_SCARD(("[myHCard 0x%.8x]\n", (unsigned int) myHCard)); |
2016 |
printf("[myHCard 0x%.8x]\n", (unsigned int) myHCard); |
DEBUG_SCARD(("[dwAttrId = 0x%.8x]\n", (unsigned int) dwAttrId)); |
2017 |
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 |
|
2018 |
|
|
2019 |
if (dwAttrLen > MAX_BUFFER_SIZE) |
if (dwAttrLen > MAX_BUFFER_SIZE) |
2020 |
dwAttrLen = MAX_BUFFER_SIZE; |
dwAttrLen = MAX_BUFFER_SIZE; |
2026 |
in_uint8a(in, pbAttr, dwAttrLen); |
in_uint8a(in, pbAttr, dwAttrLen); |
2027 |
rv = SCardSetAttrib(myHCard, (MYPCSC_DWORD) dwAttrId, pbAttr, (MYPCSC_DWORD) dwAttrLen); |
rv = SCardSetAttrib(myHCard, (MYPCSC_DWORD) dwAttrId, pbAttr, (MYPCSC_DWORD) dwAttrLen); |
2028 |
|
|
|
#ifdef WITH_SCARD_DEBUG |
|
2029 |
if (rv) |
if (rv) |
2030 |
printf("<--ERROR SCardSetAttrib Code=0x%.8x-->\n", (unsigned int) rv); |
{ |
2031 |
|
DEBUG_SCARD(("<--ERROR SCardSetAttrib Code=0x%.8x, %s-->\n", (unsigned int) rv, |
2032 |
|
pcsc_stringify_error(rv))); |
2033 |
|
} |
2034 |
else |
else |
2035 |
printf("<--SUCCESS SCardSetAttrib-->\n"); |
{ |
2036 |
#endif |
DEBUG_SCARD(("<--SUCCESS SCardSetAttrib-->\n")); |
2037 |
|
} |
2038 |
|
|
2039 |
out_uint32_le(out, 0x00000000); |
out_uint32_le(out, 0x00000000); |
2040 |
out_uint32_le(out, 0x00000200); |
out_uint32_le(out, 0x00000200); |
2041 |
out_uint32_le(out, 0x00000000); |
out_uint32_le(out, 0x00000000); |
2042 |
out_uint32_le(out, 0x00000000); |
out_uint32_le(out, 0x00000000); |
2043 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
2044 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
2045 |
return rv; |
return rv; |
2046 |
} |
} |
2103 |
if (!pOutBuffer) |
if (!pOutBuffer) |
2104 |
return SC_returnNoMemoryError(&lcHandle, in, out); |
return SC_returnNoMemoryError(&lcHandle, in, out); |
2105 |
|
|
2106 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
2107 |
printf("[hContext = 0x%.8x]\n", (unsigned int) hContext); |
DEBUG_SCARD(("[hContext = 0x%.8x]\n", (unsigned int) hContext)); |
2108 |
printf("[hCard = 0x%.8x]\n", (unsigned int) hCard); |
DEBUG_SCARD(("[hCard = 0x%.8x]\n", (unsigned int) hCard)); |
2109 |
printf("[dwControlCode = 0x%.8x]\n", (unsigned int) dwControlCode); |
DEBUG_SCARD(("[dwControlCode = 0x%.8x]\n", (unsigned int) dwControlCode)); |
2110 |
printf("[nInBufferSize = %d]\n", (unsigned int) nInBufferSize); |
DEBUG_SCARD(("[nInBufferSize = %d]\n", (unsigned int) nInBufferSize)); |
2111 |
printf("[nOutBufferSize = %d]\n", (unsigned int) nOutBufferSize); |
DEBUG_SCARD(("[nOutBufferSize = %d]\n", (unsigned int) nOutBufferSize)); |
2112 |
if (nInBufferSize > 0) |
if (nInBufferSize > 0) |
2113 |
{ |
{ |
2114 |
printf("[In buffer]\n"); |
DEBUG_SCARD(("[In buffer]\n")); |
2115 |
hexdump((unsigned char *) pInBuffer, nInBufferSize); |
hexdump((unsigned char *) pInBuffer, nInBufferSize); |
2116 |
} |
} |
2117 |
printf("---> Calling SCardControl\n"); |
DEBUG_SCARD(("---> Calling SCardControl\n")); |
2118 |
#endif |
#endif |
2119 |
|
|
|
#ifdef WITH_PCSC120 |
|
2120 |
sc_nBytesReturned = nBytesReturned; |
sc_nBytesReturned = nBytesReturned; |
2121 |
myHCard = scHandleToMyPCSC(hCard); |
myHCard = scHandleToMyPCSC(hCard); |
2122 |
|
#ifdef WITH_PCSC120 |
2123 |
rv = SCardControl(myHCard, pInBuffer, (MYPCSC_DWORD) nInBufferSize, pOutBuffer, |
rv = SCardControl(myHCard, pInBuffer, (MYPCSC_DWORD) nInBufferSize, pOutBuffer, |
2124 |
&sc_nBytesReturned); |
&sc_nBytesReturned); |
|
nBytesReturned = sc_nBytesReturned; |
|
2125 |
#else |
#else |
|
sc_nBytesReturned = nBytesReturned; |
|
|
myHCard = scHandleToMyPCSC(hCard); |
|
2126 |
rv = SCardControl(myHCard, (MYPCSC_DWORD) dwControlCode, pInBuffer, |
rv = SCardControl(myHCard, (MYPCSC_DWORD) dwControlCode, pInBuffer, |
2127 |
(MYPCSC_DWORD) nInBufferSize, pOutBuffer, |
(MYPCSC_DWORD) nInBufferSize, pOutBuffer, |
2128 |
(MYPCSC_DWORD) nOutBufferRealSize, &sc_nBytesReturned); |
(MYPCSC_DWORD) nOutBufferRealSize, &sc_nBytesReturned); |
|
nBytesReturned = sc_nBytesReturned; |
|
2129 |
#endif |
#endif |
2130 |
|
nBytesReturned = sc_nBytesReturned; |
2131 |
|
|
2132 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
2133 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
2134 |
printf("<--ERROR SCardControl Code=0x%.8x-->\n", (unsigned int) rv); |
{ |
2135 |
|
DEBUG_SCARD(("<--ERROR SCardControl Code=0x%.8x, %s-->\n", (unsigned int) rv, |
2136 |
|
pcsc_stringify_error(rv))); |
2137 |
|
} |
2138 |
else |
else |
2139 |
{ |
{ |
2140 |
printf("<--SUCCESS SCardControl-->\n"); |
DEBUG_SCARD(("<--SUCCESS SCardControl-->\n")); |
2141 |
printf("[LENGTH %d]\n", (unsigned int) nBytesReturned); |
DEBUG_SCARD(("[LENGTH %d]\n", (unsigned int) nBytesReturned)); |
2142 |
printf("+++++++++++++++++++++\n"); |
DEBUG_SCARD(("+++++++++++++++++++++\n")); |
2143 |
hexdump((unsigned char *) pOutBuffer, nBytesReturned); |
hexdump((unsigned char *) pOutBuffer, nBytesReturned); |
2144 |
printf("+++++++++++++++++++++\n"); |
DEBUG_SCARD(("+++++++++++++++++++++\n")); |
2145 |
} |
} |
2146 |
#endif |
#endif |
2147 |
|
|
2154 |
outRepos(out, nBytesReturned); |
outRepos(out, nBytesReturned); |
2155 |
} |
} |
2156 |
|
|
2157 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
2158 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
2159 |
return rv; |
return rv; |
2160 |
} |
} |
2173 |
SERVER_DWORD Result = 0x00000000; |
SERVER_DWORD Result = 0x00000000; |
2174 |
unsigned char *psize, *pend, *pStatusCode; |
unsigned char *psize, *pend, *pStatusCode; |
2175 |
SERVER_DWORD addToEnd = 0; |
SERVER_DWORD addToEnd = 0; |
2176 |
|
#ifdef WITH_DEBUG_SCARD |
|
#ifdef WITH_SCARD_DEBUG |
|
2177 |
unsigned char *pbeg = out->p; |
unsigned char *pbeg = out->p; |
2178 |
printf("--------------------------------\n"); |
|
2179 |
printf("[NTHANDLE %08X]\n", handle); |
DEBUG_SCARD(("--------------------------------\n")); |
2180 |
printf("[REQUEST %08X]\n", request); |
DEBUG_SCARD(("[NTHANDLE %08X]\n", handle)); |
2181 |
printf("[INPUT DUMP]--------------------\n"); |
DEBUG_SCARD(("[REQUEST %08X]\n", request)); |
2182 |
|
DEBUG_SCARD(("[INPUT DUMP]--------------------\n")); |
2183 |
hexdump(in->p, in->end - in->p); |
hexdump(in->p, in->end - in->p); |
2184 |
#endif |
#endif |
2185 |
/* Processing request */ |
/* Processing request */ |
2197 |
/* SCardEstablishContext */ |
/* SCardEstablishContext */ |
2198 |
case SC_ESTABLISH_CONTEXT: |
case SC_ESTABLISH_CONTEXT: |
2199 |
{ |
{ |
2200 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardEstablishContext--->\n")); |
|
printf("<---SCardEstablishContext--->\n"); |
|
|
#endif |
|
2201 |
Result = (SERVER_DWORD) TS_SCardEstablishContext(in, out); |
Result = (SERVER_DWORD) TS_SCardEstablishContext(in, out); |
2202 |
break; |
break; |
2203 |
} |
} |
2204 |
/* SCardReleaseContext */ |
/* SCardReleaseContext */ |
2205 |
case SC_RELEASE_CONTEXT: |
case SC_RELEASE_CONTEXT: |
2206 |
{ |
{ |
2207 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardReleaseContext--->\n")); |
|
printf("<---SCardReleaseContext--->\n"); |
|
|
#endif |
|
2208 |
Result = (SERVER_DWORD) TS_SCardReleaseContext(in, out); |
Result = (SERVER_DWORD) TS_SCardReleaseContext(in, out); |
2209 |
break; |
break; |
2210 |
} |
} |
2211 |
/* SCardIsValidContext */ |
/* SCardIsValidContext */ |
2212 |
case SC_IS_VALID_CONTEXT: |
case SC_IS_VALID_CONTEXT: |
2213 |
{ |
{ |
2214 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardIsValidContext--->\n")); |
|
printf("<---SCardIsValidContext--->\n"); |
|
|
#endif |
|
2215 |
Result = (SERVER_DWORD) TS_SCardIsValidContext(in, out); |
Result = (SERVER_DWORD) TS_SCardIsValidContext(in, out); |
2216 |
break; |
break; |
2217 |
} |
} |
2220 |
case SC_LIST_READERS + 4: /* SCardListReadersW */ |
case SC_LIST_READERS + 4: /* SCardListReadersW */ |
2221 |
{ |
{ |
2222 |
BOOL wide = request != SC_LIST_READERS; |
BOOL wide = request != SC_LIST_READERS; |
2223 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardListReaders---> (%s)\n", |
2224 |
printf("<---SCardListReaders---> (%s)\n", |
(wide) ? ("WIDE") : ("ASCII"))); |
|
(wide) ? ("WIDE") : ("ASCII")); |
|
|
#endif |
|
2225 |
Result = (SERVER_DWORD) TS_SCardListReaders(in, out, wide); |
Result = (SERVER_DWORD) TS_SCardListReaders(in, out, wide); |
2226 |
break; |
break; |
2227 |
} |
} |
2230 |
case SC_CONNECT + 4: /* SCardConnectW */ |
case SC_CONNECT + 4: /* SCardConnectW */ |
2231 |
{ |
{ |
2232 |
BOOL wide = request != SC_CONNECT; |
BOOL wide = request != SC_CONNECT; |
2233 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardConnect---> (%s)\n", |
2234 |
printf("<---SCardConnect---> (%s)\n", |
(wide) ? ("WIDE") : ("ASCII"))); |
|
(wide) ? ("WIDE") : ("ASCII")); |
|
|
#endif |
|
2235 |
Result = (SERVER_DWORD) TS_SCardConnect(in, out, wide); |
Result = (SERVER_DWORD) TS_SCardConnect(in, out, wide); |
2236 |
break; |
break; |
2237 |
} |
} |
2238 |
/* ScardReconnect */ |
/* ScardReconnect */ |
2239 |
case SC_RECONNECT: |
case SC_RECONNECT: |
2240 |
{ |
{ |
2241 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardReconnect--->\n")); |
|
printf("<---SCardReconnect--->\n"); |
|
|
#endif |
|
2242 |
Result = (SERVER_DWORD) TS_SCardReconnect(in, out); |
Result = (SERVER_DWORD) TS_SCardReconnect(in, out); |
2243 |
break; |
break; |
2244 |
} |
} |
2245 |
/* ScardDisconnect */ |
/* ScardDisconnect */ |
2246 |
case SC_DISCONNECT: |
case SC_DISCONNECT: |
2247 |
{ |
{ |
2248 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardDisconnect--->\n")); |
|
printf("<---SCardDisconnect--->\n"); |
|
|
#endif |
|
2249 |
Result = (SERVER_DWORD) TS_SCardDisconnect(in, out); |
Result = (SERVER_DWORD) TS_SCardDisconnect(in, out); |
2250 |
break; |
break; |
2251 |
} |
} |
2254 |
case SC_GET_STATUS_CHANGE + 4: /* SCardGetStatusChangeW */ |
case SC_GET_STATUS_CHANGE + 4: /* SCardGetStatusChangeW */ |
2255 |
{ |
{ |
2256 |
BOOL wide = request != SC_GET_STATUS_CHANGE; |
BOOL wide = request != SC_GET_STATUS_CHANGE; |
2257 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardGetStatusChange---> (%s)\n", |
2258 |
printf("<---SCardGetStatusChange---> (%s)\n", |
(wide) ? ("WIDE") : ("ASCII"))); |
|
(wide) ? ("WIDE") : ("ASCII")); |
|
|
#endif |
|
2259 |
Result = (SERVER_DWORD) TS_SCardGetStatusChange(in, out, wide); |
Result = (SERVER_DWORD) TS_SCardGetStatusChange(in, out, wide); |
2260 |
break; |
break; |
2261 |
} |
} |
2262 |
/* SCardCancel */ |
/* SCardCancel */ |
2263 |
case SC_CANCEL: |
case SC_CANCEL: |
2264 |
{ |
{ |
2265 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardCancel--->\n")); |
|
printf("<---SCardCancel--->\n"); |
|
|
#endif |
|
2266 |
Result = (SERVER_DWORD) TS_SCardCancel(in, out); |
Result = (SERVER_DWORD) TS_SCardCancel(in, out); |
2267 |
break; |
break; |
2268 |
} |
} |
2271 |
case SC_LOCATE_CARDS_BY_ATR + 4: /* SCardLocateCardsByATRW */ |
case SC_LOCATE_CARDS_BY_ATR + 4: /* SCardLocateCardsByATRW */ |
2272 |
{ |
{ |
2273 |
BOOL wide = request != SC_LOCATE_CARDS_BY_ATR; |
BOOL wide = request != SC_LOCATE_CARDS_BY_ATR; |
2274 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardLocateCardsByATR---> (%s)\n", |
2275 |
printf("<---SCardLocateCardsByATR---> (%s)\n", |
(wide) ? ("WIDE") : ("ASCII"))); |
|
(wide) ? ("WIDE") : ("ASCII")); |
|
|
#endif |
|
2276 |
Result = (SERVER_DWORD) TS_SCardLocateCardsByATR(in, out, wide); |
Result = (SERVER_DWORD) TS_SCardLocateCardsByATR(in, out, wide); |
2277 |
break; |
break; |
2278 |
} |
} |
2279 |
/* SCardBeginTransaction */ |
/* SCardBeginTransaction */ |
2280 |
case SC_BEGIN_TRANSACTION: |
case SC_BEGIN_TRANSACTION: |
2281 |
{ |
{ |
2282 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardBeginTransaction--->\n")); |
|
printf("<---SCardBeginTransaction--->\n"); |
|
|
#endif |
|
2283 |
Result = (SERVER_DWORD) TS_SCardBeginTransaction(in, out); |
Result = (SERVER_DWORD) TS_SCardBeginTransaction(in, out); |
2284 |
break; |
break; |
2285 |
} |
} |
2286 |
/* SCardBeginTransaction */ |
/* SCardBeginTransaction */ |
2287 |
case SC_END_TRANSACTION: |
case SC_END_TRANSACTION: |
2288 |
{ |
{ |
2289 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardEndTransaction--->\n")); |
|
printf("<---SCardEndTransaction--->\n"); |
|
|
#endif |
|
2290 |
Result = (SERVER_DWORD) TS_SCardEndTransaction(in, out); |
Result = (SERVER_DWORD) TS_SCardEndTransaction(in, out); |
2291 |
break; |
break; |
2292 |
} |
} |
2293 |
/* ScardTransmit */ |
/* ScardTransmit */ |
2294 |
case SC_TRANSMIT: |
case SC_TRANSMIT: |
2295 |
{ |
{ |
2296 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardTransmit--->\n")); |
|
printf("<---SCardTransmit--->\n"); |
|
|
#endif |
|
2297 |
Result = (SERVER_DWORD) TS_SCardTransmit(in, out); |
Result = (SERVER_DWORD) TS_SCardTransmit(in, out); |
2298 |
break; |
break; |
2299 |
} |
} |
2300 |
/* SCardControl */ |
/* SCardControl */ |
2301 |
case SC_CONTROL: |
case SC_CONTROL: |
2302 |
{ |
{ |
2303 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardControl--->\n")); |
|
printf("<---SCardControl--->\n"); |
|
|
#endif |
|
2304 |
Result = (SERVER_DWORD) TS_SCardControl(in, out); |
Result = (SERVER_DWORD) TS_SCardControl(in, out); |
2305 |
break; |
break; |
2306 |
} |
} |
2308 |
#ifndef WITH_PCSC120 |
#ifndef WITH_PCSC120 |
2309 |
case SC_GETATTRIB: |
case SC_GETATTRIB: |
2310 |
{ |
{ |
2311 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardGetAttrib--->\n")); |
|
printf("<---SCardGetAttrib--->\n"); |
|
|
#endif |
|
2312 |
Result = (SERVER_DWORD) TS_SCardGetAttrib(in, out); |
Result = (SERVER_DWORD) TS_SCardGetAttrib(in, out); |
2313 |
break; |
break; |
2314 |
} |
} |
2315 |
#endif |
#endif |
2316 |
case SC_ACCESS_STARTED_EVENT: |
case SC_ACCESS_STARTED_EVENT: |
2317 |
{ |
{ |
2318 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardAccessStartedEvent-->\n")); |
|
printf("<---SCardAccessStartedEvent-->\n"); |
|
|
#endif |
|
2319 |
Result = (SERVER_DWORD) TS_SCardAccessStartedEvent(in, out); |
Result = (SERVER_DWORD) TS_SCardAccessStartedEvent(in, out); |
2320 |
break; |
break; |
2321 |
} |
} |
2323 |
case SC_STATUS + 4: /* SCardStatusW */ |
case SC_STATUS + 4: /* SCardStatusW */ |
2324 |
{ |
{ |
2325 |
BOOL wide = request != SC_STATUS; |
BOOL wide = request != SC_STATUS; |
2326 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardStatus---> (%s)\n", |
2327 |
printf("<---SCardStatus---> (%s)\n", (wide) ? ("WIDE") : ("ASCII")); |
(wide) ? ("WIDE") : ("ASCII"))); |
|
#endif |
|
2328 |
Result = (SERVER_DWORD) TS_SCardStatus(in, out, wide); |
Result = (SERVER_DWORD) TS_SCardStatus(in, out, wide); |
2329 |
break; |
break; |
2330 |
} |
} |
2331 |
case SC_STATE: /* SCardState */ |
case SC_STATE: /* SCardState */ |
2332 |
{ |
{ |
2333 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardState--->")); |
|
printf("<---SCardState--->"); |
|
|
#endif |
|
2334 |
Result = (SERVER_DWORD) TS_SCardState(in, out); |
Result = (SERVER_DWORD) TS_SCardState(in, out); |
2335 |
break; |
break; |
2336 |
} |
} |
2337 |
default: |
default: |
2338 |
{ |
{ |
2339 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---UNSUPPORTED-FUNC--->\n")); |
|
printf("<---UNSUPPORTED-FUNC--->\n"); |
|
|
#endif |
|
2340 |
Result = 0x80100014; |
Result = 0x80100014; |
2341 |
out_uint8s(out, 256); |
out_uint8s(out, 256); |
2342 |
break; |
break; |
2363 |
out_uint8s(out, addToEnd); |
out_uint8s(out, addToEnd); |
2364 |
} |
} |
2365 |
|
|
2366 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
2367 |
printf("[OUTPUT DUMP]-------------------\n"); |
DEBUG_SCARD(("[OUTPUT DUMP]-------------------\n")); |
2368 |
hexdump(pbeg, (size_t) (out->p) - (size_t) pbeg); |
hexdump(pbeg, (size_t) (out->p) - (size_t) pbeg); |
2369 |
printf("--------------------------------\n"); |
DEBUG_SCARD(("--------------------------------\n")); |
2370 |
#endif |
#endif |
2371 |
return STATUS_SUCCESS; |
return STATUS_SUCCESS; |
2372 |
} |
} |
2503 |
size_t buffer_len = 0; |
size_t buffer_len = 0; |
2504 |
scard_device_control(data->handle, data->request, data->in, data->out); |
scard_device_control(data->handle, data->request, data->in, data->out); |
2505 |
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 |
|
|
pthread_mutex_lock(&sendControl); |
|
|
#endif |
|
2506 |
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 |
|
|
pthread_mutex_unlock(&sendControl); |
|
|
#endif |
|
2507 |
SC_destroyThreadData(data); |
SC_destroyThreadData(data); |
2508 |
} |
} |
2509 |
|
|
2511 |
static void * |
static void * |
2512 |
thread_function(PThreadListElement listElement) |
thread_function(PThreadListElement listElement) |
2513 |
{ |
{ |
2514 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
2515 |
long sTime = 0; |
long sTime = 0; |
2516 |
#endif |
#endif |
2517 |
if ((listElement != NULL) && (listElement->data != NULL)) |
if ((listElement != NULL) && (listElement->data != NULL)) |
2518 |
{ |
{ |
2519 |
while (1) |
while (1) |
2520 |
{ |
{ |
2521 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
2522 |
sTime = time(NULL); |
sTime = time(NULL); |
2523 |
#endif |
#endif |
2524 |
pthread_mutex_lock(&listElement->nodata); |
pthread_mutex_lock(&listElement->nodata); |
2525 |
SC_deviceControl(listElement->data); |
SC_deviceControl(listElement->data); |
2526 |
listElement->data = NULL; |
listElement->data = NULL; |
2527 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[HANDLING TIME %d]\n", (int) (time(NULL) - sTime))); |
|
printf("[HANDLING TIME %d]\n", (int) (time(NULL) - sTime)); |
|
|
#endif |
|
2528 |
pthread_mutex_unlock(&listElement->busy); |
pthread_mutex_unlock(&listElement->busy); |
2529 |
} |
} |
2530 |
} |
} |
2538 |
int Result = 0; |
int Result = 0; |
2539 |
PThreadListElement cur = threadList, last = threadList; |
PThreadListElement cur = threadList, last = threadList; |
2540 |
|
|
2541 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[THREAD COUNT %d]\n", threadCount)); |
|
printf("[THREAD COUNT %d]\n", threadCount); |
|
|
#endif |
|
2542 |
|
|
2543 |
while (cur) |
while (cur) |
2544 |
{ |
{ |
2571 |
Result = pthread_create(&cur->thread, NULL, (void *(*)(void *)) thread_function, cur); |
Result = pthread_create(&cur->thread, NULL, (void *(*)(void *)) thread_function, cur); |
2572 |
if (0 != Result) |
if (0 != Result) |
2573 |
{ |
{ |
2574 |
printf("[THREAD CREATE ERROR 0x%.8x]\n", Result); |
error("[THREAD CREATE ERROR 0x%.8x]\n", Result); |
2575 |
SC_xfree(&threadListHandle, cur); |
SC_xfree(&threadListHandle, cur); |
2576 |
SC_destroyThreadData(data); |
SC_destroyThreadData(data); |
2577 |
data = NULL; |
data = NULL; |
2632 |
#endif /* MAKE_PROTO */ |
#endif /* MAKE_PROTO */ |
2633 |
|
|
2634 |
void |
void |
2635 |
scard_tcp_lock(void) |
scard_lock(int lock) |
2636 |
{ |
{ |
2637 |
if (!tcp_sendcontrol_mutex) |
if (!scard_mutex) |
2638 |
|
{ |
2639 |
|
int i; |
2640 |
|
|
2641 |
|
scard_mutex = |
2642 |
|
(pthread_mutex_t **) xmalloc(sizeof(pthread_mutex_t *) * SCARD_LOCK_LAST); |
2643 |
|
|
2644 |
|
for (i = 0; i < SCARD_LOCK_LAST; i++) |
2645 |
|
{ |
2646 |
|
scard_mutex[i] = NULL; |
2647 |
|
} |
2648 |
|
} |
2649 |
|
|
2650 |
|
if (!scard_mutex[lock]) |
2651 |
{ |
{ |
2652 |
tcp_sendcontrol_mutex = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t)); |
scard_mutex[lock] = (pthread_mutex_t *) xmalloc(sizeof(pthread_mutex_t)); |
2653 |
pthread_mutex_init(tcp_sendcontrol_mutex, NULL); |
pthread_mutex_init(scard_mutex[lock], NULL); |
2654 |
} |
} |
2655 |
|
|
2656 |
pthread_mutex_lock(tcp_sendcontrol_mutex); |
pthread_mutex_lock(scard_mutex[lock]); |
2657 |
} |
} |
2658 |
|
|
2659 |
void |
void |
2660 |
scard_tcp_unlock(void) |
scard_unlock(int lock) |
2661 |
{ |
{ |
2662 |
pthread_mutex_unlock(tcp_sendcontrol_mutex); |
pthread_mutex_unlock(scard_mutex[lock]); |
2663 |
} |
} |
2664 |
|
|
2665 |
STREAM |
STREAM |