Esempio n. 1
0
        public Readers(ReaderScope scope)
        {
            uint retVal;

            switch (scope)
            {
            case ReaderScope.Null:
                context = new CardContextSafeHandler(IntPtr.Zero);
                break;

            case ReaderScope.System:
                retVal = NativeMethods.SCardEstablishContext(ContextScope.SCARD_SCOPE_SYSTEM, IntPtr.Zero, IntPtr.Zero, out context);
                if (retVal != 0)
                {
                    throw new InvalidOperationException("Failed to create static context for reader: 0x" + retVal.ToString("X"));
                }
                break;

            case ReaderScope.User:
                retVal = NativeMethods.SCardEstablishContext(ContextScope.SCARD_SCOPE_USER, IntPtr.Zero, IntPtr.Zero, out context);
                if (retVal != 0)
                {
                    throw new InvalidOperationException("Failed to create static context for reader: 0x" + retVal.ToString("X"));
                }
                break;
            }

            List = new List <string>();
            UpdateList();
        }
Esempio n. 2
0
        public Readers(ReaderScope scope)
        {
            uint retVal;

            switch (scope)
            {
            case ReaderScope.Null:
                context = new CardContextSafeHandler(IntPtr.Zero);
                break;

            case ReaderScope.System:
                retVal = NativeMethods.SCardEstablishContext(ContextScope.SCARD_SCOPE_SYSTEM, IntPtr.Zero, IntPtr.Zero, out context);
                if (retVal != 0)
                {
                    throw new InvalidOperationException("Failed to create static context for reader: 0x" + retVal.ToString("X"));
                }
                break;

            case ReaderScope.User:
                retVal = NativeMethods.SCardEstablishContext(ContextScope.SCARD_SCOPE_USER, IntPtr.Zero, IntPtr.Zero, out context);
                if (retVal != 0)
                {
                    throw new InvalidOperationException("Failed to create static context for reader: 0x" + retVal.ToString("X"));
                }
                break;
            }

            int size = 0;

            //List the readers
            //todo::listen for new readers changes (via the "\\?PnP?\Notification" reader)
            char[] readers = null;
            retVal = NativeMethods.SCardListReaders(context, null, readers, ref size);
            if (retVal != 0 && retVal != 0x8010002E)
            {
                throw new InvalidOperationException("Failed to list readers (length): 0x" + retVal.ToString("X"));
            }

            if (retVal == 0x8010002E) //no readers
            {
                List = new List <string>(0);
            }
            else
            {
                readers = new char[size];
                retVal  = NativeMethods.SCardListReaders(context, null, readers, ref size);
                if (retVal != 0)
                {
                    throw new InvalidOperationException("Failed to list readers: 0x" + retVal.ToString("X"));
                }

                List = MultiString.ToStringList(readers);
            }
        }
Esempio n. 3
0
        internal EidCard(CardContextSafeHandler context, String readerName)
        {
            this.context = context;
            this.ReaderName = readerName;

            CardProtocols protocol;
            uint retVal = NativeMethods.SCardConnect(context, ReaderName, CardShareMode.SCARD_SHARE_SHARED, CardProtocols.SCARD_PROTOCOL_T0 | CardProtocols.SCARD_PROTOCOL_T1, out handler, out protocol);
            if (retVal == 0x80100069L) throw new NoCardException("Not card was found in the reader");
            if (retVal == 0x8010000BL) throw new ReaderException("The card is being accessed from a different context");
            if (retVal == 0x80100009L) throw new ReaderException("The specified reader does not exist");
            if (retVal != 0) throw new InvalidOperationException("Failed to open card reader: 0x" + retVal.ToString("X"));
        }
Esempio n. 4
0
 public Readers(ReaderScope scope)
 {
     uint retVal;
     switch (scope)
     {
         case ReaderScope.Null:
             context = new CardContextSafeHandler(IntPtr.Zero);
             break;
         case ReaderScope.System:
             retVal = NativeMethods.SCardEstablishContext(ContextScope.SCARD_SCOPE_SYSTEM, IntPtr.Zero, IntPtr.Zero, out context);
             if (retVal != 0) throw new InvalidOperationException("Failed to create static context for reader: 0x" + retVal.ToString("X"));
             break;
         case ReaderScope.User:
             retVal = NativeMethods.SCardEstablishContext(ContextScope.SCARD_SCOPE_USER, IntPtr.Zero, IntPtr.Zero, out context);
             if (retVal != 0) throw new InvalidOperationException("Failed to create static context for reader: 0x" + retVal.ToString("X"));
             break;
     }
 }
