esp_mesh_internal.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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:10000 */
  32. int fail; /**< parent selection fail times, if the scan times reach this value,
  33. will disconnect with associated children and join self-healing. default:60 */
  34. int monitor_ie; /**< acceptable times of parent ie change before update self 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. will switch to a better parent */
  39. int cnx_rssi; /* RSSI threshold for keeping a good connection with parent */
  40. int select_rssi; /* RSSI threshold for parent selection, should be a value greater than switch_rssi */
  41. int switch_rssi; /* RSSI threshold for action to reselect a better parent */
  42. int backoff_rssi; /* RSSI threshold for connecting to the root */
  43. } mesh_switch_parent_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; /** mesh networking IE type */
  54. uint8_t encryped : 1; /**< if 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 scanned 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. /*******************************************************
  84. * Function Definitions
  85. *******************************************************/
  86. /**
  87. * @brief set mesh softAP beacon interval
  88. *
  89. * @param interval beacon interval(ms) (100ms ~ 60000ms)
  90. *
  91. * @return
  92. * - ESP_OK
  93. * - ESP_FAIL
  94. * - ESP_ERR_WIFI_ARG
  95. */
  96. esp_err_t esp_mesh_set_beacon_interval(int interval_ms);
  97. /**
  98. * @brief get mesh softAP beacon interval
  99. *
  100. * @param interval beacon interval(ms)
  101. *
  102. * @return
  103. * - ESP_OK
  104. */
  105. esp_err_t esp_mesh_get_beacon_interval(int *interval_ms);
  106. /**
  107. * @brief set attempts for mesh self-organized networking
  108. *
  109. * @param attempts
  110. *
  111. * @return
  112. * - ESP_OK
  113. * - ESP_FAIL
  114. */
  115. esp_err_t esp_mesh_set_attempts(mesh_attempts_t *attempts);
  116. /**
  117. * @brief get attempts for mesh self-organized networking
  118. *
  119. * @param attempts
  120. *
  121. * @return
  122. * - ESP_OK
  123. * - ESP_FAIL
  124. */
  125. esp_err_t esp_mesh_get_attempts(mesh_attempts_t *attempts);
  126. /**
  127. * @brief set parameters for parent switch
  128. *
  129. * @param paras parameters for parent switch
  130. *
  131. * @return
  132. * - ESP_OK
  133. * - ESP_FAIL
  134. */
  135. esp_err_t esp_mesh_set_switch_parent_paras(mesh_switch_parent_t *paras);
  136. /**
  137. * @brief get parameters for parent switch
  138. *
  139. * @param paras parameters for parent switch
  140. *
  141. * @return
  142. * - ESP_OK
  143. * - ESP_FAIL
  144. */
  145. esp_err_t esp_mesh_get_switch_parent_paras(mesh_switch_parent_t *paras);
  146. /**
  147. * @brief print the number of txQ waiting
  148. *
  149. * @return
  150. * - ESP_OK
  151. * - ESP_FAIL
  152. */
  153. esp_err_t esp_mesh_print_txQ_waiting(void);
  154. /**
  155. * @brief print the number of rxQ waiting
  156. *
  157. * @return
  158. * - ESP_OK
  159. * - ESP_FAIL
  160. */
  161. esp_err_t esp_mesh_print_rxQ_waiting(void);
  162. /**
  163. * @brief set passive scan time
  164. *
  165. * @param interval_ms passive scan time(ms)
  166. *
  167. * @return
  168. * - ESP_OK
  169. * - ESP_FAIL
  170. * - ESP_ERR_ARGUMENT
  171. */
  172. esp_err_t esp_mesh_set_passive_scan_time(int time_ms);
  173. /**
  174. * @brief get passive scan time
  175. *
  176. * @return interval_ms passive scan time(ms)
  177. */
  178. int esp_mesh_get_passive_scan_time(void);
  179. #ifdef __cplusplus
  180. }
  181. #endif
  182. #endif /* __ESP_MESH_INTERNAL_H__ */