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