/*****************************************************************************/
/* Copyright Notice:                                                         */
/*               (C) COPYRIGHT IBM CORP. 1996,2002 - PROGRAM PROPERTY OF IBM */
/*               ALL RIGHTS RESERVED                                         */
/**INC+***********************************************************************/
/* Header:    winlua.h                                                       */
/*                                                                           */
/* Purpose:   Defines types and structures by the RUI API and all data       */
/*            required internally by the RUI API                             */
/*                                                                           */
/*****************************************************************************/

#ifndef LUA_CH_INCLUDED
#define LUA_CH_INCLUDED

/*****************************************************************************/
/* Define this header file to be C if this is inluded by a C++ source file   */
/*****************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif

/*****************************************************************************/
/* for Win32 environment:                                                    */
/* -  ensure correct packing                                                 */
/* -  remove references to far                                               */
/*****************************************************************************/
#pragma pack(4)
#define far

/*****************************************************************************/
/*   define flipping macros                                                  */
/*****************************************************************************/
#ifndef SWAP2
#define SWAP2(s) (unsigned short)((((s)>>8)&0xFF)|((s)<<8))
#endif

#ifndef SWAP4
#define SWAP4(l)        (unsigned long)((((l) >> 24) & 0xFF) |\
                        ((((l) & 0xFF0000) >> 8) & 0xFF00) | (((l) & 0xFF00)\
                        << 8) | ((l) << 24))
#endif
#define LUA_FLIPI(X) SWAP2(X)
#define LUA_FLIPL(X) SWAP4(X)

/*****************************************************************************/
/* LUA VERB TYPES                                                            */
/*****************************************************************************/
#define LUA_VERB_RUI                    (0x0052)
#define LUA_VERB_SLI                    (0x0052)

/*****************************************************************************/
/* LUA OPCODES (RUI and SLI)                                                 */
/*****************************************************************************/
#define LUA_OPCODE_RUI_INIT             (0x8001)
#define LUA_OPCODE_RUI_TERM             (0x8002)
#define LUA_OPCODE_RUI_READ             (0x8003)
#define LUA_OPCODE_RUI_WRITE            (0x8004)
#define LUA_OPCODE_RUI_PURGE            (0x8005)
#define LUA_OPCODE_RUI_BID              (0x8006)

#define LUA_OPCODE_SLI_OPEN             (0x0001)
#define LUA_OPCODE_SLI_CLOSE            (0x0002)
#define LUA_OPCODE_SLI_RECEIVE          (0x0003)
#define LUA_OPCODE_SLI_SEND             (0x0004)
#define LUA_OPCODE_SLI_PURGE            (0x0005)
#define LUA_OPCODE_SLI_BID              (0x0006)
#define LUA_OPCODE_SLI_BIND_ROUTINE     (0x0011)
#define LUA_OPCODE_SLI_STSN_ROUTINE     (0x0012)
#define LUA_OPCODE_SLI_CRV_ROUTINE      (0x0013)
#define LUA_OPCODE_SLI_SDT_ROUTINE      (0x0014)

/*****************************************************************************/
/* LUA PRIMARY RETURN CODES                                                  */
/*****************************************************************************/
#define LUA_OK                          (0x0000)
#define LUA_PARAMETER_CHECK             (0x0100)
#define LUA_STATE_CHECK                 (0x0200)
#define LUA_SESSION_FAILURE             (0x0F00)
#define LUA_UNSUCCESSFUL                (0x1400)
#define LUA_NEGATIVE_RSP                (0x1800)
#define LUA_CANCELLED                   (0x2100)
#define LUA_IN_PROGRESS                 (0x3000)
#define LUA_STATUS                      (0x4000)
#define LUA_COMM_SUBSYSTEM_ABENDED      (0x03F0)
#define LUA_COMM_SUBSYSTEM_NOT_LOADED   (0x04F0)
#define LUA_INVALID_VERB_SEGMENT        (0x08F0)
#define LUA_UNEXPECTED_DOS_ERROR        (0x11F0)
#define LUA_STACK_TOO_SMALL             (0x15F0)
#define LUA_INVALID_VERB                (0xFFFF)

