Some sceNet / sceHttpInit usage questions

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Mr_Bogus
Posts: 3
Joined: Sat Apr 09, 2005 6:54 am
Location: Stockholm

Post by Mr_Bogus »

I have managed to get ifhandle.prx loaded and started from ms without any errors.
But when i try to load and start pspnet.prx after that i get 80020148 error.

All prx are extraced from the same game that i own.

Anyone that knows what may be the problem?
PspPet
Posts: 210
Joined: Wed Mar 30, 2005 2:13 am
Contact:

Post by PspPet »

TRF-Yu-Ki wrote:
> So PspPet patched the entry points himself; before that patch... calling sceNetInit() would put the Instruction-pointer where? I guess since he got it working, what I'm saying now is pointless. But, I'm just curious how a call to a non-existant routine wouldn't crash.

Still a good question. The STUBs are 8 byte routines (room for 2 mips opcodes). When not resident they are a "SWI" (software interrupt system trap) followed by NOP. If you call them and they are not resident you get that error code.
For regular entries there is a different SWI to switch to kernel mode to do "ForUser" entries. My patch hack replaces them with direct "j" jump instructions (user to user space)

In theory the not resident SWI *should* check first and patch them itself - but that's not working as expected (or something else is confusing the system)

-----
Mr_Bogus wrote:
> I have managed to get ifhandle.prx loaded and started from ms without any errors.
> But when i try to load and start pspnet.prx after that i get 80020148 error.
> All prx are extraced from the same game that i own.

I hit the same problem:
"ifhandle.prx" is encrypted and therefore loads. "pspnet.prx" is not encrypted ("ELF") and won't load.
[[If you think about it, it would be a bad thing, for Sony, for the system to load unencrypted prxs from memory stick ]]

Loading from "flash0:/kd/" works (all are encrypted), more legal, and they do have all the core libraries.

