/***********************************************************************************************
* Superpro.cs
*
* Developed by     : SafeNet, Inc
*
* Copyright (C) 2009 SafeNet, Inc. All rights reserved.
*
* Description - This module provide defination and wrappers for 
*               SuperPro Dual Client Library APIs.
*
* Revision 1.1 - Added new error codes and API's for 6.1
* Revision 1.2 - Added new API's and constants's for 6.2.0
* Revision 1.3 - Added new API's and constants 6.4.0
* Revision 1.4 - Added new API, constants and updated Shell error codes for 6.5.0
* Revision 1.5 - Added new API's, constants and error codes for 6.6.0
* Revision 1.6 - Added new API's, constants and error codes for 7.0.0
* Revision 1.7 - Update NSPRO_KEY_MONITOR_INFO_EX, constants and error codes for 7.1.0
***********************************************************************************************/
using System;
public class Superpro : IDisposable
{
    #region Constructor / Destructor
    /* Define API packet for communication   */
    public static uint SPRO_APIPACKET_SIZE = 1028;
    private byte[] packet;
    private bool disposed;

    private string strError = "Unable to load the required SuperPro Library(sx32w.dll).\n" +
       "Either the library is missing or corrupted.";

    public Superpro()
    {
        packet = new byte[SPRO_APIPACKET_SIZE];
    }
    ~Superpro()
    {
        Dispose(false);
    }

    /* Implement IDisposable */
    public void Dispose()
    {
        Dispose(true);
        GC.SuppressFinalize(this);
    }
    /* Private class specifically for this object.*/
    protected virtual void Dispose(bool disposing)
    {
        if (!this.disposed)
        {
            if (disposing)
            {
                this.packet = null;
                /* only MANAGED resource should be dispose     */
                /* here that implement the IDisposable         */
                /* Interface                                    */
            }
            /* only UNMANAGED resource should be dispose here */
            /*                                                */
        }
        disposed = true;
    }
    #endregion

    #region Superpro API Error Codes
    /* Superpro API Error codes */

    public const int SP_SUCCESS = 0;
    public const int SP_INVALID_FUNCTION_CODE = 1;
    public const int SP_INVALID_PACKET = 2;
    public const int SP_UNIT_NOT_FOUND = 3;
    public const int SP_ACCESS_DENIED = 4;
    public const int SP_INVALID_MEMORY_ADDRESS = 5;
    public const int SP_INVALID_ACCESS_CODE = 6;
    public const int SP_PORT_IS_BUSY = 7;
    public const int SP_WRITE_NOT_READY = 8;
    public const int SP_NO_PORT_FOUND = 9;
    public const int SP_ALREADY_ZERO = 10;
    public const int SP_DRIVER_OPEN_ERROR = 11;
    public const int SP_DRIVER_NOT_INSTALLED = 12;
    public const int SP_IO_COMMUNICATIONS_ERROR = 13;
    public const int SP_PACKET_TOO_SMALL = 15;
    public const int SP_INVALID_PARAMETER = 16;
    public const int SP_MEM_ACCESS_ERROR = 17;
    public const int SP_VERSION_NOT_SUPPORTED = 18;
    public const int SP_OS_NOT_SUPPORTED = 19;
    public const int SP_QUERY_TOO_LONG = 20;
    public const int SP_INVALID_COMMAND = 21;
    public const int SP_MEM_ALIGNMENT_ERROR = 29;
    public const int SP_DRIVER_IS_BUSY = 30;
    public const int SP_PORT_ALLOCATION_FAILURE = 31;
    public const int SP_PORT_RELEASE_FAILURE = 32;
    public const int SP_ACQUIRE_PORT_TIMEOUT = 39;
    public const int SP_SIGNAL_NOT_SUPPORTED = 42;
    public const int SP_UNKNOWN_MACHINE = 44;
    public const int SP_SYS_API_ERROR = 45;
    public const int SP_UNIT_IS_BUSY = 46;
    public const int SP_INVALID_PORT_TYPE = 47;
    public const int SP_INVALID_MACH_TYPE = 48;
    public const int SP_INVALID_IRQ_MASK = 49;
    public const int SP_INVALID_CONT_METHOD = 50;
    public const int SP_INVALID_PORT_FLAGS = 51;
    public const int SP_INVALID_LOG_PORT_CFG = 52;
    public const int SP_INVALID_OS_TYPE = 53;
    public const int SP_INVALID_LOG_PORT_NUM = 54;
    public const int SP_INVALID_ROUTER_FLGS = 56;
    public const int SP_INIT_NOT_CALLED = 57;
    public const int SP_DRVR_TYPE_NOT_SUPPORTED = 58;
    public const int SP_FAIL_ON_DRIVER_COMM = 59;

