ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
ps2ip.h File Reference
#include <stddef.h>
#include <tcpip.h>
+ Include dependency graph for ps2ip.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define accept(a, b, c)   lwip_accept(a,b,c)
 
#define bind(a, b, c)   lwip_bind(a,b,c)
 
#define shutdown(a, b)   lwip_shutdown(a,b)
 
#define disconenct(s)   lwip_close(s)
 
#define closesocket(s)   lwip_close(s)
 
#define connect(a, b, c)   lwip_connect(a,b,c)
 
#define getsockname(a, b, c)   lwip_getsockname(a,b,c)
 
#define getpeername(a, b, c)   lwip_getpeername(a,b,c)
 
#define setsockopt(a, b, c, d, e)   lwip_setsockopt(a,b,c,d,e)
 
#define getsockopt(a, b, c, d, e)   lwip_getsockopt(a,b,c,d,e)
 
#define listen(a, b)   lwip_listen(a,b)
 
#define recv(a, b, c, d)   lwip_recv(a,b,c,d)
 
#define recvfrom(a, b, c, d, e, f)   lwip_recvfrom(a,b,c,d,e,f)
 
#define send(a, b, c, d)   lwip_send(a,b,c,d)
 
#define sendto(a, b, c, d, e, f)   lwip_sendto(a,b,c,d,e,f)
 
#define socket(a, b, c)   lwip_socket(a,b,c)
 
#define select(a, b, c, d, e)   lwip_select(a,b,c,d,e)
 
#define ioctlsocket(a, b, c)   lwip_ioctl(a,b,c)
 
#define inet_addr(cp)   ipaddr_addr(cp)
 
#define inet_aton(cp, addr)   ip4addr_aton(cp, (ip4_addr_t*)addr)
 
#define inet_ntoa(addr)   ip4addr_ntoa((const ip4_addr_t*)&(addr))
 
#define inet_ntoa_r(addr, buf, buflen)   ip4addr_ntoa_r((const ip4_addr_t*)&(addr), buf, buflen)
 
#define I_netif_add   DECLARE_IMPORT(26, netif_add)
 

Functions

int ps2ipInit (struct ip4_addr *ip_address, struct ip4_addr *subnet_mask, struct ip4_addr *gateway)
 
void ps2ipDeinit (void)
 
void ps2ipSetHsyncTicksPerMSec (unsigned char ticks)
 
int lwip_accept (int s, struct sockaddr *addr, socklen_t *addrlen)
 
int lwip_bind (int s, const struct sockaddr *name, socklen_t namelen)
 
int lwip_shutdown (int s, int how)
 
int lwip_getpeername (int s, struct sockaddr *name, socklen_t *namelen)
 
int lwip_getsockname (int s, struct sockaddr *name, socklen_t *namelen)
 
int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *optlen)
 
int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_t optlen)
 
int lwip_close (int s)
 
int lwip_connect (int s, const struct sockaddr *name, socklen_t namelen)
 
int lwip_listen (int s, int backlog)
 
int lwip_recv (int s, void *mem, size_t len, int flags)
 
int lwip_read (int s, void *mem, size_t len)
 
int lwip_recvfrom (int s, void *mem, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen)
 
int lwip_send (int s, const void *dataptr, size_t size, int flags)
 
int lwip_sendto (int s, const void *dataptr, size_t size, int flags, const struct sockaddr *to, socklen_t tolen)
 
int lwip_socket (int domain, int type, int protocol)
 
int lwip_write (int s, const void *dataptr, size_t size)
 
int lwip_select (int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, struct timeval *timeout)
 
int lwip_ioctl (int s, long cmd, void *argp)
 
int lwip_fcntl (int s, int cmd, int val)
 
int ps2ip_setconfig (const t_ip_info *ip_info)
 
int ps2ip_getconfig (char *netif_name, t_ip_info *ip_info)
 
err_t ps2ip_input (struct pbuf *p, struct netif *inp)
 
