Page 1 of 1

ps2ip_init() hangs?...again

Posted: Thu Jan 15, 2009 4:31 am
by methos3
Hi!
I'm back to my project, and some parts are almost done, I've sucessfully finished the PC version of my network program, but... there's a little problem on the PS2.
When I make a call to ps2ip_init(), the application hangs!
I loaded all the modules, look to the function:

Code: Select all

void loadmodules(){
//pad and cdvd modules
SifExecModuleBuffer(ps2dev9, size_ps2dev9, 0, NULL, &ret);
if&#40;ret<0&#41;&#123;
scr_printf&#40;"Error loading ps2dev9 modules\n"&#41;;
SleepThread&#40;&#41;;
&#125;
//load up, in this order&#58; ps2ip and ps2ips, and finally&#58;
char *ip = "192.168.2.12", *gw = 192.168.2.1, *nm = "255.255.255.0";
char* args = malloc&#40;strlen&#40;ip&#41;+strlen&#40;nm&#41;+strlen&#40;gw&#41;+3&#41;;
int a;
strcpy&#40;&args&#91;a&#93;, ip&#41;; a+=strlen&#40;ip&#41;+1;
strcpy&#40;&args&#91;a&#93;, nm&#41;; a+=strlen&#40;nm&#41;+1;
strcpy&#40;&args&#91;a&#93;, gw&#41;; a+=strlen&#40;gw&#41;+1;
SifExecModuleBuffer&#40;ps2smap, size_ps2smap, a, args, &ret&#41;;
if&#40;ret<0&#41;
printf&#40;"Error loading ps2smap\n"&#41;;
SleepThread&#40;&#41;;
&#125;
Ok, this functions works, and I can also see the "192.168.2.12" IP on my router's traf monitor;

But, the first thing that I do in main function is:

Code: Select all

int main&#40;&#41;&#123;
resetIop&#40;&#41;; //Ok, this is my IOP reset function, ever worker for me
SifInitRpc&#40;0&#41;;
if&#40;ps2ip_init&#40;&#41; < 0&#41;&#123;
scr_printf&#40;"Error initializing ps2ip rpc!\n"&#41;;
SleepThread&#40;&#41;;
&#125;
//grapf init stuff
//server functions &#40;no joypad functions&#41;

return 0;
&#125;

I tried to load the program using the launchelf's network, and via USB, but nothing worked...

Any idea?
Maybe it's the order of the modules loading? (ps2dev9, ps2ip, ps2ips and then ps2smap)?

Thanks for any help!

methos

Posted: Fri Jan 16, 2009 11:21 pm
by methos3
Maybe I'm missing something?
I found here on the forums that the ps2dev9.irx doesn't relies anymore on the iomanx.irx, and so I'm not loading it.
I'm using the latest ps2sdk revision, from the svn.
All the modules load OK, as I said, but there is any other module that I need to load to get this program running?

[edit]:
I spend an entire day trying to get the ps2link source to see what it loads to use ps2ips, and didn't find, looked at uLE but it doen't use a propietary ftp driver, but I founf the ps2ftp source at the SVN and foun this:

Code: Select all

if &#40;!underPS2Link&#41; &#123;
                SifExitRpc&#40;&#41;;
                SifIopReset&#40;"rom0&#58;UDNL rom0&#58;EELOADCNF", 0&#41;;
                while&#40;!SifIopSync&#40;&#41;&#41;;
        &#125;
        SifInitRpc&#40;0&#41;;

        //load dev9 and smap here
        printf&#40;"Loading Network Adapter drivers...\n"&#41;;
        if &#40;!underPS2Link&#41; &#123;
                setupIP&#40;&#41;;
                SifExecModuleBuffer&#40;&iomanx_irx, size_iomanx_irx, 0, NULL, &ret&#41;;
                printf&#40;"\tLoaded IOMANX&#58; %d\n", ret&#41;;
                SifExecModuleBuffer&#40;&ps2dev9_irx, size_ps2dev9_irx, 0, NULL, &ret&#41;;
                printf&#40;"\tLoaded PS2DEV9&#58; %d\n", ret&#41;;
                SifExecModuleBuffer&#40;&ps2ip_irx, size_ps2ip_irx, 0, NULL, &ret&#41;;
                printf&#40;"\tLoaded PS2IP&#58; %d\n", ret&#41;;
                SifExecModuleBuffer&#40;&ps2ips_irx, size_ps2ips_irx, 0, NULL, &ret&#41;;
                printf&#40;"\tLoaded PS2IPS&#58; %d\n", ret&#41;;
                SifExecModuleBuffer&#40;&ps2smap_irx, size_ps2smap_irx, if_conf_len, &if_conf&#91;0&#93;, &ret&#41;;
                printf&#40;"\tLoaded PS2SMAP&#58; %d\n", ret&#41;;
        &#125;
        
        printf&#40;"Initialising IP stack...\n"&#41;;
        ps2ip_init&#40;&#41;;
The only thing different from mine is that it loads the iomanx.irx, even the order of the module loading is the same that I used:
ps2dev9, ps2ip, ps2ips, ps2smap with args.
I also used bin2c, and not bin2s, but don't believe it coul be a prolem, since I can load/init the freesio2/freepad modules and use controlers, the old version of the usb mas device driver with the rpc server works (only for testing purposes I added the old usb_mass.irx and its rpc stuff, in place of the usbhdfsd.irx).

I don't have time to test on my ps2 today, I'm not at home right now.

Someone can explain me what the iomanx.irx does and if it's really necessary to use the ps2ips?

Posted: Sat Jan 17, 2009 10:06 am
by radad
You should check the return from SifExecModuleBuffer (I am not talking about the last parameter). A value of -200 means there is a dependency error and the module wasnt loaded.

IOMANX is the iop side of the rpc functions for file access. On the ee side its the fileXio* functions defined in ee/rpc/filexio. It shouldnt be needed for ps2ips.

Posted: Sat Jan 17, 2009 11:37 am
by methos3
radad wrote:You should check the return from SifExecModuleBuffer (I am not talking about the last parameter). A value of -200 means there is a dependency error and the module wasnt loaded.

IOMANX is the iop side of the rpc functions for file access. On the ee side its the fileXio* functions defined in ee/rpc/filexio. It shouldnt be needed for ps2ips.
Yes, the problem was a dependency error!!
I never would check the returnn value instear of the last arg if you didn't say me!
ps2dev9.irx is returning -200.
Why should it return -200? I don't have time to test right now, but... what kind of module should ps2dev9.irx need to load? poweroff.irx?
Thanks, man!

Posted: Sat Jan 17, 2009 11:56 am
by radad
If you have a look in iop/dev9/dev9/src/imports.lst you can find out its dependencies:

Code: Select all

dmacman
intrman
loadcore
poweroff
stdio
thbase
thsemap
poweroff should be the only one you need to load, the rest are loaded as standard.

Posted: Sat Jan 17, 2009 12:32 pm
by Jim

Code: Select all

int a; 
strcpy&#40;&args&#91;a&#93;, ip&#41;; a+=strlen&#40;ip&#41;+1;
Where is 'a' initialized?

Jim

Posted: Sat Jan 17, 2009 2:38 pm
by LionX
what version of ps2link are you using >

Posted: Sun Jan 18, 2009 2:52 am
by methos3
radad wrote:If you have a look in iop/dev9/dev9/src/imports.lst you can find out its dependencies:

Code: Select all

dmacman
intrman
loadcore
poweroff
stdio
thbase
thsemap
poweroff should be the only one you need to load, the rest are loaded as standard.
Worked! I looked onto imports.lst before, but I didn't see the poweroff part.
Now ps2ip_init is working (I tested on the emulator), but the smap loading returns -200... Could it be anything that the ps2 emulator doens't load? I'm not at home right now, so I can't test on my PS2. (for sure this time I'm not missing any required module to load ps2smap.irx, I loaded: poweroff, dev9, ps2ip, dns(for ps2ips), ps2ips, and smap, which returns -200)

