2020-09-15 15:27:01 +02:00
|
|
|
|
using PCSC;
|
|
|
|
|
using PCSC.Iso7816;
|
|
|
|
|
|
|
|
|
|
namespace NFC.Readers.PCSC
|
|
|
|
|
{
|
|
|
|
|
public class Card : ICard
|
|
|
|
|
{
|
|
|
|
|
private IsoReader _ISOReader;
|
|
|
|
|
private string _ReaderID;
|
|
|
|
|
|
|
|
|
|
public Card(IsoReader isoreader, string readerID)
|
|
|
|
|
{
|
|
|
|
|
_ISOReader = isoreader;
|
|
|
|
|
_ReaderID = readerID;
|
|
|
|
|
}
|
|
|
|
|
public void Connect()
|
|
|
|
|
{
|
|
|
|
|
_ISOReader.Connect(_ReaderID, SCardShareMode.Shared, SCardProtocol.Any);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Disconnect()
|
|
|
|
|
{
|
|
|
|
|
_ISOReader.Disconnect(SCardReaderDisposition.Eject);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public APDUResponse Transmit(APDUCommand apdu_cmd)
|
|
|
|
|
{
|
|
|
|
|
Response response = _ISOReader.Transmit(Convert(apdu_cmd));
|
|
|
|
|
return Convert(response);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CommandApdu Convert(APDUCommand apdu_cmd)
|
|
|
|
|
{
|
2020-09-17 16:07:58 +02:00
|
|
|
|
CommandApdu apdu = (CommandApdu)apdu_cmd;
|
2020-09-15 15:27:01 +02:00
|
|
|
|
return apdu;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public APDUResponse Convert(Response response)
|
|
|
|
|
{
|
|
|
|
|
ResponseApdu responseApdu = response.Get(0);
|
|
|
|
|
|
|
|
|
|
APDUResponse apduResponse = new APDUResponse()
|
|
|
|
|
{
|
|
|
|
|
SW1 = responseApdu.SW1,
|
|
|
|
|
SW2 = responseApdu.SW2,
|
|
|
|
|
Body = responseApdu.GetData()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return apduResponse;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|