err_t etharp_output (struct netif *netif, struct pbuf *q, const ip_addr_t *ipaddr)
 
u32 ipaddr_addr (const char *cp)
 
int ip4addr_aton (const char *cp, ip4_addr_t *addr)
 
char * ip4addr_ntoa (const ip4_addr_t *addr)
 
char * ip4addr_ntoa_r (const ip4_addr_t *addr, char *buf, int buflen)
 
err_t tcpip_input (struct pbuf *p, struct netif *inp)
 
struct netifnetif_add (struct netif *netif, void *state, netif_init_fn init, netif_input_fn input)
 
struct netifnetif_find (const char *name)
 
void netif_set_default (struct netif *netif)
 
void netif_set_ipaddr (struct netif *netif, const ip4_addr_t *ipaddr)
 
void netif_set_netmask (struct netif *netif, const ip4_addr_t *netmask)
 
void netif_set_gw (struct netif *netif, const ip4_addr_t *gw)
 
void netif_set_up (struct netif *netif)
 
void netif_set_down (struct netif *netif)
 
struct pbufpbuf_alloc (pbuf_layer l, u16 size, pbuf_type type)
 
void pbuf_realloc (struct pbuf *p, u16 size)
 
u8 pbuf_header (struct pbuf *p, s16 header_size)
 
void pbuf_ref (struct pbuf *p)
 
u8 pbuf_free (struct pbuf *p)
 
u8 pbuf_clen (struct pbuf *p)
 
void pbuf_chain (struct pbuf *h, struct pbuf *t)
 
struct pbufpbuf_dechain (struct pbuf *p)
 
struct pbufpbuf_take (struct pbuf *f)
 
struct pbufpbuf_coalesce (struct pbuf *p, pbuf_layer layer)
 

Detailed Description

Imports and definitions for ps2ip.

Definition in file ps2ip.h.

Macro Definition Documentation

◆ accept

#define accept (   a,
  b,
 
)    lwip_accept(a,b,c)

Definition at line 53 of file ps2ip.h.

◆ bind

#define bind (   a,
  b,
 
)    lwip_bind(a,b,c)

Definition at line 54 of file ps2ip.h.

◆ closesocket

#define closesocket (   s)    lwip_close(s)

Definition at line 57 of file ps2ip.h.

◆ connect

#define connect (   a,
  b,
 
)    lwip_connect(a,b,c)

Definition at line 58 of file ps2ip.h.

◆ disconenct

#define disconenct (   s)    lwip_close(s)

Definition at line 56 of file ps2ip.h.

◆ getpeername

#define getpeername (   a,
  b,
 
)    lwip_getpeername(a,b,c)

Definition at line 60 of file ps2ip.h.

◆ getsockname

#define getsockname (   a,
  b,
 
)    lwip_getsockname(a,b,c)

Definition at line 59 of file ps2ip.h.

◆ getsockopt

#define getsockopt (   a,
  b,
  c,
  d,
 
)    lwip_getsockopt(a,b,c,d,e)

Definition at line 62 of file ps2ip.h.

◆ I_netif_add

#define I_netif_add   DECLARE_IMPORT(26, netif_add)

Definition at line 101 of file ps2ip.h.

◆ inet_addr

#define inet_addr (   cp)    ipaddr_addr(cp)

Definition at line 81 of file ps2ip.h.

◆ inet_aton

#define inet_aton (   cp,
  addr 
)    ip4addr_aton(cp, (ip4_addr_t*)addr)

Definition at line 82 of file ps2ip.h.

◆ inet_ntoa

#define inet_ntoa (   addr)    ip4addr_ntoa((const ip4_addr_t*)&(addr))

Definition at line 83 of file ps2ip.h.

◆ inet_ntoa_r

#define inet_ntoa_r (   addr,
  buf,
  buflen 
)    ip4addr_ntoa_r((const ip4_addr_t*)&(addr), buf, buflen)