    /* Networking Error Codes */

    public const int SP_SERVER_PROBABLY_NOT_UP = 60;
    public const int SP_UNKNOWN_HOST = 61;
    public const int SP_SENDTO_FAILED = 62;
    public const int SP_SOCKET_CREATION_FAILED = 63;
    public const int SP_NORESOURCES = 64;
    public const int SP_BROADCAST_NOT_SUPPORTED = 65;
    public const int SP_BAD_SERVER_MESSAGE = 66;
    public const int SP_NO_SERVER_RUNNING = 67;
    public const int SP_NO_NETWORK = 68;
    public const int SP_NO_SERVER_RESPONSE = 69;
    public const int SP_NO_LICENSE_AVAILABLE = 70;
    public const int SP_INVALID_LICENSE = 71;
    public const int SP_INVALID_OPERATION = 72;
    public const int SP_BUFFER_TOO_SMALL = 73;
    public const int SP_INTERNAL_ERROR = 74;
    public const int SP_PACKET_ALREADY_INITIALIZED = 75;
    public const int SP_PROTOCOL_NOT_INSTALLED = 76;


    public const int SP_NO_LEASE_FEATURE = 101;
    public const int SP_LEASE_EXPIRED = 102;
    public const int SP_COUNTER_LIMIT_REACHED = 103;
    public const int SP_NO_DIGITAL_SIGNATURE = 104;
    public const int SP_SYS_FILE_CORRUPTED = 105;
    public const int SP_STRING_BUFFER_TOO_LONG = 106;
    public const int SP_INVALID_DEV_CODE = 107;
    public const int SP_DEVID_DOES_NOT_MATCH = 108;
    public const int SP_DEVICE_SHARING_DETECTED = 109;
    public const int SP_SERVER_VERSION_NOT_SUPPORTED = 110;
    public const int SP_FILE_NOT_FOUND = 111;
    public const int SP_PATH_TOO_LONG = 112;
    public const int SP_SOFT_DB_CORRUPT = 113;
    public const int SP_SOFT_DB_RESTORE_DETECTED = 114;
    public const int SP_PRST_DATA_CORRUPT = 115;
    public const int SP_SECURITY_RUNTIME_NOT_DETECTED = 116;
    public const int SP_TIME_TAMPER_DETECTED = 117;
    public const int SP_END_DATE_REACHED = 118;
    public const int SP_START_DATE_NOT_REACHED = 119;
    public const int SP_HOST_ID_ERROR = 120;
    public const int SP_LIC_INVALID = 121;
    public const int SP_LIC_RUN_TIME_ERROR = 122;
    public const int SP_LIC_MEMORY_CORRUPTED = 123;
    public const int SP_NOT_ENOUGH_MEMORY = 124;
    public const int SP_IP_ADDRESS_BLOCKED = 125;
    public const int SP_SERVER_OUT_OF_WORKING_TIME = 126;
    public const int SP_SECURITY_RUNTIME_VERSION_MISMATCH = 127;

    /* CodeCover Error Codes */

    public const int SH_SP_BAD_ALGO = 401;
    public const int SH_SP_LONG_MSG = 402;
    public const int SH_SP_READ_ERROR = 403;
    public const int SH_SP_NOT_ENOUGH_MEMORY = 404;
    public const int SH_SP_CANNOT_OPEN = 405;
    public const int SH_SP_WRITE_ERROR = 406;
    public const int SH_SP_CANNOT_OVERWRITE = 407;
    public const int SH_SP_INVALID_HEADER = 408;
    public const int SH_SP_TMP_CREATE_ERROR = 409;
    public const int SH_SP_PATH_NOT_THERE = 410;
    public const int SH_SP_BAD_FILE_INFO = 411;
    public const int SH_SP_NOT_WIN32_FILE = 412;
    public const int SH_SP_INVALID_MACHINE = 413;
    public const int SH_SP_INVALID_SECTION = 414;
    public const int SH_SP_INVALID_RELOC = 415;
    public const int SH_SP_CRYPT_ERROR = 416;
    public const int SH_SP_SMARTHEAP_ERROR = 417;
    public const int SH_SP_IMPORT_OVERWRITE_ERROR = 418;
    public const int SH_SP_NO_PESHELL = 420;
    public const int SH_SP_FRAMEWORK_REQUIRED = 421;
    public const int SH_SP_CANNOT_HANDLE_FILE = 422;
    public const int SH_SP_IMPORT_DLL_ERROR = 423;
    public const int SH_SP_IMPORT_FUNCTION_ERROR = 424;
    public const int SH_SP_X64_SHELL_ENGINE = 425;
    public const int SH_SP_STRONG_NAME = 426;
    public const int SH_SP_FRAMEWORK_10 = 427;
    public const int SH_SP_FRAMEWORK_SDK_10 = 428;
    public const int SH_SP_FRAMEWORK_11 = 429;
    public const int SH_SP_FRAMEWORK_SDK_11 = 430;
    public const int SH_SP_FRAMEWORK_20_OR_30 = 431;
    public const int SH_SP_FRAMEWORK_SDK_20 = 432;
    public const int SH_SP_APP_NOT_SUPPORTED = 433;
    public const int SH_SP_FILE_COPY = 434;
    public const int SH_SP_HEADER_SIZE_EXCEED = 435;
    public const int SH_SP_SGEN = 436;
    public const int SH_SP_CODE_MORPHING = 437;

