| View previous topic :: View next topic |
| Author |
Message |
rapso
Joined: 28 Mar 2005 Posts: 147
|
Posted: Sun Jul 19, 2009 11:00 am Post subject: pspdev/sdk/net/simple stuck on "connection state 2 of 4 |
|
|
hi,
I was implementing network stuff based on that sample.
here is the critical code
| Code: |
DU32 TryCount=0;
DU32 StateLast=~0;
while(TryCount<50)
{
D_LOG_INFO("Try: %d",TryCount++);
DS32 State=~0;
if((Ret=sceNetApctlGetState(&State)) != 0)
{
D_LOG_CRITICAL("failed with code: 0x%x %d",Ret,Ret);
break;
}
if(State!=StateLast)
{
D_LOG_INFO("connection state %d of 4",State);
StateLast = State;
}
if(State == 4)
{
D_LOG_INFO("Successfull");
Connected = true;
break; // connected with static IP
}
// yield
sceKernelDelayThread((g_Logger.LogLevel()==EDLE_INFO?500:50)*1000);
}
|
my log output is
| Code: |
Initialising Network Manager
calling pspSdkLoadInetModules()
done
calling pspSdkInetInit()
done
calling sceNetApctlConnect(0)
done
Connecting...
Try: 0
connection state 2 of 4
Try: 1
Try: 2
Try: 3
Try: 4
connection state 0 of 4
Try: 5
Try: 6
Try: 7
Try: 8... |
there is no error code returned, but suddenly the state gets back to 0
so I started the sample, it compares state>stateLast instead of != in my case, anyway. it stucks at:
| Code: |
...
connection state 0 of 4
connection state 2 of 4
|
my network is working, I was playing online games and the browser also works.
some pages on the net (not related to programming tho), said u need to hardcode the ip instead of hdcp, I did this, but nothing changed (browser still works).
I'm working with devkitPro/devkitPSP 11
my PSP-FW is 3.40 OE-A
i'm deving for 1.50, so I put all my eboots in the psp\game150\gamename\ folder.
any idea what might be wrong? I ran out of ideas (and searching on the web and here didn't really help now).
thx in advance
rapso |
|
| Back to top |
|
 |
Dariusc123456
Joined: 12 Aug 2008 Posts: 394
|
Posted: Sun Jul 19, 2009 1:46 pm Post subject: |
|
|
Just for starters, you should update your psp cfw and your pspsdk. Ever since Sony randomize the nids, it been hard for most developers todo alot of things. _________________ PSHN - Playstation Hacking Network
PSX/PS1 - HACK - Game Shark
PS2 - HACK - Swap
PSP - HACK - Pandora
PS3 - ? |
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Sun Jul 19, 2009 2:18 pm Post subject: |
|
|
| You might look at the network init code I used in Basilisk II. There were issues with how some people were retrying on the network connect that I fixed. |
|
| Back to top |
|
 |
Torch

Joined: 28 May 2008 Posts: 842
|
Posted: Sun Jul 19, 2009 8:29 pm Post subject: |
|
|
| Code: | int connect_to_apctl(int config) {
int err;
int state;
int stateLast = -1;
char stateinfo[25];
char st_text[50];
if ((err = sceNetApctlConnect(config)) < 0)
{
sprintf(st_text, "sceNetApctlConnect returns %x.", err);
goto error_connecting;
}
while (1)
{
if (sceWlanGetSwitchState() != 1)
{
sprintf(st_text, "WLAN switch is turned off.");
err = -1;
goto error_connecting;
}
if ((err = sceNetApctlGetState(&state)) < 0)
{
sprintf(st_text, "sceNetApctlGetState returns %x.", err);
goto error_connecting;
}
if (state != stateLast)
{
switch (state)
{
case PSP_NET_APCTL_STATE_DISCONNECTED:
strcpy(stateinfo, "Disconnected");
break;
case PSP_NET_APCTL_STATE_SCANNING:
strcpy(stateinfo, "Scanning");
break;
case PSP_NET_APCTL_STATE_JOINING:
strcpy(stateinfo, "Joining");
break;
case PSP_NET_APCTL_STATE_GETTING_IP:
strcpy(stateinfo, "Obtaining IP address");
break;
case PSP_NET_APCTL_STATE_GOT_IP:
strcpy(stateinfo, "IP address obtained");
break;
case PSP_NET_APCTL_STATE_EAP_AUTH:
strcpy(stateinfo, "EAP Authenticating");
break;
case PSP_NET_APCTL_STATE_KEY_EXCHANGE:
strcpy(stateinfo, "Exchanging key information");
break;
}
sprintf(st_text, "Connection state %d: %s.", state, stateinfo);
//print st_text to show connection state
stateLast = state;
}
if (state == 4) goto connected;
sceKernelDelayThread(50 * 1000);
}
error_connecting:
//print st_text to show error
connected:
return (err < 0)?0:1;
} |
Last edited by Torch on Mon Jul 20, 2009 4:06 pm; edited 1 time in total |
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Mon Jul 20, 2009 1:10 am Post subject: |
|
|
| So they've identified more of the states, huh? :) I'll have to update my own stuff some time. |
|
| Back to top |
|
 |
rapso
Joined: 28 Mar 2005 Posts: 147
|
Posted: Mon Jul 20, 2009 3:18 am Post subject: |
|
|
| Dariusc123456 wrote: | | Just for starters, you should update your psp cfw and your pspsdk. Ever since Sony randomize the nids, it been hard for most developers todo alot of things. |
it's the latest devkitpro sdk for psp and I don't really want to update my fw without beeing sure it would solve the issue.
| J.F. wrote: |
You might look at the network init code I used in Basilisk II. There were issues with how some people were retrying on the network connect that I fixed. |
sounds like a cool project, did you port it (cause I've found non-psp version) or is this from scratch by yourself?
anyway, I checked your code and the only difference I found was an sceNetApctlDisconnect(); ahead of connect. That didn't change the behaviour :/
Thx, that shows me at least what's going on, but I'm still not sure how to fix my issue, or at least what the issue is.
It's "joining", joining what? just connecting to the wlan router?
then it's disconnected, probably it failed, that's not bad, better than a random crash at least, but what's going on? Is there anything to get more infos on the issue? (I've still tested it with the sample, I guess that shall work and it's somehow an setup issue on my network? )
Any more hints how to debug that? did anyone test if the 1.5 network eboot works on newer FWs at all?
it's really not that simple to google for "could not connect" :/ |
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Mon Jul 20, 2009 4:34 am Post subject: |
|
|
| rapso wrote: | | J.F. wrote: |
You might look at the network init code I used in Basilisk II. There were issues with how some people were retrying on the network connect that I fixed. |
sounds like a cool project, did you port it (cause I've found non-psp version) or is this from scratch by yourself? |
Just a port. Lots of folks have worked on B2 (they're in the docs). There was also an earlier port of B2 to the PSP with old code. I just did a new port with the latest code, and added some extra features like changing floppy and CD images on the fly, changing the control mapping, TV out on the Slim, etc.
| Quote: | anyway, I checked your code and the only difference I found was an sceNetApctlDisconnect(); ahead of connect. That didn't change the behaviour :/
|
Yeah, if you don't do that disconnect, any retries WILL fail. That is clearly not your problem here, though. |
|
| Back to top |
|
 |
Torch

Joined: 28 May 2008 Posts: 842
|
Posted: Mon Jul 20, 2009 4:13 pm Post subject: |
|
|
I've edited the above code a bit. It should now work stand alone. You can just load the modules and call the function from any application. If it still doesn't work, then something else is wrong.
I've only loaded the INet modules for TCP/UDP. You'll need to load the HTTP modules if you want to use HTTP (Or you could handle the protocol yourself for simple requests to avoid the bloat/synchronous delay of the Sony modules).
I use this to load the modules:
| Code: | int err;
char st_text[50];
if((err = sceUtilityLoadNetModule(1)) < 0)
{
if (err == 0x80110802)
{
sprintf(st_text, "Common net modules already loaded %x.", err);
}
else
{
sprintf(st_text, "Error, could not load common net modules %x.", err);
goto error_delay;
}
}
if((err = sceUtilityLoadNetModule(3)) < 0)
{
if (err == 0x80110802)
{
sprintf(st_text, "Inet modules already loaded %x.", err);
sceKernelDelayThread(2000 * 1000);
}
else
{
sprintf(st_text, "Error, could not load Inet modules %x.", err);
goto error_delay;
}
}
if ((err = pspSdkInetInit()) < 0)
{
if (err == 0x80000020)
{
sprintf(st_text, "Network already initialized %x.", err);
sceKernelDelayThread(2000 * 1000);
}
else
{
sprintf(st_text, "Error, could not initialize network %x.", err);
goto error_delay;
}
}
goto no_errors;
error_delay:
//print st_text to show error
sceKernelDelayThread(2000 * 1000);
no_errors:
//...
//connect thread |
|
|
| Back to top |
|
 |
Torch

Joined: 28 May 2008 Posts: 842
|
Posted: Mon Jul 20, 2009 4:24 pm Post subject: |
|
|
| J.F. wrote: | | Yeah, if you don't do that disconnect, any retries WILL fail. That is clearly not your problem here, though. |
I've never used the disconnect function. I dunno about older firmware, but once its connected to the AP and if you go out of range, or AP fails, or if you turn off the WLAN switch, then the state automatically reverts to disconnected (I have a thread logging the connection info). I just call the connect to AP function again and it connects without any problems. (Of course I actually wait until the state returns disconnected on its own instead of instantly retrying when the network seems to have failed.)
Maybe its only required if it hangs during the connection procedure. But from all the network sample and homebrew source I've seen I don't think anyone has bothered to handle the error if it craps out in the connect to AP function while the states are changing :P |
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Tue Jul 21, 2009 12:25 am Post subject: |
|
|
[quote="Torch"] | J.F. wrote: |
Maybe its only required if it hangs during the connection procedure. But from all the network sample and homebrew source I've seen I don't think anyone has bothered to handle the error if it craps out in the connect to AP function while the states are changing :P |
Yeah, it's just if it doesn't finish connecting before the timeout on the connection. You can either make the timeout longer and hope it eventually connects, or you can disconnect and retry. Disconnecting and retrying is nearly always faster than longer timeouts. |
|
| Back to top |
|
 |
rapso
Joined: 28 Mar 2005 Posts: 147
|
Posted: Tue Jul 21, 2009 9:20 pm Post subject: |
|
|
got it working, first, in order to get the simple net sample running
- wpa and without encryption does not work, just wep (64 and 128)
- it's not running with just one setup for network. In the end I created all possible and iterated through them (every time changing the router settings), once I found a working one, I deleted all the others and it didn't work anymore (wtf?)
in order to get it working on my engine, I had to create a user thread, but this user thread could not read/write files (where I read some configs that failed, but as my logging also writes files, I didn't see that fail).
so, i'm doing it like
kernel thread loads the inet libs
kernel creates user thread
kernel polling user thread (with sleep of 10ms) userthread is initializing networkk
Kernel closes user thread
.
.
.
two tiny questions left
1. is there some permission I need to enabled to get file access on the user thread? (as I would prefer to run everything after the inet lib loading on user side), I didn't really find a doc for the scecreatethread (or whatever the name was, havn't the code here).
2. it shall be ok to do the rest of networking on kernel side, right? (it was 4am when I got it finally running and had not time to test)
Thanks for all your support here :)
rapso |
|
| Back to top |
|
 |
Torch

Joined: 28 May 2008 Posts: 842
|
Posted: Tue Jul 21, 2009 9:22 pm Post subject: |
|
|
Network doesn't work properly from kernel mode. No wonder....
I didn't know you could even get it working to the point you did under kernel mode. |
|
| Back to top |
|
 |
rapso
Joined: 28 Mar 2005 Posts: 147
|
Posted: Tue Jul 21, 2009 11:05 pm Post subject: |
|
|
| Torch wrote: | Network doesn't work properly from kernel mode. No wonder....
I didn't know you could even get it working to the point you did under kernel mode. | as I said, most of the time I was working with the sample, it starts the user mode after loading the inet module and this was where I stuck 99% of the time.
those additional thread issues were solved in one night, there is no real docu about this, tho. (or at least I didn't find it, for rendering I was using yapspd which explains 99% of the stuff needed). |
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Wed Jul 22, 2009 1:26 am Post subject: |
|
|
1.50-based homebrew can only use WEP encryption. To use WPA, you have to switch to 3.xx based homebrew.
Also, the network connections list the PSP maintains seems really fragile. I've had to go delete all connections and remake them a number of times. |
|
| Back to top |
|
 |
jojojoris
Joined: 30 Mar 2008 Posts: 261
|
Posted: Wed Jul 22, 2009 3:58 am Post subject: |
|
|
Why don't we use the normal network dialog from the firmware to establish the connection? In my opinion that would be far more user friendly and it looks more professional. _________________
| Code: | int main(){
SetupCallbacks();
makeNiceGame();
sceKernelExitGame();
} |
|
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Wed Jul 22, 2009 6:41 am Post subject: |
|
|
| jojojoris wrote: | | Why don't we use the normal network dialog from the firmware to establish the connection? In my opinion that would be far more user friendly and it looks more professional. |
Because no one knows how to do that. :) |
|
| Back to top |
|
 |
Torch

Joined: 28 May 2008 Posts: 842
|
Posted: Wed Jul 22, 2009 7:30 am Post subject: |
|
|
| J.F. wrote: | | Because no one knows how to do that. :) |
??
Its been done in some homebrew like PSPKVM, and in VLF its just a single function call. Its supports everything right up to creating a new configuration. |
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Wed Jul 22, 2009 7:47 am Post subject: |
|
|
| Well, post some example code and maybe people will use it. :) |
|
| Back to top |
|
 |
Torch

Joined: 28 May 2008 Posts: 842
|
Posted: Wed Jul 22, 2009 8:56 am Post subject: |
|
|
| Theres a sample in the SDK IIRC which shows how to display the dialog on top while you're rendering with the GU. |
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Wed Jul 22, 2009 2:23 pm Post subject: |
|
|
Would that be utility/netdialog? No wonder no one knows about it. :)
I'll have to try adding that into my stuff. Thanks for the tip. |
|
| Back to top |
|
 |