Definition at line 84 of file ps2ip.h.

◆ ioctlsocket

#define ioctlsocket (   a,
  b,
 
)    lwip_ioctl(a,b,c)

Definition at line 70 of file ps2ip.h.

◆ listen

#define listen (   a,
 
)    lwip_listen(a,b)

Definition at line 63 of file ps2ip.h.

◆ recv

#define recv (   a,
  b,
  c,
 
)    lwip_recv(a,b,c,d)

Definition at line 64 of file ps2ip.h.

◆ recvfrom

#define recvfrom (   a,
  b,
  c,
  d,
  e,
 
)    lwip_recvfrom(a,b,c,d,e,f)

Definition at line 65 of file ps2ip.h.

◆ select

#define select (   a,
  b,
  c,
  d,
 
)    lwip_select(a,b,c,d,e)

Definition at line 69 of file ps2ip.h.

◆ send

#define send (   a,
  b,
  c,
 
)    lwip_send(a,b,c,d)

Definition at line 66 of file ps2ip.h.

◆ sendto

#define sendto (   a,
  b,
  c,
  d,
  e,
 
)    lwip_sendto(a,b,c,d,e,f)

Definition at line 67 of file ps2ip.h.

◆ setsockopt

#define setsockopt (   a,
  b,
  c,
  d,
 
)    lwip_setsockopt(a,b,c,d,e)

Definition at line 61 of file ps2ip.h.

◆ shutdown

#define shutdown (   a,
 
)    lwip_shutdown(a,b)

Definition at line 55 of file ps2ip.h.

◆ socket

#define socket (   a,
  b,
 
)    lwip_socket(a,b,c)

Definition at line 68 of file ps2ip.h.

Function Documentation

◆ etharp_output()

err_t etharp_output ( struct netif netif,
struct pbuf q,
const ip_addr_t ipaddr 
)

Referenced by SMapIFInit().

◆ ip4addr_aton()

int ip4addr_aton ( const char *  cp,
ip4_addr_t *  addr 
)

◆ ip4addr_ntoa()

char* ip4addr_ntoa ( const ip4_addr_t *  addr)

returns ptr to static buffer; not reentrant!

◆ ip4addr_ntoa_r()

char* ip4addr_ntoa_r ( const ip4_addr_t *  addr,
char *  buf,
int  buflen 
)

◆ ipaddr_addr()

u32 ipaddr_addr ( const char *  cp)

◆ lwip_accept()

int lwip_accept ( int  s,
struct sockaddr addr,
socklen_t addrlen 
)

◆ lwip_bind()

int lwip_bind ( int  s,
const struct sockaddr name,
socklen_t  namelen 
)

◆ lwip_close()

int lwip_close ( int  s)

◆ lwip_connect()

int lwip_connect ( int  s,
const struct sockaddr name,
socklen_t  namelen 
)

◆ lwip_fcntl()

int lwip_fcntl ( int  s,
int  cmd,
int  val 
)

◆ lwip_getpeername()

int lwip_getpeername ( int  s,
struct sockaddr name,
socklen_t namelen 
)

◆ lwip_getsockname()

int lwip_getsockname ( int  s,
struct sockaddr name,
socklen_t namelen 
)

◆ lwip_getsockopt()

int lwip_getsockopt ( int  s,
int  level,
int  optname,
void *  optval,
socklen_t optlen 
)

◆ lwip_ioctl()

int lwip_ioctl ( int  s,
long  cmd,
void *  argp 
)

◆ lwip_listen()

int lwip_listen ( int  s,
int  backlog 
)

◆ lwip_read()

int lwip_read ( int  s,
void *  mem,
size_t  len 
)

◆ lwip_recv()

int lwip_recv ( int  s,
void *  mem,
size_t  len,
int  flags 
)

◆ lwip_recvfrom()

