1%% 2%% %CopyrightBegin% 3%% 4%% Copyright Ericsson AB 2005-2020. All Rights Reserved. 5%% 6%% Licensed under the Apache License, Version 2.0 (the "License"); 7%% you may not use this file except in compliance with the License. 8%% You may obtain a copy of the License at 9%% 10%% http://www.apache.org/licenses/LICENSE-2.0 11%% 12%% Unless required by applicable law or agreed to in writing, software 13%% distributed under the License is distributed on an "AS IS" BASIS, 14%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15%% See the License for the specific language governing permissions and 16%% limitations under the License. 17%% 18%% %CopyrightEnd% 19%% 20 21%% 22 23%%% Description : SSH connection protocol 24 25-define(DEFAULT_PACKET_SIZE, 65536). 26-define(DEFAULT_WINDOW_SIZE, 10*?DEFAULT_PACKET_SIZE). 27 28-define(DEFAULT_TIMEOUT, 5000). 29-define(MAX_PROTO_VERSION, 255). % Max length of the hello string 30 31%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 32%% 33%% CONNECT messages 34%% 35%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 36 37%%%---------------------------------------------------------------------- 38%%% # SSH_MSG_xxx 39%%% Description: Packet types used by the connection protocol. 40%%%---------------------------------------------------------------------- 41-define(SSH_MSG_GLOBAL_REQUEST, 80). 42-define(SSH_MSG_REQUEST_SUCCESS, 81). 43-define(SSH_MSG_REQUEST_FAILURE, 82). 44-define(SSH_MSG_CHANNEL_OPEN, 90). 45-define(SSH_MSG_CHANNEL_OPEN_CONFIRMATION, 91). 46-define(SSH_MSG_CHANNEL_OPEN_FAILURE, 92). 47-define(SSH_MSG_CHANNEL_WINDOW_ADJUST, 93). 48-define(SSH_MSG_CHANNEL_DATA, 94). 49-define(SSH_MSG_CHANNEL_EXTENDED_DATA, 95). 50-define(SSH_MSG_CHANNEL_EOF, 96). 51-define(SSH_MSG_CHANNEL_CLOSE, 97). 52-define(SSH_MSG_CHANNEL_REQUEST, 98). 53-define(SSH_MSG_CHANNEL_SUCCESS, 99). 54-define(SSH_MSG_CHANNEL_FAILURE, 100). 55 56-record(ssh_msg_global_request, 57 { 58 name, 59 want_reply, 60 data %% ... 61 }). 62 63-record(ssh_msg_request_success, 64 { 65 data %% ... 66 }). 67 68-record(ssh_msg_request_failure, 69 { 70 }). 71 72 73-record(ssh_msg_channel_open, 74 { 75 channel_type, 76 sender_channel, 77 initial_window_size, 78 maximum_packet_size, 79 data %% ... 80 }). 81 82-record(ssh_msg_channel_open_confirmation, 83 { 84 recipient_channel, 85 sender_channel, 86 initial_window_size, 87 maximum_packet_size, 88 data %% ... 89 }). 90 91 92%%%---------------------------------------------------------------------- 93%%% # SSH_OPEN_xxx 94%%% Description: Reason codes for SSH_MSG_OPEN_FAILURE packages. 95%%%---------------------------------------------------------------------- 96 97-define(SSH_OPEN_ADMINISTRATIVELY_PROHIBITED, 1). 98-define(SSH_OPEN_CONNECT_FAILED, 2). 99-define(SSH_OPEN_UNKNOWN_CHANNEL_TYPE, 3). 100-define(SSH_OPEN_RESOURCE_SHORTAGE, 4). 101 102-record(ssh_msg_channel_open_failure, 103 { 104 recipient_channel, 105 reason, 106 description, 107 lang 108 }). 109 110 111-record(ssh_msg_channel_window_adjust, 112 { 113 recipient_channel, 114 bytes_to_add 115 }). 116 117-record(ssh_msg_channel_data, 118 { 119 recipient_channel, 120 data 121 }). 122 123%%%---------------------------------------------------------------------- 124%%% # SSH_EXTENDED_DATA_xxx 125%%% Description: Type codes for SSH_MSG_CHANNEL_EXTENDED_DATA packages 126%%%---------------------------------------------------------------------- 127-define(SSH_EXTENDED_DATA_DEFAULT, 0). 128-define(SSH_EXTENDED_DATA_STDERR, 1). 129 130-record(ssh_msg_channel_extended_data, 131 { 132 recipient_channel, 133 data_type_code, 134 data 135 }). 136 137-record(ssh_msg_channel_eof, 138 { 139 recipient_channel 140 }). 141 142-record(ssh_msg_channel_close, 143 { 144 recipient_channel 145 }). 146 147 148-record(ssh_msg_channel_request, 149 { 150 recipient_channel, 151 request_type, 152 want_reply, 153 data %% ... 154 }). 155 156 157-record(ssh_msg_channel_success, 158 { 159 recipient_channel 160 }). 161 162 163-record(ssh_msg_channel_failure, 164 { 165 recipient_channel 166 }). 167 168-define(TERMINAL_WIDTH, 80). 169-define(TERMINAL_HEIGHT, 24). 170-define(DEFAULT_TERMINAL, "vt100"). 171 172-define(TTY_OP_END,0). %% Indicates end of options. 173-define(VINTR,1). %% Interrupt character; 255 if none. Similarly for the 174 %% other characters. Not all of these characters are 175 %% supported on all systems. 176-define(VQUIT,2). %% The quit character (sends SIGQUIT signal on POSIX 177 %% systems). 178-define(VERASE,3). %% Erase the character to left of the cursor. 179-define(VKILL,4). %% Kill the current input line. 180-define(VEOF,5). %% End-of-file character (sends EOF from the terminal). 181-define(VEOL,6). %% End-of-line character in addition to carriage return 182 %% or,and). linefeed. 183-define(VEOL2,7). %% Additional end-of-line character. 184-define(VSTART,8). %% Continues paused output (normally control-Q). 185-define(VSTOP,9). %% Pauses output (normally control-S). 186-define(VSUSP,10). %% Suspends the current program. 187-define(VDSUSP,11). %% Another suspend character. 188-define(VREPRINT,12). %% Reprints the current input line. 189-define(VWERASE,13). %% Erases a word left of cursor. 190-define(VLNEXT,14). %% Enter the next character typed literally, even if it 191 %% is a special character 192-define(VFLUSH,15). %% Character to flush output. 193-define(VSWTCH,16). %% Switch to a different shell layer. 194-define(VSTATUS,17). %% Prints system status line (load, command, pid etc). 195-define(VDISCARD,18). %% Toggles the flushing of terminal output. 196-define(IGNPAR,30). %% The ignore parity flag. The parameter SHOULD be 0 if 197 %% this flag is FALSE set, and 1 if it is TRUE. 198-define(PARMRK,31). %% Mark parity and framing errors. 199-define(INPCK,32). %% Enable checking of parity errors. 200-define(ISTRIP,33). %% Strip 8th bit off characters. 201-define(INLCR,34). %% Map NL into CR on input. 202-define(IGNCR,35). %% Ignore CR on input. 203-define(ICRNL,36). %% Map CR to NL on input. 204-define(IUCLC,37). %% Translate uppercase characters to lowercase. 205-define(IXON,38). %% Enable output flow control. 206-define(IXANY,39). %% Any char will restart after stop. 207-define(IXOFF,40). %% Enable input flow control. 208-define(IMAXBEL,41). %% Ring bell on input queue full. 209-define(IUTF8,42). %% Terminal input and output is assumed to be encoded in UTF-8. 210-define(ISIG,50). %% Enable signals INTR, QUIT, [D]SUSP. 211-define(ICANON,51). %% Canonicalize input lines. 212-define(XCASE,52). %% Enable input and output of uppercase characters by 213 %% preceding their lowercase equivalents with `\'. 214-define(ECHO,53). %% Enable echoing. 215-define(ECHOE,54). %% Visually erase chars. 216-define(ECHOK,55). %% Kill character discards current line. 217-define(ECHONL,56). %% Echo NL even if ECHO is off. 218-define(NOFLSH,57). %% Don't flush after interrupt. 219-define(TOSTOP,58). %% Stop background jobs from output. 220-define(IEXTEN,59). %% Enable extensions. 221-define(ECHOCTL,60). %% Echo control characters as ^(Char). 222-define(ECHOKE,61). %% Visual erase for line kill. 223-define(PENDIN,62). %% Retype pending input. 224-define(OPOST,70). %% Enable output processing. 225-define(OLCUC,71). %% Convert lowercase to uppercase. 226-define(ONLCR,72). %% Map NL to CR-NL. 227-define(OCRNL,73). %% Translate carriage return to newline (output). 228-define(ONOCR,74). %% Translate newline to carriage return-newline 229 %% (output). 230-define(ONLRET,75). %% Newline performs a carriage return (output). 231-define(CS7,90). %% 7 bit mode. 232-define(CS8,91). %% 8 bit mode. 233-define(PARENB,92). %% Parity enable. 234-define(PARODD,93). %% Odd parity, else even. 235 236%% Specifies the input baud rate in bits per second. 237-define(TTY_OP_ISPEED,128). 238%% Specifies the output baud rate in bits per second. 239-define(TTY_OP_OSPEED,129). 240 241-record(channel, 242 { 243 type, %% "session" 244 sys, %% "none", "shell", "exec" "subsystem" 245 user, %% "user" process id (default to cm user) 246 flow_control, 247 248 local_id, %% local channel id 249 250 recv_window_size, 251 recv_window_pending = 0, %% Sum of window size updates that has not 252 %% yet been sent. This limits the number 253 %% of sent update msgs. 254 recv_packet_size, 255 recv_close = false, 256 257 remote_id, %% remote channel id 258 send_window_size, 259 send_packet_size, 260 sent_close = false, 261 send_buf = [] 262 }). 263 264-record(connection, { 265 requests = [], %% [{ChannelId, Pid}...] awaiting reply on request, 266 channel_cache, 267 channel_id_seed, 268 cli_spec, 269 options, 270 exec, 271 system_supervisor, 272 sub_system_supervisor, 273 connection_supervisor 274 }). 275