Wi-Fi MAC Layer: Scanning, Authentication, Association, and Data Transmission Processes

UsingWi‑Fias an example, theMAC layeris the "network access manager" that sits above the PHY/Baseband and decides how a device joins a network, gains access to the medium, exchanges frames, retries lost packets, and maintains connectivity.

A simplified Wi‑Fi stack looks like:

Application TCP/IP ↓ 802.11 MAC ↓ 802.11 PHY/Baseband ↓ RF ↓ Antenna

The MAC layer performs:

  • Scanning

  • Authentication

  • Association

  • Security key exchange

  • Data transmission

  • Retransmission

  • Roaming

  • Power saving

Let's walk through what happens when an ESP32-S31 connects to a Wi‑Fi AP.


Step 1: Scanning

Before connecting, the STA (station, e.g., ESP32) must discover available APs.

Passive Scan

The STA simply listens.

APs periodically send:

Beacon Frame

containing:

SSID Channel BSSID Security Mode Supported Rates Capabilities

Example:

SSID: HomeWiFi Channel: 6 Security: WPA2

Active Scan

The STA sends:

Probe Request

Example:

Who has SSID "HomeWiFi"?

AP replies:

Probe Response

At this stage, the MAC is handling management frames.

STA -------------------> Probe Request STA <------------------- Probe Response

Step 2: Authentication

Historically, 802.11 defined an authentication procedure before association.

Open System Authentication

Today this is the most common.

STA sends:

Authentication Request `

AP replies:

Authentication Response (Status = Success)
STA AP Authentication Request -----> <------- Authentication Response

This doesnotyet verify the Wi‑Fi password.

It simply says:

You may proceed to associate.

Step 3: Association

Now the station asks to join the AP.

Association Request

Contains:

SSID Supported Data Rates Capabilities QoS Features HT/VHT/HE Capabilities

Example:

I support: 802.11n MCS0~MCS7 WPA2 QoS

Association Response

AP replies:

Association ID (AID) Status Capabilities

Example:

AID = 0x0021 Status = Success

At this point:

STA is associated

but encrypted data is still unavailable.

STA AP Assoc Req -------------> <------- Assoc Resp

Step 4: WPA/WPA2/WPA3 Security

Now comes the real security process.

For WPA2-PSK the famous:

4-Way Handshake

occurs.


Goal

Both sides derive:

PTK (Pairwise Transient Key)

used to encrypt traffic.


Message 1

AP sends:

ANonce

Message 2

STA sends:

SNonce MIC

Message 3

AP sends:

Install Key GTK

Message 4

STA acknowledges.

AP STA M1 ANonce ------------> <---- M2 SNonce M3 GTK -------------> <---- M4 ACK

After this:

Encrypted traffic enabled

Now IP traffic can start.


Step 5: DHCP

This is above the MAC layer but happens immediately afterward.

DHCP Discover DHCP Offer DHCP Request DHCP ACK

Now the device obtains:

IP Address Gateway DNS

Example:

192.168.1.105

Step 6: Data Transmission

Once connected, the Wi‑Fi MAC handles frame delivery.

Example:

TCP Packet

becomes:

802.11 Data Frame

containing:

MAC Header Payload FCS

MAC Addressing

Each device has:

48-bit MAC Address

Example:

ESP32: 84:FC:E6:12:34:56 AP: 18:E8:29:AA:BB:CC

The MAC layer inserts source and destination addresses into every frame.


CSMA/CA

Wi‑Fi MAC must share the air with other devices.

Unlike Ethernet:

Can't detect collisions reliably

So Wi‑Fi uses:

CSMA/CA

Carrier Sense Multiple Access with Collision Avoidance.


Example:

Device A wants to send.

MAC first listens.

Channel Busy?

If yes:

Wait Random Backoff Retry

If no:

Transmit
Listen ↓ Busy? ↓ Wait ↓ Backoff ↓ Transmit

This logic is entirely MAC-level.


ACK and Retransmission

After every unicast frame:

Receiver sends ACK.
STA ---------- Data ----------> <------ ACK -----------

If no ACK arrives:

Retransmit `

The MAC maintains:

Retry Counter Sequence Number Duplicate Detection

This happens below TCP/IP.


Power Save

For battery devices, the MAC supports sleeping.

AP periodically indicates:

Buffered packets waiting.

through beacon information.

Station behavior:

Sleep Wake Check Beacon Retrieve Data Sleep Again

This is one reason Wi‑Fi IoT devices can save power.


Roaming

When signal quality drops:

RSSI ↓

the MAC scans for another AP.

Example:

AP1 -> AP2

The MAC performs:

Re-authentication Re-association Key Updates

while trying to keep connectivity.


Inside an ESP32-S31

Very roughly:

Application ↓ TCP/IP Stack ↓ Wi-Fi MAC ├─ Scanning ├─ Authentication ├─ Association ├─ Security ├─ ACK ├─ Retries ├─ Power Save └─ Roaming ↓ Wi-Fi Baseband ├─ OFDM ├─ Modulation ├─ Encoding └─ Synchronization ↓ RF ├─ 2.4 GHz LO ├─ PA ├─ LNA └─ Antenna

