mirror of
https://gitlab.com/fabinfra/fabaccess/nfc.git
synced 2025-03-13 15:21:50 +01:00
76 lines
2.0 KiB
C#
76 lines
2.0 KiB
C#
|
using PCSC;
|
|||
|
using PCSC.Iso7816;
|
|||
|
using NFC.Interfaces;
|
|||
|
using NFC;
|
|||
|
using System;
|
|||
|
|
|||
|
namespace NFC_PCSC
|
|||
|
{
|
|||
|
public class Card_PCSC : ICard
|
|||
|
{
|
|||
|
private IsoReader _ISOReader;
|
|||
|
private string _ReaderID;
|
|||
|
|
|||
|
public Card_PCSC(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)
|
|||
|
{
|
|||
|
throw new NotImplementedException();
|
|||
|
return new CommandApdu(ConvertISOCase(apdu_cmd.Case), SCardProtocol.Any)
|
|||
|
{
|
|||
|
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
public PCSC.Iso7816.IsoCase ConvertISOCase(NFC.IsoCase isoCase)
|
|||
|
{
|
|||
|
switch(isoCase)
|
|||
|
{
|
|||
|
case NFC.IsoCase.Case1:
|
|||
|
return PCSC.Iso7816.IsoCase.Case1;
|
|||
|
case NFC.IsoCase.Case2Short:
|
|||
|
return PCSC.Iso7816.IsoCase.Case2Short;
|
|||
|
case NFC.IsoCase.Case3Short:
|
|||
|
return PCSC.Iso7816.IsoCase.Case3Short;
|
|||
|
case NFC.IsoCase.Case4Short:
|
|||
|
return PCSC.Iso7816.IsoCase.Case4Short;
|
|||
|
default:
|
|||
|
throw new Exception("Unknown IsoCase");
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
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;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|