int lwip_recvfrom ( int  s,
void *  mem,
size_t  len,
int  flags,
struct sockaddr from,
socklen_t fromlen 
)

◆ lwip_select()

int lwip_select ( int  maxfdp1,
fd_set readset,
fd_set writeset,
fd_set exceptset,
struct timeval *  timeout 
)

◆ lwip_send()

int lwip_send ( int  s,
const void *  dataptr,
size_t  size,
int  flags 
)

◆ lwip_sendto()

int lwip_sendto ( int  s,
const void *  dataptr,
size_t  size,
int  flags,
const struct sockaddr to,
socklen_t  tolen 
)

◆ lwip_setsockopt()

int lwip_setsockopt ( int  s,
int  level,
int  optname,
const void *  optval,
socklen_t  optlen 
)

◆ lwip_shutdown()

int lwip_shutdown ( int  s,
int  how 
)

◆ lwip_socket()

int lwip_socket ( int  domain,
int  type,
int  protocol 
)

◆ lwip_write()

int lwip_write ( int  s,
const void *  dataptr,
size_t  size 
)

◆ netif_add()

struct netif* netif_add ( struct netif netif,
void *  state,
netif_init_fn  init,
netif_input_fn  input 
)

Referenced by ps2ipInit().

◆ netif_find()

struct netif* netif_find ( const char *  name)

Returns a network interface given its name. The name is of the form "et0", where the first two letters are the "name" field in the netif structure, and the digit is in the num field in the same structure.

Referenced by ps2ip_getconfig(), and ps2ip_setconfig().

◆ netif_set_default()

void netif_set_default ( struct netif netif)

Referenced by ps2ipInit().

◆ netif_set_down()

void netif_set_down ( struct netif netif)

◆ netif_set_gw()

void netif_set_gw ( struct netif netif,
const ip4_addr_t *  gw 
)

Referenced by ps2ip_setconfig().

◆ netif_set_ipaddr()

void netif_set_ipaddr ( struct netif netif,
const ip4_addr_t *  ipaddr 
)

Referenced by ps2ip_setconfig().

◆ netif_set_netmask()

void netif_set_netmask ( struct netif netif,
const ip4_addr_t *  netmask 
)

Referenced by ps2ip_setconfig().

◆ netif_set_up()

void netif_set_up ( struct netif netif)

Referenced by ps2ipInit().

◆ pbuf_alloc()

struct pbuf* pbuf_alloc ( pbuf_layer  l,
u16  size,
pbuf_type  type 
)

Referenced by AllocRxPacket().

◆ pbuf_chain()

void pbuf_chain ( struct pbuf h,
struct pbuf t 
)

◆ pbuf_clen()

u8 pbuf_clen ( struct pbuf p)

◆ pbuf_coalesce()

struct pbuf* pbuf_coalesce ( struct pbuf p,
pbuf_layer  layer 
)

Referenced by SMapLowLevelOutput().

◆ pbuf_dechain()

struct pbuf* pbuf_dechain ( struct pbuf p)

◆ pbuf_free()

u8 pbuf_free ( struct pbuf p)

◆ pbuf_header()

u8 pbuf_header ( struct pbuf p,
s16  header_size 
)

◆ pbuf_realloc()

void pbuf_realloc ( struct pbuf p,
u16  size 
)

Referenced by ReallocRxPacket().

◆ pbuf_ref()

void pbuf_ref ( struct pbuf p)

Referenced by SMapLowLevelOutput().

◆ pbuf_take()

struct pbuf* pbuf_take ( struct pbuf f)

◆ ps2ip_getconfig()

int ps2ip_getconfig ( char *  netif_name,
t_ip_info ip_info 
)

Definition at line 41 of file ps2ip.c.

