Sub topic 10
How a Device Finds and Joins a Network
This chapter follows a device from "I see no network" to "I can send IP packets." It assumes you know what an SSID, a BSSID and a BSS are from the previous chapter, and that you can read short Python and shell snippets. It also assumes you know what a channel is. Security details (WPA2 and WPA3) get their own chapter. Here the security step is only a stage in the sequence.
The four stages
A Wi-Fi client does not simply "connect." It moves through a fixed sequence of states defined by 802.11:
- Discovery. The client learns that an access point (AP) exists, on which channel, and what it supports.
- Authentication. The client and AP exchange a short 802.11 handshake. In modern networks this step is mostly a formality.
- Association. The client asks to become a member of the AP's BSS, and the AP assigns it an association ID (AID).
- Security and IP setup. The client runs the WPA handshake to derive encryption keys, then uses DHCP to get an IP address.
Only after association can the client send ordinary data frames through the AP. Only after the security handshake are those frames encrypted.
Discovery: beacons and probes
Discovery happens in one of two ways.
Passive scanning. An AP broadcasts a beacon frame at a regular interval. The default is 100 time units, where one time unit is 1.024 ms, so about every 102.4 ms. A beacon carries:
- the SSID (unless hidden) and the BSSID
- the beacon interval and a timestamp
- the supported rates and capabilities (for example HT, VHT or HE)
- the channel and security settings (the RSN information element)
A client that listens on a channel for slightly longer than one beacon interval will hear every AP on that channel.
Active scanning. The client sends a probe request and waits briefly for probe responses. The request can name a specific SSID (a directed probe) or use an empty SSID (a wildcard probe). APs that match reply directly to the client with the same information a beacon carries.
Either way, the client must visit each channel in turn, because a radio listens on only one channel at a time. A scan across 2.4 GHz, 5 GHz and 6 GHz can touch dozens of channels, which is why a full scan takes a noticeable amount of time.
Scanning rules that affect behavior
- DFS channels. On 5 GHz channels where radar must be avoided, a client generally may not transmit first. It scans these channels passively and waits for a beacon.
- 6 GHz. Clients commonly learn about 6 GHz APs through hints in beacons or probe responses from 2.4 or 5 GHz APs, which avoids scanning every 6 GHz channel. Active probing there is restricted by regulation to certain situations.
- Hidden SSIDs. An AP can leave the SSID blank in beacons. The client then must send directed probes. This does not hide the network from anyone with a scanner, because the SSID appears in the probe and association frames, and it forces clients to broadcast the names of networks they know.
Authentication
The 802.11 authentication step comes from the original standard. Two kinds exist:
- Open System authentication. The client sends an authentication request, and the AP replies with success. It proves nothing. WPA2-Personal and WPA3 enterprise-style networks use it as a placeholder, and real checks happen later.
- SAE (Simultaneous Authentication of Equals). WPA3-Personal replaces the placeholder with a real password-based exchange during this step.
The older Shared Key (WEP) method is obsolete and should not be used.
Association
After authentication, the client sends an association request. It contains the SSID, the rates it supports, and its capabilities, such as channel widths, number of spatial streams and which 802.11 amendments it understands. The AP answers with an association response that contains a status code and the AID.
This is where the two sides agree on what the link can do. The result is the lower of what each side supports. A Wi-Fi 6 client that associates with a Wi-Fi 5 AP will use Wi-Fi 5 features on that link.
A failed association returns a status code. Common causes include a full AP, no common supported rates, or a security mismatch.
The security handshake and IP setup
After association, WPA2 and WPA3 networks run the 4-way handshake. Both sides already know a shared secret, and the handshake derives fresh session keys from it. Until it finishes, the AP blocks everything except these handshake frames (this is called the controlled port being closed).
When the keys are installed, the client sends DHCP requests and the network gives it an IP address, gateway and DNS server. Many "connected but no internet" problems occur here, not at the radio level, so remember that a Wi-Fi association says nothing about IP.
Leaving a network
A client or AP ends the relationship with a disassociation frame (the client stays authenticated and can re-associate) or a deauthentication frame (the client must start over). Unprotected deauthentication frames can be forged, which is why protected management frames (PMF) are required in WPA3.
Reading discovery data from a tool
On Linux, iw shows what discovery found. The following commands list nearby APs and report your current link:
# Current connection state: BSSID, frequency, signal, bit rates
iw dev wlan0 link
# Scan results: BSSID, frequency, signal and SSID per AP
sudo iw dev wlan0 scan | grep -E '^BSS|freq:|signal:|SSID:'Each BSS line is a BSSID. If one SSID shows several BSS lines, the network has several APs or several radios. The freq field is the channel's center frequency, which you can convert back to a channel number with the formula in the channels chapter.
The next script parses saved iw scan output and groups BSSIDs by SSID. It reads the text from standard input:
import re
import sys
from collections import defaultdict
networks = defaultdict(list)
bssid = freq = signal = None
for line in sys.stdin:
line = line.strip()
m = re.match(r"BSS ([0-9a-f:]{17})", line)
if m:
bssid = m.group(1)
elif line.startswith("freq:"):
freq = line.split()[1]
elif line.startswith("signal:"):
signal = line.split()[1]
elif line.startswith("SSID:"):
ssid = line[5:].strip() or "(hidden)"
networks[ssid].append((bssid, freq, signal))
for ssid, aps in networks.items():
print(ssid)
for b, f, s in aps:
print(f" {b} {f} MHz {s} dBm")Run it with sudo iw dev wlan0 scan | python3 parse_scan.py. The scan prints SSID: after the freq: and signal: lines of each entry, so each entry is complete when the SSID line is reached. A hidden network appears with an empty SSID and is shown as (hidden).
Common errors
| Symptom | Likely stage | Typical cause |
|---|---|---|
| Network not listed | Discovery | AP on a channel or band the client does not support, hidden SSID, or a DFS channel not yet heard |
| Repeated password prompt | Security handshake | Wrong passphrase or WPA mode mismatch |
| Association rejected | Association | AP at capacity, no common rates, or PMF required but unsupported |
| Connected, no internet | IP setup | DHCP failure or no upstream route |
| Slow join | Discovery | Long scan across many channels |
Exercise
A laptop sees the SSID "Office" on 5 GHz but is stuck on a password prompt that keeps reappearing. At which stage of joining does the failure most likely happen, and why can it not be the discovery stage?
Show answer
The failure is most likely in the security handshake (the 4-way handshake, or SAE on WPA3), which comes after association. The laptop already sees "Office", so discovery worked: it heard a beacon or probe response. The repeated prompt points to a wrong passphrase or a security mode mismatch.
Exercise
An AP sends beacons with the default interval of 100 time units. About how long must a client listen on one channel to be sure of hearing a beacon, and why does this make scanning many channels slow?
Show answer
Slightly more than 102.4 ms (100 x 1.024 ms). Because a radio listens on one channel at a time, a passive scan multiplies that time by the number of channels, which can reach several seconds across three bands. Active probing shortens the wait per channel.