/*****************************************************************************/
/* LUA SECONDARY RETURN CODES                                                */
/*****************************************************************************/
#define LUA_SEC_RC_OK                   (0x00000000L)
#define LUA_INVALID_LUNAME              (0x01000000L)
#define LUA_BAD_SESSION_ID              (0x02000000L)
#define LUA_DATA_TRUNCATED              (0x03000000L)
#define LUA_BAD_DATA_PTR                (0x04000000L)
#define LUA_DATA_SEG_LENGTH_ERROR       (0x05000000L)
#define LUA_RESERVED_FIELD_NOT_ZERO     (0x06000000L)
#define LUA_INVALID_POST_HANDLE         (0x07000000L)
#define LUA_PURGED                      (0x0C000000L)
#define LUA_BID_VERB_SEG_ERROR          (0x0F000000L)
#define LUA_NO_PREVIOUS_BID_ENABLED     (0x10000000L)
#define LUA_NO_DATA                     (0x11000000L)
#define LUA_BID_ALREADY_ENABLED         (0x12000000L)
#define LUA_VERB_RECORD_SPANS_SEGMENTS  (0x13000000L)
#define LUA_INVALID_FLOW                (0x14000000L)
#define LUA_NOT_ACTIVE                  (0x15000000L)
#define LUA_VERB_LENGTH_INVALID         (0x16000000L)
#define LUA_REQUIRED_FIELD_MISSING      (0x19000000L)
#define LUA_READY                       (0x30000000L)
#define LUA_NOT_READY                   (0x31000000L)
#define LUA_INIT_COMPLETE               (0x32000000L)
#define LUA_SESSION_END_REQUESTED       (0x33000000L)
#define LUA_NO_SLI_SESSION              (0x34000000L)
#define LUA_SESSION_ALREADY_OPEN        (0x35000000L)
#define LUA_INVALID_OPEN_INIT_TYPE      (0x36000000L)
#define LUA_INVALID_OPEN_DATA           (0x37000000L)
#define LUA_UNEXPECTED_SNA_SEQUENCE     (0x38000000L)
#define LUA_NEG_RSP_FROM_BIND_ROUTINE   (0x39000000L)
#define LUA_NEG_RSP_FROM_CRV_ROUTINE    (0x3A000000L)
#define LUA_NEG_RSP_FROM_STSN_ROUTINE   (0x3B000000L)
#define LUA_CRV_ROUTINE_REQUIRED        (0x3C000000L)
#define LUA_STSN_ROUTINE_REQUIRED       (0x3D000000L)
#define LUA_INVALID_OPEN_ROUTINE_TYPE   (0x3E000000L)
#define LUA_MAX_NUMBER_OF_SENDS         (0x3F000000L)
#define LUA_SEND_ON_FLOW_PENDING        (0x40000000L)
#define LUA_INVALID_MESSAGE_TYPE        (0x41000000L)
#define LUA_RECEIVE_ON_FLOW_PENDING     (0x42000000L)
#define LUA_DATA_LENGTH_ERROR           (0x43000000L)
#define LUA_CLOSE_PENDING               (0x44000000L)
#define LUA_NEGATIVE_RSP_CHASE          (0x46000000L)
#define LUA_NEGATIVE_RSP_SHUTC          (0x47000000L)
#define LUA_NEGATIVE_RSP_RSHUTD         (0x48000000L)
#define LUA_NO_RECEIVE_TO_PURGE         (0x4A000000L)
#define LUA_CANCEL_COMMAND_RECEIVED     (0x4D000000L)
#define LUA_RUI_WRITE_FAILURE           (0x4E000000L)
#define LUA_INVALID_SESSION_TYPE        (0x4F000000L)
#define LUA_SLI_BID_PENDING             (0x51000000L)
#define LUA_SLI_PURGE_PENDING           (0x52000000L)
#define LUA_PROCEDURE_ERROR             (0x53000000L)
#define LUA_INVALID_SLI_ENCR_OPTION     (0x54000000L)
#define LUA_RECEIVED_UNBIND             (0x55000000L)
#define LUA_RECEIVED_UNBIND_HOLD        (0x56000000L)
#define LUA_RECEIVED_UNBIND_NORMAL      (0x57000000L)
#define LUA_SLI_LOGIC_ERROR             (0x7F000000L)
#define LUA_TERMINATED                  (0x80000000L)
#define LUA_NO_RUI_SESSION              (0x81000000L)
#define LUA_DUPLICATE_RUI_INIT          (0x82000000L)
#define LUA_INVALID_PROCESS             (0x83000000L)
#define LUA_API_MODE_CHANGE             (0x85000000L)
#define LUA_COMMAND_COUNT_ERROR         (0x87000000L)
#define LUA_NO_READ_TO_PURGE            (0x88000000L)
#define LUA_MULTIPLE_WRITE_FLOWS        (0x89000000L)
#define LUA_DUPLICATE_READ_FLOW         (0x8A000000L)
#define LUA_DUPLICATE_WRITE_FLOW        (0x8B000000L)
#define LUA_LINK_NOT_STARTED            (0x8C000000L)
#define LUA_INVALID_ADAPTER             (0x8D000000L)
#define LUA_ENCR_DECR_LOAD_ERROR        (0x8E000000L)
#define LUA_ENCR_DECR_PROC_ERROR        (0x8F000000L)
#define LUA_INVALID_PUNAME              (0x90000000L)
#define LUA_INVALID_LUNUMBER            (0x91000000L)
#define LUA_INVALID_FORMAT              (0x92000000L)
#define LUA_DUPLICATE_RUI_REINIT        (0x93000000L)
#define LUA_REINIT_INVALID              (0X94000000L)
#define LUA_LINK_NOT_STARTED_RETRY      (0x95FF0000L)
#define LUA_NEG_RSP_FROM_SDT_ROUTINE    (0x96000000L)
#define LUA_NEG_NOTIFY_RSP              (0xBE000000L)
#define LUA_RUI_LOGIC_ERROR             (0xBF000000L)
#define LUA_COBOL_NOT_SUPPORTED         (0xC0000000L)
#define LUA_LU_INOPERATIVE              (0xFF000000L)
#define LUA_UNAUTHORIZED_ACCESS         (0x90020000L)
#define LUA_TCPCV_LENGTH_INVALID        (0X95000000L)


