Exemple #1
0
void console_init()
{
	SceNetInitParam initparam;

	if (console_initialzed) {
		return;
	}

	console_mtx = sceKernelCreateMutex("console_mutex", 0, 0, NULL);

	if (sceSysmoduleIsLoaded(SCE_SYSMODULE_NET) != SCE_SYSMODULE_LOADED)
		sceSysmoduleLoadModule(SCE_SYSMODULE_NET);

	if (sceNetShowNetstat() == SCE_NET_ERROR_ENOTINIT) {
		net_memory = malloc(NET_INIT_SIZE);

		initparam.memory = net_memory;
		initparam.size = NET_INIT_SIZE;
		initparam.flags = 0;

		sceNetInit(&initparam);
	}

	sock = sceNetSocket("netdbg", SCE_NET_AF_INET, SCE_NET_SOCK_DGRAM, 0);
	memset(&target, 0, sizeof(target));
	target.sin_family = SCE_NET_AF_INET;
	target.sin_port   = sceNetHtons(3490);

	sceNetInetPton(SCE_NET_AF_INET, "192.168.1.104", &target.sin_addr);

	console_initialzed = 1;
}
Exemple #2
0
/*-------------------------------------------------------------------------*\
* Initializes module 
\*-------------------------------------------------------------------------*/
int socket_open(void) {
    /* instals a handler to ignore sigpipe or it will crash us */
   

#if APIABSTRACTION_PS3
	sys_net_initialize_network();
#elif PE_PLAT_IS_PSVITA
	static char memory[256 * 1024];
	static int initialized = 0;

	if (!initialized)
	{
		initialized = 1;
		SceNetInitParam param;
		int ret = 0;

		/* initialize libnet */
		param.memory = memory;
		param.size = sizeof(memory);
		param.flags = 0;
		ret = sceNetInit(&param);
		if(ret < 0){
			printf("sceNetInit() failed. ret = 0x%x\n", ret);
		}
	}
#else
     signal(SIGPIPE, SIG_IGN); // make sure we ignore SIGPIPE signal that is called whenever sockets close
#endif
    return 1;
}
Exemple #3
0
int nlhInit()
{
    u32 err;
    err = sceNetInit(0x20000, 0x20, 0x1000, 0x20, 0x1000);
    if (err != 0)
    {
        my_printn("sceNetInit returns ", err, "\n");
        return err;
    }
    err = sceNetInetInit();
    if (err != 0)
    {
        my_printn("sceNetInetInit returns ", err, "\n");
        return err;
    }

    err = sceNetResolverInit();
    if (err != 0)
    {
        my_printn("sceNetResolverInit returns ", err, "\n");
        return err;
    }

    err = sceNetApctlInit(0x1000, 0x42);
    if (err != 0)
    {
        my_printn("sceNetApctlInit returns ", err, "\n");
        return err;
    }

    return 0;   // it worked!
}
Exemple #4
0
void netInit(void)
{
	sceNetInit(128*1024, 42, 4*1024, 42, 4*1024);
	
	sceNetInetInit();
	
	sceNetApctlInit(0x8000, 48);
}
int AdhocInit(int type)
{		
	int result;
	
	result = sceUtilityLoadNetModule(PSP_NET_MODULE_COMMON);
	
	if(result < 0)
	{
		printf("Adhoc error: sceUtilityLoadNetModule(PSP_NET_MODULE_COMMON): 0x%08X", result);
		return result;
	}
	
	result = sceUtilityLoadNetModule(PSP_NET_MODULE_ADHOC);
	
	if(result < 0)
	{
		printf("Adhoc error: sceUtilityLoadNetModule(PSP_NET_MODULE_ADHOC); 0x%08X", result);
		return result;
	}
	
	result = sceNetInit(128*1024, 42, 4*1024, 42, 4*1024);
	
	if(result < 0)
	{
		printf("Adhoc error: sceNetInit(); 0x%08X", result);
		return result;
	}
	
	result = sceNetAdhocInit();
	
	if(result < 0)
		printf("Adhoc error: sceNetAdhocInit(): 0x%08X", result);
	
	struct productStruct gameProduct;
	
	gameProduct.unknown = type;
	
	if(type == _ADHOC_TYPE_GAMESHARING)
		memcpy(gameProduct.product, "000000001", 9);
	else
		memcpy(gameProduct.product, "ULUS99999", 9);
	
	result = sceNetAdhocctlInit(32*1024, 0x20, &gameProduct);
	
	if(result < 0)
		printf("Adhoc error: sceNetAdhocctlInit(): 0x%08X", result);
	
	// Register pspnet_adhocctl event handler
	result = sceNetAdhocctlAddHandler(AdhocctlHandler, NULL);
	
	if(result < 0)
	{
		printf("Adhoc error: sceNetAdhocctlAddHandler\n");
		return 0;
	}
	
	return 1;
}
Exemple #6
0
void ftp_init(char *vita_ip, unsigned short int *vita_port)
{
	int ret;
	UNUSED(ret);

	SceNetInitParam initparam;
	SceNetCtlInfo info;

	if (ftp_initialized) {
		return;
	}

	/* Init Net */
	if (sceNetShowNetstat() == PSP2_NET_ERROR_ENOTINIT) {
		net_memory = malloc(NET_INIT_SIZE);

		initparam.memory = net_memory;
		initparam.size = NET_INIT_SIZE;
		initparam.flags = 0;

		ret = sceNetInit(&initparam);
		DEBUG("sceNetInit(): 0x%08X\n", ret);
	} else {
		DEBUG("Net is already initialized.\n");
	}

	/* Init NetCtl */
	ret = sceNetCtlInit();
	DEBUG("sceNetCtlInit(): 0x%08X\n", ret);

	/* Get IP address */
	ret = sceNetCtlInetGetInfo(PSP2_NETCTL_INFO_GET_IP_ADDRESS, &info);
	DEBUG("sceNetCtlInetGetInfo(): 0x%08X\n", ret);

	/* Return data */
	strcpy(vita_ip, info.ip_address);
	*vita_port = FTP_PORT;

	/* Save the IP of PSVita to a global variable */
	sceNetInetPton(PSP2_NET_AF_INET, info.ip_address, &vita_addr);

	/* Create server thread */
	server_thid = sceKernelCreateThread("FTPVita_server_thread",
		server_thread, 0x10000100, 0x10000, 0, 0, NULL);
	DEBUG("Server thread UID: 0x%08X\n", server_thid);

	/* Create the client list mutex */
	client_list_mtx = sceKernelCreateMutex("FTPVita_client_list_mutex", 0, 0, NULL);
	DEBUG("Client list mutex UID: 0x%08X\n", client_list_mtx);

	/* Start the server thread */
	sceKernelStartThread(server_thid, 0, NULL);

	ftp_initialized = 1;
}
Exemple #7
0
int nlhInit()
{
    u32 err;
    err = sceNetInit(0x20000, 0x20, 0x1000, 0x20, 0x1000);
    if (err != 0)
        return err;
    err = sceNetInetInit();
    if (err != 0)
        return err;
    err = sceNetResolverInit();
    if (err != 0)
        return err;
    err = sceNetApctlInit(0x1000, 0x42);
    if (err != 0)
        return err;
    return 0;   // it worked!
}
/**
 * network_init:
 *
 * Platform specific socket library initialization.
 *
 * Returns: true (1) if successful, otherwise false (0).
 **/