    #endregion

    #region SuperPro Constants values used by client application.
    /* Set Protocol Flags */
    public enum PROTOCOL_FLAG
    {
        NSPRO_TCP_PROTOCOL = 1,
        NSPRO_IPX_PROTOCOL = 2,
        NSPRO_NETBEUI_PROTOCOL = 4,
        NSPRO_SAP_PROTOCOL = 8
    }

    /* Enum server falgs */
    public enum ENUM_SERVER_FLAG
    {
        NSPRO_RET_ON_FIRST = 1,
        NSPRO_GET_ALL_SERVERS = 2,
        NSPRO_RET_ON_FIRST_AVAILABLE = 4
    }

    /* Key Monitoring Information */
    public class NSPRO_KEY_MONITOR_INFO
    {
        public ushort developerId;
        public ushort hardLimit;
        public ushort inUse;
        public ushort numTimeOut;
        public ushort highestUse;
    }

    public class RB_SPRO_DATE
    {
        public int year;           // the year
        public byte month;          // the month (1-12)
        public byte day;            // the day of the month (1-31)
    }

    /* Key Monitoring Information Used by NSPRO_MONITOR_INFO_EX */
    public class NSPRO_KEY_MONITOR_INFO_EX
    {
        public uint devId;          // developer id of the key
        public uint serialNum;      // serial number of the key
        public uint capabilities;   // capabilities of the key
        public uint hardLimit;      // hard limit of the key
        public uint inUse;          // number of licenses in use for the key
        public uint numTimeOut;     // number of timeouts recorded for the key
        public uint highestUse;     // highest number of licenses issued from
        public uint subLicLimit;    // the sub-license limit of certain cell
        public uint subLicInUse;    // the number of sub-licenses in use for certain cell
        public uint writePasswordCounter;     // the number of write password counter
        public uint overwritePasswordCounter; //the number of overwrite password counter
        public uint formFactor;     // the form factor of the enum key
        public uint softKeyType;    // software key type
        public RB_SPRO_DATE startDate;    // software key start date
        public RB_SPRO_DATE endDate;      // software key end date

        public NSPRO_KEY_MONITOR_INFO_EX()
        {
            this.startDate = new RB_SPRO_DATE();
            this.endDate = new RB_SPRO_DATE();
            this.startDate.year = 0;           // the year
            this.startDate.month = 0;          // the month (1-12)
            this.startDate.day = 0;  // the day of the month (1-31)
            this.endDate.year = 0;
            this.endDate.month = 0;
            this.endDate.day = 0;
        }
        // the key throughout the life of server
        //public uint reserved;       // reserved for future use
    }

    /* Monitoring Information Returned by RNBOsproGetKeyInfo */
    public class NSPRO_MONITOR_INFO
    {
        public byte[] serverName;
        public byte[] serverIPAddress;
        public byte[] serverIPXAddress;
        public byte[] version;
        public ushort protocol;
        public NSPRO_KEY_MONITOR_INFO sproKeyMonitorInfo;

        public NSPRO_MONITOR_INFO()
        {
            this.serverName = new byte[Superpro.MAX_NAME_LEN];
            this.serverIPAddress = new byte[Superpro.MAX_ADDR_LEN];
            this.serverIPXAddress = new byte[Superpro.MAX_ADDR_LEN];
            this.version = new byte[Superpro.MAX_NAME_LEN];
            this.sproKeyMonitorInfo = new NSPRO_KEY_MONITOR_INFO();
            this.sproKeyMonitorInfo.developerId = 0;
            this.sproKeyMonitorInfo.hardLimit = 0;
            this.sproKeyMonitorInfo.inUse = 0;
            this.sproKeyMonitorInfo.numTimeOut = 0;
            this.sproKeyMonitorInfo.highestUse = 0;
        }

