public PcscSmartCardConnectionInformation(IntPtr readerHandle, SCardApi scardApi) { this.CurrentBlockWaitingTime = PcscSmartCardConnectionInformation.ToUInt32(scardApi.GetAttribute(readerHandle, SCardAttributes.CurrentBWT)); this.CurrentCharacterWaitingTime = PcscSmartCardConnectionInformation.ToUInt32(scardApi.GetAttribute(readerHandle, SCardAttributes.CurrentBWT)); this.CurrentClockRate = PcscSmartCardConnectionInformation.ToUInt32(scardApi.GetAttribute(readerHandle, SCardAttributes.CurrentClock)); this.CurrentD = PcscSmartCardConnectionInformation.ToUInt32(scardApi.GetAttribute(readerHandle, SCardAttributes.CurrentD)); this.CurrentEbcEncoding = PcscSmartCardConnectionInformation.ToEcbEncoding(scardApi.GetAttribute(readerHandle, SCardAttributes.CurrentEBCEncoding)); this.CurrentF = PcscSmartCardConnectionInformation.ToUInt32(scardApi.GetAttribute(readerHandle, SCardAttributes.CurrentF)); this.CurrentN = PcscSmartCardConnectionInformation.ToUInt32(scardApi.GetAttribute(readerHandle, SCardAttributes.CurrentN)); this.CurrentW = PcscSmartCardConnectionInformation.ToUInt32(scardApi.GetAttribute(readerHandle, SCardAttributes.CurrentW)); }
private void SetConnectionInformation(PcscCardReaderConnectionInformation readerInformation, PcscSmartCardConnectionInformation cardInformation) { this.SetAndInvoke(nameof(PcscCardReader.ReaderConnectionInformation), ref this.readerConnectionInformation, readerInformation); this.SetAndInvoke(nameof(PcscCardReader.CardConnectionInformation), ref this.cardConnectionInformation, cardInformation); }
public override void UpdateConnectionInformation() { IntPtr CardHandle; PcscCardReaderConnectionInformation ReaderInformation; PcscSmartCardConnectionInformation CardInformation; switch (this.State) { case Facades.SmartCard.CardReaderState.Unknown: //Unknown state, better not connect... throw new CardReaderUnavailableException(this); case Facades.SmartCard.CardReaderState.NoCard: case Facades.SmartCard.CardReaderState.CardMute: //No card or inaccessible card. Try to connect to reader in raw mode. CardHandle = this.scardApi.Connect(this.Name, SCardShareMode.Direct, SCardProtocol.None); ReaderInformation = new PcscCardReaderConnectionInformation(CardHandle, this.scardApi); CardInformation = null; this.scardApi.Disconnect(CardHandle, SCardDisposition.Leave); break; case Facades.SmartCard.CardReaderState.CardPresent: case Facades.SmartCard.CardReaderState.CardInUse: //card is inserted but not exclusively used. Connect card possible (or just read info if already connected) if (this.CardHandle != IntPtr.Zero) { ReaderInformation = new PcscCardReaderConnectionInformation(this.CardHandle, this.scardApi); CardInformation = new PcscSmartCardConnectionInformation(this.CardHandle, this.scardApi); } else { try { CardHandle = this.scardApi.Connect(this.Name, SCardShareMode.Shared, SCardProtocol.All); ReaderInformation = new PcscCardReaderConnectionInformation(CardHandle, this.scardApi); CardInformation = new PcscSmartCardConnectionInformation(CardHandle, this.scardApi); this.scardApi.Disconnect(CardHandle, SCardDisposition.Leave); } catch (Exception) { throw new CardReaderUnavailableException(this); } } break; case Facades.SmartCard.CardReaderState.CardExclusivelyInUse: //Possible, if we are connected, but not, if another app is connected if (this.CardHandle != IntPtr.Zero) { ReaderInformation = new PcscCardReaderConnectionInformation(this.CardHandle, this.scardApi); CardInformation = new PcscSmartCardConnectionInformation(this.CardHandle, this.scardApi); } else { throw new CardReaderUnavailableException(this); } break; default: throw new ArgumentOutOfRangeException(); } this.pcscSubsystem.UpdateReaderStates(); this.SetConnectionInformation(ReaderInformation, CardInformation); }