23#include "lwip/tcpip.h"
24#include "lwip/netif.h"
26#include "lwip/prot/dhcp.h"
28#include "netif/etharp.h"
30#include "ps2ip_internal.h"
36static struct netif NIF;
37static struct pbuf *TxHead, *TxTail;
39unsigned short int hsyncTicksPerMSec = 16;
41int ps2ip_getconfig(
char* pszName,
t_ip_info* pInfo)
48 memset(pInfo,0,
sizeof(*pInfo));
51 strcpy(pInfo->netif_name,pszName);
52 pInfo->ipaddr.s_addr=pNetIF->
ip_addr.addr;
53 pInfo->netmask.s_addr=pNetIF->netmask.addr;
54 pInfo->gw.s_addr=pNetIF->gw.addr;
56 memcpy(pInfo->hw_addr,pNetIF->
hwaddr,
sizeof(pInfo->hw_addr));
59 struct dhcp *dhcp = netif_dhcp_data(pNetIF);
61 if ((dhcp != NULL) && (dhcp->state != DHCP_STATE_OFF))
63 pInfo->dhcp_enabled=1;
64 pInfo->dhcp_status=dhcp->state;
68 pInfo->dhcp_enabled=0;
69 pInfo->dhcp_status=DHCP_STATE_OFF;
73 pInfo->dhcp_enabled=0;
79int ps2ip_setconfig(
const t_ip_info* pInfo)
89 struct dhcp *dhcp = netif_dhcp_data(pNetIF);
93 if (pInfo->dhcp_enabled)
95 if ((dhcp == NULL) || (dhcp->state == DHCP_STATE_OFF))
98 netif_set_ipaddr(pNetIF,(
IPAddr*)&pInfo->ipaddr);
99 netif_set_netmask(pNetIF,(
IPAddr*)&pInfo->netmask);
100 netif_set_gw(pNetIF,(
IPAddr*)&pInfo->gw);
108 if ((dhcp != NULL) && (dhcp->state != DHCP_STATE_OFF))
111 dhcp_release(pNetIF);
117 netif_set_ipaddr(pNetIF,(
IPAddr*)&pInfo->ipaddr);
118 netif_set_netmask(pNetIF,(
IPAddr*)&pInfo->netmask);
119 netif_set_gw(pNetIF,(
IPAddr*)&pInfo->gw);
123 netif_set_ipaddr(pNetIF,(
IPAddr*)&pInfo->ipaddr);
124 netif_set_netmask(pNetIF,(
IPAddr*)&pInfo->netmask);
125 netif_set_gw(pNetIF,(
IPAddr*)&pInfo->gw);
131static void EnQTxPacket(
struct pbuf *tx)
147static err_t SMapLowLevelOutput(
struct netif* pNetIF,
struct pbuf* pOutput)
159 if((
pbuf = pbuf_coalesce(pOutput,
PBUF_RAW)) != pOutput)
167 EnQTxPacket(pOutput);
174static void LinkStateUp(
void)
179static void LinkStateDown(
void)
184static void *AllocRxPacket(
unsigned int size,
void **
payload)
194static void ReallocRxPacket(
void *packet,
unsigned int size)
196 pbuf_realloc((
struct pbuf *)packet, size);
199static void FreeRxPacket(
void *packet)
204static void EnQRxPacket(
void *packet)
206 ps2ip_input(packet, &NIF);
209static int NextTxPacket(
void **
payload)
223static void DeQTxPacket(
void)
234 if(TxTail == TxHead) {
239 TxTail = TxTail->
next;
251static int AfterTxPacket(
void **
payload)
255 if(TxTail != NULL && TxTail->
next != NULL)
265static void InitDone(
void* pvArg)
267 dbgprintf(
"InitDone: TCPIP initialized\n");
268 sys_sem_signal((sys_sem_t*)pvArg);
279 pNetIF->
output=ðarp_output;
287 dbgprintf(
"MAC address : %02d:%02d:%02d:%02d:%02d:%02d\n",pNetIF->
hwaddr[0],pNetIF->
hwaddr[1],pNetIF->
hwaddr[2],
293err_t ps2ip_input(
PBuf* pInput,
NetIF* pNetIF)
297 if((result = pNetIF->
input(pInput, pNetIF)) != ERR_OK)
303static inline void InitializeLWIP(
void)
307 dbgprintf(
"PS2IP: Module Loaded.\n");
309 sys_sem_new(&Sema, 0);
310 dbgprintf(
"PS2IP: Calling tcpip_init\n");
311 tcpip_init(InitDone,&Sema);
313 sys_arch_sem_wait(&Sema, 0);
316 dbgprintf(
"PS2IP: System Initialised\n");
320extern void _ps2sdk_ps2ipee_init(
void);
321extern void _ps2sdk_ps2ipee_deinit(
void);
340 netif_add(&NIF, ip_address, subnet_mask, gateway, NULL, &
SMapIFInit, tcpip_input);
341 netif_set_default(&NIF);
343 NetManRegisterNetworkStack(&stack);
346 _ps2sdk_ps2ipee_init();
351void ps2ipDeinit(
void){
352 _ps2sdk_ps2ipee_deinit();
354 NetManUnregisterNetworkStack();
struct netif * netif_find(const char *name)
int ps2ipInit(struct ip4_addr *ip_address, struct ip4_addr *subnet_mask, struct ip4_addr *gateway)
void ps2ipSetHsyncTicksPerMSec(unsigned char ticks)
static err_t SMapIFInit(struct netif *pNetIF)
#define NETIF_FLAG_ETHARP
#define NETIF_FLAG_BROADCAST
#define tcpip_callback(f, ctx)
@ NETMAN_NETIF_IOCTL_ETH_GET_MAC
#define NETIF_MAX_HWADDR_LEN
u8 hwaddr[NETIF_MAX_HWADDR_LEN]
netif_linkoutput_fn linkoutput