/*****************************************************************************/
/* THE FOLLOWING SECONDARY RETURN CODES ARE SNA SENSE CODES                  */
/*****************************************************************************/
#define LUA_NON_UNIQ_ID                 (0x011000C0L)
#define LUA_NON_UNIQ_NAU_AD             (0x021000C0L)
#define LUA_INV_NAU_ADDR                (0x012000C0L)
#define LUA_INV_ADPT_NUM                (0x022000C0L)

#define LUA_RESOURCE_NOT_AVAILABLE      (0x00000108L)
#define LUA_SESSION_LIMIT_EXCEEDED      (0x00000508L)
#define LUA_SLU_SESSION_LIMIT_EXCEEDED  (0x0A000508L)
#define LUA_MODE_INCONSISTENCY          (0x00000908L)
#define LUA_BRACKET_RACE_ERROR          (0x00000B08L)
#define LUA_INSUFFICIENT_RESOURCES      (0x00001208L)
#define LUA_BB_REJECT_NO_RTR            (0x00001308L)
#define LUA_BB_REJECT_RTR               (0x00001408L)
#define LUA_RECEIVER_IN_TRANSMIT_MODE   (0x00001B08L)
#define LUA_REQUEST_NOT_EXECUTABLE      (0x00001C08L)
#define LUA_INVALID_SESSION_PARAMETERS  (0x00002108L)
#define LUA_UNIT_OF_WORK_ABORTED        (0x00002408L)
#define LUA_FM_FUNCTION_NOT_SUPPORTED   (0x00002608L)
#define LUA_LU_COMPONENT_DISCONNECTED   (0x00003108L)
#define LUA_INVALID_PARAMETER_FLAGS     (0x00003308L)
#define LUA_INVALID_PARAMETER           (0x00003508L)
#define LUA_NEGOTIABLE_BIND_ERROR       (0x01003508L)
#define LUA_BIND_FM_PROFILE_ERROR       (0x02003508L)
#define LUA_BIND_TS_PROFILE_ERROR       (0x03003508L)
#define LUA_BIND_LU_TYPE_ERROR          (0x0E003508L)
#define LUA_CRYPTOGRAPHY_INOPERATIVE    (0x00004808L)
#define LUA_REQ_RESOURCES_NOT_AVAIL     (0x00004B08L)
#define LUA_SSCP_LU_SESSION_NOT_ACTIVE  (0x00005708L)
#define LUA_SSCP_PLU_SESS_NOT_ACTIVE    (0x02005708L)
#define LUA_SSCP_SLU_SESS_INACT         (0x03005708L)
#define LUA_SYNC_EVENT_RESPONSE         (0x00006708L)
#define LUA_REC_CORR_TABLE_FULL         (0x01007808L)
#define LUA_SEND_CORR_TABLE_FULL        (0x02007808L)
#define LUA_SESSION_SERVICE_PATH_ERROR  (0x00007D08L)

