1 /* COMMADPT.H   (c)Copyright Ivan Warren, 2003-2009                  */
2 /*              Structure definitions for 2703 line driver           */
3 
4 #ifndef __COMMADPT_H__
5 #define __COMMADPT_H__
6 
7 #include "hercules.h"
8 
9 #define TTYLINE_SZ 512
10 
11 typedef struct _COMMADPT_RING
12 {
13     BYTE *bfr;
14     size_t sz;
15     size_t hi;
16     size_t lo;
17     u_int havedata:1;
18     u_int overflow:1;
19 } COMMADPT_RING;
20 
21 struct COMMADPT
22 {
23     DEVBLK *dev;                /* the devblk to which this CA is attched   */
24     BYTE lnctl;                 /* Line control used                        */
25     BYTE term;                  /* Terminal type                            */
26     BYTE* code_table_toebcdic;  /* correspondence or EBCD code tables       */
27     BYTE* code_table_fromebcdic; /* correspondence or EBCD code tables      */
28     int  rto;                   /* Read Time-Out                            */
29     int  pto;                   /* Poll Time-Out                            */
30     int  eto;                   /* Enable Time-Out                          */
31     TID  cthread;               /* Thread used to control the socket        */
32     BYTE curpending;            /* Current pending operation                */
33     U16  lport;                 /* Local listening port                     */
34     in_addr_t lhost;            /* Local listening address                  */
35     U16 rport;                  /* Remote TCP Port                          */
36     in_addr_t rhost;            /* Remote connection IP address             */
37     int sfd;                    /* Communication socket FD                  */
38     int lfd;                    /* Listen socket for DIAL=IN, INOUT & NO    */
39     COND ipc;                   /* I/O <-> thread IPC condition EVB         */
40     COND ipc_halt;              /* I/O <-> thread IPC HALT special EVB      */
41     LOCK lock;                  /* COMMADPT lock                            */
42     int pipe[2];                /* pipe used for I/O to thread signaling    */
43     COMMADPT_RING inbfr;        /* Input buffer ring                        */
44     COMMADPT_RING outbfr;       /* Output buffer ring                       */
45     COMMADPT_RING pollbfr;      /* Ring used for POLL data                  */
46     COMMADPT_RING rdwrk;        /* Inbound data flow work ring              */
47     COMMADPT_RING ttybuf;       /* async: partial TTY input line            */
48     U16  devnum;                /* devnum copy from DEVBLK                  */
49     BYTE dialdata[32];          /* Dial data information                    */
50     U16  dialcount;             /* data count for dial                      */
51     BYTE pollix;                /* Next POLL Index                          */
52     U16  pollused;              /* Count of Poll data used during Poll      */
53     u_int enabled:1;            /* An ENABLE CCW has been sucesfully issued */
54     u_int connect:1;            /* A connection exists with the remote peer */
55     u_int eibmode:1;            /* EIB Setmode issued                       */
56     u_int dialin:1;             /* This is a SWITCHED DIALIN line           */
57     u_int dialout:1;            /* This is a SWITCHED DIALOUT line          */
58     u_int have_cthread:1;       /* the comm thread is running               */
59     u_int dolisten:1;           /* Start a listen                           */
60     u_int listening:1;          /* Listening                                */
61     u_int haltpending:1;        /* A request has been issued to halt current*/
62                                 /* CCW                                      */
63     u_int xparwwait:1;          /* Transparent Write Wait state : a Write   */
64                                 /* was previously issued that turned the    */
65                                 /* line into transparent mode. Anything     */
66                                 /* else than another write, Sense or NO-OP  */
67                                 /* is rejected with SENSE_CR                */
68                                 /* This condition is reset upon receipt of  */
69                                 /* DLE/ETX or DLE/ETB on a subsequent write */
70     u_int input_overrun:1;      /* The input ring buffer has overwritten    */
71                                 /* itself                                   */
72     u_int in_textmode:1;        /* Input buffer processing : text mode      */
73     u_int in_xparmode:1;        /* Input buffer processing : transparent    */
74     u_int gotdle:1;             /* DLE Received in inbound flow             */
75     u_int pollsm:1;             /* Issue Status Modifier on POLL Exit       */
76     u_int badpoll:1;            /* Bad poll data (>7 Bytes before ENQ)      */
77     u_int callissued:1;         /* The connect out for the DIAL/ENABLE      */
78                                 /* has already been issued                  */
79     u_int readcomp:1;           /* Data in the read buffer completes a read */
80     u_int datalostcond:1;       /* Data Lost Condition Raised               */
81     u_int telnet_opt:1;         /* expecting telnet option char             */
82     u_int telnet_iac:1;         /* expecting telnet command char            */
83     u_int telnet_int:1;         /* telnet interrupt received                */
84     u_int eol_flag:1;           /* carriage return received flag            */
85     u_int uctrans:1;            /* Uppercase translate flag                 */
86     u_int dumb_bs:1;            /* perform backspace editing in driver      */
87     u_int dumb_break:1;         /* map ASCII ETX (Ctrl-C) to interrupt/attn */
88     u_int haltprepare:1;        /* for race condition circumvention         */
89     u_int rxvt4apl:1;           /* 2741 mode for rxvt4apl                   */
90     u_int overstrike_flag:1;    /* overstrike sequence in progress          */
91     u_int crlf_opt:1;           /* map 2741 NL to CRLF                      */
92     u_int sendcr_opt:1;         /* send CR after input line received        */
93     u_int binary_opt:1;         /* initiate telnet binary mode              */
94     BYTE telnet_cmd;            /* telnet command received                  */
95     BYTE byte_skip_table[256];  /* async: characters to suppress in output  */
96     BYTE input_byte_skip_table[256];  /* async: characters to suppress in input  */
97     BYTE prepend_length;        /* number of bytes (0-4) to prepend         */
98     BYTE prepend_bytes[4];      /* bytes to prepend (per prepend_length)    */
99     BYTE append_length;         /* number of bytes (0-4) to append          */
100     BYTE append_bytes[4];       /* bytes to append (per append_length)      */
101     BYTE eol_char;              /* end of line character                    */
102     BYTE saved_char;            /* saved previous character for overstrike  */
103 };
104 
105 enum commadpt_lnctl {
106     COMMADPT_LNCTL_BSC=1,       /* BSC Line Control                         */
107     COMMADPT_LNCTL_ASYNC        /* ASYNC Line Control                       */
108 };
109 
110 enum commadpt_term {
111         COMMADPT_TERM_TTY,      /* TTY (TELE2) */
112         COMMADPT_TERM_2741,     /* 2741 (IBM1) */
113 };
114 
115 #define IS_BSC_LNCTL(ca)    ((ca->lnctl == COMMADPT_LNCTL_BSC))
116 #define IS_ASYNC_LNCTL(ca)  ((ca->lnctl == COMMADPT_LNCTL_ASYNC))
117 
118 enum commadpt_pendccw {
119     COMMADPT_PEND_IDLE=0,       /* NO CCW currently executing               */
120     COMMADPT_PEND_READ,         /* A READ CCW is running                    */
121     COMMADPT_PEND_WRITE,        /* A WRITE CCW is running                   */
122     COMMADPT_PEND_ENABLE,       /* A ENABLE CCW is running                  */
123     COMMADPT_PEND_DIAL,         /* A DIAL CCW is running                    */
124     COMMADPT_PEND_DISABLE,      /* A DISABLE CCW is running                 */
125     COMMADPT_PEND_PREPARE,      /* A PREPARE CCW is running                 */
126     COMMADPT_PEND_POLL,         /* A POLL CCW Is Running                    */
127     COMMADPT_PEND_TINIT,        /*                                          */
128     COMMADPT_PEND_CLOSED,       /*                                          */
129     COMMADPT_PEND_SHUTDOWN      /*                                          */
130 };
131 
132 #define COMMADPT_PEND_TEXT static char *commadpt_pendccw_text[]={\
133     "IDLE",\
134     "READ",\
135     "WRITE",\
136     "ENABLE",\
137     "DIAL",\
138     "DISABLE",\
139     "PREPARE",\
140     "POLL",\
141     "TINIT",\
142     "TCLOSED",\
143     "SHUTDOWN"}
144 
145 #endif
146