28#include "lwip/tcpip.h"
29#include "lwip/prot/dhcp.h"
30#include "lwip/netif.h"
33#include "netif/etharp.h"
35#include "ps2ip_internal.h"
41#define MODNAME "TCP/IP Stack"
47static int iTimerARP=0;
49#if defined(PS2IP_DHCP)
50static int iTimerDHCP=0;
55ps2ip_getconfig(
char* pszName,
t_ip_info* pInfo)
64 memset(pInfo,0,
sizeof(*pInfo));
67 strcpy(pInfo->netif_name,pszName);
68 pInfo->ipaddr.s_addr=pNetIF->
ip_addr.addr;
69 pInfo->netmask.s_addr=pNetIF->netmask.addr;
70 pInfo->gw.s_addr=pNetIF->gw.addr;
72 memcpy(pInfo->hw_addr,pNetIF->
hwaddr,
sizeof(pInfo->hw_addr));
75 struct dhcp *dhcp = netif_dhcp_data(pNetIF);
77 if ((dhcp != NULL) && (dhcp->state != DHCP_STATE_OFF))
79 pInfo->dhcp_enabled=1;
80 pInfo->dhcp_status=dhcp->state;
84 pInfo->dhcp_enabled=0;
85 pInfo->dhcp_status=DHCP_STATE_OFF;
90 pInfo->dhcp_enabled=0;
109 struct dhcp *dhcp = netif_dhcp_data(pNetIF);
113 if (pInfo->dhcp_enabled)
115 if ((dhcp == NULL) || (dhcp->state == DHCP_STATE_OFF))
118 netif_set_ipaddr(pNetIF,(
const IPAddr*)&pInfo->ipaddr);
119 netif_set_netmask(pNetIF,(
const IPAddr*)&pInfo->netmask);
120 netif_set_gw(pNetIF,(
const IPAddr*)&pInfo->gw);
128 if ((dhcp != NULL) && (dhcp->state != DHCP_STATE_OFF))
131 dhcp_release(pNetIF);
137 netif_set_ipaddr(pNetIF,(
const IPAddr*)&pInfo->ipaddr);
138 netif_set_netmask(pNetIF,(
const IPAddr*)&pInfo->netmask);
139 netif_set_gw(pNetIF,(
const IPAddr*)&pInfo->gw);
142 netif_set_ipaddr(pNetIF,(
const IPAddr*)&pInfo->ipaddr);
143 netif_set_netmask(pNetIF,(
const IPAddr*)&pInfo->netmask);
144 netif_set_gw(pNetIF,(
const IPAddr*)&pInfo->gw);
150static void InitDone(
void* pvArg)
152 dbgprintf(
"InitDone: TCPIP initialized\n");
153 sys_sem_signal((sys_sem_t*)pvArg);
157static void TimerThread(
void* pvArg)
165 iTimerARP+=TCP_TMR_INTERVAL;
166 if (iTimerARP>=ARP_TMR_INTERVAL)
168 iTimerARP-=ARP_TMR_INTERVAL;
172#if defined(PS2IP_DHCP)
176 iTimerDHCP+=TCP_TMR_INTERVAL;
177 if ((iTimerDHCP-TCP_TMR_INTERVAL)/DHCP_FINE_TIMER_MSECS!=iTimerDHCP/DHCP_FINE_TIMER_MSECS)
182 if (iTimerDHCP>=DHCP_COARSE_TIMER_SECS*1000)
184 iTimerDHCP-=DHCP_COARSE_TIMER_SECS*1000;
189 DelayThread(TCP_TMR_INTERVAL*250);
193static inline void InitTimer(
void)
195 iop_thread_t Thread={TH_C, (u32)
"PS2IP-timer", TimerThread, 0x300, 0x16};
196 int iTimerThreadID=CreateThread(&Thread);
198 if (iTimerThreadID<0)
200 printf(
"InitTimer: Fatal error - Failed to create tcpip timer-thread!\n");
204 StartThread(iTimerThreadID, NULL);
213 if((result = pNetIF->
input(pInput, pNetIF)) != ERR_OK)
219int _exit(
int argc,
char *argv[])
224 return MODULE_NO_RESIDENT_END;
227int _start(
int argc,
char *argv[]){
234 dbgprintf(
"PS2IP: Module Loaded.\n");
236 if ((result = RegisterLibraryEntries(&_exp_ps2ip)) != 0)
238 printf(
"PS2IP: RegisterLibraryEntries returned: %d\n", result);
239 return MODULE_NO_RESIDENT_END;
241 sys_sem_new(&Sema, 0);
242 dbgprintf(
"PS2IP: Calling tcpip_init\n");
243 tcpip_init(InitDone,&Sema);
245 sys_arch_sem_wait(&Sema, 0);
248 dbgprintf(
"PS2IP: tcpip_init called\n");
253 dbgprintf(
"PS2IP: System Initialised\n");
256 return MODULE_RESIDENT_END;
struct netif * netif_find(const char *name)
u8 hwaddr[NETIF_MAX_HWADDR_LEN]