Files
wolfssl/IDE/MDK5-ARM/Projects/EchoServer/main.c
T

214 lines
4.9 KiB
C
Raw Normal View History

2013-11-07 10:29:01 +09:00
/* main.c
*
2026-02-18 09:52:21 -07:00
* Copyright (C) 2006-2026 wolfSSL Inc.
2013-11-07 10:29:01 +09:00
*
2016-03-17 16:02:13 -06:00
* This file is part of wolfSSL.
2013-11-07 10:29:01 +09:00
*
2015-01-06 12:14:15 -07:00
* wolfSSL is free software; you can redistribute it and/or modify
2013-11-07 10:29:01 +09:00
* it under the terms of the GNU General Public License as published by
2025-07-10 16:01:52 -06:00
* the Free Software Foundation; either version 3 of the License, or
2013-11-07 10:29:01 +09:00
* (at your option) any later version.
*
2015-01-06 12:14:15 -07:00
* wolfSSL is distributed in the hope that it will be useful,
2013-11-07 10:29:01 +09:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
2016-03-17 16:02:13 -06:00
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
2013-11-07 10:29:01 +09:00
*/
2013-11-07 10:29:01 +09:00
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
2017-12-31 11:31:54 +09:00
#include "wolfssl/wolfcrypt/settings.h"
2013-11-07 10:29:01 +09:00
2017-12-31 11:31:54 +09:00
#include "cmsis_os.h" /* CMSIS RTOS definitions */
#include "rl_net.h" /* Network definitions */
2017-12-31 11:31:54 +09:00
#include <time.h>
2018-01-01 12:18:08 +09:00
#if defined(STM32F7xx)
#include "stm32f7xx_hal.h"
#elif defined(STM32F4xx)
2018-01-02 06:41:47 +09:00
#include "stm32f4xx_hal.h"
2018-01-01 12:18:08 +09:00
#elif defined(STM32F2xx)
#include "stm32f2xx_hal.h"
#endif
2017-12-31 11:31:54 +09:00
//-------- <<< Use Configuration Wizard in Context Menu >>> -----------------
// <h>Server parameter
// ====================
// <s.6>Port
// <i> Default: "11111"
#define SERVER_PORT "11111"
// </h>
// <h>Protocol
// ====================
// <o>SSL/TLS Version<0=> SSL3 <1=> TLS1.0 <2=> TLS1.1 <3=> TLS1.2 <4=> TLS1.3
#define TLS_VER 3
// <s.2>Other option
#define OTHER_OPTIONS ""
// </h>
// <h>RTC: for validate certificate date
#define RTC_YEAR 2023
2017-12-31 11:31:54 +09:00
#define RTC_MONTH 1
#define RTC_DAY 1
2017-12-31 11:31:54 +09:00
// </h>
//------------- <<< end of configuration section >>> -----------------------
2018-01-01 12:18:08 +09:00
#warning "write MPU specific Set ups\n"
static void SystemClock_Config (void) {
}
static void MPU_Config (void) {
}
static void CPU_CACHE_Enable (void) {
}
2013-11-07 10:29:01 +09:00
/*-----------------------------------------------------------------------------
* Initialize a Flash Memory Card
*----------------------------------------------------------------------------*/
2017-12-31 11:31:54 +09:00
#if !defined(NO_FILESYSTEM)
#include "rl_fs.h" /* FileSystem definitions */
static void init_filesystem(void)
{
int32_t retv;
2013-11-07 10:29:01 +09:00
retv = finit ("M0:");
2017-12-31 11:31:54 +09:00
if (retv == fsOK) {
retv = fmount ("M0:");
if (retv == fsOK) {
printf ("Drive M0 ready!\n");
}
else {
printf ("Drive M0 mount failed(%d)!\n", retv);
}
2013-11-07 10:29:01 +09:00
}
else {
printf ("Drive M0 initialization failed!\n");
}
2013-11-07 10:29:01 +09:00
}
#endif
2013-11-07 10:29:01 +09:00
2017-12-31 11:31:54 +09:00
void net_loop(void const *arg)
{
while(1) {
net_main ();
osThreadYield ();
}
}
2013-11-07 10:29:01 +09:00
2017-12-31 11:31:54 +09:00
osThreadDef(net_loop, osPriorityLow, 2, 0);
#ifdef RTE_CMSIS_RTOS_RTX
2018-01-01 12:18:08 +09:00
extern uint32_t os_time;
static time_t epochTime;
2018-01-01 12:18:08 +09:00
uint32_t HAL_GetTick(void) {
return os_time;
2017-12-31 11:31:54 +09:00
}
time_t time(time_t *t) {
return epochTime;
2017-12-31 11:31:54 +09:00
}
void setTime(time_t t) {
2018-01-01 12:18:08 +09:00
epochTime = t;
2017-12-31 11:31:54 +09:00
}
#endif /* RTE_CMSIS_RTOS_RTX */
2018-01-01 12:18:08 +09:00
2017-12-31 11:31:54 +09:00
#ifdef WOLFSSL_CURRTIME_OSTICK
#include <stdint.h>
extern uint32_t os_time;
double current_time(int reset)
{
if (reset) os_time = 0;
return (double)os_time /1000.0;
2017-12-31 11:31:54 +09:00
}
#else
#include <stdint.h>
#define DWT ((DWT_Type *) (0xE0001000UL) )
typedef struct {
uint32_t CTRL; /*!< Offset: 0x000 (R/W) Control Register */
uint32_t CYCCNT; /*!< Offset: 0x004 (R/W) Cycle Count Register */
2017-12-31 11:31:54 +09:00
} DWT_Type;
extern uint32_t SystemCoreClock;
2017-12-31 11:31:54 +09:00
double current_time(int reset)
{
if (reset) DWT->CYCCNT = 0;
return ((double)DWT->CYCCNT/SystemCoreClock);
2017-12-31 11:31:54 +09:00
}
#endif /* WOLFSSL_CURRTIME_OSTICK */
2017-12-31 11:31:54 +09:00
/*----------------------------------------------------------------------------
Main Thread 'main': Run Network
*---------------------------------------------------------------------------*/
#include <stdio.h>
2013-11-07 10:29:01 +09:00
typedef struct func_args {
int argc;
char** argv;
} func_args;
extern void echoserver_test(func_args * args);
2013-11-07 10:29:01 +09:00
2017-12-31 11:31:54 +09:00
int myoptind = 0;
char* myoptarg = NULL;
2013-11-07 10:29:01 +09:00
int main (void)
{
2018-01-01 12:18:08 +09:00
static char *argv[] =
{ "server" };
static func_args args = { 1, argv };
2017-12-31 11:31:54 +09:00
MPU_Config(); /* Configure the MPU */
CPU_CACHE_Enable(); /* Enable the CPU Cache */
HAL_Init(); /* Initialize the HAL Library */
SystemClock_Config(); /* Configure the System Clock */
2017-12-31 11:31:54 +09:00
#if !defined(NO_FILESYSTEM)
init_filesystem ();
#endif
2017-12-31 11:31:54 +09:00
net_initialize ();
#if defined(DEBUG_WOLFSSL)
printf("Turning ON Debug message\n");
wolfSSL_Debugging_ON();
#endif
2017-12-31 11:31:54 +09:00
setTime((RTC_YEAR-1970)*365*24*60*60 +
RTC_MONTH*30*24*60*60 +
RTC_DAY*24*60*60);
2018-01-01 12:18:08 +09:00
2017-12-31 11:31:54 +09:00
osThreadCreate (osThread(net_loop), NULL);
echoserver_test(&args);
printf("echoserver: Terminated\n");
while (1) {
2017-12-31 11:31:54 +09:00
osDelay(1000);
}
2013-11-07 10:29:01 +09:00
}