OldSchool Library
Network

Network functions for managing WLAN, AP connection, and socket operations on the PSP. More...

Data Structures

struct  oslNetConfig
 Structure for network configuration. More...
 

Macros

#define OSL_MAX_NET_CONFIGS   20
 Maximum number of network configurations.
 
#define OSL_RESOLVER_RETRY   4
 Number of retry attempts for resolving an address.
 

Functions

int oslIsWlanPowerOn ()
 Checks if the WLAN switch is powered on.
 
int oslIsWlanConnected ()
 Checks if the WLAN is connected to an Access Point.
 
int oslGetNetConfigs (struct oslNetConfig *result)
 Gets the network configurations.
 
int oslIsNetActive ()
 Returns whether the network is initialized.
 
int oslNetInit ()
 Initializes the network.
 
int oslNetTerm ()
 Terminates the network.
 
int oslGetIPaddress (char *IPaddress)
 Gets the current IP address when connected to an Access Point.
 
int oslConnectToAP (int config, int timeout, int(*apctlCallback)(int state))
 Tries to connect to an Access Point using the given configuration.
 
int oslDisconnectFromAP ()
 Disconnects from the Access Point.
 
int oslGetAPState ()
 Gets the current Access Point state.
 
int oslResolveAddress (char *address, char *resolvedIP)
 Resolves an address to its IP address.
 
int oslNetGetFile (const char *url, const char *filepath)
 Gets a file from the web and saves it to the specified filepath.
 
int oslNetPostForm (const char *url, char *data, char *response, unsigned int responsesize)
 Posts a web form.
 
int oslNetSocketCreate (void)
 Creates a network socket.
 
int oslNetSocketAccept (int socket)
 Accepts a connection on a socket.
 
int oslNetSocketBind (int socket, unsigned short port)
 Binds a socket to a port.
 
int oslNetSocketListen (int socket, unsigned int maxconn)
 Listens for incoming connections on a socket.
 
int oslNetSocketConnect (int socket, char *ip, unsigned short port)
 Connects a socket to a remote host.
 
int oslNetSocketSend (int socket, const void *data, int length)
 Sends data over a socket.
 
int oslNetSocketReceive (int socket, void *data, int length)
 Receives data from a socket.
 
void oslNetSocketClose (int socket)
 Closes a socket.
 
void oslNetSocketSetClear (fd_set *set)
 Clears a socket set.
 
void oslNetSocketSetAdd (int socket, fd_set *set)
 Adds a socket to a socket set.
 
void oslNetSocketSetRemove (int socket, fd_set *set)
 Removes a socket from a socket set.
 
int oslNetSocketSetIsMember (int socket, fd_set *set)
 Checks if a socket is a member of a socket set.
 
int oslNetSocketSetSelect (unsigned int maxsockets, fd_set *set)
 Selects the ready sockets from a set of sockets.
 

APCTL States

APCTL states returned by oslGetAPState().

#define OSL_APCTL_STATE_DISCONNECTED   PSP_NET_APCTL_STATE_DISCONNECTED
 Disconnected state.
 
#define OSL_APCTL_STATE_SCANNING   PSP_NET_APCTL_STATE_SCANNING
 Scanning for access points.
 
#define OSL_APCTL_STATE_JOINING   PSP_NET_APCTL_STATE_JOINING
 Joining access point.
 
#define OSL_APCTL_STATE_GETTING_IP   PSP_NET_APCTL_STATE_GETTING_IP
 Getting IP address.
 
#define OSL_APCTL_STATE_GOT_IP   PSP_NET_APCTL_STATE_GOT_IP
 Successfully got IP address.
 
#define OSL_APCTL_STATE_EAP_AUTH   PSP_NET_APCTL_STATE_EAP_AUTH
 EAP authentication in progress.
 
#define OSL_APCTL_STATE_KEY_EXCHANGE   PSP_NET_APCTL_STATE_KEY_EXCHANGE
 Key exchange in progress.
 

Error Codes

Error codes returned by network functions.

#define OSL_NET_ERROR_NET   -1
 Generic network error.
 
