PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
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
27static u32 sb[4] __attribute__((__aligned__(4))); // Server buffer
28
29static s32 threadid_rpc1;
30static SifRpcDataQueue_t qd1;
31static SifRpcServerData_t sd1;
32
33static s32 threadid_rpc2;
34static SifRpcDataQueue_t qd2;
35static SifRpcServerData_t sd2;
36
37static s32 threadid_rpc3;
38static SifRpcDataQueue_t qd3;
39static SifRpcServerData_t sd3;
40
41static s32 threadid_rpc4;
42static SifRpcDataQueue_t qd4;
43static SifRpcServerData_t sd4;
44
45static s32 threadid_rpc5;
46static SifRpcDataQueue_t qd5;
47static SifRpcServerData_t sd5;
48
49
50void* 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
61void rpc_thread_change_slot()
62{
63 if( sceSifCheckInit() == 0)
64 {
65 M_PRINTF("Sif not initialized.\n");
66 sceSifInit();
67 }
68
69 sceSifInitRpc(0);
70 sceSifSetRpcQueue(&qd5, GetThreadId());
71 sceSifRegisterRpc(&sd5, MTAPSERV_CHANGE_SLOT, (void*)rpc_server_change_slot, sb, 0, 0, &qd5);
72 sceSifRpcLoop(&qd5);
73}
74
75
76void* rpc_server_get_slot_number(s32 fno, u32 *data, s32 size)
77{
78 (void)fno;
79 (void)size;
80
81 data[1] = mtapGetSlotNumber( data[0] );
82
83 return data;
84}
85
86
87void rpc_thread_get_slot_number()
88{
89 if( sceSifCheckInit() == 0)
90 {
91 M_PRINTF("Sif not initialized.\n");
92 sceSifInit();
93 }
94
95 sceSifInitRpc(0);
96 sceSifSetRpcQueue(&qd4, GetThreadId());
97 sceSifRegisterRpc(&sd4, MTAPSERV_GET_SLOT_NUMBER, (void*)rpc_server_get_slot_number, sb, 0, 0, &qd4);
98 sceSifRpcLoop(&qd4);
99}
100
101void* RpcServerGetConnection(s32 fno, u32 *data, s32 size)
102{
103 (void)fno;
104 (void)size;
105
106 data[1] = mtapGetConnection( data[0] );
107
108 return data;
109}
110
111void RpcThreadGetConnection()
112{
113 if( sceSifCheckInit() == 0)
114 {
115 M_PRINTF("Sif not initialized.\n");
116 sceSifInit();
117 }
118
119 sceSifInitRpc(0);
120 sceSifSetRpcQueue(&qd3, GetThreadId());
121 sceSifRegisterRpc(&sd3, MTAPSERV_GET_CONNECTION, (void*)RpcServerGetConnection, sb, 0, 0, &qd3);
122 sceSifRpcLoop(&qd3);
123}
124
125void* RpcServerPortClose(s32 fno, u32 *data, s32 size)
126{
127 (void)fno;
128 (void)size;
129
130 data[1] = mtapPortClose( data[0] );
131
132 return data;
133}
134
135void RpcThreadPortClose()
136{
137 if( sceSifCheckInit() == 0)
138 {
139 M_PRINTF("Sif not initialized.\n");
140 sceSifInit();
141 }
142
143 sceSifInitRpc(0);
144 sceSifSetRpcQueue(&qd2, GetThreadId());
145 sceSifRegisterRpc(&sd2, MTAPSERV_PORT_CLOSE, (void*)RpcServerPortClose, sb, 0, 0, &qd2);
146 sceSifRpcLoop(&qd2);
147}
148
149void* RpcServerPortOpen(s32 fno, u32 *data, s32 size)
150{
151 (void)fno;
152 (void)size;
153
154 data[1] = mtapPortOpen( data[0] );
155
156 return data;
157}
158
159void RpcThreadPortOpen()
160{
161 if( sceSifCheckInit() == 0)
162 {
163 M_PRINTF("Sif not initialized.\n");
164 sceSifInit();
165 }
166
167 sceSifInitRpc(0);
168 sceSifSetRpcQueue(&qd1, GetThreadId());
169 sceSifRegisterRpc(&sd1, MTAPSERV_PORT_OPEN, (void*)RpcServerPortOpen, sb, 0, 0, &qd1);
170 sceSifRpcLoop(&qd1);
171
172}
173
174
175
176
177
178// You should *not* setup 1 RPC server pr. function. Unfortunatly, this
179// is what XMTAPMAN does, so we have to do the same to be compatible.
180s32 InitRpcServers()
181{
182 iop_thread_t rpc_thread;
183
184 // mtapPortOpen RPC Server
185 rpc_thread.attr = TH_C;
186 rpc_thread.thread = RpcThreadPortOpen;
187 rpc_thread.stacksize = 0x2000;
188 rpc_thread.priority = 32;
189
190 threadid_rpc1 = CreateThread(&rpc_thread);
191
192 if(threadid_rpc1 == 0) return 0;
193
194 StartThread(threadid_rpc1, 0);
195
196 // mtapPortClose RPC Server
197 rpc_thread.thread = RpcThreadPortClose;
198
199 threadid_rpc2 = CreateThread(&rpc_thread);
200
201 if(threadid_rpc2 == 0) return 0;
202
203 StartThread(threadid_rpc2, 0);
204
205 // mtapGetConnection RPC Server
206 rpc_thread.thread = RpcThreadGetConnection;
207
208 threadid_rpc3 = CreateThread(&rpc_thread);
209
210 if(threadid_rpc3 == 0) return 0;
211
212 StartThread(threadid_rpc3, 0);
213
214 // mtapGetSlotNumber RPC Server
215 rpc_thread.thread = rpc_thread_get_slot_number;
216
217 threadid_rpc4 = CreateThread(&rpc_thread);
218
219 if(threadid_rpc4 == 0) return 0;
220
221 StartThread(threadid_rpc4, 0);
222
223 // mtapChangeSlot RPC Server
224 rpc_thread.thread = rpc_thread_change_slot;
225
226 threadid_rpc5 = CreateThread(&rpc_thread);
227
228 if(threadid_rpc5 == 0) return 0;
229
230 StartThread(threadid_rpc5, 0);
231
232 return 1;
233}
int mtapGetConnection(int port)
Definition libmtap.c:87
int mtapPortClose(int port)
Definition libmtap.c:77
int mtapPortOpen(int port)
Definition libmtap.c:67