        public void GetKeyInfo(byte[] bBuffer)
        {
            int index;
            int j = 0;
            int offset = 0;

            for (index = 0; index < Superpro.MAX_NAME_LEN; index++)
                this.serverName[j++] = bBuffer[index];
            offset = index;
            j = 0;
            for (index = offset; index < (Superpro.MAX_ADDR_LEN + offset); index++)
                this.serverIPAddress[j++] = bBuffer[index];

            offset = index;
            j = 0;
            for (index = offset; index < (Superpro.MAX_ADDR_LEN + offset); index++)
                this.serverIPXAddress[j++] = bBuffer[index];

            offset = index;
            j = 0;
            for (index = offset; index < (Superpro.MAX_NAME_LEN + offset); index++)
                this.version[j++] = bBuffer[index];

            this.protocol = (ushort)BitConverter.ToInt16(bBuffer, index);
            this.sproKeyMonitorInfo.developerId = (ushort)BitConverter.ToUInt16(bBuffer, index + 2);
            this.sproKeyMonitorInfo.hardLimit = (ushort)BitConverter.ToUInt16(bBuffer, index + 4);
            this.sproKeyMonitorInfo.inUse = (ushort)BitConverter.ToUInt16(bBuffer, index + 6);
            this.sproKeyMonitorInfo.numTimeOut = (ushort)BitConverter.ToUInt16(bBuffer, index + 8);
            this.sproKeyMonitorInfo.highestUse = (ushort)BitConverter.ToUInt16(bBuffer, index + 10);
        }
    }

    /* Monitoring Information Returned by RNBOsproGetKeyInfoEx */
    public class NSPRO_MONITOR_INFO_EX
    {
        public uint size = 280;
        public byte[] serverName;
        public byte[] serverIPAddress;  // Server's IP address
        public byte[] serverIPXAddress; // Server's IPX address
        public byte[] version;          // version of the server
        public uint protocol;               // Protocols supported by the server
        public uint reserved;               // reserved for future use
        public NSPRO_KEY_MONITOR_INFO_EX sproKeyMonitorInfo;

        public NSPRO_MONITOR_INFO_EX()
        {
            serverName = new byte[MAX_NAME_LEN];
            serverIPAddress = new byte[MAX_IPADDR_LEN];
            serverIPXAddress = new byte[MAX_ADDR_LEN];
            version = new byte[MAX_NAME_LEN];
            sproKeyMonitorInfo = new NSPRO_KEY_MONITOR_INFO_EX();
        }

        public void GetKeyInfo(byte[] bBuffer)
        {
            int index;
            int j = 0;
            int offset;

            for (index = 0; index < Superpro.MAX_NAME_LEN; index++)
            {
                serverName[j++] = bBuffer[index];
            }
            offset = index;
            j = 0;
            for (index = offset; index < (Superpro.MAX_IPADDR_LEN + offset); index++)
            {
                serverIPAddress[j++] = bBuffer[index];
            }
            offset = index;
            j = 0;
            for (index = offset; index < (Superpro.MAX_ADDR_LEN + offset); index++)
            {
                serverIPXAddress[j++] = bBuffer[index];
            }
            offset = index;
            j = 0;
            for (index = offset; index < (Superpro.MAX_NAME_LEN + offset); index++)
            {
                version[j++] = bBuffer[index];
            }
            protocol = BitConverter.ToUInt32(bBuffer, index);
            sproKeyMonitorInfo.devId = BitConverter.ToUInt32(bBuffer, index + 8);
            sproKeyMonitorInfo.serialNum = BitConverter.ToUInt32(bBuffer, index + 12);
            sproKeyMonitorInfo.capabilities = BitConverter.ToUInt32(bBuffer, index + 16);
            sproKeyMonitorInfo.hardLimit = BitConverter.ToUInt32(bBuffer, index + 20);
            sproKeyMonitorInfo.inUse = BitConverter.ToUInt32(bBuffer, index + 24);
            sproKeyMonitorInfo.numTimeOut = BitConverter.ToUInt32(bBuffer, index + 28);
            sproKeyMonitorInfo.highestUse = BitConverter.ToUInt32(bBuffer, index + 32);
            sproKeyMonitorInfo.subLicLimit = BitConverter.ToUInt32(bBuffer, index + 36);
            sproKeyMonitorInfo.subLicInUse = BitConverter.ToUInt32(bBuffer, index + 40);
            sproKeyMonitorInfo.writePasswordCounter = bBuffer[index + 44];
            sproKeyMonitorInfo.overwritePasswordCounter = bBuffer[index + 45];
            sproKeyMonitorInfo.formFactor = bBuffer[index + 46];
            sproKeyMonitorInfo.softKeyType = bBuffer[index + 47];
            sproKeyMonitorInfo.startDate.year = BitConverter.ToUInt16(bBuffer,index + 48);
            sproKeyMonitorInfo.startDate.month = bBuffer[index + 50];
            sproKeyMonitorInfo.startDate.day = bBuffer[index + 51];
            sproKeyMonitorInfo.endDate.year = BitConverter.ToUInt16(bBuffer, index + 52);
            sproKeyMonitorInfo.endDate.month = bBuffer[index + 54];
            sproKeyMonitorInfo.endDate.day = bBuffer[index + 55];
        }
    }