#define LUA_RU_DATA_ERROR               (0x00000110L)
#define LUA_RU_LENGTH_ERROR             (0x00000210L)
#define LUA_FUNCTION_NOT_SUPPORTED      (0x00000310L)
#define LUA_HDX_BRACKET_STATE_ERROR     (0x21010510L)
#define LUA_RESPONSE_ALREADY_SENT       (0x22010510L)
#define LUA_EXR_SENSE_INCORRECT         (0x23010510L)
#define LUA_RESPONSE_OUT_OF_ORDER       (0x24010510L)
#define LUA_CHASE_RESPONSE_REQUIRED     (0x25010510L)
#define LUA_CATEGORY_NOT_SUPPORTED      (0x00000710L)

#define LUA_INCORRECT_SEQUENCE_NUMBER   (0x00000120L)
#define LUA_CHAINING_ERROR              (0x00000220L)
#define LUA_BRACKET                     (0x00000320L)
#define LUA_DIRECTION                   (0x00000420L)
#define LUA_DATA_TRAFFIC_RESET          (0x00000520L)
#define LUA_DATA_TRAFFIC_QUIESCED       (0x00000620L)
#define LUA_DATA_TRAFFIC_NOT_RESET      (0x00000720L)
#define LUA_NO_BEGIN_BRACKET            (0x00000820L)
#define LUA_SC_PROTOCOL_VIOLATION       (0x00000920L)
#define LUA_IMMEDIATE_REQ_MODE_ERROR    (0x00000A20L)
#define LUA_QUEUED_RESPONSE_ERROR       (0x00000B20L)
#define LUA_ERP_SYNC_EVENT_ERROR        (0x00000C20L)
#define LUA_RSP_BEFORE_SENDING_REQ      (0x00000D20L)
#define LUA_RSP_CORRELATION_ERROR       (0x00000E20L)
#define LUA_RSP_PROTOCOL_ERROR          (0x00000F20L)

#define LUA_INVALID_SC_OR_NC_RH         (0x00000140L)
#define LUA_BB_NOT_ALLOWED              (0x00000340L)
#define LUA_EB_NOT_ALLOWED              (0x00000440L)
#define LUA_EXCEPTION_RSP_NOT_ALLOWED   (0x00000640L)
#define LUA_DEFINITE_RSP_NOT_ALLOWED    (0x00000740L)
#define LUA_PACING_NOT_SUPPORTED        (0x00000840L)
#define LUA_CD_NOT_ALLOWED              (0x00000940L)
#define LUA_NO_RESPONSE_NOT_ALLOWED     (0x00000A40L)
#define LUA_CHAINING_NOT_SUPPORTED      (0x00000B40L)
#define LUA_BRACKETS_NOT_SUPPORTED      (0x00000C40L)
#define LUA_CD_NOT_SUPPORTED            (0x00000D40L)
#define LUA_INCORRECT_USE_OF_FI         (0x00000F40L)
#define LUA_ALTERNATE_CODE_NOT_SUPPORT  (0x00001040L)
#define LUA_INCORRECT_RU_CATEGORY       (0x00001140L)
#define LUA_INCORRECT_REQUEST_CODE      (0x00001240L)
#define LUA_INCORRECT_SPEC_OF_SDI_RTI   (0x00001340L)
#define LUA_INCORRECT_DR1I_DR2I_ERI     (0x00001440L)
#define LUA_INCORRECT_USE_OF_QRI        (0x00001540L)
#define LUA_INCORRECT_USE_OF_EDI        (0x00001640L)
#define LUA_INCORRECT_USE_OF_PDI        (0x00001740L)

#define LUA_NAU_INOPERATIVE             (0x00000380L)
#define LUA_NO_SESSION                  (0x00000580L)

/*****************************************************************************/
/* LUA_RH.RUC masks                                                          */
/*****************************************************************************/
#define LUA_RH_FMD                      ((unsigned char)(0x00))
#define LUA_RH_NC                       ((unsigned char)(0x20))
#define LUA_RH_DFC                      ((unsigned char)(0x40))
#define LUA_RH_SC                       ((unsigned char)(0x60))

