Skip to content

Commit d7ca1b3

Browse files
committed
WIP: Host commands
Signed-off-by: Daniel Schaefer <dhs@frame.work>
1 parent 2449342 commit d7ca1b3

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

FrameworkSensors/EcCommunication.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,48 @@ int CrosEcReadMemU8(HANDLE Handle, unsigned int offset, UINT8* dest)
5151

5252
return rm.bytes;
5353
}
54+
55+
int CrosEcHostCommand(HANDLE Handle, UINT8 cmd_ver, UINT8 cmd, UINT8 *req, UINT8 req_len)
56+
{
57+
NTSTATUS Status = STATUS_SUCCESS;
58+
DWORD retb{};
59+
CROSEC_COMMAND cmd{};
60+
61+
if (req_len > CROSEC_CMD_MAX_REQUEST) {
62+
Status = STATUS_INVALID_PARAMETER;
63+
TraceError("COMBO %!FUNC! Request size too long");
64+
}
65+
66+
if (Handle == INVALID_HANDLE_VALUE) {
67+
Status = STATUS_INVALID_HANDLE;
68+
TraceError("COMBO %!FUNC! Invalid Handle");
69+
return 0;
70+
}
71+
72+
cmd.version = cmd_ver;
73+
cmd.command = cmd;
74+
cmd.outsize = req_len;
75+
cmd.insize = CROSEC_CMD_MAX_REQUEST - CROSEC_CMD_HEADER_LEN;
76+
cmd.result = 0xFF;
77+
for (UINT8 i = 0; i < req_len; i++) {
78+
cmd.buffer[i] = req[i];
79+
}
80+
81+
Status = DeviceIoControl(Handle,
82+
(DWORD) IOCTL_CROSEC_XCMD,
83+
&cmd,
84+
sizeof(cmd),
85+
&cmd,
86+
sizeof(cmd),
87+
&retb,
88+
nullptr);
89+
if (!NT_SUCCESS(Status)) {
90+
TraceError("COMBO %!FUNC! ConnectToEc failed %!STATUS!", Status);
91+
return 0;
92+
}
93+
94+
TraceInformation("COMBO %!FUNC! Successfully read %d bytes from EC memory at %02x. First one %02x. retb=%d", rm.bytes, rm.offset, rm.buffer[0], retb);
95+
*dest = rm.buffer[0];
96+
97+
return rm.bytes;
98+
}

FrameworkSensors/EcCommunication.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ extern "C" {
4040

4141
#define CROSEC_CMD_MAX_REQUEST 0x100
4242
#define CROSEC_CMD_MAX_RESPONSE 0x100
43+
#define CROSEC_CMD_HEADER_LEN 0x10
4344
#define CROSEC_MEMMAP_SIZE 0xFF
4445

4546
typedef struct _CROSEC_READMEM {
@@ -50,6 +51,15 @@ typedef struct _CROSEC_READMEM {
5051

5152
int CrosEcReadMemU8(HANDLE Handle, unsigned int offset, UINT8* dest);
5253

54+
typedef struct _CROSEC_COMMAND {
55+
ULONG version;
56+
ULONG command;
57+
ULONG outsize;
58+
ULONG insize;
59+
ULONG result;
60+
UCHAR buffer[CROSEC_CMD_MAX_REQUEST];
61+
} * PCROSEC_COMMAND, CROSEC_COMMAND;
62+
5363
#ifdef __cplusplus
5464
}
5565
#endif

0 commit comments

Comments
 (0)