コード例 #1
0
ファイル: ifdwrapper.c プロジェクト: 12019/SmartCardServices
/**
 * Close a communication channel to the IFD.
 */
LONG IFDCloseIFD(PREADER_CONTEXT rContext)
{
	RESPONSECODE rv = IFD_SUCCESS;

#ifndef PCSCLITE_STATIC_DRIVER
	RESPONSECODE(*IO_close_channel) (void) = NULL;
	RESPONSECODE(*IFDH_close_channel) (DWORD) = NULL;

	if (rContext->dwVersion == IFD_HVERSION_1_0)
		IO_close_channel = rContext->psFunctions.psFunctions_v1.pvfCloseChannel;
	else
		IFDH_close_channel = rContext->psFunctions.psFunctions_v2.pvfCloseChannel;
#endif

	/* LOCK THIS CODE REGION */
	(void)SYS_MutexLock(rContext->mMutex);
#ifndef PCSCLITE_STATIC_DRIVER
	if (rContext->dwVersion == IFD_HVERSION_1_0)

		rv = (*IO_close_channel) ();
	else
		rv = (*IFDH_close_channel) (rContext->dwSlot);
#else
	if (rContext->dwVersion == IFD_HVERSION_1_0)
		rv = IO_Close_Channel();
	else
		rv = IFDHCloseChannel(rContext->dwSlot);
#endif

	/* END OF LOCKED REGION */
	(void)SYS_MutexUnLock(rContext->mMutex);

	return rv;
}
コード例 #2
0
ファイル: winscard.c プロジェクト: M-Yussef/vsmartcard
static void release_globals(void)
{
    uint32_t index;
    for (index = 0;
            index < PCSCLITE_MAX_READERS_CONTEXTS && index < vicc_max_slots;
            index++) {
        IFDHCloseChannel ((DWORD) index);
    }
    memset(cards, 0, sizeof cards);
}
コード例 #3
0
ファイル: spiceccid.c プロジェクト: fgouget/xf86-video-qxl
static void send_reply(smartcard_ccid_t *ccid, uint32_t code)
{
    uint32_t reply[4];

    reply[0] = htonl(VSC_Error);        // type
    reply[1] = htonl(ccid->lun);        // reader id
    reply[2] = htonl(sizeof(uint32_t)); // length
    reply[3] = htonl(code);             // Error code

    if (write(ccid->fd, (char *) reply, sizeof(reply)) != sizeof(reply)) {
        fprintf(stderr, "Error: lun %d fd %d write failed; errno %d\n", ccid->lun, ccid->fd, errno);
        IFDHCloseChannel(ccid->lun);
    }
}
コード例 #4
0
ファイル: ifdwrapper.c プロジェクト: andyvand/pcsc-lite-clone
/**
 * Close a communication channel to the IFD.
 */
LONG IFDCloseIFD(PREADER_CONTEXT rContext)
{
	RESPONSECODE rv = IFD_SUCCESS;
	int repeat;

#ifndef PCSCLITE_STATIC_DRIVER
	RESPONSECODE(*IO_close_channel) (void) = NULL;
	RESPONSECODE(*IFDH_close_channel) (DWORD) = NULL;

	if (rContext->dwVersion == IFD_HVERSION_1_0)
		IO_close_channel = rContext->psFunctions.psFunctions_v1.pvfCloseChannel;
	else
		IFDH_close_channel = rContext->psFunctions.psFunctions_v2.pvfCloseChannel;
#endif

	/* TRY TO LOCK THIS CODE REGION */
	repeat = 5;
again:
	rv = SYS_MutexTryLock(rContext->mMutex);
	if (EBUSY == rv)
	{
		Log1(PCSC_LOG_ERROR, "Locking failed");
		repeat--;
		if (repeat)
		{
			(void)SYS_USleep(100*1000);	/* 100 ms */
			goto again;
		}
	}

#ifndef PCSCLITE_STATIC_DRIVER
	if (rContext->dwVersion == IFD_HVERSION_1_0)

		rv = (*IO_close_channel) ();
	else
		rv = (*IFDH_close_channel) (rContext->dwSlot);
#else
	if (rContext->dwVersion == IFD_HVERSION_1_0)
		rv = IO_Close_Channel();
	else
		rv = IFDHCloseChannel(rContext->dwSlot);
#endif

	/* END OF LOCKED REGION */
	(void)SYS_MutexUnLock(rContext->mMutex);

	return rv;
}
コード例 #5
0
ファイル: spiceccid.c プロジェクト: fgouget/xf86-video-qxl
static void send_init(smartcard_ccid_t *ccid)
{
    uint32_t msg[6];

    msg[0] = htonl(VSC_Init);               // type
    msg[1] = htonl(ccid->lun);              // reader id
    msg[2] = htonl(sizeof(uint32_t) * 3);   // length
    msg[3] = htonl(VSCARD_MAGIC);           // VSCD
    msg[4] = htonl(VSCARD_VERSION);         // VSCD
    msg[5] = 0;                             // capabilities

    if (write(ccid->fd, (char *) msg, sizeof(msg)) != sizeof(msg)) {
        fprintf(stderr, "Error: lun %d fd %d write failed; errno %d\n", ccid->lun, ccid->fd, errno);
        IFDHCloseChannel(ccid->lun);
    }
}
コード例 #6
0
ファイル: spiceccid.c プロジェクト: fgouget/xf86-video-qxl
static int send_tx_buffer(smartcard_ccid_t *ccid, void *data, int len)
{
    uint32_t *reply, *p;
    int write_len = sizeof(*reply) * 3 + len;

    reply = malloc(write_len);
    p = reply;

    *p++ = htonl(VSC_APDU);         // type
    *p++ = htonl(ccid->lun);        // reader id
    *p++ = htonl(len);
    memcpy(p, data, len);

    if (write(ccid->fd, (char *) reply, write_len) != write_len) {
        fprintf(stderr, "Error: lun %d fd %d write failed; errno %d\n", ccid->lun, ccid->fd, errno);
        IFDHCloseChannel(ccid->lun);
        free(reply);
        return 0;
    }
    free(reply);
    return 1;
}
コード例 #7
0
ファイル: ifdwrapper.c プロジェクト: gopalmeena/RFID-DBSync-1
/**
 * Close a communication channel to the IFD.
 */
LONG IFDCloseIFD(READER_CONTEXT * rContext)
{
	RESPONSECODE rv;
	int repeat;

#ifndef PCSCLITE_STATIC_DRIVER
	RESPONSECODE(*IFDH_close_channel) (DWORD) = NULL;

	IFDH_close_channel = rContext->psFunctions.psFunctions_v2.pvfCloseChannel;
#endif

	/* TRY TO LOCK THIS CODE REGION */
	repeat = 5;
again:
	rv = pthread_mutex_trylock(rContext->mMutex);
	if (EBUSY == rv)
	{
		Log1(PCSC_LOG_ERROR, "Locking failed");
		repeat--;
		if (repeat)
		{
			(void)SYS_USleep(100*1000);	/* 100 ms */
			goto again;
		}
	}

#ifndef PCSCLITE_STATIC_DRIVER
	rv = (*IFDH_close_channel) (rContext->slot);
#else
	rv = IFDHCloseChannel(rContext->slot);
#endif

	/* END OF LOCKED REGION */
	(void)pthread_mutex_unlock(rContext->mMutex);

	return rv;
}