Merge branch 'feat/support_longer_data_len_in_espnow' into 'master'

feat(wifi/espnow): Support longer data length in espnow

Closes IDFGH-7935

See merge request espressif/esp-idf!31097
This commit is contained in:
Jiang Jiang Jian 2024-09-29 16:58:33 +08:00
commit ee74f278c8
4 changed files with 66 additions and 24 deletions

View File

@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2019-2023 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@ -49,7 +49,9 @@ extern "C" {
#define ESP_NOW_MAX_TOTAL_PEER_NUM 20 /*!< Maximum number of ESPNOW total peers */ #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_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 */
#define ESP_NOW_MAX_DATA_LEN_V2 1490 /**< Maximum length of data sent in each ESPNOW transmission for v2.0 */
/** /**
* @brief Status of sending ESPNOW data . * @brief Status of sending ESPNOW data .
@ -135,7 +137,12 @@ esp_err_t esp_now_init(void);
esp_err_t esp_now_deinit(void); esp_err_t esp_now_deinit(void);
/** /**
* @brief Get the version of ESPNOW * @brief Get the version of ESPNOW. Currently, ESPNOW supports two versions: v1.0 and v2.0.
*
* The v2.0 devices are capable of receiving packets from both v2.0 and v1.0 devices. In contrast, v1.0 devices can only receive packets from other v1.0 devices.
* However, v1.0 devices can receive v2.0 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 either truncate the data to the first ESP_NOW_MAX_IE_DATA_LEN bytes or discard the packet entirely.
* For detailed behavior, please refer to the documentation corresponding to the specific IDF version.
* *
* @param version ESPNOW version * @param version ESPNOW version
* *

@ -1 +1 @@
Subproject commit 53321dadb5c9b7aefafd2594e2b52261192ba551 Subproject commit 43c2ddb15a1f4d026f20f98249ca63885630c813

View File

@ -13,7 +13,15 @@ CTR with CBC-MAC Protocol (CCMP) is used to protect the action frame for securit
Frame Format 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 two versions: v1.0 and v2.0. The maximum packet length supported by v2.0 devices is ESP_NOW_MAX_DATA_LEN_V2 bytes, while the maximum packet length supported by v1.0 devices is ESP_NOW_MAX_DATA_LEN bytes.
The v2.0 devices are capable of receiving packets from both v2.0 and v1.0 devices. In contrast, v1.0 devices can only receive packets from other v1.0 devices.
However, v1.0 devices can receive v2.0 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 either truncate the data to the first ESP_NOW_MAX_IE_DATA_LEN bytes or discard the packet entirely.
For detailed behavior, please refer to the documentation corresponding to the specific IDF version.
The format of the vendor-specific action frame is as follows:
.. highlight:: none .. highlight:: none
@ -22,28 +30,39 @@ 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 | | 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. - 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. - 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. - 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 several (at least one) vendor-specific element fields. For version v2.0, x = 1532(1490 + 6*7), for version v1.0, x = 257(250 + 7).
The format of the vendor-specific element frame is as follows:
.. highlight:: none .. highlight:: none
:: ::
------------------------------------------------------------------------------- ESP-NOW v1.0:
| Element ID | Length | Organization Identifier | Type | Version | Body | ------------------------------------------------------------------------------------------
------------------------------------------------------------------------------- | Element ID | Length | Organization Identifier | Type | Reserved | Version | Body |
1 byte 1 byte 3 bytes 1 byte 1 byte 0-250 bytes ------------------------------------------------------------------------------------------
7~4 bits | 3~0 bits
1 byte 1 byte 3 bytes 1 byte 1 byte 0-250 bytes
ESP-NOW v2.0:
-----------------------------------------------------------------------------------------------------
| Element ID | Length | Organization Identifier | Type | Reserved | More data |Version | Body |
-----------------------------------------------------------------------------------------------------
7~5 bits | 1 bit |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. - 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. - 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. - 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. - 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. - 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). 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

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