Torch

Joined: 28 May 2008 Posts: 842
|
Posted: Wed Jul 22, 2009 2:31 pm Post subject: |
|
|
Another reason to use it is the configuration number keeps increasing as you add and delete access point configurations. So you may have large gaps in between. You have to start from 0 and keep incrementing the counter checking to see if that configuration number exists (and hope the user hasn't performed an abnormal amount of additions/deletions of configurations) until you decide to give up incrementing.
I guess you're intended to read the max value from somewhere first if attempting to manually enumerate the configurations. I read somewhere that there can be a maximum of 100 configurations at once (but potentially a 32 bit configuration number).
| Code: | int i, j = 0, configs[100];
for (i = 1; i <= Anyone's_Guess; i++)
{
if (sceUtilityCheckNetParam(i) == 0);
{
configs[j++] = i;
}
}
configs[j] = -1 |
|
|
| Back to top |
|
 |
jojojoris
Joined: 30 Mar 2008 Posts: 261
|
Posted: Wed Jul 22, 2009 8:36 pm Post subject: |
|
|
| J.F. wrote: | | jojojoris wrote: | | Why don't we use the normal network dialog from the firmware to establish the connection? In my opinion that would be far more user friendly and it looks more professional. |
Because no one knows how to do that. :) |
Actually I use that.
I will create an example.
EDIT:
Wait there is already one in the utility samples _________________
| Code: | int main(){
SetupCallbacks();
makeNiceGame();
sceKernelExitGame();
} |
|
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Thu Jul 23, 2009 6:12 am Post subject: |
|
|
| jojojoris wrote: | | J.F. wrote: | | jojojoris wrote: | | Why don't we use the normal network dialog from the firmware to establish the connection? In my opinion that would be far more user friendly and it looks more professional. |
Because no one knows how to do that. :) |
Actually I use that.
I will create an example.
EDIT:
Wait there is already one in the utility samples |
Well, if you can make a nicer one (you know, with things like comments and such), I'd appreciate it. :) |
|
| Back to top |
|
 |
jojojoris
Joined: 30 Mar 2008 Posts: 261
|
Posted: Fri Jul 24, 2009 2:59 am Post subject: |
|
|
| J.F. wrote: | | jojojoris wrote: | | J.F. wrote: | | jojojoris wrote: | | Why don't we use the normal network dialog from the firmware to establish the connection? In my opinion that would be far more user friendly and it looks more professional. |
Because no one knows how to do that. :) |
Actually I use that.
I will create an example.
EDIT:
Wait there is already one in the utility samples |
Well, if you can make a nicer one (you know, with things like comments and such), I'd appreciate it. :) |
http://jojosoft.1free.ws/viewtopic.php?f=7&t=3
Hope you agree this is a nicer one. _________________
| Code: | int main(){
SetupCallbacks();
makeNiceGame();
sceKernelExitGame();
} |
|
|
| Back to top |
|
 |
J.F.
Joined: 22 Feb 2004 Posts: 2906
|
Posted: Fri Jul 24, 2009 5:33 am Post subject: |
|
|
Much nicer. :)
I think the main reason no one noticed it is because it was in utilities rather than net. NONE of the net examples connect to the net using the netdialog. |
|
| Back to top |
|
 |
|