root/src/dps8/dps8_fnp2.h

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

INCLUDED FROM


   1 /*
   2  * vim: filetype=c:tabstop=4:ai:expandtab
   3  * SPDX-License-Identifier: ICU
   4  * scspell-id: 5118dce3-f62e-11ec-8fe3-80ee73e9b8e7
   5  *
   6  * ---------------------------------------------------------------------------
   7  *
   8  * Copyright (c) 2007-2013 Michael Mondy
   9  * Copyright (c) 2012-2016 Harry Reed
  10  * Copyright (c) 2013-2016 Charles Anthony
  11  * Copyright (c) 2016 Michal Tomek
  12  * Copyright (c) 2021-2024 The DPS8M Development Team
  13  *
  14  * This software is made available under the terms of the ICU License.
  15  * See the LICENSE.md file at the top-level directory of this distribution.
  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  /*  max number of FNP lines - hardware  */
  32 
  33 //
  34 // MState_t state of an FNP
  35 //
  36 
  37 // memset(0) sets service to service_undefined (0)
  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     // 60132445 FEP Coupler Spec Nov77 - Unknown.pdf
  44     // pg 59 (sheet 56):
  45     //   bit       0: CS BAR
  46     //             1: BT INH
  47     //        2 -  7: RFU
  48     //        8 - 15: Special L6 Intpr Level
  49     word16 configRegA;
  50     struct t_line
  51       {
  52         // From the CMF database
  53         enum service_types service;
  54 
  55         // libuv hook
  56         // For non-multiplexed lines, the connection to the remote is stored here;
  57         // For multiplexed lines (3270), the connection to the currently selected station is stored here. Used by wtx.
  58         uv_tcp_t * line_client;
  59 
  60         // libtelnet hook
  61         bool was_CR;
  62 
  63         // State as set by FNP commands
  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;    // echoes all characters types on the terminal
  71         t_bool crecho;      // echos a CR when a LF is typed
  72         t_bool lfecho;      // echos and inserts  a LF in the users input stream when a CR is typed
  73         t_bool tabecho;     // echos the appropriate number of spaces when a TAB is typed
  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         // Echonego
  97         bool echnego_break_table [256];
  98         word18 echnego_sync_ctr; // Sent by MCS
  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         // Pending requests
 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; // If non-zero, the number of centiseconds until
 125                           // an accept_input message should be sent; this is
 126                           // deal with 'reject_request' retries.
 127         // The 3270 controller always uses ACCEPT_INPUT
 128         bool force_accept_input;
 129 
 130         bool waitForMbxDone; // If set, the line has sent input to the CS,
 131                              // but the CS has not completed the mbx transaction;
 132                              // in order to prevent input data reordering, serialize
 133                              // the commands by waiting for this to clear before
 134                              // sending the next input.
 135         bool input_reply_pending;
 136         // Part of 'accept_input'
 137         bool input_break;
 138 
 139         // Buffer being assembled for sending to Multics
 140         unsigned char buffer[1024];   // line buffer for initial device selection and line discipline
 141         uint nPos;           // position where *next* user input is to be stored
 142 
 143         // Incoming data from the connection
 144         unsigned char * inBuffer;
 145         uint inSize; // Number of bytes in inBuffer
 146         uint inUsed; // Number of consumed bytes in buffer
 147 
 148         // Dialout hooks
 149         uv_connect_t doConnect;
 150 
 151         // Slave hooks
 152         uv_tcp_t server;
 153         int port;
 154 
 155 #if defined(TUN)
 156         // TUN hook
 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 // for now, one controller
 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     // polling and selection addresses
 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; // Number of bytes in inBuffer
 195         uint stn_in_used;
 196         //uint stn_in_used; // Number of consumed bytes in buffer
 197       } stations [IBM3270_STATIONS_MAX];
 198     // Although this is nominally a per/station event, Multics will not
 199     // resume polling until after the write is complete, so only
 200     // one event would be pending at any time; moving it out of the
 201     // 'stations' structure makes it easier for the emulator event
 202     // loops to see.
 203     bool write_complete;
 204   };
 205 
 206 #define MAX_DEV_NAME_LEN 64
 207 
 208 // Indexed by sim unit number
 209 struct fnpUnitData_s
 210   {
 211     char device_name [MAX_DEV_NAME_LEN];
 212     word24 mailboxAddress;
 213     bool fnpIsRunning;
 214     bool fnpMBXinUse [4];  // 4 FNP submailboxes
 215     bool lineWaiting [4]; // If set, fnpMBXlineno is waiting for the mailbox to be marked clear.
 216     int fnpMBXlineno [4]; // Which HSLA line is using the mbx
 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 // dn355_mailbox.incl.pl1
 240 //   input_sub_mbx
 241 //       pad1:8, line_number:10, n_free_buffers:18
 242 //       n_chars:18, op_code:9, io_cmd:9
 243 //       n_buffers
 244 //       { abs_addr:24, tally:12 } [24]
 245 //       command_data
 246 
 247 //
 248 // The FNP communicates with Multics with in-memory mailboxes
 249 //
 250 
 251 struct dn355_submailbox
 252   {
 253     word36 word1; // dn355_no; is_hsla; la_no; slot_no
 254     word36 word2; // cmd_data_len; op_code; io_cmd
 255     word36 command_data [3];
 256     word36 word6; // data_addr, word_cnt;
 257     word36 pad3 [2];
 258   };
 259 
 260 struct fnp_submailbox // 28 words
 261   {
 262                                                                  // AN85
 263     word36 word1; // dn355_no; is_hsla; la_no; slot_no    // 0      word0
 264     word36 word2; // cmd_data_len; op_code; io_cmd        // 1      word1
 265     word36 mystery [26];                                         // word2...
 266   };
 267 
 268 struct input_sub_mbx
 269   {
 270     word36 word1; // dn355_no; is_hsla; la_no; slot_no    // 0      word0
 271     word36 word2; // cmd_data_len; op_code; io_cmd        // 1      word1
 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 // map station number to selDevChar
 315 // addr_map [stn_no] == selDevChar
 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; // range of lines
 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);

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