Esempio n. 5
0
 internal static extern uint SCardConnect(CardContextSafeHandler hContext, String szReader, CardShareMode dwShareMode, CardProtocols dwPreferredProtocols, out CardSafeHandler phCard, out CardProtocols pdwActiveProtocol);
Esempio n. 6
0
 internal static extern uint SCardFreeMemory(CardContextSafeHandler hContext, IntPtr pvMem);
Esempio n. 7
0
 internal Card(CardContextSafeHandler context, String readerName, byte[] atr)
 {
     this.context    = context;
     this.ReaderName = readerName;
     this.ATR        = atr;
 }
Esempio n. 8
0
 internal static extern uint SCardGetStatusChange(CardContextSafeHandler hContext, int dwTimeout, [In, Out] SCARD_READERSTATE[] rgReaderStates, int cReaders);
Esempio n. 9
0
 internal static extern uint SCardConnect(CardContextSafeHandler hContext, String szReader, CardShareMode dwShareMode, CardProtocols dwPreferredProtocols, out CardSafeHandler phCard, out CardProtocols pdwActiveProtocol);
Esempio n. 10
0
 internal static extern uint SCardLocateCards(CardContextSafeHandler hContext, [In, MarshalAs(UnmanagedType.LPArray)] Char[] mszCards, [In, Out] SCARD_READERSTATE[] rgReaderStates, int cReaders);
Esempio n. 11
0
 internal static extern uint SCardListCards(CardContextSafeHandler hContext, byte[] pbAtr, IntPtr rgguidInterfaces, int cguidInterfaceCount, [Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 5)] Char[] mszCards, [In, Out] ref int pcchCards);
Esempio n. 12
0
 internal static extern uint SCardEstablishContext([MarshalAs(UnmanagedType.U4)] ContextScope dwScope, IntPtr pvReserved1, IntPtr pvReserved2, out CardContextSafeHandler phContext);
Esempio n. 13
0
 internal static extern uint SCardListReaders(CardContextSafeHandler hContext, [In, MarshalAs(UnmanagedType.LPArray)] Char[] mszGroups, [Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] Char[] mszReaders, [In, Out] ref int pcchReaders);
Esempio n. 14
0
 internal static extern uint SCardFreeMemory(CardContextSafeHandler hContext, IntPtr pvMem);
Esempio n. 15
0
 internal static extern uint SCardEstablishContext([MarshalAs(UnmanagedType.U4)] ContextScope dwScope, IntPtr pvReserved1, IntPtr pvReserved2, out CardContextSafeHandler phContext);
Esempio n. 16
0
 internal EidCard(CardContextSafeHandler context, String readerName, byte[] atr)
     : base(context, readerName, atr)
 {
 }
Esempio n. 17
0
 internal static extern uint SCardGetStatusChange(CardContextSafeHandler hContext, int dwTimeout, [In, Out] SCARD_READERSTATE[] rgReaderStates, int cReaders);
Esempio n. 18
0
 internal static extern uint SCardLocateCards(CardContextSafeHandler hContext, [In, MarshalAs(UnmanagedType.LPArray)] Char[] mszCards, [In, Out] SCARD_READERSTATE[] rgReaderStates, int cReaders);
Esempio n. 19
0
 internal static extern uint SCardListReaders(CardContextSafeHandler hContext, [In, MarshalAs(UnmanagedType.LPArray)] Char[] mszGroups, [Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 3)] Char[] mszReaders, [In, Out] ref int pcchReaders);
Esempio n. 20
0
 internal static extern uint SCardListCards(CardContextSafeHandler hContext, byte[] pbAtr, IntPtr rgguidInterfaces, int cguidInterfaceCount, [Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 5)] Char[] mszCards, [In, Out] ref int pcchCards);