    // Class for ServerInfo
    public class NSPRO_SERVER_INFO
    {
        public byte[] serverAddress;
        public ushort numLicAvail;

        public NSPRO_SERVER_INFO()
        {
            serverAddress = new byte[Superpro.MAX_ADDR_LEN];
        }

        public void GetServerInfo(byte[] bBuffer, int offset)
        {
            int j = 0;

            if (bBuffer.Length < Superpro.MAX_ADDR_LEN + offset + 2)
            {
                return;
            }

            for (int i = offset; i < (Superpro.MAX_ADDR_LEN + offset); i++)
            {
                serverAddress[j++] = bBuffer[i];
            }
            this.numLicAvail = BitConverter.ToUInt16(bBuffer, Superpro.MAX_ADDR_LEN + offset);
        }
    }

    /* OS Types */
    public const int RB_MIN_OS_TYPE = 0;
    public const int RB_AUTODETECT_OS_TYPE = 0;    // Autodetect OS type         
    public const int RB_OS_DOS = 1;    // DOS operating system       
    public const int RB_OS_RSRV1 = 2;    // reserved                   
    public const int RB_OS_RSRV2 = 3;    // reserved                   
    public const int RB_OS_WIN3x = 4;    // Windows 3.x operating env  
    public const int RB_OS_WINNT = 5;    // Windows NT operating system
    public const int RB_OS_OS2 = 6;    // OS/2 operating system      
    public const int RB_OS_WIN95 = 7;    // Windows 95 operating system
    public const int RB_OS_WIN32s = 8;    // Windows WIN32s env         
    public const int RB_OS_NW = 9;    // Netware operating system   
    public const int RB_OS_QNX = 10;
    public const int RB_OS_LINUX = 12;   // Linux operating system     
    public const int RB_MAX_OS_TYPE = 12;

    // String for OS Driver type                                                         
    public const int RB_DOSRM_LOCAL_DRVR = 1;    //  DOS Real Mode local driver 
    public const int RB_WIN3x_LOCAL_DRVR = 2;    // Windows 3.x local driver    
    public const int RB_WIN32s_LOCAL_DRVR = 3;    // Win32s local driver         
    public const int RB_WIN3x_SYS_DRVR = 4;    // Windows 3.x system driver   
    public const int RB_WINNT_SYS_DRVR = 5;    // Windows NT system driver    
    public const int RB_OS2_SYS_DRVR = 6;    // OS/2 system driver                   
    public const int RB_WIN95_SYS_DRVR = 7;    // Windows 95 system driver    
    public const int RB_NW_LOCAL_DRVR = 8;    // Netware local driver        
    public const int RB_QNX_LOCAL_DRVR = 9;    // QNX local driver            
    public const int RB_UNIX_SYS_DRVR = 10;   // UNIX local driver           
    public const int RB_SOLARIS_SYS_DRVR = 11;   // SOLARIS local driver        
    public const int RB_LINUX_SYS_DRVR = 12;   // Linux system driver         
    public const int RB_LINUX_LOCAL_DRVR = 13;   // Linux local driver          
    public const int RB_AIX_SYS_DRVR = 14;   // AIX system driver           
    public const int RB_UNIXWARE_SYS_DRVR = 15;   // UNIX system  driver         

    /* Making the License Update Time programmable*/
    public const int LIC_UPDATE_INT = 120;     // Default heartbeat - 2*60 = 2 min.;
    public const int MAX_HEARTBEAT = 2592000; // 30*24*60*60 seconds 
    public const int MIN_HEARTBEAT = 60;      // 60 seconds 
    public const int INFINITE_HEARTBEAT = -1;

