Beispiel #1
0
        private byte[] GetAnswerToReset()
        {
            int result = 0;

            byte[] readerName = null;
            uint   readerLen  = 0;
            uint   state      = 0;
            uint   protocol   = 0;

            byte[] atr    = null;
            uint   atrLen = 0;

            result = WinSCard.SCardStatus(card, readerName, ref readerLen, out state, out protocol, atr, ref atrLen);

            if (result != WinSCard.SCARD_S_SUCCESS)
            {
                throw new SmartCardException(result);
            }

            readerName = new byte[readerLen];
            atr        = new byte[atrLen];
            result     = WinSCard.SCardStatus(card, readerName, ref readerLen, out state, out protocol, atr, ref atrLen);

            if (result != WinSCard.SCARD_S_SUCCESS)
            {
                throw new SmartCardException(result);
            }

            #region Debug output
#if DEBUG
            if (outputDebugString)
            {
                StringBuilder sb = new StringBuilder();

                for (int i = 0; i < atrLen; i++)
                {
                    sb.AppendFormat("{0:X2}", atr[i]);
                }

                Debug.WriteLine(sb.ToString());
            }
#endif
            #endregion

            MultiString msReaderName = new MultiString(readerName);

            if (result != WinSCard.SCARD_S_SUCCESS)
            {
                throw new SmartCardException(result);
            }

            return(atr);
        }