docs(wifi/espnow): Update the description for ESP-NOW frame

This commit is contained in:
zhangyanjiao 2024-09-27 15:23:18 +08:00
parent c0d14dabfc
commit 9a45ad7d46
3 changed files with 44 additions and 25 deletions

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2019-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -48,7 +48,8 @@ extern "C" {
#define ESP_NOW_MAX_TOTAL_PEER_NUM 20 /*!< Maximum number of ESPNOW total peers */
#define ESP_NOW_MAX_ENCRYPT_PEER_NUM 6 /*!< Maximum number of ESPNOW encrypted peers */
#define ESP_NOW_MAX_DATA_LEN 250 /*!< Maximum length of ESPNOW data which is sent very time */
#define ESP_NOW_MAX_IE_DATA_LEN 250 /**< Maximum data length in a vendor-specific element */
#define ESP_NOW_MAX_DATA_LEN ESP_NOW_MAX_IE_DATA_LEN /**< Maximum length of data sent in each ESPNOW transmission for v1.0 */
/**
* @brief Status of sending ESPNOW data .
@ -123,7 +124,10 @@ esp_err_t esp_now_init(void);
esp_err_t esp_now_deinit(void);
/**
* @brief Get the version of ESPNOW
* @brief Get the version of ESPNOW. Currently, ESPNOW supports one version: v1.0.
*
* The v1.0 devices can receive packets if the packet length is less than or equal to ESP_NOW_MAX_IE_DATA_LEN.
* For packets exceeding this length, the v1.0 devices will discard the packet entirely.
*
* @param version ESPNOW version
*

View File

@ -12,7 +12,12 @@ CTR with CBC-MAC Protocol(CCMP) is used to protect the action frame for security
Frame Format
------------
ESP-NOW uses a vendor-specific action frame to transmit ESP-NOW data. The default ESP-NOW bit rate is 1 Mbps. The format of the vendor-specific action frame is as follows:
ESP-NOW uses a vendor-specific action frame to transmit ESP-NOW data. The default ESP-NOW bit rate is 1 Mbps.
Currently, ESP-NOW supports one version: v1.0. The maximum packet length supported by v1.0 devices is ESP_NOW_MAX_DATA_LEN bytes.
The v1.0 devices can receive packets if the packet length is less than or equal to ESP_NOW_MAX_IE_DATA_LEN. For packets exceeding this length, the v1.0 devices will discard the packet entirely.
The format of the vendor-specific action frame is as follows:
.. highlight:: none
@ -21,28 +26,32 @@ ESP-NOW uses a vendor-specific action frame to transmit ESP-NOW data. The defaul
------------------------------------------------------------------------------------------------------------
| MAC Header | Category Code | Organization Identifier | Random Values | Vendor Specific Content | FCS |
------------------------------------------------------------------------------------------------------------
24 bytes 1 byte 3 bytes 4 bytes 7~257 bytes 4 bytes
24 bytes 1 byte 3 bytes 4 bytes 7-x bytes 4 bytes
- Category Code: The Category Code field is set to the value(127) indicating the vendor-specific category.
- Organization Identifier: The Organization Identifier contains a unique identifier (0x18fe34), which is the first three bytes of MAC address applied by Espressif.
- Random Value: The Random Value filed is used to prevents relay attacks.
- Vendor Specific Content: The Vendor Specific Content contains vendor-specific fields as follows:
- Vendor Specific Content: The Vendor Specific Content contains one vendor-specific element field, x = 257(250 + 7).
The format of the vendor-specific element frame is as follows:
.. highlight:: none
::
-------------------------------------------------------------------------------
| Element ID | Length | Organization Identifier | Type | Version | Body |
-------------------------------------------------------------------------------
1 byte 1 byte 3 bytes 1 byte 1 byte 0~250 bytes
------------------------------------------------------------------------------------------
| Element ID | Length | Organization Identifier | Type | Reserved | Version | Body |
------------------------------------------------------------------------------------------
7~4 bits | 3~0 bits
1 byte 1 byte 3 bytes 1 byte 1 byte 0-250 bytes
- Element ID: The Element ID field is set to the value (221), indicating the vendor-specific element.
- Length: The length is the total length of Organization Identifier, Type, Version and Body.
- Organization Identifier: The Organization Identifier contains a unique identifier(0x18fe34), which is the first three bytes of MAC address applied by Espressif.
- Length: The length is the total length of Organization Identifier, Type, Version and Body, the maximum value is 255.
- Organization Identifier: The Organization Identifier contains a unique identifier (0x18fe34), which is the first three bytes of MAC address applied by Espressif.
- Type: The Type field is set to the value (4) indicating ESP-NOW.
- Version: The Version field is set to the version of ESP-NOW.
- Body: The Body contains the ESP-NOW data.
- Body: The Body contains the actual ESP-NOW data to be transmitted.
As ESP-NOW is connectionless, the MAC header is a little different from that of standard frames. The FromDS and ToDS bits of FrameControl field are both 0. The first address field is set to the destination address. The second address field is set to the source address. The third address field is set to broadcast address (0xff:0xff:0xff:0xff:0xff:0xff).

View File

@ -12,37 +12,43 @@ CTR 与 CBC-MAC 协议 (CCMP) 可用来保护动作帧的安全。ESP-NOW 广泛
帧格式
------------
ESP-NOW 使用各个供应商的动作帧传输数据,默认比特率为 1 Mbps。各个供应商的动作帧格式为
ESP-NOW 使用供应商的动作帧传输数据,默认比特率为 1 Mbps。目前 ESP-NOW 支持一个版本: v1.0。v1.0 的设备支持的最大数据包长度为 ESP_NOW_MAX_DATA_LEN bytes。
v1.0 设备可以接收长度不超过 ESP_NOW_MAX_IE_DATA_LEN 的数据包,而对于长度超过 ESP_NOW_MAX_IE_DATA_LEN 的数据包,会丢弃数据包。
供应商的动作帧格式为:
.. highlight:: none
::
-----------------------------------------------------------------------------------------
-----------------------------------------------------------------------------
| MAC 报头 | 分类代码 | 组织标识符 | 随机值 | 供应商特定内容 | FCS |
-----------------------------------------------------------------------------------------
24 字节 1 字节 3 字节 4 字节 7~257 字节 4 字节
-----------------------------------------------------------------------------
24 字节 1 字节 3 字节 4 字节 7-x 字节 4 字节
- 分类代码:分类代码字段可用于指示各个供应商的类别(比如 127
- 组织标识符:组织标识符包含一个唯一标识符 (比如 0x18fe34),为乐鑫指定的 MAC 地址的前三个字节。
- 随机值:防止重放攻击。
- 供应商特定内容:供应商特定内容包含供应商特定字段,如下所示:
- 供应商特定内容供应商特定内容包含一个特定供应商元素字段x = 257(250+7)。
特定供应商元素的帧格式为:
.. highlight:: none
::
----------------------------------------------------------------------------------------
| 元素 ID | 长度 | 组织标识符 | 类型 | 版本 | 正文 |
----------------------------------------------------------------------------------------
1 字节 1 字节 3 字节 1 字节 1 字节 0250 字节
---------------------------------------------------------------------------
| 元素 ID | 长度 | 组织标识符 | 类型 | 保留 | 版本 | 正文 |
---------------------------------------------------------------------------
7~4 比特| 3~0 比特
1 字节 1 字节 3 字节 1 字节 1 字节 0-250 字节
- 元素 ID元素 ID 字段可用于指示特定于供应商的元素。
- 长度:长度是组织标识符、类型、版本和正文的总长度。
- 组织标识符:组织标识符包含一个唯一标识符 (比如 0x18fe34),为乐鑫指定的 MAC 地址的前三个字节。
- 长度:长度是组织标识符、类型、版本和正文的总长度,最大值为 255
- 组织标识符:组织标识符包含一个唯一标识符(比如 0x18fe34,为乐鑫指定的 MAC 地址的前三个字节。
- 类型:类型字段设置为 4代表 ESP-NOW。
- 版本:版本字段设置为 ESP-NOW 的版本。
- 正文:正文包含 ESP-NOW 数据。
- 正文:正文包含实际要发送的 ESP-NOW 数据。
由于 ESP-NOW 是无连接的,因此 MAC 报头与标准帧略有不同。FrameControl 字段的 FromDS 和 ToDS 位均为 0。第一个地址字段用于配置目标地址。第二个地址字段用于配置源地址。第三个地址字段用于配置广播地址 (0xff:0xff:0xff:0xff:0xff:0xff)。