Skip to content

Commit 9755477

Browse files
committed
Add support for Mocha_StartTCPSyslogLogging and friends
1 parent 89438aa commit 9755477

3 files changed

Lines changed: 85 additions & 12 deletions

File tree

include/mocha/commands.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ extern "C" {
1212
#define IPC_CUSTOM_START_USB_LOGGING 0xFA
1313
#define IPC_CUSTOM_COPY_ENVIRONMENT_PATH 0xF9
1414
#define IPC_CUSTOM_GET_MOCHA_API_VERSION 0xF8
15+
#define IPC_CUSTOM_START_TCP_LOGGING 0xF7
16+
#define IPC_CUSTOM_STOP_TCP_LOGGING 0xF6
17+
#define IPC_CUSTOM_START_IOPSHELL_SERVER 0xF5
1518

1619
typedef enum LoadRPXTargetEnum {
1720
LOAD_RPX_TARGET_SD_CARD = 0,

include/mocha/mocha.h

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,39 @@ MochaUtilsStatus Mocha_GetEnvironmentPath(char *environmentPathBuffer, uint32_t
153153
* @return MOCHA_RESULT_SUCCESS: Logging via USB starts or has already been started<br>
154154
* MOCHA_RESULT_LIB_UNINITIALIZED: Library was not initialized. Call Mocha_InitLibrary() before using this function.<br>
155155
* MOCHA_RESULT_UNSUPPORTED_COMMAND: Command not supported by the currently loaded mocha version.<br>
156-
* MOCHA_RESULT_UNKNOWN_ERROR: Failed to retrieve the environment path.
156+
* MOCHA_RESULT_UNKNOWN_ERROR: Failed to start the usb logging.
157157
*/
158158
MochaUtilsStatus Mocha_StartUSBLogging(bool notSkipExistingLogs);
159159

160+
/**
161+
* Enables logging via TCP via OSReport and friends. See the tcp script for receiving logs<br>
162+
* @param limitToIp If set to true, only connection to the ip specified in "ipFilter" will be accepted
163+
* @param ipFilter Defined the ip address the console will connect for usb logs
164+
* @return MOCHA_RESULT_SUCCESS: Logging via TCP starts or has already been started<br>
165+
* MOCHA_RESULT_LIB_UNINITIALIZED: Library was not initialized. Call Mocha_InitLibrary() before using this function.<br>
166+
* MOCHA_RESULT_UNSUPPORTED_COMMAND: Command not supported by the currently loaded mocha version.<br>
167+
* MOCHA_RESULT_UNKNOWN_ERROR: Failed to start
168+
*/
169+
MochaUtilsStatus Mocha_StartTCPSyslogLogging(bool limitToIp, uint32_t ipFilter);
170+
171+
/**
172+
* Disabled logging via TCP. <br>
173+
* @return MOCHA_RESULT_SUCCESS: Logging via stops<br>
174+
* MOCHA_RESULT_LIB_UNINITIALIZED: Library was not initialized. Call Mocha_InitLibrary() before using this function.<br>
175+
* MOCHA_RESULT_UNSUPPORTED_COMMAND: Command not supported by the currently loaded mocha version.<br>
176+
* MOCHA_RESULT_UNKNOWN_ERROR: Failed to stop
177+
*/
178+
MochaUtilsStatus Mocha_StopTCPSyslogLogging();
179+
180+
/**
181+
* Starts the iopshell server. <br>
182+
* @return MOCHA_RESULT_SUCCESS: IOPShell server starts or has already been started<br>
183+
* MOCHA_RESULT_LIB_UNINITIALIZED: Library was not initialized. Call Mocha_InitLibrary() before using this function.<br>
184+
* MOCHA_RESULT_UNSUPPORTED_COMMAND: Command not supported by the currently loaded mocha version.<br>
185+
* MOCHA_RESULT_UNKNOWN_ERROR: Failed to start
186+
*/
187+
MochaUtilsStatus Mocha_StartIOPShellServer();
188+
160189
/**
161190
* Gives a FSClient full permissions. <br>
162191
* Requires Mocha API Version: 1

source/utils.cpp

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,27 @@ uint32_t mochaApiVersion = 0;
2323
#define IOCTL_KERN_WRITE32 0x07
2424
#define IOCTL_READ_OTP 0x08
2525

26+
namespace {
27+
MochaUtilsStatus doSimpleCustomIPCCommand(const uint32_t cmd, const uint32_t arg1 = 0, const uint32_t arg2 = 0) {
28+
MochaUtilsStatus res = MOCHA_RESULT_UNKNOWN_ERROR;
29+
int mcpFd = IOS_Open("/dev/mcp", static_cast<IOSOpenMode>(0));
30+
if (mcpFd >= 0) {
31+
ALIGN_0x40 uint32_t io_buffer[0x40 / 4];
32+
io_buffer[0] = cmd;
33+
io_buffer[1] = arg1;
34+
io_buffer[2] = arg2;
35+
36+
if (IOS_Ioctl(mcpFd, 100, io_buffer, 0xC, io_buffer, 0x4) == IOS_ERROR_OK) {
37+
res = MOCHA_RESULT_SUCCESS;
38+
}
39+
40+
IOS_Close(mcpFd);
41+
}
42+
return res;
43+
}
44+
} // namespace
45+
46+
2647
const char *Mocha_GetStatusStr(MochaUtilsStatus status) {
2748
switch (status) {
2849
case MOCHA_RESULT_SUCCESS:
@@ -337,21 +358,41 @@ MochaUtilsStatus Mocha_StartUSBLogging(bool notSkipExistingLogs) {
337358
if (mochaApiVersion < 1) {
338359
return MOCHA_RESULT_UNSUPPORTED_COMMAND;
339360
}
340-
MochaUtilsStatus res = MOCHA_RESULT_UNKNOWN_ERROR;
341-
int mcpFd = IOS_Open("/dev/mcp", (IOSOpenMode) 0);
342-
if (mcpFd >= 0) {
343-
ALIGN_0x40 uint32_t io_buffer[0x40 / 4];
344-
io_buffer[0] = IPC_CUSTOM_START_USB_LOGGING;
345-
io_buffer[1] = notSkipExistingLogs;
346361

347-
if (IOS_Ioctl(mcpFd, 100, io_buffer, 8, io_buffer, 0x4) == IOS_ERROR_OK) {
348-
res = MOCHA_RESULT_SUCCESS;
349-
}
362+
return doSimpleCustomIPCCommand(IPC_CUSTOM_START_USB_LOGGING, notSkipExistingLogs);
363+
}
350364

351-
IOS_Close(mcpFd);
365+
MochaUtilsStatus Mocha_StartTCPSyslogLogging(bool limitToIp, uint32_t ipFilter) {
366+
if (!mochaInitDone) {
367+
return MOCHA_RESULT_LIB_UNINITIALIZED;
368+
}
369+
if (mochaApiVersion < 2) {
370+
return MOCHA_RESULT_UNSUPPORTED_COMMAND;
352371
}
353372

354-
return res;
373+
return doSimpleCustomIPCCommand(IPC_CUSTOM_START_TCP_LOGGING, limitToIp, ipFilter);
374+
}
375+
376+
MochaUtilsStatus Mocha_StopTCPSyslogLogging() {
377+
if (!mochaInitDone) {
378+
return MOCHA_RESULT_LIB_UNINITIALIZED;
379+
}
380+
if (mochaApiVersion < 2) {
381+
return MOCHA_RESULT_UNSUPPORTED_COMMAND;
382+
}
383+
384+
return doSimpleCustomIPCCommand(IPC_CUSTOM_STOP_TCP_LOGGING);
385+
}
386+
387+
MochaUtilsStatus Mocha_StartIOPShellServer() {
388+
if (!mochaInitDone) {
389+
return MOCHA_RESULT_LIB_UNINITIALIZED;
390+
}
391+
if (mochaApiVersion < 2) {
392+
return MOCHA_RESULT_UNSUPPORTED_COMMAND;
393+
}
394+
395+
return doSimpleCustomIPCCommand(IPC_CUSTOM_START_IOPSHELL_SERVER);
355396
}
356397

357398
MochaUtilsStatus Mocha_UnlockFSClient(FSClient *client) {

0 commit comments

Comments
 (0)