Beispiel #1
0
/* Try to connect to given AP and get an IP via DHCP */
int connect_ap(Wifi_AccessPoint * ap)
{
	int ret;
	int status = ASSOCSTATUS_DISCONNECTED;

	clear_main();

	/* Ask for DHCP */
	Wifi_SetIP(0, 0, 0, 0, 0);
	ret = Wifi_ConnectAP(ap, WEPMODE_NONE, 0, NULL);
	if (ret) {
		print_to_debug("error connecting");
		return ASSOCSTATUS_CANNOTCONNECT;
	}

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

		status = Wifi_AssocStatus();
		if (oldStatus != status)
			printf_to_main("\n%s",
				       (char *)ASSOCSTATUS_STRINGS[status]);
		else
			printf_to_main(".");

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

	return status;
}
Beispiel #2
0
/* Display IP data for connected AP */
void display_ap(Wifi_AccessPoint * ap, int new_ap)
{
	static struct in_addr ip, gw, sn, dns1, dns2;
	int status;
	static struct hostent *google_addr = NULL;
	static struct in_addr g_ip;
	static int errno_cache;

	clear_main();

	status = Wifi_AssocStatus();

	print_xy(0, 0, "SSID :");
	print_xy(0, 1, ap->ssid);
	print_xy(0, 3, "State :");
	printf_xy(0, 4, "%s", ASSOCSTATUS_STRINGS[status]);
	if (status == ASSOCSTATUS_ASSOCIATED) {
		ip = Wifi_GetIPInfo(&gw, &sn, &dns1, &dns2);

		printf_xy(0, 6, "IP :        %s", inet_ntoa(ip));
		printf_xy(0, 7, "Subnet :    %s", inet_ntoa(sn));
		printf_xy(0, 8, "GW :        %s", inet_ntoa(gw));
		printf_xy(0, 9, "DNS1 :      %s", inet_ntoa(dns1));
		printf_xy(0, 10, "DNS2 :      %s", inet_ntoa(dns2));

		/* new association, try Google again */
		if (new_ap) {
			DEBUG_PRINT("new ap!");
			google_addr = gethostbyname("www.google.com");
			if (google_addr != NULL) {
				g_ip =
				    *(struct in_addr
				      *)(google_addr->h_addr_list[0]);
				if (try_google(&g_ip) == 0) {
					errno_cache = 0;
				} else {
					errno_cache = errno;
				}
			}
		} else {
			if (google_addr == NULL)
				printf_xy(0, 12, "DNS failed");
			else {
				printf_xy(0, 12, "Google IP : %s",
					  inet_ntoa(g_ip));
				if (errno_cache) {
					printf_xy(0, 13, "GET errno : %d",
						  errno_cache);
				} else {
					printf_xy(0, 13,
						  "GET : OK, see top screen");
				}
			}
		}
	}
}
Beispiel #3
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;
    }
}
Beispiel #4
0
int wifi_connect()
{
    iprintf("Connecting with WFC settings...\n");
  
    /* Begin connecting asynchronously */
    Wifi_AutoConnect();

    while (1) {
	switch (Wifi_AssocStatus()) {

	case ASSOCSTATUS_ASSOCIATED:
	    return 1;

	case ASSOCSTATUS_CANNOTCONNECT:
	    return 0;
	}
    }
}
Beispiel #5
0
static int arm9_wifiConnect()
{
    int j = 0, state = 5, delay;
    arm9_wifiInit();
    
    PJ_LOG(3,(THIS_FILE, "Connecting to AP..."));
    while(1) 
    {
        WaitVbl();
        switch(state) 
        {
            case 5: // connect to AP
                state=6;
                // firmware
                Wifi_AutoConnect();
                PJ_LOG(3,(THIS_FILE, "Connecting to Access Point..."));
            case 6:
                j=Wifi_AssocStatus();
                if(j == ASSOCSTATUS_ASSOCIATED) state=30;
                if(j == ASSOCSTATUS_CANNOTCONNECT) state=20;
                break;
            case 20:
                PJ_LOG(3,(THIS_FILE, "Cannot connect to Access Point."));
                return 0;
            case 30:
                delay=60;
                state=31;
            case 31:
                PJ_LOG(3,(THIS_FILE, "Connected!"));
                if(!(delay--)) 
                    return 1;
                break;
        }
    }
   
   return 0;
}
Beispiel #6
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 {
//---------------------------------------------------------------------------------
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;
}
Beispiel #8
0
int
wifi_init(void)
{
    struct links *channel = CHANNELS + CHANNEL_WIFI;
#ifdef _WIN32
    WSADATA wsaData;

    if (WSAStartup(MAKEWORD(2,2), &wsaData) != NO_ERROR) {
        confirm_error("WIFI: Error at WSAStartup()\n", 0);
        return DSH_CONNECTION_FAILED;
    }
#else
    char readtext[33];
    char iptext[33]; // ip address ONLY
    int ret, i, j, oldstatus;

    FILE *fp;

    unsigned char BUF[6];

    iprintf("WIFI: Finding AP...\n");

    fp = fopen("DallShell_Conf.txt","rb");

    if(fp == NULL)
    {
    	ret = Wifi_InitDefault(WFC_CONNECT);
    }
    else
    {
    	Wifi_InitDefault(INIT_ONLY);

    	Wifi_EnableWifi();

    	for(i=0;i<8;i++)
    	{
    		// DallShell Conf ���α׷����� txt���� ���,
    		// �ԷµǴ� ���ڿ� �迭�� ũ�⸦ �÷��� (11.08.29)
    		fgets(readtext,33,fp);
    		memset(iptext,0,33); // iptext�� memory�ʱ�ȭ (11.08.29)
    		switch(i){
    		case 0 : strcpy(ap.ssid,readtext); break;
    		case 1 : ap.ssid_len = atoi(readtext); break;
    		case 2 : ap.channel = atoi(readtext); break;
    		case 3 : memcpy(iptext, readtext, strlen(readtext)-1);
    		MyIP.s_addr = inet_addr(iptext);
    		break;
    		case 4 : memcpy(iptext, readtext, strlen(readtext)-1);
    		gateway.s_addr = inet_addr(iptext);
    		break;
    		case 5 : memcpy(iptext, readtext, strlen(readtext)-1);
    		mask.s_addr = inet_addr(iptext);
    		break;
    		case 6 : memcpy(iptext, readtext, strlen(readtext)-1);
    		dns1.s_addr = inet_addr(iptext);
    		break;
    		case 7 : memcpy(iptext, readtext, strlen(readtext)-1);
    		dns2.s_addr = inet_addr(iptext);
    		break;
    		}
    	}
    	ret = Wifi_ConnectAP(&ap,WEPMODE_NONE,0,0);
    }

    iprintf("MAC : ");
    Wifi_GetData(WIFIGETDATA_MACADDRESS, 6, BUF);
    for (i = 0; i < 6; i++) {
        iprintf("%02X", BUF[i]);
        if (i < 5)
            iprintf(":");
    }
    iprintf("\n\n");

    if(fp == NULL)
    {
    	if(ret == 0)
    	{
    		confirm_error("WIFI:Failed to connect AP!\n", 0);
    		return DSH_CONNECTION_FAILED;
    	}
    	iprintf("NULL");
    	MyIP = Wifi_GetIPInfo(&gateway, &mask, &dns1, &dns2);
    }
    else
    {
    	if(ret != -1)
    	{
    		iprintf("AP Connecting...\n");
    		while(j != ASSOCSTATUS_ASSOCIATED && j!= ASSOCSTATUS_CANNOTCONNECT)
    		{
    			oldstatus = j;
    			j = Wifi_AssocStatus();
    			if(oldstatus != j) {
    				iprintf("%s\n",ASSOCSTATUS_STRINGS[j]);
    				if(j == ASSOCSTATUS_ASSOCIATED )
    				{
    					Wifi_SetIP(MyIP.s_addr,gateway.s_addr,mask.s_addr,dns1.s_addr,dns2.s_addr);
    				}
    			}
    		}
    	}
    }

    iprintf("WIFI: Connected to AP\n"); // Mark that WIFI is available
    iprintf("IP  : %s\n", inet_ntoa(MyIP));
    iprintf("SVIP: %s\n", DOWNLOAD_IP);
#endif

    channel->name = channel_name(CHANNEL_WIFI);
    channel->number =number_connect; // number connect
    channel->connect = wifi_connect;
    channel->read = wifi_read;
    channel->write = wifi_write;
    channel->disconnect = wifi_disconnect;
    channel->cleanup = wifi_cleanup;
    return 0;
}