BOOL ReaderLeds(const char *szReaderName, BYTE red, BYTE green, BYTE blue)
{
  BYTE c_apdu[256];
  DWORD c_apdu_len;
  BYTE r_apdu[256];
  DWORD r_apdu_len;

  CARD_CHANNEL_T Channel = { 0 };
  BOOL rc = FALSE;  

  Channel.bSilent = TRUE;
  
  /* Try to connect to the card in the reader (if there's one) */
  if (CardConnect(szReaderName, &Channel))
  {
    /* Card connected, use the APDU method */   
    c_apdu_len = 0;
    c_apdu[c_apdu_len++] = 0xFF;
    c_apdu[c_apdu_len++] = 0xF0;
    c_apdu[c_apdu_len++] = 0x00;
    c_apdu[c_apdu_len++] = 0x00;
    c_apdu[c_apdu_len++] = 4;
    c_apdu[c_apdu_len++] = 0x1E;
    c_apdu[c_apdu_len++] = red;
    c_apdu[c_apdu_len++] = green;
    c_apdu[c_apdu_len++] = blue;
 
    r_apdu_len = sizeof(r_apdu);
    rc = CardTransmit(&Channel, c_apdu, c_apdu_len, r_apdu, &r_apdu_len);

    CardDisconnect(&Channel, SCARD_LEAVE_CARD);
  }
  
  if (!rc)
  {
    /* No card in the reader (or any other error...) try a direct connection to the reader itself */
    if (ReaderConnect(szReaderName, &Channel))
    {
      c_apdu_len = 0;
      c_apdu[c_apdu_len++] = 0x58;
      c_apdu[c_apdu_len++] = 0x1E;
      c_apdu[c_apdu_len++] = red;
      c_apdu[c_apdu_len++] = green;
      c_apdu[c_apdu_len++] = blue;

      r_apdu_len = sizeof(r_apdu);
      rc = ReaderControl(&Channel, c_apdu, c_apdu_len, r_apdu, &r_apdu_len);

      CardDisconnect(&Channel, SCARD_LEAVE_CARD);
    }
  }

  return rc;
}
Beispiel #2
0
bool CReader::Connect()
{
	if (m_poCard != NULL)
		Disconnect(DISCONNECT_LEAVE_CARD);

	m_poCard = CardConnect(m_csReader, m_poContext, NULL, m_oCardPluginLib);
	if (m_poCard != NULL)
	{
		m_oPKCS15.SetCard(m_poCard);
		if (m_oPinpad->UsePinpad())
		{
			MWLOG(LEV_DEBUG, MOD_CAL, L"Using Pinpad reader.");
			m_poCard->setPinpadHandler(m_oPinpad->getPinpadHandler(m_poCard->m_hCard));

		}
		else
			MWLOG(LEV_DEBUG, MOD_CAL, L"Using non-pinpad reader.");

		MWLOG(LEV_INFO, MOD_CAL, L" Connected to %ls card in reader %ls",
				Type2String(m_poCard->GetType()), m_wsReader.c_str());
	}

	return m_poCard != NULL;
}