20#ifndef PROTOCORE_SFTP_H
21#define PROTOCORE_SFTP_H
30#define PC_SFTP_VERSION 3
33#define PC_SSH_FXP_INIT 1
34#define PC_SSH_FXP_OPEN 3
35#define PC_SSH_FXP_CLOSE 4
36#define PC_SSH_FXP_READ 5
37#define PC_SSH_FXP_WRITE 6
38#define PC_SSH_FXP_LSTAT 7
39#define PC_SSH_FXP_FSTAT 8
40#define PC_SSH_FXP_SETSTAT 9
41#define PC_SSH_FXP_FSETSTAT 10
42#define PC_SSH_FXP_OPENDIR 11
43#define PC_SSH_FXP_READDIR 12
44#define PC_SSH_FXP_REMOVE 13
45#define PC_SSH_FXP_MKDIR 14
46#define PC_SSH_FXP_RMDIR 15
47#define PC_SSH_FXP_REALPATH 16
48#define PC_SSH_FXP_STAT 17
49#define PC_SSH_FXP_RENAME 18
52#define PC_SSH_FXP_VERSION 2
53#define PC_SSH_FXP_STATUS 101
54#define PC_SSH_FXP_HANDLE 102
55#define PC_SSH_FXP_DATA 103
56#define PC_SSH_FXP_NAME 104
57#define PC_SSH_FXP_ATTRS 105
61#define PC_SSH_FX_EOF 1
62#define PC_SSH_FX_NO_SUCH_FILE 2
63#define PC_SSH_FX_PERMISSION_DENIED 3
64#define PC_SSH_FX_FAILURE 4
65#define PC_SSH_FX_BAD_MESSAGE 5
66#define PC_SSH_FX_OP_UNSUPPORTED 8
69#define PC_SSH_FXF_READ 0x00000001
70#define PC_SSH_FXF_WRITE 0x00000002
71#define PC_SSH_FXF_APPEND 0x00000004
72#define PC_SSH_FXF_CREAT 0x00000008
73#define PC_SSH_FXF_TRUNC 0x00000010
74#define PC_SSH_FXF_EXCL 0x00000020
77#define PC_SSH_FILEXFER_ATTR_SIZE 0x00000001
78#define PC_SSH_FILEXFER_ATTR_UIDGID 0x00000002
79#define PC_SSH_FILEXFER_ATTR_PERMS 0x00000004
80#define PC_SSH_FILEXFER_ATTR_ACMODTIME 0x00000008
81#define PC_SSH_FILEXFER_ATTR_EXTENDED 0x80000000
84#define PC_SFTP_S_IFDIR 0040000
85#define PC_SFTP_S_IFREG 0100000
106void pc_sftp_rd_init(SftpReader *r,
const uint8_t *payload,
size_t len);
107uint8_t pc_sftp_rd_u8(SftpReader *r);
108uint32_t pc_sftp_rd_u32(SftpReader *r);
109uint64_t pc_sftp_rd_u64(SftpReader *r);
111bool pc_sftp_rd_string(SftpReader *r,
const uint8_t **out, uint32_t *out_len);
113bool pc_sftp_rd_attrs(SftpReader *r, SftpAttrs *a);
124void pc_sftp_wr_init(SftpWriter *w, uint8_t *out,
size_t cap);
125void pc_sftp_wr_u8(SftpWriter *w, uint8_t v);
126void pc_sftp_wr_u32(SftpWriter *w, uint32_t v);
127void pc_sftp_wr_u64(SftpWriter *w, uint64_t v);
128void pc_sftp_wr_bytes(SftpWriter *w,
const void *b,
size_t n);
129void pc_sftp_wr_string(SftpWriter *w,
const void *s, uint32_t n);
130void pc_sftp_wr_attrs(SftpWriter *w,
const SftpAttrs *a);
132size_t pc_sftp_wr_finish(SftpWriter *w);
134size_t pc_sftp_wr_pos(
const SftpWriter *w);
136void pc_sftp_wr_patch_u32(SftpWriter *w,
size_t at, uint32_t v);
143size_t pc_sftp_frame_len(
const uint8_t *buf,
size_t have,
size_t max);
146size_t pc_sftp_build_version(uint8_t *out,
size_t cap);
147size_t pc_sftp_build_status(uint32_t
id, uint32_t code,
const char *msg, uint8_t *out,
size_t cap);
148size_t pc_sftp_build_handle(uint32_t
id,
const void *handle, uint32_t hlen, uint8_t *out,
size_t cap);
149size_t pc_sftp_build_attrs(uint32_t
id,
const SftpAttrs *a, uint8_t *out,
size_t cap);
151size_t pc_sftp_build_data(uint32_t
id,
const void *data, uint32_t dlen, uint8_t *out,
size_t cap);
153size_t pc_sftp_build_name1(uint32_t
id,
const char *name,
const char *longname,
const SftpAttrs *a, uint8_t *out,
160size_t pc_sftp_format_longname(
bool is_dir, uint32_t perms, uint64_t size, uint32_t mtime,
const char *name,
char *out,
User-facing configuration for ProtoCore.