2022-08-03 05:26:33 -04:00
|
|
|
/*
|
2023-08-01 03:27:56 -04:00
|
|
|
* SPDX-FileCopyrightText: 2017-2023 Espressif Systems (Shanghai) CO LTD
|
2022-08-03 05:26:33 -04:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
2018-02-27 05:22:20 -05:00
|
|
|
|
|
|
|
#ifndef __ESP_MESH_INTERNAL_H__
|
|
|
|
#define __ESP_MESH_INTERNAL_H__
|
|
|
|
|
|
|
|
#include "esp_err.h"
|
2020-04-30 09:40:38 -04:00
|
|
|
#include "esp_mesh.h"
|
2018-02-27 05:22:20 -05:00
|
|
|
#include "esp_wifi.h"
|
|
|
|
#include "esp_wifi_types.h"
|
2019-03-22 02:21:15 -04:00
|
|
|
#include "esp_private/wifi.h"
|
2018-02-27 05:22:20 -05:00
|
|
|
#include "esp_wifi_crypto_types.h"
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*******************************************************
|
|
|
|
* Constants
|
|
|
|
*******************************************************/
|
|
|
|
|
|
|
|
/*******************************************************
|
|
|
|
* Structures
|
|
|
|
*******************************************************/
|
2023-08-01 03:27:56 -04:00
|
|
|
/**
|
|
|
|
* @brief Mesh attempts
|
|
|
|
*/
|
2018-02-27 05:22:20 -05:00
|
|
|
typedef struct {
|
2018-06-26 08:48:47 -04:00
|
|
|
int scan; /**< minimum scan times before being a root, default:10 */
|
|
|
|
int vote; /**< max vote times in self-healing, default:1000 */
|
|
|
|
int fail; /**< parent selection fail times, if the scan times reach this value,
|
|
|
|
device will disconnect with associated children and join self-healing. default:60 */
|
|
|
|
int monitor_ie; /**< acceptable times of parent networking IE change before update its own networking IE. default:3 */
|
2018-02-27 05:22:20 -05:00
|
|
|
} mesh_attempts_t;
|
|
|
|
|
2023-08-01 03:27:56 -04:00
|
|
|
/**
|
|
|
|
* @brief Mesh switch parent
|
|
|
|
*/
|
2018-02-27 05:22:20 -05:00
|
|
|
typedef struct {
|
2023-08-01 03:27:56 -04:00
|
|
|
int duration_ms; /**< parent weak RSSI monitor duration, if the RSSI continues to be weak during this duration_ms,
|
2018-06-26 08:48:47 -04:00
|
|
|
device will search for a new parent. */
|
2023-08-01 03:27:56 -04:00
|
|
|
int cnx_rssi; /**< RSSI threshold for keeping a good connection with parent.
|
2018-06-26 08:48:47 -04:00
|
|
|
If set a value greater than -120 dBm, a timer will be armed to monitor parent RSSI at a period time of duration_ms. */
|
2023-08-01 03:27:56 -04:00
|
|
|
int select_rssi; /**< RSSI threshold for parent selection. It should be a value greater than switch_rssi. */
|
|
|
|
int switch_rssi; /**< Disassociate with current parent and switch to a new parent when the RSSI is greater than this set threshold. */
|
|
|
|
int backoff_rssi; /**< RSSI threshold for connecting to the root */
|
2018-02-27 05:22:20 -05:00
|
|
|
} mesh_switch_parent_t;
|
|
|
|
|
2023-08-01 03:27:56 -04:00
|
|
|
/**
|
|
|
|
* @brief Mesh rssi threshold
|
|
|
|
*/
|
2018-06-19 06:23:56 -04:00
|
|
|
typedef struct {
|
2023-08-01 03:27:56 -04:00
|
|
|
int high; /**< high rssi threshold */
|
|
|
|
int medium; /**< medium rssi threshold */
|
|
|
|
int low; /**< low rssi threshold */
|
2018-06-19 06:23:56 -04:00
|
|
|
} mesh_rssi_threshold_t;
|
|
|
|
|
2018-05-21 05:22:04 -04:00
|
|
|
/**
|
2018-06-26 08:48:47 -04:00
|
|
|
* @brief Mesh networking IE
|
2018-05-21 05:22:04 -04:00
|
|
|
*/
|
|
|
|
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 */
|
2023-08-01 03:27:56 -04:00
|
|
|
uint8_t type; /**< ESP defined IE type */
|
2018-09-23 09:09:59 -04:00
|
|
|
uint8_t encrypted : 1; /**< whether mesh networking IE is encrypted */
|
2018-05-21 05:22:04 -04:00
|
|
|
uint8_t version : 7; /**< mesh networking IE version */
|
|
|
|
/**< 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 */
|
2018-06-26 08:48:47 -04:00
|
|
|
uint16_t scan_ap_num; /**< the number of scanning APs */
|
2018-06-19 06:23:56 -04:00
|
|
|
int8_t rssi; /**< RSSI of the parent */
|
|
|
|
int8_t router_rssi; /**< RSSI of the router */
|
2018-05-21 05:22:04 -04:00
|
|
|
uint8_t flag; /**< flag of networking */
|
|
|
|
uint8_t rc_addr[6]; /**< root address */
|
2018-06-19 06:23:56 -04:00
|
|
|
int8_t rc_rssi; /**< root RSSI */
|
2018-05-21 05:22:04 -04:00
|
|
|
uint8_t vote_addr[6]; /**< voter address */
|
2018-06-19 06:23:56 -04:00
|
|
|
int8_t vote_rssi; /**< vote RSSI of the router */
|
2018-05-21 05:22:04 -04:00
|
|
|
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 */
|
|
|
|
} __attribute__((packed)) mesh_assoc_t;
|
|
|
|
|
2023-08-01 03:27:56 -04:00
|
|
|
/**
|
|
|
|
* @brief Mesh chain layer
|
|
|
|
*/
|
2021-03-16 02:17:13 -04:00
|
|
|
typedef struct {
|
2023-08-01 03:27:56 -04:00
|
|
|
uint16_t layer_cap; /**< max layer */
|
|
|
|
uint16_t layer; /**< current layer */
|
2021-03-16 02:17:13 -04:00
|
|
|
} mesh_chain_layer_t;
|
|
|
|
|
2023-08-01 03:27:56 -04:00
|
|
|
/**
|
|
|
|
* @brief Mesh chain assoc
|
|
|
|
*/
|
2021-03-16 02:17:13 -04:00
|
|
|
typedef struct {
|
2023-08-01 03:27:56 -04:00
|
|
|
mesh_assoc_t tree; /**< tree top, mesh_assoc IE */
|
|
|
|
mesh_chain_layer_t chain; /**< chain top, mesh_assoc IE*/
|
2021-03-16 02:17:13 -04:00
|
|
|
} __attribute__((packed)) mesh_chain_assoc_t;
|
|
|
|
|
2022-08-03 05:26:33 -04:00
|
|
|
/* mesh max connections */
|
|
|
|
#define MESH_MAX_CONNECTIONS (10)
|
|
|
|
|
2020-04-30 09:40:38 -04:00
|
|
|
/**
|
|
|
|
* @brief Mesh PS duties
|
|
|
|
*/
|
|
|
|
typedef struct {
|
2023-08-01 03:27:56 -04:00
|
|
|
uint8_t device; /**< device power save duty*/
|
|
|
|
uint8_t parent; /**< parent power save duty*/
|
2020-04-30 09:40:38 -04:00
|
|
|
struct {
|
2023-08-01 03:27:56 -04:00
|
|
|
bool used; /**< used */
|
|
|
|
uint8_t duty; /**< duty */
|
|
|
|
uint8_t mac[6]; /**< mac */
|
|
|
|
} child[MESH_MAX_CONNECTIONS]; /**< child */
|
2020-04-30 09:40:38 -04:00
|
|
|
} esp_mesh_ps_duties_t;
|
|
|
|
|
2018-02-27 05:22:20 -05:00
|
|
|
/*******************************************************
|
|
|
|
* Function Definitions
|
|
|
|
*******************************************************/
|
|
|
|
/**
|
2018-06-26 08:48:47 -04:00
|
|
|
* @brief Set mesh softAP beacon interval
|
2018-02-27 05:22:20 -05:00
|
|
|
*
|
2023-08-01 03:27:56 -04:00
|
|
|
* @param[in] interval_ms beacon interval (msecs) (100 msecs ~ 60000 msecs)
|
2018-02-27 05:22:20 -05:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK
|
|
|
|
* - ESP_FAIL
|
2023-08-18 02:16:34 -04:00
|
|
|
* - ESP_ERR_INVALID_ARG
|
2018-02-27 05:22:20 -05:00
|
|
|
*/
|
|
|
|
esp_err_t esp_mesh_set_beacon_interval(int interval_ms);
|
|
|
|
|
|
|
|
/**
|
2018-06-26 08:48:47 -04:00
|
|
|
* @brief Get mesh softAP beacon interval
|
2018-02-27 05:22:20 -05:00
|
|
|
*
|
2023-08-01 03:27:56 -04:00
|
|
|
* @param[out] interval_ms beacon interval (msecs)
|
2018-02-27 05:22:20 -05:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK
|
|
|
|
*/
|
|
|
|
esp_err_t esp_mesh_get_beacon_interval(int *interval_ms);
|
|
|
|
|
|
|
|
/**
|
2018-06-26 08:48:47 -04:00
|
|
|
* @brief Set attempts for mesh self-organized networking
|
2018-02-27 05:22:20 -05:00
|
|
|
*
|
2018-06-26 08:48:47 -04:00
|
|
|
* @param[in] attempts
|
2018-02-27 05:22:20 -05:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK
|
|
|
|
* - ESP_FAIL
|
|
|
|
*/
|
|
|
|
esp_err_t esp_mesh_set_attempts(mesh_attempts_t *attempts);
|
|
|
|
|
|
|
|
/**
|
2018-06-26 08:48:47 -04:00
|
|
|
* @brief Get attempts for mesh self-organized networking
|
2018-02-27 05:22:20 -05:00
|
|
|
*
|
2018-06-26 08:48:47 -04:00
|
|
|
* @param[out] attempts
|
2018-02-27 05:22:20 -05:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK
|
2018-06-19 06:23:56 -04:00
|
|
|
* - ESP_ERR_MESH_ARGUMENT
|
2018-02-27 05:22:20 -05:00
|
|
|
*/
|
|
|
|
esp_err_t esp_mesh_get_attempts(mesh_attempts_t *attempts);
|
|
|
|
|
|
|
|
/**
|
2018-06-26 08:48:47 -04:00
|
|
|
* @brief Set parameters for parent switch
|
2018-02-27 05:22:20 -05:00
|
|
|
*
|
2018-06-26 08:48:47 -04:00
|
|
|
* @param[in] paras parameters for parent switch
|
2018-02-27 05:22:20 -05:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK
|
2018-06-19 06:23:56 -04:00
|
|
|
* - ESP_ERR_MESH_ARGUMENT
|
2018-02-27 05:22:20 -05:00
|
|
|
*/
|
|
|
|
esp_err_t esp_mesh_set_switch_parent_paras(mesh_switch_parent_t *paras);
|
|
|
|
|
|
|
|
/**
|
2018-06-26 08:48:47 -04:00
|
|
|
* @brief Get parameters for parent switch
|
2018-02-27 05:22:20 -05:00
|
|
|
*
|
2018-06-26 08:48:47 -04:00
|
|
|
* @param[out] paras parameters for parent switch
|
2018-02-27 05:22:20 -05:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK
|
2018-06-19 06:23:56 -04:00
|
|
|
* - ESP_ERR_MESH_ARGUMENT
|
2018-02-27 05:22:20 -05:00
|
|
|
*/
|
|
|
|
esp_err_t esp_mesh_get_switch_parent_paras(mesh_switch_parent_t *paras);
|
|
|
|
|
2018-06-19 06:23:56 -04:00
|
|
|
/**
|
2018-06-26 08:48:47 -04:00
|
|
|
* @brief Set RSSI threshold
|
|
|
|
* - 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.
|
2018-06-19 06:23:56 -04:00
|
|
|
*
|
2018-06-26 08:48:47 -04:00
|
|
|
* @param[in] threshold RSSI threshold
|
2018-06-19 06:23:56 -04:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK
|
|
|
|
* - ESP_ERR_MESH_ARGUMENT
|
|
|
|
*/
|
|
|
|
esp_err_t esp_mesh_set_rssi_threshold(const mesh_rssi_threshold_t *threshold);
|
|
|
|
|
|
|
|
/**
|
2018-06-26 08:48:47 -04:00
|
|
|
* @brief Get RSSI threshold
|
|
|
|
*
|
|
|
|
* @param[out] threshold RSSI threshold
|
2018-06-19 06:23:56 -04:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK
|
|
|
|
* - ESP_ERR_MESH_ARGUMENT
|
|
|
|
*/
|
|
|
|
esp_err_t esp_mesh_get_rssi_threshold(mesh_rssi_threshold_t *threshold);
|
|
|
|
|
|
|
|
/**
|
2018-06-26 08:48:47 -04:00
|
|
|
* @brief Enable the minimum rate to 6 Mbps
|
2018-06-19 06:23:56 -04:00
|
|
|
*
|
2018-06-26 08:48:47 -04:00
|
|
|
* @attention This API shall be called before Wi-Fi is started.
|
2018-06-19 06:23:56 -04:00
|
|
|
*
|
2018-06-26 08:48:47 -04:00
|
|
|
* @param[in] is_6m enable or not
|
2018-06-19 06:23:56 -04:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK
|
|
|
|
*/
|
|
|
|
esp_err_t esp_mesh_set_6m_rate(bool is_6m);
|
|
|
|
|
2018-02-27 05:22:20 -05:00
|
|
|
/**
|
2018-06-26 08:48:47 -04:00
|
|
|
* @brief Print the number of txQ waiting
|
2018-02-27 05:22:20 -05:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK
|
|
|
|
* - ESP_FAIL
|
|
|
|
*/
|
|
|
|
esp_err_t esp_mesh_print_txQ_waiting(void);
|
|
|
|
|
|
|
|
/**
|
2018-06-26 08:48:47 -04:00
|
|
|
* @brief Print the number of rxQ waiting
|
2018-02-27 05:22:20 -05:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK
|
|
|
|
* - ESP_FAIL
|
|
|
|
*/
|
|
|
|
esp_err_t esp_mesh_print_rxQ_waiting(void);
|
|
|
|
|
|
|
|
/**
|
2018-06-26 08:48:47 -04:00
|
|
|
* @brief Set passive scan time
|
2018-02-27 05:22:20 -05:00
|
|
|
*
|
2023-08-01 03:27:56 -04:00
|
|
|
* @param[in] time_ms passive scan time (msecs)
|
2018-02-27 05:22:20 -05:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK
|
|
|
|
* - ESP_FAIL
|
|
|
|
* - ESP_ERR_ARGUMENT
|
|
|
|
*/
|
|
|
|
esp_err_t esp_mesh_set_passive_scan_time(int time_ms);
|
|
|
|
|
|
|
|
/**
|
2018-06-26 08:48:47 -04:00
|
|
|
* @brief Get passive scan time
|
2018-02-27 05:22:20 -05:00
|
|
|
*
|
2018-06-26 08:48:47 -04:00
|
|
|
* @return interval_ms passive scan time (msecs)
|
2018-02-27 05:22:20 -05:00
|
|
|
*/
|
|
|
|
int esp_mesh_get_passive_scan_time(void);
|
|
|
|
|
2018-06-19 06:23:56 -04:00
|
|
|
/**
|
2018-06-26 08:48:47 -04:00
|
|
|
* @brief Set announce interval
|
|
|
|
* - The default short interval is 500 milliseconds.
|
|
|
|
* - The default long interval is 3000 milliseconds.
|
2018-06-19 06:23:56 -04:00
|
|
|
*
|
2018-06-26 08:48:47 -04:00
|
|
|
* @param[in] short_ms shall be greater than the default value
|
|
|
|
* @param[in] long_ms shall be greater than the default value
|
2018-06-19 06:23:56 -04:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK
|
|
|
|
*/
|
|
|
|
esp_err_t esp_mesh_set_announce_interval(int short_ms, int long_ms);
|
|
|
|
|
|
|
|
/**
|
2018-06-26 08:48:47 -04:00
|
|
|
* @brief Get announce interval
|
2018-06-19 06:23:56 -04:00
|
|
|
*
|
2018-06-26 08:48:47 -04:00
|
|
|
* @param[out] short_ms short interval
|
|
|
|
* @param[out] long_ms long interval
|
2018-06-19 06:23:56 -04:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK
|
|
|
|
*/
|
|
|
|
esp_err_t esp_mesh_get_announce_interval(int *short_ms, int *long_ms);
|
2018-02-27 05:22:20 -05:00
|
|
|
|
2020-04-30 09:40:38 -04:00
|
|
|
/**
|
2023-08-01 03:27:56 -04:00
|
|
|
* @brief Get the running duties of device, parent and children
|
|
|
|
*
|
|
|
|
* @param[out] ps_duties ps duties
|
2020-04-30 09:40:38 -04:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK
|
|
|
|
*/
|
|
|
|
esp_err_t esp_mesh_ps_get_duties(esp_mesh_ps_duties_t* ps_duties);
|
|
|
|
|
2020-10-23 11:55:29 -04:00
|
|
|
/**
|
|
|
|
* @brief Enable mesh print scan result
|
|
|
|
*
|
|
|
|
* @param[in] enable enable or not
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - ESP_OK
|
|
|
|
*/
|
|
|
|
esp_err_t esp_mesh_print_scan_result(bool enable);
|
2018-02-27 05:22:20 -05:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif /* __ESP_MESH_INTERNAL_H__ */
|