1 |
/************************************/ |
/* |
2 |
/* Smart Card support for RDesktop. */ |
rdesktop: A Remote Desktop Protocol client. |
3 |
/* Copyright (C) by Alexi Volkov */ |
Smart Card support |
4 |
/* e-mail: alexi@myrealbox.com */ |
Copyright (C) Alexi Volkov <alexi@myrealbox.com> 2006 |
5 |
/* ICQ: 264679502 */ |
|
6 |
/************************************/ |
This program is free software; you can redistribute it and/or modify |
7 |
|
it under the terms of the GNU General Public License as published by |
8 |
|
the Free Software Foundation; either version 2 of the License, or |
9 |
|
(at your option) any later version. |
10 |
|
|
11 |
|
This program is distributed in the hope that it will be useful, |
12 |
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
GNU General Public License for more details. |
15 |
|
|
16 |
|
You should have received a copy of the GNU General Public License |
17 |
|
along with this program; if not, write to the Free Software |
18 |
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 |
|
*/ |
20 |
|
|
21 |
#include <stdio.h> |
#include <stdio.h> |
22 |
#include "rdesktop.h" |
#include "rdesktop.h" |
26 |
#include <sys/types.h> |
#include <sys/types.h> |
27 |
#include <time.h> |
#include <time.h> |
28 |
#ifndef MAKE_PROTO |
#ifndef MAKE_PROTO |
29 |
|
#ifdef PCSC_OSX |
30 |
|
#include <PCSC/pcsclite.h> |
31 |
|
#include <PCSC/winscard.h> |
32 |
|
#else |
33 |
#include <pcsclite.h> |
#include <pcsclite.h> |
34 |
#include <winscard.h> |
#include <winscard.h> |
35 |
|
#endif /* PCSC_OSX */ |
36 |
#include "scard.h" |
#include "scard.h" |
37 |
|
|
38 |
/* variable segment */ |
/* variable segment */ |
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 *tcp_sendcontrol_mutex = NULL; |
48 |
|
static pthread_mutex_t *sec_channels_mutex = NULL; |
49 |
|
|
50 |
static uint32 curDevice = 0, curId = 0, curBytesOut = 0; |
static uint32 curDevice = 0, curId = 0, curBytesOut = 0; |
51 |
static PSCNameMapRec nameMapList = NULL; |
static PSCNameMapRec nameMapList = NULL; |
55 |
static pthread_mutex_t queueAccess; |
static pthread_mutex_t queueAccess; |
56 |
static pthread_mutex_t queueEmpty; |
static pthread_mutex_t queueEmpty; |
57 |
static pthread_mutex_t hcardAccess; |
static pthread_mutex_t hcardAccess; |
|
/* static pthread_mutex_t sendControl; */ |
|
58 |
|
|
59 |
static PMEM_HANDLE threadListHandle = NULL; |
static PMEM_HANDLE threadListHandle = NULL; |
60 |
static PThreadListElement threadList = NULL; |
static PThreadListElement threadList = NULL; |
126 |
rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); |
rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); |
127 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
128 |
{ |
{ |
129 |
printf("[SMART CARD: PCSC service not available]\n"); |
error("[SMART CARD: PCSC service not available]\n"); |
130 |
return 0; |
return 0; |
131 |
} |
} |
132 |
else |
else |
136 |
|
|
137 |
if (0 != pthread_mutex_init(&queueAccess, NULL)) |
if (0 != pthread_mutex_init(&queueAccess, NULL)) |
138 |
{ |
{ |
139 |
printf("[SMART CARD: Can't initialize queue access mutex]\n"); |
error("[SMART CARD: Can't initialize queue access mutex]\n"); |
140 |
return 0; |
return 0; |
141 |
} |
} |
142 |
|
|
143 |
if (0 != pthread_mutex_init(&queueEmpty, NULL)) |
if (0 != pthread_mutex_init(&queueEmpty, NULL)) |
144 |
{ |
{ |
145 |
printf("[SMART CARD: Can't initialize queue control mutex]\n"); |
error("[SMART CARD: Can't initialize queue control mutex]\n"); |
146 |
return 0; |
return 0; |
147 |
} |
} |
148 |
|
|
149 |
if (0 != pthread_mutex_init(&hcardAccess, NULL)) |
if (0 != pthread_mutex_init(&hcardAccess, NULL)) |
150 |
{ |
{ |
151 |
printf("[SMART CARD: Can't initialize hcard list access mutex]\n"); |
error("[SMART CARD: Can't initialize hcard list access mutex]\n"); |
152 |
return 0; |
return 0; |
153 |
} |
} |
154 |
|
|
|
#if 0 |
|
|
if (0 != pthread_mutex_init(&sendControl, NULL)) |
|
|
{ |
|
|
printf("[SMART CARD: Can't initialize send control mutex]\n"); |
|
|
return 0; |
|
|
} |
|
|
#endif |
|
|
|
|
|
|
|
155 |
if (0 != |
if (0 != |
156 |
pthread_create(&queueHandler, NULL, (void *(*)(void *)) queue_handler_function, NULL)) |
pthread_create(&queueHandler, NULL, (void *(*)(void *)) queue_handler_function, NULL)) |
157 |
{ |
{ |
158 |
printf("[SMART CARD: Can't create queue handling Thread]\n"); |
error("[SMART CARD: Can't create queue handling Thread]\n"); |
159 |
return 0; |
return 0; |
160 |
} |
} |
161 |
|
|
224 |
} |
} |
225 |
} |
} |
226 |
|
|
|
|
|
|
printf("******************************************************\n"); |
|
|
printf("* Smart Card support for RDesktop is initialized. *\n"); |
|
|
printf("* Copyright (C) by Alexi Volkov, alexi@myrealbox.com *\n"); |
|
|
printf("******************************************************\n"); |
|
|
|
|
227 |
return count; |
return count; |
228 |
} |
} |
229 |
|
|
482 |
} |
} |
483 |
|
|
484 |
static void |
static void |
485 |
outForceAllignment(STREAM out, unsigned int seed) |
outForceAlignment(STREAM out, unsigned int seed) |
486 |
{ |
{ |
487 |
SERVER_DWORD add = (seed - (out->p - out->data) % seed) % seed; |
SERVER_DWORD add = (seed - (out->p - out->data) % seed) % seed; |
488 |
if (add > 0) |
if (add > 0) |
|
{ |
|
489 |
out_uint8s(out, add); |
out_uint8s(out, add); |
|
} |
|
490 |
} |
} |
491 |
|
|
492 |
static unsigned int |
static unsigned int |
603 |
MYPCSC_SCARDCONTEXT hContext; |
MYPCSC_SCARDCONTEXT hContext; |
604 |
/* code segment */ |
/* code segment */ |
605 |
|
|
606 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("Establishing PC/SC Context... \n")); |
|
printf("Establishing PC/SC Context... \n"); |
|
|
#endif |
|
607 |
rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); |
rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); |
|
#ifdef WITH_SCARD_DEBUG |
|
608 |
if (rv) |
if (rv) |
609 |
printf("<--ERROR SCardEstablishContext Code=0x%.8x]-->\n", (unsigned int) rv); |
{ |
610 |
|
DEBUG_SCARD(("<--ERROR SCardEstablishContext Code=0x%.8x]-->\n", |
611 |
|
(unsigned int) rv)); |
612 |
|
} |
613 |
else |
else |
614 |
printf("<--SUCCESS SCardEstablishContext-->\n"); |
{ |
615 |
#endif |
DEBUG_SCARD(("<--SUCCESS SCardEstablishContext-->\n")); |
616 |
|
} |
617 |
|
|
618 |
out_uint32_le(out, 0x00000004); |
out_uint32_le(out, 0x00000004); |
619 |
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) */ |
631 |
|
|
632 |
in->p += 0x1C; |
in->p += 0x1C; |
633 |
in_uint32_le(in, hContext); |
in_uint32_le(in, hContext); |
634 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[CONTEXT 0x%.8x]\n", (unsigned int) hContext)); |
635 |
printf("[CONTEXT 0x%.8x]\n", (unsigned int) hContext); |
DEBUG_SCARD(("Releasing context... \n")); |
|
printf("Releasing context... \n"); |
|
|
#endif |
|
636 |
rv = SCardReleaseContext((MYPCSC_SCARDCONTEXT) hContext); |
rv = SCardReleaseContext((MYPCSC_SCARDCONTEXT) hContext); |
637 |
#ifdef WITH_SCARD_DEBUG |
|
638 |
if (rv) |
if (rv) |
639 |
printf("<--ERROR SCardReleaseContext Code=0x%.8x-->\n", (unsigned int) rv); |
{ |
640 |
|
DEBUG_SCARD(("<--ERROR SCardReleaseContext Code=0x%.8x-->\n", (unsigned int) 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-->\n", |
674 |
printf("<--ERROR SCardListReaders (no SCardIsValidContext) Code=0x%.8x-->\n", |
(unsigned int) rv)); |
|
(unsigned int) rv); |
|
|
#endif |
|
675 |
rv = SCARD_E_INVALID_HANDLE; |
rv = SCARD_E_INVALID_HANDLE; |
676 |
} |
} |
|
#ifdef WITH_SCARD_DEBUG |
|
677 |
else |
else |
678 |
printf("<--SUCCESS SCardListReaders (no SCardIsValidContext)-->\n"); |
{ |
679 |
#endif |
DEBUG_SCARD(("<--SUCCESS SCardListReaders (no SCardIsValidContext)-->\n")); |
680 |
outForceAllignment(out, 8); |
} |
681 |
|
|
682 |
|
outForceAlignment(out, 8); |
683 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
684 |
return rv; |
return rv; |
685 |
} |
} |
699 |
|
|
700 |
in->p += 0x2C; |
in->p += 0x2C; |
701 |
in_uint32_le(in, hContext); |
in_uint32_le(in, hContext); |
702 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[CONTEXT 0x%.8x]\n", (unsigned int) hContext)); |
|
printf("[CONTEXT 0x%.8x]\n", (unsigned int) hContext); |
|
|
#endif |
|
703 |
plen1 = out->p; |
plen1 = out->p; |
704 |
out_uint32_le(out, 0x00000000); /* Temp value for data length as 0x0 */ |
out_uint32_le(out, 0x00000000); /* Temp value for data length as 0x0 */ |
705 |
out_uint32_le(out, 0x01760650); |
out_uint32_le(out, 0x01760650); |
720 |
{ |
{ |
721 |
int i; |
int i; |
722 |
PSCNameMapRec tmpMap; |
PSCNameMapRec tmpMap; |
723 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
724 |
printf("[CALL RESULT of SCardListReaders 0x%.8x]\n", (unsigned int) rv); |
DEBUG_SCARD(("[CALL RESULT of SCardListReaders 0x%.8x]\n", (unsigned int) rv)); |
725 |
hexdump((void *) readers, cchReaders); |
hexdump((void *) readers, cchReaders); |
726 |
#endif |
#endif |
727 |
for (i = 0, tmpMap = nameMapList; i < nameMapCount; i++, tmpMap++) |
for (i = 0, tmpMap = nameMapList; i < nameMapCount; i++, tmpMap++) |
752 |
out_uint32_le(out, dataLength); |
out_uint32_le(out, dataLength); |
753 |
out->p = pend; |
out->p = pend; |
754 |
|
|
755 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
756 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
757 |
return rv; |
return rv; |
758 |
} |
} |
775 |
in->p += 0x1C; |
in->p += 0x1C; |
776 |
in_uint32_le(in, dwShareMode); |
in_uint32_le(in, dwShareMode); |
777 |
in_uint32_le(in, dwPreferredProtocol); |
in_uint32_le(in, dwPreferredProtocol); |
778 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[SHARE %8x]\n", (unsigned int) dwShareMode)); |
779 |
printf("[SHARE %8x]\n", (unsigned int) dwShareMode); |
DEBUG_SCARD(("[PROTO %8x]\n", (unsigned int) dwPreferredProtocol)); |
|
printf("[PROTO %8x]\n", (unsigned int) dwPreferredProtocol); |
|
|
#endif |
|
780 |
inReaderName(&lcHandle, in, &szReader, wide); |
inReaderName(&lcHandle, in, &szReader, wide); |
781 |
#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 |
|
782 |
in->p += 0x04; |
in->p += 0x04; |
783 |
in_uint32_le(in, hContext); |
in_uint32_le(in, hContext); |
784 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[CONTEXT 0x%.8x]\n", (unsigned int) hContext)); |
|
printf("[CONTEXT 0x%.8x]\n", (unsigned int) hContext); |
|
|
#endif |
|
785 |
rv = SCardConnect(hContext, szReader, (MYPCSC_DWORD) dwShareMode, |
rv = SCardConnect(hContext, szReader, (MYPCSC_DWORD) dwShareMode, |
786 |
(MYPCSC_DWORD) dwPreferredProtocol, &myHCard, &dwActiveProtocol); |
(MYPCSC_DWORD) dwPreferredProtocol, &myHCard, &dwActiveProtocol); |
787 |
hCard = scHandleToServer(myHCard); |
hCard = scHandleToServer(myHCard); |
788 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[RECEIVED HCARD 0x%016lx]\n", (unsigned long) myHCard)); |
789 |
printf("[RECEIVED HCARD 0x%016lx]\n", myHCard); |
DEBUG_SCARD(("[MANGLED HCARD 0x%08x]\n", hCard)); |
|
printf("[MANGLED HCARD 0x%08x]\n", hCard); |
|
|
#endif |
|
790 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
791 |
{ |
{ |
792 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<--ERROR SCardConnect Code=0x%.8x-->\n", (unsigned int) rv)); |
|
printf("<--ERROR SCardConnect Code=0x%.8x-->\n", (unsigned int) rv); |
|
|
#endif |
|
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-->\n", (unsigned int) rv)); |
867 |
|
} |
868 |
else |
else |
869 |
printf("<--SUCCESS SCardReconnect-->\n"); |
{ |
870 |
#endif |
DEBUG_SCARD(("<--SUCCESS SCardReconnect-->\n")); |
871 |
|
} |
872 |
|
|
873 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
874 |
out_uint32_le(out, (SERVER_DWORD) dwActiveProtocol); |
out_uint32_le(out, (SERVER_DWORD) dwActiveProtocol); |
875 |
return rv; |
return rv; |
876 |
} |
} |
891 |
in->p += 0x04; |
in->p += 0x04; |
892 |
in_uint32_le(in, hCard); |
in_uint32_le(in, hCard); |
893 |
|
|
894 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[hContext = 0x%.8x]\n", (unsigned int) hContext)); |
895 |
printf("[hContext = 0x%.8x]\n", (unsigned int) hContext); |
DEBUG_SCARD(("[hCard = 0x%.8x]\n", (unsigned int) hCard)); |
896 |
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 |
|
897 |
|
|
898 |
pthread_mutex_lock(&hcardAccess); |
pthread_mutex_lock(&hcardAccess); |
899 |
PSCHCardRec hcard = hcardFirst; |
PSCHCardRec hcard = hcardFirst; |
917 |
myHCard = scHandleToMyPCSC(hCard); |
myHCard = scHandleToMyPCSC(hCard); |
918 |
rv = SCardDisconnect(myHCard, (MYPCSC_DWORD) dwDisposition); |
rv = SCardDisconnect(myHCard, (MYPCSC_DWORD) dwDisposition); |
919 |
|
|
|
#ifdef WITH_SCARD_DEBUG |
|
920 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
921 |
printf("<--ERROR SCardDisconnect Code=0x%.8x-->\n", (unsigned int) rv); |
{ |
922 |
|
DEBUG_SCARD(("<--ERROR SCardDisconnect Code=0x%.8x-->\n", (unsigned int) rv)); |
923 |
|
} |
924 |
else |
else |
925 |
printf("<--SUCCESS SCardDisconnect-->\n"); |
{ |
926 |
#endif |
DEBUG_SCARD(("<--SUCCESS SCardDisconnect-->\n")); |
927 |
outForceAllignment(out, 8); |
} |
928 |
|
|
929 |
|
outForceAlignment(out, 8); |
930 |
return rv; |
return rv; |
931 |
} |
} |
932 |
|
|
1033 |
in->p += 0x08; |
in->p += 0x08; |
1034 |
in_uint32_le(in, hContext); |
in_uint32_le(in, hContext); |
1035 |
in->p += 0x04; |
in->p += 0x04; |
1036 |
#ifdef WITH_SCARD_DEBUG |
|
1037 |
printf("[CONTEXT 0x%.8x]\n", (unsigned int) hContext); |
DEBUG_SCARD(("[CONTEXT 0x%.8x]\n", (unsigned int) hContext)); |
1038 |
printf("[dwTimeout 0x%.8x]\n", (unsigned int) dwTimeout); |
DEBUG_SCARD(("[dwTimeout 0x%.8x]\n", (unsigned int) dwTimeout)); |
1039 |
printf("[COUNT %d]\n", (unsigned int) dwCount); |
DEBUG_SCARD(("[COUNT %d]\n", (unsigned int) dwCount)); |
1040 |
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))); |
1041 |
#endif |
|
1042 |
if (dwCount > 0) |
if (dwCount > 0) |
1043 |
{ |
{ |
1044 |
rsArray = SC_xmalloc(&lcHandle, dwCount * sizeof(SERVER_SCARD_READERSTATE_A)); |
rsArray = SC_xmalloc(&lcHandle, dwCount * sizeof(SERVER_SCARD_READERSTATE_A)); |
1055 |
in->p += 0x04; |
in->p += 0x04; |
1056 |
in_uint8a(in, cur, SERVER_SCARDSTATESIZE); |
in_uint8a(in, cur, SERVER_SCARDSTATESIZE); |
1057 |
} |
} |
1058 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
1059 |
printf("[READERS DUMP 1]------------------\n"); |
DEBUG_SCARD(("[READERS DUMP 1]------------------\n")); |
1060 |
hexdump((void *) rsArray, dwCount * sizeof(SERVER_SCARD_READERSTATE_A)); |
hexdump((void *) rsArray, dwCount * sizeof(SERVER_SCARD_READERSTATE_A)); |
1061 |
#endif |
#endif |
1062 |
|
|
1093 |
|
|
1094 |
in->p += 0x08; |
in->p += 0x08; |
1095 |
in_uint32_le(in, dataLength); |
in_uint32_le(in, dataLength); |
1096 |
#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 |
|
1097 |
inRepos(in, |
inRepos(in, |
1098 |
inString(&lcHandle, in, (char **) &(cur->szReader), dataLength, |
inString(&lcHandle, in, (char **) &(cur->szReader), dataLength, |
1099 |
wide)); |
wide)); |
1101 |
if (strcmp(cur->szReader, "\\\\?PnP?\\Notification") == 0) |
if (strcmp(cur->szReader, "\\\\?PnP?\\Notification") == 0) |
1102 |
cur->dwCurrentState |= SCARD_STATE_IGNORE; |
cur->dwCurrentState |= SCARD_STATE_IGNORE; |
1103 |
} |
} |
1104 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
1105 |
printf("[READERS DUMP 2]------------------\n"); |
DEBUG_SCARD(("[READERS DUMP 2]------------------\n")); |
1106 |
hexdump((void *) rsArray, dwCount * sizeof(SERVER_SCARD_READERSTATE_A)); |
hexdump((void *) rsArray, dwCount * sizeof(SERVER_SCARD_READERSTATE_A)); |
1107 |
#endif |
#endif |
1108 |
} |
} |
1112 |
stateArray = NULL; |
stateArray = NULL; |
1113 |
} |
} |
1114 |
|
|
1115 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("\nCalling SCardGetStatusChange...\n")); |
|
printf("\nCalling SCardGetStatusChange...\n"); |
|
|
#endif |
|
1116 |
|
|
1117 |
|
|
1118 |
myRsArray = SC_xmalloc(&lcHandle, dwCount * sizeof(MYPCSC_SCARD_READERSTATE_A)); |
myRsArray = SC_xmalloc(&lcHandle, dwCount * sizeof(MYPCSC_SCARD_READERSTATE_A)); |
1120 |
return SC_returnNoMemoryError(&lcHandle, in, out); |
return SC_returnNoMemoryError(&lcHandle, in, out); |
1121 |
memset(myRsArray, 0, dwCount * sizeof(SERVER_SCARD_READERSTATE_A)); |
memset(myRsArray, 0, dwCount * sizeof(SERVER_SCARD_READERSTATE_A)); |
1122 |
copyReaderState_ServerToMyPCSC(rsArray, myRsArray, (SERVER_DWORD) dwCount); |
copyReaderState_ServerToMyPCSC(rsArray, myRsArray, (SERVER_DWORD) dwCount); |
1123 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
1124 |
printf("[TRANSLATION OF READERS]--------------------\n"); |
DEBUG_SCARD(("[TRANSLATION OF READERS]--------------------\n")); |
1125 |
hexdump((void *) myRsArray, dwCount * sizeof(MYPCSC_SCARD_READERSTATE_A)); |
hexdump((void *) myRsArray, dwCount * sizeof(MYPCSC_SCARD_READERSTATE_A)); |
1126 |
#endif |
#endif |
1127 |
|
|
1129 |
myRsArray, (MYPCSC_DWORD) dwCount); |
myRsArray, (MYPCSC_DWORD) dwCount); |
1130 |
copyReaderState_MyPCSCToServer(myRsArray, rsArray, (MYPCSC_DWORD) dwCount); |
copyReaderState_MyPCSCToServer(myRsArray, rsArray, (MYPCSC_DWORD) dwCount); |
1131 |
|
|
|
#ifdef WITH_SCARD_DEBUG |
|
1132 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
1133 |
printf("<--ERROR SCardGetStatusChange Code=0x%.8x-->\n", (unsigned int) rv); |
{ |
1134 |
|
DEBUG_SCARD(("<--ERROR SCardGetStatusChange Code=0x%.8x-->\n", (unsigned int) rv)); |
1135 |
|
} |
1136 |
else |
else |
1137 |
printf("<--SUCCESS SCardGetStatusChange-->\n"); |
{ |
1138 |
|
DEBUG_SCARD(("<--SUCCESS SCardGetStatusChange-->\n")); |
1139 |
|
} |
1140 |
|
|
1141 |
|
#ifdef WITH_DEBUG_SCARD |
1142 |
if (dwCount > 0) |
if (dwCount > 0) |
1143 |
{ |
{ |
1144 |
printf("[READERS DUMP]------------------\n"); |
DEBUG_SCARD(("[READERS DUMP]------------------\n")); |
1145 |
hexdump((void *) rsArray, dwCount * sizeof(SERVER_SCARD_READERSTATE_A)); |
hexdump((void *) rsArray, dwCount * sizeof(SERVER_SCARD_READERSTATE_A)); |
1146 |
} |
} |
1147 |
#endif |
#endif |
1183 |
out_uint8p(out, (void *) ((unsigned char **) cur + 2), |
out_uint8p(out, (void *) ((unsigned char **) cur + 2), |
1184 |
sizeof(SERVER_SCARD_READERSTATE_A) - 2 * sizeof(unsigned char *)); |
sizeof(SERVER_SCARD_READERSTATE_A) - 2 * sizeof(unsigned char *)); |
1185 |
} |
} |
1186 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
1187 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
1188 |
return rv; |
return rv; |
1189 |
} |
} |
1196 |
|
|
1197 |
in->p += 0x1C; |
in->p += 0x1C; |
1198 |
in_uint32_le(in, hContext); |
in_uint32_le(in, hContext); |
1199 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[CONTEXT 0x%.8x]\n", (unsigned int) hContext)); |
1200 |
printf("[CONTEXT 0x%.8x]\n", (unsigned int) hContext); |
DEBUG_SCARD(("Canceling... \n")); |
|
printf("Canceling... \n"); |
|
|
#endif |
|
1201 |
rv = SCardCancel((MYPCSC_SCARDCONTEXT) hContext); |
rv = SCardCancel((MYPCSC_SCARDCONTEXT) hContext); |
|
#ifdef WITH_SCARD_DEBUG |
|
1202 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
1203 |
printf("<--ERROR SCardCancel Code=0x%.8x-->\n", (unsigned int) rv); |
{ |
1204 |
|
DEBUG_SCARD(("<--ERROR SCardCancel Code=0x%.8x-->\n", (unsigned int) rv)); |
1205 |
|
} |
1206 |
else |
else |
1207 |
printf("<--SUCCESS SCardCancel-->\n"); |
{ |
1208 |
#endif |
DEBUG_SCARD(("<--SUCCESS SCardCancel-->\n")); |
1209 |
outForceAllignment(out, 8); |
} |
1210 |
|
outForceAlignment(out, 8); |
1211 |
return rv; |
return rv; |
1212 |
} |
} |
1213 |
|
|
1228 |
|
|
1229 |
in->p += 0x2C; |
in->p += 0x2C; |
1230 |
in_uint32_le(in, hContext); |
in_uint32_le(in, hContext); |
1231 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[CONTEXT 0x%.8x]\n", (unsigned int) hContext)); |
|
printf("[CONTEXT 0x%.8x]\n", (unsigned int) hContext); |
|
|
#endif |
|
1232 |
in_uint32_le(in, atrMaskCount); |
in_uint32_le(in, atrMaskCount); |
1233 |
pAtrMasks = SC_xmalloc(&lcHandle, atrMaskCount * sizeof(SCARD_ATRMASK_L)); |
pAtrMasks = SC_xmalloc(&lcHandle, atrMaskCount * sizeof(SCARD_ATRMASK_L)); |
1234 |
if (!pAtrMasks) |
if (!pAtrMasks) |
1256 |
for (i = 0, rsCur = rsArray; i < readerCount; i++, rsCur++) |
for (i = 0, rsCur = rsArray; i < readerCount; i++, rsCur++) |
1257 |
{ |
{ |
1258 |
inReaderName(&lcHandle, in, (char **) &rsCur->szReader, wide); |
inReaderName(&lcHandle, in, (char **) &rsCur->szReader, wide); |
1259 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[CHECK READER %s]\n", |
1260 |
printf("[CHECK READER %s]\n", (rsCur->szReader) ? (rsCur->szReader) : ("NULL")); |
(rsCur->szReader) ? (rsCur->szReader) : ("NULL"))); |
|
#endif |
|
1261 |
} |
} |
1262 |
|
|
1263 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[CALL subfunction \"SCardGetStatusChange\"]\n")); |
|
printf("[CALL subfunction \"SCardGetStatusChange\"]\n"); |
|
|
#endif |
|
1264 |
/* FIXME segfault here. */ |
/* FIXME segfault here. */ |
1265 |
myRsArray = SC_xmalloc(&lcHandle, readerCount * sizeof(MYPCSC_SCARD_READERSTATE_A)); |
myRsArray = SC_xmalloc(&lcHandle, readerCount * sizeof(MYPCSC_SCARD_READERSTATE_A)); |
1266 |
if (!myRsArray) |
if (!myRsArray) |
1270 |
copyReaderState_MyPCSCToServer(myRsArray, rsArray, readerCount); |
copyReaderState_MyPCSCToServer(myRsArray, rsArray, readerCount); |
1271 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
1272 |
{ |
{ |
1273 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<--ERROR SCardGetStatusChange (no SCardLocateCardsByATR) Code=0x%.8x-->\n", (unsigned int) rv)); |
|
printf("<--ERROR SCardGetStatusChange (no SCardLocateCardsByATR) Code=0x%.8x-->\n", |
|
|
(unsigned int) rv); |
|
|
#endif |
|
1274 |
} |
} |
1275 |
else |
else |
1276 |
{ |
{ |
1277 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<--SUCCESS SCardGetStatusChange (no SCardLocateCardsByATR)-->\n")); |
|
printf("<--SUCCESS SCardGetStatusChange (no SCardLocateCardsByATR)-->\n"); |
|
|
#endif |
|
1278 |
cur = pAtrMasks; |
cur = pAtrMasks; |
1279 |
for (i = 0, cur = pAtrMasks; i < atrMaskCount; i++, cur++) |
for (i = 0, cur = pAtrMasks; i < atrMaskCount; i++, cur++) |
1280 |
{ |
{ |
1294 |
} |
} |
1295 |
if (equal) |
if (equal) |
1296 |
{ |
{ |
1297 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[FOUND]\n")); |
|
printf("[FOUND]\n"); |
|
|
#endif |
|
1298 |
rsCur->dwEventState |= 0x00000040; /* SCARD_STATE_ATRMATCH 0x00000040 */ |
rsCur->dwEventState |= 0x00000040; /* SCARD_STATE_ATRMATCH 0x00000040 */ |
1299 |
memcpy(ResArray + j, rsCur, sizeof(SCARD_READERSTATE_A)); |
memcpy(ResArray + j, rsCur, sizeof(SCARD_READERSTATE_A)); |
1300 |
} |
} |
1312 |
sizeof(SCARD_READERSTATE_A) - 2 * sizeof(unsigned char *)); |
sizeof(SCARD_READERSTATE_A) - 2 * sizeof(unsigned char *)); |
1313 |
} |
} |
1314 |
|
|
1315 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
1316 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
1317 |
return rv; |
return rv; |
1318 |
} |
} |
1327 |
in->p += 0x30; |
in->p += 0x30; |
1328 |
in_uint32_le(in, hCard); |
in_uint32_le(in, hCard); |
1329 |
myHCard = scHandleToMyPCSC(hCard); |
myHCard = scHandleToMyPCSC(hCard); |
1330 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[hCard = 0x%.8x]\n", (unsigned int) hCard)); |
1331 |
printf("[hCard = 0x%.8x]\n", (unsigned int) hCard); |
DEBUG_SCARD(("[myHCard = 0x%016lx]\n", (unsigned long) myHCard)); |
|
printf("[myHCard = 0x%016lx]\n", myHCard); |
|
|
#endif |
|
1332 |
rv = SCardBeginTransaction(myHCard); |
rv = SCardBeginTransaction(myHCard); |
|
#ifdef WITH_SCARD_DEBUG |
|
1333 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
1334 |
printf("<--ERROR SCardBeginTransaction Code=0x%.8x-->\n", (unsigned int) rv); |
{ |
1335 |
|
DEBUG_SCARD(("<--ERROR SCardBeginTransaction Code=0x%.8x-->\n", (unsigned int) rv)); |
1336 |
|
} |
1337 |
else |
else |
1338 |
printf("<--SUCCESS SCardBeginTransaction-->\n"); |
{ |
1339 |
#endif |
DEBUG_SCARD(("<--SUCCESS SCardBeginTransaction-->\n")); |
1340 |
outForceAllignment(out, 8); |
} |
1341 |
|
outForceAlignment(out, 8); |
1342 |
return rv; |
return rv; |
1343 |
} |
} |
1344 |
|
|
1355 |
in->p += 0x0C; |
in->p += 0x0C; |
1356 |
in_uint32_le(in, hCard); |
in_uint32_le(in, hCard); |
1357 |
myHCard = scHandleToMyPCSC(hCard); |
myHCard = scHandleToMyPCSC(hCard); |
1358 |
#ifdef WITH_SCARD_DEBUG |
|
1359 |
printf("[hCard = 0x%.8x]\n", (unsigned int) hCard); |
DEBUG_SCARD(("[hCard = 0x%.8x]\n", (unsigned int) hCard)); |
1360 |
printf("[myHCard = 0x%016lx]\n", myHCard); |
DEBUG_SCARD(("[myHCard = 0x%016lx]\n", (unsigned long) myHCard)); |
1361 |
printf("[dwDisposition = 0x%.8x]\n", (unsigned int) dwDisposition); |
DEBUG_SCARD(("[dwDisposition = 0x%.8x]\n", (unsigned int) dwDisposition)); |
1362 |
#endif |
|
1363 |
rv = SCardEndTransaction(myHCard, (MYPCSC_DWORD) dwDisposition); |
rv = SCardEndTransaction(myHCard, (MYPCSC_DWORD) dwDisposition); |
|
#ifdef WITH_SCARD_DEBUG |
|
1364 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
1365 |
printf("<--ERROR SCardEndTransaction Code=0x%.8x-->\n", (unsigned int) rv); |
{ |
1366 |
|
DEBUG_SCARD(("<--ERROR SCardEndTransaction Code=0x%.8x-->\n", (unsigned int) rv)); |
1367 |
|
} |
1368 |
else |
else |
1369 |
printf("<--SUCCESS SCardEndTransaction-->\n"); |
{ |
1370 |
#endif |
DEBUG_SCARD(("<--SUCCESS SCardEndTransaction-->\n")); |
1371 |
outForceAllignment(out, 8); |
} |
1372 |
|
outForceAlignment(out, 8); |
1373 |
return rv; |
return rv; |
1374 |
} |
} |
1375 |
|
|
1468 |
|
|
1469 |
if (cbRecvLength) |
if (cbRecvLength) |
1470 |
{ |
{ |
|
/* 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; |
|
|
} |
|
|
|
|
|
|
|
1471 |
recvBuf = SC_xmalloc(&lcHandle, cbRecvLength); |
recvBuf = SC_xmalloc(&lcHandle, cbRecvLength); |
1472 |
if (!recvBuf) |
if (!recvBuf) |
1473 |
return SC_returnNoMemoryError(&lcHandle, in, out); |
return SC_returnNoMemoryError(&lcHandle, in, out); |
1501 |
else |
else |
1502 |
pioRecvPci = NULL; |
pioRecvPci = NULL; |
1503 |
|
|
1504 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
1505 |
printf("++++++++++\n"); |
DEBUG_SCARD(("++++++++++\n")); |
1506 |
printf("[SEND LEN = %d]\n", (unsigned int) cbSendLength); |
DEBUG_SCARD(("[SEND LEN = %d]\n", (unsigned int) cbSendLength)); |
1507 |
printf("[RECV LEN = %d]\n", (unsigned int) cbRecvLength); |
DEBUG_SCARD(("[RECV LEN = %d]\n", (unsigned int) cbRecvLength)); |
1508 |
printf("[hCard = 0x%.8x]\n", (unsigned int) hCard); |
DEBUG_SCARD(("[hCard = 0x%.8x]\n", (unsigned int) hCard)); |
1509 |
printf("[myHCard = 0x%016lx]\n", myHCard); |
DEBUG_SCARD(("[myHCard = 0x%016lx]\n", (unsigned long) myHCard)); |
1510 |
printf("[pioSendPci]\n"); |
DEBUG_SCARD(("[pioSendPci]\n")); |
1511 |
if (pioSendPci == NULL) |
if (pioSendPci == NULL) |
1512 |
printf("NULL\n"); |
{ |
1513 |
|
DEBUG_SCARD(("NULL\n")); |
1514 |
|
} |
1515 |
else |
else |
1516 |
|
{ |
1517 |
hexdump((void *) pioSendPci, pioSendPci->cbPciLength); |
hexdump((void *) pioSendPci, pioSendPci->cbPciLength); |
1518 |
printf("[pioRecvPci]\n"); |
} |
1519 |
|
|
1520 |
|
DEBUG_SCARD(("[pioRecvPci]\n")); |
1521 |
if (pioRecvPci == NULL) |
if (pioRecvPci == NULL) |
1522 |
printf("NULL\n"); |
{ |
1523 |
|
DEBUG_SCARD(("NULL\n")); |
1524 |
|
} |
1525 |
else |
else |
1526 |
|
{ |
1527 |
hexdump((void *) pioRecvPci, pioRecvPci->cbPciLength); |
hexdump((void *) pioRecvPci, pioRecvPci->cbPciLength); |
1528 |
printf("[sendBuf]\n"); |
} |
1529 |
|
DEBUG_SCARD(("[sendBuf]\n")); |
1530 |
hexdump(sendBuf, cbSendLength); |
hexdump(sendBuf, cbSendLength); |
1531 |
printf("++++++++++\n"); |
DEBUG_SCARD(("++++++++++\n")); |
1532 |
#endif |
#endif |
1533 |
|
|
1534 |
myCbRecvLength = cbRecvLength; |
myCbRecvLength = cbRecvLength; |
1556 |
rv = SCardTransmit(myHCard, myPioSendPci, sendBuf, (MYPCSC_DWORD) cbSendLength, |
rv = SCardTransmit(myHCard, myPioSendPci, sendBuf, (MYPCSC_DWORD) cbSendLength, |
1557 |
myPioRecvPci, recvBuf, &myCbRecvLength); |
myPioRecvPci, recvBuf, &myCbRecvLength); |
1558 |
cbRecvLength = myCbRecvLength; |
cbRecvLength = myCbRecvLength; |
1559 |
|
|
1560 |
|
/* FIXME: handle responses with length > 448 bytes */ |
1561 |
|
if (cbRecvLength > 448) |
1562 |
|
{ |
1563 |
|
warning("Card response limited from %d to 448 bytes!\n", cbRecvLength); |
1564 |
|
DEBUG_SCARD(("[RECV LEN %d -> %d]\n", (unsigned int) cbRecvLength, 400)); |
1565 |
|
cbRecvLength = 448; |
1566 |
|
} |
1567 |
|
|
1568 |
if (pioRecvPci) |
if (pioRecvPci) |
1569 |
{ |
{ |
1570 |
copyIORequest_MyPCSCToServer(myPioRecvPci, pioRecvPci); |
copyIORequest_MyPCSCToServer(myPioRecvPci, pioRecvPci); |
1572 |
|
|
1573 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
1574 |
{ |
{ |
1575 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<--ERROR SCardTransmit Code=0x%.8x-->\n", (unsigned int) rv)); |
|
printf("<--ERROR SCardTransmit Code=0x%.8x-->\n", (unsigned int) rv); |
|
|
#endif |
|
1576 |
} |
} |
1577 |
else |
else |
1578 |
{ |
{ |
1579 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
1580 |
printf("<--SUCCESS SCardTransmit-->\n"); |
DEBUG_SCARD(("<--SUCCESS SCardTransmit-->\n")); |
1581 |
printf("RESULT %d\n", (unsigned int) cbRecvLength); |
DEBUG_SCARD(("RESULT %d\n", (unsigned int) cbRecvLength)); |
1582 |
hexdump(recvBuf, cbRecvLength); |
hexdump(recvBuf, cbRecvLength); |
1583 |
if (myPioRecvPci) |
if (myPioRecvPci) |
1584 |
{ |
{ |
1585 |
printf("--- myPioRecvPci ---\n"); |
DEBUG_SCARD(("--- myPioRecvPci ---\n")); |
1586 |
hexdump((void *) myPioRecvPci, myPioRecvPci->cbPciLength); |
hexdump((void *) myPioRecvPci, myPioRecvPci->cbPciLength); |
1587 |
} |
} |
1588 |
printf("------------------\n"); |
DEBUG_SCARD(("------------------\n")); |
1589 |
#endif |
#endif |
1590 |
#if 0 |
#if 0 |
1591 |
if ((pioRecvPci != NULL) && (pioRecvPci->cbPciLength > 0)) |
if ((pioRecvPci != NULL) && (pioRecvPci->cbPciLength > 0)) |
1612 |
|
|
1613 |
outBufferFinish(out, (char *) recvBuf, cbRecvLength); |
outBufferFinish(out, (char *) recvBuf, cbRecvLength); |
1614 |
} |
} |
1615 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
1616 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
1617 |
return rv; |
return rv; |
1618 |
} |
} |
1637 |
in_uint32_le(in, hCard); |
in_uint32_le(in, hCard); |
1638 |
in->p += 0x04; |
in->p += 0x04; |
1639 |
myHCard = scHandleToMyPCSC(hCard); |
myHCard = scHandleToMyPCSC(hCard); |
1640 |
#ifdef WITH_SCARD_DEBUG |
|
1641 |
printf("[hCard 0x%.8x]\n", (unsigned int) hCard); |
DEBUG_SCARD(("[hCard 0x%.8x]\n", (unsigned int) hCard)); |
1642 |
printf("[myHCard 0x%016lx]\n", myHCard); |
DEBUG_SCARD(("[myHCard 0x%016lx]\n", (unsigned long) myHCard)); |
1643 |
printf("[dwReaderLen %d]\n", (unsigned int) dwReaderLen); |
DEBUG_SCARD(("[dwReaderLen %d]\n", (unsigned int) dwReaderLen)); |
1644 |
printf("[dwAtrLen %d]\n", (unsigned int) dwAtrLen); |
DEBUG_SCARD(("[dwAtrLen %d]\n", (unsigned int) dwAtrLen)); |
|
#endif |
|
1645 |
|
|
1646 |
if (dwReaderLen <= 0 || dwReaderLen == SCARD_AUTOALLOCATE || dwReaderLen > SCARD_MAX_MEM) |
if (dwReaderLen <= 0 || dwReaderLen == SCARD_AUTOALLOCATE || dwReaderLen > SCARD_MAX_MEM) |
1647 |
dwReaderLen = SCARD_MAX_MEM; |
dwReaderLen = SCARD_MAX_MEM; |
1669 |
|
|
1670 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
1671 |
{ |
{ |
1672 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<--ERROR SCardStatus Code=0x%.8x-->\n", (unsigned int) rv)); |
|
printf("<--ERROR SCardStatus Code=0x%.8x-->\n", (unsigned int) rv); |
|
|
#endif |
|
1673 |
return SC_returnCode(rv, &lcHandle, in, out); |
return SC_returnCode(rv, &lcHandle, in, out); |
1674 |
} |
} |
1675 |
else |
else |
1676 |
{ |
{ |
1677 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
1678 |
printf("<--SUCCESS SCardStatus-->\n"); |
DEBUG_SCARD(("<--SUCCESS SCardStatus-->\n")); |
1679 |
printf("[dwState 0x%.8x]\n", (unsigned int) dwState); |
DEBUG_SCARD(("[dwState 0x%.8x]\n", (unsigned int) dwState)); |
1680 |
printf("[dwProtocol 0x%.8x]\n", (unsigned int) dwProtocol); |
DEBUG_SCARD(("[dwProtocol 0x%.8x]\n", (unsigned int) dwProtocol)); |
1681 |
printf("[Reader Name]\n"); |
DEBUG_SCARD(("[Reader Name]\n")); |
1682 |
hexdump((unsigned char *) readerName, dwReaderLen); |
hexdump((unsigned char *) readerName, dwReaderLen); |
1683 |
printf("[Atr]\n"); |
DEBUG_SCARD(("[Atr]\n")); |
1684 |
hexdump(atr, dwAtrLen); |
hexdump(atr, dwAtrLen); |
1685 |
#endif |
#endif |
1686 |
if (dwState & (SCARD_SPECIFIC | SCARD_NEGOTIABLE)) |
if (dwState & (SCARD_SPECIFIC | SCARD_NEGOTIABLE)) |
1728 |
out_uint32_le(out, dataLength); |
out_uint32_le(out, dataLength); |
1729 |
out->p = psave; |
out->p = psave; |
1730 |
} |
} |
1731 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
1732 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
1733 |
return rv; |
return rv; |
1734 |
} |
} |
1751 |
in_uint32_le(in, hCard); |
in_uint32_le(in, hCard); |
1752 |
in->p += 0x04; |
in->p += 0x04; |
1753 |
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 |
|
1754 |
|
|
1755 |
|
DEBUG_SCARD(("[hCard 0x%.8x]\n", (unsigned int) hCard)); |
1756 |
|
DEBUG_SCARD(("[myHCard 0x%.8x]\n", (unsigned int) myHCard)); |
1757 |
|
DEBUG_SCARD(("[dwAtrLen %d]\n", (unsigned int) dwAtrLen)); |
1758 |
|
|
1759 |
dwReaderLen = SCARD_MAX_MEM; |
dwReaderLen = SCARD_MAX_MEM; |
1760 |
if (dwAtrLen <= 0 || dwAtrLen == SCARD_AUTOALLOCATE || dwAtrLen > SCARD_MAX_MEM) |
if (dwAtrLen <= 0 || dwAtrLen == SCARD_AUTOALLOCATE || dwAtrLen > SCARD_MAX_MEM) |
1780 |
|
|
1781 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
1782 |
{ |
{ |
1783 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<--ERROR SCardStatus (no ScardState) Code=0x%.8x-->\n", |
1784 |
printf("<--ERROR SCardStatus (no ScardState) Code=0x%.8x-->\n", (unsigned int) rv); |
(unsigned int) rv)); |
|
#endif |
|
1785 |
return SC_returnCode(rv, &lcHandle, in, out); |
return SC_returnCode(rv, &lcHandle, in, out); |
1786 |
} |
} |
1787 |
else |
else |
1788 |
{ |
{ |
1789 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
1790 |
printf("<--SUCCESS SCardStatus (no ScardState)-->\n"); |
DEBUG_SCARD(("<--SUCCESS SCardStatus (no ScardState)-->\n")); |
1791 |
printf("[dwState 0x%.8x]\n", (unsigned int) dwState); |
DEBUG_SCARD(("[dwState 0x%.8x]\n", (unsigned int) dwState)); |
1792 |
printf("[dwProtocol 0x%.8x]\n", (unsigned int) dwProtocol); |
DEBUG_SCARD(("[dwProtocol 0x%.8x]\n", (unsigned int) dwProtocol)); |
1793 |
printf("[Atr]\n"); |
DEBUG_SCARD(("[Atr]\n")); |
1794 |
hexdump(atr, dwAtrLen); |
hexdump(atr, dwAtrLen); |
1795 |
#endif |
#endif |
1796 |
if (dwState & (SCARD_SPECIFIC | SCARD_NEGOTIABLE)) |
if (dwState & (SCARD_SPECIFIC | SCARD_NEGOTIABLE)) |
1822 |
out_uint8p(out, atr, dwAtrLen); |
out_uint8p(out, atr, dwAtrLen); |
1823 |
outRepos(out, dwAtrLen); |
outRepos(out, dwAtrLen); |
1824 |
} |
} |
1825 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
1826 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
1827 |
return rv; |
return rv; |
1828 |
} |
} |
1858 |
dwGroups = groups; |
dwGroups = groups; |
1859 |
|
|
1860 |
if (rv) |
if (rv) |
|
#ifdef WITH_SCARD_DEBUG |
|
1861 |
{ |
{ |
1862 |
printf("<--ERROR SCardListReaderGroups Code=0x%.8x-->\n", (unsigned int) rv); |
DEBUG_SCARD(("<--ERROR SCardListReaderGroups Code=0x%.8x-->\n", (unsigned int) rv)); |
|
#endif |
|
1863 |
return SC_returnCode(rv, &lcHandle, in, out); |
return SC_returnCode(rv, &lcHandle, in, out); |
|
#ifdef WITH_SCARD_DEBUG |
|
1864 |
} |
} |
1865 |
else |
else |
1866 |
{ |
{ |
1867 |
printf("<--SUCCESS SCardListReaderGroups-->\n"); |
DEBUG_SCARD(("<--SUCCESS SCardListReaderGroups-->\n")); |
1868 |
} |
} |
|
#endif |
|
1869 |
|
|
1870 |
|
|
1871 |
out_uint32_le(out, dwGroups); |
out_uint32_le(out, dwGroups); |
1875 |
outRepos(out, dwGroups); |
outRepos(out, dwGroups); |
1876 |
out_uint32_le(out, 0x00000000); |
out_uint32_le(out, 0x00000000); |
1877 |
|
|
1878 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
1879 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
1880 |
return rv; |
return rv; |
1881 |
} |
} |
1901 |
|
|
1902 |
dwAttrId = dwAttrId & 0x0000FFFF; |
dwAttrId = dwAttrId & 0x0000FFFF; |
1903 |
|
|
1904 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[hCard = 0x%.8x]\n", (unsigned int) hCard)); |
1905 |
printf("[hCard = 0x%.8x]\n", (unsigned int) hCard); |
DEBUG_SCARD(("[myHCard 0x%.8x]\n", (unsigned int) myHCard)); |
1906 |
printf("[myHCard 0x%.8x]\n", (unsigned int) myHCard); |
DEBUG_SCARD(("[dwAttrId = 0x%.8x]\n", (unsigned int) dwAttrId)); |
1907 |
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 |
|
1908 |
|
|
1909 |
if (dwAttrLen > MAX_BUFFER_SIZE) |
if (dwAttrLen > MAX_BUFFER_SIZE) |
1910 |
dwAttrLen = MAX_BUFFER_SIZE; |
dwAttrLen = MAX_BUFFER_SIZE; |
1930 |
|
|
1931 |
if (dwAttrId == 0x00000100 && rv != SCARD_S_SUCCESS) |
if (dwAttrId == 0x00000100 && rv != SCARD_S_SUCCESS) |
1932 |
{ |
{ |
1933 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("Get Attribute ATTR_VENDOR_NAME\n")); |
|
printf("Get Attribute ATTR_VENDOR_NAME\n"); |
|
|
#endif |
|
1934 |
pthread_mutex_lock(&hcardAccess); |
pthread_mutex_lock(&hcardAccess); |
1935 |
PSCHCardRec hcard = hcardFirst; |
PSCHCardRec hcard = hcardFirst; |
1936 |
while (hcard) |
while (hcard) |
1945 |
hcard = hcard->next; |
hcard = hcard->next; |
1946 |
} |
} |
1947 |
pthread_mutex_unlock(&hcardAccess); |
pthread_mutex_unlock(&hcardAccess); |
1948 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[0x%.8x]\n", (unsigned int) rv)); |
|
printf("[0x%.8x]\n", (unsigned int) rv); |
|
|
#endif |
|
1949 |
} |
} |
1950 |
|
|
1951 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
1952 |
{ |
{ |
1953 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<--ERROR SCardGetAttrib Code=0x%.8x-->\n", (unsigned int) rv)); |
|
printf("<--ERROR SCardGetAttrib Code=0x%.8x-->\n", (unsigned int) rv); |
|
|
#endif |
|
1954 |
return SC_returnCode(rv, &lcHandle, in, out); |
return SC_returnCode(rv, &lcHandle, in, out); |
1955 |
} |
} |
1956 |
else |
else |
1957 |
{ |
{ |
1958 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
1959 |
printf("<--SUCCESS SCardGetAttrib-->\n"); |
DEBUG_SCARD(("<--SUCCESS SCardGetAttrib-->\n")); |
1960 |
printf("[LENGTH %d]\n", (unsigned int) dwAttrLen); |
DEBUG_SCARD(("[LENGTH %d]\n", (unsigned int) dwAttrLen)); |
1961 |
printf("+++++++++++++++++++++\n"); |
DEBUG_SCARD(("+++++++++++++++++++++\n")); |
1962 |
hexdump(pbAttr, dwAttrLen); |
hexdump(pbAttr, dwAttrLen); |
1963 |
printf("+++++++++++++++++++++\n"); |
DEBUG_SCARD(("+++++++++++++++++++++\n")); |
1964 |
#endif |
#endif |
1965 |
out_uint32_le(out, dwAttrLen); |
out_uint32_le(out, dwAttrLen); |
1966 |
out_uint32_le(out, 0x00000200); |
out_uint32_le(out, 0x00000200); |
1976 |
outRepos(out, dwAttrLen); |
outRepos(out, dwAttrLen); |
1977 |
out_uint32_le(out, 0x00000000); |
out_uint32_le(out, 0x00000000); |
1978 |
} |
} |
1979 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
1980 |
return rv; |
return rv; |
1981 |
} |
} |
1982 |
|
|
2001 |
|
|
2002 |
dwAttrId = dwAttrId & 0x0000FFFF; |
dwAttrId = dwAttrId & 0x0000FFFF; |
2003 |
|
|
2004 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[hCard = 0x%.8x]\n", (unsigned int) hCard)); |
2005 |
printf("[hCard = 0x%.8x]\n", (unsigned int) hCard); |
DEBUG_SCARD(("[myHCard 0x%.8x]\n", (unsigned int) myHCard)); |
2006 |
printf("[myHCard 0x%.8x]\n", (unsigned int) myHCard); |
DEBUG_SCARD(("[dwAttrId = 0x%.8x]\n", (unsigned int) dwAttrId)); |
2007 |
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 |
|
2008 |
|
|
2009 |
if (dwAttrLen > MAX_BUFFER_SIZE) |
if (dwAttrLen > MAX_BUFFER_SIZE) |
2010 |
dwAttrLen = MAX_BUFFER_SIZE; |
dwAttrLen = MAX_BUFFER_SIZE; |
2016 |
in_uint8a(in, pbAttr, dwAttrLen); |
in_uint8a(in, pbAttr, dwAttrLen); |
2017 |
rv = SCardSetAttrib(myHCard, (MYPCSC_DWORD) dwAttrId, pbAttr, (MYPCSC_DWORD) dwAttrLen); |
rv = SCardSetAttrib(myHCard, (MYPCSC_DWORD) dwAttrId, pbAttr, (MYPCSC_DWORD) dwAttrLen); |
2018 |
|
|
|
#ifdef WITH_SCARD_DEBUG |
|
2019 |
if (rv) |
if (rv) |
2020 |
printf("<--ERROR SCardSetAttrib Code=0x%.8x-->\n", (unsigned int) rv); |
{ |
2021 |
|
DEBUG_SCARD(("<--ERROR SCardSetAttrib Code=0x%.8x-->\n", (unsigned int) rv)); |
2022 |
|
} |
2023 |
else |
else |
2024 |
printf("<--SUCCESS SCardSetAttrib-->\n"); |
{ |
2025 |
#endif |
DEBUG_SCARD(("<--SUCCESS SCardSetAttrib-->\n")); |
2026 |
|
} |
2027 |
|
|
2028 |
out_uint32_le(out, 0x00000000); |
out_uint32_le(out, 0x00000000); |
2029 |
out_uint32_le(out, 0x00000200); |
out_uint32_le(out, 0x00000200); |
2030 |
out_uint32_le(out, 0x00000000); |
out_uint32_le(out, 0x00000000); |
2031 |
out_uint32_le(out, 0x00000000); |
out_uint32_le(out, 0x00000000); |
2032 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
2033 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
2034 |
return rv; |
return rv; |
2035 |
} |
} |
2045 |
MYPCSC_SCARDHANDLE myHCard; |
MYPCSC_SCARDHANDLE myHCard; |
2046 |
SERVER_DWORD map[3]; |
SERVER_DWORD map[3]; |
2047 |
SERVER_DWORD dwControlCode; |
SERVER_DWORD dwControlCode; |
2048 |
char *pInBuffer, *pOutBuffer; |
unsigned char *pInBuffer, *pOutBuffer; |
2049 |
SERVER_DWORD nInBufferSize, nOutBufferSize, nOutBufferRealSize, nBytesReturned; |
SERVER_DWORD nInBufferSize, nOutBufferSize, nOutBufferRealSize, nBytesReturned; |
2050 |
MYPCSC_DWORD sc_nBytesReturned; |
MYPCSC_DWORD sc_nBytesReturned; |
2051 |
PMEM_HANDLE lcHandle = NULL; |
PMEM_HANDLE lcHandle = NULL; |
2092 |
if (!pOutBuffer) |
if (!pOutBuffer) |
2093 |
return SC_returnNoMemoryError(&lcHandle, in, out); |
return SC_returnNoMemoryError(&lcHandle, in, out); |
2094 |
|
|
2095 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
2096 |
printf("[hContext = 0x%.8x]\n", (unsigned int) hContext); |
DEBUG_SCARD(("[hContext = 0x%.8x]\n", (unsigned int) hContext)); |
2097 |
printf("[hCard = 0x%.8x]\n", (unsigned int) hCard); |
DEBUG_SCARD(("[hCard = 0x%.8x]\n", (unsigned int) hCard)); |
2098 |
printf("[dwControlCode = 0x%.8x]\n", (unsigned int) dwControlCode); |
DEBUG_SCARD(("[dwControlCode = 0x%.8x]\n", (unsigned int) dwControlCode)); |
2099 |
printf("[nInBufferSize = %d]\n", (unsigned int) nInBufferSize); |
DEBUG_SCARD(("[nInBufferSize = %d]\n", (unsigned int) nInBufferSize)); |
2100 |
printf("[nOutBufferSize = %d]\n", (unsigned int) nOutBufferSize); |
DEBUG_SCARD(("[nOutBufferSize = %d]\n", (unsigned int) nOutBufferSize)); |
2101 |
if (nInBufferSize > 0) |
if (nInBufferSize > 0) |
2102 |
{ |
{ |
2103 |
printf("[In buffer]\n"); |
DEBUG_SCARD(("[In buffer]\n")); |
2104 |
hexdump((unsigned char *) pInBuffer, nInBufferSize); |
hexdump((unsigned char *) pInBuffer, nInBufferSize); |
2105 |
} |
} |
2106 |
printf("---> Calling SCardControl\n"); |
DEBUG_SCARD(("---> Calling SCardControl\n")); |
2107 |
#endif |
#endif |
2108 |
|
|
|
#ifdef WITH_PCSC120 |
|
2109 |
sc_nBytesReturned = nBytesReturned; |
sc_nBytesReturned = nBytesReturned; |
2110 |
myHCard = scHandleToMyPCSC(hCard); |
myHCard = scHandleToMyPCSC(hCard); |
2111 |
|
#ifdef WITH_PCSC120 |
2112 |
rv = SCardControl(myHCard, pInBuffer, (MYPCSC_DWORD) nInBufferSize, pOutBuffer, |
rv = SCardControl(myHCard, pInBuffer, (MYPCSC_DWORD) nInBufferSize, pOutBuffer, |
2113 |
&sc_nBytesReturned); |
&sc_nBytesReturned); |
|
nBytesReturned = sc_nBytesReturned; |
|
2114 |
#else |
#else |
|
sc_nBytesReturned = nBytesReturned; |
|
|
myHCard = scHandleToMyPCSC(hCard); |
|
2115 |
rv = SCardControl(myHCard, (MYPCSC_DWORD) dwControlCode, pInBuffer, |
rv = SCardControl(myHCard, (MYPCSC_DWORD) dwControlCode, pInBuffer, |
2116 |
(MYPCSC_DWORD) nInBufferSize, pOutBuffer, |
(MYPCSC_DWORD) nInBufferSize, pOutBuffer, |
2117 |
(MYPCSC_DWORD) nOutBufferRealSize, &sc_nBytesReturned); |
(MYPCSC_DWORD) nOutBufferRealSize, &sc_nBytesReturned); |
|
nBytesReturned = sc_nBytesReturned; |
|
2118 |
#endif |
#endif |
2119 |
|
nBytesReturned = sc_nBytesReturned; |
2120 |
|
|
2121 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
2122 |
if (rv != SCARD_S_SUCCESS) |
if (rv != SCARD_S_SUCCESS) |
2123 |
printf("<--ERROR SCardControl Code=0x%.8x-->\n", (unsigned int) rv); |
{ |
2124 |
|
DEBUG_SCARD(("<--ERROR SCardControl Code=0x%.8x-->\n", (unsigned int) rv)); |
2125 |
|
} |
2126 |
else |
else |
2127 |
{ |
{ |
2128 |
printf("<--SUCCESS SCardControl-->\n"); |
DEBUG_SCARD(("<--SUCCESS SCardControl-->\n")); |
2129 |
printf("[LENGTH %d]\n", (unsigned int) nBytesReturned); |
DEBUG_SCARD(("[LENGTH %d]\n", (unsigned int) nBytesReturned)); |
2130 |
printf("+++++++++++++++++++++\n"); |
DEBUG_SCARD(("+++++++++++++++++++++\n")); |
2131 |
hexdump((unsigned char *) pOutBuffer, nBytesReturned); |
hexdump((unsigned char *) pOutBuffer, nBytesReturned); |
2132 |
printf("+++++++++++++++++++++\n"); |
DEBUG_SCARD(("+++++++++++++++++++++\n")); |
2133 |
} |
} |
2134 |
#endif |
#endif |
2135 |
|
|
2142 |
outRepos(out, nBytesReturned); |
outRepos(out, nBytesReturned); |
2143 |
} |
} |
2144 |
|
|
2145 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
2146 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
2147 |
return rv; |
return rv; |
2148 |
} |
} |
2161 |
SERVER_DWORD Result = 0x00000000; |
SERVER_DWORD Result = 0x00000000; |
2162 |
unsigned char *psize, *pend, *pStatusCode; |
unsigned char *psize, *pend, *pStatusCode; |
2163 |
SERVER_DWORD addToEnd = 0; |
SERVER_DWORD addToEnd = 0; |
2164 |
|
#ifdef WITH_DEBUG_SCARD |
|
#ifdef WITH_SCARD_DEBUG |
|
2165 |
unsigned char *pbeg = out->p; |
unsigned char *pbeg = out->p; |
2166 |
printf("--------------------------------\n"); |
|
2167 |
printf("[NTHANDLE %08X]\n", handle); |
DEBUG_SCARD(("--------------------------------\n")); |
2168 |
printf("[REQUEST %08X]\n", request); |
DEBUG_SCARD(("[NTHANDLE %08X]\n", handle)); |
2169 |
printf("[INPUT DUMP]--------------------\n"); |
DEBUG_SCARD(("[REQUEST %08X]\n", request)); |
2170 |
|
DEBUG_SCARD(("[INPUT DUMP]--------------------\n")); |
2171 |
hexdump(in->p, in->end - in->p); |
hexdump(in->p, in->end - in->p); |
2172 |
#endif |
#endif |
2173 |
/* Processing request */ |
/* Processing request */ |
2185 |
/* SCardEstablishContext */ |
/* SCardEstablishContext */ |
2186 |
case SC_ESTABLISH_CONTEXT: |
case SC_ESTABLISH_CONTEXT: |
2187 |
{ |
{ |
2188 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardEstablishContext--->\n")); |
|
printf("<---SCardEstablishContext--->\n"); |
|
|
#endif |
|
2189 |
Result = (SERVER_DWORD) TS_SCardEstablishContext(in, out); |
Result = (SERVER_DWORD) TS_SCardEstablishContext(in, out); |
2190 |
break; |
break; |
2191 |
} |
} |
2192 |
/* SCardReleaseContext */ |
/* SCardReleaseContext */ |
2193 |
case SC_RELEASE_CONTEXT: |
case SC_RELEASE_CONTEXT: |
2194 |
{ |
{ |
2195 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardReleaseContext--->\n")); |
|
printf("<---SCardReleaseContext--->\n"); |
|
|
#endif |
|
2196 |
Result = (SERVER_DWORD) TS_SCardReleaseContext(in, out); |
Result = (SERVER_DWORD) TS_SCardReleaseContext(in, out); |
2197 |
break; |
break; |
2198 |
} |
} |
2199 |
/* SCardIsValidContext */ |
/* SCardIsValidContext */ |
2200 |
case SC_IS_VALID_CONTEXT: |
case SC_IS_VALID_CONTEXT: |
2201 |
{ |
{ |
2202 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardIsValidContext--->\n")); |
|
printf("<---SCardIsValidContext--->\n"); |
|
|
#endif |
|
2203 |
Result = (SERVER_DWORD) TS_SCardIsValidContext(in, out); |
Result = (SERVER_DWORD) TS_SCardIsValidContext(in, out); |
2204 |
break; |
break; |
2205 |
} |
} |
2208 |
case SC_LIST_READERS + 4: /* SCardListReadersW */ |
case SC_LIST_READERS + 4: /* SCardListReadersW */ |
2209 |
{ |
{ |
2210 |
BOOL wide = request != SC_LIST_READERS; |
BOOL wide = request != SC_LIST_READERS; |
2211 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardListReaders---> (%s)\n", |
2212 |
printf("<---SCardListReaders---> (%s)\n", |
(wide) ? ("WIDE") : ("ASCII"))); |
|
(wide) ? ("WIDE") : ("ASCII")); |
|
|
#endif |
|
2213 |
Result = (SERVER_DWORD) TS_SCardListReaders(in, out, wide); |
Result = (SERVER_DWORD) TS_SCardListReaders(in, out, wide); |
2214 |
break; |
break; |
2215 |
} |
} |
2218 |
case SC_CONNECT + 4: /* SCardConnectW */ |
case SC_CONNECT + 4: /* SCardConnectW */ |
2219 |
{ |
{ |
2220 |
BOOL wide = request != SC_CONNECT; |
BOOL wide = request != SC_CONNECT; |
2221 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardConnect---> (%s)\n", |
2222 |
printf("<---SCardConnect---> (%s)\n", |
(wide) ? ("WIDE") : ("ASCII"))); |
|
(wide) ? ("WIDE") : ("ASCII")); |
|
|
#endif |
|
2223 |
Result = (SERVER_DWORD) TS_SCardConnect(in, out, wide); |
Result = (SERVER_DWORD) TS_SCardConnect(in, out, wide); |
2224 |
break; |
break; |
2225 |
} |
} |
2226 |
/* ScardReconnect */ |
/* ScardReconnect */ |
2227 |
case SC_RECONNECT: |
case SC_RECONNECT: |
2228 |
{ |
{ |
2229 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardReconnect--->\n")); |
|
printf("<---SCardReconnect--->\n"); |
|
|
#endif |
|
2230 |
Result = (SERVER_DWORD) TS_SCardReconnect(in, out); |
Result = (SERVER_DWORD) TS_SCardReconnect(in, out); |
2231 |
break; |
break; |
2232 |
} |
} |
2233 |
/* ScardDisconnect */ |
/* ScardDisconnect */ |
2234 |
case SC_DISCONNECT: |
case SC_DISCONNECT: |
2235 |
{ |
{ |
2236 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardDisconnect--->\n")); |
|
printf("<---SCardDisconnect--->\n"); |
|
|
#endif |
|
2237 |
Result = (SERVER_DWORD) TS_SCardDisconnect(in, out); |
Result = (SERVER_DWORD) TS_SCardDisconnect(in, out); |
2238 |
break; |
break; |
2239 |
} |
} |
2242 |
case SC_GET_STATUS_CHANGE + 4: /* SCardGetStatusChangeW */ |
case SC_GET_STATUS_CHANGE + 4: /* SCardGetStatusChangeW */ |
2243 |
{ |
{ |
2244 |
BOOL wide = request != SC_GET_STATUS_CHANGE; |
BOOL wide = request != SC_GET_STATUS_CHANGE; |
2245 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardGetStatusChange---> (%s)\n", |
2246 |
printf("<---SCardGetStatusChange---> (%s)\n", |
(wide) ? ("WIDE") : ("ASCII"))); |
|
(wide) ? ("WIDE") : ("ASCII")); |
|
|
#endif |
|
2247 |
Result = (SERVER_DWORD) TS_SCardGetStatusChange(in, out, wide); |
Result = (SERVER_DWORD) TS_SCardGetStatusChange(in, out, wide); |
2248 |
break; |
break; |
2249 |
} |
} |
2250 |
/* SCardCancel */ |
/* SCardCancel */ |
2251 |
case SC_CANCEL: |
case SC_CANCEL: |
2252 |
{ |
{ |
2253 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardCancel--->\n")); |
|
printf("<---SCardCancel--->\n"); |
|
|
#endif |
|
2254 |
Result = (SERVER_DWORD) TS_SCardCancel(in, out); |
Result = (SERVER_DWORD) TS_SCardCancel(in, out); |
2255 |
break; |
break; |
2256 |
} |
} |
2259 |
case SC_LOCATE_CARDS_BY_ATR + 4: /* SCardLocateCardsByATRW */ |
case SC_LOCATE_CARDS_BY_ATR + 4: /* SCardLocateCardsByATRW */ |
2260 |
{ |
{ |
2261 |
BOOL wide = request != SC_LOCATE_CARDS_BY_ATR; |
BOOL wide = request != SC_LOCATE_CARDS_BY_ATR; |
2262 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardLocateCardsByATR---> (%s)\n", |
2263 |
printf("<---SCardLocateCardsByATR---> (%s)\n", |
(wide) ? ("WIDE") : ("ASCII"))); |
|
(wide) ? ("WIDE") : ("ASCII")); |
|
|
#endif |
|
2264 |
Result = (SERVER_DWORD) TS_SCardLocateCardsByATR(in, out, wide); |
Result = (SERVER_DWORD) TS_SCardLocateCardsByATR(in, out, wide); |
2265 |
break; |
break; |
2266 |
} |
} |
2267 |
/* SCardBeginTransaction */ |
/* SCardBeginTransaction */ |
2268 |
case SC_BEGIN_TRANSACTION: |
case SC_BEGIN_TRANSACTION: |
2269 |
{ |
{ |
2270 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardBeginTransaction--->\n")); |
|
printf("<---SCardBeginTransaction--->\n"); |
|
|
#endif |
|
2271 |
Result = (SERVER_DWORD) TS_SCardBeginTransaction(in, out); |
Result = (SERVER_DWORD) TS_SCardBeginTransaction(in, out); |
2272 |
break; |
break; |
2273 |
} |
} |
2274 |
/* SCardBeginTransaction */ |
/* SCardBeginTransaction */ |
2275 |
case SC_END_TRANSACTION: |
case SC_END_TRANSACTION: |
2276 |
{ |
{ |
2277 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardEndTransaction--->\n")); |
|
printf("<---SCardEndTransaction--->\n"); |
|
|
#endif |
|
2278 |
Result = (SERVER_DWORD) TS_SCardEndTransaction(in, out); |
Result = (SERVER_DWORD) TS_SCardEndTransaction(in, out); |
2279 |
break; |
break; |
2280 |
} |
} |
2281 |
/* ScardTransmit */ |
/* ScardTransmit */ |
2282 |
case SC_TRANSMIT: |
case SC_TRANSMIT: |
2283 |
{ |
{ |
2284 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardTransmit--->\n")); |
|
printf("<---SCardTransmit--->\n"); |
|
|
#endif |
|
2285 |
Result = (SERVER_DWORD) TS_SCardTransmit(in, out); |
Result = (SERVER_DWORD) TS_SCardTransmit(in, out); |
2286 |
break; |
break; |
2287 |
} |
} |
2288 |
/* SCardControl */ |
/* SCardControl */ |
2289 |
case SC_CONTROL: |
case SC_CONTROL: |
2290 |
{ |
{ |
2291 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardControl--->\n")); |
|
printf("<---SCardControl--->\n"); |
|
|
#endif |
|
2292 |
Result = (SERVER_DWORD) TS_SCardControl(in, out); |
Result = (SERVER_DWORD) TS_SCardControl(in, out); |
2293 |
break; |
break; |
2294 |
} |
} |
2296 |
#ifndef WITH_PCSC120 |
#ifndef WITH_PCSC120 |
2297 |
case SC_GETATTRIB: |
case SC_GETATTRIB: |
2298 |
{ |
{ |
2299 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardGetAttrib--->\n")); |
|
printf("<---SCardGetAttrib--->\n"); |
|
|
#endif |
|
2300 |
Result = (SERVER_DWORD) TS_SCardGetAttrib(in, out); |
Result = (SERVER_DWORD) TS_SCardGetAttrib(in, out); |
2301 |
break; |
break; |
2302 |
} |
} |
2303 |
#endif |
#endif |
2304 |
case SC_ACCESS_STARTED_EVENT: |
case SC_ACCESS_STARTED_EVENT: |
2305 |
{ |
{ |
2306 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardAccessStartedEvent-->\n")); |
|
printf("<---SCardAccessStartedEvent-->\n"); |
|
|
#endif |
|
2307 |
Result = (SERVER_DWORD) TS_SCardAccessStartedEvent(in, out); |
Result = (SERVER_DWORD) TS_SCardAccessStartedEvent(in, out); |
2308 |
break; |
break; |
2309 |
} |
} |
2311 |
case SC_STATUS + 4: /* SCardStatusW */ |
case SC_STATUS + 4: /* SCardStatusW */ |
2312 |
{ |
{ |
2313 |
BOOL wide = request != SC_STATUS; |
BOOL wide = request != SC_STATUS; |
2314 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardStatus---> (%s)\n", |
2315 |
printf("<---SCardStatus---> (%s)\n", (wide) ? ("WIDE") : ("ASCII")); |
(wide) ? ("WIDE") : ("ASCII"))); |
|
#endif |
|
2316 |
Result = (SERVER_DWORD) TS_SCardStatus(in, out, wide); |
Result = (SERVER_DWORD) TS_SCardStatus(in, out, wide); |
2317 |
break; |
break; |
2318 |
} |
} |
2319 |
case SC_STATE: /* SCardState */ |
case SC_STATE: /* SCardState */ |
2320 |
{ |
{ |
2321 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---SCardState--->")); |
|
printf("<---SCardState--->"); |
|
|
#endif |
|
2322 |
Result = (SERVER_DWORD) TS_SCardState(in, out); |
Result = (SERVER_DWORD) TS_SCardState(in, out); |
2323 |
break; |
break; |
2324 |
} |
} |
2325 |
default: |
default: |
2326 |
{ |
{ |
2327 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("<---UNSUPPORTED-FUNC--->\n")); |
|
printf("<---UNSUPPORTED-FUNC--->\n"); |
|
|
#endif |
|
2328 |
Result = 0x80100014; |
Result = 0x80100014; |
2329 |
out_uint8s(out, 256); |
out_uint8s(out, 256); |
2330 |
break; |
break; |
2351 |
out_uint8s(out, addToEnd); |
out_uint8s(out, addToEnd); |
2352 |
} |
} |
2353 |
|
|
2354 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
2355 |
printf("[OUTPUT DUMP]-------------------\n"); |
DEBUG_SCARD(("[OUTPUT DUMP]-------------------\n")); |
2356 |
hexdump(pbeg, (size_t) (out->p) - (size_t) pbeg); |
hexdump(pbeg, (size_t) (out->p) - (size_t) pbeg); |
2357 |
printf("--------------------------------\n"); |
DEBUG_SCARD(("--------------------------------\n")); |
2358 |
#endif |
#endif |
2359 |
return STATUS_SUCCESS; |
return STATUS_SUCCESS; |
2360 |
} |
} |
2491 |
size_t buffer_len = 0; |
size_t buffer_len = 0; |
2492 |
scard_device_control(data->handle, data->request, data->in, data->out); |
scard_device_control(data->handle, data->request, data->in, data->out); |
2493 |
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 |
|
2494 |
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 |
|
2495 |
SC_destroyThreadData(data); |
SC_destroyThreadData(data); |
2496 |
} |
} |
2497 |
|
|
2499 |
static void * |
static void * |
2500 |
thread_function(PThreadListElement listElement) |
thread_function(PThreadListElement listElement) |
2501 |
{ |
{ |
2502 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
2503 |
long sTime = 0; |
long sTime = 0; |
2504 |
#endif |
#endif |
2505 |
if ((listElement != NULL) && (listElement->data != NULL)) |
if ((listElement != NULL) && (listElement->data != NULL)) |
2506 |
{ |
{ |
2507 |
while (1) |
while (1) |
2508 |
{ |
{ |
2509 |
#ifdef WITH_SCARD_DEBUG |
#ifdef WITH_DEBUG_SCARD |
2510 |
sTime = time(NULL); |
sTime = time(NULL); |
2511 |
#endif |
#endif |
2512 |
pthread_mutex_lock(&listElement->nodata); |
pthread_mutex_lock(&listElement->nodata); |
2513 |
SC_deviceControl(listElement->data); |
SC_deviceControl(listElement->data); |
2514 |
listElement->data = NULL; |
listElement->data = NULL; |
2515 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[HANDLING TIME %d]\n", (int) (time(NULL) - sTime))); |
|
printf("[HANDLING TIME %d]\n", (int) (time(NULL) - sTime)); |
|
|
#endif |
|
2516 |
pthread_mutex_unlock(&listElement->busy); |
pthread_mutex_unlock(&listElement->busy); |
2517 |
} |
} |
2518 |
} |
} |
2526 |
int Result = 0; |
int Result = 0; |
2527 |
PThreadListElement cur = threadList, last = threadList; |
PThreadListElement cur = threadList, last = threadList; |
2528 |
|
|
2529 |
#ifdef WITH_SCARD_DEBUG |
DEBUG_SCARD(("[THREAD COUNT %d]\n", threadCount)); |
|
printf("[THREAD COUNT %d]\n", threadCount); |
|
|
#endif |
|
2530 |
|
|
2531 |
while (cur) |
while (cur) |
2532 |
{ |
{ |
2559 |
Result = pthread_create(&cur->thread, NULL, (void *(*)(void *)) thread_function, cur); |
Result = pthread_create(&cur->thread, NULL, (void *(*)(void *)) thread_function, cur); |
2560 |
if (0 != Result) |
if (0 != Result) |
2561 |
{ |
{ |
2562 |
printf("[THREAD CREATE ERROR 0x%.8x]\n", Result); |
error("[THREAD CREATE ERROR 0x%.8x]\n", Result); |
2563 |
SC_xfree(&threadListHandle, cur); |
SC_xfree(&threadListHandle, cur); |
2564 |
SC_destroyThreadData(data); |
SC_destroyThreadData(data); |
2565 |
data = NULL; |
data = NULL; |
2624 |
{ |
{ |
2625 |
if (!tcp_sendcontrol_mutex) |
if (!tcp_sendcontrol_mutex) |
2626 |
{ |
{ |
2627 |
tcp_sendcontrol_mutex = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t)); |
tcp_sendcontrol_mutex = (pthread_mutex_t *) xmalloc(sizeof(pthread_mutex_t)); |
2628 |
pthread_mutex_init(tcp_sendcontrol_mutex, NULL); |
pthread_mutex_init(tcp_sendcontrol_mutex, NULL); |
2629 |
} |
} |
2630 |
|
|
2637 |
pthread_mutex_unlock(tcp_sendcontrol_mutex); |
pthread_mutex_unlock(tcp_sendcontrol_mutex); |
2638 |
} |
} |
2639 |
|
|
2640 |
|
void |
2641 |
|
scard_sec_lock(void) |
2642 |
|
{ |
2643 |
|
if (!sec_channels_mutex) |
2644 |
|
{ |
2645 |
|
sec_channels_mutex = (pthread_mutex_t *) xmalloc(sizeof(pthread_mutex_t)); |
2646 |
|
pthread_mutex_init(sec_channels_mutex, NULL); |
2647 |
|
} |
2648 |
|
|
2649 |
|
pthread_mutex_lock(sec_channels_mutex); |
2650 |
|
} |
2651 |
|
|
2652 |
|
void |
2653 |
|
scard_sec_unlock(void) |
2654 |
|
{ |
2655 |
|
pthread_mutex_unlock(sec_channels_mutex); |
2656 |
|
} |
2657 |
|
|
2658 |
STREAM |
STREAM |
2659 |
scard_tcp_init(void) |
scard_tcp_init(void) |
2660 |
{ |
{ |