PS2SDK
PS2 Homebrew Libraries
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"
13 IRX_ID(MODNAME, 1, 2);
14 
15 #ifdef DEBUG
16 #define DPRINTF(x...) printf("SECRSIF: " x)
17 #else
18 #define DPRINTF(x...)
19 #endif
20 
21 extern struct irx_export_table _exp_secrsif;
22 
23 static SifRpcDataQueue_t SifSecrDownloadHeaderQD;
24 static SifRpcDataQueue_t SifSecrDownloadBlockQD;
25 static SifRpcDataQueue_t SifSecrDownloadGetKbitQD;
26 static SifRpcDataQueue_t SifSecrDownloadGetKcQD;
27 static SifRpcDataQueue_t SifSecrDownloadGetICVPS2QD;
28 static SifRpcDataQueue_t SifSecrDiskBootHeaderQD;
29 static SifRpcDataQueue_t SifSecrDiskBootBlockQD;
30 
31 static SifRpcServerData_t SifSecrDownloadHeaderData;
32 static SifRpcServerData_t SifSecrDownloadBlockData;
33 static SifRpcServerData_t SifSecrDownloadGetKbitData;
34 static SifRpcServerData_t SifSecrDownloadGetKcData;
35 static SifRpcServerData_t SifSecrDownloadGetICVPS2Data;
36 static SifRpcServerData_t SifSecrDiskBootHeaderData;
37 static SifRpcServerData_t SifSecrDiskBootBlockData;
38 
39 static int SifSecrDownloadHeaderThreadID;
40 static int SifSecrDownloadBlockThreadID;
41 static int SifSecrDownloadGetKbitThreadID;
42 static int SifSecrDownloadGetKcThreadID;
43 static int SifSecrDownloadGetICVPS2ThreadID;
44 static int SifSecrDiskBootHeaderThreadID;
45 static int SifSecrDiskBootBlockThreadID;
46 
47 static unsigned char SifServerBuffer[0x1000];
48 
49 static 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 
58 static 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 
67 static 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 
76 static 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 
84 static 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 
93 static 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 
102 static 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 
113 static 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 
128 static 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 
143 static 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 
158 static 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 
173 static 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 
188 static 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 
203 static 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 
218 int _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 }
thbase.h
sifman.h
sysclib.h
thread
Definition: thcommon.h:143
SecrSifDownloadHeaderParams
Definition: secrsif.h:1
SecrSifDownloadGetKbitParams
Definition: secrsif.h:17
loadcore.h
SecrSifDiskBootBlockParams
Definition: secrsif.h:45
irx.h
irx_export_table
Definition: irx.h:90
SecrSifDownloadGetKcParams
Definition: secrsif.h:24
stdio.h
_iop_thread
Definition: thbase.h:39
t_SifRpcServerData
Definition: sifrpc-common.h:98
t_SifRpcDataQueue
Definition: sifrpc-common.h:153
SecrSifDiskBootHeaderParams
Definition: secrsif.h:37
SecrSifDownloadGetIcvps2Params
Definition: secrsif.h:31
secrman.h
SecrSifDownloadBlockParams
Definition: secrsif.h:10