Wi-Fi in User Mode

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

Moderators: cheriff, TyRaNiD

Post Reply
alekz
Posts: 5
Joined: Wed Nov 22, 2006 11:43 pm

Wi-Fi in User Mode

Post by alekz »

Hello everyone,

I'm trying to make a networking application and I think it would be better if it will run in User Mode.

But here is the problem, pspSdkLoadInetModules can be called only from the Kernel Mode. If I don't call it, and call only pspSdkInetInit - it says error 8002013A (LIBRARY_NOT_YET_LINKED).

So, is it possible to use Internet in User Space mode and how? Maybe I have to link the libs via Makefile somehow (static?).

BTW: do I have to call pspSdkInetInit from a new thread or it can be called from the main() function?

Thanks,
Alekz

P.S. I've run through various example codes, forum posts, but haven't found an answer yet - most of the code runs in the Kernel Mode there.
Fanjita
Posts: 217
Joined: Wed Sep 28, 2005 9:31 am

Post by Fanjita »

There's a way to do it with a function from sceUtility (sceUtilityLoadNetModule, if I recall correctly). But it only works on firmware 2.0 and higher.

The only sane way I'm aware of to do wifi that works on all firmwares is to use the traditional kernel-mode initialisation technique that you'll find in the samples, and let eLoader automatically translate it into the user-mode version for you when you run it on FW 2.00+.
Got a v2.0-v2.80 firmware PSP? Download the eLoader here to run homebrew on it!
The PSP Homebrew Database needs you!
powARman
Posts: 3
Joined: Sun Nov 26, 2006 1:19 am
Location: Erfurt, Germany
Contact:

Post by powARman »

I just tried it and it works. Instead of the pspSdkLoadInetModules() use the following:

Code: Select all

if &#40;sceUtilityLoadNetModule&#40;PSP_NET_MODULE_COMMON&#41; < 0&#41;
&#123;
  printf&#40;"Error, could not load PSP_NET_MODULE_COMMON\n"&#41;;
  sceKernelSleepThread&#40;&#41;;
&#125;
if &#40;sceUtilityLoadNetModule&#40;PSP_NET_MODULE_INET&#41; < 0&#41;
&#123;
  printf&#40;"Error, could not load PSP_NET_MODULE_INET\n"&#41;;
  sceKernelSleepThread&#40;&#41;;
&#125;
Regards,
Andreas
alekz
Posts: 5
Joined: Wed Nov 22, 2006 11:43 pm

Post by alekz »

Thanks for the info guys!

I've tried using the sceUtilityLoadNetModule functions - and they didn't return error, so it looks like they work. But, when I call pspSdkInetInit, it again says error 8002013A. I thought maybe sceUtilityLoadNetModule already inits the modules, so I tried to connect to an access point, without the pspSdkInetInit. But it resulted in 8002013A too.

@powARman - did you try it on 2.XX or 1.5 firmware?
powARman
Posts: 3
Joined: Sun Nov 26, 2006 1:19 am
Location: Erfurt, Germany
Contact:

Post by powARman »

I tried it on 271SE-B'', startet from GAME271 directory, so it runs in 2.x mode. I can successfully connect to my access point using WPA, so its definitely 2.x, cause 1.5 does not support WPA.

This is the litte program I used, I build it with "make all" using standard pspsdk Makefile:

Code: Select all

#include <pspkernel.h>
#include <pspdebug.h>
#include <pspsdk.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <psputility_netmodules.h>
#include <psputility_netparam.h>
#include <pspwlan.h>
#include <pspnet.h>
#include <pspnet_apctl.h>

#define printf pspDebugScreenPrintf

PSP_MODULE_INFO&#40;"test", 0, 1, 0&#41;;

/* Exit callback */
int exit_callback&#40;int arg1, int arg2, void *common&#41;
&#123;
	sceKernelExitGame&#40;&#41;;
	return 0;
&#125;

/* Callback thread */
int CallbackThread&#40;SceSize args, void *argp&#41;
&#123;
	int cbid;

	cbid = sceKernelCreateCallback&#40;"Exit Callback", exit_callback, NULL&#41;;
	sceKernelRegisterExitCallback&#40;cbid&#41;;
	sceKernelSleepThreadCB&#40;&#41;;

	return 0;
&#125;

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks&#40;void&#41;
&#123;
	int thid = 0;

	thid = sceKernelCreateThread&#40;"update_thread", CallbackThread,
				     0x11, 0xFA0, PSP_THREAD_ATTR_USER, 0&#41;;
	if&#40;thid >= 0&#41;
	&#123;
		sceKernelStartThread&#40;thid, 0, 0&#41;;
	&#125;

	return thid;
&#125;