/*****************************************************************************/
/* LUA MESSAGE TYPES                                                         */
/*****************************************************************************/
#define LUA_MESSAGE_TYPE_LU_DATA        ((unsigned char)(0x01))
#define LUA_MESSAGE_TYPE_SSCP_DATA      ((unsigned char)(0x11))
#define LUA_MESSAGE_TYPE_RSP            ((unsigned char)(0x02))
#define LUA_MESSAGE_TYPE_PASSTHRU       ((unsigned char)(0x1F))
#define LUA_MESSAGE_TYPE_BID            ((unsigned char)(0xC8))
#define LUA_MESSAGE_TYPE_BIND           ((unsigned char)(0x31))
#define LUA_MESSAGE_TYPE_BIS            ((unsigned char)(0x70))
#define LUA_MESSAGE_TYPE_CANCEL         ((unsigned char)(0x83))
#define LUA_MESSAGE_TYPE_CHASE          ((unsigned char)(0x84))
#define LUA_MESSAGE_TYPE_CLEAR          ((unsigned char)(0xA1))
#define LUA_MESSAGE_TYPE_CRV            ((unsigned char)(0xD0))
#define LUA_MESSAGE_TYPE_LUSTAT_LU      ((unsigned char)(0x04))
#define LUA_MESSAGE_TYPE_LUSTAT_SSCP    ((unsigned char)(0x14))
#define LUA_MESSAGE_TYPE_QC             ((unsigned char)(0x81))
#define LUA_MESSAGE_TYPE_QEC            ((unsigned char)(0x80))
#define LUA_MESSAGE_TYPE_RELQ           ((unsigned char)(0x82))
#define LUA_MESSAGE_TYPE_RQR            ((unsigned char)(0xA3))
#define LUA_MESSAGE_TYPE_RTR            ((unsigned char)(0x05))
#define LUA_MESSAGE_TYPE_SBI            ((unsigned char)(0x71))
#define LUA_MESSAGE_TYPE_SHUTD          ((unsigned char)(0xC0))
#define LUA_MESSAGE_TYPE_SIGNAL         ((unsigned char)(0xC9))
#define LUA_MESSAGE_TYPE_SDT            ((unsigned char)(0xA0))
#define LUA_MESSAGE_TYPE_STSN           ((unsigned char)(0xA2))
#define LUA_MESSAGE_TYPE_UNBIND         ((unsigned char)(0x32))

 /****************************************************************************/
 /* LUA INIT TYPES  (Used for SLI only)                                      */
 /****************************************************************************/
 #define LUA_INIT_TYPE_SEC_IS           0x01
 #define LUA_INIT_TYPE_SEC_LOG          0x02
 #define LUA_INIT_TYPE_PRIM             0x03
 #define LUA_INIT_TYPE_PRIM_SSCP        0x04

 /****************************************************************************/
 /* LUA SESSION TYPES  (Used for SLI only)                                   */
 /****************************************************************************/
 #define LUA_SESSION_TYPE_NORMAL        0x00
 #define LUA_SESSION_TYPE_DEDICATED     0x01

 /****************************************************************************/
 /* LUA SLI_OPEN EXTENSION ROUTINE TYPES                                     */
 /****************************************************************************/
 #define LUA_ROUTINE_TYPE_BIND          0x01
 #define LUA_ROUTINE_TYPE_CRV           0x02
 #define LUA_ROUTINE_TYPE_STSN          0x03
 #define LUA_ROUTINE_TYPE_SDT           0x04
 #define LUA_ROUTINE_TYPE_END           0x00

 /****************************************************************************/
 /* LUA SLI_OPEN EXTENSION LIST CONSTANTS                                    */
 /****************************************************************************/
 #define MAX_EXTENSIONS                 4

 /****************************************************************************/
 /* LUA SLI/RUI DATA CONSTANTS                                               */
 /****************************************************************************/
 #define SEQ_NUM_SIZE                   2
 #define PEEK_DATA_SIZE                 12

/*****************************************************************************/
/* LUA VERB RECORD STRUCTURES                                                */
/*****************************************************************************/

/*****************************************************************************/
/* Transmission header structure                                             */
/*****************************************************************************/

/**STRUCT+********************************************************************/
/* Structure: LUA_TH                                                         */
/*                                                                           */
/* Description: LUA interpretation of Transmission Header                    */
/*****************************************************************************/

typedef struct lua_th
{
  unsigned char    flags_efi  : 1;        /* Expedited Flow Indicator        */
  unsigned char    flags_odai : 1;        /* OAF-DAF Assignor Indicator      */
  unsigned char    flags_mpf  : 2;        /* Segmenting Mapping Field        */
  unsigned char    flags_fid  : 4;        /* Format Identification Type 2    */
#define LUA_FID  ((unsigned char)(0xF0))
#define LUA_MPF  ((unsigned char)(0x0C))
#define LUA_BBIU ((unsigned char)(0x08))
#define LUA_EBIU ((unsigned char)(0x04))
#define LUA_ODAI ((unsigned char)(0x02))
#define LUA_EFI  ((unsigned char)(0x01))
  unsigned char reserv1;
  unsigned char daf;
  unsigned char oaf;
  unsigned char snf[2];
} LUA_TH;

