14#include "rpc_client.h"
28static unsigned short int EEFrameBufferWrPtr, NumFramesInQueue;
31static int NetManIOSemaID = -1;
41static u8 *FrameBuffer = NULL;
42static struct NetManBD *FrameBufferStatus = NULL;
43static struct NetManBD *EEFrameBufferStatus = NULL;
45int NetManInitRPCClient(
void)
47 static const char NetManID[] =
"NetMan";
51 if(FrameBuffer == NULL) FrameBuffer = malloc(NETMAN_RPC_BLOCK_SIZE * NETMAN_MAX_FRAME_SIZE);
52 if(FrameBufferStatus == NULL) FrameBufferStatus = malloc(NETMAN_RPC_BLOCK_SIZE *
sizeof(
struct NetManBD));
54 if(FrameBuffer != NULL && FrameBufferStatus != NULL)
58 memset(FrameBuffer, 0, NETMAN_RPC_BLOCK_SIZE * NETMAN_MAX_FRAME_SIZE);
59 memset(FrameBufferStatus, 0, NETMAN_RPC_BLOCK_SIZE *
sizeof(
struct NetManBD));
60 EEFrameBufferWrPtr = 0;
63 for(i = 0; i < NETMAN_RPC_BLOCK_SIZE; i++)
64 FrameBufferStatus[i].length = USHRT_MAX;
66 while((result=sceSifBindRpc(&EEClient, NETMAN_RPC_NUMBER, 0))<0 || EEClient.server==NULL) DelayThread(500);
68 if((result=sceSifCallRpc(&EEClient, NETMAN_EE_RPC_FUNC_INIT, 0, &FrameBufferStatus, 4, &SifRpcRxBuffer,
sizeof(
struct NetManEEInitResult), NULL, NULL))>=0)
70 if((result=SifRpcRxBuffer.EEInitResult.result) == 0)
72 EEFrameBufferStatus = SifRpcRxBuffer.EEInitResult.FrameBufferStatus;
75 sema.option = (u32)NetManID;
78 NetManIOSemaID = CreateSema(&sema);
86void NetManDeinitRPCClient(
void)
88 if(FrameBuffer != NULL)
93 if(FrameBufferStatus != NULL)
95 free(FrameBufferStatus);
96 FrameBufferStatus = NULL;
98 if(NetManIOSemaID >= 0)
100 DeleteSema(NetManIOSemaID);
104 memset(&EEClient, 0,
sizeof(EEClient));
107void NetManRpcToggleGlobalNetIFLinkState(
int state)
109 WaitSema(NetManIOSemaID);
110 SifRpcTxBuffer.state=state;
111 sceSifCallRpc(&EEClient, NETMAN_EE_RPC_FUNC_HANDLE_LINK_STATUS_CHANGE, 0, &SifRpcTxBuffer,
sizeof(s32), NULL, 0, NULL, NULL);
112 SignalSema(NetManIOSemaID);
116void *NetManRpcNetProtStackAllocRxPacket(
unsigned int length,
void **payload)
119 volatile const struct NetManBD *bd = &FrameBufferStatus[EEFrameBufferWrPtr];
122 while(bd->length != 0) { }
125 result = &pbufs[EEFrameBufferWrPtr];
126 result->handle = (
void*)bd;
127 result->payload = &FrameBuffer[EEFrameBufferWrPtr * NETMAN_MAX_FRAME_SIZE];
128 result->length = length;
132 *payload = result->payload;
137void NetManRpcNetProtStackFreeRxPacket(
void *packet)
143static int sendFramesToEE(
int mode)
147 if (NumFramesInQueue > 0)
151 dmatReqs[(NumFramesInQueue-1) * 2 + 1].attr = SIF_DMA_INT_O;
157 res = sceSifSetDma(dmatReqs, 2*NumFramesInQueue);
163 if (mode != 0 && res == 0)
167 NumFramesInQueue = 0;
174#define FRAME_GROUPING_INTERVAL 36864
176static unsigned int FrameSendCB(
void *arg)
180 return(sendFramesToEE(1) == 0 ? 0 : FRAME_GROUPING_INTERVAL);
184static void EnQFrame(
const void *frame,
unsigned int length)
191 CancelAlarm(&FrameSendCB, NULL);
193 if (NumFramesInQueue >= NETMAN_FRAME_GROUP_SIZE)
200 bd = &FrameBufferStatus[EEFrameBufferWrPtr];
206 dmat = &dmatReqs[NumFramesInQueue * 2];
207 dmat[0].src = (
void*)frame;
208 dmat[0].dest = bd->payload;
209 dmat[0].size = (length + 3) & ~3;
213 dmat[1].dest = &EEFrameBufferStatus[EEFrameBufferWrPtr];
214 dmat[1].size =
sizeof(
struct NetManBD);
219 EEFrameBufferWrPtr = (EEFrameBufferWrPtr + 1) % NETMAN_RPC_BLOCK_SIZE;
221 if (NumFramesInQueue >= NETMAN_FRAME_GROUP_SIZE)
226 clock.lo = FRAME_GROUPING_INTERVAL;
228 SetAlarm(&clock, &FrameSendCB, NULL);
233void NetManRpcProtStackEnQRxPacket(
void *packet)
int CpuResumeIntr(int state)
int CpuSuspendIntr(int *state)