root/src/simh/sim_tmxr.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


   1 /*
   2  * sim_tmxr.h: terminal multiplexer definitions
   3  *
   4  * vim: filetype=c:tabstop=4:ai:expandtab
   5  * SPDX-License-Identifier: MIT
   6  * scspell-id: ecf608fb-f62a-11ec-bbba-80ee73e9b8e7
   7  *
   8  * ---------------------------------------------------------------------------
   9  *
  10  * Copyright (c) 2001-2008 Robert M. Supnik
  11  * Copyright (c) 2021-2023 The DPS8M Development Team
  12  *
  13  * Permission is hereby granted, free of charge, to any person obtaining a
  14  * copy of this software and associated documentation files (the "Software"),
  15  * to deal in the Software without restriction, including without limitation
  16  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  17  * and/or sell copies of the Software, and to permit persons to whom the
  18  * Software is furnished to do so, subject to the following conditions:
  19  *
  20  * The above copyright notice and this permission notice shall be included
  21  * in all copies or substantial portions of the Software.
  22  *
  23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  24  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  26  * IN NO EVENT SHALL ROBERT M SUPNIK BE LIABLE FOR ANY CLAIM, DAMAGES OR
  27  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  28  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  29  * OTHER DEALINGS IN THE SOFTWARE.
  30  *
  31  * Except as contained in this notice, the name of Robert M. Supnik shall
  32  * not be used in advertising or otherwise to promote the sale, use or
  33  * other dealings in this Software without prior written authorization from
  34  * Robert M. Supnik.
  35  *
  36  * ---------------------------------------------------------------------------
  37  */
  38 
  39 /*
  40  *  Based on the original DZ11 simulator by Thord Nilson, as updated by
  41  *  Arthur Krewat.
  42  */
  43 
  44 #ifndef SIM_TMXR_H_
  45 # define SIM_TMXR_H_    0
  46 
  47 # ifndef SIMH_SERHANDLE_DEFINED
  48 #  define SIMH_SERHANDLE_DEFINED 0
  49 typedef struct SERPORT *SERHANDLE;
  50 # endif
  51 
  52 # include "sim_sock.h"
  53 
  54 # define TMXR_V_VALID    15
  55 # define TMXR_VALID      (1 << TMXR_V_VALID)
  56 # define TMXR_MAXBUF     256                    /* buffer size */
  57 
  58 # define TMXR_DTR_DROP_TIME               500   /* milliseconds to drop DTR for 'pseudo' modem control */
  59 # define TMXR_MODEM_RING_TIME               3   /* seconds to wait for DTR for incoming connections */
  60 # define TMXR_DEFAULT_CONNECT_POLL_INTERVAL 1   /* seconds between connection polls */
  61 
  62 # define TMXR_DBG_XMT    0x0010000    /* Debug Transmit Data */
  63 # define TMXR_DBG_RCV    0x0020000    /* Debug Received Data */
  64 # define TMXR_DBG_RET    0x0040000    /* Debug Returned Received Data */
  65 # define TMXR_DBG_MDM    0x0080000    /* Debug Modem Signals */
  66 # define TMXR_DBG_CON    0x0100000    /* Debug Connection Activities */
  67 # define TMXR_DBG_ASY    0x0200000    /* Debug Asynchronous Activities */
  68 # define TMXR_DBG_TRC    0x0400000    /* Debug trace routine calls */
  69 # define TMXR_DBG_PXMT   0x0800000    /* Debug Transmit Packet Data */
  70 # define TMXR_DBG_PRCV   0x1000000    /* Debug Received Packet Data */
  71 # define TMXR_DBG_EXP    0x2000000    /* Debug Expect Activities */
  72 # define TMXR_DBG_SEND   0x4000000    /* Debug Send Activities */
  73 
  74 /* Modem Control Bits */
  75 
  76 # define TMXR_MDM_DTR         0x01    /* Data Terminal Ready */
  77 # define TMXR_MDM_RTS         0x02    /* Request To Send     */
  78 # define TMXR_MDM_DCD         0x04    /* Data Carrier Detect */
  79 # define TMXR_MDM_RNG         0x08    /* Ring Indicator      */
  80 # define TMXR_MDM_CTS         0x10    /* Clear To Send       */
  81 # define TMXR_MDM_DSR         0x20    /* Data Set Ready      */
  82 # define TMXR_MDM_INCOMING   (TMXR_MDM_DCD|TMXR_MDM_RNG|TMXR_MDM_CTS|TMXR_MDM_DSR)  /* Settable Modem Bits */
  83 # define TMXR_MDM_OUTGOING   (TMXR_MDM_DTR|TMXR_MDM_RTS)  /* Settable Modem Bits */
  84 
  85 /* Unit flags */
  86 
  87 # define TMUF_V_NOASYNCH   (UNIT_V_UF + 12)             /* Asynch Disabled unit */
  88 # define TMUF_NOASYNCH     (1u << TMUF_V_NOASYNCH)      /* This flag can be defined */
  89                                                         /* statically in a unit's flag field */
  90                                                         /* This will disable the unit from */
  91                                                         /* supporting asynchronous mux behaviors */
  92 /* Receive line speed limits */
  93 
  94 # define TMLN_SPD_50_BPS     200000 /* usec per character */
  95 # define TMLN_SPD_75_BPS     133333 /* usec per character */
  96 # define TMLN_SPD_110_BPS     90909 /* usec per character */
  97 # define TMLN_SPD_134_BPS     74626 /* usec per character */
  98 # define TMLN_SPD_150_BPS     66666 /* usec per character */
  99 # define TMLN_SPD_300_BPS     33333 /* usec per character */
 100 # define TMLN_SPD_600_BPS     16666 /* usec per character */
 101 # define TMLN_SPD_1200_BPS     8333 /* usec per character */
 102 # define TMLN_SPD_1800_BPS     5555 /* usec per character */
 103 # define TMLN_SPD_2000_BPS     5000 /* usec per character */
 104 # define TMLN_SPD_2400_BPS     4166 /* usec per character */
 105 # define TMLN_SPD_3600_BPS     2777 /* usec per character */
 106 # define TMLN_SPD_4800_BPS     2083 /* usec per character */
 107 # define TMLN_SPD_7200_BPS     1388 /* usec per character */
 108 # define TMLN_SPD_9600_BPS     1041 /* usec per character */
 109 # define TMLN_SPD_19200_BPS     520 /* usec per character */
 110 # define TMLN_SPD_38400_BPS     260 /* usec per character */
 111 # define TMLN_SPD_57600_BPS     173 /* usec per character */
 112 # define TMLN_SPD_76800_BPS     130 /* usec per character */
 113 # define TMLN_SPD_115200_BPS     86 /* usec per character */
 114 
 115 typedef struct tmln TMLN;
 116 typedef struct tmxr TMXR;
 117 struct loopbuf {
 118     int32               bpr;                            /* xmt buf remove */
 119     int32               bpi;                            /* xmt buf insert */
 120     int32               size;
 121     };
 122 
 123 struct tmln {
 124     int                 conn;                           /* line connected flag */
 125     SOCKET              sock;                           /* connection socket */
 126     char                *ipad;                          /* IP address */
 127     SOCKET              master;                         /* line specific master socket */
 128     char                *port;                          /* line specific listening port */
 129     int32               sessions;                       /* count of tcp connections received */
 130     uint32              cnms;                           /* conn time */
 131     int32               tsta;                           /* Telnet state */
 132     int32               rcve;                           /* rcv enable */
 133     int32               xmte;                           /* xmt enable */
 134     int32               dstb;                           /* disable Telnet binary mode */
 135     t_bool              notelnet;                       /* raw binary data (no telnet interpretation) */
 136     uint8               *telnet_sent_opts;              /* Telnet Options which we have sent a DON'T/WON'T */
 137     int32               rxbpr;                          /* rcv buf remove */
 138     int32               rxbpi;                          /* rcv buf insert */
 139     int32               rxbsz;                          /* rcv buffer size */
 140     int32               rxcnt;                          /* rcv count */
 141     int32               rxpcnt;                         /* rcv packet count */
 142     int32               txbpr;                          /* xmt buf remove */
 143     int32               txbpi;                          /* xmt buf insert */
 144     int32               txcnt;                          /* xmt count */
 145     int32               txpcnt;                         /* xmt packet count */
 146     int32               txdrp;                          /* xmt drop count */
 147     int32               txbsz;                          /* xmt buffer size */
 148     int32               txbfd;                          /* xmt buffered flag */
 149     t_bool              modem_control;                  /* line supports modem control behaviors */
 150     int32               modembits;                      /* modem bits which are currently set */
 151     FILE                *txlog;                         /* xmt log file */
 152     FILEREF             *txlogref;                      /* xmt log file reference */
 153     char                *txlogname;                     /* xmt log file name */
 154     char                *rxb;                           /* rcv buffer */
 155     char                *rbr;                           /* rcv break */
 156     char                *txb;                           /* xmt buffer */
 157     uint8               *rxpb;                          /* rcv packet buffer */
 158     uint32              rxpbsize;                       /* rcv packet buffer size */
 159     uint32              rxpboffset;                     /* rcv packet buffer offset */
 160     uint32              rxbps;                          /* rcv bps speed (0 - unlimited) */
 161     double              rxbpsfactor;                    /* receive speed factor (scaled to usecs) */
 162 # define TMXR_RX_BPS_UNIT_SCALE 1000000.0
 163     uint32              rxdelta;                        /* rcv inter character min time (usecs) */
 164     double              rxnexttime;                     /* min time for next receive character */
 165     uint32              txbps;                          /* xmt bps speed (0 - unlimited) */
 166     uint32              txdelta;                        /* xmt inter character min time (usecs) */
 167     double              txnexttime;                     /* min time for next transmit character */
 168     uint8               *txpb;                          /* xmt packet buffer */
 169     uint32              txpbsize;                       /* xmt packet buffer size */
 170     uint32              txppsize;                       /* xmt packet packet size */
 171     uint32              txppoffset;                     /* xmt packet buffer offset */
 172     TMXR                *mp;                            /* back pointer to mux */
 173     char                *serconfig;                     /* line config */
 174     SERHANDLE           serport;                        /* serial port handle */
 175     t_bool              ser_connect_pending;            /* serial connection notice pending */
 176     SOCKET              connecting;                     /* Outgoing socket while connecting */
 177     char                *destination;                   /* Outgoing destination address:port */
 178     t_bool              loopback;                       /* Line in loopback mode */
 179     t_bool              halfduplex;                     /* Line in half-duplex mode */
 180     t_bool              datagram;                       /* Line is datagram packet oriented */
 181     t_bool              packet;                         /* Line is packet oriented */
 182     int32               lpbpr;                          /* loopback buf remove */
 183     int32               lpbpi;                          /* loopback buf insert */
 184     int32               lpbcnt;                         /* loopback buf used count */
 185     int32               lpbsz;                          /* loopback buffer size */
 186     char                *lpb;                           /* loopback buffer */
 187     UNIT                *uptr;                          /* input polling unit (default to mp->uptr) */
 188     UNIT                *o_uptr;                        /* output polling unit (default to lp->uptr)*/
 189     DEVICE              *dptr;                          /* line specific device */
 190     EXPECT              expect;                         /* Expect rules */
 191     SEND                send;                           /* Send input state */
 192     };
 193 
 194 struct tmxr {
 195     int32               lines;                          /* # lines */
 196     char                *port;                          /* listening port */
 197     SOCKET              master;                         /* master socket */
 198     TMLN                *ldsc;                          /* line descriptors */
 199     int32               *lnorder;                       /* line connection order */
 200     DEVICE              *dptr;                          /* multiplexer device */
 201     UNIT                *uptr;                          /* polling unit (connection) */
 202     char                logfiletmpl[FILENAME_MAX];      /* template logfile name */
 203     int32               txcount;                        /* count of transmit bytes */
 204     int32               buffered;                       /* Buffered Line Behavior and Buffer Size Flag */
 205     int32               sessions;                       /* count of tcp connections received */
 206     uint32              poll_interval;                  /* frequency of connection polls (seconds) */
 207     uint32              last_poll_time;                 /* time of last connection poll */
 208     uint32              ring_start_time;                /* time ring signal was raised */
 209     char                *ring_ipad;                     /* incoming connection address awaiting DTR */
 210     SOCKET              ring_sock;                      /* incoming connection socket awaiting DTR */
 211     t_bool              notelnet;                       /* default telnet capability for incoming connections */
 212     t_bool              modem_control;                  /* multiplexer supports modem control behaviors */
 213     t_bool              packet;                         /* Lines are packet oriented */
 214     t_bool              datagram;                       /* Lines use datagram packet transport */
 215     };
 216 
 217 int32 tmxr_poll_conn (TMXR *mp);
 218 t_stat tmxr_reset_ln (TMLN *lp);
 219 t_stat tmxr_detach_ln (TMLN *lp);
 220 int32 tmxr_input_pending_ln (TMLN *lp);
 221 int32 tmxr_getc_ln (TMLN *lp);
 222 t_stat tmxr_get_packet_ln (TMLN *lp, const uint8 **pbuf, size_t *psize);
 223 t_stat tmxr_get_packet_ln_ex (TMLN *lp, const uint8 **pbuf, size_t *psize, uint8 frame_byte);
 224 void tmxr_poll_rx (TMXR *mp);
 225 t_stat tmxr_putc_ln (TMLN *lp, int32 chr);
 226 t_stat tmxr_put_packet_ln (TMLN *lp, const uint8 *buf, size_t size);
 227 t_stat tmxr_put_packet_ln_ex (TMLN *lp, const uint8 *buf, size_t size, uint8 frame_byte);
 228 void tmxr_poll_tx (TMXR *mp);
 229 int32 tmxr_send_buffered_data (TMLN *lp);
 230 t_stat tmxr_open_master (TMXR *mp, CONST char *cptr);
 231 t_stat tmxr_close_master (TMXR *mp);
 232 t_stat tmxr_attach_ex (TMXR *mp, UNIT *uptr, CONST char *cptr, t_bool async);
 233 t_stat tmxr_detach (TMXR *mp, UNIT *uptr);
 234 t_stat tmxr_attach_help(FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, const char *cptr);
 235 char *tmxr_line_attach_string(TMLN *lp);
 236 t_stat tmxr_set_get_modem_bits (TMLN *lp, int32 bits_to_set, int32 bits_to_clear, int32 *incoming_bits);
 237 t_stat tmxr_set_line_loopback (TMLN *lp, t_bool enable_loopback);
 238 t_bool tmxr_get_line_loopback (TMLN *lp);
 239 t_stat tmxr_set_line_halfduplex (TMLN *lp, t_bool enable_loopback);
 240 t_bool tmxr_get_line_halfduplex (TMLN *lp);
 241 t_stat tmxr_set_line_speed (TMLN *lp, CONST char *speed);
 242 t_stat tmxr_set_line_unit (TMXR *mp, int line, UNIT *uptr_poll);
 243 t_stat tmxr_set_line_output_unit (TMXR *mp, int line, UNIT *uptr_poll);
 244 t_stat tmxr_ex (t_value *vptr, t_addr addr, UNIT *uptr, int32 sw);
 245 t_stat tmxr_dep (t_value val, t_addr addr, UNIT *uptr, int32 sw);
 246 void tmxr_msg (SOCKET sock, const char *msg);
 247 void tmxr_linemsg (TMLN *lp, const char *msg);
 248 void tmxr_linemsgf (TMLN *lp, const char *fmt, ...);
 249 void tmxr_linemsgvf (TMLN *lp, const char *fmt, va_list args);
 250 void tmxr_fconns (FILE *st, const TMLN *lp, int32 ln);
 251 void tmxr_fstats (FILE *st, const TMLN *lp, int32 ln);
 252 t_stat tmxr_set_log (UNIT *uptr, int32 val, CONST char *cptr, void *desc);
 253 t_stat tmxr_set_nolog (UNIT *uptr, int32 val, CONST char *cptr, void *desc);
 254 t_stat tmxr_show_log (FILE *st, UNIT *uptr, int32 val, CONST void *desc);
 255 t_stat tmxr_dscln (UNIT *uptr, int32 val, CONST char *cptr, void *desc);
 256 int32 tmxr_rqln (const TMLN *lp);
 257 int32 tmxr_tqln (const TMLN *lp);
 258 int32 tmxr_tpqln (const TMLN *lp);
 259 t_bool tmxr_tpbusyln (const TMLN *lp);
 260 t_stat tmxr_set_lnorder (UNIT *uptr, int32 val, CONST char *cptr, void *desc);
 261 t_stat tmxr_show_lnorder (FILE *st, UNIT *uptr, int32 val, CONST void *desc);
 262 t_stat tmxr_show_summ (FILE *st, UNIT *uptr, int32 val, CONST void *desc);
 263 t_stat tmxr_show_cstat (FILE *st, UNIT *uptr, int32 val, CONST void *desc);
 264 t_stat tmxr_show_lines (FILE *st, UNIT *uptr, int32 val, CONST void *desc);
 265 t_stat tmxr_show_open_devices (FILE* st, DEVICE *dptr, UNIT* uptr, int32 val, CONST char* desc);
 266 t_stat tmxr_activate (UNIT *uptr, int32 interval);
 267 t_stat tmxr_activate_after (UNIT *uptr, uint32 usecs_walltime);
 268 t_stat tmxr_change_async (void);
 269 t_stat tmxr_locate_line_send (const char *dev_line, SEND **snd);
 270 t_stat tmxr_locate_line_expect (const char *dev_line, EXPECT **exp);
 271 t_stat tmxr_startup (void);
 272 t_stat tmxr_shutdown (void);
 273 t_stat tmxr_start_poll (void);
 274 t_stat tmxr_stop_poll (void);
 275 void _tmxr_debug (uint32 dbits, TMLN *lp, const char *msg, char *buf, int bufsize);
 276 # define tmxr_debug(dbits, lp, msg, buf, bufsize) do {if (sim_deb && (lp)->mp && (lp)->mp->dptr && ((dbits) & (lp)->mp->dptr->dctrl)) _tmxr_debug (dbits, lp, msg, buf, bufsize); } while (0)
 277 # define tmxr_debug_msg(dbits, lp, msg) do {if (sim_deb && (lp)->mp && (lp)->mp->dptr && ((dbits) & (lp)->mp->dptr->dctrl)) sim_debug (dbits, (lp)->mp->dptr, "%s", msg); } while (0)
 278 # define tmxr_debug_return(lp, val) do {if (sim_deb && (val) && (lp)->mp && (lp)->mp->dptr && (TMXR_DBG_RET & (lp)->mp->dptr->dctrl)) { if ((lp)->rxbps) sim_debug (TMXR_DBG_RET, (lp)->mp->dptr, "Ln%d: 0x%x - Next after: %.0f\n", (int)((lp)-(lp)->mp->ldsc), val, (lp)->rxnexttime); else sim_debug (TMXR_DBG_RET, (lp)->mp->dptr, "Ln%d: 0x%x\n", (int)((lp)-(lp)->mp->ldsc), val); } } while (0)
 279 # define tmxr_debug_trace(mp, msg) do {if (sim_deb && (mp)->dptr && (TMXR_DBG_TRC & (mp)->dptr->dctrl)) sim_debug (TMXR_DBG_TRC, mp->dptr, "%s\n", (msg)); } while (0)
 280 # define tmxr_debug_trace_line(lp, msg) do {if (sim_deb && (lp)->mp && (lp)->mp->dptr && (TMXR_DBG_TRC & (lp)->mp->dptr->dctrl)) sim_debug (TMXR_DBG_TRC, (lp)->mp->dptr, "Ln%d:%s\n", (int)((lp)-(lp)->mp->ldsc), (msg)); } while (0)
 281 # define tmxr_debug_connect(mp, msg) do {if (sim_deb && (mp)->dptr && (TMXR_DBG_CON & (mp)->dptr->dctrl)) sim_debug (TMXR_DBG_CON, mp->dptr, "%s\n", (msg)); } while (0)
 282 # define tmxr_debug_connect_line(lp, msg) do {if (sim_deb && (lp)->mp && (lp)->mp->dptr && (TMXR_DBG_CON & (lp)->mp->dptr->dctrl)) sim_debug (TMXR_DBG_CON, (lp)->mp->dptr, "Ln%d:%s\n", (int)((lp)-(lp)->mp->ldsc), (msg)); } while (0)
 283 
 284 # define tmxr_attach(mp, uptr, cptr) tmxr_attach_ex(mp, uptr, cptr, FALSE)
 285 # if (!defined(NOT_MUX_USING_CODE))
 286 #  define sim_activate tmxr_activate
 287 #  define sim_activate_after tmxr_activate_after
 288 #  define sim_clock_coschedule tmxr_clock_coschedule
 289 #  define sim_clock_coschedule_abs tmxr_clock_coschedule_abs
 290 #  define sim_clock_coschedule_tmr tmxr_clock_coschedule_tmr
 291 #  define sim_clock_coschedule_tmr_abs tmxr_clock_coschedule_tmr_abs
 292 # endif
 293 
 294 #endif /* _SIM_TMXR_H_ */

/* [previous][next][first][last][top][bottom][index][help] */