PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
rpcserver.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 "sifcmd.h"
14#include "thbase.h"
15#include "stdio.h"
16#include "sifman.h"
17#include "sifcmd.h"
18#include "freepad.h"
19
20#define PAD_BIND_RPC_ID1 0x80000100
21#define PAD_BIND_RPC_ID2 0x80000101
22
23#define PAD_BIND_OLD_RPC_ID1 0x8000010f
24#define PAD_BIND_OLD_RPC_ID2 0x8000011f
25
26enum PAD_RPCCMD {
27#ifdef BUILDING_XPADMAN
28 PAD_RPCCMD_OPEN = 0x01,
29 // 0x2 undefined
30 PAD_RPCCMD_INFO_ACT = 0x03,
31 PAD_RPCCMD_INFO_COMB,
32 PAD_RPCCMD_INFO_MODE,
33 PAD_RPCCMD_SET_MMODE,
34 PAD_RPCCMD_SET_ACTDIR,
35 PAD_RPCCMD_SET_ACTALIGN,
36 PAD_RPCCMD_GET_BTNMASK,
37 PAD_RPCCMD_SET_BTNINFO,
38 PAD_RPCCMD_SET_VREF,
39 PAD_RPCCMD_GET_PORTMAX,
40 PAD_RPCCMD_GET_SLOTMAX,
41 PAD_RPCCMD_CLOSE,
42 PAD_RPCCMD_END,
43 PAD_RPCCMD_INIT,
44 // 0x11 undefined
45 PAD_RPCCMD_GET_MODVER = 0x12,
46 PAD_RPCCMD_13
47#else
48 PAD_RPCCMD_OPEN = 0x80000100,
49 // 0x80000101 undefined
50 PAD_RPCCMD_INFO_ACT = 0x80000102,
51 PAD_RPCCMD_INFO_COMB,
52 PAD_RPCCMD_INFO_MODE,
53 PAD_RPCCMD_SET_MMODE,
54 PAD_RPCCMD_SET_ACTDIR,
55 PAD_RPCCMD_SET_ACTALIGN,
56 PAD_RPCCMD_GET_BTNMASK,
57 PAD_RPCCMD_SET_BTNINFO,
58 PAD_RPCCMD_SET_VREF,
59 PAD_RPCCMD_GET_PORTMAX,
60 PAD_RPCCMD_GET_SLOTMAX,
61 PAD_RPCCMD_CLOSE,
62 PAD_RPCCMD_END,
63#endif
64};
65
66// RPC Server
67static s32 ThreadIdRpcServer;
68static SifRpcDataQueue_t qd;
69static SifRpcServerData_t sd[2];
70static u32 sb[2][32] __attribute__((__aligned__(4))); // server buffer
71
72// RPC Server Extended
73static s32 ThreadIdRpcServerExt;
74static SifRpcDataQueue_t qdext;
75static SifRpcServerData_t sdext[2];
76static u32 sbext[2][32] __attribute__((__aligned__(4))); // server buffer
77
78static void* RpcPadOpen(u32 *data)
79{
80
81 data[3] = padPortOpen(data[1], data[2], data[4], &data[5]);
82
83 return data;
84}
85
86static void* RpcPadSetMainMode(u32 *data)
87{
88 data[5] = padSetMainMode(data[1], data[2], data[3], data[4]);
89
90 return data;
91}
92
93static void* RpcPadInfoAct(u32 *data)
94{
95
96 data[5] = padInfoAct(data[1], data[2], data[3], data[4]);
97
98 return data;
99}
100
101static void* RpcPadInfoComb(u32 *data)
102{
103 data[5] = padInfoComb(data[1], data[2], data[3], data[4]);
104
105 return data;
106}
107
108static void* RpcPadInfoMode(u32 *data)
109{
110 data[5] = padInfoMode(data[1], data[2], data[3], data[4]);
111
112 return data;
113}
114
115static void* RpcPadSetActDirect(u32 *data)
116{
117 data[5] = padSetActDirect(data[1], data[2], (u8*)&data[3]);
118
119 return data;
120}
121
122static void* RpcPadSetActAlign(u32 *data)
123{
124
125 data[5] = padSetActAlign(data[1], data[2], (u8*)&data[3]);
126
127 return data;
128}
129
130static void* RpcPadGetButtonMask(u32 *data)
131{
132
133 data[3] = padGetButtonMask(data[1], data[2]);
134
135 return data;
136}
137
138static void* RpcPadSetButtonInfo(u32 *data)
139{
140 data[4] = padSetButtonInfo(data[1], data[2], data[3]);
141
142 return data;
143}
144
145static void* RpcPadSetVrefParam(u32 *data)
146{
147 data[7] = padSetVrefParam(data[1], data[2], (u8*)&data[3]);
148
149 return data;
150}
151
152static void* RpcPadGetPortMax(u32 *data)
153{
154 data[3] = padGetPortMax();
155
156 return data;
157}
158
159static void* RpcPadGetSlotMax(u32 *data)
160{
161 data[3] = padGetSlotMax(data[1]);
162
163 return data;
164}
165
166static void* RpcPadClose(u32 *data)
167{
168 data[3] = padPortClose(data[1], data[2], data[4]);
169
170 return data;
171}
172
173static void* RpcPadEnd(u32 *data)
174{
175 data[3] = padEnd();
176
177 return data;
178}
179
180#ifdef BUILDING_XPADMAN
181static void* RpcPadInit(u32 *data)
182{
183 data[3] = padInit((void*)data[4]);
184
185 return data;
186}
187#endif
188
189#ifdef BUILDING_XPADMAN
190static void* RpcGetModVersion(u32 *data)
191{
192 data[3] = padGetModVersion();
193
194 return data;
195}
196#endif
197
198static void* RpcServer(int fno, void *buffer, int length)
199{
200 u32 *data = (u32*)buffer;
201 u32 command = data[0];
202
203 (void)fno;
204 (void)length;
205
206#ifdef BUILDING_XPADMAN
207 if ((0x00000100 & command) != 0)
208 {
209 if ((0x80000000 & command) != 0)
210 {
211 command &= 0xff;
212 command += 1;
213 }
214 else if (command == 0x00000100)
215 {
216 // Unofficial: libpad EE client from v1.3.4 has this RPC function implemented, but is not implemented within its PADMAN module.
217 return buffer;
218 }
219 }
220#endif
221
222 switch(command)
223 {
224#ifdef BUILDING_XPADMAN
225 case PAD_RPCCMD_INIT: return RpcPadInit(data);
226#endif
227 case PAD_RPCCMD_END: return RpcPadEnd(data);
228#ifdef BUILDING_XPADMAN
229 case PAD_RPCCMD_GET_MODVER: return RpcGetModVersion(data);
230#endif
231 case PAD_RPCCMD_OPEN: return RpcPadOpen(data);
232 case PAD_RPCCMD_CLOSE: return RpcPadClose(data);
233 case PAD_RPCCMD_INFO_ACT: return RpcPadInfoAct(data);
234 case PAD_RPCCMD_INFO_COMB: return RpcPadInfoComb(data);
235 case PAD_RPCCMD_INFO_MODE: return RpcPadInfoMode(data);
236 case PAD_RPCCMD_SET_MMODE: return RpcPadSetMainMode(data);
237 case PAD_RPCCMD_SET_ACTDIR: return RpcPadSetActDirect(data);
238 case PAD_RPCCMD_SET_ACTALIGN: return RpcPadSetActAlign(data);
239 case PAD_RPCCMD_GET_BTNMASK: return RpcPadGetButtonMask(data);
240 case PAD_RPCCMD_SET_BTNINFO: return RpcPadSetButtonInfo(data);
241 case PAD_RPCCMD_SET_VREF: return RpcPadSetVrefParam(data);
242 case PAD_RPCCMD_GET_PORTMAX: return RpcPadGetPortMax(data);
243 case PAD_RPCCMD_GET_SLOTMAX: return RpcPadGetSlotMax(data);
244
245 default:
246 M_PRINTF("invalid function code (%03x)\n", (int)data[0]);
247 break;
248 }
249
250 return buffer;
251}
252
253static void* RpcServerExt(int fno, void *buffer, int length)
254{
255 (void)fno;
256 (void)length;
257
258 M_PRINTF("Extend Service: This service is not supported.\n");
259
260 return buffer;
261}
262
263
264static void RpcThread(void *arg)
265{
266 (void)arg;
267
268 if( sceSifCheckInit() == 0)
269 {
270 M_PRINTF("Sif not initialized.\n");
271 sceSifInit();
272 }
273
274 sceSifInitRpc(0);
275 sceSifSetRpcQueue(&qd, GetThreadId());
276#ifdef BUILDING_XPADMAN
277 sceSifRegisterRpc(&sd[0], PAD_BIND_RPC_ID1, &RpcServer, sb[0], NULL, NULL, &qd);
278#endif
279 sceSifRegisterRpc(&sd[1], PAD_BIND_OLD_RPC_ID1, &RpcServer, sb[1], NULL, NULL, &qd);
280 sceSifRpcLoop(&qd);
281}
282
283static void RpcThreadExt(void *arg)
284{
285 (void)arg;
286
287 if( sceSifCheckInit() == 0)
288 {
289 M_PRINTF("Sif not initialized.\n");
290 sceSifInit();
291 }
292
293 sceSifInitRpc(0);
294 sceSifSetRpcQueue(&qdext, GetThreadId());
295#ifdef BUILDING_XPADMAN
296 sceSifRegisterRpc(&sdext[0], PAD_BIND_RPC_ID2, &RpcServerExt, sbext[0], NULL, NULL, &qdext);
297#endif
298 sceSifRegisterRpc(&sdext[1], PAD_BIND_OLD_RPC_ID2, &RpcServerExt, sbext[1], NULL, NULL, &qdext);
299 sceSifRpcLoop(&qdext);
300}
301
302int InitRpcServers(int prio)
303{
304 iop_thread_t rpc_thread;
305
306 if(prio == 0)
307 prio = PADMAN_THPRI_LO;
308
309 // RPC Server
310 rpc_thread.attr = TH_C;
311 rpc_thread.thread = &RpcThread;
312 rpc_thread.stacksize = 0x800;
313 rpc_thread.priority = prio;
314
315 ThreadIdRpcServer = CreateThread(&rpc_thread);
316
317 if(ThreadIdRpcServer == 0) return 0;
318
319 StartThread(ThreadIdRpcServer, NULL);
320
321 // RPC Server Extended
322 rpc_thread.attr = TH_C;
323 rpc_thread.thread = &RpcThreadExt;
324 rpc_thread.stacksize = 0x800;
325 rpc_thread.priority = prio;
326
327 ThreadIdRpcServerExt = CreateThread(&rpc_thread);
328
329 if(ThreadIdRpcServerExt == 0) return 0;
330
331 StartThread(ThreadIdRpcServerExt, NULL);
332
333 return 1;
334}
int padGetPortMax(void)
Definition libpad.c:550
int padPortOpen(int port, int slot, void *padArea)
Definition libpad.c:394
int padSetActAlign(int port, int slot, const char act_align[6])
Definition libpad.c:779
int padInfoMode(int port, int slot, int infoMode, int index)
Definition libpad.c:590
int padGetModVersion()
Definition libpad.c:575
int padSetActDirect(int port, int slot, char act_align[6])
Definition libpad.c:802
int padInit(int mode)
Definition libpad.c:297
int padPortClose(int port, int slot)
Definition libpad.c:451
int padEnd(void)
Definition libpad.c:374
unsigned char padInfoAct(int port, int slot, int word, int byte)
Definition libpad.c:740
int padSetMainMode(int port, int slot, int mode, int lock)
Definition libpad.c:658
int padGetSlotMax(int port)
Definition libpad.c:562