서해원

Add src/

Showing 77 changed files with 4929 additions and 0 deletions
1 +/src/Numaker-PFM-M2351/PulseMonitoring/Secure/Objects
2 +/src/Numaker-PFM-M2351/PulseMonitoring/Secure/Listings
3 +
4 +/src/Numaker-PFM-M2351/PulseMonitoring/NonSecure/Objects
5 +/src/Numaker-PFM-M2351/PulseMonitoring/NonSecure/Listings
1 +# ARM-TrustZone-based-Pulse-Monitoring
2 +2021-1 Capston Project
3 +
4 +# Instruction
5 +
6 +## src/Numaker-PFM-M2351
7 ++ Need a Keil uVision5
8 ++ Place a `src/Numaker-PFM-M2351` directory in a `M2351Series_BSP_CMSIS_V3.00.004` directory so that you can use the library.
9 +
10 +## src/Server
11 ++ Need a docker engine
12 +
13 ++ In src/Server/
14 + + docker build
15 + ```
16 + docker build -t server
17 + ```
18 +
19 + + docker run
20 + ```
21 + docker run --name=server -it -p80:80 -p443:443 -p2351:2351 server
22 + ```
23 +
24 +
25 +# Contact
26 ++ `shw2662@khu.ac.kr`
......
1 +<?xml version="1.0" encoding="utf-8"?>
2 +
3 +<component_viewer schemaVersion="0.1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="Component_Viewer.xsd">
4 +
5 +<component name="EventRecorderStub" version="1.0.0"/> <!--name and version of the component-->
6 + <events>
7 + </events>
8 +
9 +</component_viewer>
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff is collapsed. Click to expand it.
1 +/*
2 + * Copyright (c) 2013-2018 Arm Limited. All rights reserved.
3 + *
4 + * SPDX-License-Identifier: Apache-2.0
5 + *
6 + * Licensed under the Apache License, Version 2.0 (the License); you may
7 + * not use this file except in compliance with the License.
8 + * You may obtain a copy of the License at
9 + *
10 + * www.apache.org/licenses/LICENSE-2.0
11 + *
12 + * Unless required by applicable law or agreed to in writing, software
13 + * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14 + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 + * See the License for the specific language governing permissions and
16 + * limitations under the License.
17 + *
18 + * -----------------------------------------------------------------------------
19 + *
20 + * $Revision: V5.1.0
21 + *
22 + * Project: CMSIS-RTOS RTX
23 + * Title: RTX Configuration
24 + *
25 + * -----------------------------------------------------------------------------
26 + */
27 +
28 +#include "cmsis_compiler.h"
29 +#include "rtx_os.h"
30 +
31 +// OS Idle Thread
32 +__WEAK __NO_RETURN void osRtxIdleThread (void *argument) {
33 + (void)argument;
34 +
35 + for (;;) {}
36 +}
37 +
38 +// OS Error Callback function
39 +__WEAK uint32_t osRtxErrorNotify (uint32_t code, void *object_id) {
40 + (void)object_id;
41 +
42 + switch (code) {
43 + case osRtxErrorStackUnderflow:
44 + // Stack overflow detected for thread (thread_id=object_id)
45 + break;
46 + case osRtxErrorISRQueueOverflow:
47 + // ISR Queue overflow detected when inserting object (object_id)
48 + break;
49 + case osRtxErrorTimerQueueOverflow:
50 + // User Timer Callback Queue overflow detected for timer (timer_id=object_id)
51 + break;
52 + case osRtxErrorClibSpace:
53 + // Standard C/C++ library libspace not available: increase OS_THREAD_LIBSPACE_NUM
54 + break;
55 + case osRtxErrorClibMutex:
56 + // Standard C/C++ library mutex initialization failed
57 + break;
58 + default:
59 + // Reserved
60 + break;
61 + }
62 + for (;;) {}
63 +//return 0U;
64 +}
1 +/*------------------------------------------------------------------------------
2 + * MDK Middleware - Component ::Network
3 + * Copyright (c) 2004-2019 Arm Limited (or its affiliates). All rights reserved.
4 + *------------------------------------------------------------------------------
5 + * Name: Net_Config.c
6 + * Purpose: Network Configuration
7 + * Rev.: V7.1.0
8 + *----------------------------------------------------------------------------*/
9 +
10 +//-------- <<< Use Configuration Wizard in Context Menu >>> --------------------
11 +
12 +// <h>Network System Settings
13 +// <i>Global Network System definitions
14 +// <s.15>Local Host Name
15 +// <i>This is the name under which embedded host can be
16 +// <i>accessed on a local area network.
17 +// <i>Default: "my_host"
18 +#define NET_HOST_NAME "my_host"
19 +
20 +// <o>Memory Pool Size <1536-262144:4>
21 +// <i>This is the size of a memory pool in bytes. Buffers for
22 +// <i>network packets are allocated from this memory pool.
23 +// <i>Default: 12000 bytes
24 +#define NET_MEM_POOL_SIZE 12000
25 +
26 +// <q>Start System Services
27 +// <i>If enabled, the system will automatically start server services
28 +// <i>(HTTP, FTP, TFTP server, ...) when initializing the network system.
29 +// <i>Default: Enabled
30 +#define NET_START_SERVICE 1
31 +
32 +// <h>OS Resource Settings
33 +// <i>These settings are used to optimize usage of OS resources.
34 +// <o>Core Thread Stack Size <512-65535:4>
35 +// <i>Default: 1024 bytes
36 +#define NET_THREAD_STACK_SIZE 1024
37 +
38 +// Core Thread Priority
39 +#define NET_THREAD_PRIORITY osPriorityNormal
40 +
41 +// </h>
42 +// </h>
43 +
44 +//------------- <<< end of configuration section >>> ---------------------------
45 +
46 +#include "RTE_Components.h"
47 +
48 +#ifdef RTE_Network_Interface_ETH_0
49 +#include "Net_Config_ETH_0.h"
50 +#endif
51 +#ifdef RTE_Network_Interface_ETH_1
52 +#include "Net_Config_ETH_1.h"
53 +#endif
54 +
55 +#ifdef RTE_Network_Interface_WiFi_0
56 +#include "Net_Config_WiFi_0.h"
57 +#endif
58 +
59 +#ifdef RTE_Network_Interface_WiFi_1
60 +#include "Net_Config_WiFi_1.h"
61 +#endif
62 +
63 +#ifdef RTE_Network_Interface_PPP
64 +#include "Net_Config_PPP.h"
65 +#endif
66 +
67 +#ifdef RTE_Network_Interface_SLIP
68 +#include "Net_Config_SLIP.h"
69 +#endif
70 +
71 +#ifdef RTE_Network_Socket_UDP
72 +#include "Net_Config_UDP.h"
73 +#endif
74 +#ifdef RTE_Network_Socket_TCP
75 +#include "Net_Config_TCP.h"
76 +#endif
77 +#ifdef RTE_Network_Socket_BSD
78 +#include "Net_Config_BSD.h"
79 +#endif
80 +
81 +#ifdef RTE_Network_Web_Server_RO
82 +#include "Net_Config_HTTP_Server.h"
83 +#endif
84 +#ifdef RTE_Network_Web_Server_FS
85 +#include "Net_Config_HTTP_Server.h"
86 +#endif
87 +
88 +#ifdef RTE_Network_Telnet_Server
89 +#include "Net_Config_Telnet_Server.h"
90 +#endif
91 +
92 +#ifdef RTE_Network_TFTP_Server
93 +#include "Net_Config_TFTP_Server.h"
94 +#endif
95 +#ifdef RTE_Network_TFTP_Client
96 +#include "Net_Config_TFTP_Client.h"
97 +#endif
98 +
99 +#ifdef RTE_Network_FTP_Server
100 +#include "Net_Config_FTP_Server.h"
101 +#endif
102 +#ifdef RTE_Network_FTP_Client
103 +#include "Net_Config_FTP_Client.h"
104 +#endif
105 +
106 +#ifdef RTE_Network_DNS_Client
107 +#include "Net_Config_DNS_Client.h"
108 +#endif
109 +
110 +#ifdef RTE_Network_SMTP_Client
111 +#include "Net_Config_SMTP_Client.h"
112 +#endif
113 +
114 +#ifdef RTE_Network_SNMP_Agent
115 +#include "Net_Config_SNMP_Agent.h"
116 +#endif
117 +
118 +#ifdef RTE_Network_SNTP_Client
119 +#include "Net_Config_SNTP_Client.h"
120 +#endif
121 +
122 +#include "net_config.h"
123 +
124 +/**
125 +\addtogroup net_genFunc
126 +@{
127 +*/
128 +/**
129 + \fn void net_sys_error (NET_ERROR error)
130 + \ingroup net_cores
131 + \brief Network system error handler.
132 +*/
133 +void net_sys_error (NET_ERROR error) {
134 + /* This function is called when a fatal error is encountered. */
135 + /* The normal program execution is not possible anymore. */
136 +
137 + switch (error) {
138 + case NET_ERROR_MEM_ALLOC:
139 + /* Out of memory */
140 + break;
141 +
142 + case NET_ERROR_MEM_FREE:
143 + /* Trying to release non existing memory block */
144 + break;
145 +
146 + case NET_ERROR_MEM_CORRUPT:
147 + /* Memory Link pointer corrupted */
148 + /* More data written than the size of allocated memory block */
149 + break;
150 +
151 + case NET_ERROR_CONFIG:
152 + /* Network configuration error detected */
153 + break;
154 +
155 + case NET_ERROR_UDP_ALLOC:
156 + /* Out of UDP Sockets */
157 + break;
158 +
159 + case NET_ERROR_TCP_ALLOC:
160 + /* Out of TCP Sockets */
161 + break;
162 +
163 + case NET_ERROR_TCP_STATE:
164 + /* TCP State machine in undefined state */
165 + break;
166 + }
167 +
168 + /* End-less loop */
169 + while (1);
170 +}
171 +/**
172 +@}
173 +*/
1 +/*------------------------------------------------------------------------------
2 + * MDK Middleware - Component ::Network:Socket
3 + * Copyright (c) 2004-2019 Arm Limited (or its affiliates). All rights reserved.
4 + *------------------------------------------------------------------------------
5 + * Name: Net_Config_TCP.h
6 + * Purpose: Network Configuration for TCP Sockets
7 + * Rev.: V7.1.1
8 + *----------------------------------------------------------------------------*/
9 +
10 +//-------- <<< Use Configuration Wizard in Context Menu >>> --------------------
11 +
12 +// <h>TCP Sockets
13 +#define TCP_ENABLE 1
14 +
15 +// <o>Number of TCP Sockets <1-20>
16 +// <i>Number of available TCP sockets
17 +// <i>Default: 6
18 +#define TCP_NUM_SOCKS 6
19 +
20 +// <o>Number of Retries <0-20>
21 +// <i>How many times TCP module will try to retransmit data
22 +// <i>before giving up. Increase this value for high-latency
23 +// <i>and low throughput networks.
24 +// <i>Default: 5
25 +#define TCP_MAX_RETRY 5
26 +
27 +// <o>Retry Timeout in seconds <1-10>
28 +// <i>If data frame not acknowledged within this time frame,
29 +// <i>TCP module will try to resend the data again.
30 +// <i>Default: 4
31 +#define TCP_RETRY_TOUT 4
32 +
33 +// <o>Default Connect Timeout in seconds <1-65535>
34 +// <i>If no TCP data frame has been exchanged during this time,
35 +// <i>the TCP connection is either closed or a keep-alive frame
36 +// <i>is sent to verify that the connection still exists.
37 +// <i>Default: 120
38 +#define TCP_DEFAULT_TOUT 120
39 +
40 +// <o>Maximum Segment Size <536-1440>
41 +// <i>The Maximum Segment Size specifies the maximum
42 +// <i>number of bytes in the TCP segment's Data field.
43 +// <i>Default: 1440
44 +#define TCP_MAX_SEG_SIZE 1440
45 +
46 +// <o>Receive Window Size <536-65535>
47 +// <i>Receive Window Size specifies the size of data,
48 +// <i>that the socket is able to buffer in flow-control mode.
49 +// <i>Default: 4320
50 +#define TCP_RECEIVE_WIN_SIZE 4320
51 +
52 +// </h>
53 +
54 +// TCP Initial Retransmit period in seconds
55 +#define TCP_INITIAL_RETRY_TOUT 1
56 +
57 +// TCP SYN frame retransmit period in seconds
58 +#define TCP_SYN_RETRY_TOUT 2
59 +
60 +// Number of retries to establish a connection
61 +#define TCP_CONNECT_RETRY 7
62 +
63 +// Dynamic port start (default 49152)
64 +#define TCP_DYN_PORT_START 49152
65 +
66 +// Dynamic port end (default 65535)
67 +#define TCP_DYN_PORT_END 65535
68 +
69 +//------------- <<< end of configuration section >>> ---------------------------
1 +/*
2 + * Configuration template
3 + *
4 + * Copyright (C) 2006-2021, Arm Limited, All Rights Reserved
5 + * SPDX-License-Identifier: Apache-2.0
6 + *
7 + * Licensed under the Apache License, Version 2.0 (the "License"); you may
8 + * not use this file except in compliance with the License.
9 + * You may obtain a copy of the License at
10 + *
11 + * http://www.apache.org/licenses/LICENSE-2.0
12 + *
13 + * Unless required by applicable law or agreed to in writing, software
14 + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 + * See the License for the specific language governing permissions and
17 + * limitations under the License.
18 + */
19 +/*
20 + * This set of compile-time options may be used to enable
21 + * or disable features selectively, and reduce the global
22 + * memory footprint.
23 + */
24 +
25 +#ifndef MBEDTLS_CONFIG_H
26 +#define MBEDTLS_CONFIG_H
27 +
28 +/* System support */
29 +//#define MBEDTLS_HAVE_ASM
30 +//#define MBEDTLS_HAVE_TIME
31 +//#define MBEDTLS_HAVE_TIME_DATE
32 +//#define MBEDTLS_PLATFORM_MEMORY
33 +//#define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
34 +//#define MBEDTLS_CHECK_PARAMS
35 +
36 +/* mbed TLS feature support */
37 +//#define MBEDTLS_AES_ROM_TABLES
38 +//#define MBEDTLS_AES_FEWER_TABLES
39 +//#define MBEDTLS_CAMELLIA_SMALL_MEMORY
40 +//#define MBEDTLS_CIPHER_MODE_CBC
41 +//#define MBEDTLS_CIPHER_MODE_CFB
42 +//#define MBEDTLS_CIPHER_MODE_CTR
43 +//#define MBEDTLS_CIPHER_MODE_OFB
44 +//#define MBEDTLS_CIPHER_MODE_XTS
45 +//#define MBEDTLS_CIPHER_PADDING_PKCS7
46 +//#define MBEDTLS_CIPHER_PADDING_ONE_AND_ZEROS
47 +//#define MBEDTLS_CIPHER_PADDING_ZEROS_AND_LEN
48 +//#define MBEDTLS_CIPHER_PADDING_ZEROS
49 +//#define MBEDTLS_REMOVE_ARC4_CIPHERSUITES
50 +//#define MBEDTLS_REMOVE_3DES_CIPHERSUITES
51 +//#define MBEDTLS_ECP_DP_SECP192R1_ENABLED
52 +//#define MBEDTLS_ECP_DP_SECP224R1_ENABLED
53 +//#define MBEDTLS_ECP_DP_SECP256R1_ENABLED
54 +//#define MBEDTLS_ECP_DP_SECP384R1_ENABLED
55 +//#define MBEDTLS_ECP_DP_SECP521R1_ENABLED
56 +//#define MBEDTLS_ECP_DP_SECP192K1_ENABLED
57 +//#define MBEDTLS_ECP_DP_SECP224K1_ENABLED
58 +//#define MBEDTLS_ECP_DP_SECP256K1_ENABLED
59 +//#define MBEDTLS_ECP_DP_BP256R1_ENABLED
60 +//#define MBEDTLS_ECP_DP_BP384R1_ENABLED
61 +//#define MBEDTLS_ECP_DP_BP512R1_ENABLED
62 +//#define MBEDTLS_ECP_DP_CURVE25519_ENABLED
63 +//#define MBEDTLS_ECP_DP_CURVE448_ENABLED
64 +//#define MBEDTLS_ECP_NIST_OPTIM
65 +//#define MBEDTLS_ECP_RESTARTABLE
66 +//#define MBEDTLS_ECDSA_DETERMINISTIC
67 +//#define MBEDTLS_KEY_EXCHANGE_PSK_ENABLED
68 +//#define MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
69 +//#define MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
70 +//#define MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
71 +//#define MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
72 +//#define MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
73 +//#define MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
74 +//#define MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
75 +//#define MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
76 +//#define MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
77 +//#define MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
78 +//#define MBEDTLS_PK_PARSE_EC_EXTENDED
79 +//#define MBEDTLS_ERROR_STRERROR_DUMMY
80 +//#define MBEDTLS_GENPRIME
81 +//#define MBEDTLS_FS_IO
82 +//#define MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
83 +//#define MBEDTLS_NO_PLATFORM_ENTROPY
84 +//#define MBEDTLS_ENTROPY_FORCE_SHA256
85 +//#define MBEDTLS_ENTROPY_NV_SEED
86 +//#define MBEDTLS_MEMORY_DEBUG
87 +//#define MBEDTLS_MEMORY_BACKTRACE
88 +//#define MBEDTLS_PK_RSA_ALT_SUPPORT
89 +//#define MBEDTLS_PKCS1_V15
90 +//#define MBEDTLS_PKCS1_V21
91 +//#define MBEDTLS_PSA_CRYPTO_SPM
92 +//#define MBEDTLS_RSA_NO_CRT
93 +//#define MBEDTLS_SELF_TEST
94 +//#define MBEDTLS_SHA256_SMALLER
95 +//#define MBEDTLS_SHA512_SMALLER
96 +//#define MBEDTLS_SHA512_NO_SHA384
97 +//#define MBEDTLS_SSL_ALL_ALERT_MESSAGES
98 +//#define MBEDTLS_SSL_RECORD_CHECKING
99 +//#define MBEDTLS_SSL_DTLS_CONNECTION_ID
100 +//#define MBEDTLS_SSL_ASYNC_PRIVATE
101 +//#define MBEDTLS_SSL_CONTEXT_SERIALIZATION
102 +//#define MBEDTLS_SSL_DEBUG_ALL
103 +//#define MBEDTLS_SSL_ENCRYPT_THEN_MAC
104 +//#define MBEDTLS_SSL_EXTENDED_MASTER_SECRET
105 +//#define MBEDTLS_SSL_FALLBACK_SCSV
106 +//#define MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
107 +//#define MBEDTLS_SSL_HW_RECORD_ACCEL
108 +//#define MBEDTLS_SSL_CBC_RECORD_SPLITTING
109 +//#define MBEDTLS_SSL_RENEGOTIATION
110 +//#define MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO
111 +//#define MBEDTLS_SSL_SRV_RESPECT_CLIENT_PREFERENCE
112 +//#define MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
113 +//#define MBEDTLS_SSL_PROTO_SSL3
114 +//#define MBEDTLS_SSL_PROTO_TLS1
115 +//#define MBEDTLS_SSL_PROTO_TLS1_1
116 +//#define MBEDTLS_SSL_PROTO_TLS1_2
117 +//#define MBEDTLS_SSL_PROTO_DTLS
118 +//#define MBEDTLS_SSL_ALPN
119 +//#define MBEDTLS_SSL_DTLS_ANTI_REPLAY
120 +//#define MBEDTLS_SSL_DTLS_HELLO_VERIFY
121 +//#define MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE
122 +//#define MBEDTLS_SSL_DTLS_BADMAC_LIMIT
123 +//#define MBEDTLS_SSL_SESSION_TICKETS
124 +//#define MBEDTLS_SSL_EXPORT_KEYS
125 +//#define MBEDTLS_SSL_SERVER_NAME_INDICATION
126 +//#define MBEDTLS_SSL_TRUNCATED_HMAC
127 +//#define MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
128 +//#define MBEDTLS_USE_PSA_CRYPTO
129 +//#define MBEDTLS_VERSION_FEATURES
130 +//#define MBEDTLS_X509_ALLOW_EXTENSIONS_NON_V3
131 +//#define MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION
132 +//#define MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
133 +//#define MBEDTLS_X509_CHECK_KEY_USAGE
134 +//#define MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE
135 +//#define MBEDTLS_X509_RSASSA_PSS_SUPPORT
136 +//#define MBEDTLS_ZLIB_SUPPORT
137 +
138 +/* mbed TLS modules */
139 +//#define MBEDTLS_AES_C
140 +//#define MBEDTLS_ARC4_C
141 +//#define MBEDTLS_ASN1_PARSE_C
142 +//#define MBEDTLS_ASN1_WRITE_C
143 +//#define MBEDTLS_BASE64_C
144 +//#define MBEDTLS_BIGNUM_C
145 +//#define MBEDTLS_BLOWFISH_C
146 +//#define MBEDTLS_CAMELLIA_C
147 +//#define MBEDTLS_ARIA_C
148 +//#define MBEDTLS_CCM_C
149 +//#define MBEDTLS_CERTS_C
150 +//#define MBEDTLS_CHACHA20_C
151 +//#define MBEDTLS_CHACHAPOLY_C
152 +//#define MBEDTLS_CIPHER_C
153 +//#define MBEDTLS_CMAC_C
154 +//#define MBEDTLS_CTR_DRBG_C
155 +//#define MBEDTLS_DEBUG_C
156 +//#define MBEDTLS_DES_C
157 +//#define MBEDTLS_DHM_C
158 +//#define MBEDTLS_ECDH_C
159 +//#define MBEDTLS_ECDSA_C
160 +//#define MBEDTLS_ECJPAKE_C
161 +//#define MBEDTLS_ECP_C
162 +//#define MBEDTLS_ENTROPY_C
163 +//#define MBEDTLS_ERROR_C
164 +//#define MBEDTLS_GCM_C
165 +//#define MBEDTLS_HAVEGE_C
166 +//#define MBEDTLS_HKDF_C
167 +//#define MBEDTLS_HMAC_DRBG_C
168 +//#define MBEDTLS_NIST_KW_C
169 +//#define MBEDTLS_MD_C
170 +//#define MBEDTLS_MD2_C
171 +//#define MBEDTLS_MD4_C
172 +//#define MBEDTLS_MD5_C
173 +//#define MBEDTLS_MEMORY_BUFFER_ALLOC_C
174 +//#define MBEDTLS_NET_C
175 +//#define MBEDTLS_OID_C
176 +//#define MBEDTLS_PEM_PARSE_C
177 +//#define MBEDTLS_PEM_WRITE_C
178 +//#define MBEDTLS_PK_C
179 +//#define MBEDTLS_PK_PARSE_C
180 +//#define MBEDTLS_PK_WRITE_C
181 +//#define MBEDTLS_PKCS5_C
182 +//#define MBEDTLS_PKCS11_C
183 +//#define MBEDTLS_PKCS12_C
184 +//#define MBEDTLS_PLATFORM_C
185 +//#define MBEDTLS_POLY1305_C
186 +//#define MBEDTLS_PSA_CRYPTO_C
187 +//#define MBEDTLS_PSA_CRYPTO_SE_C
188 +//#define MBEDTLS_PSA_CRYPTO_STORAGE_C
189 +//#define MBEDTLS_PSA_ITS_FILE_C
190 +//#define MBEDTLS_RIPEMD160_C
191 +//#define MBEDTLS_RSA_C
192 +//#define MBEDTLS_SHA1_C
193 +//#define MBEDTLS_SHA256_C
194 +//#define MBEDTLS_SHA512_C
195 +//#define MBEDTLS_SSL_CACHE_C
196 +//#define MBEDTLS_SSL_COOKIE_C
197 +//#define MBEDTLS_SSL_TICKET_C
198 +//#define MBEDTLS_SSL_CLI_C
199 +//#define MBEDTLS_SSL_SRV_C
200 +//#define MBEDTLS_SSL_TLS_C
201 +//#define MBEDTLS_THREADING_C
202 +//#define MBEDTLS_TIMING_C
203 +//#define MBEDTLS_VERSION_C
204 +//#define MBEDTLS_X509_USE_C
205 +//#define MBEDTLS_X509_CRT_PARSE_C
206 +//#define MBEDTLS_X509_CRL_PARSE_C
207 +//#define MBEDTLS_X509_CSR_PARSE_C
208 +//#define MBEDTLS_X509_CREATE_C
209 +//#define MBEDTLS_X509_CRT_WRITE_C
210 +//#define MBEDTLS_X509_CSR_WRITE_C
211 +//#define MBEDTLS_XTEA_C
212 +
213 +#include "mbedtls/check_config.h"
214 +
215 +#endif /* MBEDTLS_CONFIG_H */
1 +
2 +/*
3 + * Auto generated Run-Time-Environment Configuration File
4 + * *** Do not modify ! ***
5 + *
6 + * Project: 'NonSecure'
7 + * Target: 'NonSecure'
8 + */
9 +
10 +#ifndef RTE_COMPONENTS_H
11 +#define RTE_COMPONENTS_H
12 +
13 +
14 +/*
15 + * Define the Device Header File:
16 + */
17 +#define CMSIS_device_header "M2351.h"
18 +
19 +/* ARM::PSA:Crypto:mbed TLS:2.24.0 */
20 +#define RTE_PSA_API_CRYPTO
21 +
22 +
23 +#endif /* RTE_COMPONENTS_H */
1 +/******************************************************************************
2 +**************************Hardware interface layer*****************************
3 +* | file : DEV_Config.c
4 +* | version : V1.0
5 +* | date : 2017-08-14
6 +* | function :
7 + Provide the hardware underlying interface
8 +******************************************************************************/
9 +#include "DEV_Config.h"
10 +
11 +//#include "stm32f1xx_hal_i2c.h"
12 +//#include "i2c.h"
13 +
14 +//#include "stm32f1xx_hal_spi.h"
15 +//#include "spi.h"
16 +
17 +//#include "usart.h"
18 +#include <stdio.h> //printf()
19 +#include <string.h>
20 +#include <stdlib.h>
21 +
22 +/********************************************************************************
23 +function: System Init
24 +note:
25 + Initialize the communication method
26 +********************************************************************************/
27 +uint8_t System_Init(void)
28 +{
29 +#if USE_SPI_4W
30 + //printf("USE 4wire spi\r\n");
31 +#elif USE_IIC
32 + printf("USE i2c\r\n");
33 + //DC = 1 => addrdess = 0X3D
34 + //DC = 0 => addrdess = 0X3C
35 + OLED_DC_1;
36 +#endif
37 + return 0;
38 +}
39 +
40 +void System_Exit(void)
41 +{
42 +
43 +}
44 +/********************************************************************************
45 +function: Hardware interface
46 +note:
47 + SPI4W_Write_Byte(value) :
48 + HAL library hardware SPI
49 + Register hardware SPI
50 + Gpio analog SPI
51 + I2C_Write_Byte(value, cmd):
52 + HAL library hardware I2C
53 +********************************************************************************/
54 +void SPI4W_Write_Byte(uint8_t value)
55 +{
56 + SPI_WRITE_TX(SPI1_NS, value);
57 + while (SPI_IS_BUSY(SPI1_NS));
58 + //printf("[RX] : %d\t [TX] : %d(%#x) \n", SPI_READ_RX(SPI0), value, value);
59 +}
60 +/********************************************************************************
61 +function: Delay function
62 +note:
63 + Driver_Delay_ms(xms) : Delay x ms
64 + Driver_Delay_us(xus) : Delay x us
65 +********************************************************************************/
66 +void Driver_Delay_ms(uint32_t xms)
67 +{
68 + CLK_SysTickDelay(xms * 1000);
69 +}
70 +
71 +void Driver_Delay_us(uint32_t xus)
72 +{
73 + int j;
74 + for(j=xus; j > 0; j--);
75 +}
1 +/******************************************************************************
2 +**************************Hardware interface layer*****************************
3 +* | file : DEV_Config.h
4 +* | version : V1.0
5 +* | date : 2017-08-14
6 +* | function :
7 + Provide the hardware underlying interface
8 +******************************************************************************/
9 +#ifndef _DEV_CONFIG_H_
10 +#define _DEV_CONFIG_H_
11 +
12 +//#include "stm32f1xx_hal.h"
13 +//#include "stm32f1xx_hal_gpio.h"
14 +//#include "main.h"
15 +#include <stdint.h>
16 +#include "NuMicro.h"
17 +
18 +#define USE_SPI_4W 1
19 +#define USE_IIC 0
20 +
21 +#define IIC_CMD 0X00
22 +#define IIC_RAM 0X40
23 +
24 +//#define SPI0_SCK PD2_NS
25 +//#define SPI0_SCK_GPIO_Port GPIOD
26 +
27 +//#define SPI0_MISO PD1_NS
28 +//#define SPI0_MISO_GPIO_Port GPIOD
29 +
30 +//#define SPI0_MOSI PD0_NS
31 +//#define SPI0_MOSI_GPIO_Port GPIOD
32 +
33 +#define OLED_DC PC11_NS
34 +#define OLED_DC_GPIO_Port GPIOC
35 +
36 +#define OLED_RST PC12_NS
37 +#define OLED_RST_GPIO_Port GPIOC
38 +
39 +#define OLED_CS PH9_NS
40 +#define OLED_CS_GPIO_Port GPIOH
41 +/*
42 +#define I2C1_SCL_Pin GPIO_PIN_8
43 +#define I2C1_SCL_GPIO_Port GPIOB
44 +#define I2C1_SDA_Pin GPIO_PIN_9
45 +#define I2C1_SDA_GPIO_Port GPIOB
46 +
47 +
48 +//OLED GPIO
49 +#define OLED_CS_0 HAL_GPIO_WritePin(OLED_CS_GPIO_Port, OLED_CS_Pin, GPIO_PIN_RESET)
50 +#define OLED_CS_1 HAL_GPIO_WritePin(OLED_CS_GPIO_Port, OLED_CS_Pin, GPIO_PIN_SET)
51 +
52 +#define OLED_DC_0 HAL_GPIO_WritePin(OLED_DC_GPIO_Port, OLED_DC_Pin, GPIO_PIN_RESET)
53 +#define OLED_DC_1 HAL_GPIO_WritePin(OLED_DC_GPIO_Port, OLED_DC_Pin, GPIO_PIN_SET)
54 +
55 +#define OLED_RST_0 HAL_GPIO_WritePin(OLED_RST_GPIO_Port, OLED_RST_Pin, GPIO_PIN_RESET)
56 +#define OLED_RST_1 HAL_GPIO_WritePin(OLED_RST_GPIO_Port, OLED_RST_Pin, GPIO_PIN_SET)
57 +
58 +//SPI GPIO
59 +#define SPI1_SCK_0 HAL_GPIO_WritePin(SPI1_SCK_GPIO_Port, SPI1_SCK_Pin, GPIO_PIN_RESET)
60 +#define SPI1_SCK_1 HAL_GPIO_WritePin(SPI1_SCK_GPIO_Port, SPI1_SCK_Pin, GPIO_PIN_SET)
61 +
62 +#define SPI1_MOSI_0 HAL_GPIO_WritePin(SPI1_MOSI_GPIO_Port, SPI1_MOSI_Pin, GPIO_PIN_RESET)
63 +#define SPI1_MOSI_1 HAL_GPIO_WritePin(SPI1_MOSI_GPIO_Port, SPI1_MOSI_Pin, GPIO_PIN_SET)
64 +*/
65 +/*------------------------------------------------------------------------------------------------------*/
66 +
67 +uint8_t System_Init(void);
68 +void System_Exit(void);
69 +
70 +void SPI4W_Write_Byte(uint8_t value);
71 +//void I2C_Write_Byte(uint8_t value, uint8_t Cmd);
72 +
73 +void Driver_Delay_ms(uint32_t xms);
74 +void Driver_Delay_us(uint32_t xus);
75 +
76 +#endif
1 +/******************************************************************************
2 +***************************Intermediate driver layer***************************
3 +* | file : OLED_Driver.c
4 +* | version : V1.0
5 +* | date : 2017-11-09
6 +* | function : SSD1327 Drive function
7 +
8 +note:
9 +Image scanning:
10 +Please use progressive scanning to generate images or fonts
11 +******************************************************************************/
12 +
13 +#include "OLED_Driver.h"
14 +#include <stdio.h>
15 +
16 +
17 +COLOR Buffer[OLED_WIDTH / 2 * OLED_HEIGHT];
18 +OLED_DIS sOLED_DIS;
19 +/*******************************************************************************
20 +function:
21 + Hardware reset
22 +*******************************************************************************/
23 +static void OLED_Reset(void)
24 +{
25 + OLED_RST = 1;
26 + //PC12 = 1;
27 + Driver_Delay_ms(100);
28 + OLED_RST = 0;
29 + //PC12 = 0;
30 + Driver_Delay_ms(100);
31 + OLED_RST = 1;
32 + //PC12 = 1;
33 + Driver_Delay_ms(100);
34 +}
35 +
36 +/*******************************************************************************
37 +function:
38 + Write register address and data
39 +*******************************************************************************/
40 +void OLED_WriteReg(uint8_t Reg)
41 +{
42 +#if USE_SPI_4W
43 + OLED_DC = 0;
44 + OLED_CS = 0;
45 + SPI4W_Write_Byte(Reg);
46 + OLED_CS = 1;
47 +
48 +#elif USE_IIC
49 + I2C_Write_Byte(Reg,IIC_CMD);
50 +#endif
51 +}
52 +
53 +void OLED_WriteData(uint8_t Data)
54 +{
55 +#if USE_SPI_4W
56 + OLED_DC = 1;
57 + OLED_CS = 0;
58 + SPI4W_Write_Byte(Data);
59 + OLED_CS = 1;
60 +
61 +#elif USE_IIC
62 + I2C_Write_Byte(Data,IIC_RAM);
63 +#endif
64 +}
65 +
66 +/*******************************************************************************
67 +function:
68 + Common register initialization
69 +*******************************************************************************/
70 +static void OLED_InitReg(void)
71 +{
72 + OLED_WriteReg(0xae);//--turn off oled panel
73 +
74 + OLED_WriteReg(0x15); // set column address
75 + OLED_WriteReg(0x00); // start column 0
76 + OLED_WriteReg(0x7f); // end column 127
77 +
78 + OLED_WriteReg(0x75); // set row address
79 + OLED_WriteReg(0x00); // start row 0
80 + OLED_WriteReg(0x7f); // end row 127
81 +
82 + OLED_WriteReg(0x81); // set contrast control
83 + OLED_WriteReg(0x80);
84 +
85 + OLED_WriteReg(0xa0); // gment remap
86 + OLED_WriteReg(0x51); //51
87 +
88 + OLED_WriteReg(0xa1); // start line
89 + OLED_WriteReg(0x00);
90 +
91 + OLED_WriteReg(0xa2); // display offset
92 + OLED_WriteReg(0x00);
93 +
94 + OLED_WriteReg(0xa4); // rmal display
95 + OLED_WriteReg(0xa8); // set multiplex ratio
96 + OLED_WriteReg(0x7f);
97 +
98 + OLED_WriteReg(0xb1); // set phase leghth
99 + OLED_WriteReg(0xf1);
100 +
101 + OLED_WriteReg(0xb3); // set dclk
102 + OLED_WriteReg(0x00); //80Hz:0xc1 90Hz:0xe1 100Hz:0x00 110Hz:0x30 120Hz:0x50 130Hz:0x70 01
103 +
104 + OLED_WriteReg(0xab); //
105 + OLED_WriteReg(0x01); //
106 +
107 + OLED_WriteReg(0xb6); // set phase leghth
108 + OLED_WriteReg(0x0f);
109 +
110 + OLED_WriteReg(0xbe);
111 + OLED_WriteReg(0x0f);
112 +
113 + OLED_WriteReg(0xbc);
114 + OLED_WriteReg(0x08);
115 +
116 + OLED_WriteReg(0xd5);
117 + OLED_WriteReg(0x62);
118 +
119 + OLED_WriteReg(0xfd);
120 + OLED_WriteReg(0x12);
121 +
122 +}
123 +
124 +/********************************************************************************
125 +function: Set the display scan and color transfer modes
126 +parameter:
127 + Scan_dir : Scan direction
128 + Colorchose : RGB or GBR color format
129 +********************************************************************************/
130 +void OLED_SetGramScanWay(OLED_SCAN_DIR Scan_dir)
131 +{
132 + //Get the screen scan direction
133 + sOLED_DIS.OLED_Scan_Dir = Scan_dir;
134 +
135 + //Get GRAM and OLED width and height
136 + if(Scan_dir == L2R_U2D || Scan_dir == L2R_D2U || Scan_dir == R2L_U2D || Scan_dir == R2L_D2U) {
137 + sOLED_DIS.OLED_Dis_Column = OLED_WIDTH;
138 + sOLED_DIS.OLED_Dis_Page = OLED_HEIGHT;
139 + sOLED_DIS.OLED_X_Adjust = OLED_X;
140 + sOLED_DIS.OLED_Y_Adjust = OLED_Y;
141 + } else {
142 + sOLED_DIS.OLED_Dis_Column = OLED_HEIGHT;
143 + sOLED_DIS.OLED_Dis_Page = OLED_WIDTH;
144 + sOLED_DIS.OLED_X_Adjust = OLED_Y;
145 + sOLED_DIS.OLED_Y_Adjust = OLED_X;
146 + }
147 +}
148 +
149 +/********************************************************************************
150 +function:
151 + initialization
152 +********************************************************************************/
153 +void OLED_Init(OLED_SCAN_DIR OLED_ScanDir)
154 +{
155 + //Hardware reset
156 + OLED_Reset();
157 +
158 + //Set the initialization register
159 + OLED_InitReg();
160 +
161 + //Set the display scan and color transfer modes
162 + OLED_SetGramScanWay(OLED_ScanDir);
163 + Driver_Delay_ms(200);
164 +
165 + //Turn on the OLED display
166 + OLED_WriteReg(0xAF);
167 +}
168 +
169 +/********************************************************************************
170 +function: Set the display point(Xpoint, Ypoint)
171 +parameter:
172 + xStart : X direction Start coordinates
173 + xEnd : X direction end coordinates
174 +********************************************************************************/
175 +void OLED_SetCursor(POINT Xpoint, POINT Ypoint)
176 +{
177 + if((Xpoint > sOLED_DIS.OLED_Dis_Column) || (Ypoint > sOLED_DIS.OLED_Dis_Page))
178 + return;
179 +
180 + OLED_WriteReg(0x15);
181 + OLED_WriteReg(Xpoint);
182 + OLED_WriteReg(Xpoint);
183 +
184 + OLED_WriteReg(0x75);
185 + OLED_WriteReg(Ypoint);
186 + OLED_WriteReg(Ypoint);
187 +}
188 +
189 +/********************************************************************************
190 +function: Set the display Window(Xstart, Ystart, Xend, Yend)
191 +parameter:
192 + xStart : X direction Start coordinates
193 + Ystart : Y direction Start coordinates
194 + Xend : X direction end coordinates
195 + Yend : Y direction end coordinates
196 +********************************************************************************/
197 +void OLED_SetWindow(POINT Xstart, POINT Ystart, POINT Xend, POINT Yend)
198 +{
199 + if((Xstart > sOLED_DIS.OLED_Dis_Column) || (Ystart > sOLED_DIS.OLED_Dis_Page) ||
200 + (Xend > sOLED_DIS.OLED_Dis_Column) || (Yend > sOLED_DIS.OLED_Dis_Page))
201 + return;
202 +
203 + OLED_WriteReg(0x15);
204 + OLED_WriteReg(Xstart);
205 + OLED_WriteReg(Xend - 1);
206 +
207 + OLED_WriteReg(0x75);
208 + OLED_WriteReg(Ystart);
209 + OLED_WriteReg(Yend - 1);
210 +}
211 +
212 +/********************************************************************************
213 +function: Set show color
214 +parameter:
215 + Color : Set show color,16-bit depth
216 +********************************************************************************/
217 +//static void OLED_SetColor(LENGTH Dis_Width, LENGTH Dis_Height, COLOR Color ){
218 +void OLED_SetColor(POINT Xpoint, POINT Ypoint, COLOR Color)
219 +{
220 + if(Xpoint > sOLED_DIS.OLED_Dis_Column || Ypoint > sOLED_DIS.OLED_Dis_Page) {
221 + return;
222 + }
223 + //1 byte control two points
224 + if(Xpoint % 2 == 0) {
225 + Buffer[Xpoint / 2 + Ypoint * 64] = (Color << 4) | Buffer[Xpoint / 2 + Ypoint * 64];
226 + } else {
227 + Buffer[Xpoint / 2 + Ypoint * 64] = (Color & 0x0f) | Buffer[Xpoint / 2 + Ypoint * 64];
228 + }
229 +}
230 +
231 +/********************************************************************************
232 +function:
233 + Clear screen
234 +********************************************************************************/
235 +void OLED_Clear(COLOR Color)
236 +{
237 + unsigned int i,m;
238 + //OLED_SetWindow(0, 0, sOLED_DIS.OLED_Dis_Column, sOLED_DIS.OLED_Dis_Page);
239 + for(i = 0; i < sOLED_DIS.OLED_Dis_Page; i++) {
240 + for(m = 0; m < (sOLED_DIS.OLED_Dis_Column / 2); m++) {
241 + Buffer[i * (sOLED_DIS.OLED_Dis_Column / 2) + m] = Color | (Color << 4);
242 + }
243 + }
244 +}
245 +
246 +/********************************************************************************
247 +function: Update all memory to LCD
248 +********************************************************************************/
249 +void OLED_Display(void)
250 +{
251 + uint16_t page, Column;
252 + COLOR *pBuf = (COLOR *)Buffer;
253 +
254 + OLED_SetWindow(0, 0, sOLED_DIS.OLED_Dis_Column, sOLED_DIS.OLED_Dis_Page);
255 + //write data
256 + for (page = 0; page < sOLED_DIS.OLED_Dis_Page; page++) {
257 + for(Column = 0; Column < sOLED_DIS.OLED_Dis_Column / 2; Column++ ) {
258 + OLED_WriteData(*pBuf);
259 + pBuf++;
260 + }
261 + }
262 +}
263 +
264 +/********************************************************************************
265 +function:
266 + Clear Window
267 +********************************************************************************/
268 +void OLED_ClearWindow(POINT Xstart, POINT Ystart, POINT Xend, POINT Yend, COLOR Color)
269 +{
270 + uint16_t i,m, Xpoint, Ypoint;
271 + Xpoint = (Xend - Xstart) / 2;
272 + Ypoint = Yend - Ystart;
273 +
274 + uint16_t Num = Xstart + Ystart * (sOLED_DIS.OLED_Dis_Column / 2);
275 + for(i = 0; i < Ypoint; i++) {
276 + for(m = 0; m < Xpoint; m++) {
277 + Buffer[Num + m] = 0x00;
278 + }
279 + Num = Xstart + (Ystart + i + 1) * (sOLED_DIS.OLED_Dis_Column / 2);
280 + }
281 +}
282 +
283 +/********************************************************************************
284 +function: Update Window memory to LCD
285 +********************************************************************************/
286 +void OLED_DisWindow(POINT Xstart, POINT Ystart, POINT Xend, POINT Yend)
287 +{
288 + uint16_t page, Column, Xpoint, Ypoint;
289 + Xpoint = (Xend - Xstart) / 2;
290 + Ypoint = Yend - Ystart;
291 + OLED_SetWindow(Xstart, Ystart, Xend, Yend);
292 +
293 + //write data
294 + COLOR *pBuf = (COLOR *)Buffer + Xstart + Ystart * (sOLED_DIS.OLED_Dis_Column / 2);
295 + for (page = 0; page < Ypoint; page++) {
296 + for(Column = 0; Column < Xpoint; Column++ ) {
297 + OLED_WriteData(*pBuf);
298 + pBuf++;
299 + }
300 + pBuf = (COLOR *)Buffer + Xstart + (Ystart + page + 1) * (sOLED_DIS.OLED_Dis_Column / 2);
301 + }
302 +}
303 +
304 +
305 +
306 +
1 +/******************************************************************************
2 +***************************Intermediate driver layer***************************
3 +* | file : OLED_Driver.h
4 +* | version : V1.0
5 +* | date : 2017-11-09
6 +* | function : SSD1327 Drive function
7 +
8 +note:
9 +Image scanning:
10 +Please use progressive scanning to generate images or fonts
11 +******************************************************************************/
12 +#ifndef __OLED_DRIVER_H
13 +#define __OLED_DRIVER_H
14 +
15 +#include <stdint.h>
16 +#include "DEV_Config.h"
17 +
18 +
19 +#define COLOR uint16_t //The variable type of the color (unsigned short)
20 +#define POINT uint16_t //The type of coordinate (unsigned short)
21 +#define LENGTH uint16_t //The type of coordinate (unsigned short)
22 +
23 +/********************************************************************************
24 +function:
25 + Define the full screen height length of the display
26 +********************************************************************************/
27 +#define OLED_X_MAXPIXEL 128 //OLED width maximum memory
28 +#define OLED_Y_MAXPIXEL 128 //OLED height maximum memory
29 +#define OLED_X 0
30 +#define OLED_Y 0
31 +
32 +#define OLED_WIDTH (OLED_X_MAXPIXEL - 2 * OLED_X) //OLED width
33 +#define OLED_HEIGHT OLED_Y_MAXPIXEL //OLED height
34 +
35 +/********************************************************************************
36 +function:
37 + scanning method
38 +********************************************************************************/
39 +typedef enum{
40 + L2R_U2D = 0, //The display interface is displayed , left to right, up to down
41 + L2R_D2U ,
42 + R2L_U2D ,
43 + R2L_D2U ,
44 +
45 + U2D_L2R ,
46 + U2D_R2L ,
47 + D2U_L2R ,
48 + D2U_R2L ,
49 +}OLED_SCAN_DIR;
50 +#define SCAN_DIR_DFT L2R_U2D //Default scan direction = L2R_U2D
51 +
52 +/********************************************************************************
53 +function:
54 + Defines the total number of rows in the display area
55 +********************************************************************************/
56 +typedef struct{
57 + LENGTH OLED_Dis_Column; //COLUMN
58 + LENGTH OLED_Dis_Page; //PAGE
59 + OLED_SCAN_DIR OLED_Scan_Dir;
60 + POINT OLED_X_Adjust; //OLED x actual display position calibration
61 + POINT OLED_Y_Adjust; //OLED y actual display position calibration
62 +}OLED_DIS;
63 +
64 +/********************************************************************************
65 +function:
66 + Macro definition variable name
67 +********************************************************************************/
68 +void OLED_Init(OLED_SCAN_DIR OLED_ScanDir);
69 +void OLED_SetGramScanWay(OLED_SCAN_DIR Scan_dir);
70 +
71 +void OLED_WriteReg(uint8_t Reg);
72 +void OLED_WriteData(uint8_t Data);
73 +
74 +//OLED set cursor + windows + color
75 +void OLED_SetCursor(POINT Xpoint, POINT Ypoint);
76 +void OLED_SetColor(POINT Xpoint, POINT Ypoint, COLOR Color);
77 +void OLED_SetWindow(POINT Xstart, POINT Ystart, POINT Xend, POINT Yend);
78 +void OLED_Clear(COLOR Color);
79 +void OLED_Display(void);
80 +void OLED_ClearWindow(POINT Xstart, POINT Ystart, POINT Xend, POINT Yend, COLOR Color);
81 +void OLED_DisWindow(POINT Xstart, POINT Ystart, POINT Xend, POINT Yend);
82 +
83 +
84 +#endif
85 +
86 +
87 +
88 +
89 +
This diff could not be displayed because it is too large.
1 +/**
2 + ******************************************************************************
3 + * @file fonts.h
4 + * @author MCD Application Team
5 + * @version V1.0.0
6 + * @date 18-February-2014
7 + * @brief Header for fonts.c file
8 + ******************************************************************************
9 + * @attention
10 + *
11 + * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
12 + *
13 + * Redistribution and use in source and binary forms, with or without modification,
14 + * are permitted provided that the following conditions are met:
15 + * 1. Redistributions of source code must retain the above copyright notice,
16 + * this list of conditions and the following disclaimer.
17 + * 2. Redistributions in binary form must reproduce the above copyright notice,
18 + * this list of conditions and the following disclaimer in the documentation
19 + * and/or other materials provided with the distribution.
20 + * 3. Neither the name of STMicroelectronics nor the names of its contributors
21 + * may be used to endorse or promote products derived from this software
22 + * without specific prior written permission.
23 + *
24 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32 + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 + *
35 + ******************************************************************************
36 + */
37 +
38 +/* Define to prevent recursive inclusion -------------------------------------*/
39 +#ifndef __FONTS_H
40 +#define __FONTS_H
41 +
42 +/* Max size of bitmap will based on a font24 (17x24) */
43 +#define MAX_HEIGHT_FONT 24
44 +#define MAX_WIDTH_FONT 17
45 +#define OFFSET_BITMAP 54
46 +
47 +#ifdef __cplusplus
48 + extern "C" {
49 +#endif
50 +
51 +/* Includes ------------------------------------------------------------------*/
52 +#include <stdint.h>
53 +
54 +typedef struct _tFont
55 +{
56 + const uint8_t *table;
57 + uint16_t Width;
58 + uint16_t Height;
59 +
60 +} sFONT;
61 +
62 +extern sFONT Font24;
63 +extern sFONT Font20;
64 +extern sFONT Font16;
65 +extern sFONT Font12;
66 +extern sFONT Font8;
67 +
68 +#ifdef __cplusplus
69 +}
70 +#endif
71 +
72 +#endif /* __FONTS_H */
73 +
74 +
75 +/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
This diff is collapsed. Click to expand it.
1 + /**********************************************************
2 + *
3 + * @file : wifi.h
4 + * @author : HaewonSeo
5 + *
6 + * @note : ESP8266 WiFi Module
7 + *
8 + **********************************************************/
9 +
10 +#include <stdio.h>
11 +#include <stdlib.h>
12 +#include "NuMicro.h"
13 +#include "cssd_lib.h"
14 +
15 +#ifndef __WIFI_H__
16 +#define __WIFI_H__
17 +
18 +#define WIFI_PORT UART3_NS // Used to connect to WIFI module
19 +#define BYPASS_PORT UART0_NS // Used to byass WIFI module
20 +
21 +//#define LED_Y PC11_NS // Yellow LED
22 +//#define LED_G PC12_NS // Green LED
23 +#define PWR_OFF PD7_NS
24 +#define FW_UPDATE_OFF PD6_NS
25 +
26 +#define IOCTL_INIT { \
27 + PD_NS->MODE = (GPIO_MODE_OUTPUT << 6*2) | (GPIO_MODE_OUTPUT << 7*2); }\
28 + //PC_NS->MODE = (GPIO_MODE_OUTPUT << 11*2) | (GPIO_MODE_OUTPUT << 12*2); } \
29 + //PA->MODE = (GPIO_MODE_OUTPUT << 10*2) | (GPIO_MODE_OUTPUT << 11*2) ;}
30 +
31 +typedef struct s_netData
32 +{
33 + char *data;
34 + int len;
35 +} t_netData;
36 +
37 +
38 +void printNetworkData(t_netData *netData);
39 +void WIFI_Init();
40 +void WIFI_Connect();
41 +void WIFI_Read(int);
42 +void WIFI_Write(int, const char *, int);
43 +int WIFI_ReceiveData(int, t_netData *);
44 +int WIFI_SendData(int print, t_netData *netData, int port);
45 +
46 +void WIFI_Send_BPM(int pulse);
47 +void WIFI_Send_EncryptedMsg(uint8_t *encryptedMsg, int encryptedMsgBytes, uint32_t body);
48 +void WIFI_Send_DigitallySignedData(t_digitallySignedData *dsd);
49 +void WIFI_Send_EncryptedDigitallySignedData(t_digitallySignedData *dsd);
50 +
51 + #endif /* __WIFI_H__ */
1 + /**********************************************************
2 + *
3 + * @file : cssd_lib.h
4 + * @author : HaewonSeo
5 + *
6 + * @note : M2351 Collaborative Secure Software Development Library header file
7 + *
8 + **********************************************************/
9 +#include <stdint.h>
10 +
11 +#ifndef __CSSD_LIB_H__
12 +#define __CSSD_LIB_H__
13 +
14 +
15 +typedef struct s_digitallySignedData
16 +{
17 + uint8_t data[17];
18 + uint8_t pubKey1[25];
19 + uint8_t pubKey2[25];
20 + uint8_t R[25];
21 + uint8_t S[25];
22 +} t_digitallySignedData;
23 +
24 +/*----------------------------------------------------------------------------
25 + NonSecure Callable Functions from Secure Region
26 + *----------------------------------------------------------------------------*/
27 +extern uint32_t GetSystemCoreClock(void);
28 +
29 +extern int32_t Secure_OLED_On_callback(void (*)(uint32_t));
30 +extern int32_t Secure_OLED_Off_callback(void (*)(uint32_t));
31 +
32 +/*----------------------------------------------------------------------------
33 + MAX30102 Heart-Rate Sensor functions
34 + *----------------------------------------------------------------------------*/
35 +
36 +extern uint32_t Get_BPM();
37 +extern uint32_t Get_EncryptedDigitallySignedData(t_digitallySignedData *dsd);
38 +
39 +/*----------------------------------------------------------------------------
40 + CRYPTO functions
41 + *----------------------------------------------------------------------------*/
42 +
43 +extern int32_t Encrypt_data(uint8_t *plainData, uint8_t *encryptedData, uint32_t bytes);
44 +extern int32_t Decrypt_data(uint8_t *encryptedData, uint8_t *resultData, uint32_t bytes);
45 +extern void M2351_LoadKey();
46 +extern void M2351_DeleteKey();
47 +/*----------------------------------------------------------------------------
48 + PRINT functions
49 + *----------------------------------------------------------------------------*/
50 +
51 +extern void printBlock(uint8_t *block);
52 +extern void printSecure(char *string, void *ptr, uint8_t val);
53 +extern int32_t printDigitallySignedData(t_digitallySignedData *dsd);
54 +
55 +#endif //__CSSD_LIB_H__
1 + /**********************************************************
2 + *
3 + * @file : main_ns.c
4 + * @author : HaewonSeo
5 + *
6 + * @note : Main of Non-secure world, Non-secure code for Collaborative Secure Software Development
7 + *
8 + **********************************************************/
9 +
10 +#include <arm_cmse.h>
11 +#include <string.h>
12 +#include "NuMicro.h" /* Device header */
13 +#include "cssd_lib.h" /* Collaborative Secure Software Development Library header */
14 +#include "wifi.h"
15 +#include "OLED_GUI.h"
16 +
17 +#define SW2 PB0_NS
18 +#define SW3 PB1_NS
19 +
20 +extern const char ATCommand_CIPSTART[];
21 +extern void OLED_BPM(uint32_t bpm);
22 +
23 +/*----------------------------------------------------------------------------
24 + NonSecure Functions from NonSecure Region
25 + *----------------------------------------------------------------------------*/
26 +
27 +
28 +
29 +void Control_SW3()
30 +{
31 + int result = 0;
32 + t_netData *send;
33 +
34 + send = calloc(1, sizeof(t_netData));
35 + send->data = calloc(33, sizeof(char));
36 + send->len = 0;
37 +
38 + //result = WIFI_ReceiveData(1, rec);
39 +
40 + const char msg[] = "Hello..";
41 +
42 + send->len = strlen(msg);
43 + strcpy(send->data, msg);
44 +
45 + WIFI_SendData(1, send, 1);
46 +
47 + free(send->data);
48 + free(send);
49 +
50 + t_netData *rec = malloc(sizeof(t_netData));
51 + rec->data = malloc(sizeof(char)*33);
52 + (rec->data)[32] = '\0';
53 + rec->len = 0;
54 + WIFI_ReceiveData(1, rec);
55 +
56 + free(rec->data);
57 + free(rec);
58 +
59 + return ;
60 +}
61 +
62 +/*----------------------------------------------------------------------------
63 + SysTick IRQ Handler
64 + *----------------------------------------------------------------------------*/
65 +void SysTick_Handler(void)
66 +{
67 + static uint32_t u32Ticks;
68 +
69 + switch(u32Ticks++)
70 + {
71 + case 0:
72 + break;
73 + case 100:
74 + break;
75 + case 200:
76 + break;
77 + case 300:
78 + break;
79 + case 400:
80 + break;
81 + case 500:
82 + break;
83 + case 600:
84 + u32Ticks = 0;
85 + break;
86 + default:
87 + if(u32Ticks > 600)
88 + {
89 + u32Ticks = 0;
90 + }
91 + }
92 +}
93 +
94 +/*----------------------------------------------------------------------------
95 + Main function
96 + *----------------------------------------------------------------------------*/
97 +int main(void)
98 +{
99 + int32_t i = 0;
100 + int32_t ispulse = 0;
101 + uint32_t pulse = 0;
102 + t_digitallySignedData dsd;
103 + memset(&dsd, 0, sizeof(t_digitallySignedData));
104 +
105 + int32_t SW2_toggle = 0;
106 + int32_t ns_ticks = 0;
107 +
108 + printf("\n");
109 + printf("+---------------------------------------------+\n");
110 + printf("| Non-Secure is running ... |\n");
111 + printf("+---------------------------------------------+\n");
112 +
113 + /* register NonSecure callbacks in Secure application */
114 + Secure_OLED_On_callback(&OLED_BPM);
115 + //Secure_OLED_Off_callback(&NonSecure_OLED_Off);
116 +
117 + /* Call secure API to get system core clock */
118 + SystemCoreClock = GetSystemCoreClock();
119 +
120 + /* Generate Systick interrupt each 10 ms */
121 + SysTick_Config(SystemCoreClock / 100);
122 +
123 +
124 + printf("\n");
125 + printf("+---------------------------------------------+\n");
126 + printf("| SDK1327 OLED Init |\n");
127 + printf("+---------------------------------------------+\n");
128 +
129 + OLED_Config();
130 +
131 + printf("\n");
132 + printf("+---------------------------------------------+\n");
133 + printf("| ESP8266 WiFi Module Start |\n");
134 + printf("+---------------------------------------------+\n");
135 +
136 + WIFI_Connect();
137 +
138 + while(1)
139 + {
140 + /* SW2 */
141 + if(SW2 == 0)
142 + {
143 + while(SW2 == 0);
144 + SW2_toggle = !SW2_toggle;
145 + printf("\nSW2 ON in Non-secure code ...\n\n");
146 +
147 + if(SW2_toggle)
148 + {
149 + ns_ticks = 0;
150 + printf("\nMAX30102 On ...\n\n");
151 + M2351_LoadKey();
152 + OLED_Background_On();
153 + }
154 + else
155 + {
156 + printf("\nMAX30102 Off ...\n\n");
157 + M2351_DeleteKey();
158 + OLED_Off();
159 + }
160 + }
161 + /* SW3 */
162 + if(SW3 == 0)
163 + {
164 + while(SW3 == 0);
165 + printf("\nSW3 ON in Non-secure code ...\n\n");
166 + Control_SW3();
167 + }
168 + if(SW2_toggle)
169 + {
170 + /* Get digitally signed data of BPM from MAX30102 */
171 + ispulse = Get_EncryptedDigitallySignedData(&dsd);
172 + ns_ticks++;
173 + if (ns_ticks >= 60)
174 + {
175 + ns_ticks = 0;
176 + if (ispulse)
177 + {
178 + printf("\nEncrypted digitallySignedData\n");
179 + printDigitallySignedData(&dsd);
180 + /* Send digitally signed data of BPM to Server */
181 + //WIFI_Send_BPM(ispulse);
182 + WIFI_Send_EncryptedDigitallySignedData(&dsd);
183 + }
184 + }
185 + }
186 + }
187 +}
188 +
189 +//CLK_SysTickLongDelay(300000); //300000us = 300ms = 0.3s
190 +
191 +/*
192 +void testCryptDeCrypt() {
193 +
194 + //Test Function to cipher and decypher data
195 +
196 + //__attribute__((aligned(4))) uint8_t plainData[16] = {0x32, 0x43, 0xf6, 0xa8, 0x88, 0x5a, 0x30, 0x8d, 0x31, 0x31, 0x98, 0xa2, 0xe0, 0x37, 0x07, 0x34};
197 + __attribute__((aligned(4))) uint8_t plainData[16] = {0};
198 +
199 + __attribute__((aligned(4))) uint8_t cipheredData[16] = {0};
200 + __attribute__((aligned(4))) uint8_t resultData[16] = {0};
201 +
202 + __attribute__((aligned(4))) uint8_t key[16] =
203 + {
204 + 0x7f, 0x35, 0x91, 0xd3, 0x6f, 0xd5, 0x17, 0xa3, 0x7b, 0x6d, 0xe9, 0xe0, 0xdf, 0x93, 0x4b, 0x7a
205 + };
206 + __attribute__((aligned(4))) uint8_t iv[16] = {0};
207 +
208 + sprintf((char *)plainData, "%d", 123);
209 + printf("%s\n", plainData);
210 +
211 + if (DEMO) {
212 + //printSecure("&key = %p\n",key);
213 + //printBlock(key);
214 + //printSecure("&iv = %p\n",iv);
215 + //printBlock(iv);
216 + printSecure("&plainData = %p\n",plainData, NULL);
217 + printBlock(plainData);
218 + CLK_SysTickLongDelay(500000);
219 + }
220 +
221 +// Store_key(key);
222 +// Store_iv(iv);
223 +
224 + int c = Encrypt_data(plainData, cipheredData, 16);
225 + if (c == NULL) printSecure("Error : 128bits only", NULL, NULL);
226 +
227 + if (DEMO) {
228 + CLK_SysTickLongDelay(500000);
229 + printSecure("| Nonsecure is running ... |\n",NULL, NULL);
230 +
231 + printSecure("&cipheredData = %p\n",cipheredData, NULL);
232 + printBlock(cipheredData);
233 + }
234 +
235 + int r = Decrypt_data(cipheredData, resultData, 16);
236 + if (r == NULL) printSecure("Error : 128bits only", NULL, NULL);
237 +
238 + if (DEMO) {
239 + CLK_SysTickLongDelay(500000);
240 + printSecure("| Nonsecure is running ... |\n",NULL, NULL);
241 +
242 + printSecure("&resultData = %p\n",resultData, NULL);
243 + printBlock(resultData);
244 +
245 + uint8_t error = 0;
246 + for (uint8_t i = 0 ; i < 16 ; i++) {
247 +
248 + if (resultData[i] != plainData[i]) error++;
249 +
250 + }
251 + if (error != 0) printSecure("Error plainData is not equal to resultData", NULL, NULL);
252 + else printSecure("No error plainData is equal to resultData", NULL, NULL);
253 +
254 + }
255 +
256 +}
257 +*/
258 +
...\ No newline at end of file ...\ No newline at end of file
1 +<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
2 +<ProjectWorkspace xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="project_mpw.xsd">
3 +
4 + <SchemaVersion>1.0</SchemaVersion>
5 +
6 + <Header>### uVision Project, (C) Keil Software</Header>
7 +
8 + <WorkspaceName>WorkSpace</WorkspaceName>
9 +
10 + <project>
11 + <PathAndName>.\Secure\Secure.uvprojx</PathAndName>
12 + <NodeIsExpanded>1</NodeIsExpanded>
13 + </project>
14 +
15 + <project>
16 + <PathAndName>.\NonSecure\NonSecure.uvprojx</PathAndName>
17 + <NodeIsActive>1</NodeIsActive>
18 + <NodeIsExpanded>1</NodeIsExpanded>
19 + </project>
20 +
21 +</ProjectWorkspace>
1 +/**********************************************************
2 + *
3 + * @file : M2351_crypto.h
4 + * @author : HaewonSeo
5 + *
6 + * @note : M2351 Cryptographic Accelerator
7 + **********************************************************/
8 +#include <stdio.h>
9 +#include <string.h>
10 +#include "NuMicro.h"
11 +
12 +#ifndef M2351_CRYPTO_H_
13 +#define M2351_CRYPTO_H_
14 +
15 +#define ENCRYPT 1
16 +#define DECRYPT 0
17 +
18 +static volatile int32_t g_AES_done;
19 +
20 +void CRPT_IRQHandler(void);
21 +void M2351_Crypto_Init(uint8_t, uint8_t);
22 +void M2351_Crypto_UseSessionKey(uint8_t );
23 +void M2351_Crypto_UseMasterKey(void);
24 +void M2351_Encrypt_Data(uint8_t, uint8_t *, uint8_t *, uint32_t);
25 +void M2351_Decrypt_Data(uint8_t, uint8_t *, uint8_t *, uint32_t);
26 +
27 +void M2351_FMC_Read_Key(uint32_t num, uint32_t len, char *priKey);
28 +void M2351_FMC_Write_Key(void);
29 +
30 +void M2351_ECC_GenerateKey(char *priKey, char *gKey1, char *gKey2);
31 +void M2351_SHA_Hash(uint8_t *msg, uint8_t *hash_msg);
32 +void M2351_ECDSA_GenerateSignature(uint8_t *msg, char *priKey, char* R, char *S);
33 +void M2351_ECDSA_VerificationSignature(char *hash_msg, char *pubKey1, char* pubKey2, char* R, char *S);
34 +
35 +
36 +#endif /* M2351_CRYPTO_H_ */
1 +#include "crypto_aes.h"
2 +#include "nsc.h"
3 +
4 +uint8_t cipheredSessionKey[16];
5 +uint8_t sessionIv[16];
6 +
7 +void CRPT_IRQHandler()
8 +{
9 + if(AES_GET_INT_FLAG(CRPT))
10 + {
11 + g_AES_done = 1;
12 + AES_CLR_INT_FLAG(CRPT);
13 + }
14 +}
15 +
16 +void M2351_Crypto_Init(uint8_t channel, uint8_t modeAES)
17 +{
18 + if(modeAES != ENCRYPT && modeAES != DECRYPT)
19 + printf("Error mode , mode must be ENCRYPT or DECRYPT value\n");
20 +
21 + NVIC_EnableIRQ(CRPT_IRQn);
22 + AES_ENABLE_INT(CRPT);
23 +
24 + AES_Open(CRPT, channel, modeAES, AES_MODE_CBC, AES_KEY_SIZE_128, AES_IN_OUT_SWAP);
25 +}
26 +
27 +void M2351_Crypto_UseMasterKey()
28 +{
29 +
30 + CRPT_T *crpt = CRPT;
31 + uint32_t u32Channel = 1;
32 +
33 + /* Load Key */
34 + uint32_t key_reg_addr;
35 + // 0x3CUL : channel size
36 + key_reg_addr = (uint32_t)&crpt->AES0_KEY[0] + (u32Channel * 0x3CUL);
37 +
38 + /* Enable FMC ISP function */
39 + FMC_Open();
40 +
41 + outpw(key_reg_addr, FMC_ReadUID(0));
42 + outpw(key_reg_addr+4UL, FMC_ReadUID(1));
43 + outpw(key_reg_addr+8UL, FMC_ReadUID(2));
44 + outpw(key_reg_addr+12UL, FMC_ReadUID(0));
45 +
46 + //printf("\nmasterKey = %08x%08x%08x%08x\n",FMC_ReadUID(0),FMC_ReadUID(1),FMC_ReadUID(2),FMC_ReadUID(0));
47 +
48 + /* Disable FMC ISP function */
49 + FMC_Close();
50 +
51 + //outpw(key_reg_addr, 0x2b7e1516);
52 + //outpw(key_reg_addr+4UL, 0x28aed2a6);
53 + //outpw(key_reg_addr+8UL, 0xabf71588);
54 + //outpw(key_reg_addr+12UL, 0x09cf4f3c);
55 +
56 + /* Load IV */
57 + uint32_t iv_reg_addr;
58 + iv_reg_addr = (uint32_t)&crpt->AES0_IV[0] + (u32Channel * 0x3CUL);
59 +
60 + outpw(iv_reg_addr, 0x00000000);
61 + outpw(iv_reg_addr+4UL, 0x00000000);
62 + outpw(iv_reg_addr+8UL, 0x00000000);
63 + outpw(iv_reg_addr+12UL, 0x00000000);
64 +
65 +}
66 +
67 +void M2351_Crypto_UseSessionKey(uint8_t channel)
68 +{
69 +
70 + uint8_t sessionKey[16] = {0};
71 +
72 + //printf("&cipheredSessionKey = %p\n", cipheredSessionKey);
73 + //printBlock(cipheredSessionKey);
74 +
75 + //M2351_Crypto_Init(1, DECRYPT);
76 + //M2351_Crypto_UseMasterKey();
77 + //if (DEMO)
78 + // printf("| Secure is running ... decrypt sessionKey |\n");
79 + //M2351_Decrypt_Data(1, cipheredSessionKey, sessionKey);
80 +
81 + //printf("&sessionKey = %p\n", sessionKey);
82 + //printBlock(sessionKey);
83 +
84 +
85 + if (DEMO)
86 + printf("| Secure is running ... Use sessionKey |\n");
87 + uint32_t tmp_sk[4];
88 + uint32_t tmp_si[4];
89 +
90 + for (uint8_t z = 0; z < 4; z++)
91 + {
92 + tmp_sk[z] = (sessionKey[0+(4*z)] << 24) | (sessionKey[1+(4*z)] << 16) | (sessionKey[2+(4*z)] << 8) | sessionKey[3+(4*z)];
93 + tmp_si[z] = (sessionIv[0+(4*z)] << 24) | (sessionIv[1+(4*z)] << 16) | (sessionIv[2+(4*z)] << 8) | sessionIv[3+(4*z)];
94 + }
95 + AES_SetKey(CRPT, channel, tmp_sk, AES_KEY_SIZE_128);
96 + AES_SetInitVect(CRPT, channel, tmp_si);
97 +
98 + /* Reset memory */
99 + for (uint8_t z = 0; z < 16; z++) sessionKey[z] = 0;
100 +
101 + for (uint8_t z = 0; z < 4; z++) {
102 + tmp_sk[z] = 0;
103 + tmp_si[z] = 0;
104 + }
105 +
106 +}
107 +
108 +/* Function M2351_encrypt_data is same as Nuvoton_M2351_decrypt_data */
109 +void M2351_Encrypt_Data(uint8_t channel, uint8_t InputData[], uint8_t OutputData[])
110 +{
111 +
112 + //printf("AES ECB encrypt start.\n");
113 +
114 + //printf("&inputData = %p\n",InputData);
115 + //printf("&outputData = %p\n",OutputData);
116 +
117 + AES_SetDMATransfer(CRPT, channel, (uint32_t)InputData, (uint32_t)OutputData, 16);
118 +/*
119 + printf("before start AES : \n"
120 + "CRPT->AES0_CNT : %d\n"
121 + "CRPT->AES0_DADDR : %d\n"
122 + "CRPT->AES0_IV : %d\n"
123 + "CRPT->AES0_KEY : %d\n"
124 + "CRPT->AES0_SADDR : %d\n", CRPT->AES0_CNT,CRPT->AES0_DADDR,CRPT->AES0_IV, CRPT->AES0_KEY, CRPT->AES0_SADDR);
125 +*/
126 +
127 + g_AES_done = 0;
128 + /* Start AES encrypt */
129 + AES_Start(CRPT, channel, CRYPTO_DMA_ONE_SHOT);
130 +
131 + /* Waiting for AES calculation */
132 + while(!g_AES_done);
133 +
134 + //printf("AES CBC encrypt done.\n");
135 +
136 +}
137 +
138 +/* Function M2351_decrypt_data is same as Nuvoton_M2351_encrypt_data */
139 +void M2351_Decrypt_Data(uint8_t channel, uint8_t InputData[], uint8_t OutputData[])
140 +{
141 +
142 + //printf("AES ECB decrypt start.\n");
143 + /*
144 + printf("&inputData = %p\n",InputData);
145 + printf("&outputData = %p\n",OutputData);
146 + */
147 +
148 + AES_SetDMATransfer(CRPT, channel, (uint32_t)InputData, (uint32_t)OutputData, 16);
149 +/*
150 + printf("before start AES : \n"
151 + "CRPT->AES0_CNT : %d\n"
152 + "CRPT->AES0_DADDR : %d\n"
153 + "CRPT->AES0_IV : %d\n"
154 + "CRPT->AES0_KEY : %d\n"
155 + "CRPT->AES0_SADDR : %d\n", CRPT->AES0_CNT,CRPT->AES0_DADDR,CRPT->AES0_IV, CRPT->AES0_KEY, CRPT->AES0_SADDR);
156 +*/
157 + g_AES_done = 0;
158 + /* Start AES decrypt */
159 + AES_Start(CRPT, channel, CRYPTO_DMA_ONE_SHOT);
160 + /* Waiting for AES calculation */
161 + while(!g_AES_done);
162 +
163 + //printf("AES CBC decrypt done.\n");
164 +
165 +}
1 +#include <stdio.h>
2 +#include <string.h>
3 +#include "NuMicro.h"
4 +
5 +#ifndef CRYPTO_AES_H_
6 +#define CRYPTO_AES_H_
7 +
8 +#define ENCRYPT 1
9 +#define DECRYPT 0
10 +
11 +static volatile int32_t g_AES_done;
12 +
13 +void CRPT_IRQHandler(void);
14 +void M2351_Crypto_Init(uint8_t, uint8_t);
15 +void M2351_Crypto_UseSessionKey(uint8_t );
16 +void M2351_Crypto_UseMasterKey(void);
17 +void M2351_Encrypt_Data(uint8_t, uint8_t *, uint8_t *);
18 +void M2351_Decrypt_Data(uint8_t, uint8_t *, uint8_t *);
19 +
20 +#endif /* CRYPTO_AES_H_ */
1 +<?xml version="1.0" encoding="utf-8"?>
2 +
3 +<component_viewer schemaVersion="0.1" xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="Component_Viewer.xsd">
4 +
5 +<component name="EventRecorderStub" version="1.0.0"/> <!--name and version of the component-->
6 + <events>
7 + </events>
8 +
9 +</component_viewer>
1 +///*************************************************************************
2 +// * @file MAX30102.c
3 +// * @brief
4 +// * MAX30102 driver header file
5 +// *
6 +// * @note
7 +// ********************************************************************** **/
8 +
9 +
10 +/*
11 + Optical Heart Rate Detection (PBA Algorithm)
12 + By: Nathan Seidle
13 + SparkFun Electronics
14 + Date: October 2nd, 2016
15 +
16 + Given a series of IR samples from the MAX30105 we discern when a heart beat is occurring
17 +
18 + Let's have a brief chat about what this code does. We're going to try to detect
19 + heart-rate optically. This is tricky and prone to give false readings. We really don't
20 + want to get anyone hurt so use this code only as an example of how to process optical
21 + data. Build fun stuff with our MAX30105 breakout board but don't use it for actual
22 + medical diagnosis.
23 +
24 + Excellent background on optical heart rate detection:
25 + http://www.ti.com/lit/an/slaa655/slaa655.pdf
26 +
27 + Good reading:
28 + http://www.techforfuture.nl/fjc_documents/mitrabaratchi-measuringheartratewithopticalsensor.pdf
29 + https://fruct.org/publications/fruct13/files/Lau.pdf
30 +
31 + This is an implementation of Maxim's PBA (Penpheral Beat Amplitude) algorithm. It's been
32 + converted to work within the Arduino framework.
33 +*/
34 +
35 +/* Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
36 +*
37 +* Permission is hereby granted, free of charge, to any person obtaining a
38 +* copy of this software and associated documentation files (the "Software"),
39 +* to deal in the Software without restriction, including without limitation
40 +* the rights to use, copy, modify, merge, publish, distribute, sublicense,
41 +* and/or sell copies of the Software, and to permit persons to whom the
42 +* Software is furnished to do so, subject to the following conditions:
43 +*
44 +* The above copyright notice and this permission notice shall be included
45 +* in all copies or substantial portions of the Software.
46 +*
47 +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
48 +* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
49 +* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
50 +* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
51 +* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
52 +* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
53 +* OTHER DEALINGS IN THE SOFTWARE.
54 +*
55 +* Except as contained in this notice, the name of Maxim Integrated
56 +* Products, Inc. shall not be used except as stated in the Maxim Integrated
57 +* Products, Inc. Branding Policy.
58 +*
59 +* The mere transfer of this software does not imply any licenses
60 +* of trade secrets, proprietary technology, copyrights, patents,
61 +* trademarks, maskwork rights, or any other form of intellectual
62 +* property whatsoever. Maxim Integrated Products, Inc. retains all
63 +* ownership rights.
64 +*
65 +*/
66 +
67 +
68 +#include "NuMicro.h"
69 +#include "MAX30102.h"
70 +
71 +
72 +// Data buffer
73 +uint8_t au8RDataBuf[6];
74 +
75 +// Raw HR & SPo2 data from MAX30102 DATA FIFO
76 +volatile int32_t hr_val;
77 +volatile int32_t spo2_val;
78 +
79 +extern volatile uint32_t millis_counter;
80 +//extern uint32_t GetMillis();
81 +extern uint32_t OLED_printTime;
82 +
83 +int16_t IR_AC_Max = 20;
84 +int16_t IR_AC_Min = -20;
85 +
86 +int16_t IR_AC_Signal_Current = 0;
87 +int16_t IR_AC_Signal_Previous;
88 +int16_t IR_AC_Signal_min = 0;
89 +int16_t IR_AC_Signal_max = 0;
90 +int16_t IR_Average_Estimated;
91 +
92 +int16_t positiveEdge = 0;
93 +int16_t negativeEdge = 0;
94 +int32_t ir_avg_reg = 0;
95 +
96 +int16_t cbuf[32];
97 +uint8_t offset = 0;
98 +
99 +static const uint16_t FIRCoeffs[12] = {172, 321, 579, 927, 1360, 1858, 2390, 2916, 3391, 3768, 4012, 4096};
100 +
101 +const int32_t RATE_SIZE = 4; //Increase this for more averaging. 4 is good.
102 +int32_t rates[RATE_SIZE]; //Array of heart rates
103 +int32_t rateSpot = 0;
104 +long lastBeat = 0; //Time at which the last beat occurred
105 +
106 +float beatsPerMinute;
107 +int beatAvg;
108 +
109 +
110 +
111 +/*
112 + Configuration MAX30102 by write data to a MAX30102 and check return value
113 +*/
114 +void MAX30102_Config()
115 +{
116 + uint8_t ret = 2;
117 +
118 + printf("+---------------------------------------------+\n");
119 + printf("| Configuration MAX30102 in SECURE |\n");
120 + printf("+---------------------------------------------+\n");
121 +
122 +
123 + /* FIFO Config
124 + Sample_AVG 4, FIFO_ROLLOVER_EN
125 + 1*/
126 + ret = I2C_WriteByteOneReg(I2C0, MAX30102_ADDR, MAX30102_FIFO_CONFIG, 0x50);
127 + printf("| [1] MAX30102_FIFO_CONFIG ..... |\n");
128 +
129 + /* Mode Config
130 + Mode conrtol, Active LED Channels : Multi-LED Mode
131 + */
132 + ret = I2C_WriteByteOneReg(I2C0, MAX30102_ADDR, MAX30102_MODE_CONFIG, 0x07);
133 + printf("| [2] MAX30102_MODE_CONFIG ..... |\n");
134 +
135 + /* SpO2 Config
136 + SPO2 ADC range control(4096), SPO2 sample rate 400/1s,
137 + LED pulse width = 411, ADC Resolution = 18bit
138 + 0b00101111
139 + */
140 + ret = I2C_WriteByteOneReg(I2C0, MAX30102_ADDR, MAX30102_SPO2_CONFIG, 0x2F);
141 + printf("| [3] MAX30102_SPO2_CONFIG ..... |\n");
142 +
143 + /* LED Pulse Amplitude
144 + Typical LED1(RED) current : 2.0mA
145 + Typical LED2(IR) current : 6.2mA
146 + */
147 + ret = I2C_WriteByteOneReg(I2C0, MAX30102_ADDR, MAX30102_LED1_AMP, 0x0A);
148 + printf("| [4] MAX30102_LED1_AMP ..... |\n");
149 +
150 + ret = I2C_WriteByteOneReg(I2C0, MAX30102_ADDR, MAX30102_LED2_AMP, 0x1F);
151 + printf("| [5] MAX30102_LED2_AMP ..... |\n");
152 +
153 + /* Multi-LED Mode Control Registers
154 + Slot1 : LED1(RED), Slot2 : LED2(IR)
155 + */
156 + ret = I2C_WriteByteOneReg(I2C0, MAX30102_ADDR, MAX31012_MLED_CTRL1, 0x21);
157 + printf("| [6] MAX31012_MLED_CTRL1 ..... |\n");
158 +
159 + //ret = I2C_WriteByteOneReg(I2C0, MAX30102_ADDR, MAX31012_MLED_CTRL2, 0x00);
160 + //printf("| [5]MAX31012_MLED_CTRL2 --- ret %d |\n", ret);
161 +
162 +
163 + if (ret)
164 + printf("| MAX31012 Configuration Error! |\n");
165 +
166 + printf("+---------------------------------------------+\n");
167 +
168 +}
169 +
170 +
171 +
172 +// Heart Rate Monitor functions takes a sample value and the sample number
173 +// Returns true if a beat is detected
174 +// A running average of four samples is recommended for display on the screen.
175 +int checkForBeat(int32_t sample)
176 +{
177 + int beatDetected = 0;
178 +
179 + // Save current state
180 + IR_AC_Signal_Previous = IR_AC_Signal_Current;
181 +
182 + //This is good to view for debugging
183 + //Serial.print("Signal_Current: ");
184 + //Serial.println(IR_AC_Signal_Current);
185 +
186 + // Process next data sample
187 + IR_Average_Estimated = averageDCEstimator(&ir_avg_reg, sample);
188 + IR_AC_Signal_Current = lowPassFIRFilter(sample - IR_Average_Estimated);
189 +
190 + //printf("\n\t\t\t\t\t\t IR_AC_Signal_Previous(%d), IR_AC_Signal_Current(%d)\n", IR_AC_Signal_Previous , IR_AC_Signal_Current);
191 + // Detect positive zero crossing (rising edge)
192 + if ((IR_AC_Signal_Previous < 0) & (IR_AC_Signal_Current >= 0))
193 + {
194 +
195 + IR_AC_Max = IR_AC_Signal_max; //Adjust our AC max and min
196 + IR_AC_Min = IR_AC_Signal_min;
197 +
198 + positiveEdge = 1;
199 + negativeEdge = 0;
200 + IR_AC_Signal_max = 0;
201 +
202 +
203 + //printf("\n\t\t\t\t\t\tIR_AC_Max(%d) - IR_AC_Min(%d) : %d --------------------------------------------------------\n", IR_AC_Max, IR_AC_Max, IR_AC_Min - IR_AC_Min);
204 + //if ((IR_AC_Max - IR_AC_Min) > 20 & (IR_AC_Max - IR_AC_Min) < 1000)
205 + if ((IR_AC_Max - IR_AC_Min) > 20 & (IR_AC_Max - IR_AC_Min) < 1000)
206 + {
207 + //Heart beat!!!
208 + beatDetected = 1;
209 + }
210 + }
211 +
212 + // Detect negative zero crossing (falling edge)
213 + if ((IR_AC_Signal_Previous > 0) & (IR_AC_Signal_Current <= 0))
214 + {
215 + positiveEdge = 0;
216 + negativeEdge = 1;
217 + IR_AC_Signal_min = 0;
218 + }
219 +
220 + // Find Maximum value in positive cycle
221 + if (positiveEdge & (IR_AC_Signal_Current > IR_AC_Signal_Previous))
222 + {
223 + IR_AC_Signal_max = IR_AC_Signal_Current;
224 + }
225 +
226 + // Find Minimum value in negative cycle
227 + if (negativeEdge & (IR_AC_Signal_Current < IR_AC_Signal_Previous))
228 + {
229 + IR_AC_Signal_min = IR_AC_Signal_Current;
230 + }
231 +
232 + return(beatDetected);
233 +}
234 +
235 +// Average DC Estimator
236 +int16_t averageDCEstimator(int32_t *p, uint16_t x)
237 +{
238 + *p += ((((long) x << 15) - *p) >> 4);
239 + return (*p >> 15);
240 +}
241 +
242 +// Low Pass FIR Filter
243 +int16_t lowPassFIRFilter(int16_t din)
244 +{
245 + cbuf[offset] = din;
246 +
247 + int32_t z = mul16(FIRCoeffs[11], cbuf[(offset - 11) & 0x1F]);
248 +
249 + for (uint8_t i = 0 ; i < 11 ; i++)
250 + {
251 + z += mul16(FIRCoeffs[i], cbuf[(offset - i) & 0x1F] + cbuf[(offset - 22 + i) & 0x1F]);
252 + }
253 +
254 + offset++;
255 + offset %= 32; //Wrap condition
256 +
257 + return(z >> 15);
258 +}
259 +
260 +// Integer multiplier
261 +int32_t mul16(int16_t x, int16_t y)
262 +{
263 + return((long)x * (long)y);
264 +}
265 +
266 +
267 +/* Get FIFO from MAX30102 */
268 +void MAX30102_GetFIFO()
269 +{
270 +
271 + I2C_ReadMultiBytesOneReg(I2C0, MAX30102_ADDR, MAX30102_FIFO_DATA, au8RDataBuf, 6);
272 + hr_val = (au8RDataBuf[0]<<16)|(au8RDataBuf[1]<<8)|au8RDataBuf[2]; //RED LED
273 + spo2_val = (au8RDataBuf[3]<<16)|(au8RDataBuf[4]<<8)|au8RDataBuf[5]; //IR LED(pulse oximetry)
274 +
275 + //printf("\n+---------------------------------------------+\n");
276 + //printf("HR_val : %#08x(%d)\t \n", hr_val, hr_val);
277 + //printf("HR_val : %#08x(%d),\t Spo2_val : %#08x(%d) \r\n", hr_val, hr_val, spo2_val, spo2_val);
278 + //printf("+---------------------------------------------+\n");
279 + //CLK_SysTickDelay(300000); //300000us = 300ms = 0.3s
280 +
281 +}
282 +
283 +
284 +uint32_t MAX30102_ComputeBPM()
285 +{
286 + int i;
287 + long irValue;
288 + long delta;
289 +
290 + MAX30102_GetFIFO();
291 + irValue = (long)spo2_val;
292 +
293 + if (checkForBeat(irValue) == 1)
294 + {
295 + //printf("\nWe sensed a beat!\n");
296 + //printf("\nmillis = %d\t delta = %ld\n", millis_counter, delta);
297 +
298 + delta = (millis_counter - lastBeat) - OLED_printTime;
299 + lastBeat = millis_counter;
300 +
301 + beatsPerMinute = 60 / (delta / 1000.0);
302 +
303 + if (beatsPerMinute < 150 && beatsPerMinute > 20)
304 + {
305 + rates[rateSpot++] = (int)beatsPerMinute; //Store this reading in the array
306 + rateSpot %= RATE_SIZE; //Wrap variable
307 +
308 + //Take average of readings
309 + beatAvg = 0;
310 + for (i = 0 ; i < RATE_SIZE ; i++)
311 + beatAvg += rates[i];
312 + beatAvg /= RATE_SIZE;
313 + }
314 + }
315 +
316 + printf("\nIR = %ld\t", irValue);
317 + printf("BPM = %f\t", beatsPerMinute);
318 + printf("Avg BPM = %d\t", beatAvg);
319 +
320 + if (irValue < 50000)
321 + {
322 + printf("[No Finger]");
323 + return 0;
324 + }
325 + return 1;
326 +
327 +}
328 +
329 +
1 +/**********************************************************
2 + *
3 + * @file : MAX30102.h
4 + * @author : HaewonSeo
5 + *
6 + * @note : MAX30102-Heart-Rate Sensor
7 + **********************************************************/
8 +
9 +#ifndef __I2C_MAX30102_H__
10 +#define __I2C_MAX30102_H__
11 +
12 +#include <stdio.h>
13 +#include "M2351.h"
14 +
15 +/* MAX30102 I2C-ADDRESS */
16 +#define MAX30102_ADDR 0x57 // 8bit address converted to 7bit
17 +
18 +/* MAX30102 Register Map */
19 +#define MAX30102_INT_STATUS1 0x00 // Which interrupts are tripped
20 +#define MAX30102_INT_STATUS2 0x01 // Which interrupts are tripped
21 +#define MAX30102_INT_ENABLE1 0x02 // Which interrupts are active
22 +#define MAX30102_INT_ENABLE2 0x03 // Which interrupts are active
23 +
24 +#define MAX30102_FIFO_WR_PTR 0x04 // Where data is being written
25 +#define MAX30102_OVRFLOW_CTR 0x05 // Number of lost samples
26 +#define MAX30102_FIFO_RD_PTR 0x06 // Where to read from
27 +#define MAX30102_FIFO_DATA 0x07 // Ouput data buffer
28 +
29 +#define MAX30102_FIFO_CONFIG 0x08
30 +#define MAX30102_MODE_CONFIG 0x09 // Control register
31 +#define MAX30102_SPO2_CONFIG 0x0A // Oximetry settings
32 +#define MAX30102_LED1_AMP 0x0C
33 +#define MAX30102_LED2_AMP 0x0D
34 +#define MAX30102_PILOT 0x10
35 +#define MAX31012_MLED_CTRL1 0x11
36 +#define MAX31012_MLED_CTRL2 0x12
37 +#define MAX30102_TEMP_INTG 0x1F // Temperature value, whole number
38 +#define MAX30102_TEMP_FRAC 0x20 // Temperature value, fraction
39 +#define MAX30102_DIE_TEMP 0x21
40 +#define MAX30102_PROX_INT_TRESH 0x30
41 +#define MAX30102_REV_ID 0xFE // Part revision
42 +#define MAX30102_PART_ID 0xFF // Part ID, normally 0x11
43 +
44 +
45 +//void Get_Data_From_MAX30102();
46 +void MAX30102_Config();
47 +
48 +int checkForBeat(int32_t sample);
49 +int16_t averageDCEstimator(int32_t *p, uint16_t x);
50 +int16_t lowPassFIRFilter(int16_t din);
51 +int32_t mul16(int16_t x, int16_t y);
52 +
53 +void MAX30102_GetFIFO();
54 +uint32_t MAX30102_ComputeBPM();
55 +
56 +
57 +
58 +//extern void I2C1_Init(void);
59 +//extern int32_t I2C0_Read_Write_SLAVE(uint8_t u8SlvAddr);
60 +//extern int32_t I2C0_Read(uint8_t u8SlvAddr, uint8_t u8Reg, uint8_t u8Byte);
61 +
62 +#endif //__I2C_MAX30102_H__
63 +
64 +/*** (C) COPYRIGHT 2019 Nuvoton Technology Corp. ***/
This diff is collapsed. Click to expand it.
1 +/*
2 + * Copyright (c) 2013-2018 Arm Limited. All rights reserved.
3 + *
4 + * SPDX-License-Identifier: Apache-2.0
5 + *
6 + * Licensed under the Apache License, Version 2.0 (the License); you may
7 + * not use this file except in compliance with the License.
8 + * You may obtain a copy of the License at
9 + *
10 + * www.apache.org/licenses/LICENSE-2.0
11 + *
12 + * Unless required by applicable law or agreed to in writing, software
13 + * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14 + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 + * See the License for the specific language governing permissions and
16 + * limitations under the License.
17 + *
18 + * -----------------------------------------------------------------------------
19 + *
20 + * $Revision: V5.1.0
21 + *
22 + * Project: CMSIS-RTOS RTX
23 + * Title: RTX Configuration
24 + *
25 + * -----------------------------------------------------------------------------
26 + */
27 +
28 +#include "cmsis_compiler.h"
29 +#include "rtx_os.h"
30 +
31 +// OS Idle Thread
32 +__WEAK __NO_RETURN void osRtxIdleThread (void *argument) {
33 + (void)argument;
34 +
35 + for (;;) {}
36 +}
37 +
38 +// OS Error Callback function
39 +__WEAK uint32_t osRtxErrorNotify (uint32_t code, void *object_id) {
40 + (void)object_id;
41 +
42 + switch (code) {
43 + case osRtxErrorStackUnderflow:
44 + // Stack overflow detected for thread (thread_id=object_id)
45 + break;
46 + case osRtxErrorISRQueueOverflow:
47 + // ISR Queue overflow detected when inserting object (object_id)
48 + break;
49 + case osRtxErrorTimerQueueOverflow:
50 + // User Timer Callback Queue overflow detected for timer (timer_id=object_id)
51 + break;
52 + case osRtxErrorClibSpace:
53 + // Standard C/C++ library libspace not available: increase OS_THREAD_LIBSPACE_NUM
54 + break;
55 + case osRtxErrorClibMutex:
56 + // Standard C/C++ library mutex initialization failed
57 + break;
58 + default:
59 + // Reserved
60 + break;
61 + }
62 + for (;;) {}
63 +//return 0U;
64 +}
1 +/* -----------------------------------------------------------------------------
2 + * Copyright (c) 2019 Arm Limited (or its affiliates). All rights reserved.
3 + *
4 + * SPDX-License-Identifier: Apache-2.0
5 + *
6 + * Licensed under the Apache License, Version 2.0 (the License); you may
7 + * not use this file except in compliance with the License.
8 + * You may obtain a copy of the License at
9 + *
10 + * www.apache.org/licenses/LICENSE-2.0
11 + *
12 + * Unless required by applicable law or agreed to in writing, software
13 + * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14 + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 + * See the License for the specific language governing permissions and
16 + * limitations under the License.
17 + *
18 + *
19 + * $Date: 12. November 2019
20 + * $Revision: V1.0
21 + *
22 + * Project: ESP8266 WiFi Driver
23 + * -------------------------------------------------------------------------- */
24 +
25 +//-------- <<< Use Configuration Wizard in Context Menu >>> --------------------
26 +
27 +// <h>ESP8266 WiFi Driver Configuration
28 +
29 +// <o> WiFi Driver Number (Driver_WiFi#) <0-255>
30 +// <i> Defines exported WiFi driver control block number (Driver_WiFi#)
31 +// <i> Default: 0
32 +#define WIFI_ESP8266_DRIVER_NUMBER 0
33 +
34 +// <o>Connect to hardware via Driver_USART# <0-255>
35 +// <i>Defines the serial driver control block number (Driver_USART#)
36 +// <i> Default: 0
37 +#define WIFI_ESP8266_SERIAL_DRIVER 0
38 +
39 +// <o> Serial interface baudrate <115200=>115200
40 +// <230400=>230400
41 +// <460800=>460800
42 +// <921600=>921600
43 +// <i> Defines the serial interface baudrate.
44 +// <i> Default: 115200
45 +#define WIFI_ESP8266_SERIAL_BAUDRATE 115200
46 +
47 +// <o> WiFi thread priority <0=>osPriorityLow
48 +// <1=>osPriorityBelowNormal
49 +// <2=>osPriorityNormal
50 +// <3=>osPriorityAboveNormal
51 +// <4=>osPriorityHigh
52 +// <5=>osPriorityRealtime
53 +// <i> Defines the WiFi driver thread priority.
54 +// <i> The priority of the WiFi thread should be higher as application thread priority.
55 +// <i> Default: 3
56 +#define WIFI_ESP8266_THREAD_PRIORITY 3
57 +
58 +// <o> WiFi thread stack size [bytes] <96-1073741824:8>
59 +// <i> Defines stack size for the WiFi Thread.
60 +// <i> Default: 512
61 +#define WIFI_ESP8266_THREAD_STACK_SIZE 512
62 +
63 +// <o> Socket buffer block size <128-16384:128>
64 +// <i> Defines the size of one memory block used for socket data buffering.
65 +// <i> Socket buffering consists of multiple blocks which are distributed across multiple sockets.
66 +// <i> Default: 512
67 +#define WIFI_ESP8266_SOCKET_BLOCK_SIZE 512
68 +
69 +// <o> Socket buffer block count <5-256>
70 +// <i> Defines the total number of memory blocks used for socket data buffering.
71 +// <i> Socket buffering consists of multiple blocks which are distributed across multiple sockets.
72 +// <i> Default: 8
73 +#define WIFI_ESP8266_SOCKET_BLOCK_COUNT 8
74 +
75 +// <o> Serial parser buffer block size
76 +// <i> Defines the size of one memory block in serial parser buffer.
77 +// <i> The total size of serial parser buffer is defined by memory block size and number of blocks.
78 +// <i> Default: 256
79 +#define WIFI_ESP8266_PARSER_BLOCK_SIZE 256
80 +
81 +// <o> Serial parser buffer block count
82 +// <i> Defines the number of memory blocks in serial parser buffer.
83 +// <i> The total size of serial parser buffer is defined by memory block size and number of blocks.
84 +// <i> Default: 8
85 +#define WIFI_ESP8266_PARSER_BLOCK_COUNT 8
86 +
87 +// </h>
88 +
89 +//------------- <<< end of configuration section >>> -------------------------
1 +/*------------------------------------------------------------------------------
2 + * MDK Middleware - Component ::Network
3 + * Copyright (c) 2004-2019 Arm Limited (or its affiliates). All rights reserved.
4 + *------------------------------------------------------------------------------
5 + * Name: Net_Config.c
6 + * Purpose: Network Configuration
7 + * Rev.: V7.1.0
8 + *----------------------------------------------------------------------------*/
9 +
10 +//-------- <<< Use Configuration Wizard in Context Menu >>> --------------------
11 +
12 +// <h>Network System Settings
13 +// <i>Global Network System definitions
14 +// <s.15>Local Host Name
15 +// <i>This is the name under which embedded host can be
16 +// <i>accessed on a local area network.
17 +// <i>Default: "my_host"
18 +#define NET_HOST_NAME "my_host"
19 +
20 +// <o>Memory Pool Size <1536-262144:4>
21 +// <i>This is the size of a memory pool in bytes. Buffers for
22 +// <i>network packets are allocated from this memory pool.
23 +// <i>Default: 12000 bytes
24 +#define NET_MEM_POOL_SIZE 12000
25 +
26 +// <q>Start System Services
27 +// <i>If enabled, the system will automatically start server services
28 +// <i>(HTTP, FTP, TFTP server, ...) when initializing the network system.
29 +// <i>Default: Enabled
30 +#define NET_START_SERVICE 1
31 +
32 +// <h>OS Resource Settings
33 +// <i>These settings are used to optimize usage of OS resources.
34 +// <o>Core Thread Stack Size <512-65535:4>
35 +// <i>Default: 1024 bytes
36 +#define NET_THREAD_STACK_SIZE 1024
37 +
38 +// Core Thread Priority
39 +#define NET_THREAD_PRIORITY osPriorityNormal
40 +
41 +// </h>
42 +// </h>
43 +
44 +//------------- <<< end of configuration section >>> ---------------------------
45 +
46 +#include "RTE_Components.h"
47 +
48 +#ifdef RTE_Network_Interface_ETH_0
49 +#include "Net_Config_ETH_0.h"
50 +#endif
51 +#ifdef RTE_Network_Interface_ETH_1
52 +#include "Net_Config_ETH_1.h"
53 +#endif
54 +
55 +#ifdef RTE_Network_Interface_WiFi_0
56 +#include "Net_Config_WiFi_0.h"
57 +#endif
58 +
59 +#ifdef RTE_Network_Interface_WiFi_1
60 +#include "Net_Config_WiFi_1.h"
61 +#endif
62 +
63 +#ifdef RTE_Network_Interface_PPP
64 +#include "Net_Config_PPP.h"
65 +#endif
66 +
67 +#ifdef RTE_Network_Interface_SLIP
68 +#include "Net_Config_SLIP.h"
69 +#endif
70 +
71 +#ifdef RTE_Network_Socket_UDP
72 +#include "Net_Config_UDP.h"
73 +#endif
74 +#ifdef RTE_Network_Socket_TCP
75 +#include "Net_Config_TCP.h"
76 +#endif
77 +#ifdef RTE_Network_Socket_BSD
78 +#include "Net_Config_BSD.h"
79 +#endif
80 +
81 +#ifdef RTE_Network_Web_Server_RO
82 +#include "Net_Config_HTTP_Server.h"
83 +#endif
84 +#ifdef RTE_Network_Web_Server_FS
85 +#include "Net_Config_HTTP_Server.h"
86 +#endif
87 +
88 +#ifdef RTE_Network_Telnet_Server
89 +#include "Net_Config_Telnet_Server.h"
90 +#endif
91 +
92 +#ifdef RTE_Network_TFTP_Server
93 +#include "Net_Config_TFTP_Server.h"
94 +#endif
95 +#ifdef RTE_Network_TFTP_Client
96 +#include "Net_Config_TFTP_Client.h"
97 +#endif
98 +
99 +#ifdef RTE_Network_FTP_Server
100 +#include "Net_Config_FTP_Server.h"
101 +#endif
102 +#ifdef RTE_Network_FTP_Client
103 +#include "Net_Config_FTP_Client.h"
104 +#endif
105 +
106 +#ifdef RTE_Network_DNS_Client
107 +#include "Net_Config_DNS_Client.h"
108 +#endif
109 +
110 +#ifdef RTE_Network_SMTP_Client
111 +#include "Net_Config_SMTP_Client.h"
112 +#endif
113 +
114 +#ifdef RTE_Network_SNMP_Agent
115 +#include "Net_Config_SNMP_Agent.h"
116 +#endif
117 +
118 +#ifdef RTE_Network_SNTP_Client
119 +#include "Net_Config_SNTP_Client.h"
120 +#endif
121 +
122 +#include "net_config.h"
123 +
124 +/**
125 +\addtogroup net_genFunc
126 +@{
127 +*/
128 +/**
129 + \fn void net_sys_error (NET_ERROR error)
130 + \ingroup net_cores
131 + \brief Network system error handler.
132 +*/
133 +void net_sys_error (NET_ERROR error) {
134 + /* This function is called when a fatal error is encountered. */
135 + /* The normal program execution is not possible anymore. */
136 +
137 + switch (error) {
138 + case NET_ERROR_MEM_ALLOC:
139 + /* Out of memory */
140 + break;
141 +
142 + case NET_ERROR_MEM_FREE:
143 + /* Trying to release non existing memory block */
144 + break;
145 +
146 + case NET_ERROR_MEM_CORRUPT:
147 + /* Memory Link pointer corrupted */
148 + /* More data written than the size of allocated memory block */
149 + break;
150 +
151 + case NET_ERROR_CONFIG:
152 + /* Network configuration error detected */
153 + break;
154 +
155 + case NET_ERROR_UDP_ALLOC:
156 + /* Out of UDP Sockets */
157 + break;
158 +
159 + case NET_ERROR_TCP_ALLOC:
160 + /* Out of TCP Sockets */
161 + break;
162 +
163 + case NET_ERROR_TCP_STATE:
164 + /* TCP State machine in undefined state */
165 + break;
166 + }
167 +
168 + /* End-less loop */
169 + while (1);
170 +}
171 +/**
172 +@}
173 +*/
1 +/*------------------------------------------------------------------------------
2 + * MDK Middleware - Component ::Network:Socket
3 + * Copyright (c) 2004-2019 Arm Limited (or its affiliates). All rights reserved.
4 + *------------------------------------------------------------------------------
5 + * Name: Net_Config_TCP.h
6 + * Purpose: Network Configuration for TCP Sockets
7 + * Rev.: V7.1.1
8 + *----------------------------------------------------------------------------*/
9 +
10 +//-------- <<< Use Configuration Wizard in Context Menu >>> --------------------
11 +
12 +// <h>TCP Sockets
13 +#define TCP_ENABLE 1
14 +
15 +// <o>Number of TCP Sockets <1-20>
16 +// <i>Number of available TCP sockets
17 +// <i>Default: 6
18 +#define TCP_NUM_SOCKS 6
19 +
20 +// <o>Number of Retries <0-20>
21 +// <i>How many times TCP module will try to retransmit data
22 +// <i>before giving up. Increase this value for high-latency
23 +// <i>and low throughput networks.
24 +// <i>Default: 5
25 +#define TCP_MAX_RETRY 5
26 +
27 +// <o>Retry Timeout in seconds <1-10>
28 +// <i>If data frame not acknowledged within this time frame,
29 +// <i>TCP module will try to resend the data again.
30 +// <i>Default: 4
31 +#define TCP_RETRY_TOUT 4
32 +
33 +// <o>Default Connect Timeout in seconds <1-65535>
34 +// <i>If no TCP data frame has been exchanged during this time,
35 +// <i>the TCP connection is either closed or a keep-alive frame
36 +// <i>is sent to verify that the connection still exists.
37 +// <i>Default: 120
38 +#define TCP_DEFAULT_TOUT 120
39 +
40 +// <o>Maximum Segment Size <536-1440>
41 +// <i>The Maximum Segment Size specifies the maximum
42 +// <i>number of bytes in the TCP segment's Data field.
43 +// <i>Default: 1440
44 +#define TCP_MAX_SEG_SIZE 1440
45 +
46 +// <o>Receive Window Size <536-65535>
47 +// <i>Receive Window Size specifies the size of data,
48 +// <i>that the socket is able to buffer in flow-control mode.
49 +// <i>Default: 4320
50 +#define TCP_RECEIVE_WIN_SIZE 4320
51 +
52 +// </h>
53 +
54 +// TCP Initial Retransmit period in seconds
55 +#define TCP_INITIAL_RETRY_TOUT 1
56 +
57 +// TCP SYN frame retransmit period in seconds
58 +#define TCP_SYN_RETRY_TOUT 2
59 +
60 +// Number of retries to establish a connection
61 +#define TCP_CONNECT_RETRY 7
62 +
63 +// Dynamic port start (default 49152)
64 +#define TCP_DYN_PORT_START 49152
65 +
66 +// Dynamic port end (default 65535)
67 +#define TCP_DYN_PORT_END 65535
68 +
69 +//------------- <<< end of configuration section >>> ---------------------------
1 +/*------------------------------------------------------------------------------
2 + * MDK Middleware - Component ::Network:Interface
3 + * Copyright (c) 2004-2020 Arm Limited (or its affiliates). All rights reserved.
4 + *------------------------------------------------------------------------------
5 + * Name: Net_Config_WiFi_0.h
6 + * Purpose: Network Configuration for WiFi Interface
7 + * Rev.: V7.1.0
8 + *----------------------------------------------------------------------------*/
9 +
10 +//-------- <<< Use Configuration Wizard in Context Menu >>> --------------------
11 +
12 +// <h>WiFi Network Interface
13 +#define WIFI0_ENABLE 1
14 +
15 +// <o>Connect to hardware via Driver_WiFi# <0-255>
16 +// <i>Select driver control block for WiFi interface
17 +#define WIFI0_DRIVER 0
18 +
19 +// <o>WiFi Mode <0=>Station
20 +// <1=>Access Point
21 +// <i>Mode control setting for the WiFi driver
22 +#define WIFI0_MODE 0
23 +
24 +// <e>WiFi MAC
25 +// <i>If this option is enabled, a configured MAC address
26 +// <i>will be used. If disabled, MAC address provided in
27 +// <i>the WiFi module will be used.
28 +// <i>Default: disabled
29 +#define WIFI0_MAC_CONFIG 0
30 +
31 +// <s.17>MAC Address
32 +// <i>MAC Address in text representation
33 +// <i>Value FF-FF-FF-FF-FF-FF is not allowed,
34 +// <i>LSB of first byte must be 0 (Multicast bit).
35 +// <i>Default: "1E-30-6C-32-78-F8"
36 +#define WIFI0_MAC_ADDR "1E-30-6C-32-78-F8"
37 +// </e>
38 +
39 +// <e>IPv4
40 +// <i>Enable IPv4 Protocol for Network Interface
41 +#define WIFI0_IP4_ENABLE 1
42 +
43 +// <s.15>IP Address
44 +// <i>Static IPv4 Address in text representation
45 +// <i>Default: "192.168.1.100"
46 +#define WIFI0_IP4_ADDR "192.168.1.100"
47 +
48 +// <s.15>Subnet mask
49 +// <i>Local Subnet mask in text representation
50 +// <i>Default: "255.255.255.0"
51 +#define WIFI0_IP4_MASK "255.255.255.0"
52 +
53 +// <s.15>Default Gateway
54 +// <i>IP Address of Default Gateway in text representation
55 +// <i>Default: "192.168.1.254"
56 +#define WIFI0_IP4_GATEWAY "192.168.1.254"
57 +
58 +// <s.15>Primary DNS Server
59 +// <i>IP Address of Primary DNS Server in text representation
60 +// <i>Default: "8.8.8.8"
61 +#define WIFI0_IP4_PRIMARY_DNS "8.8.8.8"
62 +
63 +// <s.15>Secondary DNS Server
64 +// <i>IP Address of Secondary DNS Server in text representation
65 +// <i>Default: "8.8.4.4"
66 +#define WIFI0_IP4_SECONDARY_DNS "8.8.4.4"
67 +
68 +// <e>IP Fragmentation
69 +// <i>This option enables fragmentation of outgoing IP datagrams,
70 +// <i>and reassembling the fragments of incoming IP datagrams.
71 +// <i>Default: enabled
72 +#define WIFI0_IP4_FRAG_ENABLE 1
73 +
74 +// <o>MTU size <576-1500>
75 +// <i>Maximum Transmission Unit in bytes
76 +// <i>Default: 1500
77 +#define WIFI0_IP4_MTU 1500
78 +// </e>
79 +
80 +// <h>ARP Address Resolution
81 +// <i>ARP cache and node address resolver settings
82 +// <o>Cache Table size <5-100>
83 +// <i>Number of cached MAC/IP addresses
84 +// <i>Default: 10
85 +#define WIFI0_ARP_TAB_SIZE 10
86 +
87 +// <o>Cache Timeout in seconds <5-255>
88 +// <i>A timeout for cached hardware/IP addresses
89 +// <i>Default: 150
90 +#define WIFI0_ARP_CACHE_TOUT 150
91 +
92 +// <o>Number of Retries <0-20>
93 +// <i>Number of Retries to resolve an IP address
94 +// <i>before ARP module gives up
95 +// <i>Default: 4
96 +#define WIFI0_ARP_MAX_RETRY 4
97 +
98 +// <o>Resend Timeout in seconds <1-10>
99 +// <i>A timeout to resend the ARP Request
100 +// <i>Default: 2
101 +#define WIFI0_ARP_RESEND_TOUT 2
102 +
103 +// <q>Send Notification on Address changes
104 +// <i>When this option is enabled, the embedded host
105 +// <i>will send a Gratuitous ARP notification at startup,
106 +// <i>or when the device IP address has changed.
107 +// <i>Default: Disabled
108 +#define WIFI0_ARP_NOTIFY 0
109 +// </h>
110 +
111 +// <e>IGMP Group Management
112 +// <i>Enable or disable Internet Group Management Protocol
113 +#define WIFI0_IGMP_ENABLE 0
114 +
115 +// <o>Membership Table size <2-50>
116 +// <i>Number of Groups this host can join
117 +// <i>Default: 5
118 +#define WIFI0_IGMP_TAB_SIZE 5
119 +// </e>
120 +
121 +// <q>NetBIOS Name Service
122 +// <i>When this option is enabled, the embedded host can be
123 +// <i>accessed by its name on local LAN using NBNS protocol.
124 +#define WIFI0_NBNS_ENABLE 1
125 +
126 +// <e>Dynamic Host Configuration
127 +// <i>When this option is enabled, local IP address, Net Mask
128 +// <i>and Default Gateway are obtained automatically from
129 +// <i>the DHCP Server on local LAN.
130 +#define WIFI0_DHCP_ENABLE 1
131 +
132 +// <s.40>Vendor Class Identifier
133 +// <i>This value is optional. If specified, it is added
134 +// <i>to DHCP request message, identifying vendor type.
135 +// <i>Default: ""
136 +#define WIFI0_DHCP_VCID ""
137 +
138 +// <q>Bootfile Name
139 +// <i>This value is optional. If enabled, the Bootfile Name
140 +// <i>(option 67) is also requested from DHCP server.
141 +// <i>Default: disabled
142 +#define WIFI0_DHCP_BOOTFILE 0
143 +
144 +// <q>NTP Servers
145 +// <i>This value is optional. If enabled, a list of NTP Servers
146 +// <i>(option 42) is also requested from DHCP server.
147 +// <i>Default: disabled
148 +#define WIFI0_DHCP_NTP_SERVERS 0
149 +// </e>
150 +
151 +// Disable ICMP Echo response
152 +#define WIFI0_ICMP_NO_ECHO 0
153 +// </e>
154 +
155 +// <e>IPv6
156 +// <i>Enable IPv6 Protocol for Network Interface
157 +#define WIFI0_IP6_ENABLE 1
158 +
159 +// <s.40>IPv6 Address
160 +// <i>Static IPv6 Address in text representation
161 +// <i>Use unspecified address "::" when static
162 +// <i>IPv6 address is not used.
163 +// <i>Default: "fec0::2"
164 +#define WIFI0_IP6_ADDR "fec0::2"
165 +
166 +// <o>Subnet prefix-length <1-128>
167 +// <i>Number of bits that define network address
168 +// <i>Default: 64
169 +#define WIFI0_IP6_PREFIX_LEN 64
170 +
171 +// <s.40>Default Gateway
172 +// <i>Default Gateway IPv6 Address in text representation
173 +// <i>Default: "fec0::1"
174 +#define WIFI0_IP6_GATEWAY "fec0::1"
175 +
176 +// <s.40>Primary DNS Server
177 +// <i>Primary DNS Server IPv6 Address in text representation
178 +// <i>Default: "2001:4860:4860::8888"
179 +#define WIFI0_IP6_PRIMARY_DNS "2001:4860:4860::8888"
180 +
181 +// <s.40>Secondary DNS Server
182 +// <i>Secondary DNS Server IPv6 Address in text representation
183 +// <i>Default: "2001:4860:4860::8844"
184 +#define WIFI0_IP6_SECONDARY_DNS "2001:4860:4860::8844"
185 +
186 +// <h>Neighbor Discovery
187 +// <i>Neighbor cache and node address resolver settings
188 +// <o>Cache Table size <5-100>
189 +// <i>Number of cached node addresses
190 +// <i>Default: 5
191 +#define WIFI0_NDP_TAB_SIZE 5
192 +
193 +// <o>Cache Timeout in seconds <5-255>
194 +// <i>Timeout for cached node addresses
195 +// <i>Default: 150
196 +#define WIFI0_NDP_CACHE_TOUT 150
197 +
198 +// <o>Number of Retries <0-20>
199 +// <i>Number of retries to resolve an IP address
200 +// <i>before NDP module gives up
201 +// <i>Default: 4
202 +#define WIFI0_NDP_MAX_RETRY 4
203 +
204 +// <o>Resend Timeout in seconds <1-10>
205 +// <i>A timeout to resend Neighbor Solicitation
206 +// <i>Default: 2
207 +#define WIFI0_NDP_RESEND_TOUT 2
208 +// </h>
209 +
210 +// <e>Dynamic Host Configuration
211 +// <i>When this option is enabled, local IPv6 address is
212 +// <i>automatically configured.
213 +#define WIFI0_DHCP6_ENABLE 1
214 +
215 +// <o>DHCPv6 Client Mode <0=>Stateless Mode <1=>Statefull Mode
216 +// <i>Stateless DHCPv6 Client uses router advertisements
217 +// <i>for IPv6 address autoconfiguration (SLAAC).
218 +// <i>Statefull DHCPv6 Client connects to DHCPv6 server for a
219 +// <i>leased IPv6 address and DNS server IPv6 addresses.
220 +#define WIFI0_DHCP6_MODE 1
221 +
222 +// <e>Vendor Class Option
223 +// <i>If enabled, Vendor Class option is added to DHCPv6
224 +// <i>request message, identifying vendor type.
225 +// <i>Default: disabled
226 +#define WIFI0_DHCP6_VCLASS_ENABLE 0
227 +
228 +// <o>Enterprise ID
229 +// <i>Enterprise-number as registered with IANA.
230 +// <i>Default: 0 (Reserved)
231 +#define WIFI0_DHCP6_VCLASS_EID 0
232 +
233 +// <s.40>Vendor Class Data
234 +// <i>This string identifies vendor type.
235 +// <i>Default: ""
236 +#define WIFI0_DHCP6_VCLASS_DATA ""
237 +// </e>
238 +// </e>
239 +
240 +// Disable ICMP6 Echo response
241 +#define WIFI0_ICMP6_NO_ECHO 0
242 +// </e>
243 +
244 +// <h>OS Resource Settings
245 +// <i>These settings are used to optimize usage of OS resources.
246 +// <o>Interface Thread Stack Size <512-65535:4>
247 +// <i>Default: 512 bytes
248 +#define WIFI0_THREAD_STACK_SIZE 512
249 +
250 +// Interface Thread Priority
251 +#define WIFI0_THREAD_PRIORITY osPriorityAboveNormal
252 +
253 +// </h>
254 +// </h>
255 +
256 +//------------- <<< end of configuration section >>> ---------------------------
1 +/*
2 + * Configuration template
3 + *
4 + * Copyright (C) 2006-2021, Arm Limited, All Rights Reserved
5 + * SPDX-License-Identifier: Apache-2.0
6 + *
7 + * Licensed under the Apache License, Version 2.0 (the "License"); you may
8 + * not use this file except in compliance with the License.
9 + * You may obtain a copy of the License at
10 + *
11 + * http://www.apache.org/licenses/LICENSE-2.0
12 + *
13 + * Unless required by applicable law or agreed to in writing, software
14 + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 + * See the License for the specific language governing permissions and
17 + * limitations under the License.
18 + */
19 +/*
20 + * This set of compile-time options may be used to enable
21 + * or disable features selectively, and reduce the global
22 + * memory footprint.
23 + */
24 +
25 +#ifndef MBEDTLS_CONFIG_H
26 +#define MBEDTLS_CONFIG_H
27 +
28 +/* System support */
29 +//#define MBEDTLS_HAVE_ASM
30 +//#define MBEDTLS_HAVE_TIME
31 +//#define MBEDTLS_HAVE_TIME_DATE
32 +//#define MBEDTLS_PLATFORM_MEMORY
33 +//#define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
34 +//#define MBEDTLS_CHECK_PARAMS
35 +
36 +/* mbed TLS feature support */
37 +#define MBEDTLS_ENTROPY_HARDWARE_ALT
38 +#define MBEDTLS_AES_ROM_TABLES
39 +//#define MBEDTLS_AES_FEWER_TABLES
40 +//#define MBEDTLS_CAMELLIA_SMALL_MEMORY
41 +#define MBEDTLS_CIPHER_MODE_CBC
42 +#define MBEDTLS_CIPHER_MODE_CFB
43 +#define MBEDTLS_CIPHER_MODE_CTR
44 +//#define MBEDTLS_CIPHER_MODE_OFB
45 +//#define MBEDTLS_CIPHER_MODE_XTS
46 +#define MBEDTLS_CIPHER_PADDING_PKCS7
47 +#define MBEDTLS_CIPHER_PADDING_ONE_AND_ZEROS
48 +#define MBEDTLS_CIPHER_PADDING_ZEROS_AND_LEN
49 +#define MBEDTLS_CIPHER_PADDING_ZEROS
50 +#define MBEDTLS_REMOVE_ARC4_CIPHERSUITES
51 +#define MBEDTLS_REMOVE_3DES_CIPHERSUITES
52 +#define MBEDTLS_ECP_DP_SECP192R1_ENABLED
53 +#define MBEDTLS_ECP_DP_SECP224R1_ENABLED
54 +#define MBEDTLS_ECP_DP_SECP256R1_ENABLED
55 +#define MBEDTLS_ECP_DP_SECP384R1_ENABLED
56 +#define MBEDTLS_ECP_DP_SECP521R1_ENABLED
57 +#define MBEDTLS_ECP_DP_SECP192K1_ENABLED
58 +#define MBEDTLS_ECP_DP_SECP224K1_ENABLED
59 +#define MBEDTLS_ECP_DP_SECP256K1_ENABLED
60 +#define MBEDTLS_ECP_DP_BP256R1_ENABLED
61 +#define MBEDTLS_ECP_DP_BP384R1_ENABLED
62 +#define MBEDTLS_ECP_DP_BP512R1_ENABLED
63 +#define MBEDTLS_ECP_DP_CURVE25519_ENABLED
64 +#define MBEDTLS_ECP_DP_CURVE448_ENABLED
65 +#define MBEDTLS_ECP_NIST_OPTIM
66 +//#define MBEDTLS_ECP_RESTARTABLE
67 +#define MBEDTLS_ECDSA_DETERMINISTIC
68 +#define MBEDTLS_KEY_EXCHANGE_PSK_ENABLED
69 +#define MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
70 +#define MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
71 +#define MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
72 +#define MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
73 +#define MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
74 +#define MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
75 +#define MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
76 +#define MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
77 +#define MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
78 +//#define MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
79 +#define MBEDTLS_PK_PARSE_EC_EXTENDED
80 +#define MBEDTLS_ERROR_STRERROR_DUMMY
81 +#define MBEDTLS_GENPRIME
82 +//#define MBEDTLS_FS_IO
83 +//#define MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
84 +#define MBEDTLS_NO_PLATFORM_ENTROPY
85 +//#define MBEDTLS_ENTROPY_FORCE_SHA256
86 +//#define MBEDTLS_ENTROPY_NV_SEED
87 +//#define MBEDTLS_MEMORY_DEBUG
88 +//#define MBEDTLS_MEMORY_BACKTRACE
89 +#define MBEDTLS_PK_RSA_ALT_SUPPORT
90 +#define MBEDTLS_PKCS1_V15
91 +#define MBEDTLS_PKCS1_V21
92 +//#define MBEDTLS_PSA_CRYPTO_SPM
93 +//#define MBEDTLS_RSA_NO_CRT
94 +#define MBEDTLS_SELF_TEST
95 +//#define MBEDTLS_SHA256_SMALLER
96 +//#define MBEDTLS_SHA512_SMALLER
97 +//#define MBEDTLS_SHA512_NO_SHA384
98 +#define MBEDTLS_SSL_ALL_ALERT_MESSAGES
99 +//#define MBEDTLS_SSL_RECORD_CHECKING
100 +//#define MBEDTLS_SSL_DTLS_CONNECTION_ID
101 +//#define MBEDTLS_SSL_ASYNC_PRIVATE
102 +//#define MBEDTLS_SSL_CONTEXT_SERIALIZATION
103 +//#define MBEDTLS_SSL_DEBUG_ALL
104 +#define MBEDTLS_SSL_ENCRYPT_THEN_MAC
105 +#define MBEDTLS_SSL_EXTENDED_MASTER_SECRET
106 +#define MBEDTLS_SSL_FALLBACK_SCSV
107 +//#define MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
108 +//#define MBEDTLS_SSL_HW_RECORD_ACCEL
109 +#define MBEDTLS_SSL_CBC_RECORD_SPLITTING
110 +#define MBEDTLS_SSL_RENEGOTIATION
111 +//#define MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO
112 +//#define MBEDTLS_SSL_SRV_RESPECT_CLIENT_PREFERENCE
113 +#define MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
114 +#define MBEDTLS_SSL_PROTO_SSL3
115 +#define MBEDTLS_SSL_PROTO_TLS1
116 +#define MBEDTLS_SSL_PROTO_TLS1_1
117 +#define MBEDTLS_SSL_PROTO_TLS1_2
118 +#define MBEDTLS_SSL_PROTO_DTLS
119 +#define MBEDTLS_SSL_ALPN
120 +#define MBEDTLS_SSL_DTLS_ANTI_REPLAY
121 +#define MBEDTLS_SSL_DTLS_HELLO_VERIFY
122 +#define MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE
123 +#define MBEDTLS_SSL_DTLS_BADMAC_LIMIT
124 +#define MBEDTLS_SSL_SESSION_TICKETS
125 +//#define MBEDTLS_SSL_EXPORT_KEYS
126 +#define MBEDTLS_SSL_SERVER_NAME_INDICATION
127 +#define MBEDTLS_SSL_TRUNCATED_HMAC
128 +//#define MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
129 +//#define MBEDTLS_USE_PSA_CRYPTO
130 +#define MBEDTLS_VERSION_FEATURES
131 +//#define MBEDTLS_X509_ALLOW_EXTENSIONS_NON_V3
132 +//#define MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION
133 +//#define MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
134 +#define MBEDTLS_X509_CHECK_KEY_USAGE
135 +#define MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE
136 +#define MBEDTLS_X509_RSASSA_PSS_SUPPORT
137 +//#define MBEDTLS_ZLIB_SUPPORT
138 +
139 +/* mbed TLS modules */
140 +#define MBEDTLS_AES_C
141 +#define MBEDTLS_ARC4_C
142 +#define MBEDTLS_ASN1_PARSE_C
143 +#define MBEDTLS_ASN1_WRITE_C
144 +#define MBEDTLS_BASE64_C
145 +#define MBEDTLS_BIGNUM_C
146 +#define MBEDTLS_BLOWFISH_C
147 +#define MBEDTLS_CAMELLIA_C
148 +//#define MBEDTLS_ARIA_C
149 +#define MBEDTLS_CCM_C
150 +#define MBEDTLS_CERTS_C
151 +//#define MBEDTLS_CHACHA20_C
152 +//#define MBEDTLS_CHACHAPOLY_C
153 +#define MBEDTLS_CIPHER_C
154 +//#define MBEDTLS_CMAC_C
155 +#define MBEDTLS_CTR_DRBG_C
156 +#define MBEDTLS_DEBUG_C
157 +#define MBEDTLS_DES_C
158 +#define MBEDTLS_DHM_C
159 +#define MBEDTLS_ECDH_C
160 +#define MBEDTLS_ECDSA_C
161 +//#define MBEDTLS_ECJPAKE_C
162 +#define MBEDTLS_ECP_C
163 +#define MBEDTLS_ENTROPY_C
164 +#define MBEDTLS_ERROR_C
165 +#define MBEDTLS_GCM_C
166 +//#define MBEDTLS_HAVEGE_C
167 +//#define MBEDTLS_HKDF_C
168 +#define MBEDTLS_HMAC_DRBG_C
169 +//#define MBEDTLS_NIST_KW_C
170 +#define MBEDTLS_MD_C
171 +//#define MBEDTLS_MD2_C
172 +//#define MBEDTLS_MD4_C
173 +#define MBEDTLS_MD5_C
174 +//#define MBEDTLS_MEMORY_BUFFER_ALLOC_C
175 +#define MBEDTLS_NET_C
176 +#define MBEDTLS_OID_C
177 +#define MBEDTLS_PEM_PARSE_C
178 +#define MBEDTLS_PEM_WRITE_C
179 +#define MBEDTLS_PK_C
180 +#define MBEDTLS_PK_PARSE_C
181 +#define MBEDTLS_PK_WRITE_C
182 +#define MBEDTLS_PKCS5_C
183 +//#define MBEDTLS_PKCS11_C
184 +#define MBEDTLS_PKCS12_C
185 +#define MBEDTLS_PLATFORM_C
186 +//#define MBEDTLS_POLY1305_C
187 +//#define MBEDTLS_PSA_CRYPTO_C
188 +//#define MBEDTLS_PSA_CRYPTO_SE_C
189 +//#define MBEDTLS_PSA_CRYPTO_STORAGE_C
190 +//#define MBEDTLS_PSA_ITS_FILE_C
191 +#define MBEDTLS_RIPEMD160_C
192 +#define MBEDTLS_RSA_C
193 +#define MBEDTLS_SHA1_C
194 +#define MBEDTLS_SHA256_C
195 +#define MBEDTLS_SHA512_C
196 +#define MBEDTLS_SSL_CACHE_C
197 +#define MBEDTLS_SSL_COOKIE_C
198 +#define MBEDTLS_SSL_TICKET_C
199 +#define MBEDTLS_SSL_CLI_C
200 +//#define MBEDTLS_SSL_SRV_C
201 +#define MBEDTLS_SSL_TLS_C
202 +//#define MBEDTLS_THREADING_C
203 +//#define MBEDTLS_TIMING_C
204 +#define MBEDTLS_VERSION_C
205 +#define MBEDTLS_X509_USE_C
206 +#define MBEDTLS_X509_CRT_PARSE_C
207 +#define MBEDTLS_X509_CRL_PARSE_C
208 +#define MBEDTLS_X509_CSR_PARSE_C
209 +#define MBEDTLS_X509_CREATE_C
210 +#define MBEDTLS_X509_CRT_WRITE_C
211 +#define MBEDTLS_X509_CSR_WRITE_C
212 +#define MBEDTLS_XTEA_C
213 +
214 +#include "mbedtls/check_config.h"
215 +
216 +#endif /* MBEDTLS_CONFIG_H */
1 +
2 +/*
3 + * Auto generated Run-Time-Environment Configuration File
4 + * *** Do not modify ! ***
5 + *
6 + * Project: 'Secure'
7 + * Target: 'Secure'
8 + */
9 +
10 +#ifndef RTE_COMPONENTS_H
11 +#define RTE_COMPONENTS_H
12 +
13 +
14 +/*
15 + * Define the Device Header File:
16 + */
17 +#define CMSIS_device_header "M2351.h"
18 +
19 +/* ARM::Security:mbed TLS:2.24.0 */
20 +#define RTE_Security_mbedTLS /* Security mbed TLS */
21 +
22 +
23 +#endif /* RTE_COMPONENTS_H */
This diff could not be displayed because it is too large.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
1 +/*
2 + * Configuration template
3 + *
4 + * Copyright (C) 2006-2021, Arm Limited, All Rights Reserved
5 + * SPDX-License-Identifier: Apache-2.0
6 + *
7 + * Licensed under the Apache License, Version 2.0 (the "License"); you may
8 + * not use this file except in compliance with the License.
9 + * You may obtain a copy of the License at
10 + *
11 + * http://www.apache.org/licenses/LICENSE-2.0
12 + *
13 + * Unless required by applicable law or agreed to in writing, software
14 + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 + * See the License for the specific language governing permissions and
17 + * limitations under the License.
18 + */
19 +/*
20 + * This set of compile-time options may be used to enable
21 + * or disable features selectively, and reduce the global
22 + * memory footprint.
23 + */
24 +
25 +#ifndef MBEDTLS_CONFIG_H
26 +#define MBEDTLS_CONFIG_H
27 +
28 +/* System support */
29 +//#define MBEDTLS_HAVE_ASM
30 +//#define MBEDTLS_HAVE_TIME
31 +//#define MBEDTLS_HAVE_TIME_DATE
32 +//#define MBEDTLS_PLATFORM_MEMORY
33 +//#define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
34 +//#define MBEDTLS_CHECK_PARAMS
35 +
36 +/* mbed TLS feature support */
37 +#define MBEDTLS_ENTROPY_HARDWARE_ALT
38 +#define MBEDTLS_AES_ROM_TABLES
39 +//#define MBEDTLS_AES_FEWER_TABLES
40 +//#define MBEDTLS_CAMELLIA_SMALL_MEMORY
41 +#define MBEDTLS_CIPHER_MODE_CBC
42 +#define MBEDTLS_CIPHER_MODE_CFB
43 +#define MBEDTLS_CIPHER_MODE_CTR
44 +//#define MBEDTLS_CIPHER_MODE_OFB
45 +//#define MBEDTLS_CIPHER_MODE_XTS
46 +#define MBEDTLS_CIPHER_PADDING_PKCS7
47 +#define MBEDTLS_CIPHER_PADDING_ONE_AND_ZEROS
48 +#define MBEDTLS_CIPHER_PADDING_ZEROS_AND_LEN
49 +#define MBEDTLS_CIPHER_PADDING_ZEROS
50 +#define MBEDTLS_REMOVE_ARC4_CIPHERSUITES
51 +#define MBEDTLS_REMOVE_3DES_CIPHERSUITES
52 +#define MBEDTLS_ECP_DP_SECP192R1_ENABLED
53 +#define MBEDTLS_ECP_DP_SECP224R1_ENABLED
54 +#define MBEDTLS_ECP_DP_SECP256R1_ENABLED
55 +#define MBEDTLS_ECP_DP_SECP384R1_ENABLED
56 +#define MBEDTLS_ECP_DP_SECP521R1_ENABLED
57 +#define MBEDTLS_ECP_DP_SECP192K1_ENABLED
58 +#define MBEDTLS_ECP_DP_SECP224K1_ENABLED
59 +#define MBEDTLS_ECP_DP_SECP256K1_ENABLED
60 +#define MBEDTLS_ECP_DP_BP256R1_ENABLED
61 +#define MBEDTLS_ECP_DP_BP384R1_ENABLED
62 +#define MBEDTLS_ECP_DP_BP512R1_ENABLED
63 +#define MBEDTLS_ECP_DP_CURVE25519_ENABLED
64 +#define MBEDTLS_ECP_DP_CURVE448_ENABLED
65 +#define MBEDTLS_ECP_NIST_OPTIM
66 +//#define MBEDTLS_ECP_RESTARTABLE
67 +#define MBEDTLS_ECDSA_DETERMINISTIC
68 +#define MBEDTLS_KEY_EXCHANGE_PSK_ENABLED
69 +#define MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED
70 +#define MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED
71 +#define MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED
72 +#define MBEDTLS_KEY_EXCHANGE_RSA_ENABLED
73 +#define MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED
74 +#define MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED
75 +#define MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED
76 +#define MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA_ENABLED
77 +#define MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED
78 +//#define MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED
79 +#define MBEDTLS_PK_PARSE_EC_EXTENDED
80 +#define MBEDTLS_ERROR_STRERROR_DUMMY
81 +#define MBEDTLS_GENPRIME
82 +//#define MBEDTLS_FS_IO
83 +//#define MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
84 +#define MBEDTLS_NO_PLATFORM_ENTROPY
85 +//#define MBEDTLS_ENTROPY_FORCE_SHA256
86 +//#define MBEDTLS_ENTROPY_NV_SEED
87 +//#define MBEDTLS_MEMORY_DEBUG
88 +//#define MBEDTLS_MEMORY_BACKTRACE
89 +#define MBEDTLS_PK_RSA_ALT_SUPPORT
90 +#define MBEDTLS_PKCS1_V15
91 +#define MBEDTLS_PKCS1_V21
92 +//#define MBEDTLS_PSA_CRYPTO_SPM
93 +//#define MBEDTLS_RSA_NO_CRT
94 +#define MBEDTLS_SELF_TEST
95 +//#define MBEDTLS_SHA256_SMALLER
96 +//#define MBEDTLS_SHA512_SMALLER
97 +//#define MBEDTLS_SHA512_NO_SHA384
98 +#define MBEDTLS_SSL_ALL_ALERT_MESSAGES
99 +//#define MBEDTLS_SSL_RECORD_CHECKING
100 +//#define MBEDTLS_SSL_DTLS_CONNECTION_ID
101 +//#define MBEDTLS_SSL_ASYNC_PRIVATE
102 +//#define MBEDTLS_SSL_CONTEXT_SERIALIZATION
103 +//#define MBEDTLS_SSL_DEBUG_ALL
104 +#define MBEDTLS_SSL_ENCRYPT_THEN_MAC
105 +#define MBEDTLS_SSL_EXTENDED_MASTER_SECRET
106 +#define MBEDTLS_SSL_FALLBACK_SCSV
107 +//#define MBEDTLS_SSL_KEEP_PEER_CERTIFICATE
108 +//#define MBEDTLS_SSL_HW_RECORD_ACCEL
109 +#define MBEDTLS_SSL_CBC_RECORD_SPLITTING
110 +#define MBEDTLS_SSL_RENEGOTIATION
111 +//#define MBEDTLS_SSL_SRV_SUPPORT_SSLV2_CLIENT_HELLO
112 +//#define MBEDTLS_SSL_SRV_RESPECT_CLIENT_PREFERENCE
113 +#define MBEDTLS_SSL_MAX_FRAGMENT_LENGTH
114 +#define MBEDTLS_SSL_PROTO_SSL3
115 +#define MBEDTLS_SSL_PROTO_TLS1
116 +#define MBEDTLS_SSL_PROTO_TLS1_1
117 +#define MBEDTLS_SSL_PROTO_TLS1_2
118 +#define MBEDTLS_SSL_PROTO_DTLS
119 +#define MBEDTLS_SSL_ALPN
120 +#define MBEDTLS_SSL_DTLS_ANTI_REPLAY
121 +#define MBEDTLS_SSL_DTLS_HELLO_VERIFY
122 +#define MBEDTLS_SSL_DTLS_CLIENT_PORT_REUSE
123 +#define MBEDTLS_SSL_DTLS_BADMAC_LIMIT
124 +#define MBEDTLS_SSL_SESSION_TICKETS
125 +//#define MBEDTLS_SSL_EXPORT_KEYS
126 +#define MBEDTLS_SSL_SERVER_NAME_INDICATION
127 +#define MBEDTLS_SSL_TRUNCATED_HMAC
128 +//#define MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH
129 +//#define MBEDTLS_USE_PSA_CRYPTO
130 +#define MBEDTLS_VERSION_FEATURES
131 +//#define MBEDTLS_X509_ALLOW_EXTENSIONS_NON_V3
132 +//#define MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION
133 +//#define MBEDTLS_X509_TRUSTED_CERTIFICATE_CALLBACK
134 +#define MBEDTLS_X509_CHECK_KEY_USAGE
135 +#define MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE
136 +#define MBEDTLS_X509_RSASSA_PSS_SUPPORT
137 +//#define MBEDTLS_ZLIB_SUPPORT
138 +
139 +/* mbed TLS modules */
140 +#define MBEDTLS_AES_C
141 +#define MBEDTLS_ARC4_C
142 +#define MBEDTLS_ASN1_PARSE_C
143 +#define MBEDTLS_ASN1_WRITE_C
144 +#define MBEDTLS_BASE64_C
145 +#define MBEDTLS_BIGNUM_C
146 +#define MBEDTLS_BLOWFISH_C
147 +#define MBEDTLS_CAMELLIA_C
148 +//#define MBEDTLS_ARIA_C
149 +#define MBEDTLS_CCM_C
150 +#define MBEDTLS_CERTS_C
151 +//#define MBEDTLS_CHACHA20_C
152 +//#define MBEDTLS_CHACHAPOLY_C
153 +#define MBEDTLS_CIPHER_C
154 +//#define MBEDTLS_CMAC_C
155 +#define MBEDTLS_CTR_DRBG_C
156 +#define MBEDTLS_DEBUG_C
157 +#define MBEDTLS_DES_C
158 +#define MBEDTLS_DHM_C
159 +#define MBEDTLS_ECDH_C
160 +#define MBEDTLS_ECDSA_C
161 +//#define MBEDTLS_ECJPAKE_C
162 +#define MBEDTLS_ECP_C
163 +#define MBEDTLS_ENTROPY_C
164 +#define MBEDTLS_ERROR_C
165 +#define MBEDTLS_GCM_C
166 +//#define MBEDTLS_HAVEGE_C
167 +//#define MBEDTLS_HKDF_C
168 +#define MBEDTLS_HMAC_DRBG_C
169 +//#define MBEDTLS_NIST_KW_C
170 +#define MBEDTLS_MD_C
171 +//#define MBEDTLS_MD2_C
172 +//#define MBEDTLS_MD4_C
173 +#define MBEDTLS_MD5_C
174 +//#define MBEDTLS_MEMORY_BUFFER_ALLOC_C
175 +#define MBEDTLS_NET_C
176 +#define MBEDTLS_OID_C
177 +#define MBEDTLS_PEM_PARSE_C
178 +#define MBEDTLS_PEM_WRITE_C
179 +#define MBEDTLS_PK_C
180 +#define MBEDTLS_PK_PARSE_C
181 +#define MBEDTLS_PK_WRITE_C
182 +#define MBEDTLS_PKCS5_C
183 +//#define MBEDTLS_PKCS11_C
184 +#define MBEDTLS_PKCS12_C
185 +#define MBEDTLS_PLATFORM_C
186 +//#define MBEDTLS_POLY1305_C
187 +//#define MBEDTLS_PSA_CRYPTO_C
188 +//#define MBEDTLS_PSA_CRYPTO_SE_C
189 +//#define MBEDTLS_PSA_CRYPTO_STORAGE_C
190 +//#define MBEDTLS_PSA_ITS_FILE_C
191 +#define MBEDTLS_RIPEMD160_C
192 +#define MBEDTLS_RSA_C
193 +#define MBEDTLS_SHA1_C
194 +#define MBEDTLS_SHA256_C
195 +#define MBEDTLS_SHA512_C
196 +#define MBEDTLS_SSL_CACHE_C
197 +#define MBEDTLS_SSL_COOKIE_C
198 +#define MBEDTLS_SSL_TICKET_C
199 +#define MBEDTLS_SSL_CLI_C
200 +//#define MBEDTLS_SSL_SRV_C
201 +#define MBEDTLS_SSL_TLS_C
202 +//#define MBEDTLS_THREADING_C
203 +//#define MBEDTLS_TIMING_C
204 +#define MBEDTLS_VERSION_C
205 +#define MBEDTLS_X509_USE_C
206 +#define MBEDTLS_X509_CRT_PARSE_C
207 +#define MBEDTLS_X509_CRL_PARSE_C
208 +#define MBEDTLS_X509_CSR_PARSE_C
209 +#define MBEDTLS_X509_CREATE_C
210 +#define MBEDTLS_X509_CRT_WRITE_C
211 +#define MBEDTLS_X509_CSR_WRITE_C
212 +#define MBEDTLS_XTEA_C
213 +
214 +#include "mbedtls/check_config.h"
215 +
216 +#endif /* MBEDTLS_CONFIG_H */
1 +/**********************************************************
2 + *
3 + * @file : nsc.c
4 + * @author : HaewonSeo
5 + *
6 + * @note : Non-Secure callable
7 + **********************************************************/
8 +
9 +#include "nsc.h"
10 +
11 +uint32_t startTime, endTime, OLED_printTime;
12 +
13 +extern char priKey[49];
14 +extern char pubKey1[49], pubKey2[49];
15 +extern char R[49], S[49];
16 +
17 +t_digitallySignedData gDSD;
18 +
19 +/*----------------------------------------------------------------------------
20 + NonSecure callable function for NonSecure callback
21 + *----------------------------------------------------------------------------*/
22 +
23 +NonSecure_funcptr pfNonSecure_OLED_On = (NonSecure_funcptr)NULL;
24 +NonSecure_funcptr pfNonSecure_OLED_Off = (NonSecure_funcptr)NULL;
25 +
26 +__NONSECURE_ENTRY
27 +int32_t Secure_OLED_On_callback(NonSecure_funcptr *callback)
28 +{
29 + pfNonSecure_OLED_On = (NonSecure_funcptr)cmse_nsfptr_create(callback);
30 + return 0;
31 +}
32 +
33 +__NONSECURE_ENTRY
34 +int32_t Secure_OLED_Off_callback(NonSecure_funcptr *callback)
35 +{
36 + pfNonSecure_OLED_Off = (NonSecure_funcptr)cmse_nsfptr_create(callback);
37 + return 0;
38 +}
39 +
40 +/*----------------------------------------------------------------------------
41 + Secure functions exported to NonSecure application
42 + Must place in Non-secure Callable
43 + *----------------------------------------------------------------------------*/
44 +
45 +__NONSECURE_ENTRY
46 +uint32_t GetSystemCoreClock(void)
47 +{
48 + //printf("System core clock = %d.\n", SystemCoreClock);
49 + return SystemCoreClock;
50 +}
51 +
52 +
53 +__NONSECURE_ENTRY
54 +uint32_t Get_BPM()
55 +{
56 + uint32_t ret;
57 + static uint32_t ticks;
58 +
59 + ret = MAX30102_ComputeBPM();
60 +
61 + ticks++;
62 +
63 + if (ticks == 60)
64 + {
65 + ticks = 0;
66 + startTime = millis_counter;
67 + /* Refresh OLED */
68 + pfNonSecure_OLED_On(9999);
69 + pfNonSecure_OLED_On(beatAvg);
70 + endTime = millis_counter;
71 +
72 + OLED_printTime = endTime - startTime;
73 + //printf("OLED print time = %u\n", OLED_printTime);
74 + }
75 + else
76 + OLED_printTime = 0;
77 +
78 + if (ret == 0)
79 + return 0;
80 +
81 + return beatAvg;
82 +}
83 +
84 +__NONSECURE_ENTRY
85 +uint32_t Get_EncryptedDigitallySignedData(t_digitallySignedData *dsd)
86 +{
87 + uint32_t ret;
88 + static uint32_t ticks;
89 + __attribute__((aligned(4))) uint8_t plainBPM[16] = //{0};
90 + {
91 + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
92 + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30
93 + };
94 +
95 + ret = MAX30102_ComputeBPM();
96 +
97 + ticks++;
98 +
99 + if (ticks >= 60)
100 + {
101 + ticks = 0;
102 + startTime = millis_counter;
103 +
104 + /* Refresh OLED */
105 + pfNonSecure_OLED_On(9999);
106 + pfNonSecure_OLED_On(beatAvg);
107 + endTime = millis_counter;
108 +
109 + OLED_printTime = endTime - startTime;
110 + //printf("OLED print time = %u\n", OLED_printTime);
111 +
112 + /* Encyrpt beatAvg */
113 + memcpy(plainBPM, &beatAvg, sizeof(uint8_t));
114 +
115 + /* hashing(sha1) -> Generate Signature -> Encrypt plainBPM & Signiture */
116 +
117 + M2351_ECDSA_GenerateSignature((uint8_t *)plainBPM, priKey, R, S);
118 +
119 + Encrypt_data((uint8_t *)plainBPM, (uint8_t *)dsd->data, sizeof(plainBPM));
120 + Encrypt_data((uint8_t *)pubKey1, (uint8_t *)dsd->pubKey1, 24);
121 + Encrypt_data((uint8_t *)pubKey2, (uint8_t *)dsd->pubKey2, 24);
122 + Encrypt_data((uint8_t *)R, (uint8_t *)dsd->R, 24);
123 + Encrypt_data((uint8_t *)S, (uint8_t *)dsd->S, 24);
124 +
125 + printf("\nplainBPM\n");
126 + printBlock(plainBPM);
127 + printf("\nencryptedBPM\n");
128 + printBlock((uint8_t *)dsd->data);
129 + }
130 + else
131 + OLED_printTime = 0;
132 +
133 + if (beatAvg == 0)
134 + return 0;
135 +
136 + return 1;
137 +}
138 +
139 +
140 +
141 +/*----------------------------------------------------------------------------
142 + CRYPTO Secure functions exported to NonSecure application
143 + Must place in Non-secure Callable
144 + *----------------------------------------------------------------------------*/
145 +
146 +__NONSECURE_ENTRY
147 +int32_t Encrypt_data(uint8_t *plainData, uint8_t *encryptedData, uint32_t bytes) {
148 +
149 + if (DEMO) printf("\n| Secure is running ... Encrypt_data |\n");
150 +
151 + M2351_Crypto_Init(0, ENCRYPT);
152 + M2351_Crypto_UseSessionKey(0);
153 + M2351_Encrypt_Data(0, plainData, encryptedData, bytes);
154 +
155 + //M2351_crypto_init(1, ENCRYPT);
156 + //M2351_crypto_useMasterKey();
157 + //M2351_encrypt_data(1, plainData, cipheredData);
158 +
159 + return (int32_t)encryptedData;
160 +}
161 +
162 +__NONSECURE_ENTRY
163 +int32_t Decrypt_data(uint8_t *encryptedData, uint8_t *resultData, uint32_t bytes) {
164 +
165 + if (DEMO) printf("\n| Secure is running ... Decrypt_data |\n");
166 +
167 + M2351_Crypto_Init(0, DECRYPT);
168 + M2351_Crypto_UseSessionKey(0);
169 + M2351_Decrypt_Data(0, encryptedData, resultData, bytes);
170 +
171 +
172 + //M2351_crypto_init(1, DECRYPT);
173 + //M2351_crypto_useMasterKey();
174 + //M2351_decrypt_data(1, cipheredData, resultData);
175 +
176 + return (int32_t)resultData;
177 +}
178 +
179 +
180 +__NONSECURE_ENTRY
181 +void M2351_LoadKey()
182 +{
183 + static int called;
184 +
185 + if (called)
186 + return ;
187 +
188 + called = 1;
189 +
190 + printf("+---------------------------------------------+\n");
191 + printf("| Load PriKey from OTP & Generate PubKey |\n");
192 + printf("+---------------------------------------------+\n");
193 +
194 + M2351_FMC_Read_Key(0, 3, priKey);
195 + printf("prikey(%d-bits) : %s\n", strlen(priKey) * 4, priKey);
196 +
197 + M2351_ECC_GenerateKey(priKey, pubKey1, pubKey2);
198 + printf("pubKey1(%d-bits) : %s\npubKey2(%d-bits) : %s\n", strlen(pubKey1) * 4, pubKey1, strlen(pubKey2) * 4, pubKey2);
199 +
200 + return ;
201 +}
202 +
203 +__NONSECURE_ENTRY
204 +void M2351_DeleteKey()
205 +{
206 + memset(priKey, 0, sizeof(char) * 49);
207 + memset(pubKey1, 0, sizeof(char) * 49);
208 + memset(pubKey2, 0, sizeof(char) * 49);
209 + memset(R, 0, sizeof(char) * 49);
210 + memset(S, 0, sizeof(char) * 49);
211 + //memset(&gDSD, 0, sizeof(t_digitallySignedData));
212 +
213 + printf("\nDelete Key & Signature OK.\n");
214 +}
215 +
216 +/*----------------------------------------------------------------------------
217 + PRINT Secure functions exported to NonSecure application
218 + Must place in Non-secure Callable
219 + *----------------------------------------------------------------------------*/
220 +
221 +
222 +__NONSECURE_ENTRY
223 +int32_t printBlock(uint8_t *block) {
224 +
225 + //printf("&block = %p\n",block);
226 +
227 + for (uint8_t i = 0; i < 4; i++) {
228 + printf("|");
229 + for (uint8_t j = 0; j < 16; j = j+4) {
230 +
231 + printf(" %02x",block[i+j]);
232 +
233 + }
234 + printf(" |\n");
235 + }
236 + printf("\n");
237 +
238 + return 1;
239 +}
240 +
241 +__NONSECURE_ENTRY
242 +int32_t printSecure(char *string, void *ptr, uint8_t val) {
243 +
244 + if (ptr == NULL && val == NULL) printf("%s\n",string);
245 + if (ptr == NULL && val != NULL) printf(string,val);
246 + if (ptr != NULL && val == NULL) printf(string,ptr);
247 +
248 + return 1;
249 +}
250 +
251 +
252 +
253 +__NONSECURE_ENTRY
254 +int32_t printDigitallySignedData(t_digitallySignedData *dsd)
255 +{
256 + int32_t i;
257 +
258 + printf(".data(%d-bits):\n", (sizeof(dsd->data)-1) * 8);
259 + for(i=0; i<16; i++)
260 + printf("%02x", dsd->data[i]);
261 +
262 + //printf("\n.pubKey1(%d-bits):\n", (sizeof(dsd->pubKey1)-1) * 8);
263 + //for(i=0; i<24; i++)
264 + // printf("%02x", dsd->pubKey1[i]);
265 +
266 + //printf("\n.pubKey2(%d-bits):\n", (sizeof(dsd->pubKey2)-1) * 8);
267 + //for(i=0; i<24; i++)
268 + // printf("%02x", dsd->pubKey2[i]);
269 +
270 + printf("\n.SignatureR(%d-bits):\n", (sizeof(dsd->R)-1) * 8);
271 + for(i=0; i<24; i++)
272 + printf("%02x", dsd->R[i]);
273 +
274 + printf("\n.SignatureS(%d-bits):\n", (sizeof(dsd->S)-1) * 8);
275 + for(i=0; i<24; i++)
276 + printf("%02x", dsd->S[i]);
277 +
278 + printf("\n");
279 +
280 + return 1;
281 +}
282 +
1 +/**********************************************************
2 + *
3 + * @file : nsc.h
4 + * @author : HaewonSeo
5 + *
6 + * @note : Non-Secure callable
7 + **********************************************************/
8 +#ifndef __NSC_H__
9 +#define __NSC_H__
10 +
11 +#include <arm_cmse.h>
12 +#include <stdio.h>
13 +#include <stdlib.h>
14 +#include "NuMicro.h"
15 +#include "M2351_crypto.h"
16 +#include "MAX30102.h"
17 +
18 +#define DEMO 1
19 +#define SUCCESS 1
20 +#define FAIL 0
21 +
22 +// Raw HR & SPo2 data from FIFO
23 +extern volatile int32_t hr_val;
24 +extern volatile int32_t spo2_val;
25 +
26 +/* typedef for NonSecure callback functions */
27 +typedef __NONSECURE_CALL void (*NonSecure_funcptr)(uint32_t);
28 +
29 +extern volatile uint32_t millis_counter;
30 +extern float beatsPerMinute;
31 +extern uint32_t beatAvg;
32 +
33 +typedef struct s_netData
34 +{
35 + char *data;
36 + int len;
37 +} t_netData;
38 +
39 +typedef struct s_digitallySignedData
40 +{
41 + uint8_t data[17];
42 + uint8_t pubKey1[25];
43 + uint8_t pubKey2[25];
44 + uint8_t R[25];
45 + uint8_t S[25];
46 +} t_digitallySignedData;
47 +
48 +
49 +__NONSECURE_ENTRY
50 +uint32_t GetSystemCoreClock(void);
51 +
52 +/*----------------------------------------------------------------------------
53 + NonSecure callable function for NonSecure callback
54 + *----------------------------------------------------------------------------*/
55 +
56 +__NONSECURE_ENTRY
57 +int32_t Secure_OLED_On_callback(NonSecure_funcptr *callback);
58 +
59 +__NONSECURE_ENTRY
60 +int32_t Secure_OLED_On_callback(NonSecure_funcptr *callback);
61 +
62 +
63 +/*----------------------------------------------------------------------------
64 + MAX30102 Heart-Rate Sensor functions exported to NonSecure application
65 + Must place in Non-secure Callable
66 + *----------------------------------------------------------------------------*/
67 +
68 +__NONSECURE_ENTRY
69 +uint32_t Get_BPM();
70 +
71 +__NONSECURE_ENTRY
72 +uint32_t Get_EncryptedDigitallySignedData();
73 +
74 +/*----------------------------------------------------------------------------
75 + CRYPTO functions exported to NonSecure application
76 + Must place in Non-secure Callable
77 + *----------------------------------------------------------------------------*/
78 +
79 +__NONSECURE_ENTRY
80 +int32_t Encrypt_data(uint8_t *,uint8_t *, uint32_t);
81 +__NONSECURE_ENTRY
82 +int32_t Decrypt_data(uint8_t *,uint8_t *, uint32_t);
83 +
84 +__NONSECURE_ENTRY
85 +void M2351_LoadKey();
86 +__NONSECURE_ENTRY
87 +void M2351_DeleteKey();
88 +
89 +/*----------------------------------------------------------------------------
90 + PRINT functions exported to NonSecure application
91 + Must place in Non-secure Callable
92 + *----------------------------------------------------------------------------*/
93 +
94 +__NONSECURE_ENTRY
95 +int32_t printBlock(uint8_t *);
96 +__NONSECURE_ENTRY
97 +int32_t printSecure(char *,void *,uint8_t);
98 +__NONSECURE_ENTRY
99 +int32_t printDigitallySignedData(t_digitallySignedData *dsd);
100 +
101 +
102 +#endif /* __NSC_H__ */
This diff is collapsed. Click to expand it.
1 +/*
2 + * SSL client demonstration program
3 + *
4 + * Copyright The Mbed TLS Contributors
5 + * SPDX-License-Identifier: Apache-2.0
6 + *
7 + * Licensed under the Apache License, Version 2.0 (the "License"); you may
8 + * not use this file except in compliance with the License.
9 + * You may obtain a copy of the License at
10 + *
11 + * http://www.apache.org/licenses/LICENSE-2.0
12 + *
13 + * Unless required by applicable law or agreed to in writing, software
14 + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 + * See the License for the specific language governing permissions and
17 + * limitations under the License.
18 + */
19 +
20 +#if !defined(MBEDTLS_CONFIG_FILE)
21 +#include "mbedtls/config.h"
22 +#else
23 +#include MBEDTLS_CONFIG_FILE
24 +#endif
25 +
26 +#if defined(MBEDTLS_PLATFORM_C)
27 +#include "mbedtls/platform.h"
28 +#else
29 +#include <stdio.h>
30 +#include <stdlib.h>
31 +#define mbedtls_time time
32 +#define mbedtls_time_t time_t
33 +#define mbedtls_fprintf fprintf
34 +#define mbedtls_printf printf
35 +#define mbedtls_exit exit
36 +#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS
37 +#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE
38 +#endif /* MBEDTLS_PLATFORM_C */
39 +
40 +#if !defined(MBEDTLS_BIGNUM_C) || !defined(MBEDTLS_ENTROPY_C) || \
41 + !defined(MBEDTLS_SSL_TLS_C) || !defined(MBEDTLS_SSL_CLI_C) || \
42 + !defined(MBEDTLS_NET_C) || !defined(MBEDTLS_RSA_C) || \
43 + !defined(MBEDTLS_CERTS_C) || !defined(MBEDTLS_PEM_PARSE_C) || \
44 + !defined(MBEDTLS_CTR_DRBG_C) || !defined(MBEDTLS_X509_CRT_PARSE_C)
45 +int main( void )
46 +{
47 + mbedtls_printf("MBEDTLS_BIGNUM_C and/or MBEDTLS_ENTROPY_C and/or "
48 + "MBEDTLS_SSL_TLS_C and/or MBEDTLS_SSL_CLI_C and/or "
49 + "MBEDTLS_NET_C and/or MBEDTLS_RSA_C and/or "
50 + "MBEDTLS_CTR_DRBG_C and/or MBEDTLS_X509_CRT_PARSE_C "
51 + "not defined.\n");
52 + mbedtls_exit( 0 );
53 +}
54 +#else
55 +
56 +#include "mbedtls/net_sockets.h"
57 +#include "mbedtls/debug.h"
58 +#include "mbedtls/ssl.h"
59 +#include "mbedtls/entropy.h"
60 +#include "mbedtls/ctr_drbg.h"
61 +#include "mbedtls/error.h"
62 +#include "mbedtls/certs.h"
63 +
64 +#include <string.h>
65 +
66 +#define SERVER_PORT "4433"
67 +#define SERVER_NAME "172.27.145.87"
68 +//#define SERVER_PORT "443"
69 +//#define SERVER_NAME "tls.mbed.org"
70 +#define GET_REQUEST "GET / HTTP/1.0\r\n\r\n"
71 +
72 +#define DEBUG_LEVEL 1
73 +
74 +
75 +static void my_debug( void *ctx, int level,
76 + const char *file, int line,
77 + const char *str )
78 +{
79 + ((void) level);
80 +
81 + mbedtls_fprintf( (FILE *) ctx, "%s:%04d: %s", file, line, str );
82 + fflush( (FILE *) ctx );
83 +}
84 +
85 +int ssl_client1( void )
86 +{
87 + int ret = 1, len;
88 + int exit_code = MBEDTLS_EXIT_FAILURE;
89 + mbedtls_net_context server_fd;
90 + uint32_t flags;
91 + unsigned char buf[1024];
92 + const char *pers = "ssl_client1";
93 +
94 + mbedtls_entropy_context entropy;
95 + mbedtls_ctr_drbg_context ctr_drbg;
96 + mbedtls_ssl_context ssl;
97 + mbedtls_ssl_config conf;
98 + mbedtls_x509_crt cacert;
99 +
100 +#if defined(MBEDTLS_DEBUG_C)
101 + mbedtls_debug_set_threshold( DEBUG_LEVEL );
102 +#endif
103 +
104 + /*
105 + * 0. Initialize the RNG and the session data
106 + */
107 + mbedtls_net_init( &server_fd );
108 + mbedtls_ssl_init( &ssl );
109 + mbedtls_ssl_config_init( &conf );
110 + mbedtls_x509_crt_init( &cacert );
111 + mbedtls_ctr_drbg_init( &ctr_drbg );
112 +
113 + mbedtls_printf( "\n . Seeding the random number generator..." );
114 + fflush( stdout );
115 +
116 + mbedtls_entropy_init( &entropy );
117 + if( ( ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, &entropy,
118 + (const unsigned char *) pers,
119 + strlen( pers ) ) ) != 0 )
120 + {
121 + mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned %d\n", ret );
122 + goto exit;
123 + }
124 +
125 + mbedtls_printf( " ok\n" );
126 +
127 + /*
128 + * 0. Initialize certificates
129 + */
130 + mbedtls_printf( " . Loading the CA root certificate ..." );
131 + fflush( stdout );
132 +
133 + ret = mbedtls_x509_crt_parse( &cacert, (const unsigned char *) mbedtls_test_cas_pem,
134 + mbedtls_test_cas_pem_len );
135 + if( ret < 0 )
136 + {
137 + mbedtls_printf( " failed\n ! mbedtls_x509_crt_parse returned -0x%x\n\n", (unsigned int) -ret );
138 + goto exit;
139 + }
140 +
141 + mbedtls_printf( " ok (%d skipped)\n", ret );
142 +
143 + /*
144 + * 1. Start the connection
145 + */
146 + mbedtls_printf( " . Connecting to tcp/%s/%s...", SERVER_NAME, SERVER_PORT );
147 + fflush( stdout );
148 +
149 + if( ( ret = mbedtls_net_connect( &server_fd, SERVER_NAME,
150 + SERVER_PORT, MBEDTLS_NET_PROTO_TCP ) ) != 0 )
151 + {
152 + mbedtls_printf( " failed\n ! mbedtls_net_connect returned %d\n\n", ret );
153 + goto exit;
154 + }
155 +
156 + mbedtls_printf( " ok\n" );
157 +
158 + /*
159 + * 2. Setup stuff
160 + */
161 + mbedtls_printf( " . Setting up the SSL/TLS structure..." );
162 + fflush( stdout );
163 +
164 + if( ( ret = mbedtls_ssl_config_defaults( &conf,
165 + MBEDTLS_SSL_IS_CLIENT,
166 + MBEDTLS_SSL_TRANSPORT_STREAM,
167 + MBEDTLS_SSL_PRESET_DEFAULT ) ) != 0 )
168 + {
169 + mbedtls_printf( " failed\n ! mbedtls_ssl_config_defaults returned %d\n\n", ret );
170 + goto exit;
171 + }
172 +
173 + mbedtls_printf( " ok\n" );
174 +
175 + /* OPTIONAL is not optimal for security,
176 + * but makes interop easier in this simplified example */
177 + mbedtls_ssl_conf_authmode( &conf, MBEDTLS_SSL_VERIFY_OPTIONAL );
178 + mbedtls_ssl_conf_ca_chain( &conf, &cacert, NULL );
179 + mbedtls_ssl_conf_rng( &conf, mbedtls_ctr_drbg_random, &ctr_drbg );
180 + mbedtls_ssl_conf_dbg( &conf, my_debug, stdout );
181 +
182 + if( ( ret = mbedtls_ssl_setup( &ssl, &conf ) ) != 0 )
183 + {
184 + mbedtls_printf( " failed\n ! mbedtls_ssl_setup returned %d\n\n", ret );
185 + goto exit;
186 + }
187 +
188 + if( ( ret = mbedtls_ssl_set_hostname( &ssl, SERVER_NAME ) ) != 0 )
189 + {
190 + mbedtls_printf( " failed\n ! mbedtls_ssl_set_hostname returned %d\n\n", ret );
191 + goto exit;
192 + }
193 +
194 + mbedtls_ssl_set_bio( &ssl, &server_fd, mbedtls_net_send, mbedtls_net_recv, NULL );
195 +
196 + /*
197 + * 4. Handshake
198 + */
199 + mbedtls_printf( " . Performing the SSL/TLS handshake..." );
200 + fflush( stdout );
201 +
202 + while( ( ret = mbedtls_ssl_handshake( &ssl ) ) != 0 )
203 + {
204 + if( ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE )
205 + {
206 + mbedtls_printf( " failed\n ! mbedtls_ssl_handshake returned -0x%x\n\n", (unsigned int) -ret );
207 + goto exit;
208 + }
209 + }
210 +
211 + mbedtls_printf( " ok\n" );
212 +
213 + /*
214 + * 5. Verify the server certificate
215 + */
216 + mbedtls_printf( " . Verifying peer X.509 certificate..." );
217 +
218 + /* In real life, we probably want to bail out when ret != 0 */
219 + if( ( flags = mbedtls_ssl_get_verify_result( &ssl ) ) != 0 )
220 + {
221 + char vrfy_buf[512];
222 +
223 + mbedtls_printf( " failed\n" );
224 +
225 + mbedtls_x509_crt_verify_info( vrfy_buf, sizeof( vrfy_buf ), " ! ", flags );
226 +
227 + mbedtls_printf( "%s\n", vrfy_buf );
228 + }
229 + else
230 + mbedtls_printf( " ok\n" );
231 +
232 + /*
233 + * 3. Write the GET request
234 + */
235 + mbedtls_printf( " > Write to server:" );
236 + fflush( stdout );
237 +
238 + len = sprintf( (char *) buf, GET_REQUEST );
239 +
240 + while( ( ret = mbedtls_ssl_write( &ssl, buf, len ) ) <= 0 )
241 + {
242 + if( ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE )
243 + {
244 + mbedtls_printf( " failed\n ! mbedtls_ssl_write returned %d\n\n", ret );
245 + goto exit;
246 + }
247 + }
248 +
249 + len = ret;
250 + mbedtls_printf( " %d bytes written\n\n%s", len, (char *) buf );
251 +
252 + /*
253 + * 7. Read the HTTP response
254 + */
255 + mbedtls_printf( " < Read from server:" );
256 + fflush( stdout );
257 +
258 + do
259 + {
260 + len = sizeof( buf ) - 1;
261 + memset( buf, 0, sizeof( buf ) );
262 + ret = mbedtls_ssl_read( &ssl, buf, len );
263 +
264 + if( ret == MBEDTLS_ERR_SSL_WANT_READ || ret == MBEDTLS_ERR_SSL_WANT_WRITE )
265 + continue;
266 +
267 + if( ret == MBEDTLS_ERR_SSL_PEER_CLOSE_NOTIFY )
268 + break;
269 +
270 + if( ret < 0 )
271 + {
272 + mbedtls_printf( "failed\n ! mbedtls_ssl_read returned %d\n\n", ret );
273 + break;
274 + }
275 +
276 + if( ret == 0 )
277 + {
278 + mbedtls_printf( "\n\nEOF\n\n" );
279 + break;
280 + }
281 +
282 + len = ret;
283 + mbedtls_printf( " %d bytes read\n\n%s", len, (char *) buf );
284 + }
285 + while( 1 );
286 +
287 + mbedtls_ssl_close_notify( &ssl );
288 +
289 + exit_code = MBEDTLS_EXIT_SUCCESS;
290 +
291 +exit:
292 +
293 +#ifdef MBEDTLS_ERROR_C
294 + if( exit_code != MBEDTLS_EXIT_SUCCESS )
295 + {
296 + char error_buf[100];
297 + mbedtls_strerror( ret, error_buf, 100 );
298 + mbedtls_printf("Last error was: %d - %s\n\n", ret, error_buf );
299 + }
300 +#endif
301 +
302 + mbedtls_net_free( &server_fd );
303 +
304 + mbedtls_x509_crt_free( &cacert );
305 + mbedtls_ssl_free( &ssl );
306 + mbedtls_ssl_config_free( &conf );
307 + mbedtls_ctr_drbg_free( &ctr_drbg );
308 + mbedtls_entropy_free( &entropy );
309 +
310 +#if defined(_WIN32)
311 + mbedtls_printf( " + Press Enter to exit this program.\n" );
312 + fflush( stdout ); getchar();
313 +#endif
314 +
315 + mbedtls_exit( exit_code );
316 +}
317 +#endif /* MBEDTLS_BIGNUM_C && MBEDTLS_ENTROPY_C && MBEDTLS_SSL_TLS_C &&
318 + MBEDTLS_SSL_CLI_C && MBEDTLS_NET_C && MBEDTLS_RSA_C &&
319 + MBEDTLS_CERTS_C && MBEDTLS_PEM_PARSE_C && MBEDTLS_CTR_DRBG_C &&
320 + MBEDTLS_X509_CRT_PARSE_C */
1 +FROM debian:buster
2 +
3 +LABEL maintainer="shw2662@khu.ac.kr"
4 +
5 +RUN apt-get update && apt-get install -y \
6 + nginx \
7 + openssl \
8 + vim \
9 + php-fpm \
10 + mariadb-server \
11 + php-mysql \
12 + php-mbstring \
13 + wget \
14 + php \
15 + gcc \
16 + libssl-dev \
17 + netstat
18 +
19 +COPY ./srcs/default ./tmp/
20 +COPY ./srcs/wordpress-5.6.2.tar.gz ./tmp/
21 +COPY ./srcs/wp-config.php ./tmp/
22 +COPY ./srcs/phpMyAdmin-4.9.7-all-languages.tar.gz ./tmp/
23 +COPY ./srcs/config.inc.php ./tmp/
24 +COPY ./srcs/run.sh ./
25 +
26 +COPY ./srcs/input.php ./tmp/
27 +COPY ./srcs/process.php ./tmp/
28 +COPY ./srcs/highcharts.php ./tmp/
29 +COPY ./srcs/socket.php ./tmp/
30 +
31 +COPY ./srcs/tcp.h ./home/
32 +COPY ./srcs/tcps.s ./home/
33 +
34 +EXPOSE 80 443 2351
35 +
36 +CMD bash run.sh
1 +<?php
2 +/* vim: set expandtab sw=4 ts=4 sts=4: */
3 +/**
4 + * phpMyAdmin sample configuration, you can use it as base for
5 + * manual configuration. For easier setup you can use setup/
6 + *
7 + * All directives are explained in documentation in the doc/ folder
8 + * or at <https://docs.phpmyadmin.net/>.
9 + *
10 + * @package PhpMyAdmin
11 + */
12 +
13 +/**
14 + * This is needed for cookie based authentication to encrypt password in
15 + * cookie. Needs to be 32 chars long.
16 + */
17 +$cfg['blowfish_secret'] = '0k}CJ:h,X,mt0Dp.,IAPww,0.6gSor,B'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
18 +
19 +/**
20 + * Servers configuration
21 + */
22 +$i = 0;
23 +
24 +/**
25 + * First server
26 + */
27 +$i++;
28 +/* Authentication type */
29 +$cfg['Servers'][$i]['auth_type'] = 'cookie';
30 +/* Server parameters */
31 +$cfg['Servers'][$i]['host'] = 'localhost';
32 +$cfg['Servers'][$i]['compress'] = false;
33 +$cfg['Servers'][$i]['AllowNoPassword'] = false;
34 +
35 +/**
36 + * phpMyAdmin configuration storage settings.
37 + */
38 +
39 +/* User used to manipulate with storage */
40 +// $cfg['Servers'][$i]['controlhost'] = '';
41 +// $cfg['Servers'][$i]['controlport'] = '';
42 +// $cfg['Servers'][$i]['controluser'] = 'pma';
43 +// $cfg['Servers'][$i]['controlpass'] = 'pmapass';
44 +
45 +/* Storage database and tables */
46 +// $cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';
47 +// $cfg['Servers'][$i]['bookmarktable'] = 'pma__bookmark';
48 +// $cfg['Servers'][$i]['relation'] = 'pma__relation';
49 +// $cfg['Servers'][$i]['table_info'] = 'pma__table_info';
50 +// $cfg['Servers'][$i]['table_coords'] = 'pma__table_coords';
51 +// $cfg['Servers'][$i]['pdf_pages'] = 'pma__pdf_pages';
52 +// $cfg['Servers'][$i]['column_info'] = 'pma__column_info';
53 +// $cfg['Servers'][$i]['history'] = 'pma__history';
54 +// $cfg['Servers'][$i]['table_uiprefs'] = 'pma__table_uiprefs';
55 +// $cfg['Servers'][$i]['tracking'] = 'pma__tracking';
56 +// $cfg['Servers'][$i]['userconfig'] = 'pma__userconfig';
57 +// $cfg['Servers'][$i]['recent'] = 'pma__recent';
58 +// $cfg['Servers'][$i]['favorite'] = 'pma__favorite';
59 +// $cfg['Servers'][$i]['users'] = 'pma__users';
60 +// $cfg['Servers'][$i]['usergroups'] = 'pma__usergroups';
61 +// $cfg['Servers'][$i]['navigationhiding'] = 'pma__navigationhiding';
62 +// $cfg['Servers'][$i]['savedsearches'] = 'pma__savedsearches';
63 +// $cfg['Servers'][$i]['central_columns'] = 'pma__central_columns';
64 +// $cfg['Servers'][$i]['designer_settings'] = 'pma__designer_settings';
65 +// $cfg['Servers'][$i]['export_templates'] = 'pma__export_templates';
66 +
67 +/**
68 + * End of servers configuration
69 + */
70 +
71 +/**
72 + * Directories for saving/loading files from server
73 + */
74 +$cfg['UploadDir'] = '';
75 +$cfg['SaveDir'] = '';
76 +
77 +/**
78 + * Whether to display icons or text or both icons and text in table row
79 + * action segment. Value can be either of 'icons', 'text' or 'both'.
80 + * default = 'both'
81 + */
82 +//$cfg['RowActionType'] = 'icons';
83 +
84 +/**
85 + * Defines whether a user should be displayed a "show all (records)"
86 + * button in browse mode or not.
87 + * default = false
88 + */
89 +//$cfg['ShowAll'] = true;
90 +
91 +/**
92 + * Number of rows displayed when browsing a result set. If the result
93 + * set contains more rows, "Previous" and "Next".
94 + * Possible values: 25, 50, 100, 250, 500
95 + * default = 25
96 + */
97 +//$cfg['MaxRows'] = 50;
98 +
99 +/**
100 + * Disallow editing of binary fields
101 + * valid values are:
102 + * false allow editing
103 + * 'blob' allow editing except for BLOB fields
104 + * 'noblob' disallow editing except for BLOB fields
105 + * 'all' disallow editing
106 + * default = 'blob'
107 + */
108 +//$cfg['ProtectBinary'] = false;
109 +
110 +/**
111 + * Default language to use, if not browser-defined or user-defined
112 + * (you find all languages in the locale folder)
113 + * uncomment the desired line:
114 + * default = 'en'
115 + */
116 +//$cfg['DefaultLang'] = 'en';
117 +//$cfg['DefaultLang'] = 'de';
118 +
119 +/**
120 + * How many columns should be used for table display of a database?
121 + * (a value larger than 1 results in some information being hidden)
122 + * default = 1
123 + */
124 +//$cfg['PropertiesNumColumns'] = 2;
125 +
126 +/**
127 + * Set to true if you want DB-based query history.If false, this utilizes
128 + * JS-routines to display query history (lost by window close)
129 + *
130 + * This requires configuration storage enabled, see above.
131 + * default = false
132 + */
133 +//$cfg['QueryHistoryDB'] = true;
134 +
135 +/**
136 + * When using DB-based query history, how many entries should be kept?
137 + * default = 25
138 + */
139 +//$cfg['QueryHistoryMax'] = 100;
140 +
141 +/**
142 + * Whether or not to query the user before sending the error report to
143 + * the phpMyAdmin team when a JavaScript error occurs
144 + *
145 + * Available options
146 + * ('ask' | 'always' | 'never')
147 + * default = 'ask'
148 + */
149 +//$cfg['SendErrorReports'] = 'always';
150 +
151 +/**
152 + * You can find more configuration options in the documentation
153 + * in the doc/ folder or at <https://docs.phpmyadmin.net/>.
154 + */
1 +##
2 +# You should look at the following URL's in order to grasp a solid understanding
3 +# of Nginx configuration files in order to fully unleash the power of Nginx.
4 +# https://www.nginx.com/resources/wiki/start/
5 +# https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
6 +# https://wiki.debian.org/Nginx/DirectoryStructure
7 +#
8 +# In most cases, administrators will remove this file from sites-enabled/ and
9 +# leave it as reference inside of sites-available where it will continue to be
10 +# updated by the nginx packaging team.
11 +#
12 +# This file will automatically load configuration files provided by other
13 +# applications, such as Drupal or Wordpress. These applications will be made
14 +# available underneath a path with that package name, such as /drupal8.
15 +#
16 +# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
17 +##
18 +
19 +# Default server configuration
20 +#
21 +server {
22 + listen 80;
23 + listen [::]:80;
24 +
25 + root /var/www/html;
26 +
27 + # Add index.php to the list if you are using PHP
28 + index index.html index.htm index.nginx-debian.html input.php;
29 +
30 + server_name ft_server80;
31 +
32 + location / {
33 + # First attempt to serve request as file, then
34 + # as directory, then fall back to displaying a 404.
35 + # autoindex on;
36 + try_files $uri $uri/ =404;
37 + }
38 +
39 + # pass PHP scripts to FastCGI server
40 + #
41 + location ~ \.php$ {
42 + include snippets/fastcgi-php.conf;
43 +
44 + # With php-fpm (or other unix sockets):
45 + fastcgi_pass unix:/run/php/php7.3-fpm.sock;
46 + # # With php-cgi (or other tcp sockets):
47 + # fastcgi_pass 127.0.0.1:9000;
48 + }
49 +
50 + # return 301 https://$host$request_uri;
51 +}
52 +
53 +server {
54 + listen 443 ssl;
55 + listen [::]:443 ssl;
56 +
57 + # SSL configuration
58 + #
59 + # listen 443 ssl default_server;
60 + # listen [::]:443 ssl default_server;
61 + #
62 + # Note: You should disable gzip for SSL traffic.
63 + # See: https://bugs.debian.org/773332
64 + #
65 + # Read up on ssl_ciphers to ensure a secure configuration.
66 + # See: https://bugs.debian.org/765782
67 + #
68 + # Self signed certs generated by the ssl-cert package
69 + # Don't use them in a production server!
70 + #
71 + # include snippets/snakeoil.conf;
72 +
73 + ssl on;
74 + ssl_certificate /etc/ssl/certs/localhost.dev.crt;
75 + ssl_certificate_key /etc/ssl/private/localhost.dev.key;
76 +
77 + root /var/www/html;
78 +
79 + # Add index.php to the list if you are using PHP
80 + index index.html index.htm index.nginx-debian.html index.php;
81 +
82 + server_name ft_server;
83 +
84 + location / {
85 + # First attempt to serve request as file, then
86 + # as directory, then fall back to displaying a 404.
87 + autoindex on;
88 + try_files $uri $uri/ =404;
89 + }
90 +
91 + # pass PHP scripts to FastCGI server
92 + #
93 + location ~ \.php$ {
94 + include snippets/fastcgi-php.conf;
95 +
96 + # With php-fpm (or other unix sockets):
97 + fastcgi_pass unix:/run/php/php7.3-fpm.sock;
98 + # # With php-cgi (or other tcp sockets):
99 + # fastcgi_pass 127.0.0.1:9000;
100 + }
101 +
102 + # deny access to .htaccess files, if Apache's document root
103 + # concurs with nginx's one
104 + #
105 + #location ~ /\.ht {
106 + # deny all;
107 + #}
108 +}
109 +
110 +
111 +# Virtual Host configuration for example.com
112 +#
113 +# You can move that to a different file under sites-available/ and symlink that
114 +# to sites-enabled/ to enable it.
115 +#
116 +#server {
117 +# listen 80;
118 +# listen [::]:80;
119 +#
120 +# server_name example.com;
121 +#
122 +# root /var/www/example.com;
123 +# index index.html;
124 +#
125 +# location / {
126 +# try_files $uri $uri/ =404;
127 +# }
128 +#}
1 +<?php
2 +
3 +$mysql_host = 'localhost';
4 +$mysql_user = 'haseo';
5 +$mysql_password = 'haseo';
6 +$mysql_db = 'M2351';
7 +
8 +// DB 접속
9 +$conn = mysqli_connect($mysql_host, $mysql_user, $mysql_password, $mysql_db);
10 +
11 +
12 +// charset 설정, 설정하지 않으면 기본 mysql 설정으로 됨, 대체적으로 euc-kr를 많이 사용
13 +//mysql_query("set names utf8");
14 +
15 +
16 +// $sql="
17 +// select * from (
18 +// SELECT DATE_FORMAT( regday, '%m-%d %HH' ) mdh , COUNT( * ) cnt, SUM( temperature ) , round(SUM( temperature ) / COUNT( * ),2) atemper
19 +// FROM `temperature`
20 +// GROUP BY DATE_FORMAT( regday, '%Y%m%d%H' )
21 +// order by regday desc
22 +// limit 12
23 +// ) t_a
24 +// order by t_a.mdh
25 +// ";
26 +//echo $sql;
27 +
28 +//$sql = "SELECT * FROM pulseTable";
29 +$sql = "SELECT * FROM
30 + (SELECT * FROM pulseTable ORDER BY date DESC LIMIT 30) A ORDER BY A.date ASC";
31 +//echo $sql;
32 +
33 +$result = mysqli_query($conn, $sql);
34 +//echo $result;
35 +
36 +$str_date="";
37 +$str_heartrate="";
38 +
39 +while ($row = mysqli_fetch_assoc($result))
40 +{
41 + $str_date .="'".$row['date']."',";
42 + $str_heartrate .="".$row['pulse'].",";
43 +}
44 +
45 +$str_date= substr($str_date,0,-1);
46 +$str_heartrate= substr($str_heartrate,0,-1);
47 +//$str_date= substr($str_date,0,-1);
48 +//$str_heartrate= substr($str_heartrate,0,-1);
49 +//echo $str_date."</br>";
50 +//echo $str_heartrate."</br>";
51 +
52 +mysqli_close($conn);
53 +
54 +?>
55 +
56 +<!DOCTYPE HTML>
57 +<html>
58 + <head>
59 + <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
60 + <title>Heart Rate Monitoring</title>
61 +
62 + <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
63 + <style type="text/css">
64 +${demo.css}
65 + </style>
66 + <script type="text/javascript">
67 +$(function () {
68 + $('#container').highcharts({
69 + chart: {
70 + type: 'line',
71 + events: {
72 + load: function() {
73 +
74 + // set up the updating of the chart each second
75 + var series = this.series[0];
76 + setInterval(function refresh(){
77 + window.location.reload();
78 + }, 3000);
79 + }
80 + }
81 + },
82 + title: {
83 + text: 'Heart Rate Monitoring'
84 + },
85 + subtitle: {
86 + text: 'Data was obtained from the MAX30102 in NuMaker-PFM-M2351 Secure World'
87 + },
88 + xAxis: {
89 + categories: [<?php echo $str_date?>]
90 + },
91 + yAxis: {
92 + title: {
93 + text: 'Heart Rate (bpm)'
94 + }
95 + },
96 + plotOptions: {
97 + line: {
98 + dataLabels: {
99 + enabled: true
100 + },
101 + enableMouseTracking: true,
102 + color: '#FF0000'
103 + }
104 + },
105 + series: [{
106 + name: 'Heart Rate',
107 + data: [<?php echo $str_heartrate?>]
108 + }
109 + ]
110 + });
111 +});
112 + </script>
113 + </head>
114 +
115 + <body>
116 +<script src="https://code.highcharts.com/highcharts.js"></script>
117 +<script src="https://code.highcharts.com/modules/series-label.js"></script>
118 +<script src="https://code.highcharts.com/modules/exporting.js"></script>
119 +<script src="https://code.highcharts.com/modules/export-data.js"></script>
120 +<script src="https://code.highcharts.com/modules/accessibility.js"></script>
121 +<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>
122 +
123 + </body>
124 +</html>
1 +<!DOCTYPE html>
2 +<html>
3 + <head>
4 + <meta charset="utf-8" />
5 + </head>
6 +
7 + <body>
8 + <form action="process.php" method="get">
9 + <p>Pulse : <input type="text" name="pulse"></p>
10 + <p>pubKey1 : <input type="text" name="pubKey1"></p>
11 + <p>pubKey2 : <input type="text" name="pubKey2"></p>
12 + <p>signatureR : <input type="text" name="signatureR"></p>
13 + <p>signatureS : <input type="text" name="signatureS"></p>
14 + <p><input type="submit" /></p>
15 + </form>
16 + </body>
17 +</html>
1 +<?php
2 +header("Content-Type: text/html; charset=UTF-8");
3 +
4 +$KEY_128 = '0000000000000000';
5 +$IV_128 = '0000000000000000';
6 +
7 +echo "[pubKey of Device]<br/>";
8 +$pubKey1 = $_GET['pubKey1'];
9 +echo "pubKey1 = $pubKey1<br/>";
10 +$pubKey2 = $_GET['pubKey2'];
11 +echo "pubKey2 = $pubKey2<br/><br/>";
12 +
13 +echo "[Encrypted digitally signed data]<br/>";
14 +$pulse = $_GET['pulse'];
15 +echo "pulse = $pulse<br/>";
16 +//$pubKey1 = $_GET['pubKey1'];
17 +//echo "pubKey1 = $pubKey1<br/>";
18 +//$pubKey2 = $_GET['pubKey2'];
19 +//echo "pubKey2 = $pubKey2<br/>";
20 +$signatureR = $_GET['signatureR'];
21 +echo "signatureR = $signatureR<br/>";
22 +$signatureS = $_GET['signatureS'];
23 +echo "signatureS = $signatureS<br/>";
24 +
25 +
26 +echo "<br/>[Decrypted digitally signed data]<br/>";
27 +
28 +$pulse = hex2bin($pulse);
29 +$pulse = openssl_decrypt($pulse, 'AES-128-CBC', $KEY_128, OPENSSL_NO_PADDING, $IV_128);
30 +//echo "pulse = $pulse<br/>";
31 +$pulse = bin2hex($pulse);
32 +echo "pulse = $pulse<br/>";
33 +
34 +$pubKey1 = openssl_decrypt($pubKey1, 'AES-128-CBC', $KEY_128, OPENSSL_NO_PADDING, $IV_128);
35 +$pubKey1 = bin2hex($pubKey1);
36 +$pubKey1 = substr($pubKey1, 1, strlen($pubKey1) / 2);
37 +//echo "pubKey1 = $pubKey1<br/>";
38 +
39 +$pubKey2 = openssl_decrypt($pubKey2, 'AES-128-CBC', $KEY_128, OPENSSL_NO_PADDING, $IV_128);
40 +$pubKey2 = bin2hex($pubKey2);
41 +$pubKey2 = substr($pubKey2, 1, strlen($pubKey2) / 2);
42 +//echo "pubKey2 = $pubKey2<br/>";
43 +
44 +$signatureR = openssl_decrypt($signatureR, 'AES-128-CBC', $KEY_128, OPENSSL_NO_PADDING, $IV_128);
45 +$signatureR = bin2hex($signatureR);
46 +$signatureR = substr($signatureR, 1, strlen($signatureR) / 2);
47 +echo "signatureR = $signatureR<br/>";
48 +
49 +$signatureS = openssl_decrypt($signatureS, 'AES-128-CBC', $KEY_128, OPENSSL_NO_PADDING, $IV_128);
50 +$signatureS = bin2hex($signatureS);
51 +$signatureS = substr($signatureS, 1, strlen($signatureS) / 2);
52 +echo "signatureS = $signatureS<br/>";
53 +
54 +echo "<br/>[Digital signature verification]<br/>";
55 +$hashPulse = sha1($hashPulse);
56 +echo "hashPulse = $hashPulse<br/>";
57 +
58 +echo "Verify signature with hashed data<br/>";
59 +$result = openssl_verify($hashPulse, $signatureR, $pubKey1, 'ecdsa-with-SHA1');
60 +
61 +// if ($result == 1) {
62 +// echo "Valid<br/>";
63 +// } elseif ($result == 0) {
64 +// echo "Invalid<br/>";
65 +// } else {
66 +// echo "error: ".openssl_error_string();
67 +// }
68 +
69 +
70 +$host = 'localhost';
71 +$user = 'haseo';
72 +$pw = 'haseo';
73 +$dbName = 'M2351';
74 +
75 +$mysqli = new mysqli($host, $user, $pw, $dbName);
76 +
77 + if($mysqli){
78 + echo "<br/>[MySQL successfully connected!]<br/>";
79 + echo "Convert binary to decimal<br/>";
80 + $pulse = hexdec($pulse[0].$pulse[1]);
81 + echo "pulse = $pulse<br/>";
82 +
83 + $query = "INSERT INTO pulseTable(pulse) VALUES ('$pulse')";
84 + mysqli_query($mysqli,$query);
85 + echo "<br/>[Success insert pulse data to DB Table!!]";
86 + }
87 + else{
88 + echo "MySQL could not be connected";
89 + }
90 +
91 +mysqli_close($mysqli);
92 +
93 +
94 +/*
95 +$encryptedBPM = $_GET['pulse'];
96 +echo 'encryptedBPM : '.$encryptedBPM.'<br/>';
97 +
98 +$decryptedBPM = Hex2Char($encryptedBPM);
99 +echo 'decryptedBPM : '.$decryptedBPM.'<br/><br/>';
100 +
101 +//echo 'decryptedBPM : '.hex2bin($decryptedBPM).'<br/><br/>';
102 +//$decryptedBPM = Hex2String($decryptedBPM);
103 +// echo 'decryptedBPM : '.$decryptedBPM.'<br/><br/>'
104 +$decryptedBPM = openssl_encrypt($decryptedBPM, 'AES-128-CBC', $KEY_128, OPENSSL_NO_PADDING, $IV_128);
105 +echo 'decryptedBPM : '.$decryptedBPM.'<br/><br/>';
106 +
107 +
108 +$teststr = '414243';
109 +echo 'teststr : '.$teststr.'<br/>';
110 +$teststr = Hex2Char($teststr);
111 +echo 'teststr : '.$teststr.'<br/>';
112 +$teststr = openssl_encrypt($teststr, 'AES-128-CBC', $KEY_128, OPENSSL_NO_PADDING, $IV_128);
113 +echo 'teststr : '.$teststr.'<br/>';
114 +$teststr = openssl_decrypt($teststr, 'AES-128-CBC', $KEY_128, OPENSSL_NO_PADDING, $IV_128);
115 +echo 'teststr : '.$teststr.'<br/>';
116 +
117 +$plain = '=000000000000000';
118 +$plain = openssl_encrypt($plain, 'AES-128-CBC', $KEY_128, OPENSSL_NO_PADDING, $IV_128);
119 +echo 'plain : '.bin2hex($plain).'<br/>';
120 +echo 'plain : '.$plain.'<br/>';
121 +$plain = openssl_decrypt($plain, 'AES-128-CBC', $KEY_128, OPENSSL_NO_PADDING, $IV_128);
122 +echo 'plain : '.$plain.'<br/>';
123 +
124 +function HexStr2Str($string){
125 + $hex='';
126 + for ($i=0; $i < strlen($string); $i+=2){
127 + $hex .= hex2bin(hexdec(($string[$i].$string[$i+1])));
128 + }
129 + return $hex;
130 +}
131 +function HexStr2DecStr($string){
132 + $hex='';
133 + for ($i=0; $i < strlen($string); $i+=2){
134 + $hex .= hexdec(($string[$i].$string[$i+1]));
135 + }
136 + return $hex;
137 +}
138 +function Hex2Char($hex){
139 + $string='';
140 + for ($i=0; $i < strlen($hex); $i+=2){
141 + $string .= chr(hexdec($hex[$i].$hex[$i+1]));
142 + }
143 + return $string;
144 +
145 +}
146 +
147 +function HexStr2Hex($str)
148 +{
149 +
150 +}
151 +*/
152 +?>
153 +
1 +#!/bin/bash
2 +
3 +service mysql start
4 +
5 +# ssl configuration
6 +openssl req -newkey rsa:4096 \
7 + -days 365 \
8 + -nodes \
9 + -x509 \
10 + -subj "/C=KR/ST=Seoul/O=KHU/OU=CSE/CN=localhost" \
11 + -keyout localhost.dev.key \
12 + -out localhost.dev.crt
13 +
14 +mv localhost.dev.key /etc/ssl/private/
15 +mv localhost.dev.crt /etc/ssl/certs/
16 +chmod 600 /etc/ssl/private/localhost.dev.key /etc/ssl/certs/localhost.dev.crt
17 +
18 +# Nginx configuration
19 +cp -p ./tmp/default /etc/nginx/sites-available
20 +
21 +# Wordpress configuration
22 +tar -xvf ./tmp/wordpress-5.6.2.tar.gz
23 +rm ./tmp/wordpress-5.6.2.tar.gz
24 +mv /wordpress/ /var/www/html
25 +cp ./tmp/wp-config.php /var/www/html/wordpress
26 +
27 +# Move PHP files
28 +mv ./tmp/input.php /var/www/html
29 +mv ./tmp/process.php /var/www/html
30 +mv ./tmp/highcharts.php /var/www/html
31 +mv ./tmp/socket.php /var/www/html
32 +
33 +# MariaDB configuration
34 +echo "CREATE USER 'haseo'@'localhost' IDENTIFIED BY 'haseo';" \
35 + | mysql -u root --skip-password
36 +
37 +echo "CREATE DATABASE wordpress;" \
38 + | mysql -u root --skip-password
39 +echo "GRANT ALL PRIVILEGES ON wordpress.* TO 'haseo'@'localhost' WITH GRANT OPTION;" \
40 + | mysql -u root --skip-password
41 +echo "FLUSH PRIVILEGES" \
42 + | mysql -u root --skip-password
43 +
44 +echo "CREATE DATABASE M2351;" \
45 + | mysql -u root --skip-password
46 +echo "GRANT ALL PRIVILEGES ON M2351.* TO 'haseo'@'localhost' WITH GRANT OPTION;" \
47 + | mysql -u root --skip-password
48 +echo "FLUSH PRIVILEGES" \
49 + | mysql -u root --skip-password
50 +
51 +
52 +# phpMyAdmin configuration
53 +tar -xvf ./tmp/phpMyAdmin-4.9.7-all-languages.tar.gz
54 +rm ./tmp/phpMyAdmin-4.9.7-all-languages.tar.gz
55 +mv phpMyAdmin-4.9.7-all-languages phpmyadmin
56 +mv phpmyadmin /var/www/html/
57 +cp ./tmp/config.inc.php /var/www/html/phpmyadmin/
58 +mysql < /var/www/html/phpmyadmin/sql/create_tables.sql
59 +
60 +# permission setting
61 +chown -R www-data:www-data /var/www/*
62 +find /var/www -type d -exec chmod 755 {} \;
63 +find /var/www -type f -exec chmod 644 {} \;
64 +
65 +# service start
66 +service nginx start
67 +service mysql restart
68 +service php7.3-fpm start
69 +service php7.3-fpm status
70 +
71 +bash
1 +#!/usr/local/bin/php -q
2 +
3 +<?php
4 +
5 +define("_IP", "127.0.0.1");
6 +define("_PORT", "2351");
7 +
8 +$sSock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
9 +socket_bind($sSock, _IP, _PORT);
10 +socket_listen($sSock);
11 +
12 +while($cSock = socket_accept($sSock))
13 +{
14 + socket_getpeername($cSock, $addr, $port);
15 + echo "SERVER >> client connected $addr:$port \n";
16 + $date = date("Y/m/d H:i:s");
17 + socket_write($cSock, $date);
18 + socket_close($cSock);
19 + echo "SERVER >> client Close.\n";
20 +}
21 +
22 +?>
1 +#define SERV_TCP_PORT (2351)
2 +#define SERV_HOST_ADDR "127.0.0.1"
3 +
4 +typedef struct {
5 + char data[64];
6 +}
7 + MsgType;
1 +// TCP sockek example
2 +// TCP server
3 +#include <stdio.h>
4 +#include <sys/types.h>
5 +#include <sys/socket.h>
6 +#include <netinet/in.h>
7 +#include <arpa/inet.h>
8 +#include <signal.h>
9 +#include "tcp.h"
10 +#include <stdlib.h>
11 +#include <unistd.h>
12 +#include <string.h>
13 +
14 +int Sockfd;
15 +
16 +void CloseServer()
17 +{
18 + close(Sockfd);
19 + printf("\nTCP Server exit.....\n");
20 +
21 + exit(0);
22 +}
23 +
24 +void main(int argc, char *argv[])
25 +{
26 + int newSockfd, cliAddrLen, n;
27 + struct sockaddr_in cliAddr, servAddr; // PF_INET, IPv4
28 + MsgType msg;
29 +
30 + // register a signal handler
31 + signal(SIGINT, CloseServer);
32 +
33 + // SOCKET
34 + // create a socket for TCP
35 + if ((Sockfd = socket(PF_INET, SOCK_STREAM, 0)) < 0)
36 + {
37 + perror("socket");
38 + exit(1);
39 + }
40 +
41 + // initailize a servAddr
42 + bzero((char *)&servAddr, sizeof(servAddr));
43 + servAddr.sin_family = PF_INET; //protocol family
44 + servAddr.sin_addr.s_addr = htonl(INADDR_ANY); // network byte ordered 32-bit address
45 + // receive any IP addresses
46 + servAddr.sin_port = htons(SERV_TCP_PORT);
47 +
48 + // BIND
49 + if (bind(Sockfd, (struct sockaddr *)&servAddr, sizeof(servAddr)) < 0)
50 + {
51 + perror("bind");
52 + exit(1);
53 + }
54 +
55 + // LISTEN
56 + listen(Sockfd, 5);
57 +
58 + printf("TCP Server started.....\n");
59 +
60 + // kernel allocate a cliAddr ifself
61 + cliAddrLen = sizeof(cliAddr);
62 +
63 + while (1)
64 + {
65 + memset(&msg, 0, sizeof(MsgType));
66 + // ACCEPT
67 + newSockfd = accept(Sockfd, (struct sockaddr *)&cliAddr, &cliAddrLen);
68 + if (newSockfd < 0)
69 + {
70 + perror("accept");
71 + exit(1);
72 + }
73 + printf("Accept a new socket\n");
74 +
75 + // READ
76 + if ((n = read(newSockfd, (char *)&msg, sizeof(msg))) < 0)
77 + {
78 + perror("read");
79 + exit(1);
80 + }
81 + printf("Received message from M2351: %s\n", msg.data);
82 +
83 + // WRITE
84 + //sprintf(msg.data, "This is a reply from %d.", getpid());
85 + char aesKey[20] = {0x61, 0x62, 0x63, 0x64, 0x65,
86 + 0x66, 0x67, 0x68, 0x69, 0x6a,
87 + 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
88 + 0x70, 0x71, 0x72, 0x73, 0x74};
89 +
90 + strcpy(msg.data, aesKey);
91 + printf("aesKey : %s\n", msg.data);
92 + if (write(newSockfd, (char *)&msg, sizeof(msg)) < 0)
93 + {
94 + perror("write");
95 + exit(1);
96 + }
97 +
98 + printf("Replied.\n");
99 +
100 + usleep(5000);
101 + // CLOSE
102 + close(newSockfd);
103 + }
104 +}
This file is too large to display.
1 +<?php
2 +/**
3 + * The base configuration for WordPress
4 + *
5 + * The wp-config.php creation script uses this file during the
6 + * installation. You don't have to use the web site, you can
7 + * copy this file to "wp-config.php" and fill in the values.
8 + *
9 + * This file contains the following configurations:
10 + *
11 + * * MySQL settings
12 + * * Secret keys
13 + * * Database table prefix
14 + * * ABSPATH
15 + *
16 + * @link https://wordpress.org/support/article/editing-wp-config-php/
17 + *
18 + * @package WordPress
19 + */
20 +
21 +// ** MySQL settings - You can get this info from your web host ** //
22 +/** The name of the database for WordPress */
23 +define( 'DB_NAME', 'wordpress' );
24 +
25 +/** MySQL database username */
26 +define( 'DB_USER', 'haseo' );
27 +
28 +/** MySQL database password */
29 +define( 'DB_PASSWORD', 'haseo' );
30 +
31 +/** MySQL hostname */
32 +define( 'DB_HOST', 'localhost' );
33 +
34 +/** Database Charset to use in creating database tables. */
35 +define( 'DB_CHARSET', 'utf8' );
36 +
37 +/** The Database Collate type. Don't change this if in doubt. */
38 +define( 'DB_COLLATE', '' );
39 +
40 +/**#@+
41 + * Authentication Unique Keys and Salts.
42 + *
43 + * Change these to different unique phrases!
44 + * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}
45 + * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
46 + *
47 + * @since 2.6.0
48 + */
49 +define( 'AUTH_KEY', 'put your unique phrase here' );
50 +define( 'SECURE_AUTH_KEY', 'put your unique phrase here' );
51 +define( 'LOGGED_IN_KEY', 'put your unique phrase here' );
52 +define( 'NONCE_KEY', 'put your unique phrase here' );
53 +define( 'AUTH_SALT', 'put your unique phrase here' );
54 +define( 'SECURE_AUTH_SALT', 'put your unique phrase here' );
55 +define( 'LOGGED_IN_SALT', 'put your unique phrase here' );
56 +define( 'NONCE_SALT', 'put your unique phrase here' );
57 +
58 +/**#@-*/
59 +
60 +/**
61 + * WordPress Database Table prefix.
62 + *
63 + * You can have multiple installations in one database if you give each
64 + * a unique prefix. Only numbers, letters, and underscores please!
65 + */
66 +$table_prefix = 'wp_';
67 +
68 +/**
69 + * For developers: WordPress debugging mode.
70 + *
71 + * Change this to true to enable the display of notices during development.
72 + * It is strongly recommended that plugin and theme developers use WP_DEBUG
73 + * in their development environments.
74 + *
75 + * For information on other constants that can be used for debugging,
76 + * visit the documentation.
77 + *
78 + * @link https://wordpress.org/support/article/debugging-in-wordpress/
79 + */
80 +define( 'WP_DEBUG', false );
81 +
82 +/* That's all, stop editing! Happy publishing. */
83 +
84 +/** Absolute path to the WordPress directory. */
85 +if ( ! defined( 'ABSPATH' ) ) {
86 + define( 'ABSPATH', __DIR__ . '/' );
87 +}
88 +
89 +/** Sets up WordPress vars and included files. */
90 +require_once ABSPATH . 'wp-settings.php';