/* 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; }
//--------------------------------------------------------------------------------- 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; }
//--------------------------------------------------------------------------------- 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 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; }