Exemplo n.º 1
0
static void getStatusChange(SCARDCONTEXT ctx, const char *readerList, DWORD timeout)
{
	SCARD_READERSTATEA readerStates[MAX_READER_STATES];
	int                readerCount = 0;

	while (readerList[0] != '\0' && readerCount < MAX_READER_STATES)
	{
		readerStates[readerCount].szReader       = readerList;
		readerStates[readerCount].dwCurrentState = SCARD_STATE_UNAWARE;

		readerList += strlen(readerList) + 1;
		readerCount++;
	}

	if (timeout == (DWORD) -1)
	{
		timeout = INFINITE;
		printf("Remove insert card(s) (or not) and hit ENTER\n");
		printf("Or type 'q' stop\n\n");
	}
	else
		printf("Remove insert card(s) or type Ctrl-C to stop\n\n");


	char keybd = 0;
	while (keybd != 'q' && keybd != 'Q')
	{
		long ret = SCardGetStatusChangeA(ctx, timeout, readerStates, (DWORD) readerCount);
		if ((long) SCARD_S_SUCCESS != ret && (long) SCARD_E_TIMEOUT != ret)
		{
			CHECK_PCSC_RET("SCardGetStatusChange", ret);
			break;
		}

		if ((long) SCARD_E_TIMEOUT == ret)
			printf(" - timeout (nothing changed)\n");
		else
		{
			for (int i = 0; i < readerCount; i++)
			{
				printState(&readerStates[i]);
				readerStates[i].dwCurrentState = readerStates[i].dwEventState &
												 ~SCARD_STATE_CHANGED & ~SCARD_STATE_UNKNOWN;
			}
		}

		// Wait until the user hits a key
		if (timeout != (DWORD) -1)
			keybd = getchar();
	}
}
Exemplo n.º 2
0
static UINT32 smartcard_GetStatusChangeA_Call(SMARTCARD_DEVICE* smartcard, SMARTCARD_OPERATION* operation, GetStatusChangeA_Call* call)
{
	LONG status;
	UINT32 index;
	GetStatusChange_Return ret;
	LPSCARD_READERSTATEA rgReaderState = NULL;
	IRP* irp = operation->irp;

	status = ret.ReturnCode = SCardGetStatusChangeA(operation->hContext, call->dwTimeOut, call->rgReaderStates, call->cReaders);

	if (status && (status != SCARD_E_TIMEOUT) && (status != SCARD_E_CANCELLED))
		return status;

	ret.cReaders = call->cReaders;
	ret.rgReaderStates = (ReaderState_Return*) calloc(ret.cReaders, sizeof(ReaderState_Return));

	for (index = 0; index < ret.cReaders; index++)
	{
		ret.rgReaderStates[index].dwCurrentState = call->rgReaderStates[index].dwCurrentState;
		ret.rgReaderStates[index].dwEventState = call->rgReaderStates[index].dwEventState;
		ret.rgReaderStates[index].cbAtr = call->rgReaderStates[index].cbAtr;
		CopyMemory(&(ret.rgReaderStates[index].rgbAtr), &(call->rgReaderStates[index].rgbAtr), 32);
	}

	smartcard_trace_get_status_change_return(smartcard, &ret, FALSE);

	status = smartcard_pack_get_status_change_return(smartcard, irp->output, &ret);

	if (status)
		return status;

	if (call->rgReaderStates)
	{
		for (index = 0; index < call->cReaders; index++)
		{
			rgReaderState = &call->rgReaderStates[index];

			if (rgReaderState->szReader)
				free((void*) rgReaderState->szReader);
		}
		free(call->rgReaderStates);
	}

	free(ret.rgReaderStates);

	return ret.ReturnCode;
}