esp_netif_defaults.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. // Copyright 2015-2016 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_NETIF_DEFAULTS_H
  14. #define _ESP_NETIF_DEFAULTS_H
  15. #include "esp_compiler.h"
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. //
  20. // Macros to assemble master configs with partial configs from netif, stack and driver
  21. //
  22. #define ESP_NETIF_INHERENT_DEFAULT_WIFI_STA() \
  23. { \
  24. .flags = (esp_netif_flags_t)(ESP_NETIF_DHCP_CLIENT | ESP_NETIF_FLAG_GARP | ESP_NETIF_FLAG_EVENT_IP_MODIFIED), \
  25. ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(mac) \
  26. ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(ip_info) \
  27. .get_ip_event = IP_EVENT_STA_GOT_IP, \
  28. .lost_ip_event = IP_EVENT_STA_LOST_IP, \
  29. .if_key = "WIFI_STA_DEF", \
  30. .if_desc = "sta", \
  31. .route_prio = 100 \
  32. } \
  33. #define ESP_NETIF_INHERENT_DEFAULT_WIFI_AP() \
  34. { \
  35. .flags = (esp_netif_flags_t)(ESP_NETIF_DHCP_SERVER | ESP_NETIF_FLAG_AUTOUP), \
  36. ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(mac) \
  37. .ip_info = &_g_esp_netif_soft_ap_ip, \
  38. .get_ip_event = 0, \
  39. .lost_ip_event = 0, \
  40. .if_key = "WIFI_AP_DEF", \
  41. .if_desc = "ap", \
  42. .route_prio = 10 \
  43. };
  44. #define ESP_NETIF_INHERENT_DEFAULT_ETH() \
  45. { \
  46. .flags = (esp_netif_flags_t)(ESP_NETIF_DHCP_CLIENT | ESP_NETIF_FLAG_GARP | ESP_NETIF_FLAG_EVENT_IP_MODIFIED), \
  47. ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(mac) \
  48. ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(ip_info) \
  49. .get_ip_event = IP_EVENT_ETH_GOT_IP, \
  50. .lost_ip_event = IP_EVENT_ETH_LOST_IP, \
  51. .if_key = "ETH_DEF", \
  52. .if_desc = "eth", \
  53. .route_prio = 50 \
  54. };
  55. #define ESP_NETIF_INHERENT_DEFAULT_PPP() \
  56. { \
  57. .flags = ESP_NETIF_FLAG_IS_PPP, \
  58. ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(mac) \
  59. ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(ip_info) \
  60. .get_ip_event = IP_EVENT_PPP_GOT_IP, \
  61. .lost_ip_event = IP_EVENT_PPP_LOST_IP, \
  62. .if_key = "PPP_DEF", \
  63. .if_desc = "ppp", \
  64. .route_prio = 20 \
  65. };
  66. #define ESP_NETIF_INHERENT_DEFAULT_OPENTHREAD() \
  67. { \
  68. .flags = 0, \
  69. ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(mac) \
  70. ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(ip_info) \
  71. .get_ip_event = 0, \
  72. .lost_ip_event = 0, \
  73. .if_key = "OT_DEF", \
  74. .if_desc = "openthread", \
  75. .route_prio = 15 \
  76. };
  77. #define ESP_NETIF_INHERENT_DEFAULT_SLIP() \
  78. { \
  79. .flags = ESP_NETIF_FLAG_IS_SLIP, \
  80. ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(mac) \
  81. ESP_COMPILER_DESIGNATED_INIT_AGGREGATE_TYPE_EMPTY(ip_info) \
  82. .get_ip_event = 0, \
  83. .lost_ip_event = 0, \
  84. .if_key = "SLP_DEF", \
  85. .if_desc = "slip", \
  86. .route_prio = 16 \
  87. };
  88. /**
  89. * @brief Default configuration reference of ethernet interface
  90. */
  91. #define ESP_NETIF_DEFAULT_ETH() \
  92. { \
  93. .base = ESP_NETIF_BASE_DEFAULT_ETH, \
  94. .driver = NULL, \
  95. .stack = ESP_NETIF_NETSTACK_DEFAULT_ETH, \
  96. }
  97. /**
  98. * @brief Default configuration reference of WIFI AP
  99. */
  100. #define ESP_NETIF_DEFAULT_WIFI_AP() \
  101. { \
  102. .base = ESP_NETIF_BASE_DEFAULT_WIFI_AP, \
  103. .driver = NULL, \
  104. .stack = ESP_NETIF_NETSTACK_DEFAULT_WIFI_AP, \
  105. }
  106. /**
  107. * @brief Default configuration reference of WIFI STA
  108. */
  109. #define ESP_NETIF_DEFAULT_WIFI_STA() \
  110. { \
  111. .base = ESP_NETIF_BASE_DEFAULT_WIFI_STA, \
  112. .driver = NULL, \
  113. .stack = ESP_NETIF_NETSTACK_DEFAULT_WIFI_STA, \
  114. }
  115. /**
  116. * @brief Default configuration reference of PPP client
  117. */
  118. #define ESP_NETIF_DEFAULT_PPP() \
  119. { \
  120. .base = ESP_NETIF_BASE_DEFAULT_PPP, \
  121. .driver = NULL, \
  122. .stack = ESP_NETIF_NETSTACK_DEFAULT_PPP, \
  123. }
  124. /**
  125. * @brief Default configuration reference of SLIP client
  126. */
  127. #define ESP_NETIF_DEFAULT_SLIP() \
  128. { \
  129. .base = ESP_NETIF_BASE_DEFAULT_SLIP, \
  130. .driver = NULL, \
  131. .stack = ESP_NETIF_NETSTACK_DEFAULT_SLIP, \
  132. }
  133. /**
  134. * @brief Default base config (esp-netif inherent) of WIFI STA
  135. */
  136. #define ESP_NETIF_BASE_DEFAULT_WIFI_STA &_g_esp_netif_inherent_sta_config
  137. /**
  138. * @brief Default base config (esp-netif inherent) of WIFI AP
  139. */
  140. #define ESP_NETIF_BASE_DEFAULT_WIFI_AP &_g_esp_netif_inherent_ap_config
  141. /**
  142. * @brief Default base config (esp-netif inherent) of ethernet interface
  143. */
  144. #define ESP_NETIF_BASE_DEFAULT_ETH &_g_esp_netif_inherent_eth_config
  145. /**
  146. * @brief Default base config (esp-netif inherent) of ppp interface
  147. */
  148. #define ESP_NETIF_BASE_DEFAULT_PPP &_g_esp_netif_inherent_ppp_config
  149. /**
  150. * @brief Default base config (esp-netif inherent) of slip interface
  151. */
  152. #define ESP_NETIF_BASE_DEFAULT_SLIP &_g_esp_netif_inherent_slip_config
  153. #define ESP_NETIF_NETSTACK_DEFAULT_ETH _g_esp_netif_netstack_default_eth
  154. #define ESP_NETIF_NETSTACK_DEFAULT_WIFI_STA _g_esp_netif_netstack_default_wifi_sta
  155. #define ESP_NETIF_NETSTACK_DEFAULT_WIFI_AP _g_esp_netif_netstack_default_wifi_ap
  156. #define ESP_NETIF_NETSTACK_DEFAULT_PPP _g_esp_netif_netstack_default_ppp
  157. #define ESP_NETIF_NETSTACK_DEFAULT_SLIP _g_esp_netif_netstack_default_slip
  158. #define ESP_NETIF_NETSTACK_DEFAULT_OPENTHREAD _g_esp_netif_netstack_default_openthread
  159. //
  160. // Include default network stacks configs
  161. // - Network stack configurations are provided in a specific network stack
  162. // implementation that is invisible to user API
  163. // - Here referenced only as opaque pointers
  164. //
  165. extern const esp_netif_netstack_config_t *_g_esp_netif_netstack_default_eth;
  166. extern const esp_netif_netstack_config_t *_g_esp_netif_netstack_default_wifi_sta;
  167. extern const esp_netif_netstack_config_t *_g_esp_netif_netstack_default_wifi_ap;
  168. extern const esp_netif_netstack_config_t *_g_esp_netif_netstack_default_ppp;
  169. extern const esp_netif_netstack_config_t *_g_esp_netif_netstack_default_slip;
  170. //
  171. // Include default common configs inherent to esp-netif
  172. // - These inherent configs are defined in esp_netif_defaults.c and describe
  173. // common behavioural patterns for common interfaces such as STA, AP, ETH, PPP
  174. //
  175. extern const esp_netif_inherent_config_t _g_esp_netif_inherent_sta_config;
  176. extern const esp_netif_inherent_config_t _g_esp_netif_inherent_ap_config;
  177. extern const esp_netif_inherent_config_t _g_esp_netif_inherent_eth_config;
  178. extern const esp_netif_inherent_config_t _g_esp_netif_inherent_ppp_config;
  179. extern const esp_netif_inherent_config_t _g_esp_netif_inherent_slip_config;
  180. extern const esp_netif_ip_info_t _g_esp_netif_soft_ap_ip;
  181. #if CONFIG_OPENTHREAD_ENABLED
  182. /**
  183. * @brief Default configuration reference of SLIP client
  184. */
  185. #define ESP_NETIF_DEFAULT_OPENTHREAD() \
  186. { \
  187. .base = ESP_NETIF_BASE_DEFAULT_OPENTHREAD, \
  188. .driver = NULL, \
  189. .stack = ESP_NETIF_NETSTACK_DEFAULT_OPENTHREAD, \
  190. }
  191. /**
  192. * @brief Default base config (esp-netif inherent) of openthread interface
  193. */
  194. #define ESP_NETIF_BASE_DEFAULT_OPENTHREAD &_g_esp_netif_inherent_openthread_config
  195. extern const esp_netif_netstack_config_t *_g_esp_netif_netstack_default_openthread;
  196. extern const esp_netif_inherent_config_t _g_esp_netif_inherent_openthread_config;
  197. #endif // CONFIG_OPENTHREAD_ENABLED
  198. #ifdef __cplusplus
  199. }
  200. #endif
  201. #endif //_ESP_NETIF_DEFAULTS_H