

package ufcodersimpleapplet;
import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Platform;
import com.sun.jna.ptr.ByteByReference;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.ShortByReference;

public class Declarations extends uFCoderSimpleApplet
{ 
     public enum DLCARDTYPE {

        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_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);
        
        private int enumValue;
        private DLCARDTYPE(int value){
            this.enumValue=value;          
        }
        public int getValue(){
            return enumValue;
        }
    } 
     
     
    public enum ERRORCODES {
        
        DL_OK                                    (0x00),
        COMMUNICATION_ERROR                      (0x01),
        CHKSUM_ERROR                             (0x02),
        READING_ERROR                            (0x03),
        WRITING_ERROR                            (0x04),
              
        BUFFER_OVERFLOW                          (0x05),
        MAX_ADDRESS_EXCEEDED                     (0x06),
        MAX_KEY_INDEX_EXCEEDED                   (0x07),
        NO_CARD                                  (0x08),
        COMMAND_NOT_SUPPORTED                    (0x09),       
        FORBIDEN_DIRECT_WRITE_IN_SECTOR_TRAILER  (0x0A),
        ADDRESSED_BLOCK_IS_NOT_SECTOR_TRAILER    (0x0B),
        WRONG_ADDRESS_MODE                       (0x0C),
        WRONG_ACCESS_BITS_VALUES                 (0x0D),
        AUTH_ERROR                               (0x0E),
        PARAMETERS_ERROR                         (0x0F),
        MAX_SIZE_EXCEEDED                        (0x10),
        UNSUPPORTED_CARD_TYPE                    (0x11),        
        COMMUNICATION_BREAK                      (0x50),
        NO_MEMORY_ERROR                          (0x51),        
        CAN_NOT_OPEN_READER                      (0x52),
        READER_NOT_SUPPORTED                     (0x53),
        READER_OPENING_ERROR                     (0x54),
        READER_PORT_NOT_OPENED                   (0x55),
        CANT_CLOSE_READER_PORT                   (0x56),
        
        WRITE_VERIFICATION_ERROR                 (0x70),
        BUFFER_SIZE_EXCEEDED                     (0x71),
        VALUE_BLOCK_INVALID                      (0x72),
        VALUE_BLOCK_ADDR_INVALID                 (0x73),
        VALUE_BLOCK_MANIPULATION_ERROR           (0x74),
        WRONG_UI_MODE                            (0x75),
        KEYS_LOCKED                              (0x76),
        KEYS_UNLOCKED                            (0x77),
        WRONG_PASSWORD                           (0x78),
        CAN_NOT_LOCK_DEVICE                      (0x79),
        CAN_NOT_UNLOCK_DEVICE                    (0x7A),
        DEVICE_EEPROM_BUSY                       (0x7B),
        RTC_SET_ERROR                            (0x7C),
        ANTICOLLISION_DISABLED                   (0x7D),
        NO_CARDS_ENUMERRATED                     (0x7E),
        CARD_ALREADY_SELECTED                    (0x7F),
                       
        FT_STATUS_ERROR_1                        (0xA0),
        FT_STATUS_ERROR_2                        (0xA1),
	FT_STATUS_ERROR_3                        (0xA2),
	FT_STATUS_ERROR_4                        (0xA3),
	FT_STATUS_ERROR_5                        (0xA4),
	FT_STATUS_ERROR_6                        (0xA5),
	FT_STATUS_ERROR_7                        (0xA6),
	FT_STATUS_ERROR_8                        (0xA7),
	FT_STATUS_ERROR_9                        (0xA8);

	      
        private int value;

        private ERRORCODES(int value) {
                this.value = value;
        }
        public int getValue(){
            return value;
        }
        
    }
       
     protected static String sPlatformType = "";

    /**
     * specifies the type of platform 1: isLinux() 2: isWindows()
     *
     * @return .so or .dll name based on the platform as String type
     */
   
    
    static public String GetPlatformType() {
        int os_type = Platform.getOSType();

        String lib_name = "uFCoder1x";
        String prefix = "";
        String postfix = "";
        String extension = "";

        switch (os_type) {
            case Platform.LINUX:
                prefix = "lib";
                extension = "so";
                break;

            case Platform.WINDOWS:
                prefix = "";
                extension = "dll";
                break;
        }

        if (Platform.isARM()) {
            postfix = "arm";
        } else if (Platform.isPPC()) {
            postfix = "ppc";
        } else if (Platform.isIntel()) {
            postfix = "x86";
        }

        if (Platform.is64Bit()) {
            postfix += "-64bit";
        }

        sPlatformType = prefix + lib_name + "-" + postfix + "." + extension;

        return sPlatformType;
    }
      
        
        
        
  public interface uFrFunction extends Library
  {              
    uFrFunction UFrInstance=(uFrFunction)Native.loadLibrary(GetPlatformType(),uFrFunction.class);
    int ReaderOpen();
    int ReaderClose();
    
    int GetReaderType(int[] iaReaderType);
    int GetReaderSerialNumber(int[] iaReaderSerial);
    
    int GetCardId(ByteByReference card_id,IntByReference card_serial);    
    int GetCardIdEx(ByteByReference bCardType,byte[] bCardUID,ByteByReference bCardUIDSize);
    int GetDlogicCardType(ByteByReference bDLCardType);
    int ReaderUISignal(int light_mode,int sound_mode);
    
    int LinearRead(byte[] aucdata,int linear_address,int data_length,ShortByReference bytes_ret,byte auth_mode,byte key_index);
    int LinearWrite(byte[] aucdata,int linear_address,int data_length,ShortByReference bytes_written,byte auth_mode,byte key_index);

    
    int LinearFormatCard(byte[]key_a,byte block_access_bits,byte sector_access_bits,byte sector_trailers_byte9,
                         byte[]key_b,ShortByReference sector_formatted,byte auth_mode,byte key_index);
    int ReaderKeyWrite(byte[]reader_key,byte key_index);
  }
}
