Basilisk II PSP Port (Mac Emulator)
That would be cool. :)Wally wrote:Well I think its time I started making a 5MB Shareware / Freeware pack for Basilisk PSP
No problem.Gaby_64 wrote:I hav done research on the forum about raw sockets but none of theme show concrete statements of why sockets dont work or even any example of codes that people have tried.
Mind posting what you have tried?
main.c
Code: Select all
#include <pspsdk.h>
#include <pspkernel.h>
#include <pspctrl.h>
#include <pspdebug.h>
#include <psppower.h>
#include <pspdisplay.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pspsdk.h>
#include <psputility_netmodules.h>
#include <psputility_netparam.h>
#include <pspwlan.h>
#include <pspnet.h>
#include <pspnet_apctl.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <sys/fcntl.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <unistd.h>
#include <netdb.h>
#define printf pspDebugScreenPrintf
#define VERS 1
#define REVS 0
PSP_MODULE_INFO("RawSockets", 0, VERS, REVS);
PSP_MAIN_THREAD_ATTR(PSP_THREAD_ATTR_USER);
int psp_net_error = 0;
int psp_net_available = 0;
char szMyIPAddr[32];
char *psp_local_ip_addr = NULL; // String: the local IP address for the PSP
int my_socket;
int kill_thread = 0;
int got_packet = 0;
/*
* Network support code
*/
static int connect_to_apctl(int config) {
int err, i;
int stateLast = -1;
pspDebugScreenClear();
if (sceWlanGetSwitchState() != 1)
pspDebugScreenPrintf("Please enable WLAN or press a button to procede without networking.\n");
for (i=0; i<10; i++)
{
SceCtrlData pad;
if (sceWlanGetSwitchState() == 1)
break;
sceCtrlReadBufferPositive(&pad, 1);
if (pad.Buttons)
return 0;
pspDebugScreenPrintf("%d... ", 10-i);
sceKernelDelayThread(1000*1000);
}
printf("\n");
if (i == 10)
return 0;
sceNetApctlDisconnect();
err = sceNetApctlConnect(config);
if (err != 0) {
pspDebugScreenPrintf("sceNetApctlConnect returns %08X\n", err);
return 0;
}
pspDebugScreenPrintf("Connecting...\n");
// loop end: 600 = 30 sec, 900 = 45 sec
for (i=0; i<900; i++) {
int state;
err = sceNetApctlGetState(&state);
if (err != 0) {
pspDebugScreenPrintf("sceNetApctlGetState returns $%x\n", err);
break;
}
if (state != stateLast) {
pspDebugScreenPrintf(" Connection state %d of 4.\n", state);
stateLast = state;
}
if (state == 4) {
break;
}
sceKernelDelayThread(50 * 1000);
}
if (i == 900 || err !=0)
return 0;
pspDebugScreenPrintf("Connected!\n");
sceKernelDelayThread(3*1000*1000);
return 1;
}
static int net_thread(SceSize args, void *argp)
{
int selComponent = 1; // access point selector
pspDebugScreenPrintf("Using connection %d to connect...\n", selComponent);
while (psp_net_available != 1)
{
if (connect_to_apctl(selComponent))
{
if (sceNetApctlGetInfo(8, szMyIPAddr) != 0)
strcpy(szMyIPAddr, "unknown IP address");
pspDebugScreenPrintf("IP: %s\n", szMyIPAddr);
psp_net_available = 1;
}
else
{
int i;
pspDebugScreenPrintf("\n\n Couldn't connect to access point.\n Press any key to try again.\n");
for (i=0; i<10; i++)
{
SceCtrlData pad;
sceCtrlReadBufferPositive(&pad, 1);
if (pad.Buttons)
break;
pspDebugScreenPrintf("%d... ", 10-i);
sceKernelDelayThread(1000*1000);
}
pspDebugScreenPrintf("\n");
if (i == 10)
{
psp_net_available = -1;
return 0;
}
}
}
return 0;
}
static void psp_net_connect (void)
{
SceUID thid;
thid = sceKernelCreateThread("net_thread", net_thread, 0x18, 0x10000, PSP_THREAD_ATTR_USER, NULL);
if (thid < 0) {
pspDebugScreenPrintf("Could not create network thread!\n");
pspDebugScreenPrintf("\n");
sceKernelDelayThread(4*1000*1000);
return;
}
sceKernelStartThread(thid, 0, NULL);
while (1)
{
if (psp_net_available)
break;
sceKernelDelayThread(1000*1000);
}
if (psp_net_available != 1)
{
pspDebugScreenPrintf("Could not connect to access point!\n");
pspDebugScreenPrintf("\n");
sceKernelDelayThread(4*1000*1000);
return;
}
else
psp_local_ip_addr = strdup(szMyIPAddr);
pspDebugScreenPrintf("Networking successfully started.\n");
sceKernelDelayThread(4*1000*1000);
}
static int InitialiseNetwork(void)
{
int err;
pspDebugScreenPrintf("load network modules...");
err = sceUtilityLoadNetModule(PSP_NET_MODULE_COMMON);
if (err != 0)
{
pspDebugScreenPrintf("Error, could not load PSP_NET_MODULE_COMMON %08X\n", err);
return 1;
}
err = sceUtilityLoadNetModule(PSP_NET_MODULE_INET);
if (err != 0)
{
pspDebugScreenPrintf("Error, could not load PSP_NET_MODULE_INET %08X\n", err);
return 1;
}
printf("done\n");
err = pspSdkInetInit();
if (err != 0)
{
pspDebugScreenPrintf("Error, could not initialise the network %08X\n", err);
return 1;
}
return 0;
}
static void psp_net_init(void)
{
if (InitialiseNetwork() != 0)
{
psp_net_error = 1;
pspDebugScreenPrintf("Networking not available.\n");
sceKernelDelayThread(4*1000*1000);
return;
}
}
/*
* Packet reception thread
*/
static int receive_proc(SceSize args, void *argp)
{
int fd = my_socket;
while (!kill_thread)
{
fd_set readfds;
FD_ZERO(&readfds);
FD_SET(fd, &readfds);
struct timeval timeout;
timeout.tv_sec = 1;
timeout.tv_usec = 0;
if (select(fd+1, &readfds, NULL, NULL, &timeout) > 0)
if (FD_ISSET(fd, &readfds))
{
printf(" Packet received\n");
got_packet = 1;
while (got_packet)
sceKernelDelayThread(100*1000);
}
}
sceKernelExitDeleteThread(0);
return 0;
}
/*
* Start packet reception thread
*/
int ether_start_pkt_thread(void)
{
SceUID read_thread = sceKernelCreateThread("Packet Receiver", receive_proc, 0x14, 0x1800, PSP_THREAD_ATTR_USER, NULL);
if(read_thread < 0)
return 0;
sceKernelStartThread(read_thread, 0, NULL);
return 1;
}
int main(void)
{
int on = 1;
ssize_t length;
struct sockaddr_in from;
socklen_t from_len = sizeof(from);
char packet[8192];
SceCtrlData pad;
pspDebugScreenInit();
pspDebugScreenSetBackColor(0xff000000);
pspDebugScreenSetTextColor(0xffffffff);
pspDebugScreenClear();
sceCtrlSetSamplingCycle(0);
sceCtrlSetSamplingMode(PSP_CTRL_MODE_DIGITAL);
psp_net_init();
if (!psp_net_error)
{
psp_net_connect();
if (psp_net_available)
{
int fd = socket (PF_INET, SOCK_RAW, IPPROTO_RAW);
if (fd < 0)
printf ("Couldn't open socket!\n");
else
{
my_socket = fd;
setsockopt(fd, SOL_SOCKET, SO_NONBLOCK, &on, sizeof(on));
if (ether_start_pkt_thread())
{
while (1)
{
while (!got_packet)
{
sceKernelDelayThread(100*1000);
sceCtrlReadBufferPositive(&pad, 1);
if (pad.Buttons & PSP_CTRL_CIRCLE)
break;
}
length = recvfrom(fd, packet, 1514, 0, (struct sockaddr *)&from, &from_len);
if (length >= 14)
{
printf("%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
packet[0], packet[1], packet[2], packet[3], packet[4], packet[5],
packet[6], packet[7], packet[8], packet[9], packet[10], packet[11],
packet[12], packet[13]);
}
else
printf("Packet length (%d) too small.\n", length);
got_packet = 0;
sceCtrlReadBufferPositive(&pad, 1);
if (pad.Buttons & PSP_CTRL_CIRCLE)
break;
}
kill_thread = 1;
sceKernelDelayThread(100*1000);
}
else
printf("Couldn't start packet receiver!\n");
}
}
}
sceKernelDelayThread(3*1000*1000);
sceKernelExitGame();
return 0; /* never reaches here, again, just to suppress warning */
}
Code: Select all
TARGET = RawSockets
OBJS = main.o
INCDIR =
CFLAGS = -O2 -G0 -Wall
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
BUILD_PRX = 1
PSP_FW_VERSION = 371
LIBDIR =
LIBS = -lpspwlan
LDFLAGS =
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = Raw Sockets Test
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.mak
I'd run the above code and try to ping the PSP from my computer. Using normal packets would allow me to see the packets (not raw). Using raw sockets, I'd get absolutely nothing.
- dennis96411
- Posts: 70
- Joined: Sun Jul 06, 2008 4:59 am
Yeah, plain sockets with regular connectivity. If you want that in B2, you could write a special version of FireFox (or whatever) that used a special command to use the PSP sockets to communicate. That's UPPER LEVEL networking. OSes provide the LOWER LEVEL. In the case of the PSP, that's Sony's socket code and libs. In the Mac, that's MacOS. MacOS deals with packets at a level lower than regular sockets. So does Windows, or Amiga TCP, or any OS. The OS handles the low level while the applications use the high level. If you're emulating an OS, you're stuck trying to figure out how to handle that low level when all you have is the higher levels. That's where raw sockets come in - it gives applications the ability to dip down into those low levels and do things they otherwise couldn't.dennis96411 wrote:Doesn't PSPKVM use sockets for internet connectivity?
when pinging the psp with the pc should I be seing anything on the psp happen?
On the comp it says it recved them but theres nothing that prints on the psp
and what does it recv from?
length = recvfrom(sock, RecvBuf, 1514, 0, (struct sockaddr *)&from, &from_len);
On the comp it says it recved them but theres nothing that prints on the psp
and what does it recv from?
length = recvfrom(sock, RecvBuf, 1514, 0, (struct sockaddr *)&from, &from_len);
Last edited by Gaby_64 on Thu Mar 19, 2009 6:32 am, edited 1 time in total.
<a><img></a>
Exactly. If it were working, you'd see prints about the packets. Raw sockets just doesn't seem available... at least not to user-mode apps. I haven't tried that same thing in kernel-mode yet. The computer saying the PSP received them shows the AP is connected and the networking properly initialized - so the PSP is getting the packets... but the user app isn't. The example is a pretty standard rawsockets example from the PC for simply dumping info about all the packets that come in.Gaby_64 wrote:when pinging the psp with the pc should I be seing anything on the psp happen?
On the comp it says it recved them but theres nothing that prints on the psp
Why is it that when I try to set it to nonblock in my app it says 109(ENOPROTOOPT)
EDIT1:
I dont think it works in kernel mode, it fails to initialize the network and freezes when trying to create a socket
EDIT2:
and the psp doesnt display anything because recvfrom fails
Error = ffffffff, -1
and from is not defined? Should that be the routers IP?
recvfrom(sock, RecvBuf, 1514, 0, (struct sockaddr *)&from, &from_len);
EDIT3:
found my answer here and some interesting info
http://msdn.microsoft.com/en-us/library ... S.85).aspx
also why do you put +1
select(sock+1, &readfd, NULL, NULL, &timeout)
EDIT4:
the sceNetInetRecvfrom function freezeson psp (I wanted to use it to be able to get the error number, is there a way to get error number from the non sce functions?)
sorry for all the questions butI still believe it is possible
EDIT5:
here is a screenshot of what I got so far:
as you can see recvfrom fails, EBADF, /* Bad file number */
but what does that mean?
EDIT6:
tested with sock_stream and sock_dgram and recvfrom returns the same results
so this could only be a problem with recvfrom and not that raw_sockets are not posible on psp
EDIT1:
I dont think it works in kernel mode, it fails to initialize the network and freezes when trying to create a socket
EDIT2:
and the psp doesnt display anything because recvfrom fails
Error = ffffffff, -1
and from is not defined? Should that be the routers IP?
recvfrom(sock, RecvBuf, 1514, 0, (struct sockaddr *)&from, &from_len);
EDIT3:
found my answer here and some interesting info
http://msdn.microsoft.com/en-us/library ... S.85).aspx
also why do you put +1
select(sock+1, &readfd, NULL, NULL, &timeout)
EDIT4:
the sceNetInetRecvfrom function freezeson psp (I wanted to use it to be able to get the error number, is there a way to get error number from the non sce functions?)
sorry for all the questions butI still believe it is possible
EDIT5:
here is a screenshot of what I got so far:
as you can see recvfrom fails, EBADF, /* Bad file number */
but what does that mean?
EDIT6:
tested with sock_stream and sock_dgram and recvfrom returns the same results
so this could only be a problem with recvfrom and not that raw_sockets are not posible on psp
<a><img></a>
Like I said, I haven't tried kernel mode. You may have to change the init around as the current init is using user functions, not kernel functions.Gaby_64 wrote:Why is it that when I try to set it to nonblock in my app it says 109(ENOPROTOOPT)
EDIT1:
I dont think it works in kernel mode, it fails to initialize the network and freezes when trying to create a socket
Most calls to recvfrom will fail... because there's no packet waiting. When a packet has been received, the function won't fail and will fill in the from field to let you know who it was from.EDIT2:
and the psp doesnt display anything because recvfrom fails
Error = ffffffff, -1
and from is not defined? Should that be the routers IP?
recvfrom(sock, RecvBuf, 1514, 0, (struct sockaddr *)&from, &from_len);
You don't seem to know how to use sockets... I suggest you read a few pages and try a few examples on the PC before trying to move to the PSP.EDIT3:
found my answer here and some interesting info
http://msdn.microsoft.com/en-us/library ... S.85).aspx
also why do you put +1
select(sock+1, &readfd, NULL, NULL, &timeout)
No idea. I just use regular stuff others already have done in other PSP apps. I don't/haven't done any research into PSP networking.EDIT4:
the sceNetInetRecvfrom function freezeson psp (I wanted to use it to be able to get the error number, is there a way to get error number from the non sce functions?)
Take this out of the B2 thread. You're cluttering it with unrelated posts.
The bad file error is probably because you're not handling the select right and passing a bad fd to the recvfrom. I probably won't answer anymore posts on this. You need to do more work yourself. We all have stuff we're working on and can't hold your hand on every single step. If I were going to do EVERYTHING, I'd already be doing it.
As to errors, perhaps things have changed slightly in the firmware since I last ran the code... I was on something like 3.90 or something. The behavior may have changed, and no, I'm not going to look into it.
The bad file error is probably because you're not handling the select right and passing a bad fd to the recvfrom. I probably won't answer anymore posts on this. You need to do more work yourself. We all have stuff we're working on and can't hold your hand on every single step. If I were going to do EVERYTHING, I'd already be doing it.
As to errors, perhaps things have changed slightly in the firmware since I last ran the code... I was on something like 3.90 or something. The behavior may have changed, and no, I'm not going to look into it.
What is the differrence between a router and an ethernet hub? I thought they were the same thing- I have an ethernet hub-can i successfully plug in two computers and have internet access with both? Or do I need a router or what?
___________
affiliateelite ~ affiliateelite.com ~ adgooroo ~ adgooroo.com
___________
affiliateelite ~ affiliateelite.com ~ adgooroo ~ adgooroo.com
Last edited by daniela on Thu Aug 20, 2009 5:46 pm, edited 1 time in total.
A hub and a router are not the same thing - a hub is a simple box that merely connects multiple ethernet sources. A router is a smart device, usually a full computer running linux or some other OS, whose task is to connect to modem, provide NAT, and often a firewall, among other things. A hub can connect multiple computers together as long as the computers do all the work themselves. A router can connect multiple computers to a single modem so that all can get on the net without having to do anything special.daniela wrote:What is the differrence between a router and an ethernet hub? I thought they were the same thing- I have an ethernet hub-can i successfully plug in two computers and have internet access with both? Or do I need a router or what?
-
- Posts: 11
- Joined: Wed Apr 23, 2008 11:44 am
Add network support...
Add network support...
maybe using udp tunneling like CIPE, OpenVPN or other protocol that suport tunneling and bridging.
maybe using udp tunneling like CIPE, OpenVPN or other protocol that suport tunneling and bridging.
Re: Add network support...
It's got UDP tunneling... for AppleTalk networking. You'd need a special server app on a PC to provide internet via UDP tunneling, and I haven't the gumption to put that much work into it.Visigotico wrote:Add network support...
maybe using udp tunneling like CIPE, OpenVPN or other protocol that suport tunneling and bridging.