// dris.h
// Dinkey Runtime Information Structure (DRIS)
// !! this file should not be modified

#pragma pack(1)

typedef struct DRIS {
    // the first 4 fields are never encrypted
    char header[4];                 // should be set to DRIS
    // inputs
    int size;                       // size of this structure
    int seed1;                      // seed for data/dris encryption
    int seed2;                      // as above
    // (maybe encrypted from now on)
    int function;                   // specify only one function
    int flags;                      // options for the function selected. To use more than one OR them together: OPTION1 | OPTION2...
    unsigned int execs_decrement;   // amount by which to dec execs if we use flag: DEC_MANY_EXECS
    int data_crypt_key_num;         // number of the key (1-3) that the dongle uses to encrypt or decrypt user data
    int rw_offset;                  // offset in the dongle data area to read or write data
    int rw_length;                  // length of data are to read/write/encrypt/decrypt
    char *rw_data_ptr;              // pointer to data to write / be read
    char alt_licence_name[256];     // protection check for different licence instead of the default one, must be null-terminated
    int var_a;                      // variable values for user algorithm
    int var_b;
    int var_c;
    int var_d;
    int var_e;
    int var_f;
    int var_g;
    int var_h;
    int alg_number;                 // the number of the user algorithm that you want to execute

    // outputs
    int ret_code;                   // return code from the protection check
    int ext_err;                    // extended error
    int type;                       // type of dongle detected. 1 = Pro, 2 = FD
    int model;                      // model of dongle detected. 1 = Lite, 2 = Plus, 4 = Net 5, 7 = Net Unlimited
    int sdsn;                       // Software Developer's Serial Number
    char prodcode[12];              // Product Code (null-terminated)
    unsigned int dongle_number;
    int update_number;
    unsigned int data_area_size;    // size of the data area used in the dongle detected
    int max_alg_num;                // the maximum algorithm number in the dongle detected
    int execs;                      // executions left: -1 indicates 'no limit'
    int exp_day;                    // expiry day: -1 indicates 'no limit'
    int exp_month;                  // expiry month: -1 indicates 'no limit'
    int exp_year;                   // expiry year: -1 indicates 'no limit'
    unsigned int features;          // features value 
    int net_users;                  // maximum number of network users for the dongle detected: -1 indicates 'no limit'
    int alg_answer;                 // answer to the user algorithm executed with the given variable values
    unsigned int fd_capacity;       // capacity of the data area in FD dongle.
    char fd_drive[128];             // drive letter of FD dongle detected e.g. 'f:\' (or mount name under Linux)
    int swkey_type;                 // 0 = no swkey detected, 1 = temporary software key, 2 = demo software key
    int swkey_exp_day;              // software key expiry date (if software key detected)
    int swkey_exp_month;            
    int swkey_exp_year;             
} DRIS;

typedef struct NU_INFO {
    char licenceName[256];
    char userName[50];
    char computerName[256];
    char ipAddress[16];
} NU_INFO;

#pragma pack()

// functions - must specify only one
#define PROTECTION_CHECK        1       // checks for dongle, check program params...
#define EXECUTE_ALGORITHM       2       // protection check + calculate answer for specified algorithm with specified inputs
#define WRITE_DATA_AREA         3       // protection check + writes dongle data area
#define READ_DATA_AREA          4       // protection check + reads dongle data area
#define ENCRYPT_USER_DATA       5       // protection check + the dongle will encrypt user data
#define DECRYPT_USER_DATA       6       // protection check + the dongle will decrypt user data
#define FAST_PRESENCE_CHECK     7       // checks for the presence of the correct dongle only with minimal security, no flags allowed.
#define STOP_NET_USER           8       // stops a network user (a protection check is NOT performed)

// flags - can specify as many as you like
#define DEC_ONE_EXEC             1      // decrement execs by 1 
#define DEC_MANY_EXECS           2      // decrement execs by number specified in execs_decrement
#define START_NET_USER           4      // starts a network user
#define USE_FUNCTION_ARGUMENT    16     // use the extra argument in the function for pointers
#define CHECK_LOCAL_FIRST        32     // always look in local ports before looking in network ports
#define CHECK_NETWORK_FIRST      64     // always look on the network before looking in local ports
#define USE_ALT_LICENCE_NAME     128    // use name specified in alt_licence_name instead of the default one
#define DONT_SET_MAXDAYS_EXPIRY  256    // if the max days expiry date has not been calculated then do not do it this time
#define MATCH_DONGLE_NUMBER      512    // restrict the search to match the dongle number specified in the DRIS
#define DONT_RETURN_FD_DRIVE     1024   // if an FD dongle has been detected then don't return the flash drive/mount name in the DRIS  


// Runtime module API declarations
#ifdef __cplusplus
	extern "C" {
#endif

int WINAPI DDProtCheck(DRIS *dris, unsigned char *data);
int WINAPI DDGetNetUserList(char *licence_name, int *num_net_users, NU_INFO *nu_info, int num_info_structs, int *extended_error);

#ifdef __cplusplus
}
#endif
