Skip to content

First, What Is It

  • Protocol: the "language rules" devices use to communicate — how data is arranged, sent, and acknowledged.
  • Layering: split complex communication into layers, each handling one job and only talking to its neighbors — like a company's front desk → department → warehouse.
  • Ai-M6x protocol stack overview: radio (Wi-Fi 6 / BLE) → IP networking (lwIP) → application protocols (HTTP/MQTT/SNTP...); each layer has its SDK implementation and example.

Breaking Down the Principle

1. Network Protocol Classification

Protocols grouped by function, including those used by Ai-M6x:

CategoryProtocolsRoleTutorial page
Wireless linkWi-Fi (802.11), BLEPhysical radio, network accessWi-Fi Intro, BLE Intro
Network layerIP, ICMPAddressing and routing ("to whom")TCP/IP Intro
Transport layerTCP, UDPReliable/unreliable delivery ("how")TCP Client, UDP Client
Application layerHTTP/S, MQTT/S, SNTP, DNS, WebSocketBusiness-oriented data formatsHTTP Intro, MQTT, SNTP
Application layer (BLE)GATT/ATT, HIDData organization after BLE connectionBLE & GATT

2. OSI vs TCP/IP Layer Mapping

The common four-layer (TCP/IP) model is a simplified OSI seven-layer model:

TCP/IP 4-layerOSI 7-layer (roughly)Typical protocolsAnalogy
ApplicationApplication/Presentation/SessionHTTP, MQTT, SNTP, DNSLetter content
TransportTransportTCP, UDPCourier label (registered/regular mail)
NetworkNetworkIP, ICMPDelivery address
LinkData link/PhysicalWi-Fi 802.11, EthernetCourier transport

3. Data Encapsulation: One Envelope Inside Another

Each layer adds its "envelope" when sending; the receiver strips them layer by layer:

This is why packet captures show layer after layer of headers — each header was added by one protocol layer.

4. Ai-M6x Protocol Stack Implementation

In code: Wi-Fi starts with wifi_task_create + fhost_init, the network stack with tcpip_init (lwIP), and BLE with btble_controller_init + hci_driver_init + bt_enable.

How the SDK Implements It

Any networking example initializes "Wi-Fi + lwIP" at startup:

c
tcpip_init(NULL, NULL);                              /* start the lwIP stack */
xTaskCreate(wifi_start_firmware_task, "wifi init", 1024, NULL, 10, NULL); /* start Wi-Fi firmware */
/* After getting an IP, TCP/UDP/HTTP/MQTT examples can work */

Common Exam & Interview Questions

What are the four TCP/IP layers and one protocol each?

Application (HTTP/MQTT), Transport (TCP/UDP), Network (IP/ICMP), Link (Wi-Fi/Ethernet).

Why encapsulate data layer by layer when sending?

Each layer handles one job (port → IP → MAC) and only adds its own header; the receiver strips them in reverse. This is why layered protocols interoperate across vendors.

What do IP and TCP each solve?

IP routes to the right device (addressing); TCP provides reliable delivery (ports, sequence numbers, ACK/retransmission). One handles address, the other handles delivery quality.

Which layer is Wi-Fi? How does it relate to TCP/IP?

Wi-Fi (802.11) is link/physical layer; TCP/IP runs on top of it. "Connected to Wi-Fi" only means the link is up — you still need an IP (DHCP) to use network protocols.

How do BLE and Wi-Fi protocol stacks differ?

BLE is a separate stack (controller + HCI + host GAP/GATT) that does not run IP/TCP; Wi-Fi goes through IP networking. Both can coexist (shared antenna, time-multiplexed), but the protocol systems differ.

Have questions?

For any other questions, visit the unified Q&A and discussion board: Ai-Thinker Discussions

Released under the MIT License. Build Time 2026-09-11 14:52:23