42 {
43  NetIF* pNetIF=netif_find(pszName);
44 
45  if (pNetIF==NULL)
46  {
47  //Net interface not found.
48  memset(pInfo,0,sizeof(*pInfo));
49  return 0;
50  }
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;
55 
56  memcpy(pInfo->hw_addr,pNetIF->hwaddr,sizeof(pInfo->hw_addr));
57 
58 #if LWIP_DHCP
59  struct dhcp *dhcp = netif_dhcp_data(pNetIF);
60 
61  if ((dhcp != NULL) && (dhcp->state != DHCP_STATE_OFF))
62  {
63  pInfo->dhcp_enabled=1;
64  pInfo->dhcp_status=dhcp->state;
65  }
66  else
67  {
68  pInfo->dhcp_enabled=0;
69  pInfo->dhcp_status=DHCP_STATE_OFF;
70  }
71 
72 #else
73  pInfo->dhcp_enabled=0;
74 #endif
75 
76  return 1;
77 }
struct netif * netif_find(const char *name)
#define netif_dhcp_data(netif)
#define NULL
Definition: tamtypes.h:91
@ DHCP_STATE_OFF
Definition: tcpip.h:1260

References t_ip_info::dhcp_enabled, DHCP_STATE_OFF, t_ip_info::dhcp_status, t_ip_info::gw, t_ip_info::hw_addr, t_ip_info::ipaddr, netif_dhcp_data, netif_find(), t_ip_info::netif_name, t_ip_info::netmask, NULL, and in_addr::s_addr.

◆ ps2ip_input()

err_t ps2ip_input ( struct pbuf p,
struct netif inp 
)

◆ ps2ip_setconfig()

int ps2ip_setconfig ( const t_ip_info ip_info)

Definition at line 79 of file ps2ip.c.

80 {
81  NetIF* pNetIF=netif_find(pInfo->netif_name);
82 
83  if (pNetIF==NULL)
84  {
85  return 0;
86  }
87 
88 #if LWIP_DHCP
89  struct dhcp *dhcp = netif_dhcp_data(pNetIF);
90 
91  //Enable dhcp here
92 
93  if (pInfo->dhcp_enabled)
94  {
95  if ((dhcp == NULL) || (dhcp->state == DHCP_STATE_OFF))
96  {
97  //Set initial IP address
98  netif_set_ipaddr(pNetIF,(IPAddr*)&pInfo->ipaddr);
99  netif_set_netmask(pNetIF,(IPAddr*)&pInfo->netmask);
100  netif_set_gw(pNetIF,(IPAddr*)&pInfo->gw);
101 
102  //Start DHCP client
103  dhcp_start(pNetIF);
104  }
105  }
106  else
107  {
108  if ((dhcp != NULL) && (dhcp->state != DHCP_STATE_OFF))
109  {
110  //Release DHCP lease
111  dhcp_release(pNetIF);
112 
113  //Stop DHCP client
114  dhcp_stop(pNetIF);
115  }
116 
117  netif_set_ipaddr(pNetIF,(IPAddr*)&pInfo->ipaddr);
118  netif_set_netmask(pNetIF,(IPAddr*)&pInfo->netmask);
119  netif_set_gw(pNetIF,(IPAddr*)&pInfo->gw);
120  }
121 
122 #else
123  netif_set_ipaddr(pNetIF,(IPAddr*)&pInfo->ipaddr);
124  netif_set_netmask(pNetIF,(IPAddr*)&pInfo->netmask);
125  netif_set_gw(pNetIF,(IPAddr*)&pInfo->gw);
126 #endif
127 
128  return 1;
129 }
void netif_set_netmask(struct netif *netif, const ip4_addr_t *netmask)
void netif_set_ipaddr(struct netif *netif, const ip4_addr_t *ipaddr)
void netif_set_gw(struct netif *netif, const ip4_addr_t *gw)

References t_ip_info::dhcp_enabled, DHCP_STATE_OFF, t_ip_info::gw, t_ip_info::ipaddr, netif_dhcp_data, netif_find(), t_ip_info::netif_name, netif_set_gw(), netif_set_ipaddr(), netif_set_netmask(), t_ip_info::netmask, and NULL.

