44 |
|
|
45 |
static struct stream out[STREAM_COUNT]; |
static struct stream out[STREAM_COUNT]; |
46 |
static int cur_stream_id = 0; |
static int cur_stream_id = 0; |
47 |
static pthread_mutex_t *tcp_sendcontrol_mutex = NULL; |
static pthread_mutex_t **scard_mutex = NULL; |
48 |
|
|
49 |
static uint32 curDevice = 0, curId = 0, curBytesOut = 0; |
static uint32 curDevice = 0, curId = 0, curBytesOut = 0; |
50 |
static PSCNameMapRec nameMapList = NULL; |
static PSCNameMapRec nameMapList = NULL; |
54 |
static pthread_mutex_t queueAccess; |
static pthread_mutex_t queueAccess; |
55 |
static pthread_mutex_t queueEmpty; |
static pthread_mutex_t queueEmpty; |
56 |
static pthread_mutex_t hcardAccess; |
static pthread_mutex_t hcardAccess; |
|
/* static pthread_mutex_t sendControl; */ |
|
57 |
|
|
58 |
static PMEM_HANDLE threadListHandle = NULL; |
static PMEM_HANDLE threadListHandle = NULL; |
59 |
static PThreadListElement threadList = NULL; |
static PThreadListElement threadList = NULL; |
151 |
return 0; |
return 0; |
152 |
} |
} |
153 |
|
|
|
#if 0 |
|
|
if (0 != pthread_mutex_init(&sendControl, NULL)) |
|
|
{ |
|
|
error("[SMART CARD: Can't initialize send control mutex]\n"); |
|
|
return 0; |
|
|
} |
|
|
#endif |
|
|
|
|
|
|
|
154 |
if (0 != |
if (0 != |
155 |
pthread_create(&queueHandler, NULL, (void *(*)(void *)) queue_handler_function, NULL)) |
pthread_create(&queueHandler, NULL, (void *(*)(void *)) queue_handler_function, NULL)) |
156 |
{ |
{ |
223 |
} |
} |
224 |
} |
} |
225 |
|
|
|
|
|
|
printf("******************************************************\n"); |
|
|
printf("* Smart Card support for RDesktop is initialized. *\n"); |
|
|
printf("* Copyright (C) by Alexi Volkov, alexi@myrealbox.com *\n"); |
|
|
printf("******************************************************\n"); |
|
|
|
|
226 |
return count; |
return count; |
227 |
} |
} |
228 |
|
|
481 |
} |
} |
482 |
|
|
483 |
static void |
static void |
484 |
outForceAllignment(STREAM out, unsigned int seed) |
outForceAlignment(STREAM out, unsigned int seed) |
485 |
{ |
{ |
486 |
SERVER_DWORD add = (seed - (out->p - out->data) % seed) % seed; |
SERVER_DWORD add = (seed - (out->p - out->data) % seed) % seed; |
487 |
if (add > 0) |
if (add > 0) |
|
{ |
|
488 |
out_uint8s(out, add); |
out_uint8s(out, add); |
|
} |
|
489 |
} |
} |
490 |
|
|
491 |
static unsigned int |
static unsigned int |
678 |
DEBUG_SCARD(("<--SUCCESS SCardListReaders (no SCardIsValidContext)-->\n")); |
DEBUG_SCARD(("<--SUCCESS SCardListReaders (no SCardIsValidContext)-->\n")); |
679 |
} |
} |
680 |
|
|
681 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
682 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
683 |
return rv; |
return rv; |
684 |
} |
} |
751 |
out_uint32_le(out, dataLength); |
out_uint32_le(out, dataLength); |
752 |
out->p = pend; |
out->p = pend; |
753 |
|
|
754 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
755 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
756 |
return rv; |
return rv; |
757 |
} |
} |
826 |
out_uint32_le(out, 0x00000004); |
out_uint32_le(out, 0x00000004); |
827 |
out_uint32_le(out, hCard); |
out_uint32_le(out, hCard); |
828 |
|
|
829 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
830 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
831 |
return rv; |
return rv; |
832 |
} |
} |
869 |
DEBUG_SCARD(("<--SUCCESS SCardReconnect-->\n")); |
DEBUG_SCARD(("<--SUCCESS SCardReconnect-->\n")); |
870 |
} |
} |
871 |
|
|
872 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
873 |
out_uint32_le(out, (SERVER_DWORD) dwActiveProtocol); |
out_uint32_le(out, (SERVER_DWORD) dwActiveProtocol); |
874 |
return rv; |
return rv; |
875 |
} |
} |
925 |
DEBUG_SCARD(("<--SUCCESS SCardDisconnect-->\n")); |
DEBUG_SCARD(("<--SUCCESS SCardDisconnect-->\n")); |
926 |
} |
} |
927 |
|
|
928 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
929 |
return rv; |
return rv; |
930 |
} |
} |
931 |
|
|
1182 |
out_uint8p(out, (void *) ((unsigned char **) cur + 2), |
out_uint8p(out, (void *) ((unsigned char **) cur + 2), |
1183 |
sizeof(SERVER_SCARD_READERSTATE_A) - 2 * sizeof(unsigned char *)); |
sizeof(SERVER_SCARD_READERSTATE_A) - 2 * sizeof(unsigned char *)); |
1184 |
} |
} |
1185 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
1186 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
1187 |
return rv; |
return rv; |
1188 |
} |
} |
1206 |
{ |
{ |
1207 |
DEBUG_SCARD(("<--SUCCESS SCardCancel-->\n")); |
DEBUG_SCARD(("<--SUCCESS SCardCancel-->\n")); |
1208 |
} |
} |
1209 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
1210 |
return rv; |
return rv; |
1211 |
} |
} |
1212 |
|
|
1311 |
sizeof(SCARD_READERSTATE_A) - 2 * sizeof(unsigned char *)); |
sizeof(SCARD_READERSTATE_A) - 2 * sizeof(unsigned char *)); |
1312 |
} |
} |
1313 |
|
|
1314 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
1315 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
1316 |
return rv; |
return rv; |
1317 |
} |
} |
1337 |
{ |
{ |
1338 |
DEBUG_SCARD(("<--SUCCESS SCardBeginTransaction-->\n")); |
DEBUG_SCARD(("<--SUCCESS SCardBeginTransaction-->\n")); |
1339 |
} |
} |
1340 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
1341 |
return rv; |
return rv; |
1342 |
} |
} |
1343 |
|
|
1368 |
{ |
{ |
1369 |
DEBUG_SCARD(("<--SUCCESS SCardEndTransaction-->\n")); |
DEBUG_SCARD(("<--SUCCESS SCardEndTransaction-->\n")); |
1370 |
} |
} |
1371 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
1372 |
return rv; |
return rv; |
1373 |
} |
} |
1374 |
|
|
1611 |
|
|
1612 |
outBufferFinish(out, (char *) recvBuf, cbRecvLength); |
outBufferFinish(out, (char *) recvBuf, cbRecvLength); |
1613 |
} |
} |
1614 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
1615 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
1616 |
return rv; |
return rv; |
1617 |
} |
} |
1727 |
out_uint32_le(out, dataLength); |
out_uint32_le(out, dataLength); |
1728 |
out->p = psave; |
out->p = psave; |
1729 |
} |
} |
1730 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
1731 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
1732 |
return rv; |
return rv; |
1733 |
} |
} |
1821 |
out_uint8p(out, atr, dwAtrLen); |
out_uint8p(out, atr, dwAtrLen); |
1822 |
outRepos(out, dwAtrLen); |
outRepos(out, dwAtrLen); |
1823 |
} |
} |
1824 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
1825 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
1826 |
return rv; |
return rv; |
1827 |
} |
} |
1874 |
outRepos(out, dwGroups); |
outRepos(out, dwGroups); |
1875 |
out_uint32_le(out, 0x00000000); |
out_uint32_le(out, 0x00000000); |
1876 |
|
|
1877 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
1878 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
1879 |
return rv; |
return rv; |
1880 |
} |
} |
1975 |
outRepos(out, dwAttrLen); |
outRepos(out, dwAttrLen); |
1976 |
out_uint32_le(out, 0x00000000); |
out_uint32_le(out, 0x00000000); |
1977 |
} |
} |
1978 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
1979 |
return rv; |
return rv; |
1980 |
} |
} |
1981 |
|
|
2028 |
out_uint32_le(out, 0x00000200); |
out_uint32_le(out, 0x00000200); |
2029 |
out_uint32_le(out, 0x00000000); |
out_uint32_le(out, 0x00000000); |
2030 |
out_uint32_le(out, 0x00000000); |
out_uint32_le(out, 0x00000000); |
2031 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
2032 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
2033 |
return rv; |
return rv; |
2034 |
} |
} |
2141 |
outRepos(out, nBytesReturned); |
outRepos(out, nBytesReturned); |
2142 |
} |
} |
2143 |
|
|
2144 |
outForceAllignment(out, 8); |
outForceAlignment(out, 8); |
2145 |
SC_xfreeallmemory(&lcHandle); |
SC_xfreeallmemory(&lcHandle); |
2146 |
return rv; |
return rv; |
2147 |
} |
} |
2490 |
size_t buffer_len = 0; |
size_t buffer_len = 0; |
2491 |
scard_device_control(data->handle, data->request, data->in, data->out); |
scard_device_control(data->handle, data->request, data->in, data->out); |
2492 |
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 |
|
2493 |
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 |
|
2494 |
SC_destroyThreadData(data); |
SC_destroyThreadData(data); |
2495 |
} |
} |
2496 |
|
|
2619 |
#endif /* MAKE_PROTO */ |
#endif /* MAKE_PROTO */ |
2620 |
|
|
2621 |
void |
void |
2622 |
scard_tcp_lock(void) |
scard_lock(int lock) |
2623 |
{ |
{ |
2624 |
if (!tcp_sendcontrol_mutex) |
if (!scard_mutex) |
2625 |
|
{ |
2626 |
|
scard_mutex = |
2627 |
|
(pthread_mutex_t **) xmalloc(sizeof(pthread_mutex_t *) * SCARD_LOCK_LAST); |
2628 |
|
} |
2629 |
|
|
2630 |
|
if (!scard_mutex[lock]) |
2631 |
{ |
{ |
2632 |
tcp_sendcontrol_mutex = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t)); |
scard_mutex[lock] = (pthread_mutex_t *) xmalloc(sizeof(pthread_mutex_t)); |
2633 |
pthread_mutex_init(tcp_sendcontrol_mutex, NULL); |
pthread_mutex_init(scard_mutex[lock], NULL); |
2634 |
} |
} |
2635 |
|
|
2636 |
pthread_mutex_lock(tcp_sendcontrol_mutex); |
pthread_mutex_lock(scard_mutex[lock]); |
2637 |
} |
} |
2638 |
|
|
2639 |
void |
void |
2640 |
scard_tcp_unlock(void) |
scard_unlock(int lock) |
2641 |
{ |
{ |
2642 |
pthread_mutex_unlock(tcp_sendcontrol_mutex); |
pthread_mutex_unlock(scard_mutex[lock]); |
2643 |
} |
} |
2644 |
|
|
2645 |
STREAM |
STREAM |