esp_mesh_internal.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. /*
  2. * SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef __ESP_MESH_INTERNAL_H__
  7. #define __ESP_MESH_INTERNAL_H__
  8. #include "esp_err.h"
  9. #include "esp_mesh.h"
  10. #include "esp_wifi.h"
  11. #include "esp_wifi_types.h"
  12. #include "esp_private/wifi.h"
  13. #include "esp_wifi_crypto_types.h"
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. /*******************************************************
  18. * Constants
  19. *******************************************************/
  20. /*******************************************************
  21. * Structures
  22. *******************************************************/
  23. typedef struct {
  24. int scan; /**< minimum scan times before being a root, default:10 */
  25. int vote; /**< max vote times in self-healing, default:1000 */
  26. int fail; /**< parent selection fail times, if the scan times reach this value,
  27. device will disconnect with associated children and join self-healing. default:60 */
  28. int monitor_ie; /**< acceptable times of parent networking IE change before update its own networking IE. default:3 */
  29. } mesh_attempts_t;
  30. typedef struct {
  31. int duration_ms; /* parent weak RSSI monitor duration, if the RSSI continues to be weak during this duration_ms,
  32. device will search for a new parent. */
  33. int cnx_rssi; /* RSSI threshold for keeping a good connection with parent.
  34. If set a value greater than -120 dBm, a timer will be armed to monitor parent RSSI at a period time of duration_ms. */
  35. int select_rssi; /* RSSI threshold for parent selection. It should be a value greater than switch_rssi. */
  36. int switch_rssi; /* Disassociate with current parent and switch to a new parent when the RSSI is greater than this set threshold. */
  37. int backoff_rssi; /* RSSI threshold for connecting to the root */
  38. } mesh_switch_parent_t;
  39. typedef struct {
  40. int high;
  41. int medium;
  42. int low;
  43. } mesh_rssi_threshold_t;
  44. /**
  45. * @brief Mesh networking IE
  46. */
  47. typedef struct {
  48. /**< mesh networking IE head */
  49. uint8_t eid; /**< element ID */
  50. uint8_t len; /**< element length */
  51. uint8_t oui[3]; /**< organization identifier */
  52. /**< mesh networking IE content */
  53. uint8_t type; /** ESP defined IE type */
  54. uint8_t encrypted : 1; /**< whether mesh networking IE is encrypted */
  55. uint8_t version : 7; /**< mesh networking IE version */
  56. /**< content */
  57. uint8_t mesh_type; /**< mesh device type */
  58. uint8_t mesh_id[6]; /**< mesh ID */
  59. uint8_t layer_cap; /**< max layer */
  60. uint8_t layer; /**< current layer */
  61. uint8_t assoc_cap; /**< max connections of mesh AP */
  62. uint8_t assoc; /**< current connections */
  63. uint8_t leaf_cap; /**< leaf capacity */
  64. uint8_t leaf_assoc; /**< the number of current connected leaf */
  65. uint16_t root_cap; /**< root capacity */
  66. uint16_t self_cap; /**< self capacity */
  67. uint16_t layer2_cap; /**< layer2 capacity */
  68. uint16_t scan_ap_num; /**< the number of scanning APs */
  69. int8_t rssi; /**< RSSI of the parent */
  70. int8_t router_rssi; /**< RSSI of the router */
  71. uint8_t flag; /**< flag of networking */
  72. uint8_t rc_addr[6]; /**< root address */
  73. int8_t rc_rssi; /**< root RSSI */
  74. uint8_t vote_addr[6]; /**< voter address */
  75. int8_t vote_rssi; /**< vote RSSI of the router */
  76. uint8_t vote_ttl; /**< vote ttl */
  77. uint16_t votes; /**< votes */
  78. uint16_t my_votes; /**< my votes */
  79. uint8_t reason; /**< reason */
  80. uint8_t child[6]; /**< child address */
  81. uint8_t toDS; /**< toDS state */
  82. } __attribute__((packed)) mesh_assoc_t;
  83. typedef struct {
  84. uint16_t layer_cap;
  85. uint16_t layer;
  86. } mesh_chain_layer_t;
  87. typedef struct {
  88. mesh_assoc_t tree;
  89. mesh_chain_layer_t chain;
  90. } __attribute__((packed)) mesh_chain_assoc_t;
  91. /* mesh max connections */
  92. #define MESH_MAX_CONNECTIONS (10)
  93. /**
  94. * @brief Mesh PS duties
  95. */
  96. typedef struct {
  97. uint8_t device;
  98. uint8_t parent;
  99. struct {
  100. bool used;
  101. uint8_t duty;
  102. uint8_t mac[6];
  103. } child[MESH_MAX_CONNECTIONS];
  104. } esp_mesh_ps_duties_t;
  105. /*******************************************************
  106. * Function Definitions
  107. *******************************************************/
  108. /**
  109. * @brief Set mesh softAP beacon interval
  110. *
  111. * @param[in] interval beacon interval (msecs) (100 msecs ~ 60000 msecs)
  112. *
  113. * @return
  114. * - ESP_OK
  115. * - ESP_FAIL
  116. * - ESP_ERR_WIFI_ARG
  117. */
  118. esp_err_t esp_mesh_set_beacon_interval(int interval_ms);
  119. /**
  120. * @brief Get mesh softAP beacon interval
  121. *
  122. * @param[out] interval beacon interval (msecs)
  123. *
  124. * @return
  125. * - ESP_OK
  126. */
  127. esp_err_t esp_mesh_get_beacon_interval(int *interval_ms);
  128. /**
  129. * @brief Set attempts for mesh self-organized networking
  130. *
  131. * @param[in] attempts
  132. *
  133. * @return
  134. * - ESP_OK
  135. * - ESP_FAIL
  136. */
  137. esp_err_t esp_mesh_set_attempts(mesh_attempts_t *attempts);
  138. /**
  139. * @brief Get attempts for mesh self-organized networking
  140. *
  141. * @param[out] attempts
  142. *
  143. * @return
  144. * - ESP_OK
  145. * - ESP_ERR_MESH_ARGUMENT
  146. */
  147. esp_err_t esp_mesh_get_attempts(mesh_attempts_t *attempts);
  148. /**
  149. * @brief Set parameters for parent switch
  150. *
  151. * @param[in] paras parameters for parent switch
  152. *
  153. * @return
  154. * - ESP_OK
  155. * - ESP_ERR_MESH_ARGUMENT
  156. */
  157. esp_err_t esp_mesh_set_switch_parent_paras(mesh_switch_parent_t *paras);
  158. /**
  159. * @brief Get parameters for parent switch
  160. *
  161. * @param[out] paras parameters for parent switch
  162. *
  163. * @return
  164. * - ESP_OK
  165. * - ESP_ERR_MESH_ARGUMENT
  166. */
  167. esp_err_t esp_mesh_get_switch_parent_paras(mesh_switch_parent_t *paras);
  168. /**
  169. * @brief Set RSSI threshold
  170. * - The default high RSSI threshold value is -78 dBm.
  171. * - The default medium RSSI threshold value is -82 dBm.
  172. * - The default low RSSI threshold value is -85 dBm.
  173. *
  174. * @param[in] threshold RSSI threshold
  175. *
  176. * @return
  177. * - ESP_OK
  178. * - ESP_ERR_MESH_ARGUMENT
  179. */
  180. esp_err_t esp_mesh_set_rssi_threshold(const mesh_rssi_threshold_t *threshold);
  181. /**
  182. * @brief Get RSSI threshold
  183. *
  184. * @param[out] threshold RSSI threshold
  185. *
  186. * @return
  187. * - ESP_OK
  188. * - ESP_ERR_MESH_ARGUMENT
  189. */
  190. esp_err_t esp_mesh_get_rssi_threshold(mesh_rssi_threshold_t *threshold);
  191. /**
  192. * @brief Enable the minimum rate to 6 Mbps
  193. *
  194. * @attention This API shall be called before Wi-Fi is started.
  195. *
  196. * @param[in] is_6m enable or not
  197. *
  198. * @return
  199. * - ESP_OK
  200. */
  201. esp_err_t esp_mesh_set_6m_rate(bool is_6m);
  202. /**
  203. * @brief Print the number of txQ waiting
  204. *
  205. * @return
  206. * - ESP_OK
  207. * - ESP_FAIL
  208. */
  209. esp_err_t esp_mesh_print_txQ_waiting(void);
  210. /**
  211. * @brief Print the number of rxQ waiting
  212. *
  213. * @return
  214. * - ESP_OK
  215. * - ESP_FAIL
  216. */
  217. esp_err_t esp_mesh_print_rxQ_waiting(void);
  218. /**
  219. * @brief Set passive scan time
  220. *
  221. * @param[in] interval_ms passive scan time (msecs)
  222. *
  223. * @return
  224. * - ESP_OK
  225. * - ESP_FAIL
  226. * - ESP_ERR_ARGUMENT
  227. */
  228. esp_err_t esp_mesh_set_passive_scan_time(int time_ms);
  229. /**
  230. * @brief Get passive scan time
  231. *
  232. * @return interval_ms passive scan time (msecs)
  233. */
  234. int esp_mesh_get_passive_scan_time(void);
  235. /**
  236. * @brief Set announce interval
  237. * - The default short interval is 500 milliseconds.
  238. * - The default long interval is 3000 milliseconds.
  239. *
  240. * @param[in] short_ms shall be greater than the default value
  241. * @param[in] long_ms shall be greater than the default value
  242. *
  243. * @return
  244. * - ESP_OK
  245. */
  246. esp_err_t esp_mesh_set_announce_interval(int short_ms, int long_ms);
  247. /**
  248. * @brief Get announce interval
  249. *
  250. * @param[out] short_ms short interval
  251. * @param[out] long_ms long interval
  252. *
  253. * @return
  254. * - ESP_OK
  255. */
  256. esp_err_t esp_mesh_get_announce_interval(int *short_ms, int *long_ms);
  257. /**
  258. * @brief Get the running duties of device, parent and children
  259. *
  260. * @return
  261. * - ESP_OK
  262. */
  263. esp_err_t esp_mesh_ps_get_duties(esp_mesh_ps_duties_t* ps_duties);
  264. /**
  265. * @brief Enable mesh print scan result
  266. *
  267. * @param[in] enable enable or not
  268. *
  269. * @return
  270. * - ESP_OK
  271. */
  272. esp_err_t esp_mesh_print_scan_result(bool enable);
  273. #ifdef __cplusplus
  274. }
  275. #endif
  276. #endif /* __ESP_MESH_INTERNAL_H__ */