/**STRUCT-********************************************************************/

/*****************************************************************************/
/* Request/Response unit header strcuture                                    */
/*****************************************************************************/
typedef struct lua_rh
{
  unsigned char    eci  : 1;              /* End Chain Indicator             */
  unsigned char    bci  : 1;              /* Begin Chain Indicator           */
  unsigned char    sdi  : 1;              /* Sense Data Included Ind         */
  unsigned char    fi   : 1;              /* Format Indicator                */
  unsigned char         : 1;              /* Reserved Field                  */
  unsigned char    ruc  : 2;              /* RU Category                     */
  unsigned char    rri  : 1;              /* Request-Response Indicator      */

  unsigned char    pi   : 1;              /* Pacing Indicator                */
  unsigned char    qri  : 1;              /* Queued Response Indicator       */
  unsigned char         : 2;              /* Reserved Field                  */
  unsigned char    ri   : 1;              /* Response Indicator              */
  unsigned char    dr2i : 1;              /* DR 2 Indicator                  */
  unsigned char         : 1;              /* Reserved Field                  */
  unsigned char    dr1i : 1;              /* DR 1 Indicator                  */

  unsigned char         : 1;              /* Reserved Field                  */
  unsigned char    pdi  : 1;              /* Padded Data Indicator           */
  unsigned char    edi  : 1;              /* Enciphered Data Indicator       */
  unsigned char    csi  : 1;              /* Code Selection Indicator        */
  unsigned char         : 1;              /* Reserved Field                  */
  unsigned char    cdi  : 1;              /* Change Direction Indicator      */
  unsigned char    ebi  : 1;              /* End Bracket Indicator           */
  unsigned char    bbi  : 1;              /* Begin Bracket Indicator         */
} LUA_RH;


/*****************************************************************************/
/* First byte of RH                                                          */
/*****************************************************************************/
#define LUA_RRI ((unsigned char)(0x80))
#define LUA_RUC ((unsigned char)(0x60))
#define LUA_FI  ((unsigned char)(0x08))
#define LUA_SDI ((unsigned char)(0x04))
#define LUA_BCI ((unsigned char)(0x02))
#define LUA_ECI ((unsigned char)(0x01))

/*****************************************************************************/
/* Second byte of RH                                                         */
/*****************************************************************************/
#define LUA_DR1I ((unsigned char)(0x80))
#define LUA_DR2I ((unsigned char)(0x20))
#define LUA_RI   ((unsigned char)(0x10))
#define LUA_QRI  ((unsigned char)(0x02))
#define LUA_PI   ((unsigned char)(0x01))

/*****************************************************************************/
/* Third byte of RH                                                          */
/*****************************************************************************/
#define LUA_BBI ((unsigned char)(0x80))
#define LUA_EBI ((unsigned char)(0x40))
#define LUA_CDI ((unsigned char)(0x20))
#define LUA_CSI ((unsigned char)(0x08))
#define LUA_EDI ((unsigned char)(0x04))
#define LUA_PDI ((unsigned char)(0x02))

/*****************************************************************************/
/* Structure for LUA_FLAG1                                                   */
/*****************************************************************************/
typedef struct LUA_FLAG1                  /* LUA_FLAG1                       */
{
  unsigned char  lu_norm     : 1;         /* lu normal flow                  */
  unsigned char  lu_exp      : 1;         /* LU expedited flow               */
  unsigned char  sscp_norm   : 1;         /* SSCP normal flow                */
  unsigned char  sscp_exp    : 1;         /* SSCP expedited flow             */
  unsigned char  nowait      : 1;         /* Don't Wait for Data Flag        */
  unsigned char  close_abend : 1;         /* reserved                        */
  unsigned char  reserv1     : 1;         /* reserved                        */
  unsigned char  bid_enable  : 1;         /* Bid Enabled Indicator           */
} LUA_FLAG1;