    /*Communication Modes */
    public const string RNBO_STANDALONE = "RNBO_STANDALONE";
    public const string RNBO_SPN_LOCAL = "RNBO_SPN_LOCAL";
    public const string RNBO_SPN_DRIVER = "RNBO_SPN_DRIVER";
    public const string RNBO_SPN_BROADCAST = "RNBO_SPN_BROADCAST";
    public const string RNBO_SPN_ALL_MODES = "RNBO_SPN_ALL_MODES";
    public const string RNBO_SPN_SERVER_MODES = "RNBO_SPN_SERVER_MODES";

    /* Sharing Flags */
    public const int SP_SHARE_USERNAME = 1;
    public const int SP_SHARE_MAC_ADDRESS = 2;
    public const int SP_SHARE_DEFAULT = 3;

    /* SuperPro 6.4 Sharing Flags */
    public const int SP_DISABLE_MAINLIC_SHARING = 0;
    public const int SP_ENABLE_MAINLIC_SHARING = 1;

    public const int SP_DISABLE_DEVICE_SHARING = 2;

    public const int SP_DISABLE_SUBLIC_SHARING = 0;
    public const int SP_ENABLE_SUBLIC_SHARING = 1;


    /* Key Type Constants */
    public const int SP_KEY_FORM_FACTOR_PARALLEL = 0;
    public const int SP_KEY_FORM_FACTOR_USB = 1;
    public const int SP_KEY_FORM_FACTOR_SOFT = 2;

    public const int SP_SUPERPRO_FAMILY_KEY = 0;
    public const int SP_ULTRAPRO_FAMILY_KEY = 1;
    public const int SP_UNKNOWN_FAMILY_KEY = 16;

    /* Software Key Type Constants */
    public const int SP_SIMPLE_SOFT = 1;
    public const int SP_SECURE_SOFT = 2;
    public const int SP_EVALUATION_SOFT = 3;


    /* Maximum number of devices */
    public const int MAX_NUM_DEV = 10;

    /* Maximum host name length */
    public const int MAX_NAME_LEN = 64;

    /* Maximum host address length */
    public const int MAX_ADDR_LEN = 32;

    /* Maximum IP address length */
    public const int MAX_IPADDR_LEN = 64;

    public const int SPRO_MAX_QUERY_SIZE = 112; //in bytes

    /* SuperPro 6.5 Terminal Client Check Flags */
    public const int SP_DISALLOW_CHECK_TERMINAL_CLIENT = 0;
    public const int SP_ALLOW_CHECK_TERMINAL_CLIENT = 1;

    /* Device Capabilities */
    public const int SP_CAPS_AES_ALGO = 1;
    public const int SP_CAPS_PASSWORD_COUNTER = 2;
    public const int SP_CAPS_SECURE_TUNNEL = 4;
    public const int SP_CAPS_DISABLE_DEVICE_SHARING = 8;

    #endregion


    #region //////////////////////// BEGIN PUBLIC METHODS   ///////////////////////////////////


    public ushort RNBOsproFormatPacket(uint packetSize)
    {
        ushort status = 0;

        try
        {
            status = SuperproNativeApi.RNBOsproFormatPacket(this.packet, packetSize);
        }
        catch (System.DllNotFoundException)
        {
            throw new System.DllNotFoundException(strError);
        }
        return status;
    }

    public ushort RNBOsproInitialize()
    {
        ushort status = 0;

        try
        {
            status = SuperproNativeApi.RNBOsproInitialize(this.packet);
        }
        catch (System.DllNotFoundException)
        {
            throw new System.DllNotFoundException(strError);
        }
        return status;
    }

    public ushort RNBOsproFindFirstUnit(ushort developerID)
    {
        ushort status = 0;

        try
        {
            status = SuperproNativeApi.RNBOsproFindFirstUnit(this.packet, developerID);
        }
        catch (System.DllNotFoundException)
        {
            throw new System.DllNotFoundException(strError);
        }
        return status;
    }

    public ushort RNBOsproFindNextUnit()
    {
        ushort status = 0;

        try
        {
            status = SuperproNativeApi.RNBOsproFindNextUnit(this.packet);
        }
        catch (System.DllNotFoundException)
        {
            throw new System.DllNotFoundException(strError);
        }
        return status;
    }

    public ushort RNBOsproRead(ushort address, ref ushort data)
    {
        ushort status = 0;

        try
        {
            status = SuperproNativeApi.RNBOsproRead(this.packet, address, ref data);
        }
        catch (System.DllNotFoundException)
        {
            throw new System.DllNotFoundException(strError);
        }
        return status;
    }

