Skip to content
uFCoder.cs 113 KiB
Newer Older
developer29's avatar
developer29 committed
using System;
using System.Text;

namespace uFR
{
    using System.Runtime.InteropServices;
    using UFR_HANDLE = System.UIntPtr;

    enum CARD_SAK
    {
        UNKNOWN = 0x00,
        MIFARE_CLASSIC_1k = 0x08,
        MF1ICS50 = 0x08,
        SLE66R35 = 0x88,
        MIFARE_CLASSIC_4k = 0x18,
        MF1ICS70 = 0x18,
        MIFARE_CLASSIC_MINI = 0x09,
        MF1ICS20 = 0x09,
    }

    enum DLOGIC_CARD_TYPE
    {
        DL_NO_CARD                  = 0x00,
        DL_MIFARE_ULTRALIGHT        = 0x01,
        DL_MIFARE_ULTRALIGHT_EV1_11 = 0x02,
        DL_MIFARE_ULTRALIGHT_EV1_21 = 0x03,
        DL_MIFARE_ULTRALIGHT_C      = 0x04,
        DL_NTAG_203                 = 0x05,
        DL_NTAG_210                 = 0x06,
        DL_NTAG_212                 = 0x07,
        DL_NTAG_213                 = 0x08,
        DL_NTAG_215                 = 0x09,
        DL_NTAG_216                 = 0x0A,
        DL_MIKRON_MIK640D           = 0x0B,
        NFC_T2T_GENERIC             = 0x0C,

        DL_MIFARE_MINI				= 0x20,
        DL_MIFARE_CLASSIC_1K		= 0x21,
        DL_MIFARE_CLASSIC_4K		= 0x22,
        DL_MIFARE_PLUS_S_2K			= 0x23,
        DL_MIFARE_PLUS_S_4K			= 0x24,
        DL_MIFARE_PLUS_X_2K			= 0x25,
        DL_MIFARE_PLUS_X_4K			= 0x26,
        DL_MIFARE_DESFIRE			= 0x27,
        DL_MIFARE_DESFIRE_EV1_2K	= 0x28,
        DL_MIFARE_DESFIRE_EV1_4K	= 0x29,
        DL_MIFARE_DESFIRE_EV1_8K	= 0x2A,
        DL_MIFARE_DESFIRE_EV2_2K	= 0x2B,
        DL_MIFARE_DESFIRE_EV2_4K	= 0x2C,
        DL_MIFARE_DESFIRE_EV2_8K	= 0x2D,
        
        DL_IMEI_UID					= 0x80
    }
    // MIFARE CLASSIC Authentication Modes:
    enum MIFARE_AUTHENTICATION
    {
        MIFARE_AUTHENT1A = 0x60,
        MIFARE_AUTHENT1B = 0x61
    }
    // DLJavaCardSignerCardTypes:
    enum JCDL_SIGNER_CARDS
    {
        DLSigner81 = 0xA0,
        DLSigner22 = 0xA1,
        DLSigner30 = 0xA2,
        DLSigner10 = 0xA3,
        DLSigner145 = 0xAA
    }
    // DLJavaCardSignerAlgorithmTypes:
    enum JCDL_SIGNER_CIPHERS
    {
        SIG_CIPHER_RSA = 0,
        SIG_CIPHER_ECDSA
    };
    enum JCDL_SIGNER_PADDINGS
    {
        PAD_NULL = 0,
        PAD_PKCS1
    };
    enum JCDL_SIGNER_DIGESTS
    {
        ALG_NULL = 0,
        ALG_SHA,
        ALG_SHA_256,
        ALG_SHA_384,
        ALG_SHA_512,
        ALG_SHA_224
    };
    enum JCDL_KEY_TYPES
    {
        TYPE_RSA_PRIVATE = 0,
        TYPE_RSA_CRT_PRIVATE,
        TYPE_EC_F2M_PRIVATE,
        TYPE_EC_FP_PRIVATE
    };
    enum JCDS_EC_KEY_DESIGNATOR
    {
        EC_KEY_DSG_K1 = 0,
        EC_KEY_DSG_R1,
        EC_KEY_DSG_R2,
        EC_KEY_DSG_RFU
    }
    // API Status Codes Type:
    public enum DL_STATUS
    {
        UFR_OK = 0x00,

        UFR_COMMUNICATION_ERROR = 0x01,
        UFR_CHKSUM_ERROR = 0x02,
        UFR_READING_ERROR = 0x03,
        UFR_WRITING_ERROR = 0x04,
        UFR_BUFFER_OVERFLOW = 0x05,
        UFR_MAX_ADDRESS_EXCEEDED = 0x06,
        UFR_MAX_KEY_INDEX_EXCEEDED = 0x07,
        UFR_NO_CARD = 0x08,
        UFR_COMMAND_NOT_SUPPORTED = 0x09,
        UFR_FORBIDEN_DIRECT_WRITE_IN_SECTOR_TRAILER = 0x0A,
        UFR_ADDRESSED_BLOCK_IS_NOT_SECTOR_TRAILER = 0x0B,
        UFR_WRONG_ADDRESS_MODE = 0x0C,
        UFR_WRONG_ACCESS_BITS_VALUES = 0x0D,
        UFR_AUTH_ERROR = 0x0E,
        UFR_PARAMETERS_ERROR = 0x0F,
        UFR_MAX_SIZE_EXCEEDED = 0x10,
        UFR_UNSUPPORTED_CARD_TYPE,

