PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
secrsif.c
1#include <loadcore.h>
2#include <stdio.h>
3#include <sysclib.h>
4#include <thbase.h>
5#include <irx.h>
6#include <secrman.h>
7#include <sifman.h>
8#include <sifcmd.h>
9
10#include "secrsif.h"
11
12#define MODNAME "secrsif"
13IRX_ID(MODNAME, 1, 2);
14
15#ifdef DEBUG
16#define DPRINTF(x...) printf("SECRSIF: " x)
17#else
18#define DPRINTF(x...)
19#endif
20
21extern struct irx_export_table _exp_secrsif;
22
23static SifRpcDataQueue_t SifSecrDownloadHeaderQD;
24static SifRpcDataQueue_t SifSecrDownloadBlockQD;
25static SifRpcDataQueue_t SifSecrDownloadGetKbitQD;
26static SifRpcDataQueue_t SifSecrDownloadGetKcQD;
27static SifRpcDataQueue_t SifSecrDownloadGetICVPS2QD;
28static SifRpcDataQueue_t SifSecrDiskBootHeaderQD;
29static SifRpcDataQueue_t SifSecrDiskBootBlockQD;
30
31static SifRpcServerData_t SifSecrDownloadHeaderData;
32static SifRpcServerData_t SifSecrDownloadBlockData;
33static SifRpcServerData_t SifSecrDownloadGetKbitData;
34static SifRpcServerData_t SifSecrDownloadGetKcData;
35static SifRpcServerData_t SifSecrDownloadGetICVPS2Data;
36static SifRpcServerData_t SifSecrDiskBootHeaderData;
37static SifRpcServerData_t SifSecrDiskBootBlockData;
38
39static int SifSecrDownloadHeaderThreadID;
40static int SifSecrDownloadBlockThreadID;
41static int SifSecrDownloadGetKbitThreadID;
42static int SifSecrDownloadGetKcThreadID;
43static int SifSecrDownloadGetICVPS2ThreadID;
44static int SifSecrDiskBootHeaderThreadID;
45static int SifSecrDiskBootBlockThreadID;
46
47static unsigned char SifServerBuffer[0x1000];
48
49static void *SifSecrDownloadHeader(int function, void *buffer, int nbytes)
50{
51 (void)function;
52 (void)nbytes;
53
54 ((struct SecrSifDownloadHeaderParams *)buffer)->result = SecrDownloadHeader(((struct SecrSifDownloadHeaderParams *)buffer)->port, ((struct SecrSifDownloadHeaderParams *)buffer)->slot, ((struct SecrSifDownloadHeaderParams *)buffer)->buffer, &((struct SecrSifDownloadHeaderParams *)buffer)->BitTable, &((struct SecrSifDownloadHeaderParams *)buffer)->size);
55 return buffer;
56}
57
58static void *SifSecrDownloadBlockHandler(int function, void *buffer, int nbytes)
59{
60 (void)function;
61 (void)nbytes;
62
63 ((struct SecrSifDownloadBlockParams *)buffer)->result = SecrDownloadBlock(((struct SecrSifDownloadBlockParams *)buffer)->buffer, ((struct SecrSifDownloadBlockParams *)buffer)->size);
64 return buffer;
65}
66
67static void *SifSecrDownloadGetKbitHandler(int function, void *buffer, int nbytes)
68{
69 (void)function;
70 (void)nbytes;
71
72 ((struct SecrSifDownloadGetKbitParams *)buffer)->result = SecrDownloadGetKbit(((struct SecrSifDownloadGetKbitParams *)buffer)->port, ((struct SecrSifDownloadGetKbitParams *)buffer)->slot, ((struct SecrSifDownloadGetKbitParams *)buffer)->kbit);
73 return buffer;
74}
75
76static void *SifSecrDownloadGetKcHandler(int function, void *buffer, int nbytes)
77{
78 (void)function;
79 (void)nbytes;
80 ((struct SecrSifDownloadGetKcParams *)buffer)->result = SecrDownloadGetKc(((struct SecrSifDownloadGetKcParams *)buffer)->port, ((struct SecrSifDownloadGetKcParams *)buffer)->slot, ((struct SecrSifDownloadGetKcParams *)buffer)->kc);
81 return buffer;
82}
83
84static void *SifSecrDownloadGetICVPS2Handler(int function, void *buffer, int nbytes)
85{
86 (void)function;
87 (void)nbytes;
88
89 ((struct SecrSifDownloadGetIcvps2Params *)buffer)->result = SecrDownloadGetICVPS2(((struct SecrSifDownloadGetIcvps2Params *)buffer)->icvps2);
90 return buffer;
91}
92
93static void *SifSecrDiskBootHeaderHandler(int function, void *buffer, int nbytes)
94{
95 (void)function;
96 (void)nbytes;
97
98 ((struct SecrSifDiskBootHeaderParams *)buffer)->result = SecrDiskBootHeader(((struct SecrSifDiskBootHeaderParams *)buffer)->buffer, &((struct SecrSifDiskBootHeaderParams *)buffer)->BitTable, &((struct SecrSifDiskBootHeaderParams *)buffer)->size);
99 return buffer;
100}
101
102static void *SifSecrDiskBootBlockHandler(int function, void *buffer, int nbytes)
103{
104 (void)function;
105 (void)nbytes;
106
107 ((struct SecrSifDiskBootBlockParams *)buffer)->result = SecrDiskBootBlock(((struct SecrSifDiskBootBlockParams *)buffer)->source, ((struct SecrSifDiskBootBlockParams *)buffer)->destination, ((struct SecrSifDiskBootBlockParams *)buffer)->size);
108 DPRINTF("sif_disk_boot_block %p %ld\n", ((struct SecrSifDiskBootBlockParams *)buffer)->source, ((struct SecrSifDiskBootBlockParams *)buffer)->result);
109
110 return buffer;
111}
112
113static void SifSecrDownloadHeaderThread(void *parameters)
114{
115 (void)parameters;
116
117 if (!sceSifCheckInit()) {
118 DPRINTF("yet sif hasn't been init\n");
119 sceSifInit();
120 }
121
122 sceSifInitRpc(0);
123 sceSifSetRpcQueue(&SifSecrDownloadHeaderQD, GetThreadId());
124 sceSifRegisterRpc(&SifSecrDownloadHeaderData, SECRSIF_DOWNLOAD_HEADER, &SifSecrDownloadHeader, SifServerBuffer, NULL, NULL, &SifSecrDownloadHeaderQD);
125 sceSifRpcLoop(&SifSecrDownloadHeaderQD);
126}
127
128static void SifSecrDownloadBlockThread(void *parameters)
129{
130 (void)parameters;
131
132 if (!sceSifCheckInit()) {
133 DPRINTF("yet sif hasn't been init\n");
134 sceSifInit();
135 }
136
137 sceSifInitRpc(0);
138 sceSifSetRpcQueue(&SifSecrDownloadBlockQD, GetThreadId());
139 sceSifRegisterRpc(&SifSecrDownloadBlockData, SECRSIF_DOWNLOAD_BLOCK, &SifSecrDownloadBlockHandler, SifServerBuffer, NULL, NULL, &SifSecrDownloadBlockQD);
140 sceSifRpcLoop(&SifSecrDownloadBlockQD);
141}
142
143static void SifSecrDownloadGetKbitThread(void *parameters)
144{
145 (void)parameters;
146
147 if (!sceSifCheckInit()) {
148 DPRINTF("yet sif hasn't been init\n");
149 sceSifInit();
150 }
151
152 sceSifInitRpc(0);
153 sceSifSetRpcQueue(&SifSecrDownloadGetKbitQD, GetThreadId());
154 sceSifRegisterRpc(&SifSecrDownloadGetKbitData, SECRSIF_DOWNLOAD_GET_KBIT, &SifSecrDownloadGetKbitHandler, SifServerBuffer, NULL, NULL, &SifSecrDownloadGetKbitQD);
155 sceSifRpcLoop(&SifSecrDownloadGetKbitQD);
156}
157
158static void SifSecrDownloadGetKcThread(void *parameters)
159{
160 (void)parameters;
161
162 if (!sceSifCheckInit()) {
163 DPRINTF("yet sif hasn't been init\n");
164 sceSifInit();
165 }
166
167 sceSifInitRpc(0);
168 sceSifSetRpcQueue(&SifSecrDownloadGetKcQD, GetThreadId());
169 sceSifRegisterRpc(&SifSecrDownloadGetKcData, SECRSIF_DOWNLOAD_GET_KC, &SifSecrDownloadGetKcHandler, SifServerBuffer, NULL, NULL, &SifSecrDownloadGetKcQD);
170 sceSifRpcLoop(&SifSecrDownloadGetKcQD);
171}
172
173static void SifSecrDownloadGetICVPS2Thread(void *parameters)
174{
175 (void)parameters;
176
177 if (!sceSifCheckInit()) {
178 DPRINTF("yet sif hasn't been init\n");
179 sceSifInit();
180 }
181
182 sceSifInitRpc(0);
183 sceSifSetRpcQueue(&SifSecrDownloadGetICVPS2QD, GetThreadId());
184 sceSifRegisterRpc(&SifSecrDownloadGetICVPS2Data, SECRSIF_DOWNLOAD_GET_ICVPS2, &SifSecrDownloadGetICVPS2Handler, SifServerBuffer, NULL, NULL, &SifSecrDownloadGetICVPS2QD);
185 sceSifRpcLoop(&SifSecrDownloadGetICVPS2QD);
186}
187
188static void SifSecrDiskBootHeaderThread(void *parameters)
189{
190 (void)parameters;
191
192 if (!sceSifCheckInit()) {
193 DPRINTF("yet sif hasn't been init\n");
194 sceSifInit();
195 }
196
197 sceSifInitRpc(0);
198 sceSifSetRpcQueue(&SifSecrDiskBootHeaderQD, GetThreadId());
199 sceSifRegisterRpc(&SifSecrDiskBootHeaderData, SECRSIF_DISK_BOOT_HEADER, &SifSecrDiskBootHeaderHandler, SifServerBuffer, NULL, NULL, &SifSecrDiskBootHeaderQD);
200 sceSifRpcLoop(&SifSecrDiskBootHeaderQD);
201}
202
203static void SifSecrDiskBootBlockThread(void *parameters)
204{
205 (void)parameters;
206
207 if (!sceSifCheckInit()) {
208 DPRINTF("yet sif hasn't been init\n");
209 sceSifInit();
210 }
211
212 sceSifInitRpc(0);
213 sceSifSetRpcQueue(&SifSecrDiskBootBlockQD, GetThreadId());
214 sceSifRegisterRpc(&SifSecrDiskBootBlockData, SECRSIF_DISK_BOOT_BLOCK, &SifSecrDiskBootBlockHandler, SifServerBuffer, NULL, NULL, &SifSecrDiskBootBlockQD);
215 sceSifRpcLoop(&SifSecrDiskBootBlockQD);
216}
217
218int _start(int argc, char *argv[])
219{
221
222 (void)argc;
223 (void)argv;
224
225 if (RegisterLibraryEntries(&_exp_secrsif) != 0) {
226 return MODULE_NO_RESIDENT_END;
227 }
228
229 thread.attr = TH_C;
230 thread.priority = 0x28;
231 thread.stacksize = 0x800;
232
233 thread.thread = &SifSecrDownloadHeaderThread;
234 if ((SifSecrDownloadHeaderThreadID = CreateThread(&thread)) == 0) {
235 return MODULE_NO_RESIDENT_END;
236 }
237
238 StartThread(SifSecrDownloadHeaderThreadID, NULL);
239
240 thread.thread = &SifSecrDownloadBlockThread;
241 if ((SifSecrDownloadBlockThreadID = CreateThread(&thread)) == 0) {
242 return MODULE_NO_RESIDENT_END;
243 }
244
245 StartThread(SifSecrDownloadBlockThreadID, NULL);
246
247 thread.thread = &SifSecrDownloadGetKbitThread;
248 if ((SifSecrDownloadGetKbitThreadID = CreateThread(&thread)) == 0) {
249 return MODULE_NO_RESIDENT_END;
250 }
251
252 StartThread(SifSecrDownloadGetKbitThreadID, NULL);
253
254 thread.thread = &SifSecrDownloadGetKcThread;
255 if ((SifSecrDownloadGetKcThreadID = CreateThread(&thread)) == 0) {
256 return MODULE_NO_RESIDENT_END;
257 }
258
259 StartThread(SifSecrDownloadGetKcThreadID, NULL);
260
261 thread.thread = &SifSecrDownloadGetICVPS2Thread;
262 if ((SifSecrDownloadGetICVPS2ThreadID = CreateThread(&thread)) == 0) {
263 return MODULE_NO_RESIDENT_END;
264 }
265
266 StartThread(SifSecrDownloadGetICVPS2ThreadID, NULL);
267
268 thread.thread = &SifSecrDiskBootHeaderThread;
269 if ((SifSecrDiskBootHeaderThreadID = CreateThread(&thread)) == 0) {
270 return MODULE_NO_RESIDENT_END;
271 }
272
273 StartThread(SifSecrDiskBootHeaderThreadID, NULL);
274
275 thread.thread = &SifSecrDiskBootBlockThread;
276 if ((SifSecrDiskBootBlockThreadID = CreateThread(&thread)) == 0) {
277 return MODULE_NO_RESIDENT_END;
278 }
279
280 StartThread(SifSecrDiskBootBlockThreadID, NULL);
281
282 return MODULE_RESIDENT_END;
283}