int Wifi_FindMatchingAP(int numaps, Wifi_AccessPoint * apdata, Wifi_AccessPoint * match_dest) {
	int ap_match,i,j,n;
	Wifi_AccessPoint ap;
	u16 macaddrzero[3] = {0,0,0}; // check for empty mac addr
	ap_match=-1;
	for(i=0;i<Wifi_GetNumAP();i++){
		Wifi_GetAPData(i,&ap);
		for(j=0;j<numaps;j++) {
			if(apdata[j].ssid_len>32 || ((signed char)apdata[j].ssid_len)<0) continue;
			if(apdata[j].ssid_len>0) { // compare SSIDs
				if(apdata[j].ssid_len!=ap.ssid_len) continue;
				for(n=0;n<apdata[j].ssid_len;n++) {
					if(apdata[j].ssid[n]!=ap.ssid[n]) break;
				}
				if(n!=apdata[j].ssid_len) continue;
			}
			if(!Wifi_CmpMacAddr(apdata[j].macaddr,macaddrzero)) { // compare mac addr
				if(!Wifi_CmpMacAddr(apdata[j].macaddr,ap.macaddr)) continue;
			}
			if(apdata[j].channel!=0) { // compare channels
				if(apdata[j].channel!=ap.channel) continue;
			}
			if(j<ap_match || ap_match==-1) {
				ap_match=j;
				if(match_dest) *match_dest = ap;
			}
			if(ap_match==0) return ap_match;
		}
	}
	return ap_match;
}
Пример #2
0
static void topbar_update_wifi(void)
{
#if 0    
    char txt[32];
    Wifi_AccessPoint ap;
    int i, num, l=8;
    num = Wifi_GetNumAP();
    pj_ansi_snprintf(txt, 32, "%d", num);
    printbtm(7,0, txt);
    for (i = 0; i < num; ++i)
    {
    Wifi_GetAPData(i, &ap);
    int quality = (ap.rssi*100)/0xD0;
    pj_ansi_snprintf(txt, 32, "%20s:%3d%%", ap.ssid, quality);
    l += i;
    printbtm(8+i,0, txt);
    if (l==12)
        l = 8;
    }
#endif    
}
Пример #3
0
void wardriving_loop()
{
	int num_aps, i, index, flags, pressed;
	touchPosition touchXY;
	Wifi_AccessPoint cur_ap;
	u32 lasttick;
	char state, display_state;
	/* Vars for AP_DISPLAY */
	int entry_n;
	struct AP_HT_Entry *entry = NULL;

	print_to_debug("Setting scan mode...");

	Wifi_ScanMode();
	state = STATE_SCANNING;
	display_state = STATE_CONNECTING;

	for (i = 0; i < 3; i++) {
		sizes[i] = DEFAULT_ALLOC_SIZE;
		num[i] = num_null[i] = 0;
		first_null[i] = -1;
		ap[i] = (struct AP_HT_Entry **)
		    malloc(sizes[i] * sizeof(struct AP_HT_Entry *));
		if (ap[i] == NULL)
			abort_msg("alloc failed");
	}

	flags = DISP_WPA | DISP_OPN | DISP_WEP;
	memset(modes, 0, sizeof(modes));
	strcpy(modes, "OPN+WEP+WPA");

	index = 0;

	TIMER0_CR = TIMER_ENABLE | TIMER_DIV_1024;
	TIMER1_CR = TIMER_ENABLE | TIMER_CASCADE;
	lasttick = tick();

	while (1) {
		switch (state) {
		case STATE_SCANNING:
			curtick = tick();

			/* Wait for VBL just before key handling and redraw */
			swiWaitForVBlank();
			scanKeys();
			pressed = keysDown();

			/* Handle stylus press to display more detailed infos 
			 * handle this before AP insertion, to avoid race
			 * conditions */
			if (pressed & KEY_TOUCH) {
				touchRead(&touchXY);
				/* Entry number : 8 pixels for text, 3 lines */
				entry_n = touchXY.py / 8 / 3;
				entry = cur_entries[entry_n];
#ifdef DEBUG
				printf_to_debug("Entry : Y : %d\n", entry_n);
				printf_to_debug("SSID : %s\n", entry->ap->ssid);
#endif
				if (entry) {
					state = STATE_AP_DISPLAY;
					//display_state = STATE_PACKET_INIT;
					display_state = STATE_CONNECTING;
					print_to_debug("Packet scan mode");
					print_to_debug(" A : try to connect");
					print_to_debug(" B : back to scan");
					break;
				}
			}

			num_aps = Wifi_GetNumAP();
			for (i = 0; i < num_aps; i++) {
				if (Wifi_GetAPData(i, &cur_ap) !=
				    WIFI_RETURN_OK)
					continue;
				insert_ap(&cur_ap);
			}

			/* Check timeouts every second */
			if (timeout && (curtick - lasttick > 1000)) {
				lasttick = tick();
				clean_timeouts(lasttick);
			}

			if (pressed & KEY_RIGHT)
				timeout += 5000;
			if (pressed & KEY_LEFT && timeout > 0)
				timeout -= 5000;

			if (pressed & KEY_DOWN)
				index++;
			if (pressed & KEY_UP && index > 0)
				index--;
			if (pressed & KEY_R
			    && (index + (DISPLAY_LINES - 1)) <= numap)
				index += DISPLAY_LINES - 1;
			if (pressed & KEY_L && index >= DISPLAY_LINES - 1)
				index -= DISPLAY_LINES - 1;

			if (pressed & KEY_B)
				flags ^= DISP_OPN;
			if (pressed & KEY_A)
				flags ^= DISP_WEP;
			if (pressed & KEY_X)
				flags ^= DISP_WPA;

			/* Update modes string */
			if (pressed & KEY_B || pressed & KEY_A
			    || pressed & KEY_X) {
				modes[0] = 0;
				if (flags & DISP_OPN)
					strcat(modes, "OPN+");
				if (flags & DISP_WEP)
					strcat(modes, "WEP+");
				if (flags & DISP_WPA)
					strcat(modes, "WPA+");
				modes[strlen(modes) - 1] = 0;	/* remove the + */
			}

			display_list(index, flags);
			break;

		case STATE_AP_DISPLAY:
			switch (display_state) {
			case STATE_CONNECTING:
				/* TODO:
				 * 1) default to packet display
				 * 2) try DHCP [DONE]
				 * 3) try default IPs
				 * 4) handle WEP ?
				 */
				/* Try to connect */
				if (!(entry->ap->flags & WFLAG_APDATA_WPA) &&
				    !(entry->ap->flags & WFLAG_APDATA_WEP)) {
					print_to_debug
					    ("Trying to connect to :");
					print_to_debug(entry->ap->ssid);
					if (entry->ap->rssi <= 40)
						print_to_debug
						    ("Warning : weak signal");
					print_to_debug("Press B to cancel");
					switch (connect_ap(entry->ap)) {
					case ASSOCSTATUS_ASSOCIATED:
						display_state =
						    STATE_CONNECTED_FIRST;
						break;

					default:
						print_to_debug("Cnx failed");
						state = STATE_SCANNING;
						Wifi_ScanMode();
					}
				} else {
					print_to_debug
					    ("WEP/WPA AP not supported");
					state = STATE_SCANNING;
					break;
				}
				break;

			case STATE_CONNECTED_FIRST:
				display_ap(entry->ap, 1);
				display_state = STATE_CONNECTED;
				break;

			case STATE_CONNECTED:
				display_ap(entry->ap, 0);
				break;

			case STATE_PACKET_INIT:
				memcpy(mac_filter, entry->ap->macaddr, 6);
				Wifi_SetChannel(entry->ap->channel);
				Wifi_RawSetPacketHandler(cap_handler);
				Wifi_SetPromiscuousMode(1);
				display_state = STATE_PACKET;
				break;

			case STATE_PACKET:
				Wifi_Update();
				if (valid_packet)
					print_to_debug("Un paquet !\n");
				else
					print_to_debug("No paquet !\n");
				break;
			}

			scanKeys();
			if (keysDown() & KEY_A && state == STATE_PACKET) {
				state = STATE_CONNECTING;
			}
			if (keysDown() & KEY_B) {
				print_to_debug("Back to scan mode");
				state = STATE_SCANNING;
				Wifi_RawSetPacketHandler(NULL);
				Wifi_SetPromiscuousMode(0);
				Wifi_ScanMode();
			}
			swiWaitForVBlank();
			break;
		}
	}
}
Пример #4
0
//---------------------------------------------------------------------------------
Wifi_AccessPoint* findAP(void){
//---------------------------------------------------------------------------------

	int selected = 0;  
	int i;
	int count = 0, displaytop = 0;

	static Wifi_AccessPoint ap;

	Wifi_ScanMode(); //this allows us to search for APs

	int pressed = 0;
	do {
		scanKeys();

		//find out how many APs there are in the area
		count = Wifi_GetNumAP();


		consoleClear();

		iprintf("%d APs detected\n\n", count);

		int displayend = displaytop + 10;
		if (displayend > count) displayend = count;

		//display the APs to the user
		for(i = displaytop; i < displayend; i++) {
			Wifi_AccessPoint ap;

			Wifi_GetAPData(i, &ap);

			// display the name of the AP
			iprintf("%s %.29s\n  Wep:%s Sig:%i\n", 
				i == selected ? "*" : " ", 
				ap.ssid, 
				ap.flags & WFLAG_APDATA_WEP ? "Yes " : "No ",
				ap.rssi * 100 / 0xD0);

		}

		pressed = keysDown();
		//move the selection asterick
		if(pressed & KEY_UP) {
			selected--;
			if(selected < 0) {
				selected = 0;
			}
			if(selected<displaytop) displaytop = selected;
		}

		if(pressed & KEY_DOWN) {
			selected++;
			if(selected >= count) {
				selected = count - 1;
			}
			displaytop = selected - 9;
			if (displaytop<0) displaytop = 0;
		}
		swiWaitForVBlank();
	} while(!(pressed & KEY_A));

	//user has made a choice so grab the ap and return it
	Wifi_GetAPData(selected, &ap);

	return &ap;
}
Пример #5
0
//---------------------------------------------------------------------------------
Wifi_AccessPoint* findAP(void){
	//---------------------------------------------------------------------------------

	int selected = 0;  
	int i;
	int count = 0;

	static Wifi_AccessPoint ap;

	Wifi_ScanMode(); //this allows us to search for APs

	while(!(keysDown() & KEY_A))
	{
		scanKeys();

		//find out how many APs there are in the area
		count = Wifi_GetNumAP();

		consoleClear();

		iprintf("Number of APs found: %d\n", count);

		//display the APs to the user
		for(i = 0; i < count; i++)
		{
			Wifi_AccessPoint ap;

			Wifi_GetAPData(i, &ap);

			// display the name of the AP
			iprintf("%s %s Wep:%s Sig:%i\n", 
				i == selected ? "*" : " ", 
				ap.ssid, 
				ap.flags & WFLAG_APDATA_WEP ? "Yes " : "No ",
				ap.rssi * 100 / 0xD0);

		}

		//move the selection asterick
		if(keysDown() & KEY_UP)
		{
			selected--;
			if(selected < 0)
			{
				selected = 0;
			}
		}

		if(keysDown()&KEY_DOWN)
		{
			selected++;
			if(selected >= count) 
			{
				selected = count - 1;
			}
		}

		swiWaitForVBlank();
	}

	//user has made a choice so grab the ap and return it
	Wifi_GetAPData(selected, &ap);

	return &ap;
}