freertos-init.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * libwebsockets - small server side websockets and web server implementation
  3. *
  4. * Copyright (C) 2010 - 2019 Andy Green <[email protected]>
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to
  8. * deal in the Software without restriction, including without limitation the
  9. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  10. * sell copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  21. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  22. * IN THE SOFTWARE.
  23. */
  24. #include "private-lib-core.h"
  25. int
  26. lws_plat_context_early_init(void)
  27. {
  28. return 0;
  29. }
  30. void
  31. lws_plat_context_early_destroy(struct lws_context *context)
  32. {
  33. #if defined(LWS_AMAZON_RTOS) && defined(LWS_WITH_MBEDTLS)
  34. mbedtls_ctr_drbg_free(&context->mcdc);
  35. mbedtls_entropy_free(&context->mec);
  36. #endif
  37. }
  38. void
  39. lws_plat_context_late_destroy(struct lws_context *context)
  40. {
  41. #ifdef LWS_WITH_PLUGINS
  42. if (context->plugin_list)
  43. lws_plat_plugins_destroy(context);
  44. #endif
  45. if (context->lws_lookup)
  46. lws_free(context->lws_lookup);
  47. }
  48. #if defined(LWS_WITH_HTTP2)
  49. /*
  50. * These are the default SETTINGS used on this platform. The user
  51. * can selectively modify them for a vhost during vhost creation.
  52. */
  53. const struct http2_settings lws_h2_defaults_esp32 = { {
  54. 1,
  55. /* H2SET_HEADER_TABLE_SIZE */ 512,
  56. /* H2SET_ENABLE_PUSH */ 0,
  57. /* H2SET_MAX_CONCURRENT_STREAMS */ 8,
  58. /* H2SET_INITIAL_WINDOW_SIZE */ 0,
  59. /* H2SET_MAX_FRAME_SIZE */ 16384,
  60. /* H2SET_MAX_HEADER_LIST_SIZE */ 512,
  61. /* H2SET_RESERVED7 */ 0,
  62. /* H2SET_ENABLE_CONNECT_PROTOCOL */ 1,
  63. }};
  64. #endif
  65. int
  66. lws_plat_init(struct lws_context *context,
  67. const struct lws_context_creation_info *info)
  68. {
  69. #if defined(LWS_AMAZON_RTOS) && defined(LWS_WITH_MBEDTLS)
  70. int n;
  71. /* initialize platform random through mbedtls */
  72. mbedtls_entropy_init(&context->mec);
  73. mbedtls_ctr_drbg_init(&context->mcdc);
  74. n = mbedtls_ctr_drbg_seed(&context->mcdc, mbedtls_entropy_func,
  75. &context->mec, NULL, 0);
  76. if (n) {
  77. lwsl_err("%s: mbedtls_ctr_drbg_seed() returned 0x%x\n",
  78. __func__, n);
  79. return 1;
  80. }
  81. #endif
  82. /* master context has the global fd lookup array */
  83. context->lws_lookup = lws_zalloc(sizeof(struct lws *) *
  84. context->max_fds, "esp32 lws_lookup");
  85. if (context->lws_lookup == NULL) {
  86. lwsl_err("OOM on lws_lookup array for %d connections\n",
  87. context->max_fds);
  88. return 1;
  89. }
  90. lwsl_notice(" mem: platform fd map: %5lu bytes\n",
  91. (unsigned long)(sizeof(struct lws *) * context->max_fds));
  92. #ifdef LWS_WITH_PLUGINS
  93. if (info->plugin_dirs)
  94. lws_plat_plugins_init(context, info->plugin_dirs);
  95. #endif
  96. #if defined(LWS_WITH_HTTP2)
  97. /* override settings */
  98. context->set = lws_h2_defaults_esp32;
  99. #endif
  100. #if defined(LWS_ESP_PLATFORM)
  101. gpio_install_isr_service(0);
  102. #endif
  103. return 0;
  104. }