Example #1
0
int nlhTerm()
{
    u32 err;

//REVIEW: we need to do something first to stop the connection
//REVIEW: -- sceNetApctlTerm returns 80410A04 on V1 firmware
    err = sceNetApctlTerm();
    if (err == 0x80410A04)
        printf("sceNetApctlTerm returned common error\n");
    else if (err != 0)
        my_printn("sceNetApctlTerm returns ", err, "\n");

    err = sceNetResolverTerm();
    if (err != 0)
        my_printn("sceNetResolverTerm returns ", err, "\n");

    err = sceNetInetTerm();
    if (err != 0)
        my_printn("sceNetInetTerm returns ", err, "\n");
    err = sceNetTerm();
    if (err != 0)
        my_printn("sceNetTerm returns ", err, "\n");

    return 0; // assume it worked
}
Example #2
0
int WiFiManager::Terminate()
{
    u32 err;

    err = sceNetApctlTerm();
    if (err == 0x80410A04)
        Console::Print("sceNetApctlTerm returned common error");
    else if (err != 0)
        Console::Print("sceNetApctlTerm returns error");

    err = sceNetResolverTerm();
    if (err != 0)
        Console::Print("sceNetResolverTerm returns error");

    err = sceNetInetTerm();
    if (err != 0)
        Console::Print("sceNetInetTerm returns error");
    err = sceNetTerm();
    if (err != 0)
        Console::Print("sceNetTerm returns error");
       
	_connected = false;
	LCD::PrintMessage("WIFI Disconnected");
   return 0; // assume it worked
}
Example #3
0
/**
 * Initialize Networking Components for Adhocctl Emulator
 * @param adhoc_id Game Product Code
 * @param server_ip Server IP
 * @return 0 on success or... -1
 */
int _initNetwork(const SceNetAdhocctlAdhocId * adhoc_id, const char * server_ip)
{
	// WLAN Switch Check
	if(sceWlanGetSwitchState() == 1)
	{
		// Initialize Access Point Control
		if(sceNetApctlInit(0x1800, 0x30) == 0)
		{
			// Attempt Counter
			int attemptmax = 10;
			
			// Attempt Number
			int attempt = 0;
			
			// Attempt Connection Setup
			for(; attempt < attemptmax; attempt++)
			{
				// Start Connection
				if(sceNetApctlConnect(_hotspot) == 0)
				{
					// Wait for Connection
					int statebefore = 0;
					int state = 0; while(state != 4)
					{
						// Query State
						int getstate = sceNetApctlGetState(&state);
						
						// Log State Change
						if(statebefore != state) printk("New Connection State: %d\n", state);					
						
						// Query Success
						if(getstate == 0 && state != 4)
						{
							// Wait for Retry
							sceKernelDelayThread(1000000);
						}
						
						// Query Error
						else break;
						
						// Save Before State
						statebefore = state;
					}
					
					// Connected
					if(state == 4)
					{
						// Create Friend Finder Socket
						int socket = sceNetInetSocket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
						
						// Created Socket
						if(socket > 0)
						{
							// Enable Port Re-use
							sceNetInetSetsockopt(socket, SOL_SOCKET, SO_REUSEADDR, &_one, sizeof(_one));
							sceNetInetSetsockopt(socket, SOL_SOCKET, SO_REUSEPORT, &_one, sizeof(_one));
							
							// Apply Receive Timeout Settings to Socket
							// uint32_t timeout = ADHOCCTL_RECV_TIMEOUT;
							// sceNetInetSetsockopt(socket, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
							
							// Server IP
							uint32_t ip = 0;
							
							// Initialize DNS Resolver
							if(sceNetResolverInit() == 0)
							{
								// Create DNS Resolver
								unsigned char rbuf[512]; int rid = 0;
								if(sceNetResolverCreate(&rid, rbuf, sizeof(rbuf)) == 0)
								{
									// Resolve Domain
									if(sceNetResolverStartNtoA(rid, server_ip, &ip, 500000, 2) != 0)
									{
										// Attempt IP Conversion
										sceNetInetInetAton(server_ip, &ip);
									}
									
									// Delete DNS Resolver
									sceNetResolverDelete(rid);
								}
								
								// Shutdown DNS Resolver
								sceNetResolverTerm();
							}
							
							// Prepare Server Address
							SceNetInetSockaddrIn addr;
							addr.sin_len = sizeof(addr);
							addr.sin_family = AF_INET;
							addr.sin_addr = ip;
							addr.sin_port = sceNetHtons(ADHOCCTL_METAPORT);
							
							// Connect to Server
							if(sceNetInetConnect(socket, (SceNetInetSockaddr *)&addr, sizeof(addr)) == 0)
							{
								// Save Meta Socket
								_metasocket = socket;
								
								// Save Product Code
								_product_code = *adhoc_id;
								
								// Clear Event Handler
								memset(_event_handler, 0, sizeof(_event_handler[0]) * ADHOCCTL_MAX_HANDLER);
								memset(_event_args, 0, sizeof(_event_args[0]) * ADHOCCTL_MAX_HANDLER);
								
								// Clear Internal Control Status
								memset(&_parameter, 0, sizeof(_parameter));
								
								// Read PSP Player Name
								sceUtilityGetSystemParamString(PSP_SYSTEMPARAM_ID_STRING_NICKNAME, (char *)_parameter.nickname.data, ADHOCCTL_NICKNAME_LEN);
								
								// Read Adhoc Channel
								sceUtilityGetSystemParamInt(PSP_SYSTEMPARAM_ID_INT_ADHOC_CHANNEL, &_parameter.channel);
								
								// Fake Channel Number 1 on Automatic Channel
								if(_parameter.channel == 0) _parameter.channel = 1;
								
								// Read PSP MAC Address
								sceWlanGetEtherAddr((void *)&_parameter.bssid.mac_addr.data);
								
								// Prepare Login Packet
								SceNetAdhocctlLoginPacketC2S packet;
								
								// Set Packet Opcode
								packet.base.opcode = OPCODE_LOGIN;
								
								// Set MAC Address
								packet.mac = _parameter.bssid.mac_addr;
								
								// Set Nickname
								packet.name = _parameter.nickname;
								
								// Set Game Product ID
								memcpy(packet.game.data, adhoc_id->data, ADHOCCTL_ADHOCID_LEN);
								
								// Acquire Network Layer Lock
								_acquireNetworkLock();
								
								// Send Login Packet
								sceNetInetSend(_metasocket, &packet, sizeof(packet), INET_MSG_DONTWAIT);
								
								// Free Network Layer Lock
								_freeNetworkLock();
								
								// Load UPNP Library
								_upnp_uid = sceKernelLoadModule("ms0:/kd/pspnet_miniupnc.prx", 0, NULL);
								
								// Start UPNP Library
								int status = 0; sceKernelStartModule(_upnp_uid, 0, NULL, &status, NULL);
								
								// Return Success
								return 0;
							}
							
							// Delete Socket
							sceNetInetClose(socket);
						}
						
						// Close Hotspot Connection
						sceNetApctlDisconnect();
					}
				}
			}
			
			// Terminate Access Point Control
			sceNetApctlTerm();	
		}
	}
	
	// Generic Error
	return -1;
}
Example #4
0
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 );
}