wolfssl_demo.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /* wolfssl_demo.h
  2. *
  3. * Copyright (C) 2006-2023 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 WOLFSSL_DEMO_H_
  22. #define WOLFSSL_DEMO_H_
  23. #include <wolfssl/ssl.h>
  24. #include "FreeRTOS_IP.h"
  25. #include "FreeRTOS_Sockets.h"
  26. #define FREQ 10000 /* Hz */
  27. #define FLASH_HP_DF_BLOCK_0 0x08000000U /* 64 B: 0x40100000 - 0x4010003F */
  28. #define FLASH_HP_DF_BLOCK_1 0x08000040U /* 64 B: 0x40100040 - 0x4010007F */
  29. #define FLASH_HP_DF_BLOCK_2 0x08000080U /* 64 B: 0x40100080 - 0x401000BF */
  30. #define FLASH_HP_DF_BLOCK_3 0x080000C0U /* 64 B: 0x401000C0 - 0x401000FF */
  31. #define DIRECT_KEY_ADDRESS_256 FLASH_HP_DF_BLOCK_1
  32. #define DIRECT_KEY_ADDRESS_128 FLASH_HP_DF_BLOCK_2
  33. /* Client connects to the server with these details. */
  34. #define SERVER_IP "192.168.11.4"
  35. #define DEFAULT_PORT 11111
  36. /* Enable wolfcrypt test */
  37. /* can be enabled with benchmark test */
  38. /*#define CRYPT_TEST*/
  39. /* Enable benchmark */
  40. /* can be enabled with cyrpt test */
  41. /* #define BENCHMARK */
  42. /* Enable TLS client */
  43. /* cannot enable with CRYPT_TEST or BENCHMARK */
  44. #define TLS_CLIENT
  45. /* use multi-thread example */
  46. /*#define TLS_MULTITHREAD_TEST*/
  47. #if defined(TLS_MULTITHREAD_TEST)
  48. #define THREAD_STACK_SIZE (5 * 1024)
  49. #endif
  50. /* Use RSA certificates */
  51. #define USE_CERT_BUFFERS_2048
  52. /* Use ECC certificates */
  53. /*#define USE_CERT_BUFFERS_256*/
  54. #if defined(USE_CERT_BUFFERS_2048) && defined(USE_CERT_BUFFERS_256)
  55. #error please set either macro USE_CERT_BUFFERS_2048 or USE_CERT_BUFFERS_256
  56. #endif
  57. typedef struct tagTestInfo
  58. {
  59. int id;
  60. int port;
  61. char name[32];
  62. const char* cipher;
  63. WOLFSSL_CTX* ctx;
  64. wolfSSL_Logging_cb log_f;
  65. #if defined(TLS_MULTITHREAD_TEST)
  66. SemaphoreHandle_t xBinarySemaphore;
  67. #endif
  68. } TestInfo;
  69. void sce_test();
  70. void TCPInit();
  71. void wolfSSL_TLS_client_init();
  72. int wolfSSL_TLS_client_do(void *pvParam);
  73. void wolfSSL_TLS_cleanup();
  74. extern WOLFSSL_CTX *client_ctx;
  75. #ifdef TLS_MULTITHREAD_TEST
  76. extern xSemaphoreHandle exit_semaph;
  77. #endif
  78. static void util_Cleanup(xSocket_t xSock, WOLFSSL_CTX *ctx, WOLFSSL *ssl) {
  79. printf("Cleaning up socket and wolfSSL objects.\n");
  80. if (xSock != NULL)
  81. FreeRTOS_closesocket(xSock);
  82. if (ssl != NULL)
  83. wolfSSL_free(ssl);
  84. if (ctx != NULL)
  85. wolfSSL_CTX_free(ctx);
  86. wolfSSL_Cleanup();
  87. }
  88. static inline void util_inf_loop(xSocket_t xClientSocket, WOLFSSL_CTX *ctx,
  89. WOLFSSL *ssl) {
  90. util_Cleanup(xClientSocket, ctx, ssl);
  91. printf("Reached infinite loop.\n");
  92. while (1)
  93. ;
  94. }
  95. #endif /* WOLFSSL_DEMO_H_ */