ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
scp.h File Reference

SCP (RCP) protocol wire codec - the pure, host-testable half of the SCP-over-SSH server (PROTOCORE_ENABLE_SSH_SCP). More...

#include "protocore_config.h"

Go to the source code of this file.

Classes

struct  ScpNs
 Dispatch table. Addressed by offset, so the layout is asserted below. More...
 

Macros

#define PROTOCORE_SCP_ACK_OK   0
 proceed
 
#define PROTOCORE_SCP_ACK_WARN   1
 warning: followed by a message + '
'
 
#define PROTOCORE_SCP_ACK_ERROR   2
 fatal error: followed by a message + '
'
 

Typedefs

typedef enum PROTO_ENUM_PACKED ScpMode
 The role of an scp invocation, parsed from the exec command.
 

Enumerations

enum  PROTO_ENUM_PACKED { SCP_MODE_INVALID = 0 , SCP_MODE_SINK , SCP_MODE_SOURCE }
 The role of an scp invocation, parsed from the exec command. More...
 

Functions

 PROTOCORE_NS_LAYOUT (ScpNs, parse_cmd, parse_cline, build_cline)
 
ScpMode protocore_scp_parse_cmd (uint8_t *work, const char *cmd, size_t cmd_len, char *path_out, size_t path_cap)
 Parse an exec command scp [-v] [-r] [-p] [-d] -t|-f <path> into .
 
proto_bool protocore_scp_parse_cline (uint8_t *work, const char *line, size_t len, uint32_t *mode_out, uint64_t *size_out, char *name_out, size_t name_cap)
 Parse a control line C<mode> <size> <name> (a trailing '
' .
 
size_t protocore_scp_build_cline (uint8_t *work, uint32_t mode, uint64_t size, const char *name, char *out, size_t cap)
 Build a control line C<mode> <size> <name>\n for a source .
 

Variables

PROTOCORE_NS ScpNs Scp PROTOCORE_UNUSED
 Module namespace.
 

Detailed Description

SCP (RCP) protocol wire codec - the pure, host-testable half of the SCP-over-SSH server (PROTOCORE_ENABLE_SSH_SCP).

SCP transfers a file over an SSH exec "scp …" channel using the old rcp line protocol: the source side sends a control line C<mode> <size> <name>\n, the peer acks with a 0 byte, then the file bytes flow, ended by a 0 byte and another ack. This file parses/builds the command line and the control line and knows the ack bytes - no filesystem, no SSH, no Arduino, zero heap. The fs::FS sink/source state machine + the channel glue live in network_drivers/session/scp/ssh_scp.

work is bytes the CALLER holds. This module reads none of them: it carries nothing between calls, so there is no state to keep and nothing to wipe. The parameter is there so a caller drives every namespace the same way.

Author
Douglas Quigg (dstroy0)
Date
2026

Definition in file scp.h.

Macro Definition Documentation

◆ PROTOCORE_SCP_ACK_OK

#define PROTOCORE_SCP_ACK_OK   0

proceed

Definition at line 35 of file scp.h.

◆ PROTOCORE_SCP_ACK_WARN

#define PROTOCORE_SCP_ACK_WARN   1

warning: followed by a message + '
'

Definition at line 36 of file scp.h.

◆ PROTOCORE_SCP_ACK_ERROR

#define PROTOCORE_SCP_ACK_ERROR   2

fatal error: followed by a message + '
'

Definition at line 37 of file scp.h.

Typedef Documentation

◆ ScpMode

typedef enum PROTO_ENUM_PACKED ScpMode

The role of an scp invocation, parsed from the exec command.

Enumeration Type Documentation

◆ PROTO_ENUM_PACKED

The role of an scp invocation, parsed from the exec command.

Enumerator
SCP_MODE_INVALID 
SCP_MODE_SINK 

scp -t <path>: the client sends a file TO the device (device receives)

SCP_MODE_SOURCE 

scp -f <path>: the client fetches a file FROM the device (device sends)

Definition at line 40 of file scp.h.

Function Documentation

◆ PROTOCORE_NS_LAYOUT()

PROTOCORE_NS_LAYOUT ( ScpNs  ,
parse_cmd  ,
parse_cline  ,
build_cline   
)

◆ protocore_scp_parse_cmd()

ScpMode protocore_scp_parse_cmd ( uint8_t *  work,
const char *  cmd,
size_t  cmd_len,
char *  path_out,
size_t  path_cap 
)

Parse an exec command scp [-v] [-r] [-p] [-d] -t|-f <path> into .

Parameters
workPROTOCORE_SCP_BORROW bytes the caller took. Not held past the call.
cmdnot NUL-terminated (cmd_len bytes). the mode; path_out gets the (NUL-terminated) target,
cmd_lenCmd len
path_outPath out
path_capPath cap
Returns
The ScpMode.

◆ protocore_scp_parse_cline()

proto_bool protocore_scp_parse_cline ( uint8_t *  work,
const char *  line,
size_t  len,
uint32_t *  mode_out,
uint64_t *  size_out,
char *  name_out,
size_t  name_cap 
)

Parse a control line C<mode> <size> <name> (a trailing '
' .

Parameters
workPROTOCORE_SCP_BORROW bytes the caller took. Not held past the call.
lineLine
lenLen
mode_outMode out
size_outSize out
name_outName out
name_capName cap
Returns
PROTO_TRUE on success.

◆ protocore_scp_build_cline()

size_t protocore_scp_build_cline ( uint8_t *  work,
uint32_t  mode,
uint64_t  size,
const char *  name,
char *  out,
size_t  cap 
)

Build a control line C<mode> <size> <name>\n for a source .

Parameters
workPROTOCORE_SCP_BORROW bytes the caller took. Not held past the call.
modeMode
sizeSize
nameName
outOut
capCap
Returns
The size_t.

Variable Documentation

◆ PROTOCORE_UNUSED

PROTOCORE_NS ScpNs Scp PROTOCORE_UNUSED
Initial value:
= {.parse_cmd = protocore_scp_parse_cmd,
.parse_cline = protocore_scp_parse_cline,
.build_cline = protocore_scp_build_cline}
proto_bool protocore_scp_parse_cline(uint8_t *work, const char *line, size_t len, uint32_t *mode_out, uint64_t *size_out, char *name_out, size_t name_cap)
Parse a control line C<mode> <size> <name> (a trailing ' ' .
size_t protocore_scp_build_cline(uint8_t *work, uint32_t mode, uint64_t size, const char *name, char *out, size_t cap)
Build a control line C<mode> <size> <name>\n for a source .
ScpMode protocore_scp_parse_cmd(uint8_t *work, const char *cmd, size_t cmd_len, char *path_out, size_t path_cap)
Parse an exec command scp [-v] [-r] [-p] [-d] -t|-f <path> into .

Module namespace.

Definition at line 92 of file scp.h.