Example #1
0
/* Deauths and re-associates a MAC address with the AP. Returns 0 on failure, 1 for success. */
int reassociate()
{
    int tries = 0, retval = 0;

    /* Make sure we can still see beacons (also, read_ap_beaon will ensure we're on the right channel) */
    read_ap_beacon();

    if(!get_external_association())
    {
        /* Deauth to void any previous association with the AP */
        deauthenticate();

        /* Try MAX_AUTH_TRIES times to authenticate to the AP */
        do
        {
            authenticate();
            tries++;
        }
        while((associate_recv_loop() != AUTH_OK) && (tries < MAX_AUTH_TRIES));

        /* If authentication was successful, try MAX_AUTH_TRIES to associate with the AP */
        if(tries < MAX_AUTH_TRIES)
        {
            tries = 0;

            do
            {
                associate();
                tries++;
            }
            while((associate_recv_loop() != ASSOCIATE_OK) && (tries < MAX_AUTH_TRIES));
        }

        if(tries < MAX_AUTH_TRIES)
        {
            retval = 1;
        }
        else
        {
            retval = 0;
        }
    }
    else
    {
        retval = 1;
    }

    return retval;
}
Example #2
0
/* Deauths and re-associates a MAC address with the AP. Returns 0 on failure, 1 for success. */
int reassociate(void)
{
	if (get_external_association()) return 1;

	int state = 0, ret;

	while(1) {
		switch(state) {
			case 0:
				deauthenticate();
				state++;
				break;
			case 1:
				authenticate();
				state++;
				break;
			case 2:
				ret = process_authenticate_associate_resp(0);
				if(ret) state++;
				else return 0;
				break;
			case 3:
				associate();
				state++;
				break;
			case 4:
				ret = process_authenticate_associate_resp(0);
				if(ret) state++;
				else return 0;
				break;
			case 5:
				return 1;

		}
	}
}