1 /* main.c
2 *
3 * Copyright (C) 2006-2021 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
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include "wolfssl/wolfcrypt/settings.h"
27
28 #include "cmsis_os.h" /* CMSIS RTOS definitions */
29 #include "rl_net.h" /* Network definitions */
30 #include <time.h>
31
32 #if defined(STM32F7xx)
33 #include "stm32f7xx_hal.h"
34 #elif defined(STM32F4xx)
35 #include "stm32f4xx_hal.h"
36 #elif defined(STM32F2xx)
37 #include "stm32f2xx_hal.h"
38 #endif
39
40 //-------- <<< Use Configuration Wizard in Context Menu >>> -----------------
41
42 // <h>Server parameter
43 // ====================
44
45 // <s.6>Port
46 // <i> Default: "11111"
47 #define SERVER_PORT "11111"
48 // </h>
49
50 // <h>Protocol
51 // ====================
52
53 // <o>SSL/TLS Version<0=> SSL3 <1=> TLS1.0 <2=> TLS1.1 <3=> TLS1.2 <4=> TLS1.3
54 #define TLS_VER 3
55
56 // <s.2>Other option
57 #define OTHER_OPTIONS ""
58 // </h>
59
60 // <h>RTC: for validate certificate date
61 // <o>Year <1970-2099>
62 #define RTC_YEAR 2018
63 // <o>Month <1=>Jan<2=>Feb<3=>Mar<4=>Apr<5=>May<6=>Jun<7=>Jul<8=>Aut<9=>Sep<10=>Oct<11=>Nov<12=>Dec
64 #define RTC_MONTH 1
65 // <o>Day <1-31>
66 #define RTC_DAY 1
67 // </h>
68
69 //------------- <<< end of configuration section >>> -----------------------
70
71 #warning "write MPU specific Set ups\n"
SystemClock_Config(void)72 static void SystemClock_Config (void) {
73
74 }
75
MPU_Config(void)76 static void MPU_Config (void) {
77
78 }
79
CPU_CACHE_Enable(void)80 static void CPU_CACHE_Enable (void) {
81
82 }
83
84
85 /*-----------------------------------------------------------------------------
86 * Initialize a Flash Memory Card
87 *----------------------------------------------------------------------------*/
88 #if !defined(NO_FILESYSTEM)
89 #include "rl_fs.h" /* FileSystem definitions */
90
init_filesystem(void)91 static void init_filesystem (void) {
92 int32_t retv;
93
94 retv = finit ("M0:");
95 if (retv == fsOK) {
96 retv = fmount ("M0:");
97 if (retv == fsOK) {
98 printf ("Drive M0 ready!\n");
99 }
100 else {
101 printf ("Drive M0 mount failed(%d)!\n", retv);
102 }
103 }
104 else {
105 printf ("Drive M0 initialization failed!\n");
106 }
107 }
108 #endif
109
110
net_loop(void const * arg)111 void net_loop(void const *arg)
112 {
113 while(1) {
114 net_main ();
115 osThreadYield ();
116 }
117 }
118
119 osThreadDef(net_loop, osPriorityLow, 2, 0);
120
121 #ifdef RTE_CMSIS_RTOS_RTX
122 extern uint32_t os_time;
123 static time_t epochTime;
124
HAL_GetTick(void)125 uint32_t HAL_GetTick(void) {
126 return os_time;
127 }
128
time(time_t * t)129 time_t time(time_t *t){
130 return epochTime ;
131 }
132
setTime(time_t t)133 void setTime(time_t t){
134 epochTime = t;
135 }
136 #endif
137
138
139 #ifdef WOLFSSL_CURRTIME_OSTICK
140
141 #include <stdint.h>
142 extern uint32_t os_time;
143
current_time(int reset)144 double current_time(int reset)
145 {
146 if(reset) os_time = 0 ;
147 return (double)os_time /1000.0;
148 }
149
150 #else
151
152 #include <stdint.h>
153 #define DWT ((DWT_Type *) (0xE0001000UL) )
154 typedef struct
155 {
156 uint32_t CTRL; /*!< Offset: 0x000 (R/W) Control Register */
157 uint32_t CYCCNT; /*!< Offset: 0x004 (R/W) Cycle Count Register */
158 } DWT_Type;
159
160 extern uint32_t SystemCoreClock ;
161
current_time(int reset)162 double current_time(int reset)
163 {
164 if(reset) DWT->CYCCNT = 0 ;
165 return ((double)DWT->CYCCNT/SystemCoreClock) ;
166 }
167 #endif
168
169 /*----------------------------------------------------------------------------
170 Main Thread 'main': Run Network
171 *---------------------------------------------------------------------------*/
172 #include <stdio.h>
173 typedef struct func_args {
174 int argc;
175 char** argv;
176 } func_args;
177
178 extern void echoserver_test(func_args * args) ;
179
180 int myoptind = 0;
181 char* myoptarg = NULL;
182
main(void)183 int main (void) {
184 static char *argv[] =
185 { "server" } ;
186 static func_args args = { 1, argv } ;
187
188 MPU_Config(); /* Configure the MPU */
189 CPU_CACHE_Enable(); /* Enable the CPU Cache */
190 HAL_Init(); /* Initialize the HAL Library */
191 SystemClock_Config(); /* Configure the System Clock */
192
193 #if !defined(NO_FILESYSTEM)
194 init_filesystem ();
195 #endif
196 net_initialize ();
197
198 #if defined(DEBUG_WOLFSSL)
199 printf("Turning ON Debug message\n") ;
200 wolfSSL_Debugging_ON() ;
201 #endif
202
203 setTime((RTC_YEAR-1970)*365*24*60*60 + RTC_MONTH*30*24*60*60 + RTC_DAY*24*60*60);
204
205 osThreadCreate (osThread(net_loop), NULL);
206
207 echoserver_test(&args) ;
208 printf("echoserver: Terminated\n") ;
209 while(1)
210 osDelay(1000);
211
212 }
213
214