예제 #1
0
파일: NFCclass.cs 프로젝트: vebin/NewPOS
        public int SendAPDU()
        {
            int    indx;
            string tmpStr;

            pioSendRequest.dwProtocol  = Aprotocol;
            pioSendRequest.cbPciLength = 8;

            // Display Apdu In
            tmpStr = "";
            for (indx = 0; indx <= SendLen - 1; indx++)
            {
                tmpStr = tmpStr + " " + string.Format("{0:X2}", SendBuff[indx]);
            }
            displayOut(2, 0, tmpStr, mMsg);
            retCode = ModWinsCard.SCardTransmit(hCard, ref pioSendRequest, ref SendBuff[0], SendLen, ref pioSendRequest, ref RecvBuff[0], ref RecvLen);

            if (retCode != ModWinsCard.SCARD_S_SUCCESS)
            {
                displayOut(1, retCode, "", mMsg);
                return(retCode);
            }

            tmpStr = "";
            for (indx = 0; indx <= RecvLen - 1; indx++)
            {
                tmpStr = tmpStr + " " + string.Format("{0:X2}", RecvBuff[indx]);
            }

            displayOut(3, 0, tmpStr, mMsg);
            return(retCode);
        }
예제 #2
0
파일: NFCclass.cs 프로젝트: vebin/NewPOS
        private void displayOut(int errType, int retVal, string PrintText, System.Windows.Forms.RichTextBox mMsg)
        {
            try
            {
                switch (errType)
                {
                case 0:
                    mMsg.SelectionColor = Color.Green;
                    break;

                case 1:
                    mMsg.SelectionColor = Color.Red;
                    PrintText           = ModWinsCard.GetScardErrMsg(retVal);
                    break;

                case 2:
                    mMsg.SelectionColor = Color.Black;
                    PrintText           = "<" + PrintText;
                    break;

                case 3:
                    mMsg.SelectionColor = Color.Black;
                    PrintText           = ">" + PrintText;
                    break;

                case 4:
                    break;
                }
                mMsg.AppendText(PrintText);
                mMsg.AppendText("\n");
                mMsg.SelectionColor = Color.Black;
                mMsg.Focus();
            }
            catch (Exception ex) { }
        }
예제 #3
0
파일: NFCclass.cs 프로젝트: vebin/NewPOS
        public void getATR(System.Windows.Forms.ComboBox cbReader)
        {
            string tmpStr;
            int    indx;

            displayOut(0, 0, "Invoke Card Status", mMsg);
            ATRLen = 33;

            retCode = ModWinsCard.SCardStatus(hCard, cbReader.Text, ref ReaderLen, ref dwState, ref dwActProtocol, ref ATRVal[0], ref ATRLen);

            if (retCode != ModWinsCard.SCARD_S_SUCCESS)
            {
                displayOut(1, retCode, "", mMsg);
                //System.Environment.Exit(0);
            }

            else
            {
                tmpStr = "ATR Length : " + ATRLen.ToString();
                displayOut(3, 0, tmpStr, mMsg);

                tmpStr = "ATR Value : ";

                for (indx = 0; indx <= ATRLen - 1; indx++)
                {
                    tmpStr = tmpStr + " " + string.Format("{0:X2}", ATRVal[indx]);
                }

                displayOut(3, 0, tmpStr, mMsg);
            }

            tmpStr = "Active Protocol: ";

            switch (dwActProtocol)
            {
            case 1:
                tmpStr = tmpStr + "T=0";
                break;

            case 2:
                tmpStr = tmpStr + "T=1";
                break;

            default:
                tmpStr = "No protocol is defined.";
                break;
            }

            displayOut(3, 1, tmpStr, mMsg);
            InterpretATR();
        }
예제 #4
0
파일: NFCclass.cs 프로젝트: vebin/NewPOS
        public void initializereader(System.Windows.Forms.ComboBox cbReader, ToolStripStatusLabel Tssl)
        {
            tssl = Tssl;
            string ReaderList = "" + Convert.ToChar(0);
            int    indx;
            int    pcchReaders = 0;
            string rName       = "";

            //Establish Context
            retCode = ModWinsCard.SCardEstablishContext(ModWinsCard.SCARD_SCOPE_USER, 0, 0, ref hContext);

            if (retCode != ModWinsCard.SCARD_S_SUCCESS)
            {
                //displayOut(1, retCode, "");

                return;
            }

            // 2. List PC/SC card readers installed in the system

            retCode = ModWinsCard.SCardListReaders(this.hContext, null, null, ref pcchReaders);

            if (retCode != ModWinsCard.SCARD_S_SUCCESS)
            {
                //displayOut(1, retCode, "");

                return;
            }

            byte[] ReadersList = new byte[pcchReaders];

            // Fill reader list
            retCode = ModWinsCard.SCardListReaders(this.hContext, null, ReadersList, ref pcchReaders);

            if (retCode != ModWinsCard.SCARD_S_SUCCESS)
            {
                tssl.Text = ("SCardListReaders Error: " + ModWinsCard.GetScardErrMsg(retCode));

                return;
            }
            else
            {
                displayOut(0, 0, " ", mMsg);
            }

            rName = "";
            indx  = 0;

            //Convert reader buffer to string
            while (ReadersList[indx] != 0)
            {
                while (ReadersList[indx] != 0)
                {
                    rName = rName + (char)ReadersList[indx];
                    indx  = indx + 1;
                }

                //Add reader name to list
                cbReader.Items.Add(rName);
                rName = "";
                indx  = indx + 1;
            }

            if (cbReader.Items.Count > 0)
            {
                cbReader.SelectedIndex = 0;
            }
            retCode = ModWinsCard.SCardConnect(hContext, cbReader.SelectedItem.ToString(), ModWinsCard.SCARD_SHARE_SHARED,
                                               ModWinsCard.SCARD_PROTOCOL_T0 | ModWinsCard.SCARD_PROTOCOL_T1, ref hCard, ref Protocol);

            if (retCode != ModWinsCard.SCARD_S_SUCCESS)
            {
                displayOut(1, retCode, "", mMsg);
            }
            else
            {
                displayOut(0, 0, "Successful connection to " + cbReader.Text, mMsg);
            }
            connActive = true;
            loadkeys();
        }