Skip to content

Commit a5d494d

Browse files
PR #492: Fix MQTT client network integration and buffer handling
Co-Authored-By: [email protected] <[email protected]>
1 parent 0003ef3 commit a5d494d

File tree

8 files changed

+424
-327
lines changed

8 files changed

+424
-327
lines changed
Lines changed: 106 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,133 @@
11
cmake_minimum_required(VERSION 3.13)
2-
project(freertos_wolfssl_demo C)
2+
project(freertos_sim C)
33

4-
# Set C standard
5-
set(CMAKE_C_STANDARD 11)
6-
set(CMAKE_C_STANDARD_REQUIRED ON)
4+
# Set build type if not specified
5+
if(NOT CMAKE_BUILD_TYPE)
6+
set(CMAKE_BUILD_TYPE Debug)
7+
endif()
78

8-
# Configure certificate paths
9-
set(WOLFSSL_CERTS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../wolfssl/certs")
9+
# FreeRTOS source files
10+
set(FREERTOS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/freertos")
11+
set(FREERTOS_KERNEL_DIR "${FREERTOS_DIR}/FreeRTOS-Kernel")
12+
13+
# wolfSSL directories
14+
set(WOLFSSL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../wolfssl")
15+
set(WOLFIP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../wolfip")
16+
set(WOLFMQTT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../wolfMQTT")
17+
18+
# Certificate paths
19+
set(WOLFSSL_CERTS_DIR "${WOLFSSL_DIR}/certs")
20+
21+
# Add definitions for certificate paths
1022
add_definitions(
11-
-DWOLFSSL_USER_SETTINGS
1223
-DMQTT_TLS_CA_CERT="${WOLFSSL_CERTS_DIR}/ca-cert.pem"
1324
-DMQTT_TLS_CLIENT_CERT="${WOLFSSL_CERTS_DIR}/client-cert.pem"
1425
-DMQTT_TLS_CLIENT_KEY="${WOLFSSL_CERTS_DIR}/client-key.pem"
1526
)
1627

17-
# FreeRTOS Kernel source files for POSIX port
18-
set(FREERTOS_PORT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/freertos/FreeRTOS-Kernel/portable/ThirdParty/GCC/Posix)
19-
set(FREERTOS_HEAP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/freertos/FreeRTOS-Kernel/portable/MemMang)
28+
# wolfSSL configuration
29+
add_definitions(
30+
-DWOLFSSL_USER_SETTINGS
31+
-DHAVE_TLS_EXTENSIONS
32+
-DHAVE_SUPPORTED_CURVES
33+
-DTFM_TIMING_RESISTANT
34+
-DECC_TIMING_RESISTANT
35+
-DWC_RSA_BLINDING
36+
-DHAVE_AESGCM
37+
-DHAVE_CHACHA
38+
-DHAVE_POLY1305
39+
-DHAVE_ECC
40+
-DHAVE_CURVE25519
41+
-DHAVE_ED25519
42+
)
2043

21-
# Include directories
22-
include_directories(
23-
${CMAKE_CURRENT_SOURCE_DIR}/include
24-
${CMAKE_CURRENT_SOURCE_DIR}/freertos/FreeRTOS-Kernel/include
25-
${FREERTOS_PORT_DIR}
26-
${CMAKE_CURRENT_SOURCE_DIR}/../../../wolfip/src
27-
${CMAKE_CURRENT_SOURCE_DIR}/../../../wolfip
28-
${CMAKE_CURRENT_SOURCE_DIR}/../../../wolfip/src/http
29-
${CMAKE_CURRENT_SOURCE_DIR}/../../../wolfip/src/port
30-
${CMAKE_CURRENT_SOURCE_DIR}/../../../wolfssl
31-
${CMAKE_CURRENT_SOURCE_DIR}/../../../wolfssl/include
32-
${CMAKE_CURRENT_SOURCE_DIR}/../../../wolfMQTT
44+
# wolfIP definitions
45+
add_definitions(
46+
-DLINK_MTU=1500
47+
-DRXBUF_SIZE=8192
48+
-DTXBUF_SIZE=8192
49+
-DMAX_TCPSOCKETS=8
50+
-DMAX_UDPSOCKETS=8
51+
-DMAX_TIMERS=24
52+
-DWOLFIP_DEBUG
53+
-DWOLFSSL_DEBUG
54+
-DWOLFMQTT_DEBUG
55+
-DETH_TYPE_IP=0x0800
3356
)
3457

3558
# FreeRTOS source files
36-
set(FREERTOS_SOURCES
37-
${CMAKE_CURRENT_SOURCE_DIR}/freertos/FreeRTOS-Kernel/tasks.c
38-
${CMAKE_CURRENT_SOURCE_DIR}/freertos/FreeRTOS-Kernel/queue.c
39-
${CMAKE_CURRENT_SOURCE_DIR}/freertos/FreeRTOS-Kernel/list.c
40-
${CMAKE_CURRENT_SOURCE_DIR}/freertos/FreeRTOS-Kernel/timers.c
41-
${CMAKE_CURRENT_SOURCE_DIR}/freertos/FreeRTOS-Kernel/event_groups.c
42-
${CMAKE_CURRENT_SOURCE_DIR}/freertos/FreeRTOS-Kernel/stream_buffer.c
43-
${FREERTOS_PORT_DIR}/port.c
44-
${FREERTOS_HEAP_DIR}/heap_3.c
45-
${CMAKE_CURRENT_SOURCE_DIR}/freertos/utils/utils.c
59+
set(FREERTOS_SRC
60+
${FREERTOS_KERNEL_DIR}/tasks.c
61+
${FREERTOS_KERNEL_DIR}/queue.c
62+
${FREERTOS_KERNEL_DIR}/list.c
63+
${FREERTOS_KERNEL_DIR}/timers.c
64+
${FREERTOS_KERNEL_DIR}/event_groups.c
65+
${FREERTOS_KERNEL_DIR}/stream_buffer.c
66+
${FREERTOS_KERNEL_DIR}/portable/ThirdParty/GCC/Posix/port.c
67+
${FREERTOS_KERNEL_DIR}/portable/MemMang/heap_3.c
68+
${FREERTOS_DIR}/utils/utils.c
4669
)
4770

48-
# Add wolfIP library
49-
add_library(wolfip STATIC
50-
${CMAKE_CURRENT_SOURCE_DIR}/../../../wolfip/src/wolfip.c
51-
${CMAKE_CURRENT_SOURCE_DIR}/../../../wolfip/src/http/httpd.c
52-
${CMAKE_CURRENT_SOURCE_DIR}/../../../wolfip/src/port/wolfssl_io.c
71+
# wolfIP source files
72+
set(WOLFIP_SRC
73+
${WOLFIP_DIR}/src/wolfip.c
74+
${WOLFIP_DIR}/src/fifo.c
75+
${WOLFIP_DIR}/src/http/httpd.c
76+
${WOLFIP_DIR}/src/port/wolfssl_io.c
77+
${WOLFIP_DIR}/src/port/posix/linux_tap.c
78+
${WOLFIP_DIR}/src/port/posix/bsd_socket.c
5379
)
5480

55-
# Add the main application
56-
add_executable(freertos_sim
57-
${FREERTOS_SOURCES}
81+
# Application source files
82+
set(APP_SRC
5883
src/main.c
5984
src/wolfip_freertos.c
6085
src/mqtt_client.c
6186
src/mqtt_net.c
87+
src/wolfip_utils.c
88+
)
89+
90+
# Include directories
91+
include_directories(
92+
${CMAKE_CURRENT_SOURCE_DIR}/include
93+
${FREERTOS_KERNEL_DIR}/include
94+
${FREERTOS_KERNEL_DIR}/portable/ThirdParty/GCC/Posix
95+
${WOLFSSL_DIR}
96+
${WOLFIP_DIR}
97+
${WOLFIP_DIR}/src/include
98+
${WOLFMQTT_DIR}
99+
)
100+
101+
# Create static library for wolfIP
102+
add_library(wolfip STATIC ${WOLFIP_SRC})
103+
104+
# Set compiler flags for wolfIP library
105+
target_compile_options(wolfip PRIVATE
106+
-Wall
107+
-Wextra
108+
-g
109+
-fpack-struct
62110
)
63111

112+
# Create executable
113+
add_executable(freertos_sim
114+
${FREERTOS_SRC}
115+
${APP_SRC}
116+
)
117+
118+
# Link libraries
64119
target_link_libraries(freertos_sim
65-
pthread
66120
wolfip
67-
${CMAKE_CURRENT_SOURCE_DIR}/../../../wolfMQTT/src/.libs/libwolfmqtt.a
68-
${CMAKE_CURRENT_SOURCE_DIR}/../../../wolfssl/src/.libs/libwolfssl.a
121+
wolfssl
122+
wolfmqtt
123+
pthread
69124
m
70-
crypto
125+
)
126+
127+
# Compiler flags
128+
target_compile_options(freertos_sim PRIVATE
129+
-Wall
130+
-Wextra
131+
-g
132+
-fpack-struct
71133
)
Lines changed: 44 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,18 @@
1-
/* FreeRTOSConfig.h
2-
*
3-
* Copyright (C) 2006-2024 wolfSSL Inc.
4-
*
5-
* This file is part of wolfSSL.
6-
*
7-
* wolfSSL is free software; you can redistribute it and/or modify
8-
* it under the terms of the GNU General Public License as published by
9-
* the Free Software Foundation; either version 2 of the License, or
10-
* (at your option) any later version.
11-
*
12-
* wolfSSL is distributed in the hope that it will be useful,
13-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15-
* GNU General Public License for more details.
16-
*
17-
* You should have received a copy of the GNU General Public License
18-
* along with this program; if not, write to the Free Software
19-
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20-
*/
21-
221
#ifndef FREERTOS_CONFIG_H
232
#define FREERTOS_CONFIG_H
243

25-
/* Scheduler Related */
264
#define configUSE_PREEMPTION 1
275
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0
286
#define configUSE_TICKLESS_IDLE 0
29-
#define configCPU_CLOCK_HZ ( ( unsigned long ) 60000000 )
30-
#define configTICK_RATE_HZ ( ( TickType_t ) 1000 )
7+
#define configCPU_CLOCK_HZ 60000000
8+
#define configTICK_RATE_HZ 1000
319
#define configMAX_PRIORITIES 5
32-
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 4096 )
10+
#define configMINIMAL_STACK_SIZE 4096
3311
#define configMAX_TASK_NAME_LEN 16
3412
#define configUSE_16_BIT_TICKS 0
3513
#define configIDLE_SHOULD_YIELD 1
3614
#define configUSE_TASK_NOTIFICATIONS 1
37-
#define configTASK_NOTIFICATION_ARRAY_ENTRIES 3
15+
#define configTASK_NOTIFICATION_ARRAY_ENTRIES 3
3816
#define configUSE_MUTEXES 1
3917
#define configUSE_RECURSIVE_MUTEXES 1
4018
#define configUSE_COUNTING_SEMAPHORES 1
@@ -44,59 +22,60 @@
4422
#define configUSE_NEWLIB_REENTRANT 0
4523
#define configENABLE_BACKWARD_COMPATIBILITY 0
4624
#define configNUM_THREAD_LOCAL_STORAGE_POINTERS 5
47-
#define configUSE_MINI_LIST_ITEM 1
25+
#define configSTACK_DEPTH_TYPE uint32_t
26+
#define configMESSAGE_BUFFER_LENGTH_TYPE size_t
4827

4928
/* Memory allocation related definitions. */
50-
#define configSUPPORT_STATIC_ALLOCATION 0
51-
#define configSUPPORT_DYNAMIC_ALLOCATION 1
52-
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 60 * 1024 ) )
53-
#define configAPPLICATION_ALLOCATED_HEAP 0
29+
#define configSUPPORT_STATIC_ALLOCATION 0
30+
#define configSUPPORT_DYNAMIC_ALLOCATION 1
31+
#define configTOTAL_HEAP_SIZE 102400
32+
#define configAPPLICATION_ALLOCATED_HEAP 0
33+
#define configSTACK_ALLOCATION_FROM_SEPARATE_HEAP 0
5434

5535
/* Hook function related definitions. */
56-
#define configUSE_IDLE_HOOK 0
57-
#define configUSE_TICK_HOOK 0
58-
#define configCHECK_FOR_STACK_OVERFLOW 0
59-
#define configUSE_MALLOC_FAILED_HOOK 0
60-
#define configUSE_DAEMON_TASK_STARTUP_HOOK 0
36+
#define configUSE_IDLE_HOOK 0
37+
#define configUSE_TICK_HOOK 0
38+
#define configCHECK_FOR_STACK_OVERFLOW 0
39+
#define configUSE_MALLOC_FAILED_HOOK 0
40+
#define configUSE_DAEMON_TASK_STARTUP_HOOK 0
6141

6242
/* Run time and task stats gathering related definitions. */
63-
#define configGENERATE_RUN_TIME_STATS 0
64-
#define configUSE_TRACE_FACILITY 0
65-
#define configUSE_STATS_FORMATTING_FUNCTIONS 0
43+
#define configGENERATE_RUN_TIME_STATS 0
44+
#define configUSE_TRACE_FACILITY 0
45+
#define configUSE_STATS_FORMATTING_FUNCTIONS 0
6646

6747
/* Co-routine related definitions. */
68-
#define configUSE_CO_ROUTINES 0
69-
#define configMAX_CO_ROUTINE_PRIORITIES 1
48+
#define configUSE_CO_ROUTINES 0
49+
#define configMAX_CO_ROUTINE_PRIORITIES 1
7050

7151
/* Software timer related definitions. */
72-
#define configUSE_TIMERS 1
73-
#define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )
74-
#define configTIMER_QUEUE_LENGTH 10
75-
#define configTIMER_TASK_STACK_DEPTH configMINIMAL_STACK_SIZE
52+
#define configUSE_TIMERS 1
53+
#define configTIMER_TASK_PRIORITY (configMAX_PRIORITIES - 1)
54+
#define configTIMER_QUEUE_LENGTH 10
55+
#define configTIMER_TASK_STACK_DEPTH configMINIMAL_STACK_SIZE
7656

7757
/* Define to trap errors during development. */
78-
#define configASSERT( x )
58+
#define configASSERT(x) if((x) == 0) { taskDISABLE_INTERRUPTS(); for(;;); }
7959

8060
/* Optional functions - most linkers will remove unused functions anyway. */
81-
#define INCLUDE_vTaskPrioritySet 1
82-
#define INCLUDE_uxTaskPriorityGet 1
83-
#define INCLUDE_vTaskDelete 1
84-
#define INCLUDE_vTaskSuspend 1
85-
#define INCLUDE_xResumeFromISR 1
86-
#define INCLUDE_vTaskDelayUntil 1
87-
#define INCLUDE_vTaskDelay 1
88-
#define INCLUDE_xTaskGetSchedulerState 1
89-
#define INCLUDE_xTaskGetCurrentTaskHandle 1
90-
#define INCLUDE_uxTaskGetStackHighWaterMark 0
91-
#define INCLUDE_xTaskGetIdleTaskHandle 0
92-
#define INCLUDE_eTaskGetState 0
93-
#define INCLUDE_xEventGroupSetBitFromISR 1
94-
#define INCLUDE_xTimerPendFunctionCall 0
95-
#define INCLUDE_xTaskAbortDelay 0
96-
#define INCLUDE_xTaskGetHandle 0
97-
#define INCLUDE_xTaskResumeFromISR 1
61+
#define INCLUDE_vTaskPrioritySet 1
62+
#define INCLUDE_uxTaskPriorityGet 1
63+
#define INCLUDE_vTaskDelete 1
64+
#define INCLUDE_vTaskSuspend 1
65+
#define INCLUDE_xResumeFromISR 1
66+
#define INCLUDE_vTaskDelayUntil 1
67+
#define INCLUDE_vTaskDelay 1
68+
#define INCLUDE_xTaskGetSchedulerState 1
69+
#define INCLUDE_xTaskGetCurrentTaskHandle 1
70+
#define INCLUDE_uxTaskGetStackHighWaterMark 0
71+
#define INCLUDE_xTaskGetIdleTaskHandle 0
72+
#define INCLUDE_eTaskGetState 0
73+
#define INCLUDE_xEventGroupSetBitFromISR 1
74+
#define INCLUDE_xTimerPendFunctionCall 0
75+
#define INCLUDE_xTaskAbortDelay 0
76+
#define INCLUDE_xTaskGetHandle 0
77+
#define INCLUDE_xTaskResumeFromISR 1
9878

99-
/* POSIX Port specific definitions. */
100-
#define configPOSIX_STACK_SIZE ( ( unsigned short ) 8192 )
79+
/* A header file that defines trace macro can be included here. */
10180

10281
#endif /* FREERTOS_CONFIG_H */

0 commit comments

Comments
 (0)