Skip to content

Commit

Permalink
Separate netman by functions
Browse files Browse the repository at this point in the history
  • Loading branch information
fjtrujy committed Dec 17, 2023
1 parent 966ee66 commit 5c5283e
Show file tree
Hide file tree
Showing 5 changed files with 521 additions and 302 deletions.
37 changes: 36 additions & 1 deletion ee/network/netman/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,44 @@
# Licenced under Academic Free License version 2.0
# Review ps2sdk README & LICENSE files for further details.

EE_OBJS = netman.o rpc_server.o rpc_client.o erl-support.o
CORE_OBJS = erl-support.o

NETMAN_OBJS = \
__netman_MainNetProtStack.o __netman_IsInitialized.o __netman_IsNetStackInitialized.o __netman_NIFLinkState.o \
NetManToggleGlobalNetIFLinkState.o NetManGetGlobalNetIFLinkState.o NetManInit.o NetManDeinit.o \
NetManRegisterNetworkStack.o NetManUnregisterNetworkStack.o NetManNetIFXmit.o NetManIoctl.o \
NetManNetProtStackAllocRxPacket.o NetManNetProtStackFreeRxPacket.o NetManNetProtStackEnQRxPacket.o \
NetManTxPacketNext.o NetManTxPacketDeQ.o NetManTxPacketAfter.o NetManNetProtStackReallocRxPacket.o

RPC_SERVER_OBJS = \
__NETMAN_RpcSvr_threadID.o __NETMAN_Rx_threadID.o __NETMAN_SifHandlerID.o __rpc_server_IsInitialized.o \
__rpc_server_IsProcessingRx.o __rpc_server_FrameBufferStatus.o __rpc_server_RxIOPFrameBufferStatus.o \
__rpc_server_cb_queue.o __rpc_server_cb_srv.o \
__rpc_server_ClearBufferLen.o _NetManRPCAllocRxBuffers.o _NetManInitRPCServer.o _NetManDeinitRPCServer.o

RPC_CLIENT_OBJS = \
__rpc_client_TransmitBuffer.o __rpc_client_ReceiveBuffer.o __NETMAN_rpc_cd.o __NetManIOSemaID.o \
__NETMAN_Tx_threadID.o __netman_IOPFrameBufferWrPtr.o __netman_IOPFrameBuffer.o \
__netman_IOPFrameBufferStatus.o __netman_FrameBufferStatus.o __netman_rpc_client_IsInitialized.o \
__netman_rpc_client_IIsProcessingTx.o __rpc_client_deinitCleanup.o NetManInitRPCClient.o \
NetManRPCRegisterNetworkStack.o NetManRPCUnregisterNetworkStack.o NetManDeinitRPCClient.o NetManRpcIoctl.o \
NetManRpcNetIFXmit.o NetManSetMainIF.o NetManQueryMainIF.o NetManSetLinkMode.o

EE_OBJS = $(CORE_OBJS) $(NETMAN_OBJS) $(RPC_SERVER_OBJS) $(RPC_CLIENT_OBJS)

include $(PS2SDKSRC)/Defs.make
include $(PS2SDKSRC)/ee/Rules.lib.make
include $(PS2SDKSRC)/ee/Rules.make
include $(PS2SDKSRC)/ee/Rules.release

$(NETMAN_OBJS:%=$(EE_OBJS_DIR)%): $(EE_SRC_DIR)netman.c
$(DIR_GUARD)
$(EE_C_COMPILE) -DF_$(*:$(EE_OBJS_DIR)%=%) $< -c -o $@

$(RPC_SERVER_OBJS:%=$(EE_OBJS_DIR)%): $(EE_SRC_DIR)rpc_server.c
$(DIR_GUARD)
$(EE_C_COMPILE) -DF_$(*:$(EE_OBJS_DIR)%=%) $< -c -o $@

