vpcd: added real thread safety
This commit is contained in:
@@ -30,12 +30,9 @@ void VpcdReader::init(wchar_t *section) {
|
||||
bool VpcdReader::CheckATR() {
|
||||
bool r = false;
|
||||
|
||||
{
|
||||
SectionLocker lock(ioSection);
|
||||
if (vicc_present((struct vicc_ctx *) ctx) == 1) {
|
||||
r = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (r) {
|
||||
@@ -53,10 +50,7 @@ bool VpcdReader::QueryTransmit(BYTE *APDU,int APDUlen,BYTE *Resp,int *Resplen) {
|
||||
bool r = false;
|
||||
|
||||
if (APDU && APDUlen && Resp && Resplen) {
|
||||
{
|
||||
SectionLocker lock(ioSection);
|
||||
rapdu_len = vicc_transmit((struct vicc_ctx *) ctx, APDUlen, APDU, &rapdu);
|
||||
}
|
||||
rapdu_len = vicc_transmit((struct vicc_ctx *) ctx, APDUlen, APDU, &rapdu);
|
||||
if (rapdu_len > 0) {
|
||||
memcpy(Resp, rapdu, rapdu_len);
|
||||
*Resplen = rapdu_len;
|
||||
@@ -76,10 +70,7 @@ bool VpcdReader::QueryATR(BYTE *ATR,DWORD *ATRsize,bool reset) {
|
||||
bool r = false;
|
||||
|
||||
if (ATR && ATRsize) {
|
||||
{
|
||||
SectionLocker lock(ioSection);
|
||||
atr_len = vicc_getatr((struct vicc_ctx *) ctx, &atr);
|
||||
}
|
||||
atr_len = vicc_getatr((struct vicc_ctx *) ctx, &atr);
|
||||
if (atr_len > 0) {
|
||||
/* TODO do length checking on length of ATR when ATRsize is
|
||||
* correctly initialized by Reader.cpp */
|
||||
@@ -87,9 +78,7 @@ bool VpcdReader::QueryATR(BYTE *ATR,DWORD *ATRsize,bool reset) {
|
||||
*ATRsize = atr_len;
|
||||
free(atr);
|
||||
r = true;
|
||||
if (reset)
|
||||
{
|
||||
SectionLocker lock(ioSection);
|
||||
if (reset) {
|
||||
vicc_reset((struct vicc_ctx *) ctx);
|
||||
}
|
||||
} else {
|
||||
@@ -102,10 +91,7 @@ bool VpcdReader::QueryATR(BYTE *ATR,DWORD *ATRsize,bool reset) {
|
||||
|
||||
DWORD VpcdReader::startServer() {
|
||||
breakSocket = false;
|
||||
{
|
||||
SectionLocker lock(ioSection);
|
||||
ctx = vicc_init(NULL, port);
|
||||
}
|
||||
ctx = vicc_init(NULL, port);
|
||||
while (!breakSocket) {
|
||||
CheckATR();
|
||||
Sleep(1000);
|
||||
@@ -117,10 +103,7 @@ void VpcdReader::shutdown() {
|
||||
breakSocket=true;
|
||||
WaitForSingleObject(serverThread,10000);
|
||||
serverThread = NULL;
|
||||
{
|
||||
SectionLocker lock(ioSection);
|
||||
vicc_exit((struct vicc_ctx *) ctx);
|
||||
}
|
||||
vicc_exit((struct vicc_ctx *) ctx);
|
||||
state=SCARD_ABSENT;
|
||||
ctx = NULL;
|
||||
if (waitRemoveIpr!=NULL) {
|
||||
|
||||
Reference in New Issue
Block a user