    public ushort RNBOsproExtendedRead(ushort address, ref ushort data, ref byte accessCode)
    {
        ushort status = 0;

        try
        {
            status = SuperproNativeApi.RNBOsproExtendedRead(this.packet, address, ref data, ref accessCode);
        }
        catch (System.DllNotFoundException)
        {
            throw new System.DllNotFoundException(strError);
        }
        return status;
    }

    public ushort RNBOsproWrite(ushort writePassword, ushort address, ref ushort data, ref byte accessCode)
    {
        ushort status = 0;

        try
        {
            status = SuperproNativeApi.RNBOsproWrite(this.packet, writePassword, address, data, accessCode);
        }
        catch (System.DllNotFoundException)
        {
            throw new System.DllNotFoundException(strError);
        }
        return status;
    }

    public ushort RNBOsproOverwrite(ushort writePassword, ushort overwritePassword1, ushort overwritePassword2, ushort address, ref ushort data, ref byte accessCode)
    {
        ushort status = 0;

        try
        {
            status = SuperproNativeApi.RNBOsproOverwrite(this.packet, writePassword, overwritePassword1, overwritePassword2, address, data, accessCode);
        }
        catch (System.DllNotFoundException)
        {
            throw new System.DllNotFoundException(strError);
        }
        return status;
    }

    public ushort RNBOsproDecrement(ushort writePassword, ushort address)
    {
        ushort status = 0;

        try
        {
            status = SuperproNativeApi.RNBOsproDecrement(this.packet, writePassword, address);
        }
        catch (System.DllNotFoundException)
        {
            throw new System.DllNotFoundException(strError);
        }
        return status;
    }

    public ushort RNBOsproActivate(ushort writePassword, ushort activatePassword1, ushort activatePassword2, ushort address)
    {
        ushort status = 0;

        try
        {
            status = SuperproNativeApi.RNBOsproActivate(this.packet, writePassword, activatePassword1, activatePassword2, address);
        }
        catch (System.DllNotFoundException)
        {
            throw new System.DllNotFoundException(strError);
        }
        return status;
    }

    public ushort RNBOsproQuery(ushort address, byte[] queryData, byte[] response, ref uint response32, ushort length)
    {
        ushort status = 0;

        try
        {
            status = SuperproNativeApi.RNBOsproQuery(this.packet, address, queryData, response, ref response32, length);
        }
        catch (System.DllNotFoundException)
        {
            throw new System.DllNotFoundException(strError);
        }
        return status;
    }

    public ushort RNBOsproGetFullStatus()
    {
        ushort status = 0;

        try
        {
            status = SuperproNativeApi.RNBOsproGetFullStatus(this.packet);
        }
        catch (System.DllNotFoundException)
        {
            throw new System.DllNotFoundException(strError);
        }
        return status;
    }

    public ushort RNBOsproGetVersion(ref byte majVerion, ref byte minVersion, ref byte revision, ref byte osDrvrType)
    {
        ushort status = 0;

        try
        {
            status = SuperproNativeApi.RNBOsproGetVersion(this.packet, ref majVerion, ref minVersion, ref revision, ref osDrvrType);
        }
        catch (System.DllNotFoundException)
        {
            throw new System.DllNotFoundException(strError);
        }
        return status;
    }

    public ushort RNBOsproGetKeyType(ref int keyFamily, ref int formFactor, ref int memUsed)
    {
        ushort status = 0;

        try
        {
            status = SuperproNativeApi.RNBOsproGetKeyType(this.packet, ref keyFamily, ref formFactor, ref memUsed);
        }
        catch (System.DllNotFoundException)
        {
            throw new System.DllNotFoundException(strError);
        }
        return status;
    }

    public void RNBOsproCleanup()
    {
        try
        {
            SuperproNativeApi.RNBOsproCleanup();
        }
        catch (System.DllNotFoundException)
        {
            throw new System.DllNotFoundException(strError);
        }
        return;
    }

    public ushort RNBOsproGetHardLimit(out ushort hardLimit)
    {
        ushort status = 0;
        hardLimit = 0;

        try
        {
            status = SuperproNativeApi.RNBOsproGetHardLimit(this.packet, out hardLimit);
        }
        catch (System.DllNotFoundException)
        {
            throw new System.DllNotFoundException(strError);
        }
        return status;
    }

    public ushort RNBOsproGetSubLicense(ushort address)
    {
        ushort status = 0;

        try
        {
            status = SuperproNativeApi.RNBOsproGetSubLicense(this.packet, address);
        }
        catch (System.DllNotFoundException)
        {
            throw new System.DllNotFoundException(strError);
        }
        return status;
    }