=====
re: Patch tricks and socket sample app
I'll clean up the current slimey trick and make it 1.0/1.50 aware and post it sometime soon.
After you get past the load/init hassles, the sceNetInet library is almost identical to standard Berkeley style sockets. Very easy to write simple and relatively standard socket based apps (eg: telnet to your PSP, UDP, roll your own HTTP, ...). Separate there is the HTTP helper library which is a PSP unique feature (haven't looked at that yet)
LiquidIce
Posts: 55
Joined: Mon Apr 04, 2005 1:15 am
Contact:

Post by LiquidIce »

That is great news PspPet! Thanks for all of the info and tips. I'm looking forward to playing around with the code you wrote, as well as exploring other PRX files, now that you've discovered how to load them correctly.

Just to get people thinking on the possibilities this has... here are a few ideas:

-Adding netcode to games to make them multiplayer
-Adding 2 player network mode to the emulators
-Video/Audio/Game Download Applications
-EBoot Auto-Updater (dangerous, i know...)
-Integration with Web Services - SNMP Management
-Control and monitoring of other electronic devices (-PSP Home Control 2.0!!! (may require additional hardware))
-PVR Remote Scheduling
-PSP Web Browser (possibly porting over lynx, or pocket mozilla)
-Email App
-RSS Reader
-Video Confrencing / Video Chat (If Sony ever releases a camera, or if we can hack our own to use the USB port - still months away, i know)
-Skype / VOIP
-Net Stumbler - Wifi access point finder / strength tester (dubayou has been working on this for months... where is the eboot?? lol)

Cheers!
PspPet
Posts: 210
Joined: Wed Mar 30, 2005 2:13 am
Contact:

Post by PspPet »

> re: Patch tricks and socket sample app
> I'll clean up the current slimey trick and make it 1.0/1.50 aware and post it sometime soon.

http://aibohack.com/psp/wifi_sample_001.zip

Very primitive, very lame telnetd-like test app.
Based on nem's HelloWorld app structure (not using any "sdk", extra fluff stripped out). Works on 1.0 or 1.50.
[built with ooPo's psptoolchain under Cygwin but others should work]

Lots of work to flesh out, but doesn't make sense until there is a more stable SDK (and added in a standard "socket.h" format)
Should help if you need to dive into WiFi features right now.
----
Read the README.TXT file. The app start up, connects to the *only* Infrastructure connection [if it stops at "00000003", then turn off DHCP].
Then you can telnet to the PSP from your PC. The PSP will show what you type.

Not meant to be a full example (and certainly not a real telnetd server). Good for illustrating the PRX load tricks, patching tricks and general LAN initialization for Infrastructure mode (Access points). Go crazy.
NOTE: if you want to merge code to your own program, look for "SLIME NOTE" comments. All the network library glue and patching is in "nlh.c"
KaL
Posts: 41
Joined: Sun Apr 03, 2005 9:59 pm

Post by KaL »

Can ping. Not telnet. I probably did something wrong. (I'm running on 1.5 , "infrastructure" mode, on a static IP.)

It's funny to notice that when the console is on stand-by, the ping does not respond :)
jimparis
Posts: 1145
Joined: Fri Jun 10, 2005 4:21 am
Location: Boston

Post by jimparis »

PspPet wrote: Very primitive, very lame telnetd-like test app.
Impressive! I can telnet and it displays what I type. Works great here (1.5).
PspPet wrote: if it stops at "00000003", then turn off DHCP
It also stops at 00000003 if you leave the SSID blank. I had to explicitly set my SSID for it to work.
Last edited by jimparis on Wed Jun 29, 2005 5:17 am, edited 1 time in total.
Hippo
Posts: 19
Joined: Sat Jun 25, 2005 10:51 am

Post by Hippo »

Haha, awesome. I just had a friend of mine connect to it, and he's... well, he's far away. Most excellent!
woehrl
Posts: 2
Joined: Wed Jun 29, 2005 5:37 am

Post by woehrl »

this is absolutly awesome, but i don't really know how the programm knows which settings it should use
and the refreshing on the PSP takes sometimes up to minutes, but it's absoluteley great for this state!
PspPet
Posts: 210
Joined: Wed Mar 30, 2005 2:13 am
Contact:

Post by PspPet »

I haven't figured out all the configuration enumeration code (mostly from Wipeout, which has a real UI to pick the configuration).

Right now it should work if you have one configuration, setup using explicit SSID and IP address.

> refreshing on the PSP takes sometimes up to minutes,
I think that's because of the send buffering (TCP/IP). If you close the connection it will flush it immediately (and exit the PSP app).
LiquidIce
Posts: 55
Joined: Mon Apr 04, 2005 1:15 am
Contact:

Post by LiquidIce »

PspPet, you are the man!! Thanks for making the seemingly impossible, a reality. Your efforts are greatly appreciated and good things are to come of your hard work. Thanks again!

BTW, I can't wait to see THIS in action...

#ifdef TEST_AIBO
TestAiboPoll(szMyIPAddr);
#endif

Make sure you get some good video. :-)
tourettes
Posts: 1
Joined: Wed Jun 29, 2005 1:33 pm

Post by tourettes »

help!!

like i put the wifi test files on my psp, and started the app, and then on my psp I get this message

Connecting
00000000

I cant do anything after this, nothing gets me out of this, not even turning this off or taking the memory card out. How to get this problem fixed?
User avatar
sq377
Posts: 87
Joined: Mon Apr 11, 2005 3:30 am

Post by sq377 »

pull out the battery, and the memory stick. Put back in the battery after a few seconds, then try turning it back on.
User avatar
Shazz
Posts: 244
Joined: Tue Aug 31, 2004 11:42 pm
Location: Somewhere over the rainbow
Contact:

Post by Shazz »

Hum hum, what about a ps2link-like server on the psp ??? :D

I definitively need to buy a wifi router, a shame wifi adhoc connections don't work...

By the way, great work PspPet :D
- TiTAN Art Division -
http://www.titandemo.org
PspPet
Posts: 210
Joined: Wed Mar 30, 2005 2:13 am
Contact:

Post by PspPet »

re: AIBO
Still working on the AIBO stuff (connection timeout problems right now).

Re: connection woes
If you see "Connecting 00000000 " and it never increases, then the connection is failing very early on. Is the WiFi light turning on?

Check your Infrastructure connection, and test it. If the access point can't be found it will stay at "Connecting 00000000 "

As mentioned pop the battery when done or if you have a problem (I stripped the standard exit code from the sample to make it as focused as possible). Shouldn't need to remove the memory stick.

> a shame wifi adhoc connections don't work...
The adhoc initialization is different. In the game uses it is used for game sharing/interplay.
Don't know if an adhoc connection to a PC will work if you have the IP addresses all set manually (need to try that)
Cool Matty
Posts: 7
Joined: Thu Jun 30, 2005 12:23 am

Post by Cool Matty »

Using telnet at the moment, would it be possible to have a "computer monitoring" setup?

Like, lets say I set up a cron job to telnet the PSP new data every minute. Would that work?

Hmm, after reading again, it looks like it might not. Would it be possible to set up the PSP to receive information from telnet as usual, but refresh the information upon each connection, instead of closing the program? (Then press a button to close the program instead, or use the home button)
Nick Fury
Posts: 45
Joined: Wed Jun 22, 2005 12:14 pm

Post by Nick Fury »

Cool Matty wrote:Using telnet at the moment, would it be possible to have a "computer monitoring" setup?

Like, lets say I set up a cron job to telnet the PSP new data every minute. Would that work?

Hmm, after reading again, it looks like it might not. Would it be possible to set up the PSP to receive information from telnet as usual, but refresh the information upon each connection, instead of closing the program? (Then press a button to close the program instead, or use the home button)
While your ideas are nifty I think you are missing the point of the program. The point being to demonstrate that networking (psppet can correct me if I'm wrong about this, I dont know what the hell he/she is thinking) is more than possible on this device. It's meant to be more of a proof of concept than a standalone app. Use the source and start coding out your very own system monitor.
Squall333
Posts: 91
Joined: Thu Apr 28, 2005 5:32 am

Post by Squall333 »

Since its possible to telnet to your computer is it possible for 2 psp's to connect to each other and type back and forth?
Cool Matty
Posts: 7
Joined: Thu Jun 30, 2005 12:23 am

Post by Cool Matty »

Nick Fury wrote:
Cool Matty wrote:Using telnet at the moment, would it be possible to have a "computer monitoring" setup?

Like, lets say I set up a cron job to telnet the PSP new data every minute. Would that work?

Hmm, after reading again, it looks like it might not. Would it be possible to set up the PSP to receive information from telnet as usual, but refresh the information upon each connection, instead of closing the program? (Then press a button to close the program instead, or use the home button)
While your ideas are nifty I think you are missing the point of the program. The point being to demonstrate that networking (psppet can correct me if I'm wrong about this, I dont know what the hell he/she is thinking) is more than possible on this device. It's meant to be more of a proof of concept than a standalone app. Use the source and start coding out your very own system monitor.
I understand the point of it. It just seems like a simple modification of the source to get it to stay open until you use home.

Unfortunately, as simple as it is, I make no claim to my knowledge of C programming. (Which is slim to none) The furthest I ever got in C was your standard Hello World and arrays. I moved on to PHP, which was much simpler, and fit my purposes.

If it's too much trouble, that's fine, it was just a simple request, something would make this "proof of concept" program actually useful, besides just cool.
Vini
Posts: 12
Joined: Wed May 18, 2005 3:36 am

Post by Vini »

How do you turn DHCP off?
etx
Posts: 33
Joined: Sat Apr 02, 2005 12:54 am
Location: Detroit

Post by etx »

Vini wrote:How do you turn DHCP off?
Manually configure your network settings.
KaL
Posts: 41
Joined: Sun Apr 03, 2005 9:59 pm

Post by KaL »

What about adding psppet's work into pspsdk ?
Squall333
Posts: 91
Joined: Thu Apr 28, 2005 5:32 am

Post by Squall333 »

This is probably a stuid question but i hope someone can help. Is the code for this as short as it could be im only asking because i see the aibo stuff on the bottom. I want to learn how to write a simple program like this and am wondering how hard is this really?
PspPet
Posts: 210
Joined: Wed Mar 30, 2005 2:13 am
Contact:

Post by PspPet »

[selective replies]
> Using telnet at the moment, would it be possible to have a "computer monitoring" setup?
As mentioned many things are possible. All will require a little C programming and familiarity with Berkeley sockets (/WinSock)
At this point it is a developer sample code program. A fuller more useful app may come later, or others may want to write one. If you want to dive into PSP programming, start with the PSPSDK and write something simple. If you want to dive into sockets programming, you can do that on your PC.

There are other similar PSP as a display server possibilities. For example being able to send a JPG from your PC to the PSP which shows it on the screen -- a simple wireless "picture frame". Another scenario - transmit the camera image from a Sony CLIE PDA to the PSP. Many things are possible.
----
> Since its possible to telnet to your computer is it possible for 2 psp's to connect to each other and type back and forth?
Yes - but "typing" on the PSP is tedious ;->
Many regular Wireless client apps are less interesting on the PSP since it lacks a keyboard or a touch screen. Better if you don't need elaborate input on the PSP (like the scenarios mentioned above)
----
> What about adding psppet's work into pspsdk ?
Eventually I'll move my sample app over to the pspsdk format. Requires similar STUB table tricks.
----
> Is the code for this as short as it could be
Close to it (the important parts of 'main.c' are very short). There are a few diagnostic features in it, but most has been stripped out for the release to focus on the test scenario

> im only asking because i see the aibo stuff on the bottom. I want to learn how to write a simple program like this and am wondering how hard is this really?
re: AIBO
If interested in AIBO programming, there are other resources. See the main AIBO part of my site (http://aibohack.com) or other AIBO centric BBS (eg: http://www.aibo-life.org). AiboCam/AiboRemote programs are already running on a number of platforms (including Palm PDA, PocketPC PDAs, Zipit Linux, as well as regular Windows). I will be making/porting/adapting AiboCam/AiboRemote for the PSP (my main motivation for doing all this work). Pimping for AiboPet.

re: how hard is it?
The LAN connection logic is perhaps the easiest part of these kinds of apps. There are general hassles dealing with bad connections or dropped connections, and other platform specifics. The "Berkeley socket" interface hasn't changed much in 20 years, so that tells you something.
Usually most of the work is the user interface. Reasonable graphic. Perhaps the most difficult on the PSP is living with the minimal input controls (8 buttons, analog stick). Great for games, but the PSP is not a PDA (no touch screen, keyboard or microphone)
GeekMyRide
Posts: 1
Joined: Wed Jul 06, 2005 12:33 am
Contact:

So what do I compile this in...

Post by GeekMyRide »

Ok, n00b here to PSP development - what do I need to write and compile the source code I'm seeing here... couldn't find a primer for developers, but you guys are at the top of your game, sooooo ;)

Best,

-Auri
--
Yup, I wrote a book: http://www.GeekMyRide.net
PspPet
Posts: 210
Joined: Wed Mar 30, 2005 2:13 am
Contact:

Post by PspPet »

> ...what do I need to write and compile the source code I'm seeing here
Start with the PSPSDK
http://forums.ps2dev.org/viewforum.php?f=19

The sample code mentioned in this thread is using an older program structure. An improved version will be released soon, using the PSPSDK program structure.
mrbrown
Site Admin
Posts: 1537
Joined: Sat Jan 17, 2004 11:24 am

Patching proved to be unnecessary

Post by mrbrown »

Did a bit of experimentation last night and it seems that you don't have to patch any of the network module's stubs into your program.

If your program is running in kernel mode (via 0x1000 and thread attribute 0), and if you have delayed imports from a module, and you load and start that module, then it all just works. The main caveat is that you need to be running in the kernel memory space so that your code doesn't choke when jumping to an address that isn't memory mapped.

TyRaNiD has put code into PSPSDK's crt0.c to automatically switch your program into kernel space, and has updated his debugging code and samples to use kernel stubs directly.

So for now anything using delayed imports must use kernel mode, which was true even with the patching method. We're working on a way to allow folks to load modules from user mode and get them resolved as syscalls.
User avatar
Agoln
Posts: 326
Joined: Wed Jun 08, 2005 3:14 am
Location: Fort Wayne, IN

Post by Agoln »

Ok, I have just pulled up some old code of mine that uses sockets, and there are a few things in it that I'm not quite sure how to handle. All of these are things that I didn't see in the sample, but yet have in my code.

Here they are:

HostEntry*
gethostbyname()
InetAddr*
SockAddr*

I know that the sockaddr_in struct replaced the SockInetAddr struct, but what about the SockAddr struct?

Any help here is well appreciated.

Thanks!
Lego of my Ago!
PspPet
Posts: 210
Joined: Wed Mar 30, 2005 2:13 am
Contact:

Post by PspPet »

> if your program is running in kernel mode (via 0x1000 and thread attribute 0), and if you have delayed imports from a module, and you load and start that module
Thanks for the tip.
Qualification - the library module must be loaded into kernel memory space too (either naturally or forced)

This fixes some cases (like the simple "usbmode" sample).
However all the important sceNetLib? libraries complain if you try to force them to load into kernel memory (they want to be in user memory, which the system won't auto fixup)

========
> ...I have just pulled up some old code of mine that uses sockets
The socket interface is not yet complete, and will never will be 100% compatible with common features - and to say nothing of weird implementations ;->

>gethostbyname() and anything related to using host names instead of IP addresses
There is a resolver component. I suspect that would provide the needed functionality (in a very different way). Need some work to figure it out. If you can live with known IP addresses, so much the better...
> but what about the SockAddr struct?
Try the more basic "struct sockaddr" ??. Only the mainstream variations are in the header (focusing on TCP/IP and UDP/IP)

Even the 20 year old sockets standard is far from standard ;->
User avatar
Agoln
Posts: 326
Joined: Wed Jun 08, 2005 3:14 am
Location: Fort Wayne, IN

Post by Agoln »

Not sure if there was a reason for this, but...

Code: Select all

// Socket address, internet style.
struct sockaddr_in {
        unsigned short sin_family; // REVIEW: is this correct ?
        unsigned short sin_port; // use htons()
        unsigned char sin_addr[4];
        char    sin_zero[8];
};
vs.

Code: Select all

// Internet address (a structure for historical reasons)
struct in_addr {
	   unsigned long s_addr; // that's a 32-bit long, or 4 bytes
}; 
    
// Socket address, internet style.
struct sockaddr_in {
        unsigned short sin_family; // REVIEW: is this correct ?
        unsigned short sin_port; // use htons()
        struct in_addr sin_addr;
        char    sin_zero[8];
};
not sure why it was a signed character, but according to http://www.ecst.csuchico.edu/~beej/guid ... ructs.html , which is how I learned them.... the struct was how to do it...

What's the reason for those?

EDIT*:

Also, if someone can help me out here... rinco has been trying for awhile and can't help me much, and I'm not too much help to myself.

When I run the binary that came with teh wifi sample, it gives me a thread ID of 039A3C13. When I run it myself, I get one that is darn near that, but not the same. Then, it goes into +start and hangs at this part of the code:

Code: Select all

    u32* addr = (u32*)0x88014318;
    if (*addr != 0x27bdffd0)
    {
	    addr = (u32*)0x88017308;
	    if (*addr != 0x27bdffd0)
        {
            printf("ERROR: version error (find)!\n");
            return 0;   // something terribly wrong
        }
    }
It then just shut's off. Does anyone know the cause of this?

I cannot load the PRX from flash0:, it gives me a -2million number, i'm guessing uninit'd int. I am really frustrated and would really enjoy it if someone would be able to help me out. Thanks.
Lego of my Ago!
PspPet
Posts: 210
Joined: Wed Mar 30, 2005 2:13 am
Contact:

Post by PspPet »

re: sockaddr_in and char/unsigned char

Not sure what you are asking. I originally took mine from Winsock.
The current header in wifi_sample_001 is wrong. Please check this thread:
http://forums.ps2dev.org/viewtopic.php?t=2433

Code: Select all

struct sockaddr_in { 
   unsigned char sin_size; // // PSP specific - ignored
   unsigned char sin_family; // usually AF_INET 
        unsigned short sin_port; // use htons() 
        unsigned char sin_addr[4]; 
        char    sin_zero[8]; 
}; 
Ie. the "sin_family" field is 1 byte, the second byte.

=====
> When I run the binary that came with teh wifi sample, it gives me a thread ID of 039A3C13. When I run it myself, I get one that is darn near that, but not the same.
That's probably ok.

> Then, it goes into +start and hangs at this part of the code:

That is not ;->
Are you running the released binary (or a rebuilt one)?. What version of firmware ?
It does have hard coded addresses (which may be different with different versions of firmware, so the checks may fail - but it shouldn't crash on the checks (unless the kernel memory is not accessible)
======
If you are building your own sample: Your program needs to have access to KERNEL memory and run as a KERNEL thread (otherwise this trickery won't work)

If you based your program on the HelloWorld structure, take a look at the "startup.s" provided in wifi_sample_001. Merge the module flags and thread start attributes from my sample into your 'startup.s'
If you based your program on the PSPSDK (ie. no startup.s), then use:

Code: Select all

PSP_MODULE_INFO(MY_APP_NAME, 0x1000, 1, 1);
PSP_MAIN_THREAD_ATTR(0);
NOTE: wifi_sample_002 (coming soon) uses the PSPSDK structure (and probably the pspDebugFind routines to avoid using hard coded addresses)

---
> I cannot load the PRX from flash0:, it gives me a -2million number,
That will happen if you don't have the right flags (can't load from flash0 from a user thread, or from the kernel mode startup code, or if the KMEM memory is not enabled) - which in turn causes other problems...
Post Reply