/// <summary>
        /// Connects to the card in the smartcard reader.
        /// </summary>
        /// <param name="share">A flag that indicates whether other applications may form connections to the card.</param>
        /// <param name="protocol">A bit mask of acceptable protocols for the connection. Possible values may be combined with the <b>OR</b> operation.</param>
        /// <exception cref="ObjectDisposedException">The SmartcardReader has been closed.</exception>
        /// <exception cref="SmartcardException">An error occurred while communication with the smartcard reader.</exception>
        public void Connect(SmartcardShare share, SmartcardProtocols protocol)
        {
            if (m_Disposed)
            {
                throw new ObjectDisposedException(this.GetType().FullName);
            }
            if (m_Card != IntPtr.Zero)
            {
                throw new SmartcardException(ResourceController.GetString("Error_SmartcardAlreadyConnected"));
            }
            int ret = NativeMethods.SCardConnect(m_Context, m_ReaderName, (int)share, (int)protocol, out m_Card, out m_ActiveProtocol);

            if (ret != NativeMethods.SCARD_S_SUCCESS)
            {
                throw new SmartcardException(ResourceController.GetString("Error_SmartcardConnect"), ret);
            }
            // make sure the user has at least the 'AllowedAtrs' option of the SmartcardPermission
            // for the current ATR
            try {
                SmartcardPermission permission = new SmartcardPermission(new Atr[] { Atr });
                permission.Demand();
            } catch {
                Dispose();
                throw;
            }
        }
        /// <summary>
        /// Reconnects to the card in the smartcard reader.
        /// </summary>
        /// <param name="share">A flag that indicates whether other applications may form connections to the card.</param>
        /// <param name="protocol">A bit mask of acceptable protocols for the connection. Possible values may be combined with the <b>OR</b> operation.</param>
        /// <param name="disposition">Type of initialization that should be performed on the card.</param>
        /// <exception cref="ObjectDisposedException">The SmartcardReader has been closed.</exception>
        /// <exception cref="SmartcardException">An error occurred while communication with the smartcard reader.</exception>
        public void Reconnect(SmartcardShare share, SmartcardProtocols protocol, SmartcardDisposition disposition)
        {
            if (m_Disposed)
            {
                throw new ObjectDisposedException(this.GetType().FullName);
            }
            if (m_Card == IntPtr.Zero)
            {
                throw new SmartcardException(ResourceController.GetString("Error_SmartcardNotConnected"));
            }
            int ret = NativeMethods.SCardReconnect(m_Card, (int)share, (int)protocol, (int)disposition, out m_ActiveProtocol);

            if (ret != NativeMethods.SCARD_S_SUCCESS)
            {
                throw new SmartcardException(ResourceController.GetString("Error_SmartcardReconnect"), ret);
            }
        }
Exemple #3
0
 /// <summary>
 /// Connects to the card in the smartcard reader.
 /// </summary>
 /// <param name="share">A flag that indicates whether other applications may form connections to the card.</param>
 /// <param name="protocol">A bit mask of acceptable protocols for the connection. Possible values may be combined with the <b>OR</b> operation.</param>
 /// <exception cref="ObjectDisposedException">The SmartcardReader has been closed.</exception>
 /// <exception cref="SmartcardException">An error occurred while communication with the smartcard reader.</exception>
 public void Connect(SmartcardShare share, SmartcardProtocols protocol) {
     if (m_Disposed)
         throw new ObjectDisposedException(this.GetType().FullName);
     if (m_Card != IntPtr.Zero)
         throw new SmartcardException(ResourceController.GetString("Error_SmartcardAlreadyConnected"));
     int ret = NativeMethods.SCardConnect(m_Context, m_ReaderName, (int)share, (int)protocol, out m_Card, out m_ActiveProtocol);
     if (ret != NativeMethods.SCARD_S_SUCCESS)
         throw new SmartcardException(ResourceController.GetString("Error_SmartcardConnect"), ret);
     // make sure the user has at least the 'AllowedAtrs' option of the SmartcardPermission
     // for the current ATR
     try {
         SmartcardPermission permission = new SmartcardPermission(new Atr[] { Atr });
         permission.Demand();
     } catch {
         Dispose();
         throw;
     }
 }
Exemple #4
0
 /// <summary>
 /// Reconnects to the card in the smartcard reader.
 /// </summary>
 /// <param name="share">A flag that indicates whether other applications may form connections to the card.</param>
 /// <param name="protocol">A bit mask of acceptable protocols for the connection. Possible values may be combined with the <b>OR</b> operation.</param>
 /// <param name="disposition">Type of initialization that should be performed on the card.</param>
 /// <exception cref="ObjectDisposedException">The SmartcardReader has been closed.</exception>
 /// <exception cref="SmartcardException">An error occurred while communication with the smartcard reader.</exception>
 public void Reconnect(SmartcardShare share, SmartcardProtocols protocol, SmartcardDisposition disposition) {
     if (m_Disposed)
         throw new ObjectDisposedException(this.GetType().FullName);
     if (m_Card == IntPtr.Zero)
         throw new SmartcardException(ResourceController.GetString("Error_SmartcardNotConnected"));
     int ret = NativeMethods.SCardReconnect(m_Card, (int)share, (int)protocol, (int)disposition, out m_ActiveProtocol);
     if (ret != NativeMethods.SCARD_S_SUCCESS)
         throw new SmartcardException(ResourceController.GetString("Error_SmartcardReconnect"), ret);
 }