esp-sdk-lib.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /* esp-sdk-lib.h
  2. *
  3. * Copyright (C) 2006-2024 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. #ifndef __ESP_SDK_LIB_H__
  22. #define __ESP_SDK_LIB_H__
  23. /* Always include wolfcrypt/settings.h before any other wolfSSL file. */
  24. /* Reminder: settings.h pulls in user_settings.h; don't include it here. */
  25. #include <wolfssl/wolfcrypt/settings.h>
  26. #if defined(WOLFSSL_ESPIDF) /* Entire file is only for Espressif EDP-IDF */
  27. /* WOLFSSL_USER_SETTINGS must be defined, typically in the CMakeLists.txt: */
  28. /* set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DWOLFSSL_USER_SETTINGS") */
  29. #ifndef WOLFSSL_USER_SETTINGS
  30. #error "WOLFSSL_USER_SETTINGS must be defined for Espressif targts"
  31. #endif
  32. /* FreeRTOS */
  33. #include <freertos/FreeRTOS.h>
  34. #include <freertos/task.h>
  35. #include <freertos/event_groups.h>
  36. /* Espressif */
  37. #include "sdkconfig.h" /* ensure ESP-IDF settings are available everywhere */
  38. #include <esp_idf_version.h>
  39. #include <esp_log.h>
  40. #define ESP_SDK_MEM_LIB_VERSION 1
  41. /**
  42. ******************************************************************************
  43. ******************************************************************************
  44. ** USER APPLICATION SETTINGS BEGIN
  45. ******************************************************************************
  46. ******************************************************************************
  47. **/
  48. /* when using a private config with plain text passwords,
  49. * file my_private_config.h should be excluded from git updates */
  50. /* #define USE_MY_PRIVATE_CONFIG */
  51. /* Note that IntelliSense may not work properly in the next section for the
  52. * Espressif SDK 3.4 on the ESP8266. Macros should still be defined.
  53. * See the project-level Makefile. Example found in:
  54. * https://github.com/wolfSSL/wolfssl/tree/master/IDE/Espressif/ESP-IDF/examples/template
  55. *
  56. * The USE_MY_PRIVATE_[OS]_CONFIG is typically an environment variable that
  57. * triggers the make (not cmake) to add compiler defines.
  58. */
  59. #if defined(USE_MY_PRIVATE_WINDOWS_CONFIG)
  60. #include "/workspace/my_private_config.h"
  61. #elif defined(USE_MY_PRIVATE_WSL_CONFIG)
  62. #include "/mnt/c/workspace/my_private_config.h"
  63. #elif defined(USE_MY_PRIVATE_LINUX_CONFIG)
  64. #include "~/workspace/my_private_config.h"
  65. #elif defined(USE_MY_PRIVATE_MAC_CONFIG)
  66. #include "~/Documents/my_private_config.h"
  67. #elif defined(USE_MY_PRIVATE_CONFIG)
  68. /* This section works best with cmake & non-environment variable setting */
  69. #if defined(WOLFSSL_CMAKE_SYSTEM_NAME_WINDOWS)
  70. #define WOLFSSL_CMAKE
  71. #include "/workspace/my_private_config.h"
  72. #elif defined(WOLFSSL_MAKE_SYSTEM_NAME_WINDOWS)
  73. #define WOLFSSL_MAKE
  74. #include "/workspace/my_private_config.h"
  75. #elif defined(WOLFSSL_CMAKE_SYSTEM_NAME_WSL)
  76. #define WOLFSSL_CMAKE
  77. #include "/mnt/c/workspace/my_private_config.h"
  78. #elif defined(WOLFSSL_MAKE_SYSTEM_NAME_WSL)
  79. #define WOLFSSL_MAKE
  80. #include "/mnt/c/workspace/my_private_config.h"
  81. #elif defined(WOLFSSL_CMAKE_SYSTEM_NAME_LINUX)
  82. #define WOLFSSL_CMAKE
  83. #include "~/workspace/my_private_config.h"
  84. #elif defined(WOLFSSL_MAKE_SYSTEM_NAME_LINUX)
  85. #define WOLFSSL_MAKE
  86. #include "~/workspace/my_private_config.h"
  87. #elif defined(WOLFSSL_CMAKE_SYSTEM_NAME_APPLE)
  88. #include "~/Documents/my_private_config.h"
  89. #elif defined(WOLFSSL_MAKE_SYSTEM_NAME_APPLE)
  90. #define WOLFSSL_MAKE
  91. #include "~/Documents/my_private_config.h"
  92. #elif defined(OS_WINDOWS)
  93. #include "/workspace/my_private_config.h"
  94. #else
  95. /* Edit as needed for your private config: */
  96. #warning "default private config using /workspace/my_private_config.h"
  97. #include "/workspace/my_private_config.h"
  98. #endif
  99. #else
  100. /*
  101. ** The examples use WiFi configuration that you can set via project
  102. ** configuration menu
  103. **
  104. ** If you'd rather not, just change the below entries to strings with
  105. ** the config you want - ie #define EXAMPLE_WIFI_SSID "mywifissid"
  106. */
  107. #if defined(CONFIG_ESP_WIFI_SSID)
  108. /* tyically from ESP32 with ESP-IDF v4 ot v5 */
  109. #define EXAMPLE_ESP_WIFI_SSID CONFIG_ESP_WIFI_SSID
  110. #elif defined(CONFIG_EXAMPLE_WIFI_SSID)
  111. /* typically from ESP8266 rtos-sdk/v3.4 */
  112. #undef EXAMPLE_ESP_WIFI_SSID
  113. #define EXAMPLE_ESP_WIFI_SSID CONFIG_EXAMPLE_WIFI_SSID
  114. #else
  115. #define EXAMPLE_ESP_WIFI_SSID "MYSSID_WIFI_CONNECT"
  116. #endif
  117. #if defined(CONFIG_ESP_WIFI_PASSWORD)
  118. /* tyically from ESP32 with ESP-IDF v4 or v5 */
  119. #define EXAMPLE_ESP_WIFI_PASS CONFIG_ESP_WIFI_PASSWORD
  120. #elif defined(CONFIG_EXAMPLE_WIFI_SSID)
  121. /* typically from ESP8266 rtos-sdk/v3.4 */
  122. #undef EXAMPLE_ESP_WIFI_PASS
  123. #define EXAMPLE_ESP_WIFI_PASS CONFIG_EXAMPLE_WIFI_PASSWORD
  124. #else
  125. #define EXAMPLE_ESP_WIFI_PASS "MYPASSWORD_WIFI_CONNECT"
  126. #endif
  127. #endif
  128. #ifdef __cplusplus
  129. extern "C" {
  130. #endif
  131. WOLFSSL_LOCAL esp_err_t esp_sdk_time_mem_init(void);
  132. WOLFSSL_LOCAL esp_err_t sdk_var_whereis(const char* v_name, void* v);
  133. WOLFSSL_LOCAL intptr_t esp_sdk_stack_pointer(void);
  134. /******************************************************************************
  135. * Time helpers
  136. ******************************************************************************/
  137. WOLFSSL_LOCAL esp_err_t esp_sdk_time_lib_init(void);
  138. /* a function to show the current data and time */
  139. WOLFSSL_LOCAL esp_err_t esp_show_current_datetime(void);
  140. /* worst case, if GitHub time not available, used fixed time */
  141. WOLFSSL_LOCAL esp_err_t set_fixed_default_time(void);
  142. /* set time from string (e.g. GitHub commit time) */
  143. WOLFSSL_LOCAL esp_err_t set_time_from_string(const char* time_buffer);
  144. /* set time from NTP servers,
  145. * also initially calls set_fixed_default_time or set_time_from_string */
  146. WOLFSSL_LOCAL esp_err_t set_time(void);
  147. /* wait NTP_RETRY_COUNT seconds before giving up on NTP time */
  148. WOLFSSL_LOCAL esp_err_t set_time_wait_for_ntp(void);
  149. #ifndef NO_ESP_SDK_WIFI
  150. /******************************************************************************
  151. * WiFi helpers
  152. ******************************************************************************/
  153. /* ESP lwip */
  154. #define EXAMPLE_ESP_MAXIMUM_RETRY CONFIG_ESP_MAXIMUM_RETRY
  155. #define TLS_SMP_WIFI_SSID CONFIG_WIFI_SSID
  156. #define TLS_SMP_WIFI_PASS CONFIG_WIFI_PASSWORD
  157. /* Optionally enable WiFi. Typically not used for wolfcrypt tests */
  158. /* #define USE_WIFI_EXAMPLE */
  159. #ifdef USE_WIFI_EXAMPLE
  160. #include "esp_netif.h"
  161. #if defined(CONFIG_IDF_TARGET_ESP8266)
  162. /* TODO find and implement ESP8266 example include */
  163. #else
  164. #include "protocol_examples_common.h" /* see project CMakeLists.txt */
  165. #endif
  166. #endif
  167. /* ESP lwip */
  168. #define EXAMPLE_ESP_MAXIMUM_RETRY CONFIG_ESP_MAXIMUM_RETRY
  169. WOLFSSL_LOCAL esp_err_t esp_sdk_wifi_lib_init(void);
  170. WOLFSSL_LOCAL esp_err_t esp_sdk_wifi_init_sta(void);
  171. WOLFSSL_LOCAL esp_err_t esp_sdk_wifi_show_ip(void);
  172. #endif /* !NO_ESP_SDK_WIFI */
  173. /******************************************************************************
  174. * Debug helpers
  175. ******************************************************************************/
  176. WOLFSSL_LOCAL esp_err_t sdk_init_meminfo(void);
  177. WOLFSSL_LOCAL void* wc_debug_pvPortMalloc(size_t size,
  178. const char* file, int line, const char* fname);
  179. #ifdef __cplusplus
  180. } /* extern "C" */
  181. #endif
  182. /* Check for traps */
  183. #if defined(CONFIG_IDF_TARGET_ESP8266)
  184. #if !defined(NO_SESSION_CACHE) && \
  185. !defined(MICRO_SESSION_CACHE) && \
  186. !defined(SMALL_SESSION_CACHE)
  187. #warning "Limited DRAM/IRAM on ESP8266. Check session cache settings"
  188. #endif
  189. #endif
  190. #endif /* WOLFSSL_ESPIDF */
  191. #endif /* __ESP_SDK_LIB_H__ */