    public ushort RNBOsproReleaseLicense(ushort address, ref ushort numSubLic)
    {
        ushort status = 0;

        try
        {
            status = SuperproNativeApi.RNBOsproReleaseLicense(this.packet, address, ref numSubLic);
        }
        catch (System.DllNotFoundException)
        {
            throw new System.DllNotFoundException(strError);
        }
        return status;
    }

    public ushort RNBOsproSetContactServer(string serverName)
    {
        ushort status = 0;

        try
        {
            status = SuperproNativeApi.RNBOsproSetContactServer(this.packet, serverName);
        }
        catch (System.DllNotFoundException)
        {
            throw new System.DllNotFoundException(strError);
        }
        return status;
    }

    public ushort RNBOsproGetContactServer(byte[] serverNameBuffer, uint serverNameBufferSize)
    {
        ushort status = 0;

        try
        {
            status = SuperproNativeApi.RNBOsproGetContactServer(this.packet, serverNameBuffer, serverNameBufferSize);
        }
        catch (System.DllNotFoundException)
        {
            throw new System.DllNotFoundException(strError);
        }
        return status;
    }

    public ushort RNBOsproEnumServer(int enumFlag, ushort developerID, byte[] nsproServerInfo, ref ushort numServerInfo)
    {
        ushort status = 0;

        try
        {
            status = SuperproNativeApi.RNBOsproEnumServer(enumFlag, developerID, nsproServerInfo, ref numServerInfo);
        }
        catch (System.DllNotFoundException)
        {
            throw new System.DllNotFoundException(strError);
        }
        return status;
    }

    public ushort RNBOsproGetKeyInfo(ushort developerID, ushort keyIndex, byte[] nsproMonitorInfo)
    {
        ushort status = 0;

        try
        {
            status = SuperproNativeApi.RNBOsproGetKeyInfo(this.packet, developerID, keyIndex, nsproMonitorInfo);
        }
        catch (System.DllNotFoundException)
        {
            throw new System.DllNotFoundException(strError);
        }
        return status;
    }

    public ushort RNBOsproGetKeyInfoEx(uint developerID, uint keyIndex, uint subLicAddress, byte[] nsproMonitorInfoEx, uint size)
    {
        ushort status = 0;

        try
        {
            status = SuperproNativeApi.RNBOsproGetKeyInfoEx(this.packet, developerID, keyIndex, subLicAddress, nsproMonitorInfoEx, size);
        }
        catch (System.DllNotFoundException)
        {
            throw new System.DllNotFoundException(strError);
        }
        return status;
    }

    public ushort RNBOsproSetProtocol(int protocol)
    {
        ushort status = 0;

        try
        {
            status = SuperproNativeApi.RNBOsproSetProtocol(this.packet, protocol);
        }
        catch (System.DllNotFoundException)
        {
            throw new System.DllNotFoundException(strError);
        }
        return status;
    }

    public ushort RNBOsproSetHeartBeat(int heartBeatValue)
    {
        ushort status = 0;

        try
        {
            status = SuperproNativeApi.RNBOsproSetHeartBeat(this.packet, heartBeatValue);
        }
        catch (System.DllNotFoundException)
        {
            throw new System.DllNotFoundException(strError);
        }
        return status;
    }

    public ushort RNBOsproSetSharedLicense(ushort shareMainLic, ushort shareSubLic)
    {
        ushort status = 0;

        try
        {
            status = SuperproNativeApi.RNBOsproSetSharedLicense(this.packet, shareMainLic, shareSubLic);
        }
        catch (System.DllNotFoundException)
        {
            throw new System.DllNotFoundException(strError);
        }
        return status;
    }

    public ushort RNBOsproCheckTerminalService(int termserv)
    {
        ushort status = 0;

        try
        {
            status = SuperproNativeApi.RNBOsproCheckTerminalService(this.packet, termserv);
        }
        catch (System.DllNotFoundException)
        {
            throw new System.DllNotFoundException(strError);
        }
        return status;
    }

    public ushort RNBOsproSetDeveloperCode(byte[] devCode, uint size)
    {
        ushort status = 0;

        try
        {
            status = SuperproNativeApi.RNBOsproSetDeveloperCode(this.packet, devCode, size);
        }
        catch (System.DllNotFoundException)
        {
            throw new System.DllNotFoundException(strError);
        }
        return status;
    }

    public ushort RNBOsproSetConfigFile(string cfgFileName)
    {
        ushort status = 0;

        try
        {
            status = SuperproNativeApi.RNBOsproSetConfigFile(this.packet, cfgFileName);
        }
        catch (System.DllNotFoundException)
        {
            throw new System.DllNotFoundException(strError);
        }
        return status;
    }
    #endregion
}