esp_mesh_internal.h 8.8 KB

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