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

with System;
with Interfaces;

package dris is

   pragma linker_options ("-ldpwin32");

   subtype uint8 is Interfaces.Unsigned_8;
   subtype int32 is Interfaces.Integer_32;
   subtype uint32 is Interfaces.Unsigned_32;
   subtype uint64 is Interfaces.Unsigned_64;

   type t_DRIS;

   type t_DRIS_access is access all t_DRIS;

   -- functions - must specify only one
   type t_functions is
     (NONE,
      PROTECTION_CHECK,     -- checks for dongle, check program params...
      EXECUTE_ALGORITHM,    -- protection check + calculate answer for specified algorithm with specified inputs
      WRITE_DATA_AREA,      -- protection check + writes dongle data area
      READ_DATA_AREA,       -- protection check + reads dongle data area
      ENCRYPT_USER_DATA,    -- protection check + the dongle will encrypt user data
      DECRYPT_USER_DATA,    -- protection check + the dongle will decrypt user data
      FAST_PRESENCE_CHECK,  -- checks for the presence of the correct dongle only with minimal security, no flags allowed.
      STOP_NET_USER         -- stops a network user (a protection check is NOT performed)
     );
   for t_functions'Size use 32;

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

   -- DDProtCheck
   function DDProtCheck (dris : t_DRIS_access; data : System.Address) return int32;
   pragma import (StdCall, DDProtCheck, "DDProtCheck");

   type t_array_4_char is array (0..3) of Character;
   type t_array_12_char is array (0..11) of Character;
   type t_array_128_char is array (0..127) of Character;
   type t_array_256_char is array (0..255) of Character;

   type t_DRIS is record
      -- the first 4 fields are never encrypted
      header : t_array_4_char;

      -- inputs
      size : int32;                     -- size of this structure
      seed1 : uint32;                   -- seed for data/dris encryption
      seed2 : uint32;                   -- as above
      -- (maybe encrypted from now on)
      funct : t_functions;              -- specify only one function
      flags : int32;                    -- options for the function selected. To use more than one OR them together: OPTION1 | OPTION2...
      execs_decrement : uint32;         -- amount by which to dec execs if we use flag: DEC_MANY_EXECS
      data_crypt_key_num : int32;       -- number of the key (1-3) that the dongle uses to encrypt or decrypt user data
      rw_offset : int32;                -- offset in the dongle data area to read or write data
      rw_length : int32;                -- length of data are to read/write/encrypt/decrypt
      rw_data_ptr : System.Address;     -- pointer to data to write / be read
      alt_prog_name : t_array_256_char;	-- protection check for different program instead of this one, must be null-terminated
      var_a : int32;                    -- variable values for user algorithm
      var_b : int32;
      var_c : int32;
      var_d : int32;
      var_e : int32;
      var_f : int32;
      var_g : int32;
      var_h : int32;
      alg_number : int32;               -- the number of the user algorithm that you want to execute

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

end dris;
