public SCardError Transmit(IntPtr hCard, IntPtr pioSendPci, byte[] pbSendBuffer, int pcbSendLength, IntPtr pioRecvPci, byte[] pbRecvBuffer, ref int pcbRecvLength) { var recvlen = IntPtr.Zero; if (pbRecvBuffer != null) { if (pcbRecvLength > pbRecvBuffer.Length || pcbRecvLength < 0) { throw new ArgumentOutOfRangeException(nameof(pcbRecvLength)); } recvlen = (IntPtr)pcbRecvLength; } else { if (pcbRecvLength != 0) { throw new ArgumentOutOfRangeException(nameof(pcbRecvLength)); } } var sendbuflen = IntPtr.Zero; if (pbSendBuffer != null) { if (pcbSendLength > pbSendBuffer.Length || pcbSendLength < 0) { throw new ArgumentOutOfRangeException(nameof(pcbSendLength)); } sendbuflen = (IntPtr)pcbSendLength; } else { if (pcbSendLength != 0) { throw new ArgumentOutOfRangeException(nameof(pcbSendLength)); } } var rc = SCardHelper.ToSCardError(SCardTransmit( hCard, pioSendPci, pbSendBuffer, sendbuflen, pioRecvPci, pbRecvBuffer, ref recvlen)); pcbRecvLength = (int)recvlen; return(rc); }
public SCardError Reconnect(IntPtr hCard, SCardShareMode dwShareMode, SCardProtocol dwPreferredProtocols, SCardReaderDisposition dwInitialization, out SCardProtocol pdwActiveProtocol) { int activeproto; var result = SCardReconnect( hCard, (int)dwShareMode, (int)dwPreferredProtocols, (int)dwInitialization, out activeproto); pdwActiveProtocol = (SCardProtocol)activeproto; return(SCardHelper.ToSCardError(result)); }
public SCardError EstablishContext(SCardScope dwScope, IntPtr pvReserved1, IntPtr pvReserved2, out IntPtr phContext) { var ctx = IntPtr.Zero; var rc = SCardHelper.ToSCardError( SCardEstablishContext( (int)dwScope, pvReserved1, pvReserved2, ref ctx)); phContext = ctx; return(rc); }
public SCardError EstablishContext(SCardScope dwScope, IntPtr pvReserved1, IntPtr pvReserved2, out IntPtr phContext) { var ctx = 0; var rc = SCardHelper.ToSCardError(MacOsxNativeMethods.SCardEstablishContext( (int)dwScope, pvReserved1, pvReserved2, ref ctx)); phContext = (IntPtr)ctx; return(rc); }
public SCardError ListReaders( IntPtr hContext, string[] Groups, out string[] Readers) { IntPtr ctx = (IntPtr)hContext; Int32 dwReaders = 0; SCardError rc; // initialize groups array byte[] mszGroups = null; if (Groups != null) { mszGroups = SCardHelper._ConvertToByteArray(Groups, textEncoding); } // determine the needed buffer size rc = SCardHelper.ToSCardError( SCardListReaders(ctx, mszGroups, null, ref dwReaders)); if (rc != SCardError.Success) { Readers = null; return(rc); } // initialize array byte[] mszReaders = new byte[(int)dwReaders * sizeof(char)]; rc = SCardHelper.ToSCardError( SCardListReaders(ctx, mszGroups, mszReaders, ref dwReaders)); if (rc == SCardError.Success) { Readers = SCardHelper._ConvertToStringArray(mszReaders, textEncoding); } else { Readers = null; } return(rc); }
public SCardError Connect(IntPtr hContext, string szReader, SCardShareMode dwShareMode, SCardProtocol dwPreferredProtocols, out IntPtr phCard, out SCardProtocol pdwActiveProtocol) { var readername = SCardHelper.ConvertToByteArray(szReader, TextEncoding, Platform.Lib.CharSize); var result = SCardConnect(hContext, readername, (int)dwShareMode, (int)dwPreferredProtocols, out phCard, out var activeproto); pdwActiveProtocol = (SCardProtocol)activeproto; return(SCardHelper.ToSCardError(result)); }
public SCardError GetAttrib(IntPtr hCard, IntPtr dwAttrId, byte[] pbAttr, out int pcbAttrLen) { var attrlen = (pbAttr != null) ? (IntPtr)pbAttr.Length : IntPtr.Zero; var rc = SCardHelper.ToSCardError(SCardGetAttrib( hCard, dwAttrId, pbAttr, ref attrlen)); pcbAttrLen = (int)attrlen; return(rc); }
public SCardError GetAttrib(IntPtr hCard, IntPtr dwAttrId, byte[] pbAttr, out int pcbAttrLen) { var attrlen = (pbAttr != null) ? pbAttr.Length : 0; var rc = SCardHelper.ToSCardError(SCardGetAttrib( hCard, unchecked ((int)dwAttrId.ToInt64()), // On a 64-bit platform IntPtr.ToInt32() will throw an OverflowException pbAttr, ref attrlen)); pcbAttrLen = attrlen; return(rc); }
public SCardError EstablishContext( SCardScope dwScope, IntPtr pvReserved1, IntPtr pvReserved2, ref IntPtr phContext) { IntPtr ctx = IntPtr.Zero; SCardError rc = SCardHelper.ToSCardError(SCardEstablishContext( (IntPtr)dwScope, (IntPtr)pvReserved1, (IntPtr)pvReserved2, ref ctx)); phContext = (IntPtr)ctx; return(rc); }
public SCardError GetStatusChange( IntPtr hContext, IntPtr dwTimeout, SCardReaderState[] rgReaderStates) { SCARD_READERSTATE[] readerstates = null; int cReaders = 0; if (rgReaderStates != null) { cReaders = rgReaderStates.Length; readerstates = new SCARD_READERSTATE[cReaders]; for (int i = 0; i < cReaders; i++) { readerstates[i] = rgReaderStates[i].winscard_rstate; } } SCardError rc; // On a 64-bit platforms .ToInt32() will throw an OverflowException Int32 timeout = unchecked ((Int32)dwTimeout.ToInt64()); rc = SCardHelper.ToSCardError( SCardGetStatusChange( (IntPtr)hContext, (Int32)timeout, readerstates, (Int32)cReaders)); if (rc == SCardError.Success) { if (rgReaderStates != null) { for (int i = 0; i < cReaders; i++) { /* replace with returned values */ rgReaderStates[i].winscard_rstate = readerstates[i]; } } } return(rc); }
public SCardError ListReaders(IntPtr hContext, string[] groups, out string[] readers) { var dwReaders = 0; // initialize groups array byte[] mszGroups = null; if (groups != null) { mszGroups = SCardHelper.ConvertToByteArray(groups, TextEncoding); } // determine the needed buffer size var ctx = hContext.ToInt32(); var rc = SCardHelper.ToSCardError( MacOsxNativeMethods.SCardListReaders( ctx, mszGroups, null, ref dwReaders)); if (rc != SCardError.Success) { readers = null; return(rc); } // initialize array for returning reader names var mszReaders = new byte[(int)dwReaders]; rc = SCardHelper.ToSCardError( MacOsxNativeMethods.SCardListReaders( ctx, mszGroups, mszReaders, ref dwReaders)); readers = (rc == SCardError.Success) ? SCardHelper.ConvertToStringArray(mszReaders, TextEncoding) : null; return(rc); }
public SCardError ListReaderGroups( IntPtr hContext, out string[] Groups) { IntPtr ctx = (IntPtr)hContext; IntPtr dwGroups = IntPtr.Zero; SCardError rc; // determine the needed buffer size rc = SCardHelper.ToSCardError( SCardListReaderGroups( ctx, null, ref dwGroups)); if (rc != SCardError.Success) { Groups = null; return(rc); } // initialize array byte[] mszGroups = new byte[(int)dwGroups]; rc = SCardHelper.ToSCardError( SCardListReaderGroups( ctx, mszGroups, ref dwGroups)); if (rc == SCardError.Success) { Groups = SCardHelper._ConvertToStringArray(mszGroups, textEncoding); } else { Groups = null; } return(rc); }
public SCardError GetAttrib(IntPtr hCard, IntPtr attributeId, byte[] receiveBuffer, int receiveBufferLength, out int attributeLength) { if (receiveBuffer == null && receiveBufferLength != 0) { throw new ArgumentOutOfRangeException(nameof(receiveBufferLength)); } if (receiveBuffer != null && (receiveBufferLength < 0 || receiveBufferLength > receiveBuffer.Length)) { throw new ArgumentOutOfRangeException(nameof(receiveBufferLength)); } attributeLength = receiveBufferLength; var rc = SCardHelper.ToSCardError(SCardGetAttrib( hCard, unchecked ((int)attributeId .ToInt64()), // On a 64-bit platform IntPtr.ToInt32() will throw an OverflowException receiveBuffer, ref attributeLength)); return(rc); }
public SCardError ListReaders(IntPtr hContext, string[] groups, out string[] readers) { var dwReaders = 0; // initialize groups array byte[] mszGroups = null; if (groups != null) { mszGroups = SCardHelper.ConvertToByteArray(groups, TextEncoding); } // determine the needed buffer size var rc = SCardHelper.ToSCardError( SCardListReaders(hContext, mszGroups, null, ref dwReaders)); if (rc != SCardError.Success) { readers = null; return(rc); } // initialize array var mszReaders = new byte[dwReaders * sizeof(char)]; rc = SCardHelper.ToSCardError( SCardListReaders(hContext, mszGroups, mszReaders, ref dwReaders)); readers = (rc == SCardError.Success) ? SCardHelper.ConvertToStringArray(mszReaders, TextEncoding) : null; return(rc); }
public SCardError GetAttrib( IntPtr hCard, IntPtr dwAttrId, byte[] pbAttr, out int pcbAttrLen) { IntPtr attrlen = IntPtr.Zero; if (pbAttr != null) { attrlen = (IntPtr)pbAttr.Length; } SCardError rc = SCardHelper.ToSCardError(SCardGetAttrib( (IntPtr)hCard, (IntPtr)dwAttrId, pbAttr, ref attrlen)); pcbAttrLen = (int)attrlen; return(rc); }
public SCardError SetAttrib(IntPtr hCard, IntPtr dwAttrId, byte[] pbAttr, int attrSize) { // On a 64-bit platforms IntPtr.ToInt32() will throw an OverflowException var attrid = unchecked ((int)dwAttrId.ToInt64()); var cbAttrLen = 0; if (pbAttr != null) { if (attrSize > pbAttr.Length || attrSize < 0) { throw new ArgumentOutOfRangeException(nameof(attrSize)); } cbAttrLen = attrSize; } return(SCardHelper.ToSCardError( SCardSetAttrib( hCard, attrid, pbAttr, cbAttrLen))); }
public SCardError GetStatusChange( IntPtr hContext, IntPtr dwTimeout, SCardReaderState[] rgReaderStates) { SCARD_READERSTATE[] readerstates = null; int cReaders = 0; if (rgReaderStates != null) { cReaders = rgReaderStates.Length; readerstates = new SCARD_READERSTATE[cReaders]; for (int i = 0; i < cReaders; i++) { readerstates[i] = rgReaderStates[i].pcsclite_rstate; } } IntPtr retval = SCardGetStatusChange( (IntPtr)hContext, (IntPtr)dwTimeout, readerstates, (IntPtr)cReaders); SCardError rc = SCardHelper.ToSCardError(retval); if (rc == SCardError.Success) { if (rgReaderStates != null) { for (int i = 0; i < cReaders; i++) { /* replace with returned values */ rgReaderStates[i].pcsclite_rstate = readerstates[i]; } } } return(rc); }
public SCardError GetStatusChange(IntPtr hContext, IntPtr dwTimeout, SCardReaderState[] rgReaderStates) { SCARD_READERSTATE[] readerstates = null; var cReaders = 0; if (rgReaderStates != null) { // copy the last known state into the buffer cReaders = rgReaderStates.Length; readerstates = new SCARD_READERSTATE[cReaders]; for (var i = 0; i < cReaders; i++) { readerstates[i] = rgReaderStates[i].WindowsReaderState; } } // On a 64-bit platforms .ToInt32() will throw an OverflowException var timeout = unchecked ((int)dwTimeout.ToInt64()); var rc = SCardHelper.ToSCardError( SCardGetStatusChange( hContext, timeout, readerstates, cReaders)); if (rc != SCardError.Success || rgReaderStates == null) { return(rc); } for (var i = 0; i < cReaders; i++) { // replace with returned values rgReaderStates[i].WindowsReaderState = readerstates[i]; } return(rc); }
public SCardError SetAttrib(IntPtr hCard, IntPtr attributeId, byte[] sendBuffer, int sendBufferLength) { // On a 64-bit platforms IntPtr.ToInt32() will throw an OverflowException var attrid = unchecked ((int)attributeId.ToInt64()); var cbAttrLen = 0; if (sendBuffer != null) { if (sendBufferLength > sendBuffer.Length || sendBufferLength < 0) { throw new ArgumentOutOfRangeException(nameof(sendBufferLength)); } cbAttrLen = sendBufferLength; } return(SCardHelper.ToSCardError( SCardSetAttrib( hCard, attrid, sendBuffer, cbAttrLen))); }
public SCardError GetAttrib( IntPtr hCard, IntPtr dwAttrId, byte[] pbAttr, out int pcbAttrLen) { Int32 attrlen = 0; if (pbAttr != null) { attrlen = (Int32)pbAttr.Length; } SCardError rc = SCardHelper.ToSCardError(SCardGetAttrib( (IntPtr)hCard, // On a 64-bit platform IntPtr.ToInt32() will throw an OverflowException unchecked ((Int32)dwAttrId.ToInt64()), pbAttr, ref attrlen)); pcbAttrLen = (int)attrlen; return(rc); }
public SCardError GetAttrib(IntPtr hCard, IntPtr attributeId, byte[] receiveBuffer, int receiveBufferLength, out int attributeLength) { if (receiveBuffer == null && receiveBufferLength != 0) { throw new ArgumentOutOfRangeException(nameof(receiveBufferLength)); } if (receiveBuffer != null && (receiveBufferLength < 0 || receiveBufferLength > receiveBuffer.Length)) { throw new ArgumentOutOfRangeException(nameof(receiveBufferLength)); } var attrlen = (IntPtr)receiveBufferLength; var rc = SCardHelper.ToSCardError(UnixNativeMethods.SCardGetAttrib( hCard, attributeId, receiveBuffer, ref attrlen)); attributeLength = (int)attrlen; return(rc); }
public SCardError Control( IntPtr hCard, IntPtr dwControlCode, byte[] pbSendBuffer, byte[] pbRecvBuffer, out int lpBytesReturned) { Int32 sendbuflen = 0; if (pbSendBuffer != null) { sendbuflen = (Int32)pbSendBuffer.Length; } Int32 recvbuflen = 0; if (pbRecvBuffer != null) { recvbuflen = (Int32)pbRecvBuffer.Length; } Int32 bytesret; SCardError rc = SCardHelper.ToSCardError(SCardControl( (IntPtr)hCard, // On a 64-bit platform IntPtr.ToInt32() will throw an OverflowException unchecked ((Int32)dwControlCode.ToInt64()), pbSendBuffer, sendbuflen, pbRecvBuffer, recvbuflen, out bytesret)); lpBytesReturned = (int)bytesret; return(rc); }
public SCardError Control( IntPtr hCard, IntPtr dwControlCode, byte[] pbSendBuffer, byte[] pbRecvBuffer, out int lpBytesReturned) { IntPtr sendbuflen = IntPtr.Zero; if (pbSendBuffer != null) { sendbuflen = (IntPtr)pbSendBuffer.Length; } IntPtr recvbuflen = IntPtr.Zero; if (pbRecvBuffer != null) { recvbuflen = (IntPtr)pbRecvBuffer.Length; } IntPtr bytesret; SCardError rc = SCardHelper.ToSCardError(SCardControl( (IntPtr)hCard, (IntPtr)dwControlCode, pbSendBuffer, sendbuflen, pbRecvBuffer, recvbuflen, out bytesret)); lpBytesReturned = (int)bytesret; return(rc); }
public SCardError GetStatusChange(IntPtr hContext, IntPtr dwTimeout, SCardReaderState[] rgReaderStates) { SCARD_READERSTATE[] readerstates = null; var cReaders = 0; if (rgReaderStates != null) { // copy the last known state into the buffer cReaders = rgReaderStates.Length; readerstates = new SCARD_READERSTATE[cReaders]; for (var i = 0; i < cReaders; i++) { readerstates[i] = rgReaderStates[i].MacOsXReaderState; } } var timeout = unchecked ((int)dwTimeout.ToInt64()); var rc = SCardHelper.ToSCardError(MacOsxNativeMethods.SCardGetStatusChange( hContext.ToInt32(), timeout, readerstates, cReaders)); if (rc != SCardError.Success || rgReaderStates == null) { return(rc); } for (var i = 0; i < cReaders; i++) { // replace with returned values rgReaderStates[i].MacOsXReaderState = readerstates[i]; } return(rc); }
public SCardError Control(IntPtr hCard, IntPtr dwControlCode, byte[] pbSendBuffer, int sendBufferLength, byte[] pbRecvBuffer, int recvBufferLength, out int lpBytesReturned) { if (pbSendBuffer == null && sendBufferLength > 0) { throw new ArgumentException("send buffer is null", nameof(sendBufferLength)); } if ((pbSendBuffer != null && pbSendBuffer.Length < sendBufferLength) || sendBufferLength < 0) { throw new ArgumentOutOfRangeException(nameof(sendBufferLength)); } if (pbRecvBuffer == null && recvBufferLength > 0) { throw new ArgumentException("receive buffer is null", nameof(recvBufferLength)); } if ((pbRecvBuffer != null && pbRecvBuffer.Length < recvBufferLength) || recvBufferLength < 0) { throw new ArgumentOutOfRangeException(nameof(recvBufferLength)); } // On a 64-bit platform IntPtr.ToInt32() will throw an OverflowException var controlCode = unchecked ((int)dwControlCode.ToInt64()); return(SCardHelper.ToSCardError(SCardControl( hCard, controlCode, pbSendBuffer, sendBufferLength, pbRecvBuffer, recvBufferLength, out lpBytesReturned))); }
public SCardError EndTransaction(IntPtr hCard, SCardReaderDisposition dwDisposition) { return(SCardHelper.ToSCardError(SCardEndTransaction(hCard, (int)dwDisposition))); }
public SCardError IsValidContext(IntPtr hContext) { return(SCardHelper.ToSCardError(SCardIsValidContext(hContext))); }
public SCardError ReleaseContext(IntPtr hContext) { return(SCardHelper.ToSCardError(SCardReleaseContext(hContext))); }
public SCardError Cancel(IntPtr hContext) { return(SCardHelper.ToSCardError(SCardCancel(hContext))); }
public SCardError Status(IntPtr hCard, out string[] szReaderName, out IntPtr pdwState, out IntPtr pdwProtocol, out byte[] pbAtr) { var readerName = new byte[MAX_READER_NAME * CharSize]; var readerNameSize = MAX_READER_NAME; pbAtr = new byte[MAX_ATR_SIZE]; var atrlen = pbAtr.Length; int state, proto; var rc = SCardHelper.ToSCardError(SCardStatus( hCard, readerName, ref readerNameSize, out state, out proto, pbAtr, ref atrlen)); if (rc == SCardError.InsufficientBuffer || (MAX_READER_NAME < readerNameSize) || (pbAtr.Length < atrlen)) { // second try if (MAX_READER_NAME < readerNameSize) { // readername byte array was too short readerName = new byte[readerNameSize * CharSize]; } if (pbAtr.Length < atrlen) { // ATR byte array was too short pbAtr = new byte[atrlen]; } rc = SCardHelper.ToSCardError(SCardStatus( hCard, readerName, ref readerNameSize, out state, out proto, pbAtr, ref atrlen)); } pdwProtocol = (IntPtr)proto; if (rc == SCardError.Success) { pdwState = (IntPtr)state.ConvertToSCardState(); if (atrlen < pbAtr.Length) { Array.Resize(ref pbAtr, atrlen); } if (readerNameSize < (readerName.Length / CharSize)) { Array.Resize(ref readerName, readerNameSize * CharSize); } szReaderName = SCardHelper.ConvertToStringArray(readerName, TextEncoding); } else { pdwState = (IntPtr)SCardState.Unknown; szReaderName = null; } return(rc); }