        UFR_WRITE_VERIFICATION_ERROR = 0x70,
        UFR_BUFFER_SIZE_EXCEEDED = 0x71,
        UFR_VALUE_BLOCK_INVALID = 0x72,
        UFR_VALUE_BLOCK_ADDR_INVALID = 0x73,
        UFR_VALUE_BLOCK_MANIPULATION_ERROR = 0x74,
        UFR_WRONG_UI_MODE = 0x75,
        UFR_KEYS_LOCKED = 0x76,
        UFR_KEYS_UNLOCKED = 0x77,
        UFR_WRONG_PASSWORD = 0x78,
        UFR_CAN_NOT_LOCK_DEVICE = 0x79,
        UFR_CAN_NOT_UNLOCK_DEVICE = 0x7A,
        UFR_DEVICE_EEPROM_BUSY = 0x7B,
        UFR_RTC_SET_ERROR = 0x7C,
        UFR_TAG_UNKNOWN = 0x7D,

        UFR_COMMUNICATION_BREAK = 0x50,
        UFR_NO_MEMORY_ERROR = 0x51,
        UFR_CAN_NOT_OPEN_READER = 0x52,
        UFR_READER_NOT_SUPPORTED = 0x53,
        UFR_READER_OPENING_ERROR = 0x54,
        UFR_READER_PORT_NOT_OPENED = 0x55,
        UFR_CANT_CLOSE_READER_PORT = 0x56,

        UFR_FT_STATUS_ERROR_1 = 0xA0,
        UFR_FT_STATUS_ERROR_2 = 0xA1,
        UFR_FT_STATUS_ERROR_3 = 0xA2,
        UFR_FT_STATUS_ERROR_4 = 0xA3,
        UFR_FT_STATUS_ERROR_5 = 0xA4,
        UFR_FT_STATUS_ERROR_6 = 0xA5,
        UFR_FT_STATUS_ERROR_7 = 0xA6,
        UFR_FT_STATUS_ERROR_8 = 0xA7,
        UFR_FT_STATUS_ERROR_9 = 0xA8,

        //NDEF error codes
        UFR_WRONG_NDEF_CARD_FORMAT = 0x80,
        UFR_NDEF_MESSAGE_NOT_FOUND = 0x81,
        UFR_NDEF_UNSUPPORTED_CARD_TYPE = 0x82,
        UFR_NDEF_CARD_FORMAT_ERROR = 0x83,
        UFR_MAD_NOT_ENABLED = 0x84,
        UFR_MAD_VERSION_NOT_SUPPORTED = 0x85,
        
        UFR_TIMEOUT_ERR = 0x90,

    	// multiple units - return from the functions with ReaderList_ prefix in name
    	UFR_DEVICE_WRONG_HANDLE = 0x100,
    	UFR_DEVICE_INDEX_OUT_OF_BOUND,
    	UFR_DEVICE_ALREADY_OPENED,
    	UFR_DEVICE_ALREADY_CLOSED,
    	UFR_DEVICE_IS_NOT_CONNECTED,
    
    	// Originality Check Error Codes:
    	UFR_NOT_NXP_GENUINE = 0x200,
    	UFR_OPEN_SSL_DYNAMIC_LIB_FAILED,
    	UFR_OPEN_SSL_DYNAMIC_LIB_NOT_FOUND,

        UFR_NOT_IMPLEMENTED = 0x1000,
        UFR_COMMAND_FAILED,

        // APDU Error Codes:
        UFR_APDU_JC_APP_NOT_SELECTED = 0x6000,
        UFR_APDU_JC_APP_BUFF_EMPTY,
        UFR_APDU_WRONG_SELECT_RESPONSE,
        UFR_APDU_WRONG_KEY_TYPE,
        UFR_APDU_WRONG_KEY_SIZE,
        UFR_APDU_WRONG_KEY_PARAMS,
        UFR_APDU_WRONG_ALGORITHM,
        UFR_APDU_PLAIN_TEXT_SIZE_EXCEEDED,
        UFR_APDU_UNSUPPORTED_KEY_SIZE,
        UFR_APDU_UNSUPPORTED_ALGORITHMS,
        UFR_APDU_SW_TAG = 0x0A0000,

        MAX_UFR_STATUS /*= 10000000,
        UNKNOWN_ERROR */ = 2147483647 // 0x7FFFFFFF
    };

    public enum DL_SECURE_CODE
    {
        USER_PIN = 0,
        SO_PIN,
        USER_PUK,
        SO_PUK
    };