#define OSL_NET_ERROR_INET   -2
 Internet error.
 
#define OSL_NET_ERROR_RESOLVER   -3
 Resolver error.
 
#define OSL_NET_ERROR_APCTL   -4
 APCTL error.
 
#define OSL_NET_ERROR_SSL   -5
 SSL error.
 
#define OSL_NET_ERROR_HTTP   -6
 HTTP error.
 
#define OSL_NET_ERROR_HTTPS   -7
 HTTPS error.
 
#define OSL_NET_ERROR_CERT   -8
 Certificate error.
 
#define OSL_NET_ERROR_COOKIE   -9
 Cookie error.
 
#define OSL_ERR_APCTL_GETINFO   -10
 Error getting APCTL info.
 
#define OSL_ERR_APCTL_CONNECT   -11
 Error connecting to APCTL.
 
#define OSL_ERR_APCTL_TIMEOUT   -12
 APCTL connection timeout.
 
#define OSL_ERR_APCTL_GETSTATE   -13
 Error getting APCTL state.
 
#define OSL_ERR_RESOLVER_CREATE   -14
 Error creating resolver.
 
#define OSL_ERR_RESOLVER_RESOLVING   -15
 Error resolving address.
 
#define OSL_ERR_WLAN_OFF   -16
 WLAN is turned off.
 
#define OSL_USER_ABORTED   -17
 Operation was aborted by the user.
 
#define OSL_ERR_HTTP_INIT   -18
 Error initializing HTTP.
 
#define OSL_ERR_HTTP_TEMPLATE   -19
 Error with HTTP template.
 
#define OSL_ERR_HTTP_TIMEOUT   -20
 HTTP connection timeout.
 
#define OSL_ERR_HTTP_CONNECT   -21
 Error connecting via HTTP.
 
#define OSL_ERR_HTTP_REQUEST   -22
 Error making HTTP request.
 
#define OSL_ERR_HTTP_GENERIC   -23
 Generic HTTP error.
 

Detailed Description

Network functions for managing WLAN, AP connection, and socket operations on the PSP.

Function Documentation

◆ oslIsWlanPowerOn()

int oslIsWlanPowerOn ( )

Checks if the WLAN switch is powered on.

Returns
1 if the WLAN is powered on, else 0.

◆ oslIsWlanConnected()

int oslIsWlanConnected ( )

Checks if the WLAN is connected to an Access Point.

Returns
1 if connected to an AP, else 0.

◆ oslGetNetConfigs()

int oslGetNetConfigs ( struct oslNetConfig * result)

Gets the network configurations.

Parameters
resultPointer to an array of oslNetConfig structures to be filled with the network configurations.
Returns
The number of network configurations found.

◆ oslIsNetActive()

int oslIsNetActive ( )

Returns whether the network is initialized.

Returns
1 if network is active, else 0.

◆ oslNetInit()

int oslNetInit ( )

Initializes the network.

Returns
0 on success, otherwise an error code.

◆ oslNetTerm()

int oslNetTerm ( )

Terminates the network.

Returns
0 on success, otherwise an error code.

◆ oslGetIPaddress()

int oslGetIPaddress ( char * IPaddress)

Gets the current IP address when connected to an Access Point.

Parameters
IPaddressPointer to a char array where the IP address will be stored.
Returns
0 on success, otherwise an error code.

◆ oslConnectToAP()

int oslConnectToAP ( int config,
int timeout,
int(* apctlCallback )(int state) )

Tries to connect to an Access Point using the given configuration.

Parameters
configIndex of the configuration to use.
timeoutTimeout (in seconds) for the connection.
apctlCallbackPointer to a callback function that will be called with the current state.
Returns
0 on success, otherwise an error code.

◆ oslDisconnectFromAP()

int oslDisconnectFromAP ( )

Disconnects from the Access Point.

Returns
0 on success, otherwise an error code.

◆ oslGetAPState()

int oslGetAPState ( )

Gets the current Access Point state.

Returns
The current AP state.

◆ oslResolveAddress()

