Exemplo n.º 1
0
void Menu::ConnectWifi()
{
    consoleClear();

    CONFIG config;
    if(!Config::Load(&config)) {
        printf("No configuration set\n\n");
        Menu::Continue();
        return;
    }

    printf("Connecting wifi\n");
    Wifi_AutoConnect();

    while(1) {
        int n = Wifi_AssocStatus();
        int ln = -1;

        switch(n) {
        case ASSOCSTATUS_AUTHENTICATING:
            if(ln != ASSOCSTATUS_AUTHENTICATING)
                printf("Authenticating\n");
            break;
        case ASSOCSTATUS_ASSOCIATING:
            if(ln != ASSOCSTATUS_ASSOCIATING)
                printf("Associating\n");
            break;
        case ASSOCSTATUS_ACQUIRINGDHCP:
            if(ln != ASSOCSTATUS_ACQUIRINGDHCP)
                printf("Acquiring IP address from DHCP\n");
            break;
        case ASSOCSTATUS_ASSOCIATED:
            in_addr a;
            a.s_addr = Wifi_GetIP();
            printf("Connected: %s\n", inet_ntoa(a));
            Menu::ConnectNX(config);
            Wifi_DisconnectAP();
            return;
        case ASSOCSTATUS_CANNOTCONNECT:
            printf("Connection failed\n\n");
            Menu::Continue();
            return;
        }

        ln = n;
    }
}
Exemplo n.º 2
0
int wifi_listen()
{
    struct sockaddr_in addr;
    int s;
    uint32 my_ip;

    memset(&addr, 0, sizeof addr);
    addr.sin_family = AF_INET;
    addr.sin_port = htons(TCP_PORT);
    s = socket(AF_INET, SOCK_STREAM, 0);
    bind(s, (struct sockaddr *) &addr, sizeof addr);
    listen(s, 2);

    my_ip = Wifi_GetIP();
    iprintf("Listening on %d.%d.%d.%d:%d\n",
	    my_ip & 0xFF,
	    (my_ip >> 8) & 0xFF,
	    (my_ip >> 16) & 0xFF,
	    (my_ip >> 24) & 0xFF,
	    TCP_PORT);

    return s;
}
Exemplo n.º 3
0
//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------
	Wifi_InitDefault(false);
	
	consoleDemoInit(); 

	Keyboard* kb = keyboardDemoInit();
	kb->OnKeyPressed = keyPressed;

	while(1) {
		int status = ASSOCSTATUS_DISCONNECTED;

		consoleClear();
		consoleSetWindow(NULL, 0,0,32,24);

		Wifi_AccessPoint* ap = findAP();

		consoleClear();
		consoleSetWindow(NULL, 0,0,32,10);

		iprintf("Connecting to %s\n", ap->ssid);

		//this tells the wifi lib to use dhcp for everything
		Wifi_SetIP(0,0,0,0,0);	
		char wepkey[64];
		int wepmode = WEPMODE_NONE;
		if (ap->flags & WFLAG_APDATA_WEP) {
			iprintf("Enter Wep Key\n");
			while (wepmode == WEPMODE_NONE) {
				scanf("%s",wepkey);
				if (strlen(wepkey)==13) {
					wepmode = WEPMODE_128BIT;
				} else if (strlen(wepkey) == 5) {
					wepmode = WEPMODE_40BIT;
				} else {
					iprintf("Invalid key!\n");
				}
			}
			Wifi_ConnectAP(ap, wepmode, 0, (u8*)wepkey);
		} else {
			Wifi_ConnectAP(ap, WEPMODE_NONE, 0, 0);
		}
		consoleClear();
		while(status != ASSOCSTATUS_ASSOCIATED && status != ASSOCSTATUS_CANNOTCONNECT) {

			status = Wifi_AssocStatus();
			int len = strlen(ASSOCSTATUS_STRINGS[status]);
			iprintf("\x1b[0;0H\x1b[K");
			iprintf("\x1b[0;%dH%s", (32-len)/2,ASSOCSTATUS_STRINGS[status]);

			scanKeys();

			if(keysDown() & KEY_B) break;
			
			swiWaitForVBlank();
		}

		char url[256];

		if(status == ASSOCSTATUS_ASSOCIATED) {
			u32 ip = Wifi_GetIP();

			iprintf("\nip: [%i.%i.%i.%i]\n", (ip ) & 0xFF, (ip >> 8) & 0xFF, (ip >> 16) & 0xFF, (ip >> 24) & 0xFF);
			while(1) {

				scanf("%s", url);

				if ( 0 == strcmp(url,"quit")) break;

				struct hostent *host = gethostbyname(url);

				if(host)
					iprintf("IP (%s) : %s\n",  url, inet_ntoa(*(struct in_addr *)host->h_addr_list[0]));
				else
					iprintf("Could not resolve\n");

				swiWaitForVBlank();
			}
		} else {
Exemplo n.º 4
0
//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------
	Wifi_InitDefault(false);
	
	consoleDemoInit(); 

	//Keyboard* kb = keyboardDemoInit();
	//kb->OnKeyPressed = keyPressed;

	while(1);

	{
		int status = ASSOCSTATUS_DISCONNECTED;

		consoleClear();

		Wifi_AccessPoint* ap = findAP();

		iprintf("Connecting to %s\n", ap->ssid);

		//this tells the wifi lib to use dhcp for everything
		Wifi_SetIP(0,0,0,0,0);	

		Wifi_ConnectAP(ap, WEPMODE_NONE, 0, 0);

		while(status != ASSOCSTATUS_ASSOCIATED && status != ASSOCSTATUS_CANNOTCONNECT) {
			int oldStatus = status;

			status = Wifi_AssocStatus();

			iprintf("%s", oldStatus != status ? ASSOCSTATUS_STRINGS[status] : ".");

			scanKeys();

			if(keysDown() & KEY_B) break;
			
			swiWaitForVBlank();
		}
		consoleClear();
		consoleSetWindow(NULL, 0,0,32,10);

		char url[256];

		if(status == ASSOCSTATUS_ASSOCIATED) {
			while(1) {
				u32 ip = Wifi_GetIP();

				iprintf("ip: [%i.%i.%i.%i]", (ip ) & 0xFF, (ip >> 8) & 0xFF, (ip >> 16) & 0xFF, (ip >> 24) & 0xFF);

				scanf("%s", url);

				struct hostent *host = gethostbyname(url);

				if(host)
					iprintf("IP (%s) : %s\n",  url, inet_ntoa(*(struct in_addr *)host->h_addr_list[0]));
				else
					iprintf("Could not resolve\n");

				scanKeys();

				if(keysDown() & KEY_B) break;

				swiWaitForVBlank();
			}
		}
	}
	return 0;
}