$(RPC_CLIENT_OBJS:%=$(EE_OBJS_DIR)%): $(EE_SRC_DIR)rpc_client.c
$(DIR_GUARD)
$(EE_C_COMPILE) -DF_$(*:$(EE_OBJS_DIR)%=%) $< -c -o $@
6 changes: 3 additions & 3 deletions ee/network/netman/src/include/rpc_server.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
int NetManInitRPCServer(void);
void NetManDeinitRPCServer(void);
int NetManRPCAllocRxBuffers(void);
int _NetManInitRPCServer(void);
void _NetManDeinitRPCServer(void);
int _NetManRPCAllocRxBuffers(void);
134 changes: 92 additions & 42 deletions ee/network/netman/src/netman.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,142 +8,192 @@
#include "rpc_client.h"
#include "rpc_server.h"

static struct NetManNetProtStack MainNetProtStack;
static unsigned char IsInitialized=0, IsNetStackInitialized=0;
static char NIFLinkState = 0;
#ifdef F___netman_MainNetProtStack
struct NetManNetProtStack __netman_MainNetProtStack;
#else
extern struct NetManNetProtStack __netman_MainNetProtStack;
#endif

#ifdef F___netman_IsInitialized
unsigned char __netman_IsInitialized=0;
#else
extern unsigned char __netman_IsInitialized;
#endif

#ifdef F___netman_IsNetStackInitialized
unsigned char __netman_IsNetStackInitialized=0;
#else
extern unsigned char __netman_IsNetStackInitialized;
#endif

#ifdef F___netman_NIFLinkState
char __netman_NIFLinkState = 0;
#else
extern char __netman_NIFLinkState;
#endif

static inline void NetManUpdateStack__netman_NIFLinkState(void)
{
if(__netman_IsNetStackInitialized)
{
if(__netman_NIFLinkState)
__netman_MainNetProtStack.LinkStateUp();
else
__netman_MainNetProtStack.LinkStateDown();
}
}

#ifdef F_NetManToggleGlobalNetIFLinkState
/* Upon stack registration on the IOP side, this function will be called.
But the network stack won't be updated then because the RPC wouldn't have been completely initialized,
which would prevent the stack from performing some actions like sending Gratuitous Arp packets.
The NIF status updated will be sent again when the RPC is fully initialized, as shown in NetManRegisterNetworkStack(). */
void NetManToggleGlobalNetIFLinkState(unsigned char state)
{
NIFLinkState = state;
__netman_NIFLinkState = state;

NetManUpdateStackNIFLinkState();
NetManUpdateStack__netman_NIFLinkState();
}
#endif

#ifdef F_NetManGetGlobalNetIFLinkState
int NetManGetGlobalNetIFLinkState(void)
{
return NIFLinkState;
}

void NetManUpdateStackNIFLinkState(void)
{
if(IsNetStackInitialized)
{
if(NIFLinkState)
MainNetProtStack.LinkStateUp();
else
MainNetProtStack.LinkStateDown();
}
return __netman_NIFLinkState;
}
#endif

#ifdef F_NetManInit
int NetManInit(void)
{
int result;

if(!IsInitialized)
if(!__netman_IsInitialized)
{
if((result=NetManInitRPCServer())==0)
if((result=_NetManInitRPCServer())==0)
{
if((result=NetManInitRPCClient())==0) IsInitialized = 1;
if((result=NetManInitRPCClient())==0) __netman_IsInitialized = 1;
}
}else result = 0;

return result;
}
#endif

#ifdef F_NetManDeinit
void NetManDeinit(void)
{
if(IsInitialized)
if(__netman_IsInitialized)
{
NetManUnregisterNetworkStack();

NetManDeinitRPCClient();
NetManDeinitRPCServer();
IsInitialized = 0;
_NetManDeinitRPCServer();
__netman_IsInitialized = 0;
}
}
#endif