Referenced by ethApplyIPConfig().

◆ ps2ipDeinit()

void ps2ipDeinit ( void  )

Definition at line 342 of file ps2ip.c.

342  {
344 }
void NetManUnregisterNetworkStack(void)
Definition: netman.c:92

References NetManUnregisterNetworkStack().

Referenced by main().

◆ ps2ipInit()

int ps2ipInit ( struct ip4_addr ip_address,
struct ip4_addr subnet_mask,
struct ip4_addr gateway 
)

Initializes PS2IP. Specify a dummy address like "169.254.0.1" if DHCP is to be used, before enabling DHCP via ps2ip_setconfig().

Definition at line 316 of file ps2ip.c.

316  {
317  static struct NetManNetProtStack stack={
318  &LinkStateUp,
319  &LinkStateDown,
320  &AllocRxPacket,
321  &FreeRxPacket,
322  &EnQRxPacket,
323  &NextTxPacket,
324  &DeQTxPacket,
325  &AfterTxPacket,
327  };
328 
329  NetManInit();
330 
331  InitializeLWIP();
332 
333  netif_add(&NIF, ip_address, subnet_mask, gateway, NULL, &SMapIFInit, tcpip_input);
335 
337  netif_set_up(&NIF);
338 
339  return 0;
340 }
int NetManRegisterNetworkStack(const struct NetManNetProtStack *stack)
Definition: netman.c:70
int NetManInit(void)
Definition: netman.c:43
struct netif * netif_add(struct netif *netif, void *state, netif_init_fn init, netif_input_fn input)
void netif_set_default(struct netif *netif)
err_t tcpip_input(struct pbuf *p, struct netif *inp)
void netif_set_up(struct netif *netif)
static void FreeRxPacket(void *packet)
Definition: ps2ip.c:196
static void DeQTxPacket(void)
Definition: ps2ip.c:220
static struct netif NIF
Definition: ps2ip.c:36
static void LinkStateUp(void)
Definition: ps2ip.c:171
static void LinkStateDown(void)
Definition: ps2ip.c:176
static int AfterTxPacket(void **payload)
Definition: ps2ip.c:248
static void * AllocRxPacket(unsigned int size, void **payload)
Definition: ps2ip.c:181
static int NextTxPacket(void **payload)
Definition: ps2ip.c:206
static void InitializeLWIP(void)
Definition: ps2ip.c:300
static void EnQRxPacket(void *packet)
Definition: ps2ip.c:201
static void ReallocRxPacket(void *packet, unsigned int size)
Definition: ps2ip.c:191
static err_t SMapIFInit(struct netif *pNetIF)
Definition: ps2ip.c:269

References AfterTxPacket(), AllocRxPacket(), DeQTxPacket(), EnQRxPacket(), FreeRxPacket(), InitializeLWIP(), LinkStateDown(), LinkStateUp(), netif_add(), netif_set_default(), netif_set_up(), NetManInit(), NetManRegisterNetworkStack(), NextTxPacket(), NIF, NULL, ReallocRxPacket(), SMapIFInit(), and tcpip_input().

Referenced by main().

◆ ps2ipSetHsyncTicksPerMSec()

void ps2ipSetHsyncTicksPerMSec ( unsigned char  ticks)

Use to specify the number of H-sync ticks per milisecond (Default: 16). Use this function to keep timings accurate, if a mode like 480P (~31KHz H-sync) is used instead of NTSC/PAL (~16KHz H-sync).

Definition at line 346 of file ps2ip.c.

346  {
347  hsyncTicksPerMSec = ticks;
348 }
unsigned short int hsyncTicksPerMSec
Definition: ps2ip.c:39

References hsyncTicksPerMSec.

◆ tcpip_input()

err_t tcpip_input ( struct pbuf p,
struct netif inp 
)

Referenced by ps2ipInit().