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

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