bool network_init(void)
{
#ifdef _WIN32
   WSADATA wsaData;
#endif
   static bool inited = false;
   if (inited)
      return true;

#if defined(_WIN32)
   if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
   {
      network_deinit();
      return false;
   }
#elif defined(__CELLOS_LV2__) && !defined(__PSL1GHT__)
   int timeout_count = 10;

   cellSysmoduleLoadModule(CELL_SYSMODULE_NET);
   sys_net_initialize_network();

   if (cellNetCtlInit() < 0)
      return false;

   for (;;)
   {
      int state;
      if (cellNetCtlGetState(&state) < 0)
         return false;

      if (state == CELL_NET_CTL_STATE_IPObtained)
         break;

      retro_sleep(500);
      timeout_count--;
      if (timeout_count < 0)
         return 0;
   }
#elif defined(VITA)
   SceNetInitParam initparam;

   if (sceNetShowNetstat() == SCE_NET_ERROR_ENOTINIT)
   {
      _net_compat_net_memory = malloc(COMPAT_NET_INIT_SIZE);

      initparam.memory       = _net_compat_net_memory;
      initparam.size         = COMPAT_NET_INIT_SIZE;
      initparam.flags        = 0;

      sceNetInit(&initparam);

      sceNetCtlInit();
   }

   retro_epoll_fd = sceNetEpollCreate("epoll", 0);
#elif defined(GEKKO)
   char t[16];
   if (if_config(t, NULL, NULL, TRUE, 10) < 0)
      return false;
#elif defined(WIIU)
   socket_lib_init();
#elif defined(_3DS)
    _net_compat_net_memory = (u32*)memalign(SOC_ALIGN, SOC_BUFFERSIZE);
	if (_net_compat_net_memory == NULL)
		return false;
	Result ret = socInit(_net_compat_net_memory, SOC_BUFFERSIZE);//WIFI init
	if (ret != 0)
		return false;
#else
   signal(SIGPIPE, SIG_IGN); /* Do not like SIGPIPE killing our app. */
#endif

   inited = true;
   return true;
}
Exemple #9
0
static int network_interface_up(struct sockaddr_in *target, int index,
      const char *ip_address, unsigned udp_port, int *s)
{
   (void)index;

#if defined(VITA)
   if (sceNetShowNetstat() == PSP2_NET_ERROR_ENOTINIT)
   {
      SceNetInitParam initparam;
      net_memory = malloc(NET_INIT_SIZE);

      initparam.memory = net_memory;
      initparam.size = NET_INIT_SIZE;
      initparam.flags = 0;

      sceNetInit(&initparam);
   }
   *s                 = sceNetSocket("RA_netlogger", PSP2_NET_AF_INET, PSP2_NET_SOCK_DGRAM, 0);
   target->sin_family = PSP2_NET_AF_INET;
   target->sin_port   = sceNetHtons(udp_port);

   sceNetInetPton(PSP2_NET_AF_INET, ip_address, &target->sin_addr);
#else

#if defined(__CELLOS_LV2__) && !defined(__PSL1GHT__)
   int ret = 0;

   int state, timeout_count = 10;
   ret = cellNetCtlInit();
   if (ret < 0)
      return -1;

   for (;;)
   {
      ret = cellNetCtlGetState(&state);
      if (ret < 0)
         return -1;

      if (state == CELL_NET_CTL_STATE_IPObtained)
         break;

      retro_sleep(500);
      timeout_count--;
      if (index && timeout_count < 0)
         return 0;
   }
#elif defined(GEKKO)
   char t[16];
   if (if_config(t, NULL, NULL, TRUE) < 0)
      ret = -1;
#endif
   if (ret < 0)
      return -1;

   *s                 = socket(AF_INET, SOCK_DGRAM, 0);

   target->sin_family = AF_INET;
   target->sin_port   = htons(udp_port);
#ifdef GEKKO
   target->sin_len    = 8;
#endif

   inet_pton(AF_INET, ip_address, &target->sin_addr);
#endif
   return 0;
}
Exemple #10
0
int adhocInit(char *MatchingData)
{
	char mac[6];
	struct productStruct product;

	ClearPspList();

	strcpy(product.product, "ULUS99999");
	product.unknown = 0;

    u32 err;
	printf2("sceNetInit()\n");
    err = sceNetInit(0x20000, 0x20, 0x1000, 0x20, 0x1000);
    if (err != 0)
        return err;
	g_NetInit = true;

	printf2("sceNetAdhocInit()\n");
    err = sceNetAdhocInit();
    if (err != 0)
        return err;
	g_NetAdhocInit = true;
	
	printf2("sceNetAdhocctlInit()\n");
    err = sceNetAdhocctlInit(0x2000, 0x20, &product);
    if (err != 0)
        return err;
	g_NetAdhocctlInit = true;

    // Connect
    err = sceNetAdhocctlConnect("");
    if (err != 0)
        return err;
	g_NetAdhocctlConnect = true;

    int stateLast = -1;
    printf2("Connecting...\n");
    while (1)
    {
        int state;
        err = sceNetAdhocctlGetState(&state);
        if (err != 0)
        {
        		pspDebugScreenInit();
            printf("sceNetApctlGetState returns $%x\n", err);
            sceKernelDelayThread(10*1000000); // 10sec to read before exit
			return -1;
        }
        if (state > stateLast)
        {
        		sprintf(temp,"  connection state %d of 1\n", state);
            printf2(temp);
            stateLast = state;
        }
        if (state == 1)
            break;  // connected

        // wait a little before polling again
        sceKernelDelayThread(50*1000); // 50ms
    }
    printf2("Connected!\n");
    
    
	sceWlanGetEtherAddr(mac);
	
	
    printf2("sceNetAdhocPdpCreate\n");
    
    
	pdpId = sceNetAdhocPdpCreate(mac,
		     0x309,		// 0x309 in lumines
		     0x400, 	// 0x400 in lumines
		     0);		// 0 in lumines
	if(pdpId <= 0)
	{
		
		pspDebugScreenInit();
		printf("pdpId = %x\n", pdpId);
		return -1;
	}
	g_NetAdhocPdpCreate = true;

	printf2("sceNetAdhocMatchingInit()\n");
	
	err = sceNetAdhocMatchingInit(0x20000);
	if(err != 0)
	{
		pspDebugScreenInit();
		printf("error = %x\n", err);
	}
	g_NetAdhocMatchingInit = true;
	
	printf2("sceNetAdhocMatchingCreate()\n");
	matchingId = sceNetAdhocMatchingCreate( 3,
											0xa,
											0x22b,
											0x800,
											0x2dc6c0,
											0x5b8d80,
											3,
											0x7a120,
											matchingCallback);

	if(matchingId < 0)
	{
		sprintf(temp,"matchingId = %x\n", matchingId);
		printf2(temp);
	}
	g_NetAdhocMatchingCreate = true;

	/*char tempStr[100];
	tempStr[0] = '\0';	
	if(strlen(MatchingData))
	{
		strncpy(tempStr, strrchr(MatchingData, '/')+1, 100);
		strrchr(tempStr, '.')[0] = '\0';
	}*
	printf("tempStr=%s\n", tempStr);*/

	printf2("sceNetAdhocMatchingStart()\n");
	
	err = sceNetAdhocMatchingStart(matchingId, 	// 1 in lumines (presuming what is returned from create)
			 0x10,		// 0x10
			 0x2000,		// 0x2000
			 0x10,		// 0x10
			 0x2000,		// 0x2000
			 strlen(MatchingData)+1,
			 MatchingData);		
	if(err != 0)
	{
		pspDebugScreenInit();
		printf("error = %x\n", err);
	}
	
	g_NetAdhocMatchingStart = true;

	// All the init functions have passed
	return 0;
}
Exemple #11
0
void netInit()
{
	int res;

	loadNetModules();

	res = sceNetInit(0x20000, 0x2A, 0, 0x2A, 0);
	
	if (res < 0) 
	{
		throwError(6000, "Error 0x%08X in sceNetInit\n", res);		
	}

	res = sceNetInetInit();
	
	if (res < 0) 
	{
		netTerm();
		throwError(6000, "Error 0x%08X in sceNetInetInit\n", res);				
	}

	res = sceNetResolverInit();
	
	if (res < 0) 
	{
		netTerm();
		throwError(6000, "Error 0x%08X in sceNetResolverInit\n", res);		
	}

	res = sceNetApctlInit(0x1800, 0x30);
	
	if (res < 0) 
	{
		netTerm();
		throwError(6000, "Error 0x%08X in sceNetApctlInit\n", res);		
	}

	res = sceSslInit(0x28000);
	
	if (res < 0) 
	{
		netTerm();
		throwError(6000, "Error 0x%08X in sceSslInit\n", res);
	}

	res = sceHttpInit(0x25800);
	
	if (res < 0) 
	{
		netTerm();
		throwError(6000, "Error 0x%08X in sceHttpInit\n", res);
	}

	res = sceHttpsInit(0, 0, 0, 0);
	if (res < 0) 
	{
		netTerm();
		throwError(6000, "Error 0x%08X in sceHttpsInit\n", res);
	}

	res = sceHttpsLoadDefaultCert(0, 0);
	
	if (res < 0) 
	{
		netTerm();
		throwError(6000, "Error 0x%08X in sceHttpsLoadDefaultCert\n", res);
	}

	res = sceHttpLoadSystemCookie();
	
	if (res < 0) 
	{
		netTerm();
		throwError(6000, "Error 0x%08X in sceHttpsLoadDefaultCert\n", res);
	}	
}
Exemple #12
0
int main()
{
    lua_State *lua = luaL_newstate();
    lua_atpanic(lua, panic);

    // Net init
    sceSysmoduleLoadModule(SCE_SYSMODULE_NET);
    SceNetInitParam netInitParam;
    int size = 1024 * 512;
    netInitParam.memory = malloc(size);
    netInitParam.size = size;
    netInitParam.flags = 0;
    sceNetInit(&netInitParam);

    sceSysmoduleLoadModule(SCE_SYSMODULE_HTTP);
#ifdef DEBUGGER_IP
    debugNetInit(DEBUGGER_IP, DEBUGGER_PORT, DEBUG);
#endif
    sceHttpInit(1024 * 50);

    // Init libs
    debugf("Init libs....\n");
    debugf("vita2d...\n");
    vita2d_init();
    debugf("physfs\n");
    PHYSFS_init(NULL);
    debugf("lualibs\n");
    luaL_openlibs(lua);
    debugf("ffi\n");
    open_ffi(lua);

    lua_pushcfunction(lua, print);
    lua_setglobal(lua, "print");

    /*
    // Display splash
    unsigned int goal = 2*60;
    unsigned int counter = 0;
    vita2d_texture *tex = vita2d_load_PNG_buffer(splash_data);
    SceCtrlData pad;
    memset(&pad, 0, sizeof(pad));
    for (;;) {
        ++counter;
        if (counter >= goal)
            break;
        sceCtrlPeekBufferPositive(0, &pad, 1);
        if (pad.buttons & SCE_CTRL_ANY)
            break;
        vita2d_start_drawing();
        vita2d_clear_screen();
        vita2d_draw_texture(tex, 0, 0);
        vita2d_end_drawing();
        vita2d_swap_buffers();
    }
    */

    debugf("[Lua] Loading app0:/lib/init.lua ...\n");
    if(luaL_loadfile(lua, "app0:/lib/init.lua") == 0)
    {
        if(lua_pcall(lua, 0, 0, 0) != 0)
        {
            debugf("[Lua] init error: %s\n", lua_tostring(lua, -1));
            lua_pop(lua, 1);
        }
    }

    /*debugf("[Lua] Loading app0:/boot.lua ...\n");
    if(luaL_loadfile(lua, "app0:/boot.lua") == 0)
    {
        if(lua_pcall(lua, 0, 0, 0) != 0)
        {
            debugf("[Lua] bootscript err: %s\n", lua_tostring(lua, -1));
            lua_pop(lua, 1);
        }
    }
    else
    {
    debugf("[Lua] bootscript load err: %s\n", lua_tostring(lua, -1));
        lua_pop(lua, 1);
    }*/

    debugf("Deinit. Goodbye.\n");
    sceHttpTerm();
    PHYSFS_deinit();
    vita2d_fini();
    //vita2d_free_texture(tex);

    sceKernelExitProcess(0);
    return 0;
}
Exemple #13
0
int adhocInit(const char *matchingData)
{
	struct productStruct product;
	int error = 0, state = 0;
	unsigned char mac[6];
	const char *unknown = "";
	char message[256];

	video_set_mode(32);

	mode = MODE_LOBBY;
	Server = 0;
	adhoc_initialized = 0;

	g_unk1        = 0;
	g_matchEvent  = 0;
	g_matchOptLen = 0;
	matchChanged  = 0;
	memset(g_mac, 0, sizeof(g_mac));
	memset(g_mymac, 0, sizeof(g_mymac));

	sprintf((char *)product.product, PRODUCT "00%d%d%d", VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD);
	product.unknown = 0;

	ClearPspList();

	if (strlen(matchingData) == 0)
		return -1;

	strcpy(g_matchingData, matchingData);

	sprintf(message, TEXT(CONNECTING_TO_x), TEXT(LOBBY));
	adhoc_init_progress(10, message);

	if ((error = sceNetInit(0x20000, 0x20, 0x1000, 0x20, 0x1000)) == 0)
	{
		update_progress();
		if ((error = sceNetAdhocInit()) == 0)
		{
			update_progress();
			if ((error = sceNetAdhocctlInit(0x2000, 0x20, &product)) == 0)
			{
				update_progress();
				if ((error = sceNetAdhocctlConnect(unknown)) == 0)
				{
					update_progress();
					do
					{
						if ((error = sceNetAdhocctlGetState(&state)) != 0) break;
						sceKernelDelayThread(1000000/60);

					} while (state != 1);

					if (!error)
					{
						update_progress();

						sceWlanGetEtherAddr(mac);
						update_progress();

						if ((pdpId = sceNetAdhocPdpCreate(mac, PDP_PORT, PDP_BUFFER_SIZE, 0)) > 0)
						{
							update_progress();
							if ((error = sceNetAdhocMatchingInit(0x20000)) == 0)
							{
								update_progress();
								if ((matchingId = sceNetAdhocMatchingCreate(MATCHING_CREATE_PARAMS)) >= 0)
								{
									update_progress();
									if ((error = sceNetAdhocMatchingStart(MATCHING_START_PARAMS)) == 0)
									{
										update_progress();
										show_progress(TEXT(CONNECTED));
										sceKernelDelayThread(1000000);
										adhoc_initialized = 1;
										return 0;
									}
									sceNetAdhocMatchingDelete(matchingId);
								}
								error = 2;
								sceNetAdhocMatchingTerm();
							}
							sceNetAdhocPdpDelete(pdpId, 0);
						}
						error = 1;
					}
					sceNetAdhocctlDisconnect();
				}
				sceNetAdhocctlTerm();
			}
			sceNetAdhocTerm();
		}
		sceNetTerm();
	}

	switch (error)
	{
	case 1:  sprintf(message, "%s (PDP ID = %08x)", TEXT(FAILED), pdpId); break;
	case 2:  sprintf(message, "%s (Matching ID = %08x)", TEXT(FAILED), matchingId); break;
	default: sprintf(message, "%s (Error Code = %08x)", TEXT(FAILED), error); break;
	}

	show_progress(message);

	pad_wait_clear();
	pad_wait_press(PAD_WAIT_INFINITY);

	return -1;
}
int main_thread( SceSize args, void *argp )
{
	char ip[16], * argv[5];
	int port, entry;
	parseArgs( argv, args, ( char * )argp );
	//sceUtilityGetNetParam
	strcpy( ip, argv[1] );
	port = atoi( argv[2] );
	entry = atoi( argv[3] );
	block_size = atoi( argv[4] );
	log( "%s:%d entry %d\n", ip, port, entry );
	
	/*ctrl_opts.inited = sceUtilityLoadNetModule( PSP_NET_MODULE_COMMON );
	if ( ctrl_opts.inited != 0 )
	{
		log( "Error loading Net modules (0x%08x)\n", ctrl_opts.inited );
		goto net_term;
	}
	ctrl_opts.inited = sceUtilityLoadNetModule( PSP_NET_MODULE_INET );
	if ( ctrl_opts.inited != 0 )
	{
		log( "Error loading iNet module (0x%08x)\n", ctrl_opts.inited );
		goto net_term;
	}*/
	ctrl_opts.inited = sceNetInit( 0x10000, 0x20, 0x1000, 0x20, 0x1000 );
	if ( ctrl_opts.inited != 0 )
	{
		log( "Error Initing pspnet (0x%08x)\n", ctrl_opts.inited );
		goto net_term;
	}
	ctrl_opts.inited = sceNetInetInit();
	if ( ctrl_opts.inited != 0 )
	{
		log( "Error initing Inet (0x%08x)\n", ctrl_opts.inited );
		goto net_term;
	}
	ctrl_opts.inited = sceNetResolverInit();
	if( ctrl_opts.inited != 0 )
	{
		log( "Error initing Resolver (0x%08x)\n", ctrl_opts.inited );
		goto net_term;
	}
	ctrl_opts.inited = sceNetApctlInit( 0x1400, 0x42 );
	if ( ctrl_opts.inited != 0 )
	{
		log( "Error initing Apctl (0x%08x)\n", ctrl_opts.inited );
		goto net_term;
	}
	log( "pspnet init OK!\n" );
	
	ctrl_opts.inited = connectApctl( entry );
	if ( ctrl_opts.inited != 0 )
	{
		log( "Error connecting Apctl (0x%08x)\n", ctrl_opts.inited );
		goto net_term;
	}
	
	ctrl_opts.inited = connectSocket( ip, ( unsigned short )port );
	if ( ctrl_opts.inited != 0 )
	{
		log( "Error connecting Socket\n" );
		goto net_term;
	}
	ctrl_opts.inited = 1;
	
	sceKernelSleepThread();
	
net_term:
	log( "stopping wifi...\n" );
	disconnectSocket();
	disconnectApctl();
	sceNetApctlTerm();
	sceNetResolverTerm();
	sceNetInetTerm();
	sceNetTerm();
	//sceUtilityUnloadNetModule( PSP_NET_MODULE_INET );
	//sceUtilityUnloadNetModule( PSP_NET_MODULE_COMMON );
	ctrl_opts.thid = -1;
	ctrl_opts.inited = -1;
	return sceKernelExitDeleteThread( 0 );
}
Exemple #15
0
int pspAdhocInit(const char *product_name, 
                PspMatchingCallback callback)
{
  /* Shut down adhoc, if currently enabled */
  pspAdhocShutdown();

  struct productStruct product;
  char mac[20];
  int err, state = 0;

  strncpy(product.product, product_name, 9);
  product.unknown = 0;
  if (sceUtilityGetSystemParamString(PSP_SYSTEMPARAM_ID_STRING_NICKNAME, 
                                     _matching_data, 128) != 0)
    return 0;

  if ((err = sceNetInit(0x20000, 0x2A, 0x1000, 0x2A, 0x1000)) == 0)
  {
    _net_init = 1;
    if ((err = sceNetAdhocInit()) == 0)
    {
      _net_adhoc_init = 1;
      if ((err = sceNetAdhocctlInit(0x2000, 0x20, &product)) == 0)
      {
        _net_adhoc_ctl_init = 1;
        if ((err = sceNetAdhocctlConnect((void*)"")) == 0)
        {
          _net_adhoc_ctl_connect = 1;
          do
          {
            if ((err = sceNetAdhocctlGetState(&state)) != 0) break;
            sceKernelDelayThread(1000000/60);
          } while (state != 1);

          /* Get WLAN MAC */
          unsigned char own_mac[8];
          sceWlanGetEtherAddr(own_mac);
          memcpy(_own_mac, own_mac, sizeof(unsigned char) * 6);

          if (err == 0)
          {
            sceWlanGetEtherAddr((unsigned char*)mac);
            if ((_pdp_id = sceNetAdhocPdpCreate((unsigned char*)mac, 0x309, 0x400, 0)) > 0)
            {
              _net_adhoc_pdp_create = 1;
              if ((err = sceNetAdhocMatchingInit(0x20000)) == 0)
              {
                _net_adhoc_matching_init = 1;
                _matching_id = sceNetAdhocMatchingCreate(3,
                                                        0xa,
                                                        0x22b,
                                                        0x800,
                                                        0x2dc6c0,
                                                        0x5b8d80,
                                                        3,
                                                        0x7a120,
                                                        callback);
                if (_matching_id >= 0)
                {
                  _net_adhoc_matching_create = 1;
                  err = sceNetAdhocMatchingStart(_matching_id,
                                                0x10,
                                                0x2000,
                                                0x10,
                                                0x2000,
                                                strlen(_matching_data) + 1,
                                                _matching_data);
                  if (err == 0)
                  {
                    _net_adhoc_matching_start = 1;
                    /* Everything checked out */
                    return 1;
                  }
                  sceNetAdhocMatchingDelete(_matching_id);
                  _net_adhoc_matching_create = 0;
                }
                sceNetAdhocMatchingTerm();
                _net_adhoc_matching_init = 0;
              }
              sceNetAdhocPdpDelete(_pdp_id, 0);
              _net_adhoc_pdp_create = 0;
            }
          }
          sceNetAdhocctlDisconnect();
          _net_adhoc_ctl_connect = 0;
        }
        sceNetAdhocctlTerm();
        _net_adhoc_ctl_init = 0;
      }
      sceNetAdhocTerm();
      _net_adhoc_init = 0;
    }
    sceNetTerm();
    _net_init = 0;
  }
  
  return 0;
}
Exemple #16
0
/**
 * Init debugnet library 
 *
 * @par Example:
 * @code
 * #define LOGLEVEL 3  
 * int ret;
 * ret = debugNetInit("172.26.0.2", 18194, DEBUG);
 * @endcode
 *
 * @param serverIP - your pc/mac server ip
 * @param port - udp port server
 * @param level - DEBUG,ERROR,INFO or NONE 
 */
