Esempio n. 1
0
        void ChangeReader()
        {
            if (reader != null)
            {
                reader.StopMonitor();
                reader = null;
            }

            eReaderStatus.Text = "";
            eCardAtr.Text      = "";

            ReaderSelectForm readerSelect = new ReaderSelectForm(imgHeader.BackColor);

            readerSelect.SelectedReader = eReaderName.Text;
            readerSelect.ShowDialog();
            if (readerSelect.SelectedReader != null)
            {
                eReaderName.Text = readerSelect.SelectedReader;
            }

            reader = new SCardReader(eReaderName.Text);

            SetNfcMode(0, false);

            reader.StartMonitor(new SCardReader.StatusChangeCallback(ReaderStatusChanged));
        }
Esempio n. 2
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;
            }
        }
Esempio n. 3
0
        void MainFormShown(object sender, EventArgs e)
        {
            waitForm = new WaitForm();

            SplashForm f = new SplashForm();

            f.ShowDialog();

            if (AppConfig.ReadBoolean("reader_reconnect"))
            {
                ReaderList = new SCardReaderList();
                if (ReaderList != null)
                {
                    string reader_name = AppConfig.ReadString("reader_name");
                    if (ReaderList.Contains(reader_name))
                    {
                        Reader = new SCardReader(reader_name);
                        DisplayReaderPresent();
                        Reader.StartMonitor(new SCardReader.StatusChangeCallback(ReaderStatusChanged));
                        return;
                    }
                    ReaderList = null;
                }
            }

            SelectReader();
        }
Esempio n. 4
0
        void MainFormShown(object sender, EventArgs e)
        {
            if (true)
            {
                SplashForm splash = new SplashForm();
                splash.ShowDialog();
            }

            ReaderSelectForm readerSelect = new ReaderSelectForm(imgHeader.BackColor);

            if (readerSelect.SelectedReader == null)
            {
                readerSelect.Preselect("SpringCard|NFC|tactless");
                for (;;)
                {
                    readerSelect.ShowDialog();
                    if (readerSelect.SelectedReader != null)
                    {
                        break;
                    }

                    if (MessageBox.Show("This application can't run without a reader. Do you want to leave the application now ?",
                                        "No reader selected",
                                        MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                    {
                        Application.Exit();
                        return;
                    }
                }
            }

            eReaderName.Text   = readerSelect.SelectedReader;
            eReaderStatus.Text = "";
            eCardAtr.Text      = "";

            reader = new SCardReader(eReaderName.Text);

            Settings s = new Settings();

            if ((s.SelectedType >= 0) && (s.SelectedType < cbNdefType.Items.Count))
            {
                cbNdefType.SelectedIndex = s.SelectedType;
            }
            else
            {
                cbNdefType.SelectedIndex = 0;
            }
            CbNdefTypeSelectedIndexChanged(null, null);

            SetNfcMode(0, false);
            ShowStatus();

            reader.StartMonitor(new SCardReader.StatusChangeCallback(ReaderStatusChanged));
        }
Esempio n. 5
0
        public void setReader(string readerName)
        {
            Trace.WriteLine("Selecting reader: " + readerName);

            eReaderName.Text   = readerName;
            eReaderStatus.Text = "";
            eCardAtr.Text      = "";

            reader = new SCardReader(readerName);
            reader.StartMonitor(new SCardReader.StatusChangeCallback(ReaderStatusChanged));
        }
Esempio n. 6
0
        void SelectReader(string ReaderName)
        {
            eReaderName.Text = ReaderName;
            reader           = new SCardReader(ReaderName);

            LimitToP2PProtocols(true);

            CbModeCheckedChanged(null, null);
            CbNdefTypeSelectedIndexChanged(null, null);

            reader.StartMonitor(new SCardReader.StatusChangeCallback(ReaderStatusChanged));
        }
Esempio n. 7
0
        void SelectReader()
        {
            if ((ReaderList != null) || (Reader != null))
            {
                if (!UserWantsToClose())
                {
                    return;
                }

                CloseDevice();
            }

            ReaderSelectForm f  = new ReaderSelectForm();
            bool             rc = (f.ShowDialog(this) == DialogResult.OK);

            if (rc)
            {
                string ReaderName = f.SelectedReader;

                ReaderList = new SCardReaderList();
                if (ReaderList != null)
                {
                    Reader = ReaderList.GetReader(ReaderName);
                    if (Reader != null)
                    {
                        DisplayReaderPresent();
                        Reader.StartMonitor(new SCardReader.StatusChangeCallback(ReaderStatusChanged));
                        return;
                    }
                    else
                    {
                        MessageBox.Show(this,
                                        "Failed to connect to the PC/SC reader. Please click the 'Reader' link to select another reader.",
                                        Title,
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Exclamation);
                    }
                    ReaderList = null;
                }
                else
                {
                    MessageBox.Show(this,
                                    "The PC/SC subsystem doesn't seem to be running. Please check your system's configuration.",
                                    Title,
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Exclamation);
                }
            }
        }
 private void SetReader(string readerName)
 {
     try
     {
         _reader = new SCardReader(readerName);
         _reader.StartMonitor(new SCardReader.StatusChangeCallback(ReaderStatusChanged));
         InfoNotify("Connection Status|Current Reader is " + readerName);
     }
     catch (Exception ex)
     {
         ErrorHandler.TreatError(ex);
         MessageBox.Show(@"You cannot Proceed without a working NFC Reader. Please check!");
         this.CloseProcess();
     }
 }
Esempio n. 9
0
 void MainFormShown(object sender, EventArgs e)
 {
     if (AppConfig.ReadBoolean("reader_reconnect"))
     {
         if (AppConfig.ReadString("reader_mode") == "serial")
         {
             SCardReaderList_CcidOverSerial.BackgroundInstantiate(
                 new SCardReaderList_CcidOverSerial.BackgroundInstantiateCallback(OnSerialReaderListInstantiated),
                 AppConfig.ReadString("serial_port"),
                 true,
                 AppConfig.ReadBoolean("serial_use_lpcd"));
         }
         else
         {
             ReaderList = new SCardReaderList();
             if (ReaderList != null)
             {
                 string reader_name = AppConfig.ReadString("reader_name");
                 Logger.Trace("Looking for PC/SC reader '" + reader_name + "'");
                 if (ReaderList.Contains(reader_name))
                 {
                     Logger.Trace("Found!");
                     Reader = new SCardReader(reader_name);
                     DisplayReaderPresent();
                     Reader.StartMonitor(new SCardReader.StatusChangeCallback(ReaderStatusChanged));
                     return;
                 }
                 else
                 {
                     Logger.Trace("Not found!");
                     MessageBox.Show(this,
                                     "Failed to reconnect to the previous PC/SC reader. Please click the 'Reader' link to select another reader.",
                                     Title, MessageBoxButtons.OK,
                                     MessageBoxIcon.Exclamation);
                 }
                 ReaderList = null;
             }
             else
             {
                 MessageBox.Show(this,
                                 "The PC/SC subsystem doesn't seem to be running. Please check your system's configuration.",
                                 Title,
                                 MessageBoxButtons.OK,
                                 MessageBoxIcon.Exclamation);
             }
         }
     }
 }
Esempio n. 10
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;
            }
        }
 public void Start(AdapterErrorCallback _AdapterError)
 {
     _AdapterErrorCallback = _AdapterError;
     _reader.StartMonitor(new SCardReader.StatusChangeCallback(ReaderStatusChanged));
 }
Esempio n. 12
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));
                }
            }
        }
Esempio n. 13
0
        void SelectReader()
        {
            if ((ReaderList != null) || (Reader != null))
            {
                if (!UserWantsToClose())
                {
                    return;
                }

                CloseDevice();
            }

            ReaderSelectAnyForm f = new ReaderSelectAnyForm();
            bool rc = (f.ShowDialog(this) == DialogResult.OK);

            if (rc)
            {
                if (f.Mode == "pc/sc")
                {
                    string ReaderName;
                    f.GetPCSCParameters(out ReaderName);

                    ReaderList = new SCardReaderList();
                    if (ReaderList != null)
                    {
                        Reader = ReaderList.GetReader(ReaderName);
                        if (Reader != null)
                        {
                            DisplayReaderPresent();
                            Reader.StartMonitor(new SCardReader.StatusChangeCallback(ReaderStatusChanged));
                        }
                        else
                        {
                            MessageBox.Show(this, "Failed to connect to the PC/SC reader. Please click the 'Reader' link to select another reader.", Title, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        }
                    }
                    else
                    {
                        MessageBox.Show(this, "The PC/SC subsystem doesn't seem to be running. Please check your system's configuration.", Title, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
                else if (f.Mode == "serial")
                {
                    string PortName;
                    bool   UseNotifications;
                    bool   UseLpcdPolling;

                    f.GetSerialParameters(out PortName, out UseNotifications, out UseLpcdPolling);

                    SCardReaderList_CcidOverSerial.BackgroundInstantiate(
                        new SCardReaderList_CcidOverSerial.BackgroundInstantiateCallback(OnSerialReaderListInstantiated),
                        PortName,
                        UseNotifications,
                        UseLpcdPolling);
                }
                else if (f.Mode == "network")
                {
                    string Address;
                    ushort Port;

                    f.GetNetworkParameters(out Address, out Port);

                    SCardReaderList_CcidOverNetwork.BackgroundInstantiate(
                        new SCardReaderList_CcidOverNetwork.BackgroundInstantiateCallback(OnNetworkReaderListInstantiated),
                        Address,
                        Port);
                }
            }
        }