Jim wrote:Where is 'a' initialized?
Since it's declared, its value is equal to zero ;-)
LionX wrote:what version of ps2link are you using >
I don't use ps2link, I use uLaunchelf instead.



So... this is it, as soon as I get home I will test the code on the PS2 to see if the smap loading doesn't return -200.
I will post the results here later,
Cya!

Posted: Sun Jan 18, 2009 8:57 am
by radad
smap should only need dev9 and ps2ip. Emulators cant be fully trusted, best wait till you can test on real hardware.
Since it's declared, its value is equal to zero ;-)
Thats not true. C doesnt initialise variables implicitly. You have to be explicit.

Posted: Sun Jan 18, 2009 9:57 am
by methos3
radad wrote:smap should only need dev9 and ps2ip. Emulators cant be fully trusted, best wait till you can test on real hardware.
Since it's declared, its value is equal to zero ;-)
Thats not true. C doesnt initialise variables implicitly. You have to be explicit.
Serious?
I didn't know about this.
Yes, on the real hardware it worked, I needed the following:
*ps2dev9(needed ps2poweroff)
*ps2ip
*ps2ips(needed dns.irx)
*ps2smap with args
*get home to test everything

I made a simple program to transfer a file, I ported it from my PC version.
Then, I tested with a 220kb file, and it (veeeeeery slowly) transfered 180KB (or more, I don't remember) to the ps2
but, when the ps2 screen shows that 180KB was received, the pc side application says that the whole file was sent and closes the socket, should I leave the pc-side socket open? I'm going to test this tomorrow.
Looks like it's some buffering issue, because with any file that I try to transfer to the PS2, in the PC says that the file transfer was completed, and on the ps2 says that there are some KBs to be received.


ps.:Thanks for all the help that you gave me!

Posted: Sun Jan 18, 2009 10:19 am
by Jim
It's only guaranteed to be 0 if you declare it at global scope or you declare it as 'static' (and your C runtime is clearing it out at startup) . Otherwise automatic variables at function scope are undefined.

Jim

Posted: Mon Jan 19, 2009 1:39 am
by methos3
Jim wrote:It's only guaranteed to be 0 if you declare it at global scope or you declare it as 'static' (and your C runtime is clearing it out at startup) . Otherwise automatic variables at function scope are undefined.

Jim
Yes, first posted, I corrected the startup code, see the new one:

Code: Select all

void loadmodules&#40;int free&#41;
&#123;
    scr_printf&#40;"Carregando modulos"&#41;;
    s32 ret;
    int rv;

    char* IP = "192.168.2.12";
    char* NM = "255.255.255.0";
    char* GW = "192.168.2.1";
    char *args = malloc&#40;strlen&#40;IP&#41; + strlen&#40;NM&#41; + strlen&#40;GW&#41;&#41;;
    int a = 0;



    rv=SifExecModuleBuffer&#40;freesio2, size_freesio2, 0, NULL, &ret&#41;;
    scr_printf&#40;"Carregando freesio2&#58; %d\n", rv&#41;;
    if&#40;rv<0&#41; SleepThread&#40;&#41;;
    rv=SifExecModuleBuffer&#40;freepad, size_freepad, 0, NULL, &ret&#41;;
    scr_printf&#40;"Carregando freepad&#58; %d\n", rv&#41;;
    if&#40;rv<0&#41; SleepThread&#40;&#41;;
    rv=SifExecModuleBuffer&#40;usbd, size_usbd, 0, NULL, &ret&#41;;
    scr_printf&#40;"Carregando usbd&#58; %d\n", rv&#41;;
    if&#40;rv<0&#41; SleepThread&#40;&#41;;
    rv=SifExecModuleBuffer&#40;usb_mass, size_usb_mass, 0, NULL, &ret&#41;;
    scr_printf&#40;"Carregando usb_mass&#58; %d\n", rv&#41;;
    if&#40;rv<0&#41; SleepThread&#40;&#41;;
    rv=SifExecModuleBuffer&#40;poweroff, size_poweroff, 0, NULL, &ret&#41;;
    scr_printf&#40;"Carregando poweroff&#58; %d\n", rv&#41;;
    if&#40;rv<0&#41; SleepThread&#40;&#41;;
    rv=SifExecModuleBuffer&#40;ps2dev9, size_ps2dev9, 0, NULL, &ret&#41;;
    scr_printf&#40;"Carregando dev9&#58; %d\n", rv&#41;;
    if&#40;rv<0&#41; SleepThread&#40;&#41;;
    rv=SifExecModuleBuffer&#40;ps2ip, size_ps2ip, 0, NULL, &ret&#41;;
    scr_printf&#40;"Carregando ps2ip&#58; %d\n", rv&#41;;
    if&#40;rv<0&#41; SleepThread&#40;&#41;;
    rv=SifExecModuleBuffer&#40;dns, size_dns, 0, NULL, &ret&#41;;
    scr_printf&#40;"Carregando dns&#58; %d\n", rv&#41;;
    if&#40;rv<0&#41; SleepThread&#40;&#41;;
    rv=SifExecModuleBuffer&#40;ps2ips, size_ps2ips, 0, NULL, &ret&#41;;
    scr_printf&#40;"Carregando ps2ips&#58; %d\n", rv&#41;;
    if&#40;rv<0&#41; SleepThread&#40;&#41;;
    /* load up smap with static settings */
   strcpy&#40;&args&#91;a&#93;, IP&#41;; a += strlen&#40;IP&#41; + 1;
   strcpy&#40;&args&#91;a&#93;, NM&#41;; a += strlen&#40;NM&#41; + 1;
   strcpy&#40;&args&#91;a&#93;, GW&#41;; a += strlen&#40;GW&#41; + 1;
   rv=SifExecModuleBuffer&#40;ps2smap, size_ps2smap, a, args, &ret&#41;;
    scr_printf&#40;"Carregando freesio2&#58; %d", rv&#41;;
    //if&#40;rv<0&#41; SleepThread&#40;&#41;;





&#125;
Now I could receive a 70KB zipped file and save it to the memory card, whihout (much) problems.

And... why didn't I see THIS:

Code: Select all


poweroff_IMPORTS_start
I_AddPowerOffHandler
poweroff_IMPORTS_end
on the imports.lst file!? Maybe it's my eyes :S
And I didn't know that SifExecModuleBuffer returns an int like SifLoadModule.
Now my little program is fully functional(I just need to don't close the socket on the client, that sends the file, because of the buffered data), I need only to remove the scr_printf's and make my GUI for the program,

Cya!

ps.: If you are interested on my program (veeeery simple), post here or send me a message, It have a server/client for PC and a server for the PS2 (i'm still developing the client). The PC side was built using Visual Studio 2005 (C++.NET), but can be easily ported to C for Windows, Linux, etc.

Posted: Mon Jan 19, 2009 7:16 am
by Jim

Code: Select all

char* IP = "192.168.2.12"; 
    char* NM = "255.255.255.0"; 
    char* GW = "192.168.2.1"; 
    char *args = malloc&#40;strlen&#40;IP&#41; + strlen&#40;NM&#41; + strlen&#40;GW&#41;&#41;; 
    int a = 0;
... 
   strcpy&#40;&args&#91;a&#93;, IP&#41;; a += strlen&#40;IP&#41; + 1; 
   strcpy&#40;&args&#91;a&#93;, NM&#41;; a += strlen&#40;NM&#41; + 1; 
   strcpy&#40;&args&#91;a&#93;, GW&#41;; a += strlen&#40;GW&#41; + 1; 
Now you are almost certainly corrupting the heap by writing 3 too many bytes. You had that right before with the +3 in the malloc..

Jim

Posted: Mon Jan 19, 2009 8:27 am
by methos3
Mmm...
Are you saying that the three empty bytes that I'll pass within the argument don't need to be allocated, because they are \0?
Can you explain me better why the '\0' bytes don't need any space allocated on the memory?
I'll correct this later.

Posted: Mon Jan 19, 2009 10:44 pm
by Jim
I'm saying you HAVEN'T allowed for the \0s

Posted: Mon Jan 19, 2009 10:53 pm
by dlanor
methos3 wrote:Mmm...
Are you saying that the three empty bytes that I'll pass within the argument don't need to be allocated, because they are \0?
No.

What he is saying is that you neglected to add 3 to the size specified in the malloc call. That size only includes the content characters of the three strings, with no extra space for the three string terminators. So your final string will have its terminator, and two preceding characters, stored beyond the end of the allocated block. And depending on the implementation this may or may not cause an error exception (it really should), and it is a definite error in either case.

@Jim:
Sorry, we seem to have posted close in time.
Didn't mean to 'step on your toes' here. :)

Best regards: dlanor

Posted: Mon Jan 19, 2009 11:40 pm
by methos3
LOL!
I re-wrote the last code, because I was whihout my Motorola w388, that contains the code, and forgot the +3...
I was lucky when I tested, then, because it worked.
In no time I will put the +3 in the malloc funtcion.

Jim, sorry for don't paying attention on what you said, I've become confused thinking "why should I don't allocate space for the '\0's?".

Thanks! This way my program won't break so easily, haha

Cya!