pspdev/sdk/net/simple stuck on "connection state 2 of 4

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

Moderators: cheriff, TyRaNiD

Post Reply
rapso
Posts: 140
Joined: Mon Mar 28, 2005 6:35 am

pspdev/sdk/net/simple stuck on "connection state 2 of 4

Post by rapso »

hi,

I was implementing network stuff based on that sample.

here is the critical code

Code: Select all

		DU32 TryCount=0;
		DU32 StateLast=~0;
		while&#40;TryCount<50&#41;
		&#123;
			D_LOG_INFO&#40;"Try&#58; %d",TryCount++&#41;;
			DS32 State=~0;
			if&#40;&#40;Ret=sceNetApctlGetState&#40;&State&#41;&#41; != 0&#41;
			&#123;
				D_LOG_CRITICAL&#40;"failed with code&#58; 0x%x %d",Ret,Ret&#41;;
				break;
			&#125;
			if&#40;State!=StateLast&#41;
			&#123;
				D_LOG_INFO&#40;"connection state %d of 4",State&#41;;
				StateLast = State;
			&#125;
			if&#40;State == 4&#41;
			&#123;
				D_LOG_INFO&#40;"Successfull"&#41;;
				Connected	=	true;
				break;  // connected with static IP
			&#125;
			// yield
			sceKernelDelayThread&#40;&#40;g_Logger.LogLevel&#40;&#41;==EDLE_INFO?500&#58;50&#41;*1000&#41;;
		&#125;
my log output is

Code: Select all

Initialising Network Manager
calling pspSdkLoadInetModules&#40;&#41;
done
calling pspSdkInetInit&#40;&#41;
done
calling sceNetApctlConnect&#40;0&#41;
done
Connecting...
Try&#58; 0
connection state 2 of 4
Try&#58; 1
Try&#58; 2
Try&#58; 3
Try&#58; 4
connection state 0 of 4
Try&#58; 5
Try&#58; 6
Try&#58; 7
Try&#58; 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: Select all

...
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
Dariusc123456
Posts: 388
Joined: Tue Aug 12, 2008 12:46 am

Post by Dariusc123456 »

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 - ?
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

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.
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

Code: Select all

int connect_to_apctl&#40;int config&#41; &#123;
	int err;
	int state;
	int stateLast = -1;
	char stateinfo&#91;25&#93;;
	char st_text&#91;50&#93;;

	if &#40;&#40;err = sceNetApctlConnect&#40;config&#41;&#41; < 0&#41;
	&#123;
		sprintf&#40;st_text, "sceNetApctlConnect returns %x.", err&#41;;
		goto error_connecting;
	&#125;

	while &#40;1&#41;
	&#123;
		if &#40;sceWlanGetSwitchState&#40;&#41; != 1&#41;
		&#123;
			sprintf&#40;st_text, "WLAN switch is turned off."&#41;;
			err = -1;
			goto error_connecting;
		&#125;

		if &#40;&#40;err = sceNetApctlGetState&#40;&state&#41;&#41; < 0&#41;
		&#123;
			sprintf&#40;st_text, "sceNetApctlGetState returns %x.", err&#41;;
			goto error_connecting;
		&#125;

		if &#40;state != stateLast&#41;
		&#123;
			switch &#40;state&#41;
			&#123;
				case PSP_NET_APCTL_STATE_DISCONNECTED&#58;
					strcpy&#40;stateinfo, "Disconnected"&#41;;
					break;
				case PSP_NET_APCTL_STATE_SCANNING&#58;
					strcpy&#40;stateinfo, "Scanning"&#41;;
					break;
				case PSP_NET_APCTL_STATE_JOINING&#58;
					strcpy&#40;stateinfo, "Joining"&#41;;
					break;
				case PSP_NET_APCTL_STATE_GETTING_IP&#58;
					strcpy&#40;stateinfo, "Obtaining IP address"&#41;;
					break;
				case PSP_NET_APCTL_STATE_GOT_IP&#58;
					strcpy&#40;stateinfo, "IP address obtained"&#41;;
					break;
				case PSP_NET_APCTL_STATE_EAP_AUTH&#58;
					strcpy&#40;stateinfo, "EAP Authenticating"&#41;;
					break;
				case PSP_NET_APCTL_STATE_KEY_EXCHANGE&#58;
					strcpy&#40;stateinfo, "Exchanging key information"&#41;;
					break;
			&#125;

			sprintf&#40;st_text, "Connection state %d&#58; %s.", state, stateinfo&#41;;
			//print st_text to show connection state
			stateLast = state;
		&#125;

		if &#40;state == 4&#41; goto connected;

		sceKernelDelayThread&#40;50 * 1000&#41;;
	&#125;

