PS2SDK
PS2 Homebrew Libraries
rpcservers.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007 Lukasz Bruun <mail@lukasz.dk>
3  *
4  * See the file LICENSE included with this distribution for licensing terms.
5  */
6 
12 #include "types.h"
13 #include "irx.h"
14 #include "stdio.h"
15 #include "freemtap.h"
16 #include "sifman.h"
17 #include "sifcmd.h"
18 #include "thbase.h"
19 
20 #define MTAPSERV_PORT_OPEN 0x80000901
21 #define MTAPSERV_PORT_CLOSE 0x80000902
22 #define MTAPSERV_GET_CONNECTION 0x80000903
23 #define MTAPSERV_GET_SLOT_NUMBER 0x800009FE
24 #define MTAPSERV_CHANGE_SLOT 0x800009FF
25 
26 
27 static u32 sb[4] __attribute__((__aligned__(4))); // Server buffer
28 
29 static s32 threadid_rpc1;
30 static SifRpcDataQueue_t qd1;
31 static SifRpcServerData_t sd1;
32 
33 static s32 threadid_rpc2;
34 static SifRpcDataQueue_t qd2;
35 static SifRpcServerData_t sd2;
36 
37 static s32 threadid_rpc3;
38 static SifRpcDataQueue_t qd3;
39 static SifRpcServerData_t sd3;
40 
41 static s32 threadid_rpc4;
42 static SifRpcDataQueue_t qd4;
43 static SifRpcServerData_t sd4;
44 
45 static s32 threadid_rpc5;
46 static SifRpcDataQueue_t qd5;
47 static SifRpcServerData_t sd5;
48 
49 
50 void* rpc_server_change_slot(s32 fno, u32 *data, s32 size)
51 {
52  (void)fno;
53  (void)size;
54 
55  data[1] = mtapChangeSlot( data[0], data[1] );
56 
57  return data;
58 }
59 
60 
61 void rpc_thread_change_slot(void *arg)
62 {
63  (void)arg;
64 
65  if( sceSifCheckInit() == 0)
66  {
67  M_PRINTF("Sif not initialized.\n");
68  sceSifInit();
69  }
70 
71  sceSifInitRpc(0);
72  sceSifSetRpcQueue(&qd5, GetThreadId());
73  sceSifRegisterRpc(&sd5, MTAPSERV_CHANGE_SLOT, (void*)rpc_server_change_slot, sb, 0, 0, &qd5);
74  sceSifRpcLoop(&qd5);
75 }
76 
77 
78 void* rpc_server_get_slot_number(s32 fno, u32 *data, s32 size)
79 {
80  (void)fno;
81  (void)size;
82 
83  data[1] = mtapGetSlotNumber( data[0] );
84 
85  return data;
86 }
87 
88 
89 void rpc_thread_get_slot_number(void *arg)
90 {
91  (void)arg;
92 
93  if( sceSifCheckInit() == 0)
94  {
95  M_PRINTF("Sif not initialized.\n");
96  sceSifInit();
97  }
98 
99  sceSifInitRpc(0);
100  sceSifSetRpcQueue(&qd4, GetThreadId());
101  sceSifRegisterRpc(&sd4, MTAPSERV_GET_SLOT_NUMBER, (void*)rpc_server_get_slot_number, sb, 0, 0, &qd4);
102  sceSifRpcLoop(&qd4);
103 }
104 
105 void* RpcServerGetConnection(s32 fno, u32 *data, s32 size)
106 {
107  (void)fno;
108  (void)size;
109 
110  data[1] = mtapGetConnection( data[0] );
111 
112  return data;
113 }
114 
115 void RpcThreadGetConnection(void *arg)
116 {
117  (void)arg;
118 
119  if( sceSifCheckInit() == 0)
120  {
121  M_PRINTF("Sif not initialized.\n");
122  sceSifInit();
123  }
124 
125  sceSifInitRpc(0);
126  sceSifSetRpcQueue(&qd3, GetThreadId());
127  sceSifRegisterRpc(&sd3, MTAPSERV_GET_CONNECTION, (void*)RpcServerGetConnection, sb, 0, 0, &qd3);
128  sceSifRpcLoop(&qd3);
129 }
130 
131 void* RpcServerPortClose(s32 fno, u32 *data, s32 size)
132 {
133  (void)fno;
134  (void)size;
135 
136  data[1] = mtapPortClose( data[0] );
137 
138  return data;
139 }
140 
141 void RpcThreadPortClose(void *arg)
142 {
143  (void)arg;
144 
145  if( sceSifCheckInit() == 0)
146  {
147  M_PRINTF("Sif not initialized.\n");
148  sceSifInit();
149  }
150 
151  sceSifInitRpc(0);
152  sceSifSetRpcQueue(&qd2, GetThreadId());
153  sceSifRegisterRpc(&sd2, MTAPSERV_PORT_CLOSE, (void*)RpcServerPortClose, sb, 0, 0, &qd2);
154  sceSifRpcLoop(&qd2);
155 }
156 
157 void* RpcServerPortOpen(s32 fno, u32 *data, s32 size)
158 {
159  (void)fno;
160  (void)size;
161 
162  data[1] = mtapPortOpen( data[0] );
163 
164  return data;
165 }
166 
167 void RpcThreadPortOpen(void *arg)
168 {
169  (void)arg;
170 
171  if( sceSifCheckInit() == 0)
172  {
173  M_PRINTF("Sif not initialized.\n");
174  sceSifInit();
175  }
176 
177  sceSifInitRpc(0);
178  sceSifSetRpcQueue(&qd1, GetThreadId());
179  sceSifRegisterRpc(&sd1, MTAPSERV_PORT_OPEN, (void*)RpcServerPortOpen, sb, 0, 0, &qd1);
180  sceSifRpcLoop(&qd1);
181 
182 }
183 
184 
185 
186 
187 
188 // You should *not* setup 1 RPC server pr. function. Unfortunatly, this
189 // is what XMTAPMAN does, so we have to do the same to be compatible.
190 s32 InitRpcServers()
191 {
192  iop_thread_t rpc_thread;
193 
194  // mtapPortOpen RPC Server
195  rpc_thread.attr = TH_C;
196  rpc_thread.thread = RpcThreadPortOpen;
197  rpc_thread.stacksize = 0x2000;
198  rpc_thread.priority = 32;
199 
200  threadid_rpc1 = CreateThread(&rpc_thread);
201 
202  if(threadid_rpc1 == 0) return 0;
203 
204  StartThread(threadid_rpc1, 0);
205 
206  // mtapPortClose RPC Server
207  rpc_thread.thread = RpcThreadPortClose;
208 
209  threadid_rpc2 = CreateThread(&rpc_thread);
210 
211  if(threadid_rpc2 == 0) return 0;
212 
213  StartThread(threadid_rpc2, 0);
214 
215  // mtapGetConnection RPC Server
216  rpc_thread.thread = RpcThreadGetConnection;
217 
218  threadid_rpc3 = CreateThread(&rpc_thread);
219 
220  if(threadid_rpc3 == 0) return 0;
221 
222  StartThread(threadid_rpc3, 0);
223 
224  // mtapGetSlotNumber RPC Server
225  rpc_thread.thread = rpc_thread_get_slot_number;
226 
227  threadid_rpc4 = CreateThread(&rpc_thread);
228 
229  if(threadid_rpc4 == 0) return 0;
230 
231  StartThread(threadid_rpc4, 0);
232 
233  // mtapChangeSlot RPC Server
234  rpc_thread.thread = rpc_thread_change_slot;
235 
236  threadid_rpc5 = CreateThread(&rpc_thread);
237 
238  if(threadid_rpc5 == 0) return 0;
239 
240  StartThread(threadid_rpc5, 0);
241 
242  return 1;
243 }
thbase.h
sifman.h
freemtap.h
irx.h
mtapGetConnection
int mtapGetConnection(int port)
Definition: libmtap.c:91
stdio.h
_iop_thread
Definition: thbase.h:39
t_SifRpcServerData
Definition: sifrpc-common.h:98
t_SifRpcDataQueue
Definition: sifrpc-common.h:153
__attribute__
Definition: gif_registers.h:38
mtapPortOpen
int mtapPortOpen(int port)
Definition: libmtap.c:71
mtapPortClose
int mtapPortClose(int port)
Definition: libmtap.c:81