15#include "rpc_server.h"
16#include "rpc_client.h"
20static unsigned char rpc_buffer[80]
__attribute__((__aligned__(4)));
32static u8 *TxFrameBuffer = NULL;
33static struct NetManBD *FrameBufferStatus = NULL;
34static struct NetManBD *EEFrameBufferStatus = NULL;
35static unsigned short int IOPFrameBufferRdPtr;
37static int RpcThreadID = -1;
38static unsigned char IsInitialized=0, IsRpcStackInitialized=0;
40static void ClearBufferLen(
int index);
42static void LinkStateUp(
void)
44 NetManRpcToggleGlobalNetIFLinkState(1);
47static void LinkStateDown(
void)
49 NetManRpcToggleGlobalNetIFLinkState(0);
52static void *AllocRxPacket(
unsigned int length,
void **payload)
54 return NetManRpcNetProtStackAllocRxPacket(length, payload);
57static void FreeRxPacket(
void *packet)
59 NetManRpcNetProtStackFreeRxPacket(packet);
62static void EnQRxPacket(
void *packet)
64 NetManRpcProtStackEnQRxPacket(packet);
67static int NextTxPacket(
void **payload)
69 *payload = &TxFrameBuffer[IOPFrameBufferRdPtr * NETMAN_MAX_FRAME_SIZE + FrameBufferStatus[IOPFrameBufferRdPtr].offset];
70 return FrameBufferStatus[IOPFrameBufferRdPtr].length;
73static void DeQTxPacket(
void)
75 ClearBufferLen(IOPFrameBufferRdPtr);
78 IOPFrameBufferRdPtr = (IOPFrameBufferRdPtr + 1) % NETMAN_RPC_BLOCK_SIZE;
93static void unregisterEENetworkStack(
void)
95 if(IsRpcStackInitialized)
97 IsRpcStackInitialized=0;
98 NetManUnregisterNetworkStack();
100 if(TxFrameBuffer != NULL)
103 TxFrameBuffer = NULL;
105 if(FrameBufferStatus != NULL)
107 free(FrameBufferStatus);
108 FrameBufferStatus = NULL;
111 EEFrameBufferStatus = NULL;
114 sceSifRemoveCmdHandler(NETMAN_SIFCMD_ID);
117static void ClearBufferLen(
int index)
119 static struct NetManBD zero = { 0 };
121 int dmat_id, OldState;
123 FrameBufferStatus[index].length = 0;
126 dmat.src = (
void*)&zero;
127 dmat.dest = &EEFrameBufferStatus[index];
128 dmat.size =
sizeof(zero);
133 dmat_id = sceSifSetDma(&dmat, 1);
135 }
while(dmat_id == 0);
138static void HandleRxEvent(
void *packet,
void *common)
142 u8 offset = bd->offset;
143 u16 len = bd->length;
147 FrameBufferStatus[id].length = len;
148 FrameBufferStatus[id].offset = offset;
153static void *NETMAN_rpc_handler(
int fno,
void *buffer,
int size)
155 static int ResultValue;
162 case NETMAN_IOP_RPC_FUNC_INIT:
163 ResultValue=NetManInitRPCClient();
166 case NETMAN_IOP_RPC_FUNC_DEINIT:
167 unregisterEENetworkStack();
168 NetManDeinitRPCClient();
171 case NETMAN_IOP_RPC_FUNC_REG_NETWORK_STACK:
172 result = &SifRpcTxBuffer;
174 if(TxFrameBuffer == NULL) TxFrameBuffer = malloc(NETMAN_MAX_FRAME_SIZE * NETMAN_RPC_BLOCK_SIZE);
175 if(FrameBufferStatus == NULL) FrameBufferStatus = malloc(
sizeof(
struct NetManBD) * NETMAN_RPC_BLOCK_SIZE);
177 if(TxFrameBuffer != NULL && FrameBufferStatus != NULL)
180 memset(FrameBufferStatus, 0,
sizeof(
struct NetManBD) * NETMAN_RPC_BLOCK_SIZE);
181 memset(TxFrameBuffer, 0, NETMAN_MAX_FRAME_SIZE * NETMAN_RPC_BLOCK_SIZE);
182 SifRpcTxBuffer.RegNetworkStackResult.FrameBuffer = TxFrameBuffer;
183 IOPFrameBufferRdPtr = 0;
184 ResultValue = NetManRegisterNetworkStack(&RpcStack);
187 sceSifAddCmdHandler(NETMAN_SIFCMD_ID, &HandleRxEvent, NULL);
192 IsRpcStackInitialized=1;
193 SifRpcTxBuffer.RegNetworkStackResult.result = ResultValue;
194 SifRpcTxBuffer.RegNetworkStackResult.FrameBufferStatus = FrameBufferStatus;
196 case NETMAN_IOP_RPC_FUNC_UNREG_NETWORK_STACK:
197 unregisterEENetworkStack();
200 case NETMAN_IOP_RPC_FUNC_IOCTL:
202 result=&SifRpcTxBuffer;
204 case NETMAN_IOP_RPC_FUNC_SET_MAIN_NETIF:
205 SifRpcTxBuffer.result=NetManSetMainIF(buffer);
206 result=&SifRpcTxBuffer;
208 case NETMAN_IOP_RPC_FUNC_QUERY_MAIN_NETIF:
209 SifRpcTxBuffer.QueryMainNetIFResult.result=NetManQueryMainIF(SifRpcTxBuffer.QueryMainNetIFResult.name);
210 result=&SifRpcTxBuffer;
212 case NETMAN_IOP_RPC_FUNC_SET_LINK_MODE:
213 ResultValue=NetManSetLinkMode(*(s32*)buffer);
217 printf(
"NETMAN [IOP]: Unrecognized command: 0x%x\n", fno);
225static void NETMAN_RPC_srv(
void *args)
229 sceSifSetRpcQueue(&rpc_qdata, RpcThreadID);
231 sceSifRegisterRpc(&rpc_sdata, NETMAN_RPC_NUMBER, &NETMAN_rpc_handler, rpc_buffer, NULL, NULL, &rpc_qdata);
232 sceSifRpcLoop(&rpc_qdata);
235int NetmanInitRPCServer(
void)
241 ThreadData.attr=TH_C;
243 ThreadData.thread=&NETMAN_RPC_srv;
244 ThreadData.stacksize=0x600;
245 ThreadData.priority=0x27;
247 StartThread(RpcThreadID=CreateThread(&ThreadData), NULL);
254void NetmanDeinitRPCServer(
void)
258 sceSifRemoveRpc(&rpc_sdata, &rpc_qdata);
259 sceSifRemoveRpcQueue(&rpc_qdata);
261 TerminateThread(RpcThreadID);
262 DeleteThread(RpcThreadID);
int CpuResumeIntr(int state)
int CpuSuspendIntr(int *state)