error_connecting&#58;
	//print st_text to show error
connected&#58;
	return &#40;err < 0&#41;?0&#58;1;
&#125;
Last edited by Torch on Mon Jul 20, 2009 4:06 pm, edited 1 time in total.
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

So they've identified more of the states, huh? :) I'll have to update my own stuff some time.
rapso
Posts: 140
Joined: Mon Mar 28, 2005 6:35 am

Post by rapso »

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 :/
Torch wrote:
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" :/
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

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.
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.
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

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: Select all

	int err;
	char st_text&#91;50&#93;;

	if&#40;&#40;err = sceUtilityLoadNetModule&#40;1&#41;&#41; < 0&#41;
	&#123;
		if &#40;err == 0x80110802&#41;
		&#123;
			sprintf&#40;st_text, "Common net modules already loaded %x.", err&#41;;
		&#125;
		else
		&#123;
			sprintf&#40;st_text, "Error, could not load common net modules %x.", err&#41;;
			goto error_delay;
		&#125;
	&#125;
	if&#40;&#40;err = sceUtilityLoadNetModule&#40;3&#41;&#41; < 0&#41;
	&#123;
		if &#40;err == 0x80110802&#41;
		&#123;
			sprintf&#40;st_text, "Inet modules already loaded %x.", err&#41;;
			sceKernelDelayThread&#40;2000 * 1000&#41;;
		&#125;
		else
		&#123;
			sprintf&#40;st_text, "Error, could not load Inet modules %x.", err&#41;;
			goto error_delay;
		&#125;
	&#125;
	if &#40;&#40;err = pspSdkInetInit&#40;&#41;&#41; < 0&#41;
	&#123;
		if &#40;err == 0x80000020&#41;
		&#123;
			sprintf&#40;st_text, "Network already initialized %x.", err&#41;;
			sceKernelDelayThread&#40;2000 * 1000&#41;;
		&#125;
		else
		&#123;
			sprintf&#40;st_text, "Error, could not initialize network %x.", err&#41;;
			goto error_delay;
		&#125;
	&#125;
	goto no_errors;

error_delay&#58;
	//print st_text to show error
	sceKernelDelayThread&#40;2000 * 1000&#41;;

no_errors&#58;
//...
//connect thread
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

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
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Torch wrote:
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.
rapso
Posts: 140
Joined: Mon Mar 28, 2005 6:35 am

Post by rapso »

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
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

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.
rapso
Posts: 140
Joined: Mon Mar 28, 2005 6:35 am

Post by rapso »

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).
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

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.
jojojoris
Posts: 255
Joined: Sun Mar 30, 2008 4:06 am

Post by jojojoris »

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: Select all

int main&#40;&#41;&#123;
     SetupCallbacks&#40;&#41;;
     makeNiceGame&#40;&#41;;
     sceKernelExitGame&#40;&#41;;
&#125;
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

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. :)
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

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.
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Well, post some example code and maybe people will use it. :)
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

Theres a sample in the SDK IIRC which shows how to display the dialog on top while you're rendering with the GU.
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

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.
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

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: Select all

int i, j = 0, configs&#91;100&#93;;
	for &#40;i = 1; i <= Anyone's_Guess; i++&#41;
	&#123;
		if &#40;sceUtilityCheckNetParam&#40;i&#41; == 0&#41;;
		&#123;
			configs&#91;j++&#93; = i;
		&#125;
	&#125;
	configs&#91;j&#93; = -1
jojojoris
Posts: 255
Joined: Sun Mar 30, 2008 4:06 am

Post by jojojoris »

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: Select all

int main&#40;&#41;&#123;
     SetupCallbacks&#40;&#41;;
     makeNiceGame&#40;&#41;;
     sceKernelExitGame&#40;&#41;;
&#125;
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

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. :)
jojojoris
Posts: 255
Joined: Sun Mar 30, 2008 4:06 am

Post by jojojoris »

J.F. wrote:
jojojoris wrote:
J.F. wrote: 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: Select all

int main&#40;&#41;&#123;
     SetupCallbacks&#40;&#41;;
     makeNiceGame&#40;&#41;;
     sceKernelExitGame&#40;&#41;;
&#125;
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

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.
Post Reply