sceNetApctlConnect() problem

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

Moderators: cheriff, TyRaNiD

Post Reply
Freezez
Posts: 7
Joined: Sat Feb 16, 2008 2:09 am

sceNetApctlConnect() problem

Post by Freezez »

Hi.
I've tried to make a PSP program which use wifi to connect on the Internet but it's don't work.
I can compile it perfectly but when I run the program sceNetApctlConnect return an error 1106... something like that.

Here is the code (very dirty sorry) :

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <zlib.h>

#include <unistd.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/select.h>
#include <errno.h>


/* PSP  includes */
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspsdk.h>
#include <pspwlan.h>
#include <pspdisplay.h>

#include <pspnet.h>
#include <pspnet_inet.h>
#include <pspnet_apctl.h>
#include <pspnet_resolver.h>
#include <psputility_netmodules.h>
#include <netinet/in.h>


/* Define printf, just to make typing easier */
#define printf  pspDebugScreenPrintf

/// If defined, can be executed on linux
/* #define LINUX_MODE */

#define PSP_MODULES_NAME "Onix"

#ifndef PSPFW30X
	PSP_MODULE_INFO&#40;PSP_MODULE_NAME, 0x0000, 1, 1&#41;;
#else
	PSP_MODULE_INFO&#40;PSP_MODULE_NAME, 0x0, 1, 1&#41;;
	PSP_HEAP_SIZE_KB&#40;16*1024&#41;;
#endif
	
PSP_MAIN_THREAD_ATTR&#40;0&#41;;	// kernel app
PSP_MAIN_THREAD_STACK_SIZE_KB&#40;64&#41;;

/// Connect to an access point
int connect_to_apctl&#40;int config&#41;
&#123;
	int err;
	int stateLast = -1;
	
	// Connect using the first profile
	err = sceNetApctlConnect&#40;config&#41;;
	if &#40;err != 0&#41;
	&#123;
		printf&#40;"&#91;-&#93; sceNetApctlConnect returns %08X\n", err&#41;;
		return 1;
	&#125;

	printf&#40;"&#91;*&#93; Connecting...\n"&#41;;
	while &#40;1&#41;
	&#123;
		int state;
		err = sceNetApctlGetState&#40;&state&#41;;
		if &#40;err != 0&#41;
		&#123;
			printf&#40;"&#91;-&#93; sceNetApctlGetState returns $%x\n", err&#41;;
			break;
		&#125;
		if &#40;state > stateLast&#41;
		&#123;
			printf&#40;"&#91;*&#93; connection state %d of 4\n", state&#41;;
			stateLast = state;
		&#125;
		if &#40;state == 4&#41;
			break;  // connected with static IP

		// wait a little before polling again
		sceKernelDelayThread&#40;50*1000&#41;; // 50ms
	&#125;
	printf&#40;"&#91;+&#93; Connected!\n"&#41;;

	if&#40;err != 0&#41;
	&#123;
		return 1;
	&#125;

	return 0;
&#125;

int UserInetInit&#40;&#41;&#123;	
	if&#40;sceNetInit&#40;0x20000, 0x20, 0x1000, 0x20, 0x1000&#41;&#41;&#123;
		printf&#40;"&#91;-&#93; Error when sceNetInit&#40;&#41;\n"&#41;;
		return 1;
	&#125;
		
	if&#40;sceNetInetInit&#40;&#41;&#41;&#123;
		printf&#40;"&#91;-&#93; Error when sceNetInetInit&#40;&#41;\n"&#41;;
		return 1;
	&#125;
	
	if&#40;sceNetApctlInit&#40;0x1400, 0x42&#41;&#41;&#123;	// increase stack size
		printf&#40;"&#91;-&#93; Error when sceNetApctlInit&#40;&#41;\n"&#41;;
		return 1;
	&#125;
	
	return 0;
&#125;

int main&#40;int argc, char *argv&#91;&#93;&#41;&#123;
	pspDebugScreenInit&#40;&#41;;
	atexit&#40;sceKernelExitGame&#41;;
	
	printf&#40;"&#91;*&#93; PspDebugScreen initialized\n"&#41;;
	
	if&#40;sceUtilityLoadNetModule&#40;PSP_NET_MODULE_COMMON&#41;&#41;&#123;	// load common
		printf&#40;"&#91;-&#93; Unable to load common net module\n"&#41;;
	&#125;
	
	if&#40;sceUtilityLoadNetModule&#40;PSP_NET_MODULE_INET&#41;&#41;&#123;	// load inet
		printf&#40;"&#91;-&#93; Unable to load inet module\n"&#41;;
	&#125;

	if&#40;UserInetInit&#40;&#41; == 0&#41;&#123;
		connect_to_apctl&#40;1&#41;;
	&#125;
	
	sceKernelSleepThread&#40;&#41;;
	return 0;
&#125;
I use 3.71 M33-2 firmware and pspsdk-1.0+beta2.
Thanks.
Insert_witty_name
Posts: 376
Joined: Wed May 10, 2006 11:31 pm

Post by Insert_witty_name »

Remove the following line:

Code: Select all

PSP_MAIN_THREAD_ATTR&#40;0&#41;;   // kernel app
Freezez
Posts: 7
Joined: Sat Feb 16, 2008 2:09 am

Post by Freezez »

Thanks for your answer. I've tried what you say but nothing happened.
I have always the 80110601 error.
Insert_witty_name
Posts: 376
Joined: Wed May 10, 2006 11:31 pm

Post by Insert_witty_name »

80110601 is a bad netconf.

Delete your network settings and re-enter them.
Freezez
Posts: 7
Joined: Sat Feb 16, 2008 2:09 am

Post by Freezez »

I will try that but other apps using this netconf work perfectly. Why ?
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Freezez wrote:I will try that but other apps using this netconf work perfectly. Why ?
I ran into this with Doom. I think it has to do with trying to iterate through all connections versus just using the first one. It's all I could figure on it at the time.
Post Reply