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; |
152 |
return 0; |
return 0; |
153 |
} |
} |
154 |
|
|
|
#if 0 |
|
|
if (0 != pthread_mutex_init(&sendControl, NULL)) |
|
|
{ |
|
|
error("[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 |
{ |
{ |
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 |
679 |
DEBUG_SCARD(("<--SUCCESS SCardListReaders (no SCardIsValidContext)-->\n")); |
DEBUG_SCARD(("<--SUCCESS SCardListReaders (no SCardIsValidContext)-->\n")); |
680 |
} |
} |
681 |
|
|
682 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
683 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
684 |
return rv; |
return rv; |
685 |
} |
} |
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 |
} |
} |
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 |
} |
} |
870 |
DEBUG_SCARD(("<--SUCCESS SCardReconnect-->\n")); |
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 |
} |
} |
926 |
DEBUG_SCARD(("<--SUCCESS SCardDisconnect-->\n")); |
DEBUG_SCARD(("<--SUCCESS SCardDisconnect-->\n")); |
927 |
} |
} |
928 |
|
|
929 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
930 |
return rv; |
return rv; |
931 |
} |
} |
932 |
|
|
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 |
} |
} |
1207 |
{ |
{ |
1208 |
DEBUG_SCARD(("<--SUCCESS SCardCancel-->\n")); |
DEBUG_SCARD(("<--SUCCESS SCardCancel-->\n")); |
1209 |
} |
} |
1210 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
1211 |
return rv; |
return rv; |
1212 |
} |
} |
1213 |
|
|
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 |
} |
} |
1338 |
{ |
{ |
1339 |
DEBUG_SCARD(("<--SUCCESS SCardBeginTransaction-->\n")); |
DEBUG_SCARD(("<--SUCCESS SCardBeginTransaction-->\n")); |
1340 |
} |
} |
1341 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
1342 |
return rv; |
return rv; |
1343 |
} |
} |
1344 |
|
|
1369 |
{ |
{ |
1370 |
DEBUG_SCARD(("<--SUCCESS SCardEndTransaction-->\n")); |
DEBUG_SCARD(("<--SUCCESS SCardEndTransaction-->\n")); |
1371 |
} |
} |
1372 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
1373 |
return rv; |
return rv; |
1374 |
} |
} |
1375 |
|
|
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 |
} |
} |
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 |
} |
} |
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 |
} |
} |
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 |
} |
} |
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 |
|
|
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 |
} |
} |
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 |
} |
} |
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 |
|
|
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 |
{ |
{ |