24#ifndef PROTOCORE_SSH_CHANNEL_H
25#define PROTOCORE_SSH_CHANNEL_H
61using SshChannelDataCb = void (*)(uint8_t slot, uint32_t channel,
const uint8_t *data,
size_t len);
77using SshForwardOpenCb = int (*)(uint8_t slot, uint32_t channel,
const char *host,
size_t host_len, uint16_t port);
81using SshForwardDataCb = void (*)(uint8_t slot, uint32_t channel,
const uint8_t *data,
size_t len);
122#if PC_ENABLE_SSH_SFTP
124using SshSftpOpenCb = void (*)(uint8_t slot, uint32_t channel);
126using SshSftpDataCb = void (*)(uint8_t slot, uint32_t channel,
const uint8_t *data,
size_t len);
127void pc_ssh_channel_set_sftp_open_cb(SshSftpOpenCb cb);
128void pc_ssh_channel_set_sftp_data_cb(SshSftpDataCb cb);
133using SshScpOpenCb = void (*)(uint8_t slot, uint32_t channel,
const char *cmd,
size_t cmd_len);
135using SshScpDataCb = void (*)(uint8_t slot, uint32_t channel,
const uint8_t *data,
size_t len);
136void pc_ssh_channel_set_scp_open_cb(SshScpOpenCb cb);
137void pc_ssh_channel_set_scp_data_cb(SshScpDataCb cb);
153 uint16_t orig_port, uint8_t *out,
size_t *out_len,
size_t cap);
229 size_t *out_len,
size_t cap);
#define PC_SSH_MAX_CHANNELS
User-facing configuration for ProtoCore.
int pc_ssh_channel_build_close(uint8_t i, uint32_t channel, uint8_t *out, size_t *out_len, size_t cap)
Build SSH_MSG_CHANNEL_EOF + SSH_MSG_CHANNEL_CLOSE for channel channel and mark it closed.
int pc_ssh_channel_handle_window_adjust(uint8_t i, const uint8_t *payload, size_t len)
Handle SSH_MSG_CHANNEL_WINDOW_ADJUST (grows the peer window).
int(*)(uint8_t slot, uint32_t channel, const char *host, size_t host_len, uint16_t port) SshForwardOpenCb
"direct-tcpip" forward request: a client asked the server to open a TCP connection to host : port (ss...
int pc_ssh_channel_open_forwarded(uint8_t i, const char *conn_addr, uint16_t conn_port, const char *orig_addr, uint16_t orig_port, uint8_t *out, size_t *out_len, size_t cap)
Open a server-initiated "forwarded-tcpip" channel (RFC 4254 §7.2, ssh -R).
int pc_ssh_channel_handle_close(uint8_t i, const uint8_t *payload, size_t len, uint8_t *out, size_t *out_len, size_t cap)
Handle an inbound SSH_MSG_CHANNEL_CLOSE: route to the recipient channel, reply with EOF + CLOSE,...
int pc_ssh_channel_handle_open(uint8_t i, const uint8_t *payload, size_t len, uint8_t *out, size_t *out_len, size_t cap)
Handle SSH_MSG_CHANNEL_OPEN and emit CHANNEL_OPEN_CONFIRMATION.
int pc_ssh_channel_handle_data(uint8_t i, const uint8_t *payload, size_t len, uint8_t *out, size_t *out_len, size_t cap)
Handle SSH_MSG_CHANNEL_DATA: bounds-check, update the window, and invoke the data callback....
void pc_ssh_channel_set_forward_data_cb(SshForwardDataCb cb)
Install the direct-tcpip forward inbound-data callback.
int ssh_global_request_handle(uint8_t i, const uint8_t *payload, size_t len, uint8_t *out, size_t *out_len, size_t cap)
Handle SSH_MSG_GLOBAL_REQUEST (RFC 4254 §4).
void pc_ssh_channel_init(uint8_t i)
Reset channel state for slot i.
void pc_ssh_channel_set_data_cb(SshChannelDataCb cb)
Install the inbound-data callback (session channels).
void pc_ssh_channel_set_forward_confirm_cb(SshForwardConfirmCb cb)
Install the forwarded-tcpip open-confirmation callback (opt-in, ssh -R).
void pc_ssh_channel_set_rforward_open_cb(SshRemoteForwardOpenCb cb)
Install the remote-forward (ssh -R) open-policy callback (opt-in).
int pc_ssh_channel_build_data(uint8_t i, uint32_t channel, const uint8_t *data, size_t len, uint8_t *out, size_t *out_len, size_t cap)
Build an SSH_MSG_CHANNEL_DATA message carrying data to the client on channel channel (a local channel...
int(*)(uint8_t slot, const char *bind_addr, size_t addr_len, uint16_t bind_port) SshRemoteForwardOpenCb
"tcpip-forward" remote-forward request (ssh -R): the client asks the server to listen on bind_addr : ...
void pc_ssh_channel_set_rforward_cancel_cb(SshRemoteForwardCancelCb cb)
Install the remote-forward (ssh -R) cancel callback (opt-in).
SshChanType
Channel type (RFC 4254).
@ SSH_CHAN_DIRECT_TCPIP
"direct-tcpip" - client-initiated TCP forward (ssh -L)
@ SSH_CHAN_SESSION
"session" - shell / exec / data
@ SSH_CHAN_FORWARDED_TCPIP
"forwarded-tcpip" - server-initiated TCP forward (ssh -R)
@ SSH_CHAN_SCP
a "session" running an exec "scp …" (PC_ENABLE_SSH_SCP)
@ SSH_CHAN_SFTP
a "session" running the "sftp" subsystem (PC_ENABLE_SSH_SFTP)
int(*)(uint8_t slot, const char *bind_addr, size_t addr_len, uint16_t bind_port) SshRemoteForwardCancelCb
"cancel-tcpip-forward" request (RFC 4254 §7.1): drop a remote forward.
int pc_ssh_channel_handle_open_confirm(uint8_t i, const uint8_t *payload, size_t len)
Handle SSH_MSG_CHANNEL_OPEN_CONFIRMATION for a channel we opened (ssh -R).
SshChannel ssh_chan[MAX_SSH_CONNS][PC_SSH_MAX_CHANNELS]
Channel pool: PC_SSH_MAX_CHANNELS channels per SSH connection (BSS). Owned by this layer; src/ code r...
void(*)(uint8_t slot, uint32_t channel, const uint8_t *data, size_t len) SshForwardDataCb
Inbound data on a direct-tcpip channel (the owner writes it to the forwarded TCP socket)....
int pc_ssh_channel_handle_open_failure(uint8_t i, const uint8_t *payload, size_t len)
Handle SSH_MSG_CHANNEL_OPEN_FAILURE for a channel we opened (ssh -R).
int pc_ssh_channel_handle_request(uint8_t i, const uint8_t *payload, size_t len, uint8_t *out, size_t *out_len, size_t cap)
Handle SSH_MSG_CHANNEL_REQUEST.
void pc_ssh_channel_set_forward_open_cb(SshForwardOpenCb cb)
Install the direct-tcpip forward open-policy callback (opt-in).
void(*)(uint8_t slot, uint32_t channel, bool ok) SshForwardConfirmCb
Result of the client's reply to a server-initiated forwarded-tcpip channel: ok = true on CHANNEL_OPEN...
void(*)(uint8_t slot, uint32_t channel, const uint8_t *data, size_t len) SshChannelDataCb
Application callback for inbound channel data (raw bytes), tagged with the channel id it arrived on.
Per-connection channel state.
bool open
True once the channel is confirmed open both ways.
uint32_t peer_max_pkt
Client's maximum packet size.
uint32_t peer_window
Bytes we may still send to the client.
SshChanType type
session, direct-tcpip, or forwarded-tcpip.
bool pending
True for a server-initiated channel we opened, awaiting the client's confirmation.
uint32_t local_id
Our channel id (== slot index).
uint32_t local_window
Bytes we may still receive before WINDOW_ADJUST.
uint32_t peer_id
Client's channel id.