fix(wifi/mesh): fix the IE crypto disable error and update doc

This commit is contained in:
zhangyanjiao 2023-08-10 19:35:43 +08:00 committed by Jack
parent 2b6feac67c
commit 07245bf43a
6 changed files with 69 additions and 64 deletions

View File

@ -136,10 +136,13 @@ extern "C" {
/**
* @brief Flag of mesh networking IE
*/
#define MESH_ASSOC_FLAG_VOTE_IN_PROGRESS (0x02) /**< vote in progress */
#define MESH_ASSOC_FLAG_MAP_ASSOC (0x01) /**< Mesh AP doesn't detect children leave yet */
#define MESH_ASSOC_FLAG_VOTE_IN_PROGRESS (0x02) /**< station in vote, set when root vote start, clear when connect to router or when root switch*/
#define MESH_ASSOC_FLAG_STA_VOTED (0x04) /**< station vote done, set when connect to router */
#define MESH_ASSOC_FLAG_NETWORK_FREE (0x08) /**< no root in current network */
#define MESH_ASSOC_FLAG_ROOTS_FOUND (0x20) /**< root conflict is found */
#define MESH_ASSOC_FLAG_ROOT_FIXED (0x40) /**< fixed root */
#define MESH_ASSOC_FLAG_STA_VOTE_EXPIRE (0x10) /**< the voted address is expired, means the voted device lose the chance to be root */
#define MESH_ASSOC_FLAG_ROOTS_FOUND (0x20) /**< roots conflict is found, means that thre are at least two roots in the mesh network */
#define MESH_ASSOC_FLAG_ROOT_FIXED (0x40) /**< the root is fixed in the mesh network */
/**
@ -1291,7 +1294,7 @@ int esp_mesh_get_capacity_num(void);
/**
* @brief Set mesh IE crypto functions
*
* @attention This API can be called at any time after mesh is initialized.
* @attention This API can be called at any time after mesh is configured.
*
* @param[in] crypto_funcs crypto functions for mesh IE
* - If crypto_funcs is set to NULL, mesh IE is no longer encrypted.
@ -1303,7 +1306,7 @@ esp_err_t esp_mesh_set_ie_crypto_funcs(const mesh_crypto_funcs_t *crypto_funcs);
/**
* @brief Set mesh IE crypto key
*
* @attention This API can be called at any time after mesh is initialized.
* @attention This API can be called at any time after mesh is configured.
*
* @param[in] key ASCII crypto key
* @param[in] len length in bytes, range:8~64

View File

@ -50,12 +50,14 @@ typedef struct {
} mesh_switch_parent_t;
/**
* @brief Mesh rssi threshold
* @brief Mesh RSSI threshold
*/
typedef struct {
int high; /**< high rssi threshold */
int medium; /**< medium rssi threshold */
int low; /**< low rssi threshold */
int high; /**< high RSSI threshold, used to determine whether the new parent and the current parent are in the same RSSI range */
int medium; /**< medium RSSI threshold, used to determine whether the new parent and the current parent are in the same RSSI range */
int low; /**< low RSSI threshold. If the parent's RSSI is lower than low for a period time of duration_ms,
then the mesh node will post MESH_WEAK_RSSI event.
Also used to determine whether the new parent and the current parent are in the same RSSI range */
} mesh_rssi_threshold_t;
/**
@ -63,47 +65,47 @@ typedef struct {
*/
typedef struct {
/**< mesh networking IE head */
uint8_t eid; /**< element ID */
uint8_t len; /**< element length */
uint8_t oui[3]; /**< organization identifier */
/**< mesh networking IE content */
uint8_t type; /**< ESP defined IE type */
uint8_t eid; /**< element ID, vendor specific, 221 */
uint8_t len; /**< element length, the length after this member */
uint8_t oui[3]; /**< organization identifier, 0x18fe34 */
uint8_t type; /**< ESP defined IE type, include Assoc IE, SSID IE, Ext Assoc IE, Roots IE, etc. */
uint8_t encrypted : 1; /**< whether mesh networking IE is encrypted */
uint8_t version : 7; /**< mesh networking IE version */
uint8_t version : 7; /**< mesh networking IE version, equal to 2 if mesh PS is enabled, equal to 1 otherwise */
/**< content */
uint8_t mesh_type; /**< mesh device type */
uint8_t mesh_id[6]; /**< mesh ID */
uint8_t layer_cap; /**< max layer */
uint8_t layer; /**< current layer */
uint8_t assoc_cap; /**< max connections of mesh AP */
uint8_t assoc; /**< current connections */
uint8_t leaf_cap; /**< leaf capacity */
uint8_t leaf_assoc; /**< the number of current connected leaf */
uint16_t root_cap; /**< root capacity */
uint16_t self_cap; /**< self capacity */
uint16_t layer2_cap; /**< layer2 capacity */
uint16_t scan_ap_num; /**< the number of scanning APs */
int8_t rssi; /**< RSSI of the parent */
int8_t router_rssi; /**< RSSI of the router */
uint8_t flag; /**< flag of networking */
uint8_t rc_addr[6]; /**< root address */
int8_t rc_rssi; /**< root RSSI */
uint8_t vote_addr[6]; /**< voter address */
int8_t vote_rssi; /**< vote RSSI of the router */
uint8_t vote_ttl; /**< vote ttl */
uint16_t votes; /**< votes */
uint16_t my_votes; /**< my votes */
uint8_t reason; /**< reason */
uint8_t child[6]; /**< child address */
uint8_t toDS; /**< toDS state */
uint8_t mesh_type; /**< mesh device type, include idle, root, node, etc, refer to mesh_type_t */
uint8_t mesh_id[6]; /**< mesh ID, only the same mesh id can form a unified mesh network */
uint8_t layer_cap; /**< layer_cap = max_layer - layer, indicates the number of remaining available layers of the mesh network */
uint8_t layer; /**< the current layer of this node */
uint8_t assoc_cap; /**< the maximum connections of this mesh AP */
uint8_t assoc; /**< current connections of this mesh AP */
uint8_t leaf_cap; /**< the maximum number of leaves in the mesh network */
uint8_t leaf_assoc; /**< the number of current connected leaves */
uint16_t root_cap; /**< the capacity of the root, equal to the total child numbers plus 1, root node updates root_cap and self_cap */
uint16_t self_cap; /**< the capacity of myself, total child numbers plus 1, all nodes update this member */
uint16_t layer2_cap; /**< the capacity of layer2 node, total child numbers plus 1, layer2 node updates layer2_cap and self_cap, root sets this to 0 */
uint16_t scan_ap_num; /**< the number of mesh APs around */
int8_t rssi; /**< RSSI of the connected parent, default value is -120, root node will not update this */
int8_t router_rssi; /**< RSSI of the router, default value is -120 */
uint8_t flag; /**< flag of networking, indicates the status of the network, refer to MESH_ASSOC_FLAG_XXX */
/**< vote related */
uint8_t rc_addr[6]; /**< the address of the root candidate, i.e. the voted addesss before connection, root node will update this with self address */
int8_t rc_rssi; /**< the router RSSI of the root candidate */
uint8_t vote_addr[6]; /**< the voted address after connection */
int8_t vote_rssi; /**< the router RSSI of the voted address */
uint8_t vote_ttl; /**< vote ttl, indicate the voting is from myself or from other nodes */
uint16_t votes; /**< the number of all voting nodes */
uint16_t my_votes; /**< the number of nodes that voted for me */
uint8_t reason; /**< the reason why the voting happens, root initiated or child initiated, refer to mesh_vote_reason_t */
uint8_t child[6]; /**< child address, not used currently */
uint8_t toDS; /**< state represents whether the root is able to access external IP network */
} __attribute__((packed)) mesh_assoc_t;
/**
* @brief Mesh chain layer
*/
typedef struct {
uint16_t layer_cap; /**< max layer */
uint16_t layer; /**< current layer */
uint16_t layer_cap; /**< max layer of the network */
uint16_t layer; /**< current layer of this node */
} mesh_chain_layer_t;
/**
@ -111,22 +113,22 @@ typedef struct {
*/
typedef struct {
mesh_assoc_t tree; /**< tree top, mesh_assoc IE */
mesh_chain_layer_t chain; /**< chain top, mesh_assoc IE*/
mesh_chain_layer_t chain; /**< chain top, mesh_assoc IE */
} __attribute__((packed)) mesh_chain_assoc_t;
/* mesh max connections */
#define MESH_MAX_CONNECTIONS (10)
/**
* @brief Mesh PS duties
* @brief Mesh power save duties
*/
typedef struct {
uint8_t device; /**< device power save duty*/
uint8_t parent; /**< parent power save duty*/
struct {
bool used; /**< used */
uint8_t duty; /**< duty */
uint8_t mac[6]; /**< mac */
bool used; /**< whether the child is joined */
uint8_t duty; /**< power save duty of the child */
uint8_t mac[6]; /**< mac address of the child */
} child[MESH_MAX_CONNECTIONS]; /**< child */
} esp_mesh_ps_duties_t;
@ -200,7 +202,7 @@ esp_err_t esp_mesh_set_switch_parent_paras(mesh_switch_parent_t *paras);
esp_err_t esp_mesh_get_switch_parent_paras(mesh_switch_parent_t *paras);
/**
* @brief Set RSSI threshold
* @brief Set RSSI threshold of current parent
* - The default high RSSI threshold value is -78 dBm.
* - The default medium RSSI threshold value is -82 dBm.
* - The default low RSSI threshold value is -85 dBm.
@ -214,7 +216,7 @@ esp_err_t esp_mesh_get_switch_parent_paras(mesh_switch_parent_t *paras);
esp_err_t esp_mesh_set_rssi_threshold(const mesh_rssi_threshold_t *threshold);
/**
* @brief Get RSSI threshold
* @brief Get RSSI threshold of current parent
*
* @param[out] threshold RSSI threshold
*

View File

@ -412,7 +412,7 @@ typedef struct {
esp_aes_decrypt_t aes_decrypt; /**< Decrypt one AES block callback function */
esp_aes_decrypt_init_t aes_decrypt_init; /**< Initialize AES callback function for decryption */
esp_aes_decrypt_deinit_t aes_decrypt_deinit; /**< Deinitialize AES decryption callback function */
esp_aes_128_encrypt_t aes_128_encrypt; /**< The AES 128 encrypt callback function used by esp_wifi */
esp_aes_128_encrypt_t aes_128_encrypt; /**< The AES 128 encrypt callback function used by esp_wifi */
esp_aes_128_decrypt_t aes_128_decrypt; /**< The AES 128 decrypt callback function used by esp_wifi */
esp_omac1_aes_128_t omac1_aes_128; /**< One-Key CBC MAC (OMAC1) hash with AES-128 callback function for MIC computation */
esp_ccmp_decrypt_t ccmp_decrypt; /**< Decrypt data callback function using CCMP */

@ -1 +1 @@
Subproject commit a65d997669b98f8348158fb5f47d9832b46eccc7
Subproject commit c9cff30ae4aa2aaf251d9823f3feef4e784c7fd2

View File

@ -301,17 +301,8 @@ void app_main(void)
/* mesh initialization */
ESP_ERROR_CHECK(esp_mesh_init());
ESP_ERROR_CHECK(esp_event_handler_register(MESH_EVENT, ESP_EVENT_ANY_ID, &mesh_event_handler, NULL));
/* mesh enable IE crypto */
/* mesh config */
mesh_cfg_t cfg = MESH_INIT_CONFIG_DEFAULT();
#if CONFIG_MESH_IE_CRYPTO_FUNCS
/* modify IE crypto key */
ESP_ERROR_CHECK(esp_mesh_set_ie_crypto_funcs(&g_wifi_default_mesh_crypto_funcs));
ESP_ERROR_CHECK(esp_mesh_set_ie_crypto_key(CONFIG_MESH_IE_CRYPTO_KEY, strlen(CONFIG_MESH_IE_CRYPTO_KEY)));
#else
/* disable IE crypto */
ESP_LOGI(MESH_TAG, "<Config>disable IE crypto");
ESP_ERROR_CHECK(esp_mesh_set_ie_crypto_funcs(NULL));
#endif
/* mesh ID */
memcpy((uint8_t *) &cfg.mesh_id, MESH_ID, 6);
/* router */
@ -327,6 +318,16 @@ void app_main(void)
memcpy((uint8_t *) &cfg.mesh_ap.password, CONFIG_MESH_AP_PASSWD,
strlen(CONFIG_MESH_AP_PASSWD));
ESP_ERROR_CHECK(esp_mesh_set_config(&cfg));
/* mesh enable IE crypto */
#if CONFIG_MESH_IE_CRYPTO_FUNCS
/* modify IE crypto key */
ESP_ERROR_CHECK(esp_mesh_set_ie_crypto_funcs(&g_wifi_default_mesh_crypto_funcs));
ESP_ERROR_CHECK(esp_mesh_set_ie_crypto_key(CONFIG_MESH_IE_CRYPTO_KEY, strlen(CONFIG_MESH_IE_CRYPTO_KEY)));
#else
/* disable IE crypto */
ESP_LOGI(MESH_TAG, "<Config>disable IE crypto");
ESP_ERROR_CHECK(esp_mesh_set_ie_crypto_funcs(NULL));
#endif
/* mesh start */
ESP_ERROR_CHECK(esp_mesh_start());
ESP_LOGI(MESH_TAG, "mesh starts successfully, heap:%" PRId32, esp_get_free_heap_size());

View File

@ -39,7 +39,7 @@
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/usb_serial_jtag.h"
#include "esp_coexist_internal.h"
#include "esp_coexist.h"
#include "esp_log.h"
#include "esp_netif.h"
#include "esp_spiffs.h"
@ -173,8 +173,7 @@ void app_main(void)
ESP_ERROR_CHECK(example_connect());
#if CONFIG_ESP_COEX_SW_COEXIST_ENABLE
ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_MIN_MODEM));
coex_enable();
coex_schm_status_bit_set(1, 1);
esp_coex_wifi_i154_enable();
#else
ESP_ERROR_CHECK(esp_wifi_set_ps(WIFI_PS_NONE));
#endif