#ifdef F_NetManRegisterNetworkStack
int NetManRegisterNetworkStack(const struct NetManNetProtStack *stack)
{
int result;

if((result=NetManInit())==0)
{
if(!IsNetStackInitialized)
if(!__netman_IsNetStackInitialized)
{
if((result=NetManRPCRegisterNetworkStack())==0)
{
memcpy(&MainNetProtStack, stack, sizeof(MainNetProtStack));
IsNetStackInitialized=1;
if((result=NetManRPCAllocRxBuffers()) == 0)
NetManUpdateStackNIFLinkState();
memcpy(&__netman_MainNetProtStack, stack, sizeof(__netman_MainNetProtStack));
__netman_IsNetStackInitialized=1;
if((result=_NetManRPCAllocRxBuffers()) == 0)
NetManUpdateStack__netman_NIFLinkState();
}
}
else result=0;
}

return result;
}
#endif

#ifdef F_NetManUnregisterNetworkStack
void NetManUnregisterNetworkStack(void)
{
if(IsNetStackInitialized)
if(__netman_IsNetStackInitialized)
{
NetManRPCUnregisterNetworkStack();
memset(&MainNetProtStack, 0, sizeof(MainNetProtStack));
memset(&__netman_MainNetProtStack, 0, sizeof(__netman_MainNetProtStack));

IsNetStackInitialized=0;
__netman_IsNetStackInitialized=0;
}
}
#endif

#ifdef F_NetManNetIFXmit
void NetManNetIFXmit(void)
{
if(IsInitialized)
if(__netman_IsInitialized)
NetManRpcNetIFXmit();
}
#endif

#ifdef F_NetManIoctl
int NetManIoctl(unsigned int command, void *arg, unsigned int arg_len, void *output, unsigned int length)
{
return IsInitialized?NetManRpcIoctl(command, arg, arg_len, output, length):-1;
return __netman_IsInitialized?NetManRpcIoctl(command, arg, arg_len, output, length):-1;
}
#endif

#ifdef F_NetManNetProtStackAllocRxPacket
void *NetManNetProtStackAllocRxPacket(unsigned int length, void **payload)
{
return IsNetStackInitialized?MainNetProtStack.AllocRxPacket(length, payload):NULL;
return __netman_IsNetStackInitialized? __netman_MainNetProtStack.AllocRxPacket(length, payload) : NULL;
}
#endif

#ifdef F_NetManNetProtStackFreeRxPacket
void NetManNetProtStackFreeRxPacket(void *packet)
{
if(IsNetStackInitialized) MainNetProtStack.FreeRxPacket(packet);
if(__netman_IsNetStackInitialized) __netman_MainNetProtStack.FreeRxPacket(packet);
}
#endif

#ifdef F_NetManNetProtStackEnQRxPacket
void NetManNetProtStackEnQRxPacket(void *packet)
{
if(IsNetStackInitialized)
MainNetProtStack.EnQRxPacket(packet);
if(__netman_IsNetStackInitialized)
__netman_MainNetProtStack.EnQRxPacket(packet);
}
#endif

#ifdef F_NetManTxPacketNext
int NetManTxPacketNext(void **payload)
{
return IsInitialized?MainNetProtStack.NextTxPacket(payload):-1;
return __netman_IsInitialized? __netman_MainNetProtStack.NextTxPacket(payload) : -1;
}
#endif

#ifdef F_NetManTxPacketDeQ
void NetManTxPacketDeQ(void)
{
if(IsInitialized)
MainNetProtStack.DeQTxPacket();
if(__netman_IsInitialized)
__netman_MainNetProtStack.DeQTxPacket();
}
#endif

#ifdef F_NetManTxPacketAfter
int NetManTxPacketAfter(void **payload)
{
return IsInitialized?MainNetProtStack.AfterTxPacket(payload):-1;
return __netman_IsInitialized? __netman_MainNetProtStack.AfterTxPacket(payload) : -1;
}
#endif

#ifdef F_NetManNetProtStackReallocRxPacket
void NetManNetProtStackReallocRxPacket(void *packet, unsigned int length)
{
if(IsNetStackInitialized) MainNetProtStack.ReallocRxPacket(packet, length);
if(__netman_IsNetStackInitialized) __netman_MainNetProtStack.ReallocRxPacket(packet, length);
}
#endif
Loading

0 comments on commit 5c5283e

Please sign in to comment.