Exemplo n.º 1
0
        //fin zona biometrica



        private void cbReaders_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbReaders.SelectedIndex == -1)
            {
                return;
            }

            if (reader != null)
            {
                reader.StopMonitor();
            }

            try
            {
                string readerName = this.cbReaders.GetItemText(cbReaders.SelectedItem);
                reader = new SCardReader(readerName);
                reader.StartMonitor(readerStatusChanged);
            }
            catch (Exception Ex)
            {
                MessageBox.Show("Hay un error mientras se esta creado el objeto de lectoras : " + Ex.Message);

                return;
            }
        }
Exemplo n.º 2
0
        void MainFormFormClosed(object sender, FormClosedEventArgs e)
        {
            if (reader != null)
            {
                reader.StopMonitor();
                reader = null;
            }

            Settings s = new Settings();

            s.SelectedType = cbNdefType.SelectedIndex;
            s.Save();
        }
 public void Stop()
 {
     if (_reader != null)
     {
         _reader.StopMonitor();
     }
     if (_llcp != null)
     {
         _llcp.Stop();
         _llcp = null;
     }
 }
Exemplo n.º 4
0
        private void cbReaders_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbReaders.SelectedIndex == -1)
            {
                return;
            }

            if (reader != null)
            {
                reader.StopMonitor();
            }

            try
            {
                string readerName = this.cbReaders.GetItemText(cbReaders.SelectedItem);
                reader = new SCardReader(readerName);
                reader.StartMonitor(readerStatusChanged);
            }
            catch (Exception Ex)
            {
                MessageBox.Show("There was an error while creating the reader's object : " + Ex.Message);
                return;
            }
        }
Exemplo n.º 5
0
        void MainFormClosed(object sender, FormClosedEventArgs e)
        {
            if (cardchannel != null)
            {
                cardchannel.Disconnect();
                cardchannel = null;
            }

            if (reader != null)
            {
                reader.StopMonitor();
                reader = null;
            }

            SystemConsole.Free();
        }
Exemplo n.º 6
0
        void ReaderStatusChanged(uint ReaderState, CardBuffer CardAtr)
        {
            /* The ReaderStatusChanged function is called as a delegate (callback) by the SCardReader object    */
            /* within its backgroung thread. Therefore we must use the BeginInvoke syntax to switch back from   */
            /* the context of the background thread to the context of the application's main thread. Overwise   */
            /* we'll get a security violation when trying to access the window's visual components (that belong */
            /* to the application's main thread and can't be safely manipulated by background threads).         */
            if (InvokeRequired)
            {
                this.BeginInvoke(new ReaderStatusChangedInvoker(ReaderStatusChanged), ReaderState, CardAtr);
                return;
            }

            string s = SCARD.ReaderStatusToString(ReaderState);

            Trace.WriteLine("ReaderStatusChanged: " + s);
            eReaderStatus.Text = s;

            if (CardAtr != null)
            {
                s             = CardAtr.AsString(" ");
                eCardAtr.Text = s;
                Trace.WriteLine("\t" + s);
            }
            else
            {
                eCardAtr.Text = "";
            }

            if (ReaderState == SCARD.STATE_UNAWARE)
            {
                if (llcp != null)
                {
                    llcp.Stop();
                    llcp = null;
                }

                MessageBox.Show("The reader we were working on has disappeared from the system. This application will terminate now.",
                                "The reader has been removed",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);

                Application.Exit();
            }
            else if ((ReaderState & SCARD.STATE_UNAVAILABLE) != 0)
            {
                Trace.WriteLine("Card unavailable");
            }
            else if ((ReaderState & SCARD.STATE_MUTE) != 0)
            {
                Trace.WriteLine("Card mute");
            }
            else if ((ReaderState & SCARD.STATE_INUSE) != 0)
            {
                Trace.WriteLine("Card in use");
            }
            else if ((ReaderState & SCARD.STATE_EMPTY) != 0)
            {
                Trace.WriteLine("Card absent");

                if (llcp != null)
                {
                    Trace.WriteLine("*** Target lost ***");

                    llcp.Stop();
                    llcp = null;

                    PerformStatusChange();
                }

                pControl.Enabled = true;
            }
            else if ((ReaderState & SCARD.STATE_PRESENT) != 0)
            {
                Trace.WriteLine("Card present");

                if ((llcp == null) && ((ReaderState & SCARD.STATE_INUSE) == 0))
                {
                    /* Try to work with this card, it may be a LLCP peer */
                    reader.StopMonitor();

                    pControl.Enabled = false;
                    Trace.WriteLine("*** Starting LLCP ***");

                    llcp = new LlcpInitiator(reader);

                    switch (status)
                    {
                    case Status.SendAndRecv_Ready:
                        /* We are both a receiver and a sender */
                        StartReceiver();
                        StartSender();
                        break;

                    case Status.RecvOnly_Ready:
                    case Status.RecvThenSend_RecvReady:
                    case Status.SendThenRecv_RecvReady:
                        /* We are a receiver */
                        StartReceiver();
                        break;

                    case Status.SendOnly_Ready:
                    case Status.RecvThenSend_SendReady:
                    case Status.SendThenRecv_SendReady:
                        /* We are a sender */
                        StartSender();
                        break;

                    default:
                        break;
                    }

                    if (!llcp.Start())
                    {
                        Trace.WriteLine("*** Failed to start LLCP ***");
                        MessageBox.Show("Failed to instantiate LLCP layer on the newly inserted card. This is likely to be caused by another application taking control of the card before us. Please close all other PC/SC-aware applications. It may also be required to instruct Windows to stop probing the card, see the paragraph pcsc_no_minidriver in the Readme of the PC/SC SDK for more informations.", "Communication error");
                        llcp             = null;
                        pControl.Enabled = true;
                    }

                    reader.StartMonitor(new SCardReader.StatusChangeCallback(ReaderStatusChanged));
                }
            }
        }
