Beispiel #1
0
        protected void Dispose(bool disposing)
        {
            int ret = SCardDisconnect(card, dispose_disposition);

            if (ret != 0)
            {
                Console.WriteLine(SmartCardContext.ToException(ret).Message);
            }
        }
Beispiel #2
0
        public int Transmit(byte[] sendBuffer, byte[] receiveBuffer)
        {
            SmartCardIORequest sendPci = SmartCardIORequest.T1;
            SmartCardIORequest recvPci = SmartCardIORequest.T1;
            uint   len = (uint)receiveBuffer.Length;
            IntPtr ptr = Marshal.AllocHGlobal((int)len);

            try {
                int ret = SCardTransmit(card, ref sendPci, sendBuffer, (uint)sendBuffer.Length, ref recvPci, ptr, ref len);
                if (ret != 0)
                {
                    throw SmartCardContext.ToException(ret);
                }
                //Console.Write("Transmit received {0} bytes: ", len);
                Marshal.Copy(ptr, receiveBuffer, 0, (int)len);
                //Console.WriteLine(BitConverter.ToString(receiveBuffer, 0, (int)len));
                return((int)len);
            } finally {
                Marshal.FreeHGlobal(ptr);
            }
        }
Beispiel #3
0
        public SmartCardState GetStatus()
        {
            uint readerLen = 0;
            int  ret       = SCardGetStatus(card, IntPtr.Zero, ref readerLen, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);

            if (ret != 0)
            {
                throw SmartCardContext.ToException(ret);
            }
            IntPtr             readerPtr = Marshal.AllocHGlobal((int)readerLen);
            SmartCardState     state;
            SmartCardProtocols protocol;
            uint atrLen = 0;

            ret = SCardGetStatus(card, readerPtr, ref readerLen, out state, out protocol, IntPtr.Zero, out atrLen);
            if (ret != 0)
            {
                throw SmartCardContext.ToException(ret);
            }
            return(state);
        }