/*****************************************************************************/
/* Definitions for LUA_FLAG1                                                 */
/*****************************************************************************/
#define LUA_BID_ENABLE ((unsigned char)(0x80))
#define LUA_CLOSE_ABEND ((unsigned char)(0x20))                  /* reserved */
#define LUA_NOWAIT ((unsigned char)(0x10))
#define LUA_SSCP_EXP ((unsigned char)(0x08))
#define LUA_SSCP_NORM ((unsigned char)(0x04))
#define LUA_LU_EXP ((unsigned char)(0x02))
#define LUA_LU_NORM ((unsigned char)(0x01))

/*****************************************************************************/
/* Structure for LUA_FLAG2                                                   */
/*****************************************************************************/
typedef struct LUA_FLAG2                  /* LUA_FLAG2                       */
{
  unsigned char  lu_norm     : 1;         /* lu normal flow                  */
  unsigned char  lu_exp      : 1;         /* LU expedited flow               */
  unsigned char  sscp_norm   : 1;         /* SSCP normal flow                */
  unsigned char  sscp_exp    : 1;         /* SSCP expedited flow             */
  unsigned char              : 2;         /* reserved                        */
  unsigned char  async       : 1;         /* flags asynchronous verb
                                             completion                      */
  unsigned char  bid_enable  : 1;         /* Bid Enabled Indicator           */
} LUA_FLAG2;

/*****************************************************************************/
/* Definition for LUA_FLAG2                                                  */
/*****************************************************************************/
#define LUA_ASYNC ((unsigned char)(0x40))

/**STRUCT+********************************************************************/
/* Structure: LUA_COMMON                                                     */
/*                                                                           */
/* Description: Common verb header                                           */
/*****************************************************************************/

typedef struct lua_common
{
  unsigned short   lua_verb;
  unsigned short   lua_verb_length;
  unsigned short   lua_prim_rc;
  unsigned long    lua_sec_rc;
  unsigned short   lua_opcode;
  unsigned long    lua_correlator;
  unsigned char    lua_luname[8];
  unsigned short   lua_extension_list_offset;
  unsigned short   lua_cobol_offset;
  unsigned long    lua_sid;
  unsigned short   lua_max_length;
  unsigned short   lua_data_length;
  unsigned char   *lua_data_ptr;
  unsigned long    lua_post_handle;

  LUA_TH           lua_th;

  LUA_RH           lua_rh;
  LUA_FLAG1        lua_flag1;
  unsigned char    lua_message_type;
  LUA_FLAG2        lua_flag2;

  unsigned char    lua_resv56[7];
  unsigned char    lua_encr_decr_option;
} LUA_COMMON;


 /****************************************************************************/
 /*  LUA SPECIFIC FIELDS FOR THE SLI_OPEN VERB                               */
 /****************************************************************************/
typedef struct LUA_EXT_ENTRY
  {
  unsigned char lua_routine_type;       /* Extension Routine Type      */
  unsigned char lua_module_name[9];     /* Extension Module Name       */
  unsigned char lua_procedure_name[33]; /* Extension Procedure Name    */
  } LUA_EXT_ENTRY;

typedef struct SLI_OPEN
  {
  unsigned char lua_init_type;             /* Type of Session Initiation  */
  unsigned char lua_session_type;          /* SLI Session Type            */
  unsigned short  lua_wait;                /* Secondary Retry Wait Time   */
  LUA_EXT_ENTRY lua_open_extension[MAX_EXTENSIONS];
  unsigned char lua_ending_delim;          /* Extension List Delimiter    */
  }SLI_OPEN;

/**STRUCT+********************************************************************/
/* Structure: RUI_INIT                                                       */
/*                                                                           */
/* Description: Allows RUI application to specify LU it wants to use by      */
/*              supplying LU number and PU name, rather than LU name         */
/*****************************************************************************/

typedef struct rui_init
{
  unsigned char     rui_init_format;              /* %D{1}%                      */
  unsigned char     lua_puname[8];
  unsigned char     lua_lunumber;
  unsigned char     synchronous;
  unsigned char     rui_term_synchronous;
  unsigned char     wait_for_link;
  unsigned char     reserv1[13];

  unsigned char     tcpcv_len;

} RUI_INIT;

#define lua_resv65 lua_session_type
 /****************************************************************************/
 /* LUA SPECIFIC FIELDS FOR THE SLI_OPEN, SLI_SEND RUI_BID AND SLI_BID VERBS */
 /****************************************************************************/
typedef union LUA_SPECIFIC
  {
  struct SLI_OPEN  open;
  unsigned char    lua_sequence_number[SEQ_NUM_SIZE]; /* sequence number     */
  unsigned char    lua_peek_data[PEEK_DATA_SIZE];      /* Data Pending       */
  } LUA_SPECIFIC;

 /****************************************************************************/
 /* GENERIC LUA VERB RECORD TYPEDEF DECLARATION                              */
 /****************************************************************************/