int connect_to_apctl&#40;int config&#41; &#123;
  int err;
  int stateLast = -1;

  if &#40;sceWlanGetSwitchState&#40;&#41; != 1&#41;
    pspDebugScreenClear&#40;&#41;;

  while &#40;sceWlanGetSwitchState&#40;&#41; != 1&#41; &#123;
    pspDebugScreenSetXY&#40;0, 0&#41;;
    printf&#40;"Please enable WLAN to continue.\n"&#41;;
    sceKernelDelayThread&#40;1000 * 1000&#41;;
  &#125;

  err = sceNetApctlConnect&#40;config&#41;;
  if &#40;err != 0&#41; &#123;
    printf&#40;"sceNetApctlConnect returns %08X\n", err&#41;;
    return 0;
  &#125;

  printf&#40;"Connecting...\n"&#41;;
  while &#40;1&#41; &#123;
    int state;
    err = sceNetApctlGetState&#40;&state&#41;;
    if &#40;err != 0&#41; &#123;
      printf&#40;"sceNetApctlGetState returns $%x\n", err&#41;;
      break;
    &#125;
    if &#40;state != stateLast&#41; &#123;
      printf&#40;"  Connection state %d of 4.\n", state&#41;;
      stateLast = state;
    &#125;
    if &#40;state == 4&#41; &#123;
      break;
    &#125;
    sceKernelDelayThread&#40;50 * 1000&#41;;
  &#125;
  printf&#40;"Connected!\n"&#41;;
  sceKernelDelayThread&#40;3000 * 1000&#41;;

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

  return 1;
&#125;

char *getconfname&#40;int confnum&#41; &#123;
  static char confname&#91;128&#93;;
  sceUtilityGetNetParam&#40;confnum, PSP_NETPARAM_NAME, &#40;netData *&#41;confname&#41;;
  return confname;
&#125;

int net_thread&#40;SceSize args, void *argp&#41;
&#123;
  int selComponent = 1;
  
  printf&#40;"Using connection %d &#40;%s&#41; to connect...\n", selComponent, getconfname&#40;selComponent&#41;&#41;;

  if &#40;connect_to_apctl&#40;selComponent&#41;&#41;
  &#123;
    char szMyIPAddr&#91;32&#93;;
    if &#40;sceNetApctlGetInfo&#40;8, szMyIPAddr&#41; != 0&#41;
      strcpy&#40;szMyIPAddr, "unknown IP address"&#41;;
    printf&#40;"IP&#58; %s\n", szMyIPAddr&#41;;
    sceKernelSleepThread&#40;&#41;;
  &#125;
  return 0;
&#125;

int InitialiseNetwork&#40;void&#41;
&#123;
  int err;

  printf&#40;"load network modules..."&#41;;
  err = sceUtilityLoadNetModule&#40;PSP_NET_MODULE_COMMON&#41;;
  if &#40;err != 0&#41;
  &#123;
    printf&#40;"Error, could not load PSP_NET_MODULE_COMMON %08X\n", err&#41;;
    return 1;
  &#125;
  err = sceUtilityLoadNetModule&#40;PSP_NET_MODULE_INET&#41;;
  if &#40;err != 0&#41;
  &#123;
    printf&#40;"Error, could not load PSP_NET_MODULE_INET %08X\n", err&#41;;
    return 1;
  &#125;
  printf&#40;"done\n"&#41;;

  err = pspSdkInetInit&#40;&#41;;
  if &#40;err != 0&#41;
  &#123;
    printf&#40;"Error, could not initialise the network %08X\n", err&#41;;
    return 1;
  &#125;
  return 0;
&#125;

/* Simple thread */
int main&#40;int argc, char **argv&#41;
&#123;
	SceUID thid;

	SetupCallbacks&#40;&#41;;

	pspDebugScreenInit&#40;&#41;;

  if &#40;InitialiseNetwork&#40;&#41; != 0&#41;
  &#123;
    sceKernelSleepThread&#40;&#41;;
  &#125;

  thid = sceKernelCreateThread&#40;"net_thread", net_thread, 0x18, 0x10000, PSP_THREAD_ATTR_USER, NULL&#41;;
  if &#40;thid < 0&#41; &#123;
    printf&#40;"Error! Thread could not be created!\n"&#41;;
    sceKernelSleepThread&#40;&#41;;
  &#125;

  sceKernelStartThread&#40;thid, 0, NULL&#41;;

  sceKernelExitDeleteThread&#40;0&#41;;

	return 0;
&#125;
Regards,
Andreas
*eyelash
Posts: 3
Joined: Wed Jan 10, 2007 8:07 am

Post by *eyelash »

hi!

i tryied to make a app with WPA wi-fi user mode support. (on 3.0X OE)
but im fail... this returns false.

look this simple example: http://www.megaupload.com/?d=1ULAWXFC

thanks!
*eyelash
PSP TA-082 with FW 3.03 OE-A2
Post Reply