Skip to content

Commit 13c4be0

Browse files
committed
Add wifi-always-on patch
1 parent 1db5069 commit 13c4be0

5 files changed

Lines changed: 75 additions & 10 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ PlayStation® Vita™ network logging plugin
2020
## Credits
2121
* [Princess-of-Sleeping](https://github.com/Princess-of-Sleeping), [cuevavirus](https://git.shotatoshounenwachigau.moe/) - PrincessLog
2222
* [SKGleba](https://github.com/SKGleba) - settings menu idea and injection code
23+
* [Electry](https://github.com/Electry) - wifi patch
2324
* CBPS

include/catlog.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ typedef struct {
77
uint32_t host;
88
uint16_t port;
99
uint16_t loglevel;
10+
uint8_t net;
1011
} CatLogConfig_t;
1112

12-
int CatLogReadConfig(uint32_t* host, uint16_t* port, uint16_t* level);
13-
int CatLogUpdateConfig(uint32_t host, uint16_t port, uint16_t level);
13+
int CatLogReadConfig(uint32_t* host, uint16_t* port, uint16_t* level, uint8_t* net);
14+
int CatLogUpdateConfig(uint32_t host, uint16_t port, uint16_t level, uint8_t net);
1415

1516
#endif // CATLOG_H

kernel_module/src/main.c

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,16 @@ int module_get_export_func(SceUID pid, const char *modname, uint32_t libnid, uin
4949
name##HookUid = taiHookFunctionExportForKernel(KERNEL_PID, &name##HookRef, (module), (lib_nid), (func_nid), \
5050
(const void *)name##HookFunc)
5151

52+
#define BIND_FUNC_OFFSET_HOOK(name, modid, segidx, offset, thumb) \
53+
name##HookUid = taiHookFunctionOffsetForKernel(KERNEL_PID, &name##HookRef, \
54+
(modid), (segidx), (offset), thumb, (const void*)name##HookFunc)
5255

5356
#define GetExport(modname, lib_nid, func_nid, func) \
5457
module_get_export_func(KERNEL_PID, modname, lib_nid, func_nid, (uintptr_t *)func)
5558

5659

60+
CatLogConfig_t Config;
61+
5762
static int net_thread_run = 0;
5863
static SceUID net_thread_uid = 0;
5964

@@ -95,6 +100,13 @@ DECL_FUNC_HOOK(sceSblQafMgrIsAllowSystemAppDebugForDriver_patched)
95100
return 1;
96101
}
97102

103+
DECL_FUNC_HOOK(ScePower_3e10_patched, int pid, int flags, unsigned int set)
104+
{
105+
if (flags == 3 && Config.net) // WLAN/COM
106+
set = 1;
107+
return TAI_CONTINUE(int, ScePower_3e10_patchedHookRef, pid, flags, set);
108+
}
109+
98110
/* flags for sceNetShutdown */
99111
#define SCE_NET_SHUT_RD 0
100112
#define SCE_NET_SHUT_WR 1
@@ -180,7 +192,6 @@ static int net_thread(SceSize args, void *argp)
180192
return 0;
181193
}
182194

183-
CatLogConfig_t Config;
184195

185196
int SaveConfig(void)
186197
{
@@ -198,6 +209,7 @@ int CreateConfig(void)
198209
Config.host = 0x0100007f; // 127.0.0.1
199210
Config.port = DEFAULT_PORT;
200211
Config.loglevel = 2;
212+
Config.net = 0;
201213

202214
SceUID fd = ksceIoOpen(CFG_PATH, SCE_O_WRONLY | SCE_O_CREAT | SCE_O_TRUNC, 0666);
203215
if (fd < 0) return fd;
@@ -210,8 +222,25 @@ int CreateConfig(void)
210222

211223
int CheckConfig(void)
212224
{
213-
SceIoStat buf;
214-
return ksceIoGetstat(CFG_PATH, &buf);
225+
SceUID fd = ksceIoOpen(CFG_PATH, SCE_O_RDONLY, 0);
226+
if (fd < 0)
227+
{
228+
return fd;
229+
}
230+
231+
CatLogConfig_t tmp;
232+
233+
int res = ksceIoRead(fd, &tmp, sizeof(CatLogConfig_t));
234+
235+
if (res != sizeof(CatLogConfig_t))
236+
{
237+
ksceIoClose(fd);
238+
return -1;
239+
}
240+
241+
ksceIoClose(fd);
242+
243+
return 0;
215244
}
216245

217246
int LoadConfig(void)
@@ -252,7 +281,7 @@ int LoadConfig(void)
252281
}
253282

254283

255-
int CatLogUpdateConfig(uint32_t host, uint16_t port, uint16_t level)
284+
int CatLogUpdateConfig(uint32_t host, uint16_t port, uint16_t level, uint8_t net)
256285
{
257286
uint32_t state;
258287

@@ -261,6 +290,7 @@ int CatLogUpdateConfig(uint32_t host, uint16_t port, uint16_t level)
261290
Config.host = host;
262291
Config.port = port;
263292
Config.loglevel = level;
293+
Config.net = net;
264294
sceKernelSetAssertLevelForKernel(Config.loglevel);
265295

266296
server.sin_addr.s_addr = host;
@@ -273,7 +303,7 @@ int CatLogUpdateConfig(uint32_t host, uint16_t port, uint16_t level)
273303
return 0;
274304
}
275305

276-
int CatLogReadConfig(uint32_t* host, uint16_t* port, uint16_t* level)
306+
int CatLogReadConfig(uint32_t* host, uint16_t* port, uint16_t* level, uint8_t* net)
277307
{
278308
int res;
279309
uint32_t state;
@@ -298,6 +328,12 @@ int CatLogReadConfig(uint32_t* host, uint16_t* port, uint16_t* level)
298328
goto end;
299329
}
300330

331+
res = ksceKernelMemcpyKernelToUser((void *)net, &Config.net, 1);
332+
if (res < 0)
333+
{
334+
goto end;
335+
}
336+
301337
end:
302338
EXIT_SYSCALL(state);
303339

@@ -328,6 +364,15 @@ int CatLogInit(void)
328364
goto end;
329365
}
330366

367+
tai_module_info_t modInfo;
368+
modInfo.size = sizeof(tai_module_info_t);
369+
370+
if (taiGetModuleInfoForKernel(KERNEL_PID, "ScePower", &modInfo) < 0)
371+
{
372+
ret = -1;
373+
goto end;
374+
}
375+
331376
if (GetExport("SceSysmem", 0x88C17370, 0xCE9060F1, &sceKernelSetAssertLevelForKernel) < 0)
332377
if (GetExport("SceSysmem", 0x13D793B7, 0xC5889385, &sceKernelSetAssertLevelForKernel) < 0)
333378
{
@@ -359,6 +404,8 @@ int CatLogInit(void)
359404
BIND_FUNC_EXPORT_HOOK(sceSblQafMgrIsAllowKernelDebugForDriver_patched, "SceSysmem", 0xFFFFFFFF, 0x382C71E8);
360405
BIND_FUNC_EXPORT_HOOK(sceSblQafMgrIsAllowSystemAppDebugForDriver_patched, "SceSysmem", 0xFFFFFFFF, 0xCAD47130);
361406

407+
BIND_FUNC_OFFSET_HOOK(ScePower_3e10_patched, modInfo.modid, 0, 0x3E10, 1);
408+
362409
ret = sceDebugDisableInfoDumpForKernel(0);
363410
if (ret < 0)
364411
{

user_module/network_settings.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@
6868
<list_item id="id_catlog_level_debug" title="Debug" value="1"/>
6969
<list_item id="id_catlog_level_trace" title="Trace" value="2"/>
7070
</list>
71+
72+
<toggle_switch id="enable_net"
73+
key="/CONFIG/CATLOG/net"
74+
title="Keep Wi-Fi ON"
75+
description="Always keep wifi on" />
76+
7177
</setting_list>
7278

7379
</setting_list>

user_module/user.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ DECL_FUNC_HOOK(sceRegMgrGetKeyInt, const char *category, const char *name, int *
6363
{
6464
*value = cfg.port;
6565
}
66+
67+
if (sceClibStrncmp(name, "net", 3) == 0)
68+
{
69+
*value = cfg.net;
70+
}
6671
}
6772
return 0;
6873
}
@@ -100,7 +105,12 @@ DECL_FUNC_HOOK(sceRegMgrSetKeyInt, const char *category, const char *name, int v
100105
cfg.port = value;
101106
}
102107

103-
CatLogUpdateConfig(cfg.host, cfg.port, cfg.loglevel);
108+
if (sceClibStrncmp(name, "net", 3) == 0)
109+
{
110+
cfg.net = value;
111+
}
112+
113+
CatLogUpdateConfig(cfg.host, cfg.port, cfg.loglevel, cfg.net);
104114

105115
return 0;
106116
}
@@ -116,7 +126,7 @@ DECL_FUNC_HOOK(sceRegMgrSetKeyStr, const char *category, const char *name, char
116126
sceNetInetPton(SCE_NET_AF_INET, value, &cfg.host);
117127
}
118128

119-
CatLogUpdateConfig(cfg.host, cfg.port, cfg.loglevel);
129+
CatLogUpdateConfig(cfg.host, cfg.port, cfg.loglevel, cfg.net);
120130
return 0;
121131
}
122132
return TAI_CONTINUE(int, sceRegMgrSetKeyStrHookRef, category, name, value, len);
@@ -199,7 +209,7 @@ int module_start(SceSize argc, const void *args)
199209
return SCE_KERNEL_START_SUCCESS;
200210
}
201211

202-
CatLogReadConfig(&cfg.host, &cfg.port, &cfg.loglevel);
212+
CatLogReadConfig(&cfg.host, &cfg.port, &cfg.loglevel, &cfg.net);
203213

204214
BIND_FUNC_IMPORT_HOOK(sceKernelLoadStartModule, "SceSettings", 0xCAE9ACE6, 0x2DCC4AFA);
205215
BIND_FUNC_IMPORT_HOOK(sceKernelStopUnloadModule, "SceSettings", 0xCAE9ACE6, 0x2415F8A4);

0 commit comments

Comments
 (0)