freertos-misc.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. /*
  26. * Normally you don't want this, use lws_sul instead inside the event loop.
  27. * But sometimes for drivers it makes sense, so there's an internal-only
  28. * crossplatform api for it.
  29. */
  30. void
  31. lws_msleep(unsigned int ms)
  32. {
  33. vTaskDelay(portTICK_PERIOD_MS > ms ? 1 : ms / portTICK_PERIOD_MS);
  34. }
  35. lws_usec_t
  36. lws_now_usecs(void)
  37. {
  38. struct timeval tv;
  39. gettimeofday(&tv, NULL);
  40. return ((unsigned long long)tv.tv_sec * 1000000LL) + tv.tv_usec;
  41. }
  42. size_t
  43. lws_get_random(struct lws_context *context, void *buf, size_t len)
  44. {
  45. #if defined(LWS_WITH_ESP32)
  46. uint8_t *pb = buf;
  47. while (len) {
  48. uint32_t r = esp_random();
  49. uint8_t *p = (uint8_t *)&r;
  50. int b = 4;
  51. if (len < (size_t)b)
  52. b = len;
  53. len -= b;
  54. while (b--)
  55. *pb++ = p[b];
  56. }
  57. return pb - (uint8_t *)buf;
  58. #else
  59. #if defined(LWS_WITH_MBEDTLS)
  60. int n;
  61. n = mbedtls_ctr_drbg_random(&context->mcdc, buf, len);
  62. if (!n)
  63. return len;
  64. /* failed */
  65. lwsl_err("%s: mbedtls_ctr_drbg_random returned 0x%x\n", __func__, n);
  66. #endif
  67. return 0;
  68. #endif
  69. }
  70. void lwsl_emit_syslog(int level, const char *line)
  71. {
  72. lwsl_emit_stderr(level, line);
  73. }
  74. int
  75. lws_plat_drop_app_privileges(struct lws_context *context, int actually_init)
  76. {
  77. return 0;
  78. }
  79. int
  80. lws_plat_recommended_rsa_bits(void)
  81. {
  82. /*
  83. * 2048-bit key generation takes up to a minute on ESP32, 4096
  84. * is like 15 minutes +
  85. */
  86. return 2048;
  87. }