esp_mesh_internal.h 8.0 KB

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