#ifndef __HLAPI_H
#define __HLAPI_H

/****************************************************************************/
/**                                                                        **/
/**                           Hardlock E-Y-E                               **/
/**                    API-Structures and definitions                      **/
/**                                                                        **/
/**   This file contains some helpful defines to access a Hardlock using   **/
/**   the application programing interface (API) for Hardlock E-Y-E.       **/
/**                                                                        **/
/**                     (c) 1992 by ///FAST Electronic                     **/
/**                                                                        **/
/**                                                                        **/
/**              Authors : Thomas Schr”ter                                 **/
/**                        Henri Volk                                      **/
/**              Version : 3.0                                             **/
/**              Date    : 01-Sep-1992                                     **/
/**                                                                        **/
/****************************************************************************/

#define EYECAST (char   huge *)

/* -------------------------------- */
/* Definitions and API structures : */
/* -------------------------------- */
typedef unsigned char  Byte;
typedef   signed short Word;
typedef unsigned long  Long;

typedef struct
{
  Word Use_Key;
  Byte Key[8];
}
DES_MODE;

typedef struct
{
  Word ModAd;                      /* Moduleaddress EYE      */
  Word Register;                   /* Memory register adress */
  Word Value;                      /* Memory value           */
  Byte Reserved[4];
}
EYE_MODE;

typedef union
{
  DES_MODE Des;
  EYE_MODE Eye;
}
HARDWARE;

typedef struct hl_api
{
  Byte      API_Version_ID[2];     /* Version                    */
  Word      API_Options[2];        /* API Optionflags            */
  Word      ModID;                 /* Modul-ID (EYE = 0...)      */
  HARDWARE  Module;                /* Hardware type              */
  void far *Data;                  /* Pointer to cipher data     */
  Word      Bcnt;                  /* Number of blocks           */
  Word      Function;              /* Function number            */
  Word      Status;                /* Actual status              */
  Word      Remote;                /* Remote or local??          */
  Word      Port;                  /* Port address if local      */
  Word      Speed;                 /* Speed of port if local     */
  Word      NetUsers;              /* Current Logins (HLSERVER)  */
  Byte      ID_Ref[8];             /* Referencestring            */
  Byte      ID_Verify[8];          /* Encrypted ID_Ref           */
  Long      Task_ID;               /* Multitasking program ID    */
  Byte      Reserved[200];         /* Reserved area              */
}
HL_API;

/* ------------- */
/* Module-ID's : */
/* ------------- */
#define EYE_DONGLE       0         /* Hardlock E-Y-E             */
#define DES_DONGLE       1         /* FAST DES                   */

/* --------------------- */
/* API function calls  : */
/* --------------------- */
#define API_INIT            0         /* Init API structure      */
#define API_DOWN            1         /* Free API structure      */
#define API_FORCE_DOWN      31        /* Force deinintialization */
#define API_MULTI_SHELL_ON  2         /* MTS is enabled          */
#define API_MULTI_SHELL_OFF 3         /* MTS is disabled         */
#define API_MULTI_ON        4         /* Enable MTS              */
#define API_MULTI_OFF       5         /* Disable  MTS            */
#define API_AVAIL           6         /* Dongle available?       */
#define API_LOGIN           7         /* Login dongle server     */
#define API_LOGOUT          8         /* Logout dongle server    */
#define API_INFO            9         /* Get API informations    */

/* --------------------------- */
/* Data and memory functions : */
/* --------------------------- */
#define API_KEYE             11        /* Use KEYE for encryption         */
#define API_READ             20        /* Read one word of dongle EEPROM  */
#define API_WRITE            21        /* Write one word of dongle EEPROM */
#define API_READ_BLOCK       23        /* Read EEPROM in one block        */
#define API_WRITE_BLOCK      24        /* Write EEPROM in one block       */
#define API_GET_ID_KEY       30        /* Encrypt ID_Ref to ID_Verify     */
#define API_ABORT            53        /* Critical Error Abort            */

/* -------------------- */
/* Dongle access mode : */
/* -------------------- */
#define LOCAL_DEVICE     1         /* Query local HL only        */
#define NET_DEVICE       2         /* Query remote HL only       */
#define DONT_CARE        3         /* Query local or remote HL   */

/* ------------------ */
/* API Status Codes : */
/* ------------------ */
#define STATUS_OK         0         /* API call was succesfull    */
#define NOT_INIT          1         /* DONGLE not initialized     */
#define ALREADY_INIT      2         /* Already initialized        */
#define UNKNOWN_DONGLE    3         /* Device not supported       */
#define UNKNOWN_FUNCTION  4         /* Function not supported     */
#define NO_DONGLE         7         /* No device available        */
#define NETWORK_ERROR     8         /* A network error occured    */
#define NO_ACCESS         9         /* No device available        */
#define INVALID_PARAM    10         /* A wrong parameter occured  */
#define VERSION_MISMATCH 11         /* HL-Server not API version  */

#ifdef __cplusplus
extern "C" {
#endif

  /* --------------------- */
  /* Function prototypes : */
  /* --------------------- */
  static int CALL_API      (HL_API far *as);
  Word far   HL_LOGIN      (Word ModAd, Word Access, char * RefKey, char * VerKey);
  Word far   HL_LOGOUT     (void);
  Word far   HL_AVAIL      (void);
  Word far   HL_PORTINF    (void);
  Word far   HL_ACCINF     (void);
  Word far   HL_USERINF    (void);
  Word far   HL_MAXUSER    (void);
  Word far   HL_MEMINF     (void);
  Word far   HL_CODE       (void far *Data, Word Count);
  Word far   HL_WRITE      (Word Register,  Word Value);
  Word far   HL_READ       (Word Register, int far *Value);
  char far * HL_GET_ID     (char * id_ref);
  Word far   HL_READBL     (char * Eeprom);
  Word far   HL_WRITEBL    (char * Eeprom);
  Word far   HL_ABORT      (void);
  Word far   HL_VERSION    (void);

  /****************************************************************************/
  /****************************************************************************/
  /* The following functions map the old Hardlock Calls on the new API. These */
  /* functions are defined only for compatibility reasons.                    */
  /* !!! Don't mix old and new functions. Don't use if it is not necessary.!!!*/
  /****************************************************************************/
  /****************************************************************************/
  void far   HL_ON         (int Port, Word ModAd);
  void far   HL_OFF        (int Port);
  int  far   K_EYE         (int Port, char huge *Inp, int BlkCnt);
  void far   HL_WR         (int Port, int Register, Word Val);
  Word far   HL_RD         (int Port, int Register);
  void far   INT_ON        (void);
  void far   INT_OFF       (void);

#ifdef __cplusplus
}
#endif

#endif