Exemplo n.º 7
0
        void ReaderStatusChanged(uint ReaderState, CardBuffer CardAtr)
        {
            /* The ReaderStatusChanged function is called as a delegate (callback) by the SCardReader object    */
            /* within its backgroung thread. Therefore we must use the BeginInvoke syntax to switch back from   */
            /* the context of the background thread to the context of the application's main thread. Overwise   */
            /* we'll get a security violation when trying to access the window's visual components (that belong */
            /* to the application's main thread and can't be safely manipulated by background threads).         */
            if (InvokeRequired)
            {
                this.BeginInvoke(new ReaderStatusChangedInvoker(ReaderStatusChanged), ReaderState, CardAtr);
                return;
            }

            DisplayReaderState(ReaderState, CardAtr);

            if (ReaderState == SCARD.STATE_UNAWARE)
            {
                if (cardChannel != null)
                {
                    cardChannel.Disconnect();
                    cardChannel = null;
                }
                if (Reader != null)
                {
                    Reader.StopMonitor();
                    Reader.Release();
                    Reader = null;
                }
                if (ReaderList != null)
                {
                    ReaderList.Release();
                    ReaderList = null;
                }

                btnReadAgain.Enabled = false;
                btnWrite.Enabled     = false;

                MessageBox.Show(this,
                                "The reader we were working on has been removed from the system. Please click the 'Reader' link to select another reader.",
                                Title,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);

                DisplayReaderState(0, null);
                DisplayReaderAbsent();
                return;
            }

            if ((ReaderState & SCARD.STATE_EMPTY) != 0)
            {
                if (cardChannel != null)
                {
                    cardChannel.Disconnect();
                    cardChannel = null;
                }

                btnReadAgain.Enabled = false;
                btnWrite.Enabled     = false;
            }
            else if ((ReaderState & SCARD.STATE_UNAVAILABLE) != 0)
            {
                btnReadAgain.Enabled = false;
                btnWrite.Enabled     = false;
            }
            else if ((ReaderState & SCARD.STATE_MUTE) != 0)
            {
                btnReadAgain.Enabled = false;
                btnWrite.Enabled     = false;
            }
            else if ((ReaderState & SCARD.STATE_INUSE) != 0)
            {
            }
            else if ((ReaderState & SCARD.STATE_PRESENT) != 0)
            {
                if (cardChannel == null)
                {
                    /* New card -> leave edit mode */
                    cardChannel = Reader.GetChannel();

                    DisplayWorking(false);

                    if (cardChannel.Connect())
                    {
                        cardReaderThread = new Thread(ReadCardFirst);
                        cardReaderThread.Start();
                    }
                    else
                    {
                        ClearDisplay();
                        MessageBox.Show(this,
                                        "Failed to connect to the card in the reader. Please verify that you don't have another application running in the background, that tries to access to the smartcards in the same reader.",
                                        Title,
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Exclamation);
                        cardChannel = null;
                    }
                }
            }
        }