Exemple #1
0
 internal VendorAttributes(SmartcardReader sr) {
     int ret, length = NativeMethods.SCARD_AUTOALLOCATE;
     IntPtr result;
     uint resultDWord;
     // get the serial number
     ret = NativeMethods.SCardGetAttrib(sr.Card, NativeMethods.SCARD_ATTR_VENDOR_IFD_SERIAL_NO, out result, ref length);
     if (ret == NativeMethods.SCARD_S_SUCCESS) {
         m_SerialNumber = Marshal.PtrToStringAnsi(result, length);
         NativeMethods.SCardFreeMemory(sr.Context, result);
     }
     // get the device type
     length = NativeMethods.SCARD_AUTOALLOCATE;
     ret = NativeMethods.SCardGetAttrib(sr.Card, NativeMethods.SCARD_ATTR_VENDOR_IFD_TYPE, out result, ref length);
     if (ret == NativeMethods.SCARD_S_SUCCESS) {
         m_DeviceType = Marshal.PtrToStringAnsi(result, length);
         NativeMethods.SCardFreeMemory(sr.Context, result);
     }
     // get the vendor name
     length = NativeMethods.SCARD_AUTOALLOCATE;
     ret = NativeMethods.SCardGetAttrib(sr.Card, NativeMethods.SCARD_ATTR_VENDOR_NAME, out result, ref length);
     if (ret == NativeMethods.SCARD_S_SUCCESS) {
         m_VendorName = Marshal.PtrToStringAnsi(result, length);
         NativeMethods.SCardFreeMemory(sr.Context, result);
     }
     // get the device version
     length = 4;
     ret = NativeMethods.SCardGetAttrib(sr.Card, NativeMethods.SCARD_ATTR_VENDOR_IFD_VERSION, out resultDWord, ref length);
     if (ret == NativeMethods.SCARD_S_SUCCESS) {
         m_DeviceVersion = new Version((int)(resultDWord >> 24), (int)((resultDWord >> 16) & 0xFF), (int)(resultDWord & 0xFFFF));
     }
 }
 /// <summary>
 /// Opens a SmartcardReader.
 /// </summary>
 /// <returns>An instance of the SmartcardReader class -or- a null reference if no smartcard reader was found.</returns>
 /// <exception cref="SmartcardException">An error occurred while communication with the smartcard reader.</exception>
 public static SmartcardReader OpenReader()
 {
     string[] readers = SmartcardReader.GetReaders();
     if (readers.Length == 0)
     {
         return(null);
     }
     return(new SmartcardReader(readers[0]));
 }
        /// <summary>
        /// Opens a SmartcardReader that has a card inserted with a specified ATR.
        /// </summary>
        /// <param name="atr">The ATR to search for.</param>
        /// <returns>An instance of the SmartcardReader class -or- a null reference if no smartcard reader was found.</returns>
        /// <exception cref="ArgumentNullException"><i>atr</i> is a null reference.</exception>
        /// <exception cref="SmartcardException">An error occurred while communication with the smartcard reader.</exception>
        public static SmartcardReader OpenReader(Atr atr)
        {
            if (atr == null)
            {
                throw new ArgumentNullException("atr", ResourceController.GetString("Error_ParamNull"));
            }
            string[]        readers = SmartcardReader.GetReaders();
            SmartcardReader sr      = null;

            foreach (string reader in readers)
            {
                sr = new SmartcardReader(reader);
                sr.Connect();
                if (atr.IsMatch(sr.Atr.GetValue()))
                {
                    break;
                }
                sr.Dispose();
                sr = null;
            }
            return(sr);
        }
        internal VendorAttributes(SmartcardReader sr)
        {
            int    ret, length = NativeMethods.SCARD_AUTOALLOCATE;
            IntPtr result;
            uint   resultDWord;

            // get the serial number
            ret = NativeMethods.SCardGetAttrib(sr.Card, NativeMethods.SCARD_ATTR_VENDOR_IFD_SERIAL_NO, out result, ref length);
            if (ret == NativeMethods.SCARD_S_SUCCESS)
            {
                m_SerialNumber = Marshal.PtrToStringAnsi(result, length);
                NativeMethods.SCardFreeMemory(sr.Context, result);
            }
            // get the device type
            length = NativeMethods.SCARD_AUTOALLOCATE;
            ret    = NativeMethods.SCardGetAttrib(sr.Card, NativeMethods.SCARD_ATTR_VENDOR_IFD_TYPE, out result, ref length);
            if (ret == NativeMethods.SCARD_S_SUCCESS)
            {
                m_DeviceType = Marshal.PtrToStringAnsi(result, length);
                NativeMethods.SCardFreeMemory(sr.Context, result);
            }
            // get the vendor name
            length = NativeMethods.SCARD_AUTOALLOCATE;
            ret    = NativeMethods.SCardGetAttrib(sr.Card, NativeMethods.SCARD_ATTR_VENDOR_NAME, out result, ref length);
            if (ret == NativeMethods.SCARD_S_SUCCESS)
            {
                m_VendorName = Marshal.PtrToStringAnsi(result, length);
                NativeMethods.SCardFreeMemory(sr.Context, result);
            }
            // get the device version
            length = 4;
            ret    = NativeMethods.SCardGetAttrib(sr.Card, NativeMethods.SCARD_ATTR_VENDOR_IFD_VERSION, out resultDWord, ref length);
            if (ret == NativeMethods.SCARD_S_SUCCESS)
            {
                m_DeviceVersion = new Version((int)(resultDWord >> 24), (int)((resultDWord >> 16) & 0xFF), (int)(resultDWord & 0xFFFF));
            }
        }
Exemple #5
0
 /// <summary>
 /// Opens a SmartcardReader that has a card inserted with a specified ATR.
 /// </summary>
 /// <param name="atr">The ATR to search for.</param>
 /// <returns>An instance of the SmartcardReader class -or- a null reference if no smartcard reader was found.</returns>
 /// <exception cref="ArgumentNullException"><i>atr</i> is a null reference.</exception>
 /// <exception cref="SmartcardException">An error occurred while communication with the smartcard reader.</exception>
 public static SmartcardReader OpenReader(Atr atr) {
     if (atr == null)
         throw new ArgumentNullException("atr", ResourceController.GetString("Error_ParamNull"));
     string[] readers = SmartcardReader.GetReaders();
     SmartcardReader sr = null;
     foreach(string reader in readers) {
         sr = new SmartcardReader(reader);
         sr.Connect();
         if (atr.IsMatch(sr.Atr.GetValue()))
             break;
         sr.Dispose();
         sr = null;
     }
     return sr;
 }