A useful rule of thumb

  • MACdecideswho can talk, when to talk, and who we're talking to.

  • Basebandconverts packets into Wi‑Fi symbols and vice versa.

  • RFconverts those symbols into actual 2.4 GHz radio waves.

So when you see logs like:

wifi: scan start wifi: authentication success wifi: association success wifi: connected

those events are primarily being driven by theWi‑Fi MAC layer, while the baseband and RF are the engines that physically move the bits through the air.

相关新闻

ROS2笔记1

ROS2笔记1

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/11/19 3:15:53 阅读更多 →
26 精武杯手机部分复盘

26 精武杯手机部分复盘

【简要案情】 近期&#xff0c;某市反诈部门接到多名群众报案&#xff0c;均遭遇“投资理财”类电信网络诈骗&#xff0c;指向的犯罪团伙涉案资金巨大、作案链条隐蔽。办案单位迅速成立专案组开展电子数据取证工作。经初查&#xff0c;该犯罪团伙搭建虚假投资平台&#xff0c;通…

2026/10/27 9:11:53 阅读更多 →
PHP安全漏洞修复指南:防SQL注入与XSS

PHP安全漏洞修复指南:防SQL注入与XSS

一、为什么 PHP 项目总被盯上做 PHP 开发这些年&#xff0c;我见过太多项目上线后被黑的情况。说句实话&#xff0c;大部分漏洞并不是什么高深的技术&#xff0c;翻来覆去就是 SQL 注入和 XSS 这两类。很多新手写代码的时候图省事&#xff0c;直接把用户输入拼进 SQL 语句&…

2026/10/27 9:11:52 阅读更多 →

最新新闻

Electron桌面应用开发实战:从环境搭建到打包发布全流程

Electron桌面应用开发实战:从环境搭建到打包发布全流程

做前端这些年&#xff0c;我大部分时间都在跟浏览器标签页打交道&#xff0c;直到第一次把桌面应用跑起来&#xff0c;才发现原来自己一直被限制在地址栏和刷新按钮围起来的框框里。Electron这个词&#xff0c;最开始是在某段时间频繁出现在同事的讨论里&#xff0c;一个用HTML…

2026/11/18 13:59:04 阅读更多 →
滑盖智能锁T109深度解析:结构原理、安装调试与故障排查

滑盖智能锁T109深度解析:结构原理、安装调试与故障排查

简介&#xff1a;亚太天能T109滑盖智能锁产品说明书是一份PDF格式的官方技术文档&#xff0c;主要面向智能锁安装人员、终端用户及售后维护者&#xff0c;帮助快速掌握产品安装、配置与常见故障处理。全包仅1个PDF文件&#xff0c;大小4.37MB&#xff0c;内容结构清晰&#xff…

2026/11/18 15:33:23 阅读更多 →
PMSM弱磁控制原理与Simulink建模:高速AGV驱动系统设计指南

PMSM弱磁控制原理与Simulink建模:高速AGV驱动系统设计指南

上个月我在调试一台高速AGV的驱动系统&#xff0c;整车要求空载跑到8m/s&#xff0c;电机转速已经拉到额定点&#xff0c;驱动器的输出电压也顶到了母线电压极限附近。再往上踩速度指令&#xff0c;转速纹丝不动&#xff0c;三相电流反而开始震荡。那会儿我的第一反应就是&…

2026/11/18 17:05:28 阅读更多 →
C++核心知识点:从内存管理到STL的实战指南

C++核心知识点:从内存管理到STL的实战指南

C 这门语言我前前后后折腾了十几年&#xff0c;用它写过嵌入式驱动、做过游戏服务端&#xff0c;也搭过基础组件库。每次看到新人一头扎进"C 核心知识点"这个搜索词&#xff0c;我其实挺感慨的——这门语言的难点从来不是语法多&#xff0c;而是知识点之间的耦合太深…

2026/11/18 14:33:19 阅读更多 →
T109滑盖智能锁怎么装?安装调试与故障排查全攻略

T109滑盖智能锁怎么装?安装调试与故障排查全攻略

简介&#xff1a;亚太天能T109滑盖智能锁产品说明书以PDF格式发布&#xff0c;适合智能锁用户、安装人员与售后维修人员阅读。内容围绕T109系列指纹密码刷卡锁展开&#xff0c;先介绍前面板、后面板、锁体、机械钥匙、电池盒盖等部件名称与功能&#xff0c;再给出完整安装步骤&…

2026/11/18 17:05:28 阅读更多 →
LLM知识降熵:从信息垄断到理解权下放

LLM知识降熵:从信息垄断到理解权下放

你有没有过这种经历&#xff1a;翻开源码注释、论文摘要或者一份专业报告&#xff0c;每个字都认识&#xff0c;连在一起却像天书。想找人聊聊&#xff0c;身边要么没人懂&#xff0c;要么懂的懒得跟你解释。后来我试着把同一段内容丢给一个大语言模型&#xff0c;几秒钟之后&a…

2026/11/18 14:13:08 阅读更多 →

日新闻

周新闻

月新闻