19 |
*/ |
*/ |
20 |
|
|
21 |
#include <stdio.h> |
#include <stdio.h> |
|
#include "rdesktop.h" |
|
22 |
#include <unistd.h> |
#include <unistd.h> |
23 |
#include <fcntl.h> |
#include <fcntl.h> |
24 |
#include <strings.h> |
#include <strings.h> |
26 |
#include <time.h> |
#include <time.h> |
27 |
#ifndef MAKE_PROTO |
#ifndef MAKE_PROTO |
28 |
#ifdef PCSC_OSX |
#ifdef PCSC_OSX |
29 |
|
#include <PCSC/wintypes.h> |
30 |
#include <PCSC/pcsclite.h> |
#include <PCSC/pcsclite.h> |
31 |
#include <PCSC/winscard.h> |
#include <PCSC/winscard.h> |
32 |
#else |
#else |
33 |
|
#include <wintypes.h> |
34 |
#include <pcsclite.h> |
#include <pcsclite.h> |
35 |
#include <winscard.h> |
#include <winscard.h> |
36 |
#endif /* PCSC_OSX */ |
#endif /* PCSC_OSX */ |
37 |
|
#include "rdesktop.h" |
38 |
#include "scard.h" |
#include "scard.h" |
39 |
|
|
40 |
/* variable segment */ |
/* variable segment */ |
46 |
|
|
47 |
static struct stream out[STREAM_COUNT]; |
static struct stream out[STREAM_COUNT]; |
48 |
static int cur_stream_id = 0; |
static int cur_stream_id = 0; |
49 |
static pthread_mutex_t *tcp_sendcontrol_mutex = NULL; |
static pthread_mutex_t **scard_mutex = NULL; |
50 |
|
|
51 |
static uint32 curDevice = 0, curId = 0, curBytesOut = 0; |
static uint32 curDevice = 0, curId = 0, curBytesOut = 0; |
52 |
static PSCNameMapRec nameMapList = NULL; |
static PSCNameMapRec nameMapList = NULL; |
56 |
static pthread_mutex_t queueAccess; |
static pthread_mutex_t queueAccess; |
57 |
static pthread_mutex_t queueEmpty; |
static pthread_mutex_t queueEmpty; |
58 |
static pthread_mutex_t hcardAccess; |
static pthread_mutex_t hcardAccess; |
|
/* static pthread_mutex_t sendControl; */ |
|
59 |
|
|
60 |
static PMEM_HANDLE threadListHandle = NULL; |
static PMEM_HANDLE threadListHandle = NULL; |
61 |
static PThreadListElement threadList = NULL; |
static PThreadListElement threadList = NULL; |
81 |
|
|
82 |
#ifndef MAKE_PROTO |
#ifndef MAKE_PROTO |
83 |
|
|
84 |
static NTSTATUS |
static RD_NTSTATUS |
85 |
scard_create(uint32 device_id, uint32 accessmask, uint32 sharemode, uint32 create_disposition, |
scard_create(uint32 device_id, uint32 accessmask, uint32 sharemode, uint32 create_disposition, |
86 |
uint32 flags_and_attributes, char *filename, NTHANDLE * phandle) |
uint32 flags_and_attributes, char *filename, RD_NTHANDLE * phandle) |
87 |
{ |
{ |
88 |
return STATUS_SUCCESS; |
return RD_STATUS_SUCCESS; |
89 |
} |
} |
90 |
|
|
91 |
static NTSTATUS |
static RD_NTSTATUS |
92 |
scard_close(NTHANDLE handle) |
scard_close(RD_NTHANDLE handle) |
93 |
{ |
{ |
94 |
return STATUS_SUCCESS; |
return RD_STATUS_SUCCESS; |
95 |
} |
} |
96 |
|
|
97 |
static NTSTATUS |
static RD_NTSTATUS |
98 |
scard_read(NTHANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result) |
scard_read(RD_NTHANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result) |
99 |
{ |
{ |
100 |
return STATUS_SUCCESS; |
return RD_STATUS_SUCCESS; |
101 |
} |
} |
102 |
|
|
103 |
static NTSTATUS |
static RD_NTSTATUS |
104 |
scard_write(NTHANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result) |
scard_write(RD_NTHANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result) |
105 |
{ |
{ |
106 |
return STATUS_SUCCESS; |
return RD_STATUS_SUCCESS; |
107 |
} |
} |
108 |
#endif /* MAKE_PROTO */ |
#endif /* MAKE_PROTO */ |
109 |
|
|
127 |
rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); |
rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); |
128 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
129 |
{ |
{ |
130 |
printf("[SMART CARD: PCSC service not available]\n"); |
error("[SMART CARD: PCSC service not available]\n"); |
131 |
return 0; |
return 0; |
132 |
} |
} |
133 |
else |
else |
137 |
|
|
138 |
if (0 != pthread_mutex_init(&queueAccess, NULL)) |
if (0 != pthread_mutex_init(&queueAccess, NULL)) |
139 |
{ |
{ |
140 |
printf("[SMART CARD: Can't initialize queue access mutex]\n"); |
error("[SMART CARD: Can't initialize queue access mutex]\n"); |
141 |
return 0; |
return 0; |
142 |
} |
} |
143 |
|
|
144 |
if (0 != pthread_mutex_init(&queueEmpty, NULL)) |
if (0 != pthread_mutex_init(&queueEmpty, NULL)) |
145 |
{ |
{ |
146 |
printf("[SMART CARD: Can't initialize queue control mutex]\n"); |
error("[SMART CARD: Can't initialize queue control mutex]\n"); |
147 |
return 0; |
return 0; |
148 |
} |
} |
149 |
|
|
150 |
if (0 != pthread_mutex_init(&hcardAccess, NULL)) |
if (0 != pthread_mutex_init(&hcardAccess, NULL)) |
151 |
{ |
{ |
152 |
printf("[SMART CARD: Can't initialize hcard list access mutex]\n"); |
error("[SMART CARD: Can't initialize hcard list access mutex]\n"); |
153 |
return 0; |
return 0; |
154 |
} |
} |
155 |
|
|
|
#if 0 |
|
|
if (0 != pthread_mutex_init(&sendControl, NULL)) |
|
|
{ |
|
|
printf("[SMART CARD: Can't initialize send control mutex]\n"); |
|
|
return 0; |
|
|
} |
|
|
#endif |
|
|
|
|
|
|
|
156 |
if (0 != |
if (0 != |
157 |
pthread_create(&queueHandler, NULL, (void *(*)(void *)) queue_handler_function, NULL)) |
pthread_create(&queueHandler, NULL, (void *(*)(void *)) queue_handler_function, NULL)) |
158 |
{ |
{ |
159 |
printf("[SMART CARD: Can't create queue handling Thread]\n"); |
error("[SMART CARD: Can't create queue handling Thread]\n"); |
160 |
return 0; |
return 0; |
161 |
} |
} |
162 |
|
|
225 |
} |
} |
226 |
} |
} |
227 |
|
|
|
|
|
|
printf("******************************************************\n"); |
|
|
printf("* Smart Card support for RDesktop is initialized. *\n"); |
|
|
printf("* Copyright (C) by Alexi Volkov, alexi@myrealbox.com *\n"); |
|
|
printf("******************************************************\n"); |
|
|
|
|
228 |
return count; |
return count; |
229 |
} |
} |
230 |
|
|
483 |
} |
} |
484 |
|
|
485 |
static void |
static void |
486 |
outForceAllignment(STREAM out, unsigned int seed) |
outForceAlignment(STREAM out, unsigned int seed) |
487 |
{ |
{ |
488 |
SERVER_DWORD add = (seed - (out->p - out->data) % seed) % seed; |
SERVER_DWORD add = (seed - (out->p - out->data) % seed) % seed; |
489 |
if (add > 0) |
if (add > 0) |
|
{ |
|
490 |
out_uint8s(out, add); |
out_uint8s(out, add); |
|
} |
|
491 |
} |
} |
492 |
|
|
493 |
static unsigned int |
static unsigned int |
494 |
inString(PMEM_HANDLE * handle, STREAM in, char **destination, SERVER_DWORD dataLength, BOOL wide) |
inString(PMEM_HANDLE * handle, STREAM in, char **destination, SERVER_DWORD dataLength, RD_BOOL wide) |
495 |
{ |
{ |
496 |
unsigned int Result = (wide) ? (2 * dataLength) : (dataLength); |
unsigned int Result = (wide) ? (2 * dataLength) : (dataLength); |
497 |
PMEM_HANDLE lcHandle = NULL; |
PMEM_HANDLE lcHandle = NULL; |
525 |
} |
} |
526 |
|
|
527 |
static unsigned int |
static unsigned int |
528 |
outString(STREAM out, char *source, BOOL wide) |
outString(STREAM out, char *source, RD_BOOL wide) |
529 |
{ |
{ |
530 |
PMEM_HANDLE lcHandle = NULL; |
PMEM_HANDLE lcHandle = NULL; |
531 |
char *reader = getAlias(source); |
char *reader = getAlias(source); |
559 |
} |
} |
560 |
|
|
561 |
static void |
static void |
562 |
inReaderName(PMEM_HANDLE * handle, STREAM in, char **destination, BOOL wide) |
inReaderName(PMEM_HANDLE * handle, STREAM in, char **destination, RD_BOOL wide) |
563 |
{ |
{ |
564 |
SERVER_DWORD dataLength; |
SERVER_DWORD dataLength; |
565 |
in->p += 0x08; |
in->p += 0x08; |
604 |
MYPCSC_SCARDCONTEXT hContext; |
MYPCSC_SCARDCONTEXT hContext; |
605 |
/* code segment */ |
/* code segment */ |
606 |
|
|
607 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("Establishing PC/SC Context... \n")); |
|
printf("Establishing PC/SC Context... \n"); |
|
|
#endif |
|
608 |
rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); |
rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); |
|
#ifdef WITH_SCARD_DEBUG |
|
609 |
if (rv) |
if (rv) |
610 |
printf("<--ERROR SCardEstablishContext Code=0x%.8x]-->\n", (unsigned int) rv); |
{ |
611 |
|
DEBUG_SCARD(("<--ERROR SCardEstablishContext Code=0x%.8x, %s]-->\n", |
612 |
|
(unsigned int) rv, pcsc_stringify_error(rv))); |
613 |
|
} |
614 |
else |
else |
615 |
printf("<--SUCCESS SCardEstablishContext-->\n"); |
{ |
616 |
#endif |
DEBUG_SCARD(("<--SUCCESS SCardEstablishContext-->\n")); |
617 |
|
} |
618 |
|
|
619 |
out_uint32_le(out, 0x00000004); |
out_uint32_le(out, 0x00000004); |
620 |
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) */ |
632 |
|
|
633 |
in->p += 0x1C; |
in->p += 0x1C; |
634 |
in_uint32_le(in, hContext); |
in_uint32_le(in, hContext); |
635 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[CONTEXT 0x%.8x]\n", (unsigned int) hContext)); |
636 |
printf("[CONTEXT 0x%.8x]\n", (unsigned int) hContext); |
DEBUG_SCARD(("Releasing context... \n")); |
|
printf("Releasing context... \n"); |
|
|
#endif |
|
637 |
rv = SCardReleaseContext((MYPCSC_SCARDCONTEXT) hContext); |
rv = SCardReleaseContext((MYPCSC_SCARDCONTEXT) hContext); |
638 |
#ifdef WITH_SCARD_DEBUG |
|
639 |
if (rv) |
if (rv) |
640 |
printf("<--ERROR SCardReleaseContext Code=0x%.8x-->\n", (unsigned int) rv); |
{ |
641 |
|
DEBUG_SCARD(("<--ERROR SCardReleaseContext Code=0x%.8x, %s-->\n", (unsigned int) rv, |
642 |
|
pcsc_stringify_error(rv))); |
643 |
|
} |
644 |
else |
else |
645 |
printf("<--SUCCESS SCardReleaseContext-->\n"); |
{ |
646 |
#endif |
DEBUG_SCARD(("<--SUCCESS SCardReleaseContext-->\n")); |
647 |
|
} |
648 |
|
|
649 |
return rv; |
return rv; |
650 |
} |
} |
651 |
|
|
660 |
|
|
661 |
in->p += 0x1C; |
in->p += 0x1C; |
662 |
in_uint32_le(in, hContext); |
in_uint32_le(in, hContext); |
663 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[CONTEXT 0x%.8x]\n", (unsigned int) hContext)); |
664 |
printf("[CONTEXT 0x%.8x]\n", (unsigned int) hContext); |
DEBUG_SCARD(("Checking... \n")); |
|
printf("Checking... \n"); |
|
|
#endif |
|
665 |
/* 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 */ |
666 |
|
|
667 |
readers = SC_xmalloc(&lcHandle, 1024); |
readers = SC_xmalloc(&lcHandle, 1024); |
669 |
return SC_returnNoMemoryError(&lcHandle, in, out); |
return SC_returnNoMemoryError(&lcHandle, in, out); |
670 |
|
|
671 |
rv = SCardListReaders((MYPCSC_SCARDCONTEXT) hContext, NULL, readers, &readerCount); |
rv = SCardListReaders((MYPCSC_SCARDCONTEXT) hContext, NULL, readers, &readerCount); |
672 |
|
|
673 |
if (rv) |
if (rv) |
674 |
{ |
{ |
675 |
#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 |
|
676 |
rv = SCARD_E_INVALID_HANDLE; |
rv = SCARD_E_INVALID_HANDLE; |
677 |
} |
} |
|
#ifdef WITH_SCARD_DEBUG |
|
678 |
else |
else |
679 |
printf("<--SUCCESS SCardListReaders (no SCardIsValidContext)-->\n"); |
{ |
680 |
#endif |
DEBUG_SCARD(("<--SUCCESS SCardListReaders (no SCardIsValidContext)-->\n")); |
681 |
outForceAllignment(out, 8); |
} |
682 |
|
|
683 |
|
outForceAlignment(out, 8); |
684 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
685 |
return rv; |
return rv; |
686 |
} |
} |
687 |
|
|
688 |
|
|
689 |
static MYPCSC_DWORD |
static MYPCSC_DWORD |
690 |
TS_SCardListReaders(STREAM in, STREAM out, BOOL wide) |
TS_SCardListReaders(STREAM in, STREAM out, RD_BOOL wide) |
691 |
{ |
{ |
692 |
#define readerArraySize 1024 |
#define readerArraySize 1024 |
693 |
MYPCSC_DWORD rv; |
MYPCSC_DWORD rv; |
700 |
|
|
701 |
in->p += 0x2C; |
in->p += 0x2C; |
702 |
in_uint32_le(in, hContext); |
in_uint32_le(in, hContext); |
703 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[CONTEXT 0x%.8x]\n", (unsigned int) hContext)); |
|
printf("[CONTEXT 0x%.8x]\n", (unsigned int) hContext); |
|
|
#endif |
|
704 |
plen1 = out->p; |
plen1 = out->p; |
705 |
out_uint32_le(out, 0x00000000); /* Temp value for data length as 0x0 */ |
out_uint32_le(out, 0x00000000); /* Temp value for data length as 0x0 */ |
706 |
out_uint32_le(out, 0x01760650); |
out_uint32_le(out, 0x01760650); |
721 |
{ |
{ |
722 |
int i; |
int i; |
723 |
PSCNameMapRec tmpMap; |
PSCNameMapRec tmpMap; |
724 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
725 |
printf("[CALL RESULT of SCardListReaders 0x%.8x]\n", (unsigned int) rv); |
DEBUG_SCARD(("[CALL RESULT of SCardListReaders 0x%.8x]\n", (unsigned int) rv)); |
726 |
hexdump((void *) readers, cchReaders); |
hexdump((void *) readers, cchReaders); |
727 |
#endif |
#endif |
728 |
for (i = 0, tmpMap = nameMapList; i < nameMapCount; i++, tmpMap++) |
for (i = 0, tmpMap = nameMapList; i < nameMapCount; i++, tmpMap++) |
753 |
out_uint32_le(out, dataLength); |
out_uint32_le(out, dataLength); |
754 |
out->p = pend; |
out->p = pend; |
755 |
|
|
756 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
757 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
758 |
return rv; |
return rv; |
759 |
} |
} |
760 |
|
|
761 |
|
|
762 |
static MYPCSC_DWORD |
static MYPCSC_DWORD |
763 |
TS_SCardConnect(STREAM in, STREAM out, BOOL wide) |
TS_SCardConnect(STREAM in, STREAM out, RD_BOOL wide) |
764 |
{ |
{ |
765 |
MYPCSC_DWORD rv; |
MYPCSC_DWORD rv; |
766 |
SCARDCONTEXT hContext; |
SCARDCONTEXT hContext; |
776 |
in->p += 0x1C; |
in->p += 0x1C; |
777 |
in_uint32_le(in, dwShareMode); |
in_uint32_le(in, dwShareMode); |
778 |
in_uint32_le(in, dwPreferredProtocol); |
in_uint32_le(in, dwPreferredProtocol); |
779 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[SHARE %8x]\n", (unsigned int) dwShareMode)); |
780 |
printf("[SHARE %8x]\n", (unsigned int) dwShareMode); |
DEBUG_SCARD(("[PROTO %8x]\n", (unsigned int) dwPreferredProtocol)); |
|
printf("[PROTO %8x]\n", (unsigned int) dwPreferredProtocol); |
|
|
#endif |
|
781 |
inReaderName(&lcHandle, in, &szReader, wide); |
inReaderName(&lcHandle, in, &szReader, wide); |
782 |
#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 |
|
783 |
in->p += 0x04; |
in->p += 0x04; |
784 |
in_uint32_le(in, hContext); |
in_uint32_le(in, hContext); |
785 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[CONTEXT 0x%.8x]\n", (unsigned int) hContext)); |
|
printf("[CONTEXT 0x%.8x]\n", (unsigned int) hContext); |
|
|
#endif |
|
786 |
rv = SCardConnect(hContext, szReader, (MYPCSC_DWORD) dwShareMode, |
rv = SCardConnect(hContext, szReader, (MYPCSC_DWORD) dwShareMode, |
787 |
(MYPCSC_DWORD) dwPreferredProtocol, &myHCard, &dwActiveProtocol); |
(MYPCSC_DWORD) dwPreferredProtocol, &myHCard, &dwActiveProtocol); |
788 |
hCard = scHandleToServer(myHCard); |
hCard = scHandleToServer(myHCard); |
789 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[RECEIVED HCARD 0x%016lx]\n", (unsigned long) myHCard)); |
790 |
printf("[RECEIVED HCARD 0x%016lx]\n", myHCard); |
DEBUG_SCARD(("[MANGLED HCARD 0x%08x]\n", hCard)); |
|
printf("[MANGLED HCARD 0x%08x]\n", hCard); |
|
|
#endif |
|
791 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
792 |
{ |
{ |
793 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<--ERROR SCardConnect Code=0x%.8x, %s-->\n", (unsigned int) rv, |
794 |
printf("<--ERROR SCardConnect Code=0x%.8x-->\n", (unsigned int) rv); |
pcsc_stringify_error(rv))); |
|
#endif |
|
795 |
} |
} |
796 |
else |
else |
797 |
{ |
{ |
798 |
char *szVendor = getVendor(szReader); |
char *szVendor = getVendor(szReader); |
799 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<--SUCCESS ScardConnect-->\n")); |
|
printf("<--SUCCESS ScardConnect-->\n"); |
|
|
#endif |
|
800 |
if (szVendor && (strlen(szVendor) > 0)) |
if (szVendor && (strlen(szVendor) > 0)) |
801 |
{ |
{ |
802 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("Set Attribute ATTR_VENDOR_NAME\n")); |
|
printf("Set Attribute ATTR_VENDOR_NAME\n"); |
|
|
#endif |
|
803 |
pthread_mutex_lock(&hcardAccess); |
pthread_mutex_lock(&hcardAccess); |
804 |
PSCHCardRec hcard = xmalloc(sizeof(TSCHCardRec)); |
PSCHCardRec hcard = xmalloc(sizeof(TSCHCardRec)); |
805 |
if (hcard) |
if (hcard) |
829 |
out_uint32_le(out, 0x00000004); |
out_uint32_le(out, 0x00000004); |
830 |
out_uint32_le(out, hCard); |
out_uint32_le(out, hCard); |
831 |
|
|
832 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
833 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
834 |
return rv; |
return rv; |
835 |
} |
} |
855 |
in->p += 0x04; |
in->p += 0x04; |
856 |
in_uint32_le(in, hCard); |
in_uint32_le(in, hCard); |
857 |
myHCard = scHandleToMyPCSC(hCard); |
myHCard = scHandleToMyPCSC(hCard); |
858 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[SHARE = 0x%.8x]\n", (unsigned int) dwShareMode)); |
859 |
printf("[SHARE = 0x%.8x]\n", (unsigned int) dwShareMode); |
DEBUG_SCARD(("[PROTO = 0x%.8x]\n", (unsigned int) dwPreferredProtocol)); |
860 |
printf("[PROTO = 0x%.8x]\n", (unsigned int) dwPreferredProtocol); |
DEBUG_SCARD(("[INIT = 0x%.8x]\n", (unsigned int) dwInitialization)); |
861 |
printf("[INIT = 0x%.8x]\n", (unsigned int) dwInitialization); |
DEBUG_SCARD(("[hContext = 0x%.8x]\n", (unsigned int) hContext)); |
862 |
printf("[hContext = 0x%.8x]\n", (unsigned int) hContext); |
DEBUG_SCARD(("[hCard = 0x%.8x]\n", (unsigned int) hCard)); |
863 |
printf("[hCard = 0x%.8x]\n", (unsigned int) hCard); |
DEBUG_SCARD(("[myHCard = 0x%016lx]\n", (unsigned long) myHCard)); |
|
printf("[myHCard = 0x%016lx]\n", myHCard); |
|
|
#endif |
|
864 |
rv = SCardReconnect(myHCard, (MYPCSC_DWORD) dwShareMode, (MYPCSC_DWORD) dwPreferredProtocol, |
rv = SCardReconnect(myHCard, (MYPCSC_DWORD) dwShareMode, (MYPCSC_DWORD) dwPreferredProtocol, |
865 |
(MYPCSC_DWORD) dwInitialization, &dwActiveProtocol); |
(MYPCSC_DWORD) dwInitialization, &dwActiveProtocol); |
|
#ifdef WITH_SCARD_DEBUG |
|
866 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
867 |
printf("<--ERROR SCardReconnect Code=0x%.8x-->\n", (unsigned int) rv); |
{ |
868 |
|
DEBUG_SCARD(("<--ERROR SCardReconnect Code=0x%.8x, %s-->\n", (unsigned int) rv, |
869 |
|
pcsc_stringify_error(rv))); |
870 |
|
} |
871 |
else |
else |
872 |
printf("<--SUCCESS SCardReconnect-->\n"); |
{ |
873 |
#endif |
DEBUG_SCARD(("<--SUCCESS SCardReconnect-->\n")); |
874 |
|
} |
875 |
|
|
876 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
877 |
out_uint32_le(out, (SERVER_DWORD) dwActiveProtocol); |
out_uint32_le(out, (SERVER_DWORD) dwActiveProtocol); |
878 |
return rv; |
return rv; |
879 |
} |
} |
894 |
in->p += 0x04; |
in->p += 0x04; |
895 |
in_uint32_le(in, hCard); |
in_uint32_le(in, hCard); |
896 |
|
|
897 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[hContext = 0x%.8x]\n", (unsigned int) hContext)); |
898 |
printf("[hContext = 0x%.8x]\n", (unsigned int) hContext); |
DEBUG_SCARD(("[hCard = 0x%.8x]\n", (unsigned int) hCard)); |
899 |
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 |
|
900 |
|
|
901 |
pthread_mutex_lock(&hcardAccess); |
pthread_mutex_lock(&hcardAccess); |
902 |
PSCHCardRec hcard = hcardFirst; |
PSCHCardRec hcard = hcardFirst; |
920 |
myHCard = scHandleToMyPCSC(hCard); |
myHCard = scHandleToMyPCSC(hCard); |
921 |
rv = SCardDisconnect(myHCard, (MYPCSC_DWORD) dwDisposition); |
rv = SCardDisconnect(myHCard, (MYPCSC_DWORD) dwDisposition); |
922 |
|
|
|
#ifdef WITH_SCARD_DEBUG |
|
923 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
924 |
printf("<--ERROR SCardDisconnect Code=0x%.8x-->\n", (unsigned int) rv); |
{ |
925 |
|
DEBUG_SCARD(("<--ERROR SCardDisconnect Code=0x%.8x, %s-->\n", (unsigned int) rv, |
926 |
|
pcsc_stringify_error(rv))); |
927 |
|
} |
928 |
else |
else |
929 |
printf("<--SUCCESS SCardDisconnect-->\n"); |
{ |
930 |
#endif |
DEBUG_SCARD(("<--SUCCESS SCardDisconnect-->\n")); |
931 |
outForceAllignment(out, 8); |
} |
932 |
|
|
933 |
|
outForceAlignment(out, 8); |
934 |
return rv; |
return rv; |
935 |
} |
} |
936 |
|
|
953 |
return recall; |
return recall; |
954 |
} |
} |
955 |
|
|
956 |
static BOOL |
static RD_BOOL |
957 |
mappedStatus(MYPCSC_DWORD code) |
mappedStatus(MYPCSC_DWORD code) |
958 |
{ |
{ |
959 |
code >>= 16; |
code >>= 16; |
962 |
} |
} |
963 |
|
|
964 |
static MYPCSC_DWORD |
static MYPCSC_DWORD |
965 |
incStatus(MYPCSC_DWORD code, BOOL mapped) |
incStatus(MYPCSC_DWORD code, RD_BOOL mapped) |
966 |
{ |
{ |
967 |
if (mapped || (code & SCARD_STATE_CHANGED)) |
if (mapped || (code & SCARD_STATE_CHANGED)) |
968 |
{ |
{ |
1016 |
|
|
1017 |
|
|
1018 |
static MYPCSC_DWORD |
static MYPCSC_DWORD |
1019 |
TS_SCardGetStatusChange(STREAM in, STREAM out, BOOL wide) |
TS_SCardGetStatusChange(STREAM in, STREAM out, RD_BOOL wide) |
1020 |
{ |
{ |
1021 |
MYPCSC_DWORD rv; |
MYPCSC_DWORD rv; |
1022 |
SERVER_SCARDCONTEXT hContext; |
SERVER_SCARDCONTEXT hContext; |
1028 |
long i; |
long i; |
1029 |
PMEM_HANDLE lcHandle = NULL; |
PMEM_HANDLE lcHandle = NULL; |
1030 |
#if 0 |
#if 0 |
1031 |
BOOL mapped = False; |
RD_BOOL mapped = False; |
1032 |
#endif |
#endif |
1033 |
|
|
1034 |
in->p += 0x18; |
in->p += 0x18; |
1037 |
in->p += 0x08; |
in->p += 0x08; |
1038 |
in_uint32_le(in, hContext); |
in_uint32_le(in, hContext); |
1039 |
in->p += 0x04; |
in->p += 0x04; |
1040 |
#ifdef WITH_SCARD_DEBUG |
|
1041 |
printf("[CONTEXT 0x%.8x]\n", (unsigned int) hContext); |
DEBUG_SCARD(("[CONTEXT 0x%.8x]\n", (unsigned int) hContext)); |
1042 |
printf("[dwTimeout 0x%.8x]\n", (unsigned int) dwTimeout); |
DEBUG_SCARD(("[dwTimeout 0x%.8x]\n", (unsigned int) dwTimeout)); |
1043 |
printf("[COUNT %d]\n", (unsigned int) dwCount); |
DEBUG_SCARD(("[COUNT %d]\n", (unsigned int) dwCount)); |
1044 |
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))); |
1045 |
#endif |
|
1046 |
if (dwCount > 0) |
if (dwCount > 0) |
1047 |
{ |
{ |
1048 |
rsArray = SC_xmalloc(&lcHandle, dwCount * sizeof(SERVER_SCARD_READERSTATE_A)); |
rsArray = SC_xmalloc(&lcHandle, dwCount * sizeof(SERVER_SCARD_READERSTATE_A)); |
1059 |
in->p += 0x04; |
in->p += 0x04; |
1060 |
in_uint8a(in, cur, SERVER_SCARDSTATESIZE); |
in_uint8a(in, cur, SERVER_SCARDSTATESIZE); |
1061 |
} |
} |
1062 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
1063 |
printf("[READERS DUMP 1]------------------\n"); |
DEBUG_SCARD(("[READERS DUMP 1]------------------\n")); |
1064 |
hexdump((void *) rsArray, dwCount * sizeof(SERVER_SCARD_READERSTATE_A)); |
hexdump((void *) rsArray, dwCount * sizeof(SERVER_SCARD_READERSTATE_A)); |
1065 |
#endif |
#endif |
1066 |
|
|
1097 |
|
|
1098 |
in->p += 0x08; |
in->p += 0x08; |
1099 |
in_uint32_le(in, dataLength); |
in_uint32_le(in, dataLength); |
1100 |
#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 |
|
1101 |
inRepos(in, |
inRepos(in, |
1102 |
inString(&lcHandle, in, (char **) &(cur->szReader), dataLength, |
inString(&lcHandle, in, (char **) &(cur->szReader), dataLength, |
1103 |
wide)); |
wide)); |
1105 |
if (strcmp(cur->szReader, "\\\\?PnP?\\Notification") == 0) |
if (strcmp(cur->szReader, "\\\\?PnP?\\Notification") == 0) |
1106 |
cur->dwCurrentState |= SCARD_STATE_IGNORE; |
cur->dwCurrentState |= SCARD_STATE_IGNORE; |
1107 |
} |
} |
1108 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
1109 |
printf("[READERS DUMP 2]------------------\n"); |
DEBUG_SCARD(("[READERS DUMP 2]------------------\n")); |
1110 |
hexdump((void *) rsArray, dwCount * sizeof(SERVER_SCARD_READERSTATE_A)); |
hexdump((void *) rsArray, dwCount * sizeof(SERVER_SCARD_READERSTATE_A)); |
1111 |
#endif |
#endif |
1112 |
} |
} |
1116 |
stateArray = NULL; |
stateArray = NULL; |
1117 |
} |
} |
1118 |
|
|
1119 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("\nCalling SCardGetStatusChange...\n")); |
|
printf("\nCalling SCardGetStatusChange...\n"); |
|
|
#endif |
|
1120 |
|
|
1121 |
|
|
1122 |
myRsArray = SC_xmalloc(&lcHandle, dwCount * sizeof(MYPCSC_SCARD_READERSTATE_A)); |
myRsArray = SC_xmalloc(&lcHandle, dwCount * sizeof(MYPCSC_SCARD_READERSTATE_A)); |
1124 |
return SC_returnNoMemoryError(&lcHandle, in, out); |
return SC_returnNoMemoryError(&lcHandle, in, out); |
1125 |
memset(myRsArray, 0, dwCount * sizeof(SERVER_SCARD_READERSTATE_A)); |
memset(myRsArray, 0, dwCount * sizeof(SERVER_SCARD_READERSTATE_A)); |
1126 |
copyReaderState_ServerToMyPCSC(rsArray, myRsArray, (SERVER_DWORD) dwCount); |
copyReaderState_ServerToMyPCSC(rsArray, myRsArray, (SERVER_DWORD) dwCount); |
1127 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
1128 |
printf("[TRANSLATION OF READERS]--------------------\n"); |
DEBUG_SCARD(("[TRANSLATION OF READERS]--------------------\n")); |
1129 |
hexdump((void *) myRsArray, dwCount * sizeof(MYPCSC_SCARD_READERSTATE_A)); |
hexdump((void *) myRsArray, dwCount * sizeof(MYPCSC_SCARD_READERSTATE_A)); |
1130 |
#endif |
#endif |
1131 |
|
|
1133 |
myRsArray, (MYPCSC_DWORD) dwCount); |
myRsArray, (MYPCSC_DWORD) dwCount); |
1134 |
copyReaderState_MyPCSCToServer(myRsArray, rsArray, (MYPCSC_DWORD) dwCount); |
copyReaderState_MyPCSCToServer(myRsArray, rsArray, (MYPCSC_DWORD) dwCount); |
1135 |
|
|
|
#ifdef WITH_SCARD_DEBUG |
|
1136 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
1137 |
printf("<--ERROR SCardGetStatusChange Code=0x%.8x-->\n", (unsigned int) rv); |
{ |
1138 |
|
DEBUG_SCARD(("<--ERROR SCardGetStatusChange Code=0x%.8x, %s-->\n", |
1139 |
|
(unsigned int) rv, pcsc_stringify_error(rv))); |
1140 |
|
} |
1141 |
else |
else |
1142 |
printf("<--SUCCESS SCardGetStatusChange-->\n"); |
{ |
1143 |
|
DEBUG_SCARD(("<--SUCCESS SCardGetStatusChange-->\n")); |
1144 |
|
} |
1145 |
|
|
1146 |
|
#ifdef WITH_DEBUG_SCARD |
1147 |
if (dwCount > 0) |
if (dwCount > 0) |
1148 |
{ |
{ |
1149 |
printf("[READERS DUMP]------------------\n"); |
DEBUG_SCARD(("[READERS DUMP]------------------\n")); |
1150 |
hexdump((void *) rsArray, dwCount * sizeof(SERVER_SCARD_READERSTATE_A)); |
hexdump((void *) rsArray, dwCount * sizeof(SERVER_SCARD_READERSTATE_A)); |
1151 |
} |
} |
1152 |
#endif |
#endif |
1188 |
out_uint8p(out, (void *) ((unsigned char **) cur + 2), |
out_uint8p(out, (void *) ((unsigned char **) cur + 2), |
1189 |
sizeof(SERVER_SCARD_READERSTATE_A) - 2 * sizeof(unsigned char *)); |
sizeof(SERVER_SCARD_READERSTATE_A) - 2 * sizeof(unsigned char *)); |
1190 |
} |
} |
1191 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
1192 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
1193 |
return rv; |
return rv; |
1194 |
} |
} |
1201 |
|
|
1202 |
in->p += 0x1C; |
in->p += 0x1C; |
1203 |
in_uint32_le(in, hContext); |
in_uint32_le(in, hContext); |
1204 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[CONTEXT 0x%.8x]\n", (unsigned int) hContext)); |
1205 |
printf("[CONTEXT 0x%.8x]\n", (unsigned int) hContext); |
DEBUG_SCARD(("Canceling... \n")); |
|
printf("Canceling... \n"); |
|
|
#endif |
|
1206 |
rv = SCardCancel((MYPCSC_SCARDCONTEXT) hContext); |
rv = SCardCancel((MYPCSC_SCARDCONTEXT) hContext); |
|
#ifdef WITH_SCARD_DEBUG |
|
1207 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
1208 |
printf("<--ERROR SCardCancel Code=0x%.8x-->\n", (unsigned int) rv); |
{ |
1209 |
|
DEBUG_SCARD(("<--ERROR SCardCancel Code=0x%.8x, %s-->\n", (unsigned int) rv, |
1210 |
|
pcsc_stringify_error(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 |
|
|
1220 |
static MYPCSC_DWORD |
static MYPCSC_DWORD |
1221 |
TS_SCardLocateCardsByATR(STREAM in, STREAM out, BOOL wide) |
TS_SCardLocateCardsByATR(STREAM in, STREAM out, RD_BOOL wide) |
1222 |
{ |
{ |
1223 |
int i, j, k; |
int i, j, k; |
1224 |
MYPCSC_DWORD rv; |
MYPCSC_DWORD rv; |
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, %s-->\n", (unsigned int) rv, pcsc_stringify_error(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 |
{ |
{ |
1287 |
for (j = 0, rsCur = rsArray; j < readerCount; j++, rsCur++) |
for (j = 0, rsCur = rsArray; j < readerCount; j++, rsCur++) |
1288 |
{ |
{ |
1289 |
BOOL equal = 1; |
RD_BOOL equal = 1; |
1290 |
for (k = 0; k < cur->cbAtr; k++) |
for (k = 0; k < cur->cbAtr; k++) |
1291 |
{ |
{ |
1292 |
/* This line check if them equal */ |
/* This line check if them equal */ |
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, %s-->\n", |
1342 |
|
(unsigned int) rv, pcsc_stringify_error(rv))); |
1343 |
|
} |
1344 |
else |
else |
1345 |
printf("<--SUCCESS SCardBeginTransaction-->\n"); |
{ |
1346 |
#endif |
DEBUG_SCARD(("<--SUCCESS SCardBeginTransaction-->\n")); |
1347 |
outForceAllignment(out, 8); |
} |
1348 |
|
outForceAlignment(out, 8); |
1349 |
return rv; |
return rv; |
1350 |
} |
} |
1351 |
|
|
1362 |
in->p += 0x0C; |
in->p += 0x0C; |
1363 |
in_uint32_le(in, hCard); |
in_uint32_le(in, hCard); |
1364 |
myHCard = scHandleToMyPCSC(hCard); |
myHCard = scHandleToMyPCSC(hCard); |
1365 |
#ifdef WITH_SCARD_DEBUG |
|
1366 |
printf("[hCard = 0x%.8x]\n", (unsigned int) hCard); |
DEBUG_SCARD(("[hCard = 0x%.8x]\n", (unsigned int) hCard)); |
1367 |
printf("[myHCard = 0x%016lx]\n", myHCard); |
DEBUG_SCARD(("[myHCard = 0x%016lx]\n", (unsigned long) myHCard)); |
1368 |
printf("[dwDisposition = 0x%.8x]\n", (unsigned int) dwDisposition); |
DEBUG_SCARD(("[dwDisposition = 0x%.8x]\n", (unsigned int) dwDisposition)); |
1369 |
#endif |
|
1370 |
rv = SCardEndTransaction(myHCard, (MYPCSC_DWORD) dwDisposition); |
rv = SCardEndTransaction(myHCard, (MYPCSC_DWORD) dwDisposition); |
|
#ifdef WITH_SCARD_DEBUG |
|
1371 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
1372 |
printf("<--ERROR SCardEndTransaction Code=0x%.8x-->\n", (unsigned int) rv); |
{ |
1373 |
|
DEBUG_SCARD(("<--ERROR SCardEndTransaction Code=0x%.8x, %s-->\n", (unsigned int) rv, |
1374 |
|
pcsc_stringify_error(rv))); |
1375 |
|
} |
1376 |
else |
else |
1377 |
printf("<--SUCCESS SCardEndTransaction-->\n"); |
{ |
1378 |
#endif |
DEBUG_SCARD(("<--SUCCESS SCardEndTransaction-->\n")); |
1379 |
outForceAllignment(out, 8); |
} |
1380 |
|
outForceAlignment(out, 8); |
1381 |
return rv; |
return rv; |
1382 |
} |
} |
1383 |
|
|
1476 |
|
|
1477 |
if (cbRecvLength) |
if (cbRecvLength) |
1478 |
{ |
{ |
|
/* 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; |
|
|
} |
|
|
|
|
|
|
|
1479 |
recvBuf = SC_xmalloc(&lcHandle, cbRecvLength); |
recvBuf = SC_xmalloc(&lcHandle, cbRecvLength); |
1480 |
if (!recvBuf) |
if (!recvBuf) |
1481 |
return SC_returnNoMemoryError(&lcHandle, in, out); |
return SC_returnNoMemoryError(&lcHandle, in, out); |
1509 |
else |
else |
1510 |
pioRecvPci = NULL; |
pioRecvPci = NULL; |
1511 |
|
|
1512 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
1513 |
printf("++++++++++\n"); |
DEBUG_SCARD(("++++++++++\n")); |
1514 |
printf("[SEND LEN = %d]\n", (unsigned int) cbSendLength); |
DEBUG_SCARD(("[SEND LEN = %d]\n", (unsigned int) cbSendLength)); |
1515 |
printf("[RECV LEN = %d]\n", (unsigned int) cbRecvLength); |
DEBUG_SCARD(("[RECV LEN = %d]\n", (unsigned int) cbRecvLength)); |
1516 |
printf("[hCard = 0x%.8x]\n", (unsigned int) hCard); |
DEBUG_SCARD(("[hCard = 0x%.8x]\n", (unsigned int) hCard)); |
1517 |
printf("[myHCard = 0x%016lx]\n", myHCard); |
DEBUG_SCARD(("[myHCard = 0x%016lx]\n", (unsigned long) myHCard)); |
1518 |
printf("[pioSendPci]\n"); |
DEBUG_SCARD(("[pioSendPci]\n")); |
1519 |
if (pioSendPci == NULL) |
if (pioSendPci == NULL) |
1520 |
printf("NULL\n"); |
{ |
1521 |
|
DEBUG_SCARD(("NULL\n")); |
1522 |
|
} |
1523 |
else |
else |
1524 |
|
{ |
1525 |
hexdump((void *) pioSendPci, pioSendPci->cbPciLength); |
hexdump((void *) pioSendPci, pioSendPci->cbPciLength); |
1526 |
printf("[pioRecvPci]\n"); |
} |
1527 |
|
|
1528 |
|
DEBUG_SCARD(("[pioRecvPci]\n")); |
1529 |
if (pioRecvPci == NULL) |
if (pioRecvPci == NULL) |
1530 |
printf("NULL\n"); |
{ |
1531 |
|
DEBUG_SCARD(("NULL\n")); |
1532 |
|
} |
1533 |
else |
else |
1534 |
|
{ |
1535 |
hexdump((void *) pioRecvPci, pioRecvPci->cbPciLength); |
hexdump((void *) pioRecvPci, pioRecvPci->cbPciLength); |
1536 |
printf("[sendBuf]\n"); |
} |
1537 |
|
DEBUG_SCARD(("[sendBuf]\n")); |
1538 |
hexdump(sendBuf, cbSendLength); |
hexdump(sendBuf, cbSendLength); |
1539 |
printf("++++++++++\n"); |
DEBUG_SCARD(("++++++++++\n")); |
1540 |
#endif |
#endif |
1541 |
|
|
1542 |
myCbRecvLength = cbRecvLength; |
myCbRecvLength = cbRecvLength; |
1564 |
rv = SCardTransmit(myHCard, myPioSendPci, sendBuf, (MYPCSC_DWORD) cbSendLength, |
rv = SCardTransmit(myHCard, myPioSendPci, sendBuf, (MYPCSC_DWORD) cbSendLength, |
1565 |
myPioRecvPci, recvBuf, &myCbRecvLength); |
myPioRecvPci, recvBuf, &myCbRecvLength); |
1566 |
cbRecvLength = myCbRecvLength; |
cbRecvLength = myCbRecvLength; |
1567 |
|
|
1568 |
|
/* FIXME: handle responses with length > 448 bytes */ |
1569 |
|
if (cbRecvLength > 448) |
1570 |
|
{ |
1571 |
|
warning("Card response limited from %d to 448 bytes!\n", cbRecvLength); |
1572 |
|
DEBUG_SCARD(("[RECV LEN %d -> %d]\n", (unsigned int) cbRecvLength, 400)); |
1573 |
|
cbRecvLength = 448; |
1574 |
|
} |
1575 |
|
|
1576 |
if (pioRecvPci) |
if (pioRecvPci) |
1577 |
{ |
{ |
1578 |
copyIORequest_MyPCSCToServer(myPioRecvPci, pioRecvPci); |
copyIORequest_MyPCSCToServer(myPioRecvPci, pioRecvPci); |
1580 |
|
|
1581 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
1582 |
{ |
{ |
1583 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<--ERROR SCardTransmit Code=0x%.8x, %s-->\n", (unsigned int) rv, |
1584 |
printf("<--ERROR SCardTransmit Code=0x%.8x-->\n", (unsigned int) rv); |
pcsc_stringify_error(rv))); |
|
#endif |
|
1585 |
} |
} |
1586 |
else |
else |
1587 |
{ |
{ |
1588 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
1589 |
printf("<--SUCCESS SCardTransmit-->\n"); |
DEBUG_SCARD(("<--SUCCESS SCardTransmit-->\n")); |
1590 |
printf("RESULT %d\n", (unsigned int) cbRecvLength); |
DEBUG_SCARD(("RESULT %d\n", (unsigned int) cbRecvLength)); |
1591 |
hexdump(recvBuf, cbRecvLength); |
hexdump(recvBuf, cbRecvLength); |
1592 |
if (myPioRecvPci) |
if (myPioRecvPci) |
1593 |
{ |
{ |
1594 |
printf("--- myPioRecvPci ---\n"); |
DEBUG_SCARD(("--- myPioRecvPci ---\n")); |
1595 |
hexdump((void *) myPioRecvPci, myPioRecvPci->cbPciLength); |
hexdump((void *) myPioRecvPci, myPioRecvPci->cbPciLength); |
1596 |
} |
} |
1597 |
printf("------------------\n"); |
DEBUG_SCARD(("------------------\n")); |
1598 |
#endif |
#endif |
1599 |
#if 0 |
#if 0 |
1600 |
if ((pioRecvPci != NULL) && (pioRecvPci->cbPciLength > 0)) |
if ((pioRecvPci != NULL) && (pioRecvPci->cbPciLength > 0)) |
1621 |
|
|
1622 |
outBufferFinish(out, (char *) recvBuf, cbRecvLength); |
outBufferFinish(out, (char *) recvBuf, cbRecvLength); |
1623 |
} |
} |
1624 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
1625 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
1626 |
return rv; |
return rv; |
1627 |
} |
} |
1628 |
|
|
1629 |
static MYPCSC_DWORD |
static MYPCSC_DWORD |
1630 |
TS_SCardStatus(STREAM in, STREAM out, BOOL wide) |
TS_SCardStatus(STREAM in, STREAM out, RD_BOOL wide) |
1631 |
{ |
{ |
1632 |
MYPCSC_DWORD rv; |
MYPCSC_DWORD rv; |
1633 |
SERVER_SCARDCONTEXT hCard; |
SERVER_SCARDCONTEXT hCard; |
1646 |
in_uint32_le(in, hCard); |
in_uint32_le(in, hCard); |
1647 |
in->p += 0x04; |
in->p += 0x04; |
1648 |
myHCard = scHandleToMyPCSC(hCard); |
myHCard = scHandleToMyPCSC(hCard); |
1649 |
#ifdef WITH_SCARD_DEBUG |
|
1650 |
printf("[hCard 0x%.8x]\n", (unsigned int) hCard); |
DEBUG_SCARD(("[hCard 0x%.8x]\n", (unsigned int) hCard)); |
1651 |
printf("[myHCard 0x%016lx]\n", myHCard); |
DEBUG_SCARD(("[myHCard 0x%016lx]\n", (unsigned long) myHCard)); |
1652 |
printf("[dwReaderLen %d]\n", (unsigned int) dwReaderLen); |
DEBUG_SCARD(("[dwReaderLen %d]\n", (unsigned int) dwReaderLen)); |
1653 |
printf("[dwAtrLen %d]\n", (unsigned int) dwAtrLen); |
DEBUG_SCARD(("[dwAtrLen %d]\n", (unsigned int) dwAtrLen)); |
|
#endif |
|
1654 |
|
|
1655 |
if (dwReaderLen <= 0 || dwReaderLen == SCARD_AUTOALLOCATE || dwReaderLen > SCARD_MAX_MEM) |
if (dwReaderLen <= 0 || dwReaderLen == SCARD_AUTOALLOCATE || dwReaderLen > SCARD_MAX_MEM) |
1656 |
dwReaderLen = SCARD_MAX_MEM; |
dwReaderLen = SCARD_MAX_MEM; |
1678 |
|
|
1679 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
1680 |
{ |
{ |
1681 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<--ERROR SCardStatus Code=0x%.8x, %s-->\n", (unsigned int) rv, |
1682 |
printf("<--ERROR SCardStatus Code=0x%.8x-->\n", (unsigned int) rv); |
pcsc_stringify_error(rv))); |
|
#endif |
|
1683 |
return SC_returnCode(rv, &lcHandle, in, out); |
return SC_returnCode(rv, &lcHandle, in, out); |
1684 |
} |
} |
1685 |
else |
else |
1686 |
{ |
{ |
1687 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
1688 |
printf("<--SUCCESS SCardStatus-->\n"); |
DEBUG_SCARD(("<--SUCCESS SCardStatus-->\n")); |
1689 |
printf("[dwState 0x%.8x]\n", (unsigned int) dwState); |
DEBUG_SCARD(("[dwState 0x%.8x]\n", (unsigned int) dwState)); |
1690 |
printf("[dwProtocol 0x%.8x]\n", (unsigned int) dwProtocol); |
DEBUG_SCARD(("[dwProtocol 0x%.8x]\n", (unsigned int) dwProtocol)); |
1691 |
printf("[Reader Name]\n"); |
DEBUG_SCARD(("[Reader Name]\n")); |
1692 |
hexdump((unsigned char *) readerName, dwReaderLen); |
hexdump((unsigned char *) readerName, dwReaderLen); |
1693 |
printf("[Atr]\n"); |
DEBUG_SCARD(("[Atr]\n")); |
1694 |
hexdump(atr, dwAtrLen); |
hexdump(atr, dwAtrLen); |
1695 |
#endif |
#endif |
1696 |
if (dwState & (SCARD_SPECIFIC | SCARD_NEGOTIABLE)) |
if (dwState & (SCARD_SPECIFIC | SCARD_NEGOTIABLE)) |
1738 |
out_uint32_le(out, dataLength); |
out_uint32_le(out, dataLength); |
1739 |
out->p = psave; |
out->p = psave; |
1740 |
} |
} |
1741 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
1742 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
1743 |
return rv; |
return rv; |
1744 |
} |
} |
1761 |
in_uint32_le(in, hCard); |
in_uint32_le(in, hCard); |
1762 |
in->p += 0x04; |
in->p += 0x04; |
1763 |
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 |
|
1764 |
|
|
1765 |
|
DEBUG_SCARD(("[hCard 0x%.8x]\n", (unsigned int) hCard)); |
1766 |
|
DEBUG_SCARD(("[myHCard 0x%.8x]\n", (unsigned int) myHCard)); |
1767 |
|
DEBUG_SCARD(("[dwAtrLen %d]\n", (unsigned int) dwAtrLen)); |
1768 |
|
|
1769 |
dwReaderLen = SCARD_MAX_MEM; |
dwReaderLen = SCARD_MAX_MEM; |
1770 |
if (dwAtrLen <= 0 || dwAtrLen == SCARD_AUTOALLOCATE || dwAtrLen > SCARD_MAX_MEM) |
if (dwAtrLen <= 0 || dwAtrLen == SCARD_AUTOALLOCATE || dwAtrLen > SCARD_MAX_MEM) |
1790 |
|
|
1791 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
1792 |
{ |
{ |
1793 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<--ERROR SCardStatus (no ScardState) Code=0x%.8x, %s-->\n", |
1794 |
printf("<--ERROR SCardStatus (no ScardState) Code=0x%.8x-->\n", (unsigned int) rv); |
(unsigned int) rv, pcsc_stringify_error(rv))); |
|
#endif |
|
1795 |
return SC_returnCode(rv, &lcHandle, in, out); |
return SC_returnCode(rv, &lcHandle, in, out); |
1796 |
} |
} |
1797 |
else |
else |
1798 |
{ |
{ |
1799 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
1800 |
printf("<--SUCCESS SCardStatus (no ScardState)-->\n"); |
DEBUG_SCARD(("<--SUCCESS SCardStatus (no ScardState)-->\n")); |
1801 |
printf("[dwState 0x%.8x]\n", (unsigned int) dwState); |
DEBUG_SCARD(("[dwState 0x%.8x]\n", (unsigned int) dwState)); |
1802 |
printf("[dwProtocol 0x%.8x]\n", (unsigned int) dwProtocol); |
DEBUG_SCARD(("[dwProtocol 0x%.8x]\n", (unsigned int) dwProtocol)); |
1803 |
printf("[Atr]\n"); |
DEBUG_SCARD(("[Atr]\n")); |
1804 |
hexdump(atr, dwAtrLen); |
hexdump(atr, dwAtrLen); |
1805 |
#endif |
#endif |
1806 |
if (dwState & (SCARD_SPECIFIC | SCARD_NEGOTIABLE)) |
if (dwState & (SCARD_SPECIFIC | SCARD_NEGOTIABLE)) |
1832 |
out_uint8p(out, atr, dwAtrLen); |
out_uint8p(out, atr, dwAtrLen); |
1833 |
outRepos(out, dwAtrLen); |
outRepos(out, dwAtrLen); |
1834 |
} |
} |
1835 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
1836 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
1837 |
return rv; |
return rv; |
1838 |
} |
} |
1868 |
dwGroups = groups; |
dwGroups = groups; |
1869 |
|
|
1870 |
if (rv) |
if (rv) |
|
#ifdef WITH_SCARD_DEBUG |
|
1871 |
{ |
{ |
1872 |
printf("<--ERROR SCardListReaderGroups Code=0x%.8x-->\n", (unsigned int) rv); |
DEBUG_SCARD(("<--ERROR SCardListReaderGroups Code=0x%.8x, %s-->\n", |
1873 |
#endif |
(unsigned int) rv, pcsc_stringify_error(rv))); |
1874 |
return SC_returnCode(rv, &lcHandle, in, out); |
return SC_returnCode(rv, &lcHandle, in, out); |
|
#ifdef WITH_SCARD_DEBUG |
|
1875 |
} |
} |
1876 |
else |
else |
1877 |
{ |
{ |
1878 |
printf("<--SUCCESS SCardListReaderGroups-->\n"); |
DEBUG_SCARD(("<--SUCCESS SCardListReaderGroups-->\n")); |
1879 |
} |
} |
|
#endif |
|
1880 |
|
|
1881 |
|
|
1882 |
out_uint32_le(out, dwGroups); |
out_uint32_le(out, dwGroups); |
1886 |
outRepos(out, dwGroups); |
outRepos(out, dwGroups); |
1887 |
out_uint32_le(out, 0x00000000); |
out_uint32_le(out, 0x00000000); |
1888 |
|
|
1889 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
1890 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
1891 |
return rv; |
return rv; |
1892 |
} |
} |
1912 |
|
|
1913 |
dwAttrId = dwAttrId & 0x0000FFFF; |
dwAttrId = dwAttrId & 0x0000FFFF; |
1914 |
|
|
1915 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[hCard = 0x%.8x]\n", (unsigned int) hCard)); |
1916 |
printf("[hCard = 0x%.8x]\n", (unsigned int) hCard); |
DEBUG_SCARD(("[myHCard 0x%.8x]\n", (unsigned int) myHCard)); |
1917 |
printf("[myHCard 0x%.8x]\n", (unsigned int) myHCard); |
DEBUG_SCARD(("[dwAttrId = 0x%.8x]\n", (unsigned int) dwAttrId)); |
1918 |
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 |
|
1919 |
|
|
1920 |
if (dwAttrLen > MAX_BUFFER_SIZE) |
if (dwAttrLen > MAX_BUFFER_SIZE) |
1921 |
dwAttrLen = MAX_BUFFER_SIZE; |
dwAttrLen = MAX_BUFFER_SIZE; |
1941 |
|
|
1942 |
if (dwAttrId == 0x00000100 && rv != SCARD_S_SUCCESS) |
if (dwAttrId == 0x00000100 && rv != SCARD_S_SUCCESS) |
1943 |
{ |
{ |
1944 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("Get Attribute ATTR_VENDOR_NAME\n")); |
|
printf("Get Attribute ATTR_VENDOR_NAME\n"); |
|
|
#endif |
|
1945 |
pthread_mutex_lock(&hcardAccess); |
pthread_mutex_lock(&hcardAccess); |
1946 |
PSCHCardRec hcard = hcardFirst; |
PSCHCardRec hcard = hcardFirst; |
1947 |
while (hcard) |
while (hcard) |
1956 |
hcard = hcard->next; |
hcard = hcard->next; |
1957 |
} |
} |
1958 |
pthread_mutex_unlock(&hcardAccess); |
pthread_mutex_unlock(&hcardAccess); |
1959 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[0x%.8x]\n", (unsigned int) rv)); |
|
printf("[0x%.8x]\n", (unsigned int) rv); |
|
|
#endif |
|
1960 |
} |
} |
1961 |
|
|
1962 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
1963 |
{ |
{ |
1964 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<--ERROR SCardGetAttrib Code=0x%.8x, %s-->\n", (unsigned int) rv, |
1965 |
printf("<--ERROR SCardGetAttrib Code=0x%.8x-->\n", (unsigned int) rv); |
pcsc_stringify_error(rv))); |
|
#endif |
|
1966 |
return SC_returnCode(rv, &lcHandle, in, out); |
return SC_returnCode(rv, &lcHandle, in, out); |
1967 |
} |
} |
1968 |
else |
else |
1969 |
{ |
{ |
1970 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
1971 |
printf("<--SUCCESS SCardGetAttrib-->\n"); |
DEBUG_SCARD(("<--SUCCESS SCardGetAttrib-->\n")); |
1972 |
printf("[LENGTH %d]\n", (unsigned int) dwAttrLen); |
DEBUG_SCARD(("[LENGTH %d]\n", (unsigned int) dwAttrLen)); |
1973 |
printf("+++++++++++++++++++++\n"); |
DEBUG_SCARD(("+++++++++++++++++++++\n")); |
1974 |
hexdump(pbAttr, dwAttrLen); |
hexdump(pbAttr, dwAttrLen); |
1975 |
printf("+++++++++++++++++++++\n"); |
DEBUG_SCARD(("+++++++++++++++++++++\n")); |
1976 |
#endif |
#endif |
1977 |
out_uint32_le(out, dwAttrLen); |
out_uint32_le(out, dwAttrLen); |
1978 |
out_uint32_le(out, 0x00000200); |
out_uint32_le(out, 0x00000200); |
1988 |
outRepos(out, dwAttrLen); |
outRepos(out, dwAttrLen); |
1989 |
out_uint32_le(out, 0x00000000); |
out_uint32_le(out, 0x00000000); |
1990 |
} |
} |
1991 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
1992 |
return rv; |
return rv; |
1993 |
} |
} |
1994 |
|
|
2013 |
|
|
2014 |
dwAttrId = dwAttrId & 0x0000FFFF; |
dwAttrId = dwAttrId & 0x0000FFFF; |
2015 |
|
|
2016 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[hCard = 0x%.8x]\n", (unsigned int) hCard)); |
2017 |
printf("[hCard = 0x%.8x]\n", (unsigned int) hCard); |
DEBUG_SCARD(("[myHCard 0x%.8x]\n", (unsigned int) myHCard)); |
2018 |
printf("[myHCard 0x%.8x]\n", (unsigned int) myHCard); |
DEBUG_SCARD(("[dwAttrId = 0x%.8x]\n", (unsigned int) dwAttrId)); |
2019 |
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 |
|
2020 |
|
|
2021 |
if (dwAttrLen > MAX_BUFFER_SIZE) |
if (dwAttrLen > MAX_BUFFER_SIZE) |
2022 |
dwAttrLen = MAX_BUFFER_SIZE; |
dwAttrLen = MAX_BUFFER_SIZE; |
2028 |
in_uint8a(in, pbAttr, dwAttrLen); |
in_uint8a(in, pbAttr, dwAttrLen); |
2029 |
rv = SCardSetAttrib(myHCard, (MYPCSC_DWORD) dwAttrId, pbAttr, (MYPCSC_DWORD) dwAttrLen); |
rv = SCardSetAttrib(myHCard, (MYPCSC_DWORD) dwAttrId, pbAttr, (MYPCSC_DWORD) dwAttrLen); |
2030 |
|
|
|
#ifdef WITH_SCARD_DEBUG |
|
2031 |
if (rv) |
if (rv) |
2032 |
printf("<--ERROR SCardSetAttrib Code=0x%.8x-->\n", (unsigned int) rv); |
{ |
2033 |
|
DEBUG_SCARD(("<--ERROR SCardSetAttrib Code=0x%.8x, %s-->\n", (unsigned int) rv, |
2034 |
|
pcsc_stringify_error(rv))); |
2035 |
|
} |
2036 |
else |
else |
2037 |
printf("<--SUCCESS SCardSetAttrib-->\n"); |
{ |
2038 |
#endif |
DEBUG_SCARD(("<--SUCCESS SCardSetAttrib-->\n")); |
2039 |
|
} |
2040 |
|
|
2041 |
out_uint32_le(out, 0x00000000); |
out_uint32_le(out, 0x00000000); |
2042 |
out_uint32_le(out, 0x00000200); |
out_uint32_le(out, 0x00000200); |
2043 |
out_uint32_le(out, 0x00000000); |
out_uint32_le(out, 0x00000000); |
2044 |
out_uint32_le(out, 0x00000000); |
out_uint32_le(out, 0x00000000); |
2045 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
2046 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
2047 |
return rv; |
return rv; |
2048 |
} |
} |
2105 |
if (!pOutBuffer) |
if (!pOutBuffer) |
2106 |
return SC_returnNoMemoryError(&lcHandle, in, out); |
return SC_returnNoMemoryError(&lcHandle, in, out); |
2107 |
|
|
2108 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
2109 |
printf("[hContext = 0x%.8x]\n", (unsigned int) hContext); |
DEBUG_SCARD(("[hContext = 0x%.8x]\n", (unsigned int) hContext)); |
2110 |
printf("[hCard = 0x%.8x]\n", (unsigned int) hCard); |
DEBUG_SCARD(("[hCard = 0x%.8x]\n", (unsigned int) hCard)); |
2111 |
printf("[dwControlCode = 0x%.8x]\n", (unsigned int) dwControlCode); |
DEBUG_SCARD(("[dwControlCode = 0x%.8x]\n", (unsigned int) dwControlCode)); |
2112 |
printf("[nInBufferSize = %d]\n", (unsigned int) nInBufferSize); |
DEBUG_SCARD(("[nInBufferSize = %d]\n", (unsigned int) nInBufferSize)); |
2113 |
printf("[nOutBufferSize = %d]\n", (unsigned int) nOutBufferSize); |
DEBUG_SCARD(("[nOutBufferSize = %d]\n", (unsigned int) nOutBufferSize)); |
2114 |
if (nInBufferSize > 0) |
if (nInBufferSize > 0) |
2115 |
{ |
{ |
2116 |
printf("[In buffer]\n"); |
DEBUG_SCARD(("[In buffer]\n")); |
2117 |
hexdump((unsigned char *) pInBuffer, nInBufferSize); |
hexdump((unsigned char *) pInBuffer, nInBufferSize); |
2118 |
} |
} |
2119 |
printf("---> Calling SCardControl\n"); |
DEBUG_SCARD(("---> Calling SCardControl\n")); |
2120 |
#endif |
#endif |
2121 |
|
|
|
#ifdef WITH_PCSC120 |
|
2122 |
sc_nBytesReturned = nBytesReturned; |
sc_nBytesReturned = nBytesReturned; |
2123 |
myHCard = scHandleToMyPCSC(hCard); |
myHCard = scHandleToMyPCSC(hCard); |
2124 |
|
#ifdef WITH_PCSC120 |
2125 |
rv = SCardControl(myHCard, pInBuffer, (MYPCSC_DWORD) nInBufferSize, pOutBuffer, |
rv = SCardControl(myHCard, pInBuffer, (MYPCSC_DWORD) nInBufferSize, pOutBuffer, |
2126 |
&sc_nBytesReturned); |
&sc_nBytesReturned); |
|
nBytesReturned = sc_nBytesReturned; |
|
2127 |
#else |
#else |
|
sc_nBytesReturned = nBytesReturned; |
|
|
myHCard = scHandleToMyPCSC(hCard); |
|
2128 |
rv = SCardControl(myHCard, (MYPCSC_DWORD) dwControlCode, pInBuffer, |
rv = SCardControl(myHCard, (MYPCSC_DWORD) dwControlCode, pInBuffer, |
2129 |
(MYPCSC_DWORD) nInBufferSize, pOutBuffer, |
(MYPCSC_DWORD) nInBufferSize, pOutBuffer, |
2130 |
(MYPCSC_DWORD) nOutBufferRealSize, &sc_nBytesReturned); |
(MYPCSC_DWORD) nOutBufferRealSize, &sc_nBytesReturned); |
|
nBytesReturned = sc_nBytesReturned; |
|
2131 |
#endif |
#endif |
2132 |
|
nBytesReturned = sc_nBytesReturned; |
2133 |
|
|
2134 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
2135 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
2136 |
printf("<--ERROR SCardControl Code=0x%.8x-->\n", (unsigned int) rv); |
{ |
2137 |
|
DEBUG_SCARD(("<--ERROR SCardControl Code=0x%.8x, %s-->\n", (unsigned int) rv, |
2138 |
|
pcsc_stringify_error(rv))); |
2139 |
|
} |
2140 |
else |
else |
2141 |
{ |
{ |
2142 |
printf("<--SUCCESS SCardControl-->\n"); |
DEBUG_SCARD(("<--SUCCESS SCardControl-->\n")); |
2143 |
printf("[LENGTH %d]\n", (unsigned int) nBytesReturned); |
DEBUG_SCARD(("[LENGTH %d]\n", (unsigned int) nBytesReturned)); |
2144 |
printf("+++++++++++++++++++++\n"); |
DEBUG_SCARD(("+++++++++++++++++++++\n")); |
2145 |
hexdump((unsigned char *) pOutBuffer, nBytesReturned); |
hexdump((unsigned char *) pOutBuffer, nBytesReturned); |
2146 |
printf("+++++++++++++++++++++\n"); |
DEBUG_SCARD(("+++++++++++++++++++++\n")); |
2147 |
} |
} |
2148 |
#endif |
#endif |
2149 |
|
|
2156 |
outRepos(out, nBytesReturned); |
outRepos(out, nBytesReturned); |
2157 |
} |
} |
2158 |
|
|
2159 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
2160 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
2161 |
return rv; |
return rv; |
2162 |
} |
} |
2169 |
} |
} |
2170 |
|
|
2171 |
|
|
2172 |
static NTSTATUS |
static RD_NTSTATUS |
2173 |
scard_device_control(NTHANDLE handle, uint32 request, STREAM in, STREAM out) |
scard_device_control(RD_NTHANDLE handle, uint32 request, STREAM in, STREAM out) |
2174 |
{ |
{ |
2175 |
SERVER_DWORD Result = 0x00000000; |
SERVER_DWORD Result = 0x00000000; |
2176 |
unsigned char *psize, *pend, *pStatusCode; |
unsigned char *psize, *pend, *pStatusCode; |
2177 |
SERVER_DWORD addToEnd = 0; |
SERVER_DWORD addToEnd = 0; |
2178 |
|
#ifdef WITH_DEBUG_SCARD |
|
#ifdef WITH_SCARD_DEBUG |
|
2179 |
unsigned char *pbeg = out->p; |
unsigned char *pbeg = out->p; |
2180 |
printf("--------------------------------\n"); |
|
2181 |
printf("[NTHANDLE %08X]\n", handle); |
DEBUG_SCARD(("--------------------------------\n")); |
2182 |
printf("[REQUEST %08X]\n", request); |
DEBUG_SCARD(("[NTHANDLE %08X]\n", handle)); |
2183 |
printf("[INPUT DUMP]--------------------\n"); |
DEBUG_SCARD(("[REQUEST %08X]\n", request)); |
2184 |
|
DEBUG_SCARD(("[INPUT DUMP]--------------------\n")); |
2185 |
hexdump(in->p, in->end - in->p); |
hexdump(in->p, in->end - in->p); |
2186 |
#endif |
#endif |
2187 |
/* Processing request */ |
/* Processing request */ |
2199 |
/* SCardEstablishContext */ |
/* SCardEstablishContext */ |
2200 |
case SC_ESTABLISH_CONTEXT: |
case SC_ESTABLISH_CONTEXT: |
2201 |
{ |
{ |
2202 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardEstablishContext--->\n")); |
|
printf("<---SCardEstablishContext--->\n"); |
|
|
#endif |
|
2203 |
Result = (SERVER_DWORD) TS_SCardEstablishContext(in, out); |
Result = (SERVER_DWORD) TS_SCardEstablishContext(in, out); |
2204 |
break; |
break; |
2205 |
} |
} |
2206 |
/* SCardReleaseContext */ |
/* SCardReleaseContext */ |
2207 |
case SC_RELEASE_CONTEXT: |
case SC_RELEASE_CONTEXT: |
2208 |
{ |
{ |
2209 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardReleaseContext--->\n")); |
|
printf("<---SCardReleaseContext--->\n"); |
|
|
#endif |
|
2210 |
Result = (SERVER_DWORD) TS_SCardReleaseContext(in, out); |
Result = (SERVER_DWORD) TS_SCardReleaseContext(in, out); |
2211 |
break; |
break; |
2212 |
} |
} |
2213 |
/* SCardIsValidContext */ |
/* SCardIsValidContext */ |
2214 |
case SC_IS_VALID_CONTEXT: |
case SC_IS_VALID_CONTEXT: |
2215 |
{ |
{ |
2216 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardIsValidContext--->\n")); |
|
printf("<---SCardIsValidContext--->\n"); |
|
|
#endif |
|
2217 |
Result = (SERVER_DWORD) TS_SCardIsValidContext(in, out); |
Result = (SERVER_DWORD) TS_SCardIsValidContext(in, out); |
2218 |
break; |
break; |
2219 |
} |
} |
2221 |
case SC_LIST_READERS: /* SCardListReadersA */ |
case SC_LIST_READERS: /* SCardListReadersA */ |
2222 |
case SC_LIST_READERS + 4: /* SCardListReadersW */ |
case SC_LIST_READERS + 4: /* SCardListReadersW */ |
2223 |
{ |
{ |
2224 |
BOOL wide = request != SC_LIST_READERS; |
RD_BOOL wide = request != SC_LIST_READERS; |
2225 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardListReaders---> (%s)\n", |
2226 |
printf("<---SCardListReaders---> (%s)\n", |
(wide) ? ("WIDE") : ("ASCII"))); |
|
(wide) ? ("WIDE") : ("ASCII")); |
|
|
#endif |
|
2227 |
Result = (SERVER_DWORD) TS_SCardListReaders(in, out, wide); |
Result = (SERVER_DWORD) TS_SCardListReaders(in, out, wide); |
2228 |
break; |
break; |
2229 |
} |
} |
2231 |
case SC_CONNECT: /* ScardConnectA */ |
case SC_CONNECT: /* ScardConnectA */ |
2232 |
case SC_CONNECT + 4: /* SCardConnectW */ |
case SC_CONNECT + 4: /* SCardConnectW */ |
2233 |
{ |
{ |
2234 |
BOOL wide = request != SC_CONNECT; |
RD_BOOL wide = request != SC_CONNECT; |
2235 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardConnect---> (%s)\n", |
2236 |
printf("<---SCardConnect---> (%s)\n", |
(wide) ? ("WIDE") : ("ASCII"))); |
|
(wide) ? ("WIDE") : ("ASCII")); |
|
|
#endif |
|
2237 |
Result = (SERVER_DWORD) TS_SCardConnect(in, out, wide); |
Result = (SERVER_DWORD) TS_SCardConnect(in, out, wide); |
2238 |
break; |
break; |
2239 |
} |
} |
2240 |
/* ScardReconnect */ |
/* ScardReconnect */ |
2241 |
case SC_RECONNECT: |
case SC_RECONNECT: |
2242 |
{ |
{ |
2243 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardReconnect--->\n")); |
|
printf("<---SCardReconnect--->\n"); |
|
|
#endif |
|
2244 |
Result = (SERVER_DWORD) TS_SCardReconnect(in, out); |
Result = (SERVER_DWORD) TS_SCardReconnect(in, out); |
2245 |
break; |
break; |
2246 |
} |
} |
2247 |
/* ScardDisconnect */ |
/* ScardDisconnect */ |
2248 |
case SC_DISCONNECT: |
case SC_DISCONNECT: |
2249 |
{ |
{ |
2250 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardDisconnect--->\n")); |
|
printf("<---SCardDisconnect--->\n"); |
|
|
#endif |
|
2251 |
Result = (SERVER_DWORD) TS_SCardDisconnect(in, out); |
Result = (SERVER_DWORD) TS_SCardDisconnect(in, out); |
2252 |
break; |
break; |
2253 |
} |
} |
2255 |
case SC_GET_STATUS_CHANGE: /* SCardGetStatusChangeA */ |
case SC_GET_STATUS_CHANGE: /* SCardGetStatusChangeA */ |
2256 |
case SC_GET_STATUS_CHANGE + 4: /* SCardGetStatusChangeW */ |
case SC_GET_STATUS_CHANGE + 4: /* SCardGetStatusChangeW */ |
2257 |
{ |
{ |
2258 |
BOOL wide = request != SC_GET_STATUS_CHANGE; |
RD_BOOL wide = request != SC_GET_STATUS_CHANGE; |
2259 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardGetStatusChange---> (%s)\n", |
2260 |
printf("<---SCardGetStatusChange---> (%s)\n", |
(wide) ? ("WIDE") : ("ASCII"))); |
|
(wide) ? ("WIDE") : ("ASCII")); |
|
|
#endif |
|
2261 |
Result = (SERVER_DWORD) TS_SCardGetStatusChange(in, out, wide); |
Result = (SERVER_DWORD) TS_SCardGetStatusChange(in, out, wide); |
2262 |
break; |
break; |
2263 |
} |
} |
2264 |
/* SCardCancel */ |
/* SCardCancel */ |
2265 |
case SC_CANCEL: |
case SC_CANCEL: |
2266 |
{ |
{ |
2267 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardCancel--->\n")); |
|
printf("<---SCardCancel--->\n"); |
|
|
#endif |
|
2268 |
Result = (SERVER_DWORD) TS_SCardCancel(in, out); |
Result = (SERVER_DWORD) TS_SCardCancel(in, out); |
2269 |
break; |
break; |
2270 |
} |
} |
2272 |
case SC_LOCATE_CARDS_BY_ATR: /* SCardLocateCardsByATRA */ |
case SC_LOCATE_CARDS_BY_ATR: /* SCardLocateCardsByATRA */ |
2273 |
case SC_LOCATE_CARDS_BY_ATR + 4: /* SCardLocateCardsByATRW */ |
case SC_LOCATE_CARDS_BY_ATR + 4: /* SCardLocateCardsByATRW */ |
2274 |
{ |
{ |
2275 |
BOOL wide = request != SC_LOCATE_CARDS_BY_ATR; |
RD_BOOL wide = request != SC_LOCATE_CARDS_BY_ATR; |
2276 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardLocateCardsByATR---> (%s)\n", |
2277 |
printf("<---SCardLocateCardsByATR---> (%s)\n", |
(wide) ? ("WIDE") : ("ASCII"))); |
|
(wide) ? ("WIDE") : ("ASCII")); |
|
|
#endif |
|
2278 |
Result = (SERVER_DWORD) TS_SCardLocateCardsByATR(in, out, wide); |
Result = (SERVER_DWORD) TS_SCardLocateCardsByATR(in, out, wide); |
2279 |
break; |
break; |
2280 |
} |
} |
2281 |
/* SCardBeginTransaction */ |
/* SCardBeginTransaction */ |
2282 |
case SC_BEGIN_TRANSACTION: |
case SC_BEGIN_TRANSACTION: |
2283 |
{ |
{ |
2284 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardBeginTransaction--->\n")); |
|
printf("<---SCardBeginTransaction--->\n"); |
|
|
#endif |
|
2285 |
Result = (SERVER_DWORD) TS_SCardBeginTransaction(in, out); |
Result = (SERVER_DWORD) TS_SCardBeginTransaction(in, out); |
2286 |
break; |
break; |
2287 |
} |
} |
2288 |
/* SCardBeginTransaction */ |
/* SCardBeginTransaction */ |
2289 |
case SC_END_TRANSACTION: |
case SC_END_TRANSACTION: |
2290 |
{ |
{ |
2291 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardEndTransaction--->\n")); |
|
printf("<---SCardEndTransaction--->\n"); |
|
|
#endif |
|
2292 |
Result = (SERVER_DWORD) TS_SCardEndTransaction(in, out); |
Result = (SERVER_DWORD) TS_SCardEndTransaction(in, out); |
2293 |
break; |
break; |
2294 |
} |
} |
2295 |
/* ScardTransmit */ |
/* ScardTransmit */ |
2296 |
case SC_TRANSMIT: |
case SC_TRANSMIT: |
2297 |
{ |
{ |
2298 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardTransmit--->\n")); |
|
printf("<---SCardTransmit--->\n"); |
|
|
#endif |
|
2299 |
Result = (SERVER_DWORD) TS_SCardTransmit(in, out); |
Result = (SERVER_DWORD) TS_SCardTransmit(in, out); |
2300 |
break; |
break; |
2301 |
} |
} |
2302 |
/* SCardControl */ |
/* SCardControl */ |
2303 |
case SC_CONTROL: |
case SC_CONTROL: |
2304 |
{ |
{ |
2305 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardControl--->\n")); |
|
printf("<---SCardControl--->\n"); |
|
|
#endif |
|
2306 |
Result = (SERVER_DWORD) TS_SCardControl(in, out); |
Result = (SERVER_DWORD) TS_SCardControl(in, out); |
2307 |
break; |
break; |
2308 |
} |
} |
2310 |
#ifndef WITH_PCSC120 |
#ifndef WITH_PCSC120 |
2311 |
case SC_GETATTRIB: |
case SC_GETATTRIB: |
2312 |
{ |
{ |
2313 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardGetAttrib--->\n")); |
|
printf("<---SCardGetAttrib--->\n"); |
|
|
#endif |
|
2314 |
Result = (SERVER_DWORD) TS_SCardGetAttrib(in, out); |
Result = (SERVER_DWORD) TS_SCardGetAttrib(in, out); |
2315 |
break; |
break; |
2316 |
} |
} |
2317 |
#endif |
#endif |
2318 |
case SC_ACCESS_STARTED_EVENT: |
case SC_ACCESS_STARTED_EVENT: |
2319 |
{ |
{ |
2320 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardAccessStartedEvent-->\n")); |
|
printf("<---SCardAccessStartedEvent-->\n"); |
|
|
#endif |
|
2321 |
Result = (SERVER_DWORD) TS_SCardAccessStartedEvent(in, out); |
Result = (SERVER_DWORD) TS_SCardAccessStartedEvent(in, out); |
2322 |
break; |
break; |
2323 |
} |
} |
2324 |
case SC_STATUS: /* SCardStatusA */ |
case SC_STATUS: /* SCardStatusA */ |
2325 |
case SC_STATUS + 4: /* SCardStatusW */ |
case SC_STATUS + 4: /* SCardStatusW */ |
2326 |
{ |
{ |
2327 |
BOOL wide = request != SC_STATUS; |
RD_BOOL wide = request != SC_STATUS; |
2328 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardStatus---> (%s)\n", |
2329 |
printf("<---SCardStatus---> (%s)\n", (wide) ? ("WIDE") : ("ASCII")); |
(wide) ? ("WIDE") : ("ASCII"))); |
|
#endif |
|
2330 |
Result = (SERVER_DWORD) TS_SCardStatus(in, out, wide); |
Result = (SERVER_DWORD) TS_SCardStatus(in, out, wide); |
2331 |
break; |
break; |
2332 |
} |
} |
2333 |
case SC_STATE: /* SCardState */ |
case SC_STATE: /* SCardState */ |
2334 |
{ |
{ |
2335 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardState--->")); |
|
printf("<---SCardState--->"); |
|
|
#endif |
|
2336 |
Result = (SERVER_DWORD) TS_SCardState(in, out); |
Result = (SERVER_DWORD) TS_SCardState(in, out); |
2337 |
break; |
break; |
2338 |
} |
} |
2339 |
default: |
default: |
2340 |
{ |
{ |
2341 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---UNSUPPORTED-FUNC--->\n")); |
|
printf("<---UNSUPPORTED-FUNC--->\n"); |
|
|
#endif |
|
2342 |
Result = 0x80100014; |
Result = 0x80100014; |
2343 |
out_uint8s(out, 256); |
out_uint8s(out, 256); |
2344 |
break; |
break; |
2365 |
out_uint8s(out, addToEnd); |
out_uint8s(out, addToEnd); |
2366 |
} |
} |
2367 |
|
|
2368 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
2369 |
printf("[OUTPUT DUMP]-------------------\n"); |
DEBUG_SCARD(("[OUTPUT DUMP]-------------------\n")); |
2370 |
hexdump(pbeg, (size_t) (out->p) - (size_t) pbeg); |
hexdump(pbeg, (size_t) (out->p) - (size_t) pbeg); |
2371 |
printf("--------------------------------\n"); |
DEBUG_SCARD(("--------------------------------\n")); |
2372 |
#endif |
#endif |
2373 |
return STATUS_SUCCESS; |
return RD_STATUS_SUCCESS; |
2374 |
} |
} |
2375 |
|
|
2376 |
/* Thread functions */ |
/* Thread functions */ |
2377 |
|
|
2378 |
static STREAM |
static STREAM |
2379 |
duplicateStream(PMEM_HANDLE * handle, STREAM s, uint32 buffer_size, BOOL isInputStream) |
duplicateStream(PMEM_HANDLE * handle, STREAM s, uint32 buffer_size, RD_BOOL isInputStream) |
2380 |
{ |
{ |
2381 |
STREAM d = SC_xmalloc(handle, sizeof(struct stream)); |
STREAM d = SC_xmalloc(handle, sizeof(struct stream)); |
2382 |
if (d != NULL) |
if (d != NULL) |
2425 |
} |
} |
2426 |
|
|
2427 |
static PSCThreadData |
static PSCThreadData |
2428 |
SC_addToQueue(NTHANDLE handle, uint32 request, STREAM in, STREAM out) |
SC_addToQueue(RD_NTHANDLE handle, uint32 request, STREAM in, STREAM out) |
2429 |
{ |
{ |
2430 |
PMEM_HANDLE lcHandle = NULL; |
PMEM_HANDLE lcHandle = NULL; |
2431 |
PSCThreadData data = SC_xmalloc(&lcHandle, sizeof(TSCThreadData)); |
PSCThreadData data = SC_xmalloc(&lcHandle, sizeof(TSCThreadData)); |
2505 |
size_t buffer_len = 0; |
size_t buffer_len = 0; |
2506 |
scard_device_control(data->handle, data->request, data->in, data->out); |
scard_device_control(data->handle, data->request, data->in, data->out); |
2507 |
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 |
|
2508 |
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 |
|
2509 |
SC_destroyThreadData(data); |
SC_destroyThreadData(data); |
2510 |
} |
} |
2511 |
|
|
2513 |
static void * |
static void * |
2514 |
thread_function(PThreadListElement listElement) |
thread_function(PThreadListElement listElement) |
2515 |
{ |
{ |
2516 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
2517 |
long sTime = 0; |
long sTime = 0; |
2518 |
#endif |
#endif |
2519 |
if ((listElement != NULL) && (listElement->data != NULL)) |
if ((listElement != NULL) && (listElement->data != NULL)) |
2520 |
{ |
{ |
2521 |
while (1) |
while (1) |
2522 |
{ |
{ |
2523 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
2524 |
sTime = time(NULL); |
sTime = time(NULL); |
2525 |
#endif |
#endif |
2526 |
pthread_mutex_lock(&listElement->nodata); |
pthread_mutex_lock(&listElement->nodata); |
2527 |
SC_deviceControl(listElement->data); |
SC_deviceControl(listElement->data); |
2528 |
listElement->data = NULL; |
listElement->data = NULL; |
2529 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[HANDLING TIME %d]\n", (int) (time(NULL) - sTime))); |
|
printf("[HANDLING TIME %d]\n", (int) (time(NULL) - sTime)); |
|
|
#endif |
|
2530 |
pthread_mutex_unlock(&listElement->busy); |
pthread_mutex_unlock(&listElement->busy); |
2531 |
} |
} |
2532 |
} |
} |
2540 |
int Result = 0; |
int Result = 0; |
2541 |
PThreadListElement cur = threadList, last = threadList; |
PThreadListElement cur = threadList, last = threadList; |
2542 |
|
|
2543 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[THREAD COUNT %d]\n", threadCount)); |
|
printf("[THREAD COUNT %d]\n", threadCount); |
|
|
#endif |
|
2544 |
|
|
2545 |
while (cur) |
while (cur) |
2546 |
{ |
{ |
2573 |
Result = pthread_create(&cur->thread, NULL, (void *(*)(void *)) thread_function, cur); |
Result = pthread_create(&cur->thread, NULL, (void *(*)(void *)) thread_function, cur); |
2574 |
if (0 != Result) |
if (0 != Result) |
2575 |
{ |
{ |
2576 |
printf("[THREAD CREATE ERROR 0x%.8x]\n", Result); |
error("[THREAD CREATE ERROR 0x%.8x]\n", Result); |
2577 |
SC_xfree(&threadListHandle, cur); |
SC_xfree(&threadListHandle, cur); |
2578 |
SC_destroyThreadData(data); |
SC_destroyThreadData(data); |
2579 |
data = NULL; |
data = NULL; |
2615 |
return NULL; |
return NULL; |
2616 |
} |
} |
2617 |
|
|
2618 |
static NTSTATUS |
static RD_NTSTATUS |
2619 |
thread_wrapper(NTHANDLE handle, uint32 request, STREAM in, STREAM out) |
thread_wrapper(RD_NTHANDLE handle, uint32 request, STREAM in, STREAM out) |
2620 |
{ |
{ |
2621 |
if (SC_addToQueue(handle, request, in, out)) |
if (SC_addToQueue(handle, request, in, out)) |
2622 |
return STATUS_PENDING | 0xC0000000; |
return RD_STATUS_PENDING | 0xC0000000; |
2623 |
else |
else |
2624 |
return STATUS_NO_SUCH_FILE; |
return RD_STATUS_NO_SUCH_FILE; |
2625 |
} |
} |
2626 |
|
|
2627 |
DEVICE_FNS scard_fns = { |
DEVICE_FNS scard_fns = { |
2634 |
#endif /* MAKE_PROTO */ |
#endif /* MAKE_PROTO */ |
2635 |
|
|
2636 |
void |
void |
2637 |
scard_tcp_lock(void) |
scard_lock(int lock) |
2638 |
{ |
{ |
2639 |
if (!tcp_sendcontrol_mutex) |
if (!scard_mutex) |
2640 |
|
{ |
2641 |
|
int i; |
2642 |
|
|
2643 |
|
scard_mutex = |
2644 |
|
(pthread_mutex_t **) xmalloc(sizeof(pthread_mutex_t *) * SCARD_LOCK_LAST); |
2645 |
|
|
2646 |
|
for (i = 0; i < SCARD_LOCK_LAST; i++) |
2647 |
|
{ |
2648 |
|
scard_mutex[i] = NULL; |
2649 |
|
} |
2650 |
|
} |
2651 |
|
|
2652 |
|
if (!scard_mutex[lock]) |
2653 |
{ |
{ |
2654 |
tcp_sendcontrol_mutex = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t)); |
scard_mutex[lock] = (pthread_mutex_t *) xmalloc(sizeof(pthread_mutex_t)); |
2655 |
pthread_mutex_init(tcp_sendcontrol_mutex, NULL); |
pthread_mutex_init(scard_mutex[lock], NULL); |
2656 |
} |
} |
2657 |
|
|
2658 |
pthread_mutex_lock(tcp_sendcontrol_mutex); |
pthread_mutex_lock(scard_mutex[lock]); |
2659 |
} |
} |
2660 |
|
|
2661 |
void |
void |
2662 |
scard_tcp_unlock(void) |
scard_unlock(int lock) |
2663 |
{ |
{ |
2664 |
pthread_mutex_unlock(tcp_sendcontrol_mutex); |
pthread_mutex_unlock(scard_mutex[lock]); |
2665 |
} |
} |
2666 |
|
|
2667 |
STREAM |
STREAM |