1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 #include <uv.h>
21 #include "libtelnet.h"
22
23 #define encodeline(fnp,line) ((fnp) * MAX_LINES + (line))
24 #define decodefnp(coded) ((coded) / MAX_LINES)
25 #define decodeline(coded) ((coded) % MAX_LINES)
26 #define noassoc -1
27
28 extern UNIT fnp_unit [N_FNP_UNITS_MAX];
29 extern DEVICE fnp_dev;
30
31 #define MAX_LINES 96
32
33
34
35
36
37
38 enum service_types {service_undefined = 0, service_login, service_3270, service_autocall, service_slave};
39
40 typedef struct t_MState
41 {
42 t_bool accept_calls;
43
44
45
46
47
48
49 word16 configRegA;
50 struct t_line
51 {
52
53 enum service_types service;
54
55
56
57
58 uv_tcp_t * line_client;
59
60
61 bool was_CR;
62
63
64 t_bool listen;
65 uint inputBufferSize;
66 uint ctrlStrIdx;
67 t_bool breakAll;
68 t_bool handleQuit;
69 t_bool fullDuplex;
70 t_bool echoPlex;
71 t_bool crecho;
72 t_bool lfecho;
73 t_bool tabecho;
74 t_bool replay;
75 t_bool polite;
76 t_bool prefixnl;
77 t_bool eight_bit_out;
78 t_bool eight_bit_in;
79 t_bool odd_parity;
80 t_bool output_flow_control;
81 t_bool input_flow_control;
82 uint block_xfer_in_frame_sz, block_xfer_out_frame_sz;
83 uint delay_table [6];
84 #define FC_STR_SZ 4
85 uint inputSuspendLen;
86 unsigned char inputSuspendStr [4];
87 uint inputResumeLen;
88 unsigned char inputResumeStr [4];
89 uint outputSuspendLen;
90 unsigned char outputSuspendStr [4];
91 uint outputResumeLen;
92 unsigned char outputResumeStr [4];
93 uint frame_begin;
94 uint frame_end;
95
96
97 bool echnego_break_table [256];
98 word18 echnego_sync_ctr;
99 word18 echnego_screen_left;
100 uint echnego_unechoed_cnt;
101 bool echnego_on;
102 bool echnego_synced;
103
104 uint sync_msg_size;
105
106 bool line_break;
107 #if defined(FNPDBG)
108 # define SEND_OUTPUT_DELAY 100
109 #else
110 # define SEND_OUTPUT_DELAY 2
111 #endif
112 uint send_output;
113 bool accept_new_terminal;
114 #if defined(DISC_DELAY)
115 uint line_disconnected;
116 #else
117 bool line_disconnected;
118 #endif
119 bool ack_echnego_init;
120 bool ack_echnego_stop;
121 bool acu_dial_failure;
122 bool sendLineStatus;
123 bool wru_timeout;
124 uint accept_input;
125
126
127
128 bool force_accept_input;
129
130 bool waitForMbxDone;
131
132
133
134
135 bool input_reply_pending;
136
137 bool input_break;
138
139
140 unsigned char buffer[1024];
141 uint nPos;
142
143
144 unsigned char * inBuffer;
145 uint inSize;
146 uint inUsed;
147
148
149 uv_connect_t doConnect;
150
151
152 uv_tcp_t server;
153 int port;
154
155 #if defined(TUN)
156
157 bool is_tun;
158 int tun_fd;
159 bool in_frame;
160 uint8_t frame [2+1500];
161 uint frameLen;
162 #endif
163
164 word9 lineType;
165 word36 lineStatus0, lineStatus1;
166 bool sendEOT;
167 } line [MAX_LINES];
168 } t_MState;
169
170
171
172 #define IBM3270_CONTROLLERS_MAX 1
173 #define IBM3270_STATIONS_MAX 32
174
175 struct ibm3270ctlr_s
176 {
177 bool configured;
178 uint fnpno;
179 uint lineno;
180
181
182 unsigned char pollCtlrChar;
183 unsigned char pollDevChar;
184 unsigned char selCtlrChar;
185 unsigned char selDevChar;
186 bool sending_stn_in_buffer;
187 uint stn_no;
188 struct station_s
189 {
190 uv_tcp_t * client;
191 bool EORReceived;
192 bool hdr_sent;
193 unsigned char * stn_in_buffer;
194 uint stn_in_size;
195 uint stn_in_used;
196
197 } stations [IBM3270_STATIONS_MAX];
198
199
200
201
202
203 bool write_complete;
204 };
205
206 #define MAX_DEV_NAME_LEN 64
207
208
209 struct fnpUnitData_s
210 {
211 char device_name [MAX_DEV_NAME_LEN];
212 word24 mailboxAddress;
213 bool fnpIsRunning;
214 bool fnpMBXinUse [4];
215 bool lineWaiting [4];
216 int fnpMBXlineno [4];
217 char ipcName [MAX_DEV_NAME_LEN];
218
219 t_MState MState;
220 };
221
222 typedef struct s_fnpData
223 {
224 struct fnpUnitData_s fnpUnitData [N_FNP_UNITS_MAX];
225 struct ibm3270ctlr_s ibm3270ctlr [IBM3270_CONTROLLERS_MAX];
226 char * telnet_address;
227 int telnet_port;
228 int telnet3270_port;
229 uv_loop_t * loop;
230 uv_tcp_t du_server;
231 bool du_server_inited;
232 uv_tcp_t du3270_server;
233 bool du3270_server_inited;
234 int du3270_poll;
235 } t_fnpData;
236
237 extern t_fnpData fnpData;
238
239
240
241
242
243
244
245
246
247
248
249
250
251 struct dn355_submailbox
252 {
253 word36 word1;
254 word36 word2;
255 word36 command_data [3];
256 word36 word6;
257 word36 pad3 [2];
258 };
259
260 struct fnp_submailbox
261 {
262
263 word36 word1;
264 word36 word2;
265 word36 mystery [26];
266 };
267
268 struct input_sub_mbx
269 {
270 word36 word1;
271 word36 word2;
272 word36 n_buffers;
273 word36 dcws [24];
274 word36 command_data;
275 };
276
277 struct mailbox
278 {
279 word36 dia_pcw;
280 word36 mailbox_requests;
281 word36 term_inpt_mpx_wd;
282 word36 last_mbx_req_count;
283 word36 num_in_use;
284 word36 mbx_used_flags;
285 word36 crash_data [2];
286 struct dn355_submailbox dn355_sub_mbxes [8];
287 struct fnp_submailbox fnp_sub_mbxes [4];
288 };
289
290 #define MAILBOX_WORDS (sizeof (struct mailbox) / sizeof (word36))
291
292 #define DIA_PCW (offsetof (struct mailbox, dia_pcw) / sizeof (word36))
293 #define TERM_INPT_MPX_WD (offsetof (struct mailbox, term_inpt_mpx_wd) / sizeof (word36))
294 #define CRASH_DATA (offsetof (struct mailbox, crash_data) / sizeof (word36))
295 #define DN355_SUB_MBXES (offsetof (struct mailbox, dn355_sub_mbxes) / sizeof (word36))
296 #define FNP_SUB_MBXES (offsetof (struct mailbox, fnp_sub_mbxes) / sizeof (word36))
297
298 #define FNP_SUB_MBX_SIZE (sizeof (struct fnp_submailbox) / sizeof (word36))
299 #define DN355_SUB_MBX_SIZE (sizeof (struct dn355_submailbox) / sizeof (word36))
300
301 #define WORD1 0
302 #define WORD2 1
303 #define COMMAND_DATA 2
304 #define MYSTERY 2
305 #define WORD6 5
306 #define N_BUFFERS 2
307 #define DCWS 3
308 #define N_DCWS 24
309 #define INP_COMMAND_DATA 27
310
311 extern const unsigned char a2e [256];
312 extern const unsigned char e2a [256];
313 #define ADDR_MAP_ENTRIES 32
314
315
316 extern const unsigned char addr_map [ADDR_MAP_ENTRIES];
317
318 #define N_FW_ENTRIES 1024
319 extern int n_fw_entries;
320 struct fw_entry_s
321 {
322 uint line_0, line_1;
323 uint32_t ipaddr;
324 uint cidr;
325 uint32_t cidr_mask;
326 bool accept;
327 };
328 extern struct fw_entry_s fw_entries [N_FW_ENTRIES];
329
330 void fnpInit(void);
331 void fnpExit (void);
332 int lookupFnpsIomUnitNumber (int fnpUnitNum);
333 int lookupFnpLink (int fnpUnitNum);
334 void fnpProcessEvent (void);
335 t_stat diaCommand (int fnpUnitNum, char *arg3);
336 void fnpToCpuQueueMsg (int fnpUnitNum, char * msg);
337 iom_cmd_rc_t fnp_iom_cmd (uint iomUnitIdx, uint chan);
338 t_stat set_fnp_server_port (int32 arg, const char * buf);
339 t_stat set_fnp_server_address (int32 arg, const char * buf);
340 t_stat set_fnp_3270_server_port (int32 arg, const char * buf);
341 t_stat fnp_start (UNUSED int32 arg, UNUSED const char * buf);
342 void fnpConnectPrompt (uv_tcp_t * client);
343 void fnp3270ConnectPrompt (uv_tcp_t * client);
344 void processUserInput (uv_tcp_t * client, unsigned char * buf, ssize_t nread);
345 void processLineInput (uv_tcp_t * client, unsigned char * buf, ssize_t nread);
346 void fnpRecvEOR (uv_tcp_t * client);
347 void process3270Input (uv_tcp_t * client, unsigned char * buf, ssize_t nread);
348 void set_3270_write_complete (uv_tcp_t * client);
349 void startFNPListener (void);
350 void setTIMW (uint iom_unit_idx, uint chan, word24 mailboxAddress, int mbx);