esp_mesh_internal.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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:120. */
  34. int monitor_ie; /**< acceptable times of parent networking IE change before update self networking IE, default:10. */
  35. } mesh_attempts_t;
  36. typedef struct {
  37. int duration_ms; /* parent weak RSSI monitor duration. If the RSSI with current parent is less than cnx_rssi continuously
  38. within this duration_ms, device will search for a better parent. */
  39. int cnx_rssi; /* RSSI threshold for keeping a good connection with parent.
  40. If set a value greater than -120 dBm, device will arm a timer to monitor current RSSI at a period time of
  41. duration_ms. */
  42. int select_rssi; /* RSSI threshold for parent selection, should be a value greater than switch_rssi. */
  43. int switch_rssi; /* RSSI threshold for parent switch. Device will disassociate current parent and switch to a new parent when
  44. the RSSI with the new parent is greater than this set threshold. */
  45. int backoff_rssi; /* RSSI threshold for connecting to the root */
  46. } mesh_switch_parent_t;
  47. typedef struct {
  48. int high;
  49. int medium;
  50. int low;
  51. } mesh_rssi_threshold_t;
  52. /**
  53. * @brief mesh networking IE
  54. */
  55. typedef struct {
  56. /**< mesh networking IE head */
  57. uint8_t eid; /**< element ID */
  58. uint8_t len; /**< element length */
  59. uint8_t oui[3]; /**< organization identifier */
  60. /**< mesh networking IE content */
  61. uint8_t type; /** ESP defined IE type */
  62. uint8_t encryped : 1; /**< whether mesh networking IE is encrypted */
  63. uint8_t version : 7; /**< mesh networking IE version */
  64. /**< content */
  65. uint8_t mesh_type; /**< mesh device type */
  66. uint8_t mesh_id[6]; /**< mesh ID */
  67. uint8_t layer_cap; /**< max layer */
  68. uint8_t layer; /**< current layer */
  69. uint8_t assoc_cap; /**< max connections of mesh AP */
  70. uint8_t assoc; /**< current connections */
  71. uint8_t leaf_cap; /**< leaf capacity */
  72. uint8_t leaf_assoc; /**< the number of current connected leaf */
  73. uint16_t root_cap; /**< root capacity */
  74. uint16_t self_cap; /**< self capacity */
  75. uint16_t layer2_cap; /**< layer2 capacity */
  76. uint16_t scan_ap_num; /**< the number of scanned APs */
  77. int8_t rssi; /**< RSSI of the parent */
  78. int8_t router_rssi; /**< RSSI of the router */
  79. uint8_t flag; /**< flag of networking */
  80. uint8_t rc_addr[6]; /**< root address */
  81. int8_t rc_rssi; /**< root RSSI */
  82. uint8_t vote_addr[6]; /**< voter address */
  83. int8_t vote_rssi; /**< vote RSSI of the router */
  84. uint8_t vote_ttl; /**< vote ttl */
  85. uint16_t votes; /**< votes */
  86. uint16_t my_votes; /**< my votes */
  87. uint8_t reason; /**< reason */
  88. uint8_t child[6]; /**< child address */
  89. uint8_t toDS; /**< toDS state */
  90. } __attribute__((packed)) mesh_assoc_t;
  91. /*******************************************************
  92. * Function Definitions
  93. *******************************************************/
  94. /**
  95. * @brief set mesh softAP beacon interval
  96. *
  97. * @param interval beacon interval(ms) (100ms ~ 60000ms)
  98. *
  99. * @return
  100. * - ESP_OK
  101. * - ESP_FAIL
  102. * - ESP_ERR_WIFI_ARG
  103. */
  104. esp_err_t esp_mesh_set_beacon_interval(int interval_ms);
  105. /**
  106. * @brief get mesh softAP beacon interval
  107. *
  108. * @param interval beacon interval(ms)
  109. *
  110. * @return
  111. * - ESP_OK
  112. */
  113. esp_err_t esp_mesh_get_beacon_interval(int *interval_ms);
  114. /**
  115. * @brief set attempts for mesh self-organized networking
  116. *
  117. * @param attempts
  118. *
  119. * @return
  120. * - ESP_OK
  121. * - ESP_FAIL
  122. */
  123. esp_err_t esp_mesh_set_attempts(mesh_attempts_t *attempts);
  124. /**
  125. * @brief get attempts for mesh self-organized networking
  126. *
  127. * @param attempts
  128. *
  129. * @return
  130. * - ESP_OK
  131. * - ESP_ERR_MESH_ARGUMENT
  132. */
  133. esp_err_t esp_mesh_get_attempts(mesh_attempts_t *attempts);
  134. /**
  135. * @brief set parameters for parent switch
  136. *
  137. * @param paras parameters for parent switch
  138. *
  139. * @return
  140. * - ESP_OK
  141. * - ESP_ERR_MESH_ARGUMENT
  142. */
  143. esp_err_t esp_mesh_set_switch_parent_paras(mesh_switch_parent_t *paras);
  144. /**
  145. * @brief get parameters for parent switch
  146. *
  147. * @param paras parameters for parent switch
  148. *
  149. * @return
  150. * - ESP_OK
  151. * - ESP_ERR_MESH_ARGUMENT
  152. */
  153. esp_err_t esp_mesh_get_switch_parent_paras(mesh_switch_parent_t *paras);
  154. /**
  155. * @brief set RSSI threshold
  156. * The default high RSSI threshold value is -78 dBm.
  157. * The default medium RSSI threshold value is -82 dBm.
  158. * The default low RSSI threshold value is -85 dBm.
  159. *
  160. * @param threshold RSSI threshold
  161. *
  162. * @return
  163. * - ESP_OK
  164. * - ESP_ERR_MESH_ARGUMENT
  165. */
  166. esp_err_t esp_mesh_set_rssi_threshold(const mesh_rssi_threshold_t *threshold);
  167. /**
  168. * @brief get RSSI threshold
  169. * @param threshold RSSI threshold
  170. *
  171. * @return
  172. * - ESP_OK
  173. * - ESP_ERR_MESH_ARGUMENT
  174. */
  175. esp_err_t esp_mesh_get_rssi_threshold(mesh_rssi_threshold_t *threshold);
  176. /**
  177. * @brief enable the minimum rate to 6Mbps
  178. *
  179. * @attention This API shall be called before WiFi start.
  180. *
  181. * @param is_6m enable or not
  182. *
  183. * @return
  184. * - ESP_OK
  185. */
  186. esp_err_t esp_mesh_set_6m_rate(bool is_6m);
  187. /**
  188. * @brief print the number of txQ waiting
  189. *
  190. * @return
  191. * - ESP_OK
  192. * - ESP_FAIL
  193. */
  194. esp_err_t esp_mesh_print_txQ_waiting(void);
  195. /**
  196. * @brief print the number of rxQ waiting
  197. *
  198. * @return
  199. * - ESP_OK
  200. * - ESP_FAIL
  201. */
  202. esp_err_t esp_mesh_print_rxQ_waiting(void);
  203. /**
  204. * @brief set passive scan time
  205. *
  206. * @param interval_ms passive scan time(ms)
  207. *
  208. * @return
  209. * - ESP_OK
  210. * - ESP_FAIL
  211. * - ESP_ERR_ARGUMENT
  212. */
  213. esp_err_t esp_mesh_set_passive_scan_time(int time_ms);
  214. /**
  215. * @brief get passive scan time
  216. *
  217. * @return interval_ms passive scan time(ms)
  218. */
  219. int esp_mesh_get_passive_scan_time(void);
  220. /**
  221. * @brief set announce interval
  222. * The default short interval is 500 milliseconds.
  223. * The default long interval is 3000 milliseconds.
  224. *
  225. * @param short_ms shall be greater than the default value
  226. * @param long_ms shall be greater than the default value
  227. *
  228. * @return
  229. * - ESP_OK
  230. */
  231. esp_err_t esp_mesh_set_announce_interval(int short_ms, int long_ms);
  232. /**
  233. * @brief get announce interval
  234. *
  235. * @param short_ms short interval
  236. * @param long_ms long interval
  237. *
  238. * @return
  239. * - ESP_OK
  240. */
  241. esp_err_t esp_mesh_get_announce_interval(int *short_ms, int *long_ms);
  242. #ifdef __cplusplus
  243. }
  244. #endif
  245. #endif /* __ESP_MESH_INTERNAL_H__ */