1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 #if !defined(SIM_TMXR_H_)
45 # define SIM_TMXR_H_ 0
46
47 # if !defined(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
57
58 # define TMXR_DTR_DROP_TIME 500
59 # define TMXR_MODEM_RING_TIME 3
60 # define TMXR_DEFAULT_CONNECT_POLL_INTERVAL 1
61
62 # define TMXR_DBG_XMT 0x0010000
63 # define TMXR_DBG_RCV 0x0020000
64 # define TMXR_DBG_RET 0x0040000
65 # define TMXR_DBG_MDM 0x0080000
66 # define TMXR_DBG_CON 0x0100000
67 # define TMXR_DBG_ASY 0x0200000
68 # define TMXR_DBG_TRC 0x0400000
69 # define TMXR_DBG_PXMT 0x0800000
70 # define TMXR_DBG_PRCV 0x1000000
71 # define TMXR_DBG_EXP 0x2000000
72 # define TMXR_DBG_SEND 0x4000000
73
74
75
76 # define TMXR_MDM_DTR 0x01
77 # define TMXR_MDM_RTS 0x02
78 # define TMXR_MDM_DCD 0x04
79 # define TMXR_MDM_RNG 0x08
80 # define TMXR_MDM_CTS 0x10
81 # define TMXR_MDM_DSR 0x20
82 # define TMXR_MDM_INCOMING (TMXR_MDM_DCD|TMXR_MDM_RNG|TMXR_MDM_CTS|TMXR_MDM_DSR)
83 # define TMXR_MDM_OUTGOING (TMXR_MDM_DTR|TMXR_MDM_RTS)
84
85
86
87 # define TMUF_V_NOASYNCH (UNIT_V_UF + 12)
88 # define TMUF_NOASYNCH (1u << TMUF_V_NOASYNCH)
89
90
91
92
93
94 # define TMLN_SPD_50_BPS 200000
95 # define TMLN_SPD_75_BPS 133333
96 # define TMLN_SPD_110_BPS 90909
97 # define TMLN_SPD_134_BPS 74626
98 # define TMLN_SPD_150_BPS 66666
99 # define TMLN_SPD_300_BPS 33333
100 # define TMLN_SPD_600_BPS 16666
101 # define TMLN_SPD_1200_BPS 8333
102 # define TMLN_SPD_1800_BPS 5555
103 # define TMLN_SPD_2000_BPS 5000
104 # define TMLN_SPD_2400_BPS 4166
105 # define TMLN_SPD_3600_BPS 2777
106 # define TMLN_SPD_4800_BPS 2083
107 # define TMLN_SPD_7200_BPS 1388
108 # define TMLN_SPD_9600_BPS 1041
109 # define TMLN_SPD_19200_BPS 520
110 # define TMLN_SPD_38400_BPS 260
111 # define TMLN_SPD_57600_BPS 173
112 # define TMLN_SPD_76800_BPS 130
113 # define TMLN_SPD_115200_BPS 86
114
115 typedef struct tmln TMLN;
116 typedef struct tmxr TMXR;
117 struct loopbuf {
118 int32 bpr;
119 int32 bpi;
120 int32 size;
121 };
122
123 struct tmln {
124 int conn;
125 SOCKET sock;
126 char *ipad;
127 SOCKET master;
128 char *port;
129 int32 sessions;
130 uint32 cnms;
131 int32 tsta;
132 int32 rcve;
133 int32 xmte;
134 int32 dstb;
135 t_bool notelnet;
136 uint8 *telnet_sent_opts;
137 int32 rxbpr;
138 int32 rxbpi;
139 int32 rxbsz;
140 int32 rxcnt;
141 int32 rxpcnt;
142 int32 txbpr;
143 int32 txbpi;
144 int32 txcnt;
145 int32 txpcnt;
146 int32 txdrp;
147 int32 txbsz;
148 int32 txbfd;
149 t_bool modem_control;
150 int32 modembits;
151 FILE *txlog;
152 FILEREF *txlogref;
153 char *txlogname;
154 char *rxb;
155 char *rbr;
156 char *txb;
157 uint8 *rxpb;
158 uint32 rxpbsize;
159 uint32 rxpboffset;
160 uint32 rxbps;
161 double rxbpsfactor;
162 # define TMXR_RX_BPS_UNIT_SCALE 1000000.0
163 uint32 rxdelta;
164 double rxnexttime;
165 uint32 txbps;
166 uint32 txdelta;
167 double txnexttime;
168 uint8 *txpb;
169 uint32 txpbsize;
170 uint32 txppsize;
171 uint32 txppoffset;
172 TMXR *mp;
173 char *serconfig;
174 SERHANDLE serport;
175 t_bool ser_connect_pending;
176 SOCKET connecting;
177 char *destination;
178 t_bool loopback;
179 t_bool halfduplex;
180 t_bool datagram;
181 t_bool packet;
182 int32 lpbpr;
183 int32 lpbpi;
184 int32 lpbcnt;
185 int32 lpbsz;
186 char *lpb;
187 UNIT *uptr;
188 UNIT *o_uptr;
189 DEVICE *dptr;
190 EXPECT expect;
191 SEND send;
192 };
193
194 struct tmxr {
195 int32 lines;
196 char *port;
197 SOCKET master;
198 TMLN *ldsc;
199 int32 *lnorder;
200 DEVICE *dptr;
201 UNIT *uptr;
202 char logfiletmpl[FILENAME_MAX];
203 int32 txcount;
204 int32 buffered;
205 int32 sessions;
206 uint32 poll_interval;
207 uint32 last_poll_time;
208 uint32 ring_start_time;
209 char *ring_ipad;
210 SOCKET ring_sock;
211 t_bool notelnet;
212 t_bool modem_control;
213 t_bool packet;
214 t_bool datagram;
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
277 # define tmxr_debug(dbits, lp, msg, buf, bufsize) \
278 do { if (sim_deb && (lp)->mp && (lp)->mp->dptr && ((dbits) & (lp)->mp->dptr->dctrl)) \
279 _tmxr_debug (dbits, lp, msg, buf, bufsize); } while (0)
280
281 # define tmxr_debug_msg(dbits, lp, msg) \
282 do { if (sim_deb && (lp)->mp && (lp)->mp->dptr && ((dbits) & (lp)->mp->dptr->dctrl)) \
283 sim_debug (dbits, (lp)->mp->dptr, "%s", msg); } while (0)
284
285 # define tmxr_debug_return(lp, val) \
286 do { if (sim_deb && (val) && (lp)->mp && (lp)->mp->dptr && (TMXR_DBG_RET & (lp)->mp->dptr->dctrl)) \
287 { if ((lp)->rxbps) sim_debug (TMXR_DBG_RET, (lp)->mp->dptr, "Ln%d: 0x%x - Next after: %.0f\n", \
288 (int)((lp)-(lp)->mp->ldsc), val, (lp)->rxnexttime); \
289 else sim_debug (TMXR_DBG_RET, (lp)->mp->dptr, "Ln%d: 0x%x\n", (int)((lp)-(lp)->mp->ldsc), val); \
290 } } while (0)
291
292 # define tmxr_debug_trace(mp, msg) \
293 do { if (sim_deb && (mp)->dptr && (TMXR_DBG_TRC & (mp)->dptr->dctrl)) \
294 sim_debug (TMXR_DBG_TRC, mp->dptr, "%s\n", (msg)); } while (0)
295
296 # define tmxr_debug_trace_line(lp, msg) \
297 do { if (sim_deb && (lp)->mp && (lp)->mp->dptr && (TMXR_DBG_TRC & (lp)->mp->dptr->dctrl)) \
298 sim_debug (TMXR_DBG_TRC, (lp)->mp->dptr, "Ln%d:%s\n", (int)((lp)-(lp)->mp->ldsc), (msg)); } while (0)
299
300 # define tmxr_debug_connect(mp, msg) \
301 do { if (sim_deb && (mp)->dptr && (TMXR_DBG_CON & (mp)->dptr->dctrl)) \
302 sim_debug (TMXR_DBG_CON, mp->dptr, "%s\n", (msg)); } while (0)
303
304 # define tmxr_debug_connect_line(lp, msg) \
305 do { if (sim_deb && (lp)->mp && (lp)->mp->dptr && (TMXR_DBG_CON & (lp)->mp->dptr->dctrl)) \
306 sim_debug (TMXR_DBG_CON, (lp)->mp->dptr, "Ln%d:%s\n", (int)((lp)-(lp)->mp->ldsc), (msg)); } while (0)
307
308 # define tmxr_attach(mp, uptr, cptr) tmxr_attach_ex(mp, uptr, cptr, FALSE)
309
310 # if (!defined(NOT_MUX_USING_CODE))
311 # define sim_activate tmxr_activate
312 # define sim_activate_after tmxr_activate_after
313 # define sim_clock_coschedule tmxr_clock_coschedule
314 # define sim_clock_coschedule_abs tmxr_clock_coschedule_abs
315 # define sim_clock_coschedule_tmr tmxr_clock_coschedule_tmr
316 # define sim_clock_coschedule_tmr_abs tmxr_clock_coschedule_tmr_abs
317 # endif
318
319 #endif