typedef struct lua_verb_record
{
  LUA_COMMON  common;                       /* %STRUCT%                      */
  union
  {
    unsigned char   lua_peek_data[12];            /* %D{NULL_NAME}%              */
    RUI_INIT  init;                         /* %STRUCT%                      */
    struct SLI_OPEN open;
    unsigned char   lua_sequence_number[2];
  } specific;
} LUA_VERB_RECORD;

/*****************************************************************************/
/* Return codes from WinRUIStartup                                           */
/*****************************************************************************/
#define WLUASYSNOTREADY                 1
#define WLUAVERNOTSUPPORTED             2
#define WLUAINVALID                     3
#define WLUAFAILURE                     4
#define WLUAINITREJECT                  5

/*****************************************************************************/
/* Api structre definitions                                                  */
/*****************************************************************************/
#define WLUADESCRIPTION_LEN             40
typedef struct
{
  WORD wVersion;
  char szDescription[WLUADESCRIPTION_LEN + 1];
} LUADATA;

/*****************************************************************************/
/* Return codes from WinRUI                                                  */
/*****************************************************************************/
#define WLUAINVALIDHANDLE               10
#define WLUASTARTUPNOTCALLED            11

/*****************************************************************************/
/* New codes for RUI_INIT status messages                                    */
/*****************************************************************************/
#define WLUALINKINACTIVE                12
#define WLUALINKACTIVATING              13
#define WLUAPUINACTIVE                  14
#define WLUAPUACTIVE                    15
#define WLUAPUREACTIVATED               16
#define WLUALUINACTIVE                  17
#define WLUALUACTIVE                    18
#define WLUALUREACTIVATED               19
#define WLUASIDINVALID                  20
#define WLUASIDZERO                     21
#define WLUAALREADYACTIVE               22
#define WLUANTFYINVALID                 23
#define WLUAGLOBALHANDLER               24
#define WLUAGETLU                       25
#define WLUAUNKNOWN                     255


#define WLUA_NTFY_EVENT                  1
#define WLUA_NTFY_MSG_CORRELATOR         2
#define WLUA_NTFY_MSG_SID                3

/*****************************************************************************/
/* Windows RUI function prototypes                                           */
/*****************************************************************************/
int  WINAPI WinRUI (HWND, LUA_VERB_RECORD *);
int  WINAPI WinSLI (HWND, LUA_VERB_RECORD *);
BOOL WINAPI WinRUICleanup (void);
BOOL WINAPI WinSLICleanup (void);
int  WINAPI WinRUIStartup (WORD, LUADATA *);
int  WINAPI WinSLIStartup (WORD, LUADATA *);
void WINAPI RUI (LUA_VERB_RECORD *);
void WINAPI SLI (LUA_VERB_RECORD *);
int  WINAPI WinRUIGetLastInitStatus (DWORD, HANDLE, DWORD, BOOL);
int  WINAPI GetLuaReturnCode (LUA_COMMON *, UINT, unsigned char *);

/*****************************************************************************/
/* Asynchronous completion message                                           */
/*****************************************************************************/
#define WIN_RUI_ASYNC_COMPLETE_MESSAGE "WinRUI"
#define WIN_SLI_ASYNC_COMPLETE_MESSAGE "WinSLI"

/*****************************************************************************/
/* LUA VERB RECORD LENGTH CONSTANTS (SLI)                                    */
/*****************************************************************************/

#define LUA_SLI_OPEN_LENGTH ((char *)&(((LUA_VERB_RECORD *)0)->               \
                 specific.open.lua_ending_delim) - (char *)0) +               \
                 sizeof(((LUA_VERB_RECORD *)0)->specific.open.lua_ending_delim)
#define LUA_SLI_SEND_LENGTH (sizeof(LUA_COMMON)+(SEQ_NUM_SIZE))
#define LUA_SLI_BID_LENGTH  (sizeof(LUA_COMMON)+(PEEK_DATA_SIZE))
#define LUA_COMMON_LENGTH   (sizeof(LUA_COMMON))

/*****************************************************************************/
/* for Win32 environment, restore original packing mode                      */
/*****************************************************************************/
#pragma pack()

/*****************************************************************************/
/* Define this header file to be C if this is inluded by a C++ source file   */
/*****************************************************************************/
#ifdef __cplusplus
}
#endif

#endif
