htc: implement htcfs protocol bringup

This commit is contained in:
Michael Scire
2021-02-12 22:07:34 -08:00
committed by SciresM
parent 99a38dce32
commit 5c97469348
10 changed files with 316 additions and 7 deletions

View File

@@ -18,6 +18,63 @@
namespace ams::htcfs {
constexpr inline s16 HtcfsProtocol = 1;
constexpr inline s16 MaxProtocolVersion = 1;
enum class PacketCategory : u16 {
Request = 0,
Response = 1,
};
enum class PacketType : u16 {
GetMaxProtocolVersion = 0,
SetProtocolVersion = 1,
GetEntryType = 16,
OpenFile = 32,
CloseFile = 33,
GetPriorityForFile = 34,
SetPriorityForFile = 35,
CreateFile = 36,
DeleteFile = 37,
RenameFile = 38,
FileExists = 39,
ReadFile = 40,
WriteFile = 41,
FlushFile = 42,
GetFileTimeStamp = 43,
GetFileSize = 44,
SetFileSize = 45,
ReadFileLarge = 46,
WriteFileLarge = 47,
OpenDirectory = 48,
CloseDirectory = 49,
GetPriorityForDirectory = 50,
SetPriorityForDirectory = 51,
CreateDirectory = 52,
DeleteDirectory = 53,
RenameDirectory = 54,
DirectoryExists = 55,
ReadDirectory = 56,
GetEntryCount = 57,
GetWorkingDirectory = 58,
GetWorkingDirectorySize = 59,
GetCaseSensitivePath = 60,
GetDiskFreeSpace = 61,
ReadDirectoryLarge = 62,
};
struct Header {
s16 protocol;
s16 version;
PacketCategory packet_category;
PacketType packet_type;
s64 body_size;
s64 params[5];
s64 reserved;
};
static_assert(util::is_pod<Header>::value);
static_assert(sizeof(Header) == 0x40);
class HeaderFactory {
private:
s16 m_version;
@@ -26,6 +83,34 @@ namespace ams::htcfs {
public:
s16 GetVersion() const { return m_version; }
void SetVersion(s16 version) { m_version = version; }
public:
ALWAYS_INLINE void MakeRequestHeader(Header *out, PacketType packet_type, s64 body_size = 0, s64 param0 = 0, s64 param1 = 0, s64 param2 = 0, s64 param3 = 0, s64 param4 = 0) {
/* Set protocol and version. */
out->protocol = HtcfsProtocol;
out->version = m_version;
/* Set type and category. */
out->packet_category = PacketCategory::Request;
out->packet_type = packet_type;
/* Set body size. */
out->body_size = body_size;
/* Set params. */
out->params[0] = param0;
out->params[1] = param1;
out->params[2] = param2;
out->params[3] = param3;
out->params[4] = param4;
}
void MakeGetMaxProtocolVersionHeader(Header *out) {
return this->MakeRequestHeader(out, PacketType::GetMaxProtocolVersion, 0);
}
void MakeSetProtocolVersionHeader(Header *out, s16 version) {
return this->MakeRequestHeader(out, PacketType::SetProtocolVersion, 0, version);
}
};
}