forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Wi-Fi in User Mode

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
alekz



Joined: 22 Nov 2006
Posts: 5

PostPosted: Thu Nov 23, 2006 12:23 am    Post subject: Wi-Fi in User Mode Reply with quote

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.
Back to top
View user's profile Send private message
Fanjita



Joined: 28 Sep 2005
Posts: 217

PostPosted: Thu Nov 23, 2006 2:19 am    Post subject: Reply with quote

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!
Back to top
View user's profile Send private message
powARman



Joined: 26 Nov 2006
Posts: 3
Location: Erfurt, Germany

PostPosted: Sun Nov 26, 2006 1:23 am    Post subject: Reply with quote

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

Code:

if (sceUtilityLoadNetModule(PSP_NET_MODULE_COMMON) < 0)
{
  printf("Error, could not load PSP_NET_MODULE_COMMON\n");
  sceKernelSleepThread();
}
if (sceUtilityLoadNetModule(PSP_NET_MODULE_INET) < 0)
{
  printf("Error, could not load PSP_NET_MODULE_INET\n");
  sceKernelSleepThread();
}


Regards,
Andreas
Back to top
View user's profile Send private message Visit poster's website
alekz



Joined: 22 Nov 2006
Posts: 5

PostPosted: Mon Nov 27, 2006 6:40 am    Post subject: Reply with quote

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?
Back to top
View user's profile Send private message
powARman



Joined: 26 Nov 2006
Posts: 3
Location: Erfurt, Germany

PostPosted: Mon Nov 27, 2006 7:42 am    Post subject: Reply with quote

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:

#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("test", 0, 1, 0);

/* Exit callback */
int exit_callback(int arg1, int arg2, void *common)
{
   sceKernelExitGame();
   return 0;
}

/* Callback thread */
int CallbackThread(SceSize args, void *argp)
{
   int cbid;

   cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
   sceKernelRegisterExitCallback(cbid);
   sceKernelSleepThreadCB();

   return 0;
}

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void)
{
   int thid = 0;

   thid = sceKernelCreateThread("update_thread", CallbackThread,
                 0x11, 0xFA0, PSP_THREAD_ATTR_USER, 0);
   if(thid >= 0)
   {
      sceKernelStartThread(thid, 0, 0);
   }

   return thid;
}

int connect_to_apctl(int config) {
  int err;
  int stateLast = -1;

  if (sceWlanGetSwitchState() != 1)
    pspDebugScreenClear();

  while (sceWlanGetSwitchState() != 1) {
    pspDebugScreenSetXY(0, 0);
    printf("Please enable WLAN to continue.\n");
    sceKernelDelayThread(1000 * 1000);
  }

  err = sceNetApctlConnect(config);
  if (err != 0) {
    printf("sceNetApctlConnect returns %08X\n", err);
    return 0;
  }

  printf("Connecting...\n");
  while (1) {
    int state;
    err = sceNetApctlGetState(&state);
    if (err != 0) {
      printf("sceNetApctlGetState returns $%x\n", err);
      break;
    }
    if (state != stateLast) {
      printf("  Connection state %d of 4.\n", state);
      stateLast = state;
    }
    if (state == 4) {
      break;
    }
    sceKernelDelayThread(50 * 1000);
  }
  printf("Connected!\n");
  sceKernelDelayThread(3000 * 1000);

  if (err != 0) {
    return 0;
  }

  return 1;
}

char *getconfname(int confnum) {
  static char confname[128];
  sceUtilityGetNetParam(confnum, PSP_NETPARAM_NAME, (netData *)confname);
  return confname;
}

int net_thread(SceSize args, void *argp)
{
  int selComponent = 1;
 
  printf("Using connection %d (%s) to connect...\n", selComponent, getconfname(selComponent));

  if (connect_to_apctl(selComponent))
  {
    char szMyIPAddr[32];
    if (sceNetApctlGetInfo(8, szMyIPAddr) != 0)
      strcpy(szMyIPAddr, "unknown IP address");
    printf("IP: %s\n", szMyIPAddr);
    sceKernelSleepThread();
  }
  return 0;
}

int InitialiseNetwork(void)
{
  int err;

  printf("load network modules...");
  err = sceUtilityLoadNetModule(PSP_NET_MODULE_COMMON);
  if (err != 0)
  {
    printf("Error, could not load PSP_NET_MODULE_COMMON %08X\n", err);
    return 1;
  }
  err = sceUtilityLoadNetModule(PSP_NET_MODULE_INET);
  if (err != 0)
  {
    printf("Error, could not load PSP_NET_MODULE_INET %08X\n", err);
    return 1;
  }
  printf("done\n");

  err = pspSdkInetInit();
  if (err != 0)
  {
    printf("Error, could not initialise the network %08X\n", err);
    return 1;
  }
  return 0;
}

/* Simple thread */
int main(int argc, char **argv)
{
   SceUID thid;

   SetupCallbacks();

   pspDebugScreenInit();

  if (InitialiseNetwork() != 0)
  {
    sceKernelSleepThread();
  }

  thid = sceKernelCreateThread("net_thread", net_thread, 0x18, 0x10000, PSP_THREAD_ATTR_USER, NULL);
  if (thid < 0) {
    printf("Error! Thread could not be created!\n");
    sceKernelSleepThread();
  }

  sceKernelStartThread(thid, 0, NULL);

  sceKernelExitDeleteThread(0);

   return 0;
}


Regards,
Andreas
Back to top
View user's profile Send private message Visit poster's website
*eyelash



Joined: 10 Jan 2007
Posts: 3

PostPosted: Fri Jan 12, 2007 1:05 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
lgnr



Joined: 17 Dec 2009
Posts: 39

PostPosted: Mon Jul 05, 2010 8:40 am    Post subject: Reply with quote

Works fine.
Except my psp is freezing when i try to exit game and the client is still connected. Why is that?

Thanks in advance.
Back to top
View user's profile Send private message
Criptych



Joined: 12 Sep 2009
Posts: 79

PostPosted: Mon Jul 05, 2010 8:59 am    Post subject: Reply with quote

lgnr wrote:
Works fine.
Except my psp is freezing when i try to exit game and the client is still connected. Why is that?

Thanks in advance.


I've noticed this problem too, from PGE actually. I was able to fix it by shutting down all the net modules (which also disconnects, of course) before exiting the game.
_________________
PSP-2000 // CFW: 5.50 GEN-D2 ...and not upgrading until OFW supports homebrew!
(But I did downgrade to 1.50 with TimeMachine...)
"I want you to tell me how the machine makes you feel."
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group