    public enum DESFIRE_CARD_STATUS_CODES
    {
        READER_ERROR = 2999,
        CARD_OPERATION_OK = 3001,
        WRONG_KEY_TYPE = 3002,
        KEY_AUTH_ERROR = 3003,
        CARD_CRYPTO_ERROR = 3004,
        READER_CARD_COMM_ERROR = 3005,
        PC_READER_COMM_ERROR = 3006,
        COMMIT_TRANSACTION_NO_REPLY = 3007,
        COMMIT_TRANSACTION_ERROR = 3008,
        DESFIRE_CARD_NO_CHANGES = 0x0C0C,
        DESFIRE_CARD_OUT_OF_EEPROM_ERROR = 0x0C0E,
        DESFIRE_CARD_ILLEGAL_COMMAND_CODE = 0x0C1C,
        DESFIRE_CARD_INTEGRITY_ERROR = 0x0C1E,
        DESFIRE_CARD_NO_SUCH_KEY = 0x0C40,
        DESFIRE_CARD_LENGTH_ERROR = 0x0C7E,
        DESFIRE_CARD_PERMISSION_DENIED = 0x0C9D,
        DESFIRE_CARD_PARAMETER_ERROR = 0x0C9E,
        DESFIRE_CARD_APPLICATION_NOT_FOUND = 0x0CA0,
        DESFIRE_CARD_APPL_INTEGRITY_ERROR = 0x0CA1,
        DESFIRE_CARD_AUTHENTICATION_ERROR = 0x0CAE,
        DESFIRE_CARD_ADDITIONAL_FRAME = 0x0CAF,
        DESFIRE_CARD_BOUNDARY_ERROR = 0x0CBE,
        DESFIRE_CARD_PICC_INTEGRITY_ERROR = 0x0CC1,
        DESFIRE_CARD_COMMAND_ABORTED = 0x0CCA,
        DESFIRE_CARD_PICC_DISABLED_ERROR = 0x0CCD,
        DESFIRE_CARD_COUNT_ERROR = 0x0CCE,
        DESFIRE_CARD_DUPLICATE_ERROR = 0x0CDE,
        DESFIRE_CARD_EEPROM_ERROR_DES = 0x0CEE,
        DESFIRE_CARD_FILE_NOT_FOUND = 0x0CF0,
        DESFIRE_CARD_FILE_INTEGRITY_ERROR = 0x0CF1
    };

    public enum DESFIRE_KEY_SETTINGS
    {
        DESFIRE_KEY_SET_CREATE_WITH_AUTH_SET_CHANGE_KEY_CHANGE = 0x09,
        DESFIRE_KEY_SET_CREATE_WITHOUT_AUTH_SET_CHANGE_KEY_CHANGE = 0x0F,
        DESFIRE_KEY_SET_CREATE_WITH_AUTH_SET_NOT_CHANGE_KEY_CHANGE = 0x01,
        DESFIRE_KEY_SET_CREATE_WITHOUT_AUTH_SET_NOT_CHANGE_KEY_CHANGE = 0x07,
        DESFIRE_KEY_SET_CREATE_WITH_AUTH_SET_CHANGE_KEY_NOT_CHANGE = 0x08,
        DESFIRE_KEY_SET_CREATE_WITHOUT_AUTH_SET_CHANGE_KEY_NOT_CHANGE = 0x0E,
        DESFIRE_KEY_SET_CREATE_WITH_AUTH_SET_NOT_CHANGE_KEY_NOT_CHANGE = 0x00,
        DESFIRE_KEY_SET_CREATE_WITHOUT_AUTH_SET_NOT_CHANGE_KEY_NOT_CHANGE = 0x06
    };

    public static class uFCoder
    {
        public const uint JCAPP_MIN_PIN_LENGTH = 4;
        public const uint JCAPP_MAX_PIN_LENGTH = 8;
        public const uint JCAPP_PUK_LENGTH = 8;
        public const uint SIG_MAX_PLAIN_DATA_LEN = 255;
        public const string JCDL_AID_RID_PLUS = "F0 44 4C 6F 67 69 63";
        public const string JCDL_AID_PIX = "00 01";
        public const string JCDL_AID = JCDL_AID_RID_PLUS + JCDL_AID_PIX;

        const UInt32 MIN_UFR_LIB_VERSION = 0x05000003; // bytes from left to right: MSB=MajorVer, MidSB_H=MinorVer, MidSB_L=0, LSB=BuildNum
        const UInt32 MIN_UFR_FW_VERSION = 0x05000007; // bytes from left to right: MSB=MajorVer, MidSB_H=MinorVer, MidSB_L=0, LSB=BuildNum

