Ejemplo n.º 1
0
        snprint_nfc_target(out string strdst, NFC.nfc_target pnt, bool verbose)
        {
            strdst = "";
            if (null != pnt)
            {
                strdst  = "";
                strdst += NFC.str_nfc_modulation_type(pnt.nm.nmt) + " ";
                strdst += "(" + NFC.str_nfc_baud_rate(pnt.nm.nbr);
                strdst += (pnt.nm.nmt != NFC.nfc_modulation_type.NMT_DEP) ? "" : (pnt.nti.ndi.ndm == NFC.nfc_dep_mode.NDM_ACTIVE) ? "active mode" : "passive mode" + ")";
                strdst += " target:\r\n";
                string dst = "";
                switch (pnt.nm.nmt)
                {
                case NFC.nfc_modulation_type.NMT_ISO14443A:
                    snprint_nfc_iso14443a_info(out dst, pnt.nti.nai, verbose);
                    break;

                case NFC.nfc_modulation_type.NMT_JEWEL:
                    snprint_nfc_jewel_info(out dst, pnt.nti.nji, verbose);
                    break;

                case NFC.nfc_modulation_type.NMT_FELICA:
                    snprint_nfc_felica_info(out dst, pnt.nti.nfi, verbose);
                    break;

                case NFC.nfc_modulation_type.NMT_ISO14443B:
                    snprint_nfc_iso14443b_info(out dst, pnt.nti.nbi, verbose);
                    break;

                case NFC.nfc_modulation_type.NMT_ISO14443BI:
                    snprint_nfc_iso14443bi_info(out dst, pnt.nti.nii, verbose);
                    break;

                case NFC.nfc_modulation_type.NMT_ISO14443B2SR:
                    snprint_nfc_iso14443b2sr_info(out dst, pnt.nti.nsi, verbose);
                    break;

                case NFC.nfc_modulation_type.NMT_ISO14443B2CT:
                    snprint_nfc_iso14443b2ct_info(out dst, pnt.nti.nci, verbose);
                    break;

                case NFC.nfc_modulation_type.NMT_DEP:
                    snprint_nfc_dep_info(out dst, pnt.nti.ndi, verbose);
                    break;
                }
                strdst += dst;
            }
        }
Ejemplo n.º 2
0
        public static bool authenticate(NFC.nfc_device pnd, NFC.nfc_target pnt, uint uiBlock, byte[] key, mifare_cmd mc)
        {
            mifare_param mp = new mifare_param();

            // Set the authentication information (uid)
            MiscTool.memcpy(mp.mpa.abtAuthUid, 0, pnt.nti.nai.abtUid, pnt.nti.nai.szUidLen - 4, 4);
            MiscTool.memcpy(mp.mpa.abtKey, 0, key, 0, 6);
            if (nfc_initiator_mifare_cmd(pnd, mc, (byte)uiBlock, mp))
            {
                return(true);
            }
            if (NFC.nfc_initiator_select_passive_target(pnd, nmMfClassic, pnt.nti.nai.abtUid, pnt.nti.nai.szUidLen, null) <= 0)
            {
                //ERR("tag was removed");
                return(false);
            }
            return(true);
        }
Ejemplo n.º 3
0
        public static int get_rats(NFC.nfc_device pnd, NFC.nfc_target pnt, byte[] abtRx)
        {
            int res;

            byte[] abtRats = { 0xe0, 0x50 };
            // Use raw send/receive methods
            if (NFC.nfc_device_set_property_bool(pnd, NFC.nfc_property.NP_EASY_FRAMING, false) < 0)
            {
                NFC.nfc_perror(pnd, "nfc_configure");
                return(-1);
            }
            res = NFC.nfc_initiator_transceive_bytes(pnd, abtRats, abtRats.Length, abtRx, abtRx.Length, 0);
            if (res > 0)
            {
                // ISO14443-4 card, turn RF field off/on to access ISO14443-3 again
                if (NFC.nfc_device_set_property_bool(pnd, NFC.nfc_property.NP_ACTIVATE_FIELD, false) < 0)
                {
                    NFC.nfc_perror(pnd, "nfc_configure");
                    return(-1);
                }
                if (NFC.nfc_device_set_property_bool(pnd, NFC.nfc_property.NP_ACTIVATE_FIELD, true) < 0)
                {
                    NFC.nfc_perror(pnd, "nfc_configure");
                    return(-1);
                }
            }
            // Reselect tag after using get_rats, example:
            if (NFC.nfc_initiator_select_passive_target(pnd, nmMfClassic, null, 0, pnt) <= 0)
            {
                //printf("Error: tag disappeared\n");
                //NFC.nfc_close(pnd);
                //NFC.nfc_exit(context);
                //exit(EXIT_FAILURE);
                return(-1);
            }
            return(res);
        }