@@ -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+
2647const 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
357398MochaUtilsStatus Mocha_UnlockFSClient (FSClient *client) {
0 commit comments