int oslResolveAddress ( char * address,
char * resolvedIP )

Resolves an address to its IP address.

Parameters
addressThe address to resolve.
resolvedIPPointer to a char array where the resolved IP address will be stored.
Returns
0 on success, otherwise an error code.

◆ oslNetGetFile()

int oslNetGetFile ( const char * url,
const char * filepath )

Gets a file from the web and saves it to the specified filepath.

Parameters
urlThe URL of the file to download.
filepathThe path where the file should be saved.
Returns
0 on success, otherwise an error code.

◆ oslNetPostForm()

int oslNetPostForm ( const char * url,
char * data,
char * response,
unsigned int responsesize )

Posts a web form.

Parameters
urlThe URL to post the form to.
dataThe form data to be posted.
responsePointer to a char array where the server response will be stored.
responsesizeThe size of the response buffer.
Returns
0 on success, otherwise an error code.

◆ oslNetSocketCreate()

int oslNetSocketCreate ( void )

Creates a network socket.

Returns
The socket descriptor on success, otherwise an error code.

◆ oslNetSocketAccept()

int oslNetSocketAccept ( int socket)

Accepts a connection on a socket.

Parameters
socketThe socket descriptor.
Returns
The descriptor of the accepted socket, otherwise an error code.

◆ oslNetSocketBind()

int oslNetSocketBind ( int socket,
unsigned short port )

Binds a socket to a port.

Parameters
socketThe socket descriptor.
portThe port number to bind the socket to.
Returns
0 on success, otherwise an error code.

◆ oslNetSocketListen()

int oslNetSocketListen ( int socket,
unsigned int maxconn )

Listens for incoming connections on a socket.

Parameters
socketThe socket descriptor.
maxconnThe maximum number of connections to listen for.
Returns
0 on success, otherwise an error code.

◆ oslNetSocketConnect()

int oslNetSocketConnect ( int socket,
char * ip,
unsigned short port )

Connects a socket to a remote host.

Parameters
socketThe socket descriptor.
ipThe IP address of the remote host.
portThe port number of the remote host.
Returns
0 on success, otherwise an error code.

◆ oslNetSocketSend()

int oslNetSocketSend ( int socket,
const void * data,
int length )

Sends data over a socket.

Parameters
socketThe socket descriptor.
dataThe data to be sent.
lengthThe length of the data to be sent.
Returns
The number of bytes sent, otherwise an error code.

◆ oslNetSocketReceive()

int oslNetSocketReceive ( int socket,
void * data,
int length )

Receives data from a socket.

Parameters
socketThe socket descriptor.
dataThe buffer to store the received data.
lengthThe length of the buffer.
Returns
The number of bytes received, otherwise an error code.

◆ oslNetSocketClose()

void oslNetSocketClose ( int socket)

Closes a socket.

Parameters
socketThe socket descriptor.

◆ oslNetSocketSetClear()

void oslNetSocketSetClear ( fd_set * set)

Clears a socket set.

Parameters
setThe socket set to be cleared.

◆ oslNetSocketSetAdd()

void oslNetSocketSetAdd ( int socket,
fd_set * set )

Adds a socket to a socket set.

Parameters
socketThe socket descriptor.
setThe socket set to add the socket to.

◆ oslNetSocketSetRemove()

void oslNetSocketSetRemove ( int socket,
fd_set * set )

Removes a socket from a socket set.

Parameters
socketThe socket descriptor.
setThe socket set to remove the socket from.

◆ oslNetSocketSetIsMember()

int oslNetSocketSetIsMember ( int socket,
fd_set * set )

Checks if a socket is a member of a socket set.

Parameters
socketThe socket descriptor.
setThe socket set to check.
Returns
1 if the socket is a member, else 0.

◆ oslNetSocketSetSelect()

int oslNetSocketSetSelect ( unsigned int maxsockets,
fd_set * set )

Selects the ready sockets from a set of sockets.

Parameters
maxsocketsThe maximum number of sockets.
setThe socket set to select from.
Returns
The number of ready sockets, otherwise an error code.