int debugNetInit(char *serverIp, int port, int level)
{
    int ret;
    SceNetInitParam initparam;
    SceNetCtlInfo info;
    struct SceNetSockaddrIn stSockAddr;
	debugNetSetLogLevel(level);
    if (debugnet_initialized) {
        return debugnet_initialized;
    }
    /*net initialazation code from xerpi at https://github.com/xerpi/FTPVita/blob/master/ftp.c*/
    /* Init Net */
    if (sceNetShowNetstat() == PSP2_NET_ERROR_ENOTINIT) {
        net_memory = malloc(NET_INIT_SIZE);

        initparam.memory = net_memory;
        initparam.size = NET_INIT_SIZE;
        initparam.flags = 0;

        ret = sceNetInit(&initparam);
        //printf("sceNetInit(): 0x%08X\n", ret);
    } else {
        //printf("Net is already initialized.\n");
    }

    /* Init NetCtl */
    ret = sceNetCtlInit();
    //printf("sceNetCtlInit(): 0x%08X\n", ret);
   

    /* Get IP address */
    ret = sceNetCtlInetGetInfo(PSP2_NETCTL_INFO_GET_IP_ADDRESS, &info);
    //printf("sceNetCtlInetGetInfo(): 0x%08X\n", ret);


    /* Save the IP of PSVita to a global variable */
    sceNetInetPton(PSP2_NET_AF_INET, info.ip_address, &vita_addr);
	
	/* Create datagram udp socket*/
    SocketFD = sceNetSocket("debugnet_socket",
        PSP2_NET_AF_INET , PSP2_NET_SOCK_DGRAM, PSP2_NET_IPPROTO_UDP);
   
    memset(&stSockAddr, 0, sizeof stSockAddr);
	
	/*Populate SceNetSockaddrIn structure values*/
    stSockAddr.sin_family = PSP2_NET_AF_INET;
    stSockAddr.sin_port = sceNetHtons(port);
    sceNetInetPton(PSP2_NET_AF_INET, serverIp, &stSockAddr.sin_addr);

	/*Connect socket to server*/
    sceNetConnect(SocketFD, (struct SceNetSockaddr *)&stSockAddr, sizeof stSockAddr);

	/*Show log on pc/mac side*/
	debugNetUDPPrintf("debugnet initialized\n");
	debugNetUDPPrintf("Copyright (C) 2010,2015 Antonio Jose Ramos Marquez aka bigboss @psxdev\n");
	debugNetUDPPrintf("This Program is subject to the terms of the Mozilla Public\n"
		"License, v. 2.0. If a copy of the MPL was not distributed with this\n"
		"file, You can obtain one at http://mozilla.org/MPL/2.0/.\n");
    debugNetUDPPrintf("ready to have a lot of fun...\n");

	/*library debugnet initialized*/
    debugnet_initialized = 1;

    return debugnet_initialized;
}