esp_netif_defaults.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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 = 0, \
  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_SLIP() \
  67. { \
  68. .flags = ESP_NETIF_FLAG_IS_SLIP, \
  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 = "SLP_DEF", \
  74. .if_desc = "slip", \
  75. .route_prio = 16 \
  76. };
  77. /**
  78. * @brief Default configuration reference of ethernet interface
  79. */
  80. #define ESP_NETIF_DEFAULT_ETH() \
  81. { \
  82. .base = ESP_NETIF_BASE_DEFAULT_ETH, \
  83. .driver = NULL, \
  84. .stack = ESP_NETIF_NETSTACK_DEFAULT_ETH, \
  85. }
  86. /**
  87. * @brief Default configuration reference of WIFI AP
  88. */
  89. #define ESP_NETIF_DEFAULT_WIFI_AP() \
  90. { \
  91. .base = ESP_NETIF_BASE_DEFAULT_WIFI_AP, \
  92. .driver = NULL, \
  93. .stack = ESP_NETIF_NETSTACK_DEFAULT_WIFI_AP, \
  94. }
  95. /**
  96. * @brief Default configuration reference of WIFI STA
  97. */
  98. #define ESP_NETIF_DEFAULT_WIFI_STA() \
  99. { \
  100. .base = ESP_NETIF_BASE_DEFAULT_WIFI_STA, \
  101. .driver = NULL, \
  102. .stack = ESP_NETIF_NETSTACK_DEFAULT_WIFI_STA, \
  103. }
  104. /**
  105. * @brief Default configuration reference of PPP client
  106. */
  107. #define ESP_NETIF_DEFAULT_PPP() \
  108. { \
  109. .base = ESP_NETIF_BASE_DEFAULT_PPP, \
  110. .driver = NULL, \
  111. .stack = ESP_NETIF_NETSTACK_DEFAULT_PPP, \
  112. }
  113. /**
  114. * @brief Default configuration reference of SLIP client
  115. */
  116. #define ESP_NETIF_DEFAULT_SLIP() \
  117. { \
  118. .base = ESP_NETIF_BASE_DEFAULT_SLIP, \
  119. .driver = NULL, \
  120. .stack = ESP_NETIF_NETSTACK_DEFAULT_SLIP, \
  121. }
  122. /**
  123. * @brief Default base config (esp-netif inherent) of WIFI STA
  124. */
  125. #define ESP_NETIF_BASE_DEFAULT_WIFI_STA &_g_esp_netif_inherent_sta_config
  126. /**
  127. * @brief Default base config (esp-netif inherent) of WIFI AP
  128. */
  129. #define ESP_NETIF_BASE_DEFAULT_WIFI_AP &_g_esp_netif_inherent_ap_config
  130. /**
  131. * @brief Default base config (esp-netif inherent) of ethernet interface
  132. */
  133. #define ESP_NETIF_BASE_DEFAULT_ETH &_g_esp_netif_inherent_eth_config
  134. /**
  135. * @brief Default base config (esp-netif inherent) of ppp interface
  136. */
  137. #define ESP_NETIF_BASE_DEFAULT_PPP &_g_esp_netif_inherent_ppp_config
  138. /**
  139. * @brief Default base config (esp-netif inherent) of slip interface
  140. */
  141. #define ESP_NETIF_BASE_DEFAULT_SLIP &_g_esp_netif_inherent_slip_config
  142. #define ESP_NETIF_NETSTACK_DEFAULT_ETH _g_esp_netif_netstack_default_eth
  143. #define ESP_NETIF_NETSTACK_DEFAULT_WIFI_STA _g_esp_netif_netstack_default_wifi_sta
  144. #define ESP_NETIF_NETSTACK_DEFAULT_WIFI_AP _g_esp_netif_netstack_default_wifi_ap
  145. #define ESP_NETIF_NETSTACK_DEFAULT_PPP _g_esp_netif_netstack_default_ppp
  146. #define ESP_NETIF_NETSTACK_DEFAULT_SLIP _g_esp_netif_netstack_default_slip
  147. //
  148. // Include default network stacks configs
  149. // - Network stack configurations are provided in a specific network stack
  150. // implementation that is invisible to user API
  151. // - Here referenced only as opaque pointers
  152. //
  153. extern const esp_netif_netstack_config_t *_g_esp_netif_netstack_default_eth;
  154. extern const esp_netif_netstack_config_t *_g_esp_netif_netstack_default_wifi_sta;
  155. extern const esp_netif_netstack_config_t *_g_esp_netif_netstack_default_wifi_ap;
  156. extern const esp_netif_netstack_config_t *_g_esp_netif_netstack_default_ppp;
  157. extern const esp_netif_netstack_config_t *_g_esp_netif_netstack_default_slip;
  158. //
  159. // Include default common configs inherent to esp-netif
  160. // - These inherent configs are defined in esp_netif_defaults.c and describe
  161. // common behavioural patterns for common interfaces such as STA, AP, ETH, PPP
  162. //
  163. extern const esp_netif_inherent_config_t _g_esp_netif_inherent_sta_config;
  164. extern const esp_netif_inherent_config_t _g_esp_netif_inherent_ap_config;
  165. extern const esp_netif_inherent_config_t _g_esp_netif_inherent_eth_config;
  166. extern const esp_netif_inherent_config_t _g_esp_netif_inherent_ppp_config;
  167. extern const esp_netif_inherent_config_t _g_esp_netif_inherent_slip_config;
  168. extern const esp_netif_ip_info_t _g_esp_netif_soft_ap_ip;
  169. #ifdef __cplusplus
  170. }
  171. #endif
  172. #endif //_ESP_NETIF_DEFAULTS_H