        //...
        //...
        //...
        [DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        static extern bool SetDllDirectory(string lpPathName);

developer29's avatar
developer29 committed
#if WIN64
developer4's avatar
developer4 committed
        const string DLL_PATH = @"..\..\..\ufr-lib\windows\x86_64\";
developer29's avatar
developer29 committed
        const string NAME_DLL = "uFCoder-x86_64.dll";

#else
developer4's avatar
developer4 committed
        const string DLL_PATH = @"..\..\..\ufr-lib\windows\x86\";
developer29's avatar
developer29 committed
        const string NAME_DLL = "uFCoder-x86.dll";
#endif
        const string DLL_NAME = DLL_PATH + NAME_DLL;

        public static void uFrOpen()
        {
            DL_STATUS status;
            UInt32 version = 0;
            byte version_major;
            byte version_minor;
            UInt16 lib_build;
            byte fw_build;
            String uFR_NotOpenedMessage;
            bool uFR_Opened;

#if WIN64
            string DllPath = @"lib\windows\x86_64"; // for x64 target
            string name = "uFCoder-x86_64.dll";
#else
            string DllPath = @"lib\windows\x86"; // for x86 target
            string name = "uFCoder-x86.dll";
#endif
            string dll_name = DllPath + name;
            int repeat_cnt = 0;
            bool repeat = true;
            do
            {
                DllPath = @"..\" + DllPath;
                SetDllDirectory(DllPath);
                try
                {
                    version = uFCoder.GetDllVersion();
                    repeat = false;
                }
                catch (System.Exception)
                {
                    ++repeat_cnt;
                }

            } while (repeat && repeat_cnt < 3); // relative path upper folders level search

            if (repeat)
                throw new Exception("Can't find " + dll_name + ".\r\nYou will not be able to work with DL Signer cards.");

            // Check lib version:
            version_major = (byte)version;
            version_minor = (byte)(version >> 8);
            lib_build = (ushort)(version >> 16);

            version = ((UInt32)version_major << 24) | ((UInt32)version_minor << 16) | (UInt32)lib_build;
            if (version < MIN_UFR_LIB_VERSION)
            {
                uFR_NotOpenedMessage = "Wrong uFCoder library version.\r\n"
                    + "You can't work with DL Signer cards.\r\n\r\nUse uFCoder library "
                    + (MIN_UFR_LIB_VERSION >> 24) + "." + ((MIN_UFR_LIB_VERSION >> 16) & 0xFF)
                    + "." + (MIN_UFR_LIB_VERSION & 0xFFFF) + " or higher.";
                throw new Exception("Wrong uFCoder library version.\r\n"
                    + "You can't work with DL Signer cards.\r\n\r\nUse uFCoder library "
                    + (MIN_UFR_LIB_VERSION >> 24) + "." + ((MIN_UFR_LIB_VERSION >> 16) & 0xFF)
                    + "." + (MIN_UFR_LIB_VERSION & 0xFFFF) + " or higher.");
            }

            status = ReaderOpen();
            if (status != (UInt32)uFR.DL_STATUS.UFR_OK)
            {
                uFR_NotOpenedMessage = "uFR reader not opened.\r\nYou can't work with DL Signer cards."
                    + "\r\n\r\nTry to connect uFR reader and restart application.";
                throw new Exception("Can't open uFR reader.\r\nYou will not be able to work with DL Signer cards.");
            }

            // Check firmware version:
            status = GetReaderFirmwareVersion(out version_major, out version_minor);
            if (status != (UInt32)uFR.DL_STATUS.UFR_OK)
            {
                uFCoder.ReaderClose();
                throw new Exception("Can't open uFR reader.\r\nYou will not be able to work with DL Signer cards.");
            }
            status = GetBuildNumber(out fw_build);
            if (status != (UInt32)uFR.DL_STATUS.UFR_OK)
            {
                uFCoder.ReaderClose();
                throw new Exception("Can't open uFR reader.\r\nYou will not be able to work with DL Signer cards.");
            }

            version = ((UInt32)version_major << 24) | ((UInt32)version_minor << 16) | (UInt32)fw_build;
            if (version < MIN_UFR_FW_VERSION)
            {
                uFCoder.ReaderClose();
                uFR_NotOpenedMessage = "Wrong uFR firmware version.\r\n"
                    + "You can't work with DL Signer cards.\r\n\r\nPlease update firmware to "
                    + (MIN_UFR_FW_VERSION >> 24) + "." + ((MIN_UFR_FW_VERSION >> 16) & 0xFF)
                    + "." + (MIN_UFR_FW_VERSION & 0xFFFF) + " or higher.";
                throw new Exception("Wrong uFR firmware version.\r\n"
                    + "You will not be able to work with DL Signer cards.\r\n\r\nPlease update firmware to "
                    + (MIN_UFR_FW_VERSION >> 24) + "." + ((MIN_UFR_FW_VERSION >> 16) & 0xFF)
                    + "." + (MIN_UFR_FW_VERSION & 0xFFFF) + " or higher and restart application.");
            }

            uFR_Opened = true;
        }

developer29's avatar
developer29 committed
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000
        //--------------------------------------------------------------------------------------------------
        //--------------------------------------------------------------------------------------------------

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderOpen")]
        public static extern DL_STATUS ReaderOpen();

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderOpenEx")]
        public static extern DL_STATUS ReaderOpenEx(UInt32 reader_type, IntPtr port_name, UInt32 port_interface, IntPtr arg);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderClose")]
        public static extern DL_STATUS ReaderClose();

        //--------------------------------------------------------------------------------------------------

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "GetReaderType")]
        public static extern DL_STATUS GetReaderType(out UInt32 lpulReaderType);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "GetReaderSerialDescription")]
        private static extern DL_STATUS getReaderSerialDescription(StringBuilder pSerialDescription);
        public static DL_STATUS GetReaderSerialDescription(out string SerialDescription)
        {
            StringBuilder pSerialDescription = new StringBuilder(7);
            DL_STATUS status = DL_STATUS.UFR_OK;

            status = getReaderSerialDescription(pSerialDescription);
            if (status == DL_STATUS.UFR_OK)
                SerialDescription = pSerialDescription.ToString();
            else
                SerialDescription = "";
            return status;
        }

        //---------------------------------------------------------------------
        // Card emulation:
        //---------------------------------------------------------------------
        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "TagEmulationStart")]
        public static extern DL_STATUS TagEmulationStart();

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "TagEmulationStop")]
        public static extern DL_STATUS TagEmulationStop();

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "CombinedModeEmulationStart")]
        public static extern DL_STATUS CombinedModeEmulationStart();
        //---------------------------------------------------------------------

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "GetDlogicCardType")]
        public static extern DL_STATUS GetDlogicCardType(out byte lpucCardType);

        //---------------------------------------------------------------------
        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderList_UpdateAndGetCount")]
        public static extern DL_STATUS ReaderList_UpdateAndGetCount(out UInt32 NumberOfDevices);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderList_GetSerialByIndex")]
        public static extern DL_STATUS ReaderList_GetSerialByIndex(Int32 DeviceIndex, out UInt32 lpulSerialNumber);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderList_GetSerialDesByIndex")]
        public static extern DL_STATUS ReaderList_GetSerialDescriptionByIndex(Int32 DeviceIndex, out byte pSerialDescription);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderList_GetTypeByIndex")]
        public static extern DL_STATUS ReaderList_GetTypeByIndex(Int32 DeviceIndex, out UInt32 lpulReaderType);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderList_GetFTDISerialByIndex")]
        private static extern DL_STATUS GetFTDISerialByIndex(UInt32 DeviceIndex, out IntPtr DeviceSerial);
        public static DL_STATUS ReaderList_GetFTDISerialByIndex(UInt32 DeviceIndex, out string DeviceSerial)
        {
            IntPtr ptr;
            DL_STATUS status = DL_STATUS.UFR_OK;

            status = GetFTDISerialByIndex(DeviceIndex, out ptr);
            DeviceSerial = Marshal.PtrToStringAnsi(ptr);
            return status;
        }

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderList_GetFTDIDescriptionByIndex")]
        private static extern DL_STATUS GetFTDIDescriptionByIndex(UInt32 DeviceIndex, out IntPtr DeviceDescription);
        public static DL_STATUS ReaderList_GetFTDIDescriptionByIndex(UInt32 DeviceIndex, out string DeviceDescription)
        {
            IntPtr ptr;
            DL_STATUS status = DL_STATUS.UFR_OK;

            status = GetFTDIDescriptionByIndex(DeviceIndex, out ptr);
            DeviceDescription = Marshal.PtrToStringAnsi(ptr);
            return status;
        }

        //---------------------------------------------------------------------

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderList_OpenByIndex")]
        public static extern DL_STATUS ReaderList_OpenByIndex(Int32 DeviceIndex, out UFR_HANDLE hndUFR);

        //---------------------------------------------------------------------
        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "GetDllVersion")]
        public static extern UInt32 GetDllVersion();

        //---------------------------------------------------------------------
        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "GetReaderHardwareVersion")]
        public static extern DL_STATUS GetReaderHardwareVersion(out byte version_major, out byte version_minor);

        //---------------------------------------------------------------------
        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "GetReaderFirmwareVersion")]
        public static extern DL_STATUS GetReaderFirmwareVersion(out byte version_major, out byte version_minor);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "GetBuildNumber")]
        public static extern DL_STATUS GetBuildNumber(out byte build);

        //---------------------------------------------------------------------
        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "SectorTrailerWriteUnsafe_PK")]
        public static extern DL_STATUS SectorTrailerWriteUnsafe_PK(byte addressing_mode, byte address, out byte sector_trailer,
                                                  byte auth_mode, ref byte key);
        //---------------------------------------------------------------------
        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "LinearWrite_PK")]
        public static extern DL_STATUS LinearWrite_PK(out byte data, ushort linear_address, ushort length, out ushort bytes_written,
                                     byte auth_mode, ref byte key);
        //---------------------------------------------------------------------
        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "EE_Lock")]
        private static extern DL_STATUS Linkage_EE_Lock(StringBuilder password, UInt32 locked);
        public static DL_STATUS EE_Lock(String password, UInt32 locked)
        {
            if (password.Length != 8)
                return DL_STATUS.UFR_PARAMETERS_ERROR;

            StringBuilder ptr_password = new StringBuilder(password);
            return Linkage_EE_Lock(ptr_password, locked);
        }

        //--------------------------------------------------------------------------------------------------------------

        //[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderOpen")]
        //public static extern DL_STATUS ReaderOpen();

        //[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderClose")]
        //public static extern DL_STATUS ReaderClose();

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ReaderReset")]
        public static extern DL_STATUS ReaderReset();

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ReaderSoftRestart")]
        public static extern DL_STATUS ReaderSoftRestart();

        //--------------------------------------------------------------------------------------------------------------

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "UfrEnterSleepMode")]
        public static extern DL_STATUS UfrEnterSleepMode();

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "UfrLeaveSleepMode")]
        public static extern DL_STATUS UfrLeaveSleepMode();

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "AutoSleepSet")]
        public static extern DL_STATUS AutoSleepSet(byte seconds_wait);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "AutoSleepGet")]
        public static extern DL_STATUS AutoSleepGet(out byte seconds_wait);

        //[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "GetReaderType")]
        //public static extern DL_STATUS GetReaderType(out UInt32 get_reader_type);

        //[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "GetReaderSerialDescription")]
        //public static extern DL_STATUS GetReaderSerialDescription(out byte pSerialDescription);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "GetReaderSerialNumber")]
        public static extern DL_STATUS GetReaderSerialNumber(out UInt32 serial_number);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ReaderKeyWrite")]
        public static extern DL_STATUS ReaderKeyWrite(out byte aucKey, byte ucKeyIndex);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ReaderUISignal")]
        public static extern DL_STATUS ReaderUISignal(int light_mode, int sound_mode);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ReadUserData")]
        public static extern DL_STATUS ReadUserData(out byte aucData);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "WriteUserData")]
        public static extern DL_STATUS WriteUserData(out byte aucData);

        //[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "GetReaderHardwareVersion")]
        //public static extern DL_STATUS GetReaderHardwareVersion(out byte bVerMajor,
        //                                                        out byte bVerMinor);
        //[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "GetReaderFirmwareVersion")]
        //public static extern DL_STATUS GetReaderFirmwareVersion(out byte bVerMajor,
        //                                                        out byte bVerMinor);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "SetDisplayData")]
        public static extern DL_STATUS SetDisplayData(out byte display_data, byte data_length);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "SetSpeakerFrequency")]
        public static extern DL_STATUS SetSpeakerFrequency(short fhz);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "SetDisplayIntensity")]
        public static extern DL_STATUS SetDisplayIntensity(Byte intensity); // 0 to 100 [%]

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "GetDisplayIntensity")]
        public static extern DL_STATUS GetDisplayIntensity(out Byte intensity); // 0 to 100 [%]
        //--------------------------------------------------------------------------------------------------------------

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "GetCardIdEx")]
        public static extern DL_STATUS GetCardIdEx(out byte bCardType,
                                                   [In, Out] byte[] nfc_uid, // NFC_UID_MAX_LEN = 10
                                                   out byte bUidSize);

        //[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "GetDlogicCardType")]
        //public static extern DL_STATUS GetDlogicCardType(out byte lpucCardType);

        //--------------------------------------------------------------------------------------------------------------

        //[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderList_UpdateAndGetCount")]
        //public static extern DL_STATUS ReaderList_UpdateAndGetCount(Int32* NumberOfDevices);

        //[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderList_GetSerialByIndex")]
        //public static extern DL_STATUS ReaderList_GetSerialByIndex(Int32 DeviceIndex, UInt32* lpulSerialNumber);

        //[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderList_GetSerialDesByIndex")]
        //public static extern DL_STATUS ReaderList_GetSerialDescriptionByIndex(Int32 DeviceIndex, char* pSerialDescription);

        //[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderList_GetTypeByIndex")]
        //public static extern DL_STATUS ReaderList_GetTypeByIndex(Int32 DeviceIndex, UInt32* lpulReaderType);

        //[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderList_GetFTDISerialByIndex")]
        //public static extern DL_STATUS ReaderList_GetFTDISerialByIndex(Int32 DeviceIndex, char** Device_Serial);

        //[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, EntryPoint = "ReaderList_GetFTDIDescriptionByIndex")]
        //public static extern DL_STATUS ReaderList_GetFTDIDescriptionByIndex(Int32 DeviceIndex, char** Device_Description);

        //--------------------------------------------------------------------------------------------------------------

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "LinearRead")]
        public static extern DL_STATUS LinearRead(out byte aucData,
                                                  ushort linear_address,
                                                  ushort data_len,
                                                  out UInt16 bytes_written,
                                                  byte auth_mode,
                                                  byte key_index);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "LinearRead_AKM1")]
        public static extern DL_STATUS LinearRead_AKM1(out byte aucData,
                                                   ushort linear_address,
                                                   ushort data_len,
                                                   out UInt16 bytes_written,
                                                   byte key_mode);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "LinearRead_AKM2")]
        public static extern DL_STATUS LinearRead_AKM2(out byte aucData,
                                                   ushort linear_address,
                                                   ushort data_len,
                                                   out UInt16 bytes_written,
                                                   byte key_mode);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "LinearRead_PK")]
        public static extern DL_STATUS LinearRead_PK(out byte aucData,
                                                   ushort linear_address,
                                                   ushort data_len,
                                                   out UInt16 bytes_written,
                                                   byte key_mode,
                                                   out byte pk_key);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "LinearWrite")]
        public static extern DL_STATUS LinearWrite(out byte aucData,
                                                    ushort linear_address,
                                                    ushort data_len,
                                                    out UInt16 bytes_written,
                                                    byte auth_mode,
                                                    byte key_index);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "LinearWrite_AKM1")]
        public static extern DL_STATUS LinearWrite_AKM1(out byte aucData,
                                                    ushort linear_address,
                                                    ushort data_len,
                                                    out UInt16 bytes_written,
                                                    byte auth_mode);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "LinearWrite_AKM2")]
        public static extern DL_STATUS LinearWrite_AKM2(out byte aucData,
                                                    ushort linear_address,
                                                    ushort data_len,
                                                    out UInt16 bytes_written,
                                                    byte auth_mode);

        //[DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "LinearWrite_PK")]
        //public static extern DL_STATUS LinearWrite_PK(out byte aucData,
        //                                           ushort linear_address,
        //                                           ushort data_len,
        //                                           out UInt16 bytes_written,
        //                                           byte key_mode,
        //                                           out byte pk_key);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockRead")]
        public static extern DL_STATUS BlockRead(out byte data,
                                                  UInt16 block_address,
                                                  byte auth_mode,
                                                  byte key_index);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockRead_AKM1")]
        public static extern DL_STATUS BlockRead_AKM1(out byte data,
                                                      UInt16 block_address,
                                                      byte auth_mode);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockRead_AKM2")]
        public static extern DL_STATUS BlockRead_AKM2(out byte data,
                                                      UInt16 block_address,
                                                      byte auth_mode);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockRead_PK")]
        public static extern DL_STATUS BlockRead_PK(out byte data,
                                                    UInt16 block_address,
                                                    byte auth_mode,
                                                    out byte pk_key);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockWrite")]
        public static extern DL_STATUS BlockWrite(out byte data,
                                                  UInt16 block_address,
                                                  byte auth_mode,
                                                  byte key_index);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockWrite_AKM1")]
        public static extern DL_STATUS BlockWrite_AKM1(out byte data,
                                                       UInt16 block_address,
                                                       byte auth_mode);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockWrite_AKM2")]
        public static extern DL_STATUS BlockWrite_AKM2(out byte data,
                                                       UInt16 block_address,
                                                       byte auth_mode);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockWrite_PK")]
        public static extern DL_STATUS BlockWrite_PK(out byte data,
                                                     UInt16 block_address,
                                                     byte auth_mode,
                                                     out byte pk_key);



        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockInSectorRead")]
        public static extern DL_STATUS BlockInSectorRead(out byte data,
                                                         byte sector_address,
                                                         byte block_in_sector_address,
                                                         byte auth_mode, byte key_index);


        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockInSectorRead_AKM1")]
        public static extern DL_STATUS BlockInSectorRead_AKM1(out byte data,
                                                              byte sector_address,
                                                              byte block_in_sector_address,
                                                              byte auth_mode);


        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockInSectorRead_AKM2")]
        public static extern DL_STATUS BlockInSectorRead_AKM2(out byte data,
                                                              byte sector_address,
                                                              byte block_in_sector_address,
                                                              byte auth_mode);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockInSectorRead_PK")]
        public static extern DL_STATUS BlockInSectorRead_PK(out byte data,
                                                            byte sector_address,
                                                            byte block_in_sector_address,
                                                            byte auth_mode,
                                                            out byte pk_key);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockInSectorWrite")]
        public static extern DL_STATUS BlockInSectorWrite(out byte data,
                                                          byte sector_address,
                                                          byte block_in_sector_address,
                                                          byte auth_mode,
                                                          byte key_index);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockInSectorWrite_AKM1")]
        public static extern DL_STATUS BlockInSectorWrite_AKM1(out byte data,
                                                               byte sector_address,
                                                               byte block_in_sector_address,
                                                               byte auth_mode);


        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockInSectorWrite_AKM2")]
        public static extern DL_STATUS BlockInSectorWrite_AKM2(out byte data,
                                                               byte sector_address,
                                                               byte block_in_sector_address,
                                                               byte auth_mode);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "BlockInSectorWrite_PK")]
        public static extern DL_STATUS BlockInSectorWrite_PK(out byte data,
                                                             byte sector_address,
                                                             byte block_in_sector_address,
                                                             byte auth_mode,
                                                             out byte pk_key);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockRead")]
        public static extern DL_STATUS ValueBlockRead(out Int32 value,
                                                        out byte value_addr,
                                                        UInt16 block_address,
                                                        byte auth_mode,
                                                        byte key_index);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockRead_AKM1")]
        public static extern DL_STATUS ValueBlockRead_AKM1(out Int32 value,
                                                           out byte value_addr,
                                                           UInt16 block_address,
                                                           byte auth_mode);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockRead_AKM2")]
        public static extern DL_STATUS ValueBlockRead_AKM2(out Int32 value,
                                                           out byte value_addr,
                                                           UInt16 block_address,
                                                           byte auth_mode);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockRead_PK")]
        public static extern DL_STATUS ValueBlockRead_PK(out Int32 value,
                                                         out byte value_addr,
                                                         UInt16 block_address,
                                                         byte auth_mode,
                                                         out byte pk_key);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockWrite")]
        public static extern DL_STATUS ValueBlockWrite(int value,
                                                        byte value_addr,
                                                        UInt16 block_address,
                                                        byte auth_mode,
                                                        byte key_index);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockWrite_AKM1")]
        public static extern DL_STATUS ValueBlockWrite_AKM1(int value,
                                                        byte value_addr,
                                                        UInt16 block_address,
                                                        byte auth_mode);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockWrite_AKM2")]
        public static extern DL_STATUS ValueBlockWrite_AKM2(int value,
                                                        byte value_addr,
                                                        UInt16 block_address,
                                                        byte auth_mode);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockWrite_PK")]
        public static extern DL_STATUS ValueBlockWrite_PK(int value,
                                                        byte value_addr,
                                                        UInt16 block_address,
                                                        byte auth_mode,
                                                        out byte pk_key);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockIncrement")]
        public static extern DL_STATUS ValueBlockIncrement(int increment_value,
                                                            UInt16 block_address,
                                                            byte auth_mode,
                                                            byte key_index);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockIncrement_AKM1")]
        public static extern DL_STATUS ValueBlockIncrement_AKM1(int increment_value,
                                                                UInt16 block_address,
                                                                byte auth_mode);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockIncrement_AKM2")]
        public static extern DL_STATUS ValueBlockIncrement_AKM2(int increment_value,
                                                                UInt16 block_address,
                                                                byte auth_mode);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockIncrement_PK")]
        public static extern DL_STATUS ValueBlockIncrement_PK(int increment_value,
                                                                UInt16 block_address,
                                                                byte auth_mode,
                                                                out byte pk_key);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockDecrement")]
        public static extern DL_STATUS ValueBlockDecrement(int increment_value,
                                                           UInt16 block_address,
                                                           byte auth_mode,
                                                             byte key_index);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockDecrement_AKM1")]
        public static extern DL_STATUS ValueBlockDecrement_AKM1(int increment_value,
                                                                UInt16 block_address,
                                                                byte auth_mode);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockDecrement_AKM2")]
        public static extern DL_STATUS ValueBlockDecrement_AKM2(int increment_value,
                                                                UInt16 block_address,
                                                                byte auth_mode);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockDecrement_PK")]
        public static extern DL_STATUS ValueBlockDecrement_PK(int increment_value,
                                                              UInt16 block_address,
                                                              byte auth_mode,
                                                              out byte pk_key);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorRead")]
        public static extern DL_STATUS ValueBlockInSectorRead(out Int32 value,
                                                                 out byte value_addr,
                                                                 byte sector_address,
                                                                 byte block_in_sector_address,
                                                                 byte auth_mode,
                                                                 byte key_index);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorRead_AKM1")]
        public static extern DL_STATUS ValueBlockInSectorRead_AKM1(out Int32 value,
                                                                 out byte value_addr,
                                                                 byte sector_address,
                                                                 byte block_in_sector_address,
                                                                 byte auth_mode);


        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorRead_AKM2")]
        public static extern DL_STATUS ValueBlockInSectorRead_AKM2(out Int32 value,
                                                                 out byte value_addr,
                                                                 byte sector_address,
                                                                 byte block_in_sector_address,
                                                                 byte auth_mode);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorRead_PK")]
        public static extern DL_STATUS ValueBlockInSectorRead_PK(out Int32 value,
                                                                 out byte value_addr,
                                                                 byte sector_address,
                                                                 byte block_in_sector_address,
                                                                 byte auth_mode,
                                                                 out byte pk_key);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorWrite")]
        public static extern DL_STATUS ValueBlockInSectorWrite(Int32 value,
                                                               byte value_addr,
                                                               byte sector_address,
                                                               byte block_in_sector_address,
                                                               byte auth_mode, byte key_index);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorWrite_AKM1")]
        public static extern DL_STATUS ValueBlockInSectorWrite_AKM1(Int32 value,
                                                               byte value_addr,
                                                               byte sector_address,
                                                               byte block_in_sector_address,
                                                               byte auth_mode);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorWrite_AKM2")]
        public static extern DL_STATUS ValueBlockInSectorWrite_AKM2(Int32 value,
                                                               byte value_addr,
                                                               byte sector_address,
                                                               byte block_in_sector_address,
                                                               byte auth_mode);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorWrite_PK")]
        public static extern DL_STATUS ValueBlockInSectorWrite_PK(Int32 value,
                                                               byte value_addr,
                                                               byte sector_address,
                                                               byte block_in_sector_address,
                                                               byte auth_mode,
                                                               out byte pk_key);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorIncrement")]
        public static extern DL_STATUS ValueBlockInSectorIncrement(Int32 increment_value,
                                                                    byte sector_address,
                                                                    byte block_in_sector_address,
                                                                    byte auth_mode,
                                                                    byte key_index);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorIncrement_AKM1")]
        public static extern DL_STATUS ValueBlockInSectorIncrement_AKM1(Int32 increment_value,
                                                                    byte sector_address,
                                                                    byte block_in_sector_address,
                                                                    byte auth_mode);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorIncrement_AKM2")]
        public static extern DL_STATUS ValueBlockInSectorIncrement_AKM2(Int32 increment_value,
                                                                    byte sector_address,
                                                                    byte block_in_sector_address,
                                                                    byte auth_mode);


        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorIncrement_PK")]
        public static extern DL_STATUS ValueBlockInSectorIncrement_PK(Int32 increment_value,
                                                                    byte sector_address,
                                                                    byte block_in_sector_address,
                                                                    byte auth_mode,
                                                                    out byte pk_key);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorDecrement")]
        public static extern DL_STATUS ValueBlockInSectorDecrement(Int32 decrement_value,
                                                                    byte sector_address,
                                                                    byte block_in_sector_address,
                                                                    byte auth_mode,
                                                                    byte key_index);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorDecrement_AKM1")]
        public static extern DL_STATUS ValueBlockInSectorDecrement_AKM1(Int32 decrement_value,
                                                                    byte sector_address,
                                                                    byte block_in_sector_address,
                                                                    byte auth_mode);


        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorDecrement_AKM2")]
        public static extern DL_STATUS ValueBlockInSectorDecrement_AKM2(Int32 decrement_value,
                                                                    byte sector_address,
                                                                    byte block_in_sector_address,
                                                                    byte auth_mode);


        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "ValueBlockInSectorDecrement_PK")]
        public static extern DL_STATUS ValueBlockInSectorDecrement_PK(Int32 decrement_value,
                                                                    byte sector_address,
                                                                    byte block_in_sector_address,
                                                                    byte auth_mode,
                                                                    out byte pk_key);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "SectorTrailerWrite")]
        public static extern DL_STATUS SectorTrailerWrite(byte addressing_mode,
                                        byte address,
                                        out byte new_key_A,
                                        byte block0_access_bits,
                                        byte block1_access_bits,
                                        byte block2_access_bits,
                                        byte sector_trailer_access_bits,
                                        byte sector_trailer_byte9,
                                        out byte new_key_B,
                                        byte auth_mode,
                                        byte key_index);

        [DllImport(DLL_NAME, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto, EntryPoint = "SectorTrailerWrite_AKM1")]
        public static extern DL_STATUS SectorTrailerWrite_AKM1(byte addressing_mode,
                                        byte address,
                                        out byte new_key_A,
                                        byte block0_access_bits,
                                        byte block1_access_bits,
                                        byte block2_access_bits,
                                        byte sector_trailer_access_bits,
                                        byte sector_trailer_byte9,
                                        out byte new_key_B,
                                        byte auth_mode);