Exemple #1
0
/* 
 * Waits for a beacon packet from the target AP and populates the globule->ap_capabilities field.
 * This is used for obtaining the capabilities field and AP SSID.
 */
void read_ap_beacon()
{
        struct pcap_pkthdr header;
        const unsigned char *packet = NULL;
        struct radio_tap_header *rt_header = NULL;
        struct dot11_frame_header *frame_header = NULL;
        struct beacon_management_frame *beacon = NULL;
	int channel = 0;
	size_t tag_offset = 0;
	time_t start_time = 0;

	set_ap_capability(0);
	start_time = time(NULL);
	
        while(get_ap_capability() == 0)
        {
                packet = next_packet(&header);
                if(packet == NULL)
                {
                        break;
                }

                if(header.len >= MIN_BEACON_SIZE)
                {
                        rt_header = (struct radio_tap_header *) radio_header(packet, header.len);
			size_t rt_header_len = end_le16toh(rt_header->len);
			frame_header = (struct dot11_frame_header *) (packet + rt_header_len);
			
			if(is_target(frame_header))
			{
                                if((frame_header->fc & end_htole16(IEEE80211_FCTL_FTYPE | IEEE80211_FCTL_STYPE)) ==
				   end_htole16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_BEACON))
                                {
                                       	beacon = (struct beacon_management_frame *) (packet + rt_header_len + sizeof(struct dot11_frame_header));
                                       	set_ap_capability(end_le16toh(beacon->capability));

					/* Obtain the SSID and channel number from the beacon packet */
					tag_offset = rt_header_len + sizeof(struct dot11_frame_header) + sizeof(struct beacon_management_frame);
					channel = parse_beacon_tags(packet, header.len);
					
					/* If no channel was manually specified, switch to the AP's current channel */
					if(!get_fixed_channel() && get_auto_channel_select() && channel > 0 && channel != get_channel())
					{
						change_channel(channel);
						set_channel(channel);
					}

                                       	break;
				}
			}
                }

		/* If we haven't seen any beacon packets from the target within BEACON_WAIT_TIME seconds, try another channel */
		if((time(NULL) - start_time) >= BEACON_WAIT_TIME)
		{
			next_channel();
			start_time = time(NULL);
		}
        }
}
/* 
 * Waits for a beacon packet from the target AP and populates the globule->ap_capabilities field.
 * This is used for obtaining the capabilities field and AP SSID.
 */
void read_ap_beacon()
{
    struct pcap_pkthdr header;
    const u_char *packet = NULL;
    struct radio_tap_header *rt_header = NULL;
    struct dot11_frame_header *frame_header = NULL;
    struct beacon_management_frame *beacon = NULL;
    int channel = 0;
    time_t start_time = 0;

    set_ap_capability(0);
    start_time = time(NULL);

    while(get_ap_capability() == 0)
    {
        packet = next_packet(&header);
        if(packet == NULL)
        {
            break;
        }

        if(header.len >= MIN_BEACON_SIZE)
        {
            rt_header = (struct radio_tap_header *) radio_header(packet, header.len);
            frame_header = (struct dot11_frame_header *) (packet + rt_header->len);

            if(is_target(frame_header))
            {
                if(frame_header->fc.type == MANAGEMENT_FRAME && frame_header->fc.sub_type == SUBTYPE_BEACON)
                {
                    beacon = (struct beacon_management_frame *) (packet + rt_header->len + sizeof(struct dot11_frame_header));
                    set_ap_capability(beacon->capability);

                    /* Obtain the SSID and channel number from the beacon packet */
                    channel = parse_beacon_tags(packet, header.len);

                    /* If no channel was manually specified, switch to the AP's current channel */
                    if(!get_fixed_channel() && get_auto_channel_select() && channel > 0 && channel != get_channel())
                    {
                        change_channel(channel);
                        set_channel(channel);
                    }

                    break;
                }
            }
        }

        /* If we haven't seen any beacon packets from the target within BEACON_WAIT_TIME seconds, try another channel */
        if((time(NULL) - start_time) >= BEACON_WAIT_TIME)
        {
            next_channel();
            start_time = time(NULL);
        }
    }
}