Exemplo n.º 1
0
        /// <summary>
        /// Exchange data with smartcard and check response with expected data,
        /// you can use '?' digit to skip check in a specific position.
        /// </summary>
        private static string SendReceiveAdv(string command,
                                             ref string response,
                                             string expResponse,
                                             ref bool isVerified)
        {
            isVerified = false;
            response   = "";

            // exchange data
            retStr = GlobalObj.SendReceive(command, ref response);

            if (retStr != "")
            {
                // error detected
                return(retStr);
            }

            if (response.Length != expResponse.Length)
            {
                // two length are differents
                return("");
            }

            // loop for each digits
            for (int p = 0; p < response.Length; p++)
            {
                if ((expResponse.Substring(p, 1) != "?") &&
                    (expResponse.Substring(p, 1) != response.Substring(p, 1)))
                {
                    // data returned is different from expected
                    return("");
                }
            }

            isVerified = true;
            return("");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Perform exchange data with card
        /// </summary>
        private void ExchangeData()
        {
            if (!GlobalObj.IsPowered)
            {
                MainClass.ShowMessage(this, "WARNING", GlobalObj.LMan.GetString("noinitreader"), MainClass.MessageType.Warning);
                return;
            }

            command = mainwindow_Ui.TxtCmd.Text;
            mainwindow_Ui.TxtResp.Text = "";
            mainwindow_Ui.TxtResp.Show();
            MainClass.QtWait();

            retStr = GlobalObj.SendReceive(command, ref response);

            if (retStr != "")
            {
                log.Error(retStr);
                MainClass.ShowMessage(this, "ERROR", retStr, MainClass.MessageType.Error);
                return;
            }

            mainwindow_Ui.TxtResp.Text = response;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Console Application
        /// </summary>
        public static void StartApp()
        {
            // create readers list
            List <string> allreaders = new List <string>();

            // loop for each managed readers type
            foreach (IReader rdr in GlobalObj.ReaderManager.Values)
            {
                allreaders.AddRange(rdr.Readers);
            }


            // display available readers
            Console.WriteLine("\r\n" + GlobalObj.LMan.GetString("readerslist") + ":");
            for (int n = 0; n < allreaders.Count; n++)
            {
                Console.WriteLine(n.ToString().PadLeft(3) + ". " + allreaders[n]);
            }
            Console.WriteLine("\r\n" + GlobalObj.LMan.GetString("readersel"));
            Console.Write("> ");
            command = Console.ReadLine();

            if (command == "EXIT")
            {
                // exit from application
                return;
            }

            try
            {
                // set reader to use
                GlobalObj.SelectedReader = allreaders[int.Parse(command)];
            }
            catch (Exception Ex)
            {
                // error detected
                log.Error("ConsoleManager::StartApp: " + Ex.Message);
                return;
            }


            // Connect to smartcard
            ret = GlobalObj.AnswerToReset(ref ATR);

            if (ret != "")
            {
                // error on answer to reset
                log.Error("ConsoleManager::StartApp: " + ret);
                Console.WriteLine(ret);
                return;
            }

            Console.WriteLine("\r\nAnswer To Reset: " + ATR + "\r\n");

            while (1 == 1)
            {
                Console.WriteLine(GlobalObj.LMan.GetString("cmdtosend"));
                Console.Write("> ");
                command = Console.ReadLine();

                if (command == "EXIT")
                {
                    // exit from loop and from application
                    GlobalObj.CloseConnection();
                    break;
                }

                ret = GlobalObj.SendReceive(command, ref response);
                if (ret != "")
                {
                    // error on send command
                    log.Error("ConsoleManager::StartApp: " + ret);
                    Console.WriteLine("< " + ret);
                }
                else
                {
                    // response returned
                    Console.WriteLine("< " + response + "\r\n");
                }
            }
        }