example code cleanup; confirm working w/ ESP-IDF v5.0

pull/360/head
gojimmypi 2023-01-02 17:12:21 -08:00
parent 3661692c13
commit 7e26aac247
17 changed files with 1973 additions and 4069 deletions

15
.gitignore vendored
View File

@ -304,3 +304,18 @@ tpm/evp_tpm
**/main/build/CMakeFiles/* **/main/build/CMakeFiles/*
**/build/* **/build/*
# VisualGDB
**/.visualgdb
# Espressif sdk config default should be saved in sdkconfig.defaults
# we won't track the actual working sdkconfig files
/ESP32/**/sdkconfig
/ESP32/**/sdkconfig.old
/ESP32/**/sdkconfig.bak
# the solution files are not needed (Visual Studio will generated them)
/ESP32/**/*.sln
# auto-created CMake backups
**/CMakeLists.txt.old

View File

@ -1,5 +1,12 @@
# wolfSSL ESP32 Examples # wolfSSL ESP32 Examples
These are wolfSSL TLS 1.3 clients and servers for both wired and wireless Internet.
Note: wolfSSL v5.5.4 or newer is needed to use these examples with ESP-IDF v5.
See the [setup scripts](https://github.com/wolfSSL/wolfssl/tree/master/IDE/Espressif/ESP-IDF) to install.
## ESP32 TLS 1.3 Server ## ESP32 TLS 1.3 Server
- [Wireless STA server](./TLS13-wifi_station-server/README.md) - [Wireless STA server](./TLS13-wifi_station-server/README.md)
@ -39,7 +46,7 @@ coming soon:
## ESP-IDF ## ESP-IDF
Although the examples were created using VisualGDB extension for Visual Studio, the Although the examples were created using VisualGDB extension for Visual Studio, the
examples can be compiled using the ESP-IDF. examples can of course be compiled using the ESP-IDF `idf.py`.
Once the EDP-IDF is installed, use the [setp_win.bat](https://github.com/wolfSSL/wolfssl/blob/master/IDE/Espressif/ESP-IDF/setup_win.bat) to copy wolfSSL files to Once the EDP-IDF is installed, use the [setp_win.bat](https://github.com/wolfSSL/wolfssl/blob/master/IDE/Espressif/ESP-IDF/setup_win.bat) to copy wolfSSL files to
the `esp-idf\components` directory, typically in the `esp-idf\components` directory, typically in
@ -54,12 +61,39 @@ cd wolfssl\IDE\Espressif\ESP-IDF\
.\setup_win.bat .\setup_win.bat
``` ```
# Tips Build with VisualGDB toolchain from WSL
```
. /mnt/c/SysGCC/esp32/esp-idf/v5.0/export.sh
idf.py -b 115200 -p /dev/ttyS15 build flash monitor
```
## Tips
If JTAG gets into a mode where it is simply always returning an error (app continually resetting) If JTAG gets into a mode where it is simply always returning an error (app continually resetting)
try using serial port to program a basic, operational ["hello world"](./ESP32-hello-world/README.md). try using serial port to program a basic, operational ["hello world"](./ESP32-hello-world/README.md).
The Arduino IDE or command-line ESP-IDF can be handy here. The Arduino IDE or command-line ESP-IDF can be handy here.
## Toolchain Switching in VisualGDB
Due to occasional difficulty in switching between toolchains, separate VisualGDB solution
files are included for ESP-IDF v4.4.1 and v5.0.
See the `ProjectModeSettings` of the respective .`vgdbproj` file:
```
<ESPIDFExtension>
<IDFCheckout>
<Version>release/v5.0</Version>
<Subdirectory>esp-idf/v5.0</Subdirectory>
<Type>ESPIDF</Type>
</IDFCheckout>
<COMPort>COM20</COMPort>
<SuppressTestPrerequisiteChecks>false</SuppressTestPrerequisiteChecks>
<UseCCache>false</UseCCache>
<DeviceID>ESP32</DeviceID>
</ESPIDFExtension>
```
## See also: ## See also:

View File

@ -1,47 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31729.503
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7087FBCD-E3BF-44F5-BA16-5A9B41782406}"
ProjectSection(SolutionItems) = preProject
README-output.txt = README-output.txt
README.md = README.md
EndProjectSection
EndProject
Project("{803FD0C6-D64E-4E16-9DC3-1DAEC859A3D2}") = "TLS13-ENC28J60-server", "TLS13-ENC28J60-server\TLS13-ENC28J60-server.vgdbproj", "{78B33F2B-5B03-4D34-BAF6-82060DD9FA8F}"
EndProject
Project("{803FD0C6-D64E-4E16-9DC3-1DAEC859A3D2}") = "TLS13-enc28j60-client", "TLS13-ENC28J60-client\TLS13-enc28j60-client.vgdbproj", "{67AFCF00-979E-40FB-AE8A-CDEB4F8EE7DC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|VisualGDB = Debug|VisualGDB
Release|VisualGDB = Release|VisualGDB
Tests (Debug)|VisualGDB = Tests (Debug)|VisualGDB
Tests (Release)|VisualGDB = Tests (Release)|VisualGDB
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{78B33F2B-5B03-4D34-BAF6-82060DD9FA8F}.Debug|VisualGDB.ActiveCfg = Debug|VisualGDB
{78B33F2B-5B03-4D34-BAF6-82060DD9FA8F}.Debug|VisualGDB.Build.0 = Debug|VisualGDB
{78B33F2B-5B03-4D34-BAF6-82060DD9FA8F}.Release|VisualGDB.ActiveCfg = Release|VisualGDB
{78B33F2B-5B03-4D34-BAF6-82060DD9FA8F}.Release|VisualGDB.Build.0 = Release|VisualGDB
{78B33F2B-5B03-4D34-BAF6-82060DD9FA8F}.Tests (Debug)|VisualGDB.ActiveCfg = Tests (Debug)|VisualGDB
{78B33F2B-5B03-4D34-BAF6-82060DD9FA8F}.Tests (Debug)|VisualGDB.Build.0 = Tests (Debug)|VisualGDB
{78B33F2B-5B03-4D34-BAF6-82060DD9FA8F}.Tests (Release)|VisualGDB.ActiveCfg = Tests (Release)|VisualGDB
{78B33F2B-5B03-4D34-BAF6-82060DD9FA8F}.Tests (Release)|VisualGDB.Build.0 = Tests (Release)|VisualGDB
{67AFCF00-979E-40FB-AE8A-CDEB4F8EE7DC}.Debug|VisualGDB.ActiveCfg = Debug|VisualGDB
{67AFCF00-979E-40FB-AE8A-CDEB4F8EE7DC}.Debug|VisualGDB.Build.0 = Debug|VisualGDB
{67AFCF00-979E-40FB-AE8A-CDEB4F8EE7DC}.Release|VisualGDB.ActiveCfg = Release|VisualGDB
{67AFCF00-979E-40FB-AE8A-CDEB4F8EE7DC}.Release|VisualGDB.Build.0 = Release|VisualGDB
{67AFCF00-979E-40FB-AE8A-CDEB4F8EE7DC}.Tests (Debug)|VisualGDB.ActiveCfg = Tests (Debug)|VisualGDB
{67AFCF00-979E-40FB-AE8A-CDEB4F8EE7DC}.Tests (Debug)|VisualGDB.Build.0 = Tests (Debug)|VisualGDB
{67AFCF00-979E-40FB-AE8A-CDEB4F8EE7DC}.Tests (Release)|VisualGDB.ActiveCfg = Tests (Release)|VisualGDB
{67AFCF00-979E-40FB-AE8A-CDEB4F8EE7DC}.Tests (Release)|VisualGDB.Build.0 = Tests (Release)|VisualGDB
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {65BE29BE-BAE2-4235-9F23-0B1E199AB7BB}
EndGlobalSection
EndGlobal

View File

@ -1,37 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31729.503
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7087FBCD-E3BF-44F5-BA16-5A9B41782406}"
ProjectSection(SolutionItems) = preProject
README-output.txt = README-output.txt
README.md = README.md
EndProjectSection
EndProject
Project("{803FD0C6-D64E-4E16-9DC3-1DAEC859A3D2}") = "TLS13-wifi_station-client", "TLS13-wifi_station-client\TLS13-wifi_station-client.vgdbproj", "{4904362E-3B9F-44CC-9C44-740B27FDFBE5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|VisualGDB = Debug|VisualGDB
Release|VisualGDB = Release|VisualGDB
Tests (Debug)|VisualGDB = Tests (Debug)|VisualGDB
Tests (Release)|VisualGDB = Tests (Release)|VisualGDB
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4904362E-3B9F-44CC-9C44-740B27FDFBE5}.Debug|VisualGDB.ActiveCfg = Debug|VisualGDB
{4904362E-3B9F-44CC-9C44-740B27FDFBE5}.Debug|VisualGDB.Build.0 = Debug|VisualGDB
{4904362E-3B9F-44CC-9C44-740B27FDFBE5}.Release|VisualGDB.ActiveCfg = Release|VisualGDB
{4904362E-3B9F-44CC-9C44-740B27FDFBE5}.Release|VisualGDB.Build.0 = Release|VisualGDB
{4904362E-3B9F-44CC-9C44-740B27FDFBE5}.Tests (Debug)|VisualGDB.ActiveCfg = Tests (Debug)|VisualGDB
{4904362E-3B9F-44CC-9C44-740B27FDFBE5}.Tests (Debug)|VisualGDB.Build.0 = Tests (Debug)|VisualGDB
{4904362E-3B9F-44CC-9C44-740B27FDFBE5}.Tests (Release)|VisualGDB.ActiveCfg = Tests (Release)|VisualGDB
{4904362E-3B9F-44CC-9C44-740B27FDFBE5}.Tests (Release)|VisualGDB.Build.0 = Tests (Release)|VisualGDB
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {65BE29BE-BAE2-4235-9F23-0B1E199AB7BB}
EndGlobalSection
EndGlobal

View File

@ -1,31 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31729.503
MinimumVisualStudioVersion = 10.0.40219.1
Project("{803FD0C6-D64E-4E16-9DC3-1DAEC859A3D2}") = "TLS13-client", "TLS13-client.vgdbproj", "{4904362E-3B9F-44CC-9C44-740B27FDFBE5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|VisualGDB = Debug|VisualGDB
Release|VisualGDB = Release|VisualGDB
Tests (Debug)|VisualGDB = Tests (Debug)|VisualGDB
Tests (Release)|VisualGDB = Tests (Release)|VisualGDB
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4904362E-3B9F-44CC-9C44-740B27FDFBE5}.Debug|VisualGDB.ActiveCfg = Debug|VisualGDB
{4904362E-3B9F-44CC-9C44-740B27FDFBE5}.Debug|VisualGDB.Build.0 = Debug|VisualGDB
{4904362E-3B9F-44CC-9C44-740B27FDFBE5}.Release|VisualGDB.ActiveCfg = Release|VisualGDB
{4904362E-3B9F-44CC-9C44-740B27FDFBE5}.Release|VisualGDB.Build.0 = Release|VisualGDB
{4904362E-3B9F-44CC-9C44-740B27FDFBE5}.Tests (Debug)|VisualGDB.ActiveCfg = Tests (Debug)|VisualGDB
{4904362E-3B9F-44CC-9C44-740B27FDFBE5}.Tests (Debug)|VisualGDB.Build.0 = Tests (Debug)|VisualGDB
{4904362E-3B9F-44CC-9C44-740B27FDFBE5}.Tests (Release)|VisualGDB.ActiveCfg = Tests (Release)|VisualGDB
{4904362E-3B9F-44CC-9C44-740B27FDFBE5}.Tests (Release)|VisualGDB.Build.0 = Tests (Release)|VisualGDB
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E0F17030-83D2-4967-AF75-777516FF525D}
EndGlobalSection
EndGlobal

View File

@ -1,31 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31729.503
MinimumVisualStudioVersion = 10.0.40219.1
Project("{803FD0C6-D64E-4E16-9DC3-1DAEC859A3D2}") = "TLS13-client", "TLS13-wifi_station-client.vgdbproj", "{4904362E-3B9F-44CC-9C44-740B27FDFBE5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|VisualGDB = Debug|VisualGDB
Release|VisualGDB = Release|VisualGDB
Tests (Debug)|VisualGDB = Tests (Debug)|VisualGDB
Tests (Release)|VisualGDB = Tests (Release)|VisualGDB
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4904362E-3B9F-44CC-9C44-740B27FDFBE5}.Debug|VisualGDB.ActiveCfg = Debug|VisualGDB
{4904362E-3B9F-44CC-9C44-740B27FDFBE5}.Debug|VisualGDB.Build.0 = Debug|VisualGDB
{4904362E-3B9F-44CC-9C44-740B27FDFBE5}.Release|VisualGDB.ActiveCfg = Release|VisualGDB
{4904362E-3B9F-44CC-9C44-740B27FDFBE5}.Release|VisualGDB.Build.0 = Release|VisualGDB
{4904362E-3B9F-44CC-9C44-740B27FDFBE5}.Tests (Debug)|VisualGDB.ActiveCfg = Tests (Debug)|VisualGDB
{4904362E-3B9F-44CC-9C44-740B27FDFBE5}.Tests (Debug)|VisualGDB.Build.0 = Tests (Debug)|VisualGDB
{4904362E-3B9F-44CC-9C44-740B27FDFBE5}.Tests (Release)|VisualGDB.ActiveCfg = Tests (Release)|VisualGDB
{4904362E-3B9F-44CC-9C44-740B27FDFBE5}.Tests (Release)|VisualGDB.Build.0 = Tests (Release)|VisualGDB
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E0F17030-83D2-4967-AF75-777516FF525D}
EndGlobalSection
EndGlobal

View File

@ -20,9 +20,10 @@
<Version> <Version>
<GCC>8.4.0</GCC> <GCC>8.4.0</GCC>
<GDB>8.1.0</GDB> <GDB>8.1.0</GDB>
<Revision>7</Revision> <Revision>9</Revision>
</Version> </Version>
</ToolchainID> </ToolchainID>
<RelativeSourceDirectory />
<ConfigurationType>DEBUG</ConfigurationType> <ConfigurationType>DEBUG</ConfigurationType>
<BinaryDirectory>build/$(PlatformName)/$(ConfigurationName)</BinaryDirectory> <BinaryDirectory>build/$(PlatformName)/$(ConfigurationName)</BinaryDirectory>
<MakeCommandTemplate> <MakeCommandTemplate>
@ -57,6 +58,7 @@
<BuildAllTargetsInSubdir>false</BuildAllTargetsInSubdir> <BuildAllTargetsInSubdir>false</BuildAllTargetsInSubdir>
<FoldSingleItemPathLevels>true</FoldSingleItemPathLevels> <FoldSingleItemPathLevels>true</FoldSingleItemPathLevels>
</ProjectItemSettings> </ProjectItemSettings>
<TargetSpecificSettings />
<SetLDLibraryPathFromDependentArtifacts>true</SetLDLibraryPathFromDependentArtifacts> <SetLDLibraryPathFromDependentArtifacts>true</SetLDLibraryPathFromDependentArtifacts>
<ProjectGUID>4904362e-3b9f-44cc-9c44-740b27fdfbe5</ProjectGUID> <ProjectGUID>4904362e-3b9f-44cc-9c44-740b27fdfbe5</ProjectGUID>
<VirtualFolders /> <VirtualFolders />
@ -65,8 +67,8 @@
<EnableFastUpToDateCheck>true</EnableFastUpToDateCheck> <EnableFastUpToDateCheck>true</EnableFastUpToDateCheck>
<ESPIDFExtension> <ESPIDFExtension>
<IDFCheckout> <IDFCheckout>
<Version>release/v4.4</Version> <Version>v4.4.1</Version>
<Subdirectory>esp-idf/v4.4</Subdirectory> <Subdirectory>esp-idf/v4.4.1</Subdirectory>
<Type>ESPIDF</Type> <Type>ESPIDF</Type>
</IDFCheckout> </IDFCheckout>
<COMPort>COM20</COMPort> <COMPort>COM20</COMPort>
@ -155,6 +157,7 @@
<ShowMessageAfterExecuting>true</ShowMessageAfterExecuting> <ShowMessageAfterExecuting>true</ShowMessageAfterExecuting>
</CustomShortcuts> </CustomShortcuts>
<UserDefinedVariables /> <UserDefinedVariables />
<ImportedPropertySheets />
<CodeSense> <CodeSense>
<Enabled>Unknown</Enabled> <Enabled>Unknown</Enabled>
<ExtraSettings> <ExtraSettings>
@ -177,6 +180,7 @@
<BuildSettingsExtension xsi:type="com.visualgdb.build.external.esp-idf.cmake.extension" /> <BuildSettingsExtension xsi:type="com.visualgdb.build.external.esp-idf.cmake.extension" />
</VisualGDBConfiguration> </VisualGDBConfiguration>
</Configurations> </Configurations>
<ProgramArgumentsSuggestions />
<Debug xsi:type="com.visualgdb.debug.embedded"> <Debug xsi:type="com.visualgdb.debug.embedded">
<AdditionalStartupCommands /> <AdditionalStartupCommands />
<AdditionalGDBSettings> <AdditionalGDBSettings>

View File

@ -0,0 +1,345 @@
<?xml version="1.0"?>
<VisualGDBProjectSettings2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Project xsi:type="com.visualgdb.project.external.esp-idf">
<CustomSourceDirectories>
<Directories />
<PathStyle>Unknown</PathStyle>
</CustomSourceDirectories>
<AutoProgramSPIFFSPartition>true</AutoProgramSPIFFSPartition>
<ProjectModeSettings>
<ProjectGUID>eb963948-ff31-4e03-878f-5cd21b92f36b</ProjectGUID>
<GroupSourcesByTypes>true</GroupSourcesByTypes>
<GroupSourcesByPaths>true</GroupSourcesByPaths>
<HeaderScanMode>SourceDirs</HeaderScanMode>
</ProjectModeSettings>
<TestSettings>
<InitializationTimeout>30</InitializationTimeout>
<DefaultTestTimeout>60</DefaultTestTimeout>
<ApptraceInitializationTimeout>5</ApptraceInitializationTimeout>
<FinalizationTimeout>5</FinalizationTimeout>
</TestSettings>
</Project>
<Build xsi:type="com.visualgdb.build.cmake">
<BuildLogMode xsi:nil="true" />
<ToolchainID>
<ID>com.visualgdb.xtensa-esp32-elf</ID>
<Version>
<GCC>11.2.0</GCC>
<GDB>9.2.90</GDB>
<Revision>2</Revision>
</Version>
</ToolchainID>
<RelativeSourceDirectory />
<ConfigurationType>DEBUG</ConfigurationType>
<BinaryDirectory>build/$(PlatformName)/$(ConfigurationName)</BinaryDirectory>
<MakeCommandTemplate>
<SkipWhenRunningCommandList>false</SkipWhenRunningCommandList>
<RemoteHost>
<HostName>BuildMachine</HostName>
<Transport>BuiltinShortcut</Transport>
</RemoteHost>
<Command>$(ToolchainNinja)</Command>
<WorkingDirectory>$(BuildDir)</WorkingDirectory>
<BackgroundMode xsi:nil="true" />
</MakeCommandTemplate>
<CMakeCommand>
<SkipWhenRunningCommandList>false</SkipWhenRunningCommandList>
<RemoteHost>
<HostName>BuildMachine</HostName>
<Transport>BuiltinShortcut</Transport>
</RemoteHost>
<Command>$(SYSPROGS_CMAKE_PATH)</Command>
<BackgroundMode xsi:nil="true" />
</CMakeCommand>
<UpdateSourcesInCMakeFile>true</UpdateSourcesInCMakeFile>
<ExportCompileCommands>false</ExportCompileCommands>
<DisableToolchainFile>false</DisableToolchainFile>
<CMakeMakefileType>Ninja</CMakeMakefileType>
<DeployAsRoot>false</DeployAsRoot>
<CMakeCleanMode>RemoveBuildDirectory</CMakeCleanMode>
<UseCCache>false</UseCCache>
<ProjectModeSettings>
<ProjectItemSettings>
<GroupSourcesByTypes>true</GroupSourcesByTypes>
<GroupSourcesByPaths>true</GroupSourcesByPaths>
<GroupTargetsByPaths>true</GroupTargetsByPaths>
<FollowCMakeSourceGroups>false</FollowCMakeSourceGroups>
<AutoRefreshProject>true</AutoRefreshProject>
<AlwaysConsiderOutdated>false</AlwaysConsiderOutdated>
<SortTargetsByName>true</SortTargetsByName>
<RedundantTargetMode>HideOuterProjectTargets</RedundantTargetMode>
<SortSourcesByName>true</SortSourcesByName>
<BuildAllTargetsInSubdir>false</BuildAllTargetsInSubdir>
<FoldSingleItemPathLevels>true</FoldSingleItemPathLevels>
</ProjectItemSettings>
<TargetSpecificSettings />
<SetLDLibraryPathFromDependentArtifacts>true</SetLDLibraryPathFromDependentArtifacts>
<ProjectGUID>4904362e-3b9f-44cc-9c44-740b27fdfbe5</ProjectGUID>
<VirtualFolders />
<ConfigurationNameCase>Upper</ConfigurationNameCase>
<DefaultHeaderDiscoveryMode>HeaderDirectoryAndSubdirectories</DefaultHeaderDiscoveryMode>
<EnableFastUpToDateCheck>true</EnableFastUpToDateCheck>
<ESPIDFExtension>
<IDFCheckout>
<Version>release/v5.0</Version>
<Subdirectory>esp-idf/v5.0</Subdirectory>
<Type>ESPIDF</Type>
</IDFCheckout>
<COMPort>COM20</COMPort>
<SuppressTestPrerequisiteChecks>false</SuppressTestPrerequisiteChecks>
<UseCCache>false</UseCCache>
<DeviceID>ESP32</DeviceID>
</ESPIDFExtension>
</ProjectModeSettings>
</Build>
<CustomBuild>
<PreSyncActions />
<PreBuildActions />
<PostBuildActions />
<PreCleanActions />
<PostCleanActions />
</CustomBuild>
<CustomDebug>
<PreDebugActions />
<PostDebugActions />
<DebugStopActions />
<BreakMode>Default</BreakMode>
<CustomBreakCommand>
<SkipWhenRunningCommandList>false</SkipWhenRunningCommandList>
<RemoteHost>
<HostName>BuildMachine</HostName>
<Transport>BuiltinShortcut</Transport>
</RemoteHost>
<BackgroundMode xsi:nil="true" />
</CustomBreakCommand>
</CustomDebug>
<DeviceTerminalSettings>
<Connection xsi:type="com.sysprogs.terminal.connection.serial">
<ComPortName>COM20</ComPortName>
<AdvancedSettings>
<BaudRate>115200</BaudRate>
<DataBits>8</DataBits>
<Parity>None</Parity>
<StopBits>One</StopBits>
<FlowControl>None</FlowControl>
</AdvancedSettings>
</Connection>
<LastConnectionTime>0</LastConnectionTime>
<EchoTypedCharacters>false</EchoTypedCharacters>
<ClearContentsWhenReconnecting>false</ClearContentsWhenReconnecting>
<ReconnectAutomatically>false</ReconnectAutomatically>
<DisplayMode>ASCII</DisplayMode>
<Colors>
<Background>
<Alpha>255</Alpha>
<Red>0</Red>
<Green>0</Green>
<Blue>0</Blue>
</Background>
<Disconnected>
<Alpha>255</Alpha>
<Red>169</Red>
<Green>169</Green>
<Blue>169</Blue>
</Disconnected>
<Text>
<Alpha>255</Alpha>
<Red>211</Red>
<Green>211</Green>
<Blue>211</Blue>
</Text>
<Echo>
<Alpha>255</Alpha>
<Red>144</Red>
<Green>238</Green>
<Blue>144</Blue>
</Echo>
<Inactive>
<Alpha>255</Alpha>
<Red>169</Red>
<Green>169</Green>
<Blue>169</Blue>
</Inactive>
</Colors>
<HexSettings>
<MaximumBytesPerLine>16</MaximumBytesPerLine>
<ShowTextView>true</ShowTextView>
<BreaksAroundEcho>true</BreaksAroundEcho>
<AutoSend>true</AutoSend>
<SendAsHex>true</SendAsHex>
<TimeoutForAutoBreak>0</TimeoutForAutoBreak>
</HexSettings>
<LineEnding>LF</LineEnding>
<TreatLFAsCRLF>false</TreatLFAsCRLF>
<KeepOpenAfterExit>false</KeepOpenAfterExit>
<ShowAfterProgramming>false</ShowAfterProgramming>
</DeviceTerminalSettings>
<CustomShortcuts>
<Shortcuts />
<ShowMessageAfterExecuting>true</ShowMessageAfterExecuting>
</CustomShortcuts>
<UserDefinedVariables />
<ImportedPropertySheets />
<CodeSense>
<Enabled>True</Enabled>
<ExtraSettings>
<HideErrorsInSystemHeaders>true</HideErrorsInSystemHeaders>
<SupportLightweightReferenceAnalysis>true</SupportLightweightReferenceAnalysis>
<DiscoverySettings>
<Mode>Enabled</Mode>
<SearchInProjectDir>true</SearchInProjectDir>
<SearchInSourceDirs>true</SearchInSourceDirs>
<SearchInIncludeSubdirs>true</SearchInIncludeSubdirs>
</DiscoverySettings>
<CheckForClangFormatFiles>true</CheckForClangFormatFiles>
<FormattingEngine xsi:nil="true" />
</ExtraSettings>
<CodeAnalyzerSettings>
<Enabled>false</Enabled>
<SelectedAnalyzers>
<string>apiModeling.google.GTest</string>
<string>core.builtin.BuiltinFunctions</string>
<string>core.builtin.NoReturnFunctions</string>
<string>core.CallAndMessage</string>
<string>core.DivideZero</string>
<string>core.DynamicTypePropagation</string>
<string>core.NonnilStringConstants</string>
<string>core.NonNullParamChecker</string>
<string>core.NullDereference</string>
<string>core.StackAddressEscape</string>
<string>core.UndefinedBinaryOperatorResult</string>
<string>core.uninitialized.ArraySubscript</string>
<string>core.uninitialized.Assign</string>
<string>core.uninitialized.Branch</string>
<string>core.uninitialized.CapturedBlockVariable</string>
<string>core.uninitialized.UndefReturn</string>
<string>core.VLASize</string>
<string>cplusplus.NewDelete</string>
<string>cplusplus.NewDeleteLeaks</string>
<string>cplusplus.SelfAssignment</string>
<string>deadcode.DeadStores</string>
<string>nullability.NullPassedToNonnull</string>
<string>nullability.NullReturnedFromNonnull</string>
<string>security.insecureAPI.getpw</string>
<string>security.insecureAPI.gets</string>
<string>security.insecureAPI.mkstemp</string>
<string>security.insecureAPI.mktemp</string>
<string>security.insecureAPI.UncheckedReturn</string>
<string>security.insecureAPI.vfork</string>
<string>unix.API</string>
<string>unix.cstring.BadSizeArg</string>
<string>unix.cstring.NullArg</string>
<string>unix.Malloc</string>
<string>unix.MallocSizeof</string>
<string>unix.MismatchedDeallocator</string>
<string>unix.StdCLibraryFunctions</string>
<string>unix.Vfork</string>
</SelectedAnalyzers>
<ExtraArguments>
<string>-analyzer-store=region</string>
<string>-analyzer-opt-analyze-nested-blocks</string>
<string>-analyzer-eagerly-assume</string>
</ExtraArguments>
</CodeAnalyzerSettings>
</CodeSense>
<Configurations>
<VisualGDBConfiguration>
<Name>Debug</Name>
<BuildSettingsExtension xsi:type="com.visualgdb.build.external.esp-idf.cmake.extension" />
</VisualGDBConfiguration>
<VisualGDBConfiguration>
<Name>Release</Name>
<BuildSettingsExtension xsi:type="com.visualgdb.build.external.esp-idf.cmake.extension" />
</VisualGDBConfiguration>
</Configurations>
<ProgramArgumentsSuggestions />
<Debug xsi:type="com.visualgdb.debug.embedded">
<AdditionalStartupCommands>
<GDBPreStartupCommands />
<GDBStartupCommands />
<GDBFinalizationCommands />
</AdditionalStartupCommands>
<AdditionalGDBSettings>
<Features>
<DisableAutoDetection>false</DisableAutoDetection>
<UseFrameParameter>false</UseFrameParameter>
<SimpleValuesFlagSupported>false</SimpleValuesFlagSupported>
<ListLocalsSupported>false</ListLocalsSupported>
<ByteLevelMemoryCommandsAvailable>false</ByteLevelMemoryCommandsAvailable>
<ThreadInfoSupported>false</ThreadInfoSupported>
<PendingBreakpointsSupported>false</PendingBreakpointsSupported>
<SupportTargetCommand>false</SupportTargetCommand>
<ReliableBreakpointNotifications>false</ReliableBreakpointNotifications>
</Features>
<EnableSmartStepping>false</EnableSmartStepping>
<FilterSpuriousStoppedNotifications>false</FilterSpuriousStoppedNotifications>
<ForceSingleThreadedMode>false</ForceSingleThreadedMode>
<UseAppleExtensions>false</UseAppleExtensions>
<CanAcceptCommandsWhileRunning>false</CanAcceptCommandsWhileRunning>
<MakeLogFile>false</MakeLogFile>
<IgnoreModuleEventsWhileStepping>true</IgnoreModuleEventsWhileStepping>
<UseRelativePathsOnly>false</UseRelativePathsOnly>
<ExitAction>None</ExitAction>
<DisableDisassembly>false</DisableDisassembly>
<ExamineMemoryWithXCommand>false</ExamineMemoryWithXCommand>
<StepIntoNewInstanceEntry>app_main</StepIntoNewInstanceEntry>
<ExamineRegistersInRawFormat>true</ExamineRegistersInRawFormat>
<DisableSignals>false</DisableSignals>
<EnableAsyncExecutionMode>false</EnableAsyncExecutionMode>
<AsyncModeSupportsBreakpoints>true</AsyncModeSupportsBreakpoints>
<TemporaryBreakConsolidationTimeout>0</TemporaryBreakConsolidationTimeout>
<EnableNonStopMode>false</EnableNonStopMode>
<MaxBreakpointLimit>0</MaxBreakpointLimit>
<EnableVerboseMode>true</EnableVerboseMode>
<EnablePrettyPrinters>false</EnablePrettyPrinters>
</AdditionalGDBSettings>
<DebugMethod>
<ID>openocd</ID>
<Configuration xsi:type="com.visualgdb.edp.openocd.settings.esp32">
<CommandLine>-f interface/tigard.cfg -c "adapter_khz 13000" -f target/esp32.cfg</CommandLine>
<ExtraParameters>
<Frequency xsi:nil="true" />
<BoostedFrequency xsi:nil="true" />
<ConnectUnderReset>false</ConnectUnderReset>
</ExtraParameters>
<LoadProgressGUIThreshold>131072</LoadProgressGUIThreshold>
<ProgramMode>Enabled</ProgramMode>
<StartupCommands>
<string>set remotetimeout 60</string>
<string>target remote :$$SYS:GDB_PORT$$</string>
<string>mon gdb_breakpoint_override hard</string>
<string>mon reset halt</string>
<string>load</string>
</StartupCommands>
<ProgramFLASHUsingExternalTool>false</ProgramFLASHUsingExternalTool>
<PreferredGDBPort>0</PreferredGDBPort>
<PreferredTelnetPort>0</PreferredTelnetPort>
<AlwaysPassSerialNumber>false</AlwaysPassSerialNumber>
<SelectedCoreIndex xsi:nil="true" />
<LiveMemoryTimeout>5000</LiveMemoryTimeout>
<SuggestionLogicRevision>1</SuggestionLogicRevision>
<CheckFLASHSize>true</CheckFLASHSize>
<FLASHSettings>
<Size>size2MB</Size>
<Frequency>freq40M</Frequency>
<Mode>DIO</Mode>
</FLASHSettings>
<PatchBootloader>true</PatchBootloader>
</Configuration>
</DebugMethod>
<AutoDetectRTOS>true</AutoDetectRTOS>
<SemihostingSupport>Disabled</SemihostingSupport>
<SemihostingPollingDelay>0</SemihostingPollingDelay>
<StepIntoEntryPoint>false</StepIntoEntryPoint>
<ReloadFirmwareOnReset>false</ReloadFirmwareOnReset>
<ValidateEndOfStackAddress>true</ValidateEndOfStackAddress>
<StopAtEntryPoint>false</StopAtEntryPoint>
<EnableVirtualHalts>false</EnableVirtualHalts>
<DynamicAnalysisSettings />
<EndOfStackSymbol>_estack</EndOfStackSymbol>
<TimestampProviderTicksPerSecond>0</TimestampProviderTicksPerSecond>
<KeepConsoleAfterExit>false</KeepConsoleAfterExit>
<UnusedStackFillPattern xsi:nil="true" />
<CheckInterfaceDrivers>true</CheckInterfaceDrivers>
</Debug>
</VisualGDBProjectSettings2>

View File

@ -35,7 +35,7 @@
#include <wolfssl/ssl.h> #include <wolfssl/ssl.h>
#ifdef WOLFSSL_TRACK_MEMORY #ifdef WOLFSSL_TRACK_MEMORY
#include <wolfssl/wolfcrypt/mem_track.h> #include <wolfssl/wolfcrypt/mem_track.h>
#endif #endif
@ -52,15 +52,17 @@
#define USE_MY_PRIVATE_CONFIG #define USE_MY_PRIVATE_CONFIG
#ifdef USE_MY_PRIVATE_CONFIG #ifdef USE_MY_PRIVATE_CONFIG
#include "/workspace/my_private_config.h" #include "/workspace/my_private_config.h"
#else #else
/* The examples use WiFi configuration that you can set via project configuration menu /*
** The examples use WiFi configuration that you can set via project
If you'd rather not, just change the below entries to strings with ** configuration menu
the config you want - ie #define EXAMPLE_WIFI_SSID "mywifissid" **
*/ ** If you'd rather not, just change the below entries to strings with
#define EXAMPLE_ESP_WIFI_SSID CONFIG_ESP_WIFI_SSID ** the config you want - ie #define EXAMPLE_WIFI_SSID "mywifissid"
#define EXAMPLE_ESP_WIFI_PASS CONFIG_ESP_WIFI_PASSWORD */
#define EXAMPLE_ESP_WIFI_SSID CONFIG_ESP_WIFI_SSID
#define EXAMPLE_ESP_WIFI_PASS CONFIG_ESP_WIFI_PASSWORD
#endif #endif
/* ESP lwip */ /* ESP lwip */
@ -72,7 +74,7 @@
#define TLS_SMP_CLIENT_TASK_WORDS 10240 #define TLS_SMP_CLIENT_TASK_WORDS 10240
#define TLS_SMP_CLIENT_TASK_PRIORITY 8 #define TLS_SMP_CLIENT_TASK_PRIORITY 8
#define TLS_SMP_TARGET_HOST "192.168.1.144" #define TLS_SMP_TARGET_HOST "192.168.25.114"
/* include certificates. Note that there is an experiation date! /* include certificates. Note that there is an experiation date!
@ -129,20 +131,31 @@ static void event_handler(void* arg, esp_event_base_t event_base,
{ {
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) { if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) {
esp_wifi_connect(); esp_wifi_connect();
} else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) { }
else {
if ( event_base == WIFI_EVENT
&&
event_id == WIFI_EVENT_STA_DISCONNECTED) {
/* WiFi disconnected event */
if (s_retry_num < EXAMPLE_ESP_MAXIMUM_RETRY) { if (s_retry_num < EXAMPLE_ESP_MAXIMUM_RETRY) {
esp_wifi_connect(); esp_wifi_connect();
s_retry_num++; s_retry_num++;
ESP_LOGI(TAG, "retry to connect to the AP"); ESP_LOGI(TAG, "retry to connect to the AP");
} else { }
else {
xEventGroupSetBits(s_wifi_event_group, WIFI_FAIL_BIT); xEventGroupSetBits(s_wifi_event_group, WIFI_FAIL_BIT);
} }
ESP_LOGI(TAG,"connect to the AP fail"); ESP_LOGI(TAG, "connect to the AP fail");
} else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) { } /* is WiFi disconnected event */
else {
if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data; ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data;
ESP_LOGI(TAG, "got ip:" IPSTR, IP2STR(&event->ip_info.ip)); ESP_LOGI(TAG, "got ip:" IPSTR, IP2STR(&event->ip_info.ip));
s_retry_num = 0; s_retry_num = 0;
xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT); xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT);
} /* is got IP event */
}
} }
} }
@ -150,7 +163,9 @@ int set_time() {
/* we'll also return a result code of zero */ /* we'll also return a result code of zero */
int res = 0; int res = 0;
//*ideally, we'd like to set time from network, but let's set a default time, just in case */ /* ideally, we'd like to set time from network,
** but let's set a default time, just in case
*/
struct tm timeinfo; struct tm timeinfo;
timeinfo.tm_year = 2022 - 1900; timeinfo.tm_year = 2022 - 1900;
timeinfo.tm_mon = 3; timeinfo.tm_mon = 3;
@ -270,17 +285,9 @@ int tls_smp_client_task() {
struct hostent *hp; struct hostent *hp;
struct ip4_addr *ip4_addr; struct ip4_addr *ip4_addr;
struct timeval tv_now;
WOLFSSL_ENTER("tls_smp_client_task"); WOLFSSL_ENTER("tls_smp_client_task");
/* see https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/system_time.html#overview */ /* see https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/system_time.html#overview */
// ret = gettimeofday(&tv_now, NULL);
/* 0x0005dcacd95af765 */
// int64_t time_us = (int64_t)tv_now.tv_sec * 1000000L + (int64_t)tv_now.tv_usec;
// WOLFSSL_MSG(time_us) ;
/* declare wolfSSL objects */ /* declare wolfSSL objects */
WOLFSSL_CTX *ctx = NULL; /* the wolfSSL context object*/ WOLFSSL_CTX *ctx = NULL; /* the wolfSSL context object*/
@ -288,9 +295,9 @@ int tls_smp_client_task() {
#ifdef DEBUG_WOLFSSL #ifdef DEBUG_WOLFSSL
WOLFSSL_MSG("Debug ON"); ESP_LOGI(TAG,"Debug ON");
wolfSSL_Debugging_ON(); wolfSSL_Debugging_ON();
//ShowCiphers(); /* ShowCiphers(); */
#endif #endif
@ -318,14 +325,14 @@ int tls_smp_client_task() {
if (*targetServer >= '1' && *targetServer <= '9') { if (*targetServer >= '1' && *targetServer <= '9') {
/* Get the server IPv4 address from the command line call */ /* Get the server IPv4 address from the command line call */
WOLFSSL_MSG("inet_pton"); ESP_LOGI(TAG,"inet_pton");
if ((ret = inet_pton(AF_INET, if ((ret = inet_pton(AF_INET,
TLS_SMP_TARGET_HOST, TLS_SMP_TARGET_HOST,
&servAddr.sin_addr)) != 1) { &servAddr.sin_addr)) != 1) {
ESP_LOGE(TAG, "ERROR: invalid address ret=%d\n", ret); ESP_LOGE(TAG, "ERROR: invalid address ret=%d\n", ret);
ret = WOLFSSL_FAILURE; ret = WOLFSSL_FAILURE;
WOLFSSL_ERROR_MSG("ERROR: invalid address\n"); ESP_LOGE(TAG, "ERROR: invalid address\n");
} }
} }
else { else {
@ -351,17 +358,17 @@ int tls_smp_client_task() {
*/ */
sockfd = socket(AF_INET, SOCK_STREAM, 0); sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd > 0) { if (sockfd > 0) {
WOLFSSL_MSG("socket creation successful\n"); ESP_LOGI(TAG,"socket creation successful\n");
} }
else { else {
// TODO show errno // TODO show errno
ret = WOLFSSL_FAILURE; ret = WOLFSSL_FAILURE;
WOLFSSL_ERROR_MSG("ERROR: failed to create a socket.\n"); ESP_LOGE(TAG, "ERROR: failed to create a socket.\n");
} }
} }
else { else {
/* a prior error occured */ /* a prior error occurred */
WOLFSSL_ERROR_MSG("Skipping socket create.\n"); ESP_LOGE(TAG, "Skipping socket create.\n");
} }
@ -383,19 +390,22 @@ int tls_smp_client_task() {
* Upon successful completion, connect() shall return 0; otherwise, * Upon successful completion, connect() shall return 0; otherwise,
* -1 shall be returned and errno set to indicate the error. * -1 shall be returned and errno set to indicate the error.
*/ */
int connectResult = connect(sockfd, (struct sockaddr*) &servAddr, sizeof(servAddr)); int connectResult = connect(sockfd,
(struct sockaddr*) &servAddr,
sizeof(servAddr)
);
if (0 == connectResult) { if (0 == connectResult) {
WOLFSSL_MSG("sockfd connect successful\n"); ESP_LOGI(TAG,"sockfd connect successful\n");
} }
else { else {
// TODO show errno // TODO show errno
WOLFSSL_ERROR_MSG("ERROR: socket connect failed\n"); ESP_LOGE(TAG, "ERROR: socket connect failed\n");
ret = WOLFSSL_FAILURE; ret = WOLFSSL_FAILURE;
} }
} }
else { else {
/* a prior error occured */ /* a prior error occurred */
WOLFSSL_ERROR_MSG("Skipping socket connect.\n"); ESP_LOGE(TAG, "Skipping socket connect.\n");
} }
@ -418,19 +428,19 @@ int tls_smp_client_task() {
*/ */
if (ret == WOLFSSL_SUCCESS) { if (ret == WOLFSSL_SUCCESS) {
/* only proceed if the prior step was successful */ /* only proceed if the prior step was successful */
WOLFSSL_MSG("calling wolfSSL_Init"); ESP_LOGI(TAG,"calling wolfSSL_Init");
ret = wolfSSL_Init(); ret = wolfSSL_Init();
if (ret == WOLFSSL_SUCCESS) { if (ret == WOLFSSL_SUCCESS) {
WOLFSSL_MSG("wolfSSL_Init successful\n"); ESP_LOGI(TAG,"wolfSSL_Init successful\n");
} }
else { else {
WOLFSSL_ERROR_MSG("ERROR: wolfSSL_Init failed\n"); ESP_LOGE(TAG, "ERROR: wolfSSL_Init failed\n");
} }
} }
else { else {
/* a prior error occured */ /* a prior error occurred */
WOLFSSL_ERROR_MSG("Skipping wolfSSL_Init\n"); ESP_LOGE(TAG, "Skipping wolfSSL_Init\n");
} }
@ -458,21 +468,21 @@ int tls_smp_client_task() {
if (ret == WOLFSSL_SUCCESS) { if (ret == WOLFSSL_SUCCESS) {
WOLFSSL_METHOD* method = wolfTLSv1_3_client_method(); WOLFSSL_METHOD* method = wolfTLSv1_3_client_method();
if (method == NULL) { if (method == NULL) {
WOLFSSL_ERROR_MSG("ERROR : failed to get wolfTLSv1_3_client_method.\n"); ESP_LOGE(TAG, "ERROR : failed to get wolfTLSv1_3_client_method.\n");
ret = WOLFSSL_FAILURE; ret = WOLFSSL_FAILURE;
} }
else { else {
ctx = wolfSSL_CTX_new(method); ctx = wolfSSL_CTX_new(method);
if (ctx == NULL) { if (ctx == NULL) {
WOLFSSL_ERROR_MSG("ERROR : failed to create WOLFSSL_CTX\n"); ESP_LOGE(TAG, "ERROR : failed to create WOLFSSL_CTX\n");
ret = WOLFSSL_FAILURE; ret = WOLFSSL_FAILURE;
} }
} }
} }
else { else {
/* a prior error occured */ /* a prior error occurred */
WOLFSSL_ERROR_MSG("skipping wolfSSL_CTX_new\n"); ESP_LOGE(TAG, "skipping wolfSSL_CTX_new\n");
} }
@ -515,22 +525,22 @@ int tls_smp_client_task() {
*************************************************************************** ***************************************************************************
*/ */
if (ret == WOLFSSL_SUCCESS) { if (ret == WOLFSSL_SUCCESS) {
WOLFSSL_MSG("Loading cert"); ESP_LOGI(TAG, "Loading cert");
ret = wolfSSL_CTX_use_certificate_buffer(ctx, ret = wolfSSL_CTX_use_certificate_buffer(ctx,
CERT_FILE, CERT_FILE,
sizeof_CERT_FILE(), sizeof_CERT_FILE(),
WOLFSSL_FILETYPE_PEM); WOLFSSL_FILETYPE_PEM);
if (ret == WOLFSSL_SUCCESS) { if (ret == WOLFSSL_SUCCESS) {
WOLFSSL_MSG("wolfSSL_CTX_use_certificate_buffer successful\n"); ESP_LOGI(TAG, "wolfSSL_CTX_use_certificate_buffer successful\n");
} }
else { else {
WOLFSSL_ERROR_MSG("ERROR: wolfSSL_CTX_use_certificate_buffer failed\n"); ESP_LOGE(TAG, "ERROR: wolfSSL_CTX_use_certificate_buffer failed\n");
} }
} }
else { else {
/* a prior error occured */ /* a prior error occurred */
WOLFSSL_ERROR_MSG("skipping wolfSSL_CTX_use_certificate_buffer\n"); ESP_LOGE(TAG, "skipping wolfSSL_CTX_use_certificate_buffer\n");
} }
@ -582,16 +592,16 @@ int tls_smp_client_task() {
sizeof_KEY_FILE(), sizeof_KEY_FILE(),
WOLFSSL_FILETYPE_PEM); WOLFSSL_FILETYPE_PEM);
if (ret == WOLFSSL_SUCCESS) { if (ret == WOLFSSL_SUCCESS) {
WOLFSSL_MSG("wolfSSL_CTX_use_PrivateKey_buffer successful\n"); ESP_LOGI(TAG, "wolfSSL_CTX_use_PrivateKey_buffer successful\n");
} }
else { else {
/* TODO fetch and print expiration date since it is a common fail */ /* TODO fetch and print expiration date since it is a common fail */
WOLFSSL_ERROR_MSG("ERROR: wolfSSL_CTX_use_PrivateKey_buffer failed\n"); ESP_LOGE(TAG, "ERROR: wolfSSL_CTX_use_PrivateKey_buffer failed\n");
} }
} }
else { else {
/* a prior error occured */ /* a prior error occurred */
WOLFSSL_ERROR_MSG("Skipping wolfSSL_CTX_use_PrivateKey_buffer\n"); ESP_LOGE(TAG, "Skipping wolfSSL_CTX_use_PrivateKey_buffer\n");
} }
@ -637,15 +647,15 @@ int tls_smp_client_task() {
if (ret == WOLFSSL_SUCCESS) { if (ret == WOLFSSL_SUCCESS) {
ret = wolfSSL_CTX_load_verify_buffer(ctx, CA_FILE, sizeof_CA_FILE(), WOLFSSL_FILETYPE_PEM); ret = wolfSSL_CTX_load_verify_buffer(ctx, CA_FILE, sizeof_CA_FILE(), WOLFSSL_FILETYPE_PEM);
if (ret == WOLFSSL_SUCCESS) { if (ret == WOLFSSL_SUCCESS) {
WOLFSSL_MSG("wolfSSL_CTX_load_verify_buffer successful\n"); ESP_LOGI(TAG, "wolfSSL_CTX_load_verify_buffer successful\n");
} }
else { else {
WOLFSSL_ERROR_MSG("ERROR: wolfSSL_CTX_load_verify_buffer failed\n"); ESP_LOGE(TAG, "ERROR: wolfSSL_CTX_load_verify_buffer failed\n");
} }
} }
else { else {
/* a prior error occured */ /* a prior error occurred */
WOLFSSL_ERROR_MSG("skipping wolfSSL_CTX_load_verify_buffer\n"); ESP_LOGE(TAG, "skipping wolfSSL_CTX_load_verify_buffer\n");
} }
@ -674,13 +684,13 @@ int tls_smp_client_task() {
if (ret == WOLFSSL_SUCCESS) { if (ret == WOLFSSL_SUCCESS) {
ssl = wolfSSL_new(ctx); ssl = wolfSSL_new(ctx);
if (ssl == NULL) { if (ssl == NULL) {
WOLFSSL_ERROR_MSG("ERROR : failed to create WOLFSSL object\n"); ESP_LOGE(TAG, "ERROR : failed to create WOLFSSL object\n");
ret = WOLFSSL_FAILURE; ret = WOLFSSL_FAILURE;
} }
} }
else { else {
/* a prior error occured */ /* a prior error occurred */
WOLFSSL_ERROR_MSG("skipping wolfSSL_new\n"); ESP_LOGE(TAG, "skipping wolfSSL_new\n");
} }
@ -708,15 +718,15 @@ int tls_smp_client_task() {
if (ret == WOLFSSL_SUCCESS) { if (ret == WOLFSSL_SUCCESS) {
ret = wolfSSL_set_fd(ssl, sockfd); ret = wolfSSL_set_fd(ssl, sockfd);
if (ret == WOLFSSL_SUCCESS) { if (ret == WOLFSSL_SUCCESS) {
WOLFSSL_MSG("wolfSSL_set_fd successful\n"); ESP_LOGI(TAG, "wolfSSL_set_fd successful\n");
} }
else { else {
WOLFSSL_ERROR_MSG("ERROR: wolfSSL_set_fd failed\n"); ESP_LOGE(TAG, "ERROR: wolfSSL_set_fd failed\n");
} }
} }
else { else {
/* a prior error occured */ /* a prior error occurred */
WOLFSSL_ERROR_MSG("skipping wolfSSL_set_fd\n"); ESP_LOGE(TAG, "skipping wolfSSL_set_fd\n");
} }
@ -769,15 +779,15 @@ int tls_smp_client_task() {
if (ret == WOLFSSL_SUCCESS) { if (ret == WOLFSSL_SUCCESS) {
ret = wolfSSL_connect(ssl); ret = wolfSSL_connect(ssl);
if (ret == WOLFSSL_SUCCESS) { if (ret == WOLFSSL_SUCCESS) {
WOLFSSL_MSG("wolfSSL_connect successful\n"); ESP_LOGI(TAG, "wolfSSL_connect successful\n");
} }
else { else {
WOLFSSL_ERROR_MSG("ERROR: wolfSSL_connect failed\n"); ESP_LOGE(TAG, "ERROR: wolfSSL_connect failed\n");
} }
} }
else { else {
/* a prior error occured */ /* a prior error occurred */
WOLFSSL_ERROR_MSG("skipping wolfSSL_connect\n"); ESP_LOGE(TAG, "skipping wolfSSL_connect\n");
} }
@ -838,8 +848,8 @@ int tls_smp_client_task() {
/* write the message over secure connection to the server */ /* write the message over secure connection to the server */
if (wolfSSL_write(ssl, sendMessage, len) == len) { if (wolfSSL_write(ssl, sendMessage, len) == len) {
WOLFSSL_MSG("wolfSSL_write message sent successfully:\n"); ESP_LOGI(TAG, "wolfSSL_write message sent successfully:\n");
WOLFSSL_MSG(sendMessage); ESP_LOGI(TAG, "%s", sendMessage);
} }
else { else {
@ -848,15 +858,15 @@ int tls_smp_client_task() {
char err_buff[80]; char err_buff[80];
wolfSSL_ERR_error_string(err, err_buff); wolfSSL_ERR_error_string(err, err_buff);
WOLFSSL_ERROR_MSG(err_buff); ESP_LOGE(TAG, "%s", err_buff);
WOLFSSL_ERROR_MSG("ERROR: wolfSSL_write FAILED.\n"); ESP_LOGE(TAG, "ERROR: wolfSSL_write FAILED.\n");
ret = WOLFSSL_FAILURE; ret = WOLFSSL_FAILURE;
} }
} }
else { else {
/* a prior error occured */ /* a prior error occurred */
WOLFSSL_ERROR_MSG("Skipping wolfSSL_write\n"); ESP_LOGE(TAG, "Skipping wolfSSL_write\n");
} }
@ -920,9 +930,9 @@ int tls_smp_client_task() {
/* one or more bytes received is considered success */ /* one or more bytes received is considered success */
/* Print to stdout any data the server sends */ /* Print any data the server sends */
WOLFSSL_MSG("wolfSSL_read received message:\n"); ESP_LOGI(TAG, "wolfSSL_read received message:\n");
WOLFSSL_MSG(buff); ESP_LOGI(TAG, "%s", buff);
} }
else { else {
/* get the integer error value */ /* get the integer error value */
@ -932,9 +942,9 @@ int tls_smp_client_task() {
/* get the human-readable error string. */ /* get the human-readable error string. */
char err_buff[80] = "\x0"; char err_buff[80] = "\x0";
wolfSSL_ERR_error_string(err, err_buff); wolfSSL_ERR_error_string(err, err_buff);
WOLFSSL_ERROR_MSG(err_buff); ESP_LOGE(TAG, "%s", err_buff);
WOLFSSL_ERROR_MSG("ERROR: wolfSSL_read FAILED.\n"); ESP_LOGE(TAG, "ERROR: wolfSSL_read FAILED.\n");
ret = WOLFSSL_FAILURE; ret = WOLFSSL_FAILURE;
} }
} }
@ -962,16 +972,32 @@ int tls_smp_client_task() {
wolfSSL_Cleanup(); /* Cleanup the wolfSSL environment */ wolfSSL_Cleanup(); /* Cleanup the wolfSSL environment */
WOLFSSL_LEAVE("tls_smp_client_task", ret); WOLFSSL_LEAVE("tls_smp_client_task", ret);
WOLFSSL_MSG("tls_smp_client_task done!\n"); ESP_LOGI(TAG,"tls_smp_client_task done!\n");
return ret; return ret;
} }
void app_main(void) void app_main(void)
{ {
//Initialize NVS ESP_LOGI(TAG, "--------------------------------------------------------");
ESP_LOGI(TAG, "--------------------------------------------------------");
ESP_LOGI(TAG, "---------------------- BEGIN MAIN ----------------------");
ESP_LOGI(TAG, "--------------------------------------------------------");
ESP_LOGI(TAG, "--------------------------------------------------------");
ESP_LOGI(TAG, "LIBWOLFSSL_VERSION_STRING = %s", LIBWOLFSSL_VERSION_STRING);
ESP_LOGI(TAG, "CONFIG_IDF_TARGET = %s", CONFIG_IDF_TARGET);
ESP_LOGI(TAG, "CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ = %u MHz", CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ);
ESP_LOGI(TAG, "Xthal_have_ccount = %u", Xthal_have_ccount);
ESP_LOGI(TAG, "Stack HWM: %d\n", uxTaskGetStackHighWaterMark(NULL));
/* Initialize NVS */
esp_err_t ret = nvs_flash_init(); esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { if (ret == ESP_ERR_NVS_NO_FREE_PAGES
||
ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase()); ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init(); ret = nvs_flash_init();
} }
@ -986,6 +1012,8 @@ void app_main(void)
ESP_LOGI(TAG, "main loop"); ESP_LOGI(TAG, "main loop");
vTaskDelay(DelayTicks ? DelayTicks : 1); /* Minimum delay = 1 tick */ vTaskDelay(DelayTicks ? DelayTicks : 1); /* Minimum delay = 1 tick */
tls_smp_client_task(); tls_smp_client_task();
/* upon completion, wait forever */
for (;;) for (;;)
{ {
vTaskDelay(DelayTicks ? DelayTicks : 1); /* Minimum delay = 1 tick */ vTaskDelay(DelayTicks ? DelayTicks : 1); /* Minimum delay = 1 tick */

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,37 @@
#
# Default main stack size
#
# This is typically way bigger than needed for stack size. See user_settings.h
#
CONFIG_ESP_MAIN_TASK_STACK_SIZE=55000
# Legacy stack size for older ESP-IDF versions
CONFIG_MAIN_TASK_STACK_SIZE=55000
#
# Compiler options
#
CONFIG_COMPILER_OPTIMIZATION_DEFAULT=y
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_ENABLE=y
CONFIG_COMPILER_OPTIMIZATION_ASSERTION_LEVEL=2
CONFIG_COMPILER_HIDE_PATHS_MACROS=y
CONFIG_COMPILER_STACK_CHECK_MODE_NORM=y
CONFIG_COMPILER_STACK_CHECK=y
# minimum C3 chip revision known to work is 2.
# rev 0 and 1 not available for testing.
# all revisions expected to work.
CONFIG_ESP32C3_REV_MIN_0=
CONFIG_ESP32C3_REV_MIN_1=
CONFIG_ESP32C3_REV_MIN_2=y
CONFIG_ESP32C3_REV_MIN_3=
#
# Partition Table
#
CONFIG_PARTITION_TABLE_SINGLE_APP_LARGE=y
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"
CONFIG_PARTITION_TABLE_FILENAME="partitions_singleapp_large.csv"
CONFIG_PARTITION_TABLE_OFFSET=0x8000
CONFIG_PARTITION_TABLE_MD5=y
# end of Partition Table

View File

@ -1,31 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31729.503
MinimumVisualStudioVersion = 10.0.40219.1
Project("{803FD0C6-D64E-4E16-9DC3-1DAEC859A3D2}") = "ESP32-TLS13-server", "ESP32-TLS13-wifi_station-server.vgdbproj", "{6B1C0FCA-05B1-4F65-A57E-5EC9768F9866}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|VisualGDB = Debug|VisualGDB
Release|VisualGDB = Release|VisualGDB
Tests (Debug)|VisualGDB = Tests (Debug)|VisualGDB
Tests (Release)|VisualGDB = Tests (Release)|VisualGDB
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6B1C0FCA-05B1-4F65-A57E-5EC9768F9866}.Debug|VisualGDB.ActiveCfg = Debug|VisualGDB
{6B1C0FCA-05B1-4F65-A57E-5EC9768F9866}.Debug|VisualGDB.Build.0 = Debug|VisualGDB
{6B1C0FCA-05B1-4F65-A57E-5EC9768F9866}.Release|VisualGDB.ActiveCfg = Release|VisualGDB
{6B1C0FCA-05B1-4F65-A57E-5EC9768F9866}.Release|VisualGDB.Build.0 = Release|VisualGDB
{6B1C0FCA-05B1-4F65-A57E-5EC9768F9866}.Tests (Debug)|VisualGDB.ActiveCfg = Tests (Debug)|VisualGDB
{6B1C0FCA-05B1-4F65-A57E-5EC9768F9866}.Tests (Debug)|VisualGDB.Build.0 = Tests (Debug)|VisualGDB
{6B1C0FCA-05B1-4F65-A57E-5EC9768F9866}.Tests (Release)|VisualGDB.ActiveCfg = Tests (Release)|VisualGDB
{6B1C0FCA-05B1-4F65-A57E-5EC9768F9866}.Tests (Release)|VisualGDB.Build.0 = Tests (Release)|VisualGDB
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C818398D-7E23-4E3B-8076-2DCDCB03967C}
EndGlobalSection
EndGlobal

View File

@ -20,9 +20,10 @@
<Version> <Version>
<GCC>8.4.0</GCC> <GCC>8.4.0</GCC>
<GDB>8.1.0</GDB> <GDB>8.1.0</GDB>
<Revision>7</Revision> <Revision>9</Revision>
</Version> </Version>
</ToolchainID> </ToolchainID>
<RelativeSourceDirectory />
<ConfigurationType>DEBUG</ConfigurationType> <ConfigurationType>DEBUG</ConfigurationType>
<BinaryDirectory>build/$(PlatformName)/$(ConfigurationName)</BinaryDirectory> <BinaryDirectory>build/$(PlatformName)/$(ConfigurationName)</BinaryDirectory>
<MakeCommandTemplate> <MakeCommandTemplate>
@ -57,6 +58,7 @@
<BuildAllTargetsInSubdir>false</BuildAllTargetsInSubdir> <BuildAllTargetsInSubdir>false</BuildAllTargetsInSubdir>
<FoldSingleItemPathLevels>true</FoldSingleItemPathLevels> <FoldSingleItemPathLevels>true</FoldSingleItemPathLevels>
</ProjectItemSettings> </ProjectItemSettings>
<TargetSpecificSettings />
<SetLDLibraryPathFromDependentArtifacts>true</SetLDLibraryPathFromDependentArtifacts> <SetLDLibraryPathFromDependentArtifacts>true</SetLDLibraryPathFromDependentArtifacts>
<ProjectGUID>6b1c0fca-05b1-4f65-a57e-5ec9768f9866</ProjectGUID> <ProjectGUID>6b1c0fca-05b1-4f65-a57e-5ec9768f9866</ProjectGUID>
<VirtualFolders /> <VirtualFolders />
@ -65,8 +67,8 @@
<EnableFastUpToDateCheck>true</EnableFastUpToDateCheck> <EnableFastUpToDateCheck>true</EnableFastUpToDateCheck>
<ESPIDFExtension> <ESPIDFExtension>
<IDFCheckout> <IDFCheckout>
<Version>release/v4.4</Version> <Version>v4.4.1</Version>
<Subdirectory>esp-idf/v4.4</Subdirectory> <Subdirectory>esp-idf/v4.4.1</Subdirectory>
<Type>ESPIDF</Type> <Type>ESPIDF</Type>
</IDFCheckout> </IDFCheckout>
<COMPort>COM20</COMPort> <COMPort>COM20</COMPort>
@ -155,6 +157,7 @@
<ShowMessageAfterExecuting>true</ShowMessageAfterExecuting> <ShowMessageAfterExecuting>true</ShowMessageAfterExecuting>
</CustomShortcuts> </CustomShortcuts>
<UserDefinedVariables /> <UserDefinedVariables />
<ImportedPropertySheets />
<CodeSense> <CodeSense>
<Enabled>Unknown</Enabled> <Enabled>Unknown</Enabled>
<ExtraSettings> <ExtraSettings>
@ -177,6 +180,7 @@
<BuildSettingsExtension xsi:type="com.visualgdb.build.external.esp-idf.cmake.extension" /> <BuildSettingsExtension xsi:type="com.visualgdb.build.external.esp-idf.cmake.extension" />
</VisualGDBConfiguration> </VisualGDBConfiguration>
</Configurations> </Configurations>
<ProgramArgumentsSuggestions />
<Debug xsi:type="com.visualgdb.debug.embedded"> <Debug xsi:type="com.visualgdb.debug.embedded">
<AdditionalStartupCommands /> <AdditionalStartupCommands />
<AdditionalGDBSettings> <AdditionalGDBSettings>

View File

@ -0,0 +1,269 @@
<?xml version="1.0"?>
<VisualGDBProjectSettings2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Project xsi:type="com.visualgdb.project.external.esp-idf">
<CustomSourceDirectories>
<Directories />
<PathStyle>Unknown</PathStyle>
</CustomSourceDirectories>
<AutoProgramSPIFFSPartition>true</AutoProgramSPIFFSPartition>
<ProjectModeSettings>
<ProjectGUID>591b9b62-1581-445d-93c1-f2751ed04cfc</ProjectGUID>
<GroupSourcesByTypes>true</GroupSourcesByTypes>
<GroupSourcesByPaths>true</GroupSourcesByPaths>
<HeaderScanMode>SourceDirs</HeaderScanMode>
</ProjectModeSettings>
</Project>
<Build xsi:type="com.visualgdb.build.cmake">
<BuildLogMode xsi:nil="true" />
<ToolchainID>
<ID>com.visualgdb.xtensa-esp32-elf</ID>
<Version>
<GCC>11.2.0</GCC>
<GDB>9.2.90</GDB>
<Revision>2</Revision>
</Version>
</ToolchainID>
<RelativeSourceDirectory />
<ConfigurationType>DEBUG</ConfigurationType>
<BinaryDirectory>build/$(PlatformName)/$(ConfigurationName)</BinaryDirectory>
<MakeCommandTemplate>
<SkipWhenRunningCommandList>false</SkipWhenRunningCommandList>
<Command>$(ToolchainNinja)</Command>
<WorkingDirectory>$(BuildDir)</WorkingDirectory>
<BackgroundMode xsi:nil="true" />
</MakeCommandTemplate>
<CMakeCommand>
<SkipWhenRunningCommandList>false</SkipWhenRunningCommandList>
<Command>$(SYSPROGS_CMAKE_PATH)</Command>
<BackgroundMode xsi:nil="true" />
</CMakeCommand>
<UpdateSourcesInCMakeFile>true</UpdateSourcesInCMakeFile>
<ExportCompileCommands>false</ExportCompileCommands>
<DisableToolchainFile>false</DisableToolchainFile>
<CMakeMakefileType>Ninja</CMakeMakefileType>
<DeployAsRoot>false</DeployAsRoot>
<CMakeCleanMode>RemoveBuildDirectory</CMakeCleanMode>
<UseCCache>false</UseCCache>
<ProjectModeSettings>
<ProjectItemSettings>
<GroupSourcesByTypes>true</GroupSourcesByTypes>
<GroupSourcesByPaths>true</GroupSourcesByPaths>
<GroupTargetsByPaths>true</GroupTargetsByPaths>
<FollowCMakeSourceGroups>false</FollowCMakeSourceGroups>
<AutoRefreshProject>true</AutoRefreshProject>
<AlwaysConsiderOutdated>false</AlwaysConsiderOutdated>
<SortTargetsByName>true</SortTargetsByName>
<RedundantTargetMode>HideOuterProjectTargets</RedundantTargetMode>
<SortSourcesByName>true</SortSourcesByName>
<BuildAllTargetsInSubdir>false</BuildAllTargetsInSubdir>
<FoldSingleItemPathLevels>true</FoldSingleItemPathLevels>
</ProjectItemSettings>
<TargetSpecificSettings />
<SetLDLibraryPathFromDependentArtifacts>true</SetLDLibraryPathFromDependentArtifacts>
<ProjectGUID>6b1c0fca-05b1-4f65-a57e-5ec9768f9866</ProjectGUID>
<VirtualFolders />
<ConfigurationNameCase>Upper</ConfigurationNameCase>
<DefaultHeaderDiscoveryMode>HeaderDirectoryAndSubdirectories</DefaultHeaderDiscoveryMode>
<EnableFastUpToDateCheck>true</EnableFastUpToDateCheck>
<ESPIDFExtension>
<IDFCheckout>
<Version>release/v5.0</Version>
<Subdirectory>esp-idf/v5.0</Subdirectory>
<Type>ESPIDF</Type>
</IDFCheckout>
<COMPort>COM20</COMPort>
<SuppressTestPrerequisiteChecks>false</SuppressTestPrerequisiteChecks>
<UseCCache>false</UseCCache>
<DeviceID>ESP32</DeviceID>
</ESPIDFExtension>
</ProjectModeSettings>
</Build>
<CustomBuild>
<PreSyncActions />
<PreBuildActions />
<PostBuildActions />
<PreCleanActions />
<PostCleanActions />
</CustomBuild>
<CustomDebug>
<PreDebugActions />
<PostDebugActions />
<DebugStopActions />
<BreakMode>Default</BreakMode>
</CustomDebug>
<DeviceTerminalSettings>
<Connection xsi:type="com.sysprogs.terminal.connection.serial">
<ComPortName>COM20</ComPortName>
<AdvancedSettings>
<BaudRate>115200</BaudRate>
<DataBits>8</DataBits>
<Parity>None</Parity>
<StopBits>One</StopBits>
<FlowControl>None</FlowControl>
</AdvancedSettings>
</Connection>
<LastConnectionTime>0</LastConnectionTime>
<EchoTypedCharacters>false</EchoTypedCharacters>
<ClearContentsWhenReconnecting>false</ClearContentsWhenReconnecting>
<ReconnectAutomatically>false</ReconnectAutomatically>
<DisplayMode>ASCII</DisplayMode>
<Colors>
<Background>
<Alpha>255</Alpha>
<Red>0</Red>
<Green>0</Green>
<Blue>0</Blue>
</Background>
<Disconnected>
<Alpha>255</Alpha>
<Red>169</Red>
<Green>169</Green>
<Blue>169</Blue>
</Disconnected>
<Text>
<Alpha>255</Alpha>
<Red>211</Red>
<Green>211</Green>
<Blue>211</Blue>
</Text>
<Echo>
<Alpha>255</Alpha>
<Red>144</Red>
<Green>238</Green>
<Blue>144</Blue>
</Echo>
<Inactive>
<Alpha>255</Alpha>
<Red>169</Red>
<Green>169</Green>
<Blue>169</Blue>
</Inactive>
</Colors>
<HexSettings>
<MaximumBytesPerLine>16</MaximumBytesPerLine>
<ShowTextView>true</ShowTextView>
<BreaksAroundEcho>true</BreaksAroundEcho>
<AutoSend>true</AutoSend>
<SendAsHex>true</SendAsHex>
<TimeoutForAutoBreak>0</TimeoutForAutoBreak>
</HexSettings>
<LineEnding>LF</LineEnding>
<TreatLFAsCRLF>false</TreatLFAsCRLF>
<KeepOpenAfterExit>false</KeepOpenAfterExit>
<ShowAfterProgramming>false</ShowAfterProgramming>
</DeviceTerminalSettings>
<CustomShortcuts>
<Shortcuts />
<ShowMessageAfterExecuting>true</ShowMessageAfterExecuting>
</CustomShortcuts>
<UserDefinedVariables />
<ImportedPropertySheets />
<CodeSense>
<Enabled>Unknown</Enabled>
<ExtraSettings>
<HideErrorsInSystemHeaders>true</HideErrorsInSystemHeaders>
<SupportLightweightReferenceAnalysis>true</SupportLightweightReferenceAnalysis>
<CheckForClangFormatFiles>true</CheckForClangFormatFiles>
<FormattingEngine xsi:nil="true" />
</ExtraSettings>
<CodeAnalyzerSettings>
<Enabled>false</Enabled>
</CodeAnalyzerSettings>
</CodeSense>
<Configurations>
<VisualGDBConfiguration>
<Name>Debug</Name>
<BuildSettingsExtension xsi:type="com.visualgdb.build.external.esp-idf.cmake.extension" />
</VisualGDBConfiguration>
<VisualGDBConfiguration>
<Name>Release</Name>
<BuildSettingsExtension xsi:type="com.visualgdb.build.external.esp-idf.cmake.extension" />
</VisualGDBConfiguration>
</Configurations>
<ProgramArgumentsSuggestions />
<Debug xsi:type="com.visualgdb.debug.embedded">
<AdditionalStartupCommands />
<AdditionalGDBSettings>
<Features>
<DisableAutoDetection>false</DisableAutoDetection>
<UseFrameParameter>false</UseFrameParameter>
<SimpleValuesFlagSupported>false</SimpleValuesFlagSupported>
<ListLocalsSupported>false</ListLocalsSupported>
<ByteLevelMemoryCommandsAvailable>false</ByteLevelMemoryCommandsAvailable>
<ThreadInfoSupported>false</ThreadInfoSupported>
<PendingBreakpointsSupported>false</PendingBreakpointsSupported>
<SupportTargetCommand>false</SupportTargetCommand>
<ReliableBreakpointNotifications>false</ReliableBreakpointNotifications>
</Features>
<EnableSmartStepping>false</EnableSmartStepping>
<FilterSpuriousStoppedNotifications>false</FilterSpuriousStoppedNotifications>
<ForceSingleThreadedMode>false</ForceSingleThreadedMode>
<UseAppleExtensions>false</UseAppleExtensions>
<CanAcceptCommandsWhileRunning>false</CanAcceptCommandsWhileRunning>
<MakeLogFile>false</MakeLogFile>
<IgnoreModuleEventsWhileStepping>true</IgnoreModuleEventsWhileStepping>
<UseRelativePathsOnly>false</UseRelativePathsOnly>
<ExitAction>None</ExitAction>
<DisableDisassembly>false</DisableDisassembly>
<ExamineMemoryWithXCommand>false</ExamineMemoryWithXCommand>
<StepIntoNewInstanceEntry>app_main</StepIntoNewInstanceEntry>
<ExamineRegistersInRawFormat>true</ExamineRegistersInRawFormat>
<DisableSignals>false</DisableSignals>
<EnableAsyncExecutionMode>false</EnableAsyncExecutionMode>
<AsyncModeSupportsBreakpoints>true</AsyncModeSupportsBreakpoints>
<TemporaryBreakConsolidationTimeout>0</TemporaryBreakConsolidationTimeout>
<EnableNonStopMode>false</EnableNonStopMode>
<MaxBreakpointLimit>0</MaxBreakpointLimit>
<EnableVerboseMode>true</EnableVerboseMode>
<EnablePrettyPrinters>false</EnablePrettyPrinters>
</AdditionalGDBSettings>
<DebugMethod>
<ID>openocd</ID>
<Configuration xsi:type="com.visualgdb.edp.openocd.settings.esp32">
<CommandLine>-f interface/tigard.cfg -c "adapter_khz 13000" -f target/esp32.cfg</CommandLine>
<ExtraParameters>
<Frequency xsi:nil="true" />
<BoostedFrequency xsi:nil="true" />
<ConnectUnderReset>false</ConnectUnderReset>
</ExtraParameters>
<LoadProgressGUIThreshold>131072</LoadProgressGUIThreshold>
<ProgramMode>Enabled</ProgramMode>
<StartupCommands>
<string>set remotetimeout 60</string>
<string>target remote :$$SYS:GDB_PORT$$</string>
<string>mon gdb_breakpoint_override hard</string>
<string>mon reset halt</string>
<string>load</string>
</StartupCommands>
<ProgramFLASHUsingExternalTool>false</ProgramFLASHUsingExternalTool>
<PreferredGDBPort>0</PreferredGDBPort>
<PreferredTelnetPort>0</PreferredTelnetPort>
<AlwaysPassSerialNumber>false</AlwaysPassSerialNumber>
<SelectedCoreIndex xsi:nil="true" />
<LiveMemoryTimeout>5000</LiveMemoryTimeout>
<SuggestionLogicRevision>1</SuggestionLogicRevision>
<CheckFLASHSize>true</CheckFLASHSize>
<FLASHSettings>
<Size>size2MB</Size>
<Frequency>freq40M</Frequency>
<Mode>DIO</Mode>
</FLASHSettings>
<PatchBootloader>true</PatchBootloader>
</Configuration>
</DebugMethod>
<AutoDetectRTOS>true</AutoDetectRTOS>
<SemihostingSupport>Auto</SemihostingSupport>
<SemihostingPollingDelay>0</SemihostingPollingDelay>
<StepIntoEntryPoint>false</StepIntoEntryPoint>
<ReloadFirmwareOnReset>false</ReloadFirmwareOnReset>
<ValidateEndOfStackAddress>true</ValidateEndOfStackAddress>
<StopAtEntryPoint>false</StopAtEntryPoint>
<EnableVirtualHalts>false</EnableVirtualHalts>
<DynamicAnalysisSettings />
<EndOfStackSymbol>_estack</EndOfStackSymbol>
<TimestampProviderTicksPerSecond>0</TimestampProviderTicksPerSecond>
<KeepConsoleAfterExit>false</KeepConsoleAfterExit>
<UnusedStackFillPattern xsi:nil="true" />
<CheckInterfaceDrivers>true</CheckInterfaceDrivers>
</Debug>
</VisualGDBProjectSettings2>

View File

@ -31,15 +31,17 @@
#define WOLFSSL_ESPIDF #define WOLFSSL_ESPIDF
#define WOLFSSL_ESPWROOM32 #define WOLFSSL_ESPWROOM32
#define WOLFSSL_USER_SETTINGS #define WOLFSSL_USER_SETTINGS
#include <wolfssl/wolfcrypt/settings.h> // make sure this appears before any other wolfSSL headers
#include <wolfssl/version.h>
/* make sure user_settings.h appears before any other wolfSSL headers */
#include <user_settings.h>
#include <wolfssl/ssl.h> #include <wolfssl/ssl.h>
#ifdef WOLFSSL_TRACK_MEMORY #ifdef WOLFSSL_TRACK_MEMORY
#include <wolfssl/wolfcrypt/mem_track.h> #include <wolfssl/wolfcrypt/mem_track.h>
#endif #endif
/** /**
****************************************************************************** ******************************************************************************
****************************************************************************** ******************************************************************************
@ -48,19 +50,23 @@
****************************************************************************** ******************************************************************************
**/ **/
/* when using a private config with plain text passwords, not my_private_config.h should be excluded from git updates */ /* when using a private config with plain text passwords,
** define USE_MY_PRIVATE_CONFIG.
** note my_private_config.h should be excluded from git updates
*/
#define USE_MY_PRIVATE_CONFIG #define USE_MY_PRIVATE_CONFIG
#ifdef USE_MY_PRIVATE_CONFIG #ifdef USE_MY_PRIVATE_CONFIG
#include "/workspace/my_private_config.h" #include "/mnt/c/workspace/my_private_config.h"
#else #else
/* The examples use WiFi configuration that you can set via project configuration menu /* The examples use WiFi configuration that you can set via project
* configuration menu
If you'd rather not, just change the below entries to strings with *
the config you want - ie #define EXAMPLE_WIFI_SSID "mywifissid" * If you'd rather not, just change the below entries to strings with
*/ * the config you want - ie #define EXAMPLE_WIFI_SSID "mywifissid"
#define EXAMPLE_ESP_WIFI_SSID CONFIG_ESP_WIFI_SSID */
#define EXAMPLE_ESP_WIFI_PASS CONFIG_ESP_WIFI_PASSWORD #define EXAMPLE_ESP_WIFI_SSID CONFIG_ESP_WIFI_SSID
#define EXAMPLE_ESP_WIFI_PASS CONFIG_ESP_WIFI_PASSWORD
#endif #endif
/* ESP lwip */ /* ESP lwip */
@ -72,14 +78,14 @@
#define TLS_SMP_CLIENT_TASK_WORDS 10240 #define TLS_SMP_CLIENT_TASK_WORDS 10240
#define TLS_SMP_CLIENT_TASK_PRIORITY 8 #define TLS_SMP_CLIENT_TASK_PRIORITY 8
/* include certificates. Note that there is an experiation date! /* include certificates. Note that there is an expiration date!
* **
* See also https://github.com/wolfSSL/wolfssl/blob/master/wolfssl/certs_test.h ** See also https://github.com/wolfSSL/wolfssl/blob/master/wolfssl/certs_test.h
**
for example: ** for example:
**
#define USE_CERT_BUFFERS_2048 ** #define USE_CERT_BUFFERS_2048
#include <wolfssl/certs_test.h> ** #include <wolfssl/certs_test.h>
*/ */
#include "embedded_CLIENT_CERT_FILE.h" #include "embedded_CLIENT_CERT_FILE.h"
#include "embedded_SERVER_CERT_FILE.h" #include "embedded_SERVER_CERT_FILE.h"
@ -107,9 +113,11 @@ TickType_t DelayTicks = 5000 / portTICK_PERIOD_MS;
/* FreeRTOS event group to signal when we are connected*/ /* FreeRTOS event group to signal when we are connected*/
static EventGroupHandle_t s_wifi_event_group; static EventGroupHandle_t s_wifi_event_group;
/* The event group allows multiple bits for each event, but we only care about two events: /* The event group allows multiple bits for each event,
* - we are connected to the AP with an IP ** but we only care about two events:
* - we failed to connect after the maximum amount of retries */ ** - we are connected to the AP with an IP
** - we failed to connect after the maximum amount of retries
*/
#define WIFI_CONNECTED_BIT BIT0 #define WIFI_CONNECTED_BIT BIT0
#define WIFI_FAIL_BIT BIT1 #define WIFI_FAIL_BIT BIT1
@ -120,30 +128,48 @@ static int s_retry_num = 0;
static void event_handler(void* arg, esp_event_base_t event_base, static void event_handler(void* arg, esp_event_base_t event_base,
int32_t event_id, void* event_data) int32_t event_id, void* event_data)
{ {
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) { if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START)
{
esp_wifi_connect(); esp_wifi_connect();
} else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) { }
if (s_retry_num < EXAMPLE_ESP_MAXIMUM_RETRY) { else if (event_base == WIFI_EVENT
&&
event_id == WIFI_EVENT_STA_DISCONNECTED)
{
/* we have WiFi disconnected event, so try reconnect */
if (s_retry_num < EXAMPLE_ESP_MAXIMUM_RETRY)
{
esp_wifi_connect(); esp_wifi_connect();
s_retry_num++; s_retry_num++;
ESP_LOGI(TAG, "retry to connect to the AP"); ESP_LOGI(TAG, "retry to connect to the AP");
} else { }
else
{
xEventGroupSetBits(s_wifi_event_group, WIFI_FAIL_BIT); xEventGroupSetBits(s_wifi_event_group, WIFI_FAIL_BIT);
} }
ESP_LOGI(TAG,"connect to the AP fail"); ESP_LOGI(TAG, "connect to the AP fail");
} else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) { }
else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP)
{
/* we have an IP address! */
ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data; ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data;
ESP_LOGI(TAG, "got ip:" IPSTR, IP2STR(&event->ip_info.ip)); ESP_LOGI(TAG, "got ip:" IPSTR, IP2STR(&event->ip_info.ip));
s_retry_num = 0; s_retry_num = 0;
xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT); xEventGroupSetBits(s_wifi_event_group, WIFI_CONNECTED_BIT);
} }
else {
ESP_LOGI(TAG, "WiFi event not handled: event_id = %li", event_id);
}
} }
int set_time() { int set_time() {
/* we'll also return a result code of zero */ /* we'll also return a result code of zero */
int res = 0; int res = 0;
//*ideally, we'd like to set time from network, but let's set a default time, just in case */ /*ideally, we'd like to set time from network,
but let's set a default time, just in case */
struct tm timeinfo; struct tm timeinfo;
timeinfo.tm_year = 2022 - 1900; timeinfo.tm_year = 2022 - 1900;
timeinfo.tm_mon = 3; timeinfo.tm_mon = 3;
@ -209,9 +235,11 @@ void wifi_init_sta(void)
.sta = { .sta = {
.ssid = EXAMPLE_ESP_WIFI_SSID, .ssid = EXAMPLE_ESP_WIFI_SSID,
.password = EXAMPLE_ESP_WIFI_PASS, .password = EXAMPLE_ESP_WIFI_PASS,
/* Setting a password implies station will connect to all security modes including WEP/WPA. /* Setting a password implies station will connect to all security
* However these modes are deprecated and not advisable to be used. Incase your Access point * modes including WEP/WPA.However these modes are deprecated and
* doesn't support WPA2, these mode can be enabled by commenting below line */ * not advisable to be used. In case your Access point doesn't
* support WPA2, these mode can be enabled by commenting below line
*/
.threshold.authmode = WIFI_AUTH_WPA2_PSK, .threshold.authmode = WIFI_AUTH_WPA2_PSK,
.pmf_cfg = { .pmf_cfg = {
@ -226,29 +254,40 @@ void wifi_init_sta(void)
ESP_LOGI(TAG, "wifi_init_sta finished."); ESP_LOGI(TAG, "wifi_init_sta finished.");
/* Waiting until either the connection is established (WIFI_CONNECTED_BIT) or connection failed for the maximum /* Waiting until either the connection is established (WIFI_CONNECTED_BIT)
* number of re-tries (WIFI_FAIL_BIT). The bits are set by event_handler() (see above) */ ** or connection failed for the maximum number of re-tries (WIFI_FAIL_BIT).
** The bits are set by event_handler() (see above)
*/
EventBits_t bits = xEventGroupWaitBits(s_wifi_event_group, EventBits_t bits = xEventGroupWaitBits(s_wifi_event_group,
WIFI_CONNECTED_BIT | WIFI_FAIL_BIT, WIFI_CONNECTED_BIT | WIFI_FAIL_BIT,
pdFALSE, pdFALSE,
pdFALSE, pdFALSE,
portMAX_DELAY); portMAX_DELAY);
/* xEventGroupWaitBits() returns the bits before the call returned, hence we can test which event actually /* xEventGroupWaitBits() returns the bits before the call returned,
* happened. */ ** hence we can test which event actually happened.
*/
if (bits & WIFI_CONNECTED_BIT) { if (bits & WIFI_CONNECTED_BIT) {
ESP_LOGI(TAG, "connected to ap SSID:%s password:%s", ESP_LOGI(TAG, "connected to ap SSID:%s password:%s",
EXAMPLE_ESP_WIFI_SSID, EXAMPLE_ESP_WIFI_PASS); EXAMPLE_ESP_WIFI_SSID, EXAMPLE_ESP_WIFI_PASS);
} else if (bits & WIFI_FAIL_BIT) { }
else if (bits & WIFI_FAIL_BIT) {
ESP_LOGI(TAG, "Failed to connect to SSID:%s, password:%s", ESP_LOGI(TAG, "Failed to connect to SSID:%s, password:%s",
EXAMPLE_ESP_WIFI_SSID, EXAMPLE_ESP_WIFI_PASS); EXAMPLE_ESP_WIFI_SSID, EXAMPLE_ESP_WIFI_PASS);
} else { }
else {
ESP_LOGE(TAG, "UNEXPECTED EVENT"); ESP_LOGE(TAG, "UNEXPECTED EVENT");
} }
/* The event will not be processed after unregister */ /* The event will not be processed after unregister */
ESP_ERROR_CHECK(esp_event_handler_instance_unregister(IP_EVENT, IP_EVENT_STA_GOT_IP, instance_got_ip)); ESP_ERROR_CHECK(esp_event_handler_instance_unregister(IP_EVENT,
ESP_ERROR_CHECK(esp_event_handler_instance_unregister(WIFI_EVENT, ESP_EVENT_ANY_ID, instance_any_id)); IP_EVENT_STA_GOT_IP,
instance_got_ip)
);
ESP_ERROR_CHECK(esp_event_handler_instance_unregister(WIFI_EVENT,
ESP_EVENT_ANY_ID,
instance_any_id)
);
vEventGroupDelete(s_wifi_event_group); vEventGroupDelete(s_wifi_event_group);
} }
@ -258,7 +297,7 @@ int tls_smp_server_task() {
struct sockaddr_in servAddr; struct sockaddr_in servAddr;
const int BUFF_SIZE = 256; const int BUFF_SIZE = 256;
char buff[BUFF_SIZE]; char buff[BUFF_SIZE];
size_t len; /* we'll be looking at the length of messages sent and received */ size_t len; /* we'll be looking at the length of messages sent & received */
struct sockaddr_in clientAddr; struct sockaddr_in clientAddr;
socklen_t size = sizeof(clientAddr); socklen_t size = sizeof(clientAddr);
@ -270,7 +309,10 @@ int tls_smp_server_task() {
/* declare wolfSSL objects */ /* declare wolfSSL objects */
WOLFSSL_CTX *ctx = NULL; /* the wolfSSL context object*/ WOLFSSL_CTX *ctx = NULL; /* the wolfSSL context object*/
WOLFSSL *ssl = NULL; /* although called "ssl" is is the secure object for reading and writings data*/
WOLFSSL *ssl = NULL; /* although called "ssl" this is the secure object
for reading and writing data*/
#ifdef HAVE_SIGNAL #ifdef HAVE_SIGNAL
signal(SIGINT, sig_handler); signal(SIGINT, sig_handler);
@ -279,7 +321,7 @@ int tls_smp_server_task() {
#ifdef DEBUG_WOLFSSL #ifdef DEBUG_WOLFSSL
wolfSSL_Debugging_ON(); wolfSSL_Debugging_ON();
WOLFSSL_MSG("Debug ON v0.2b"); WOLFSSL_MSG("Debug ON v0.2b");
//ShowCiphers(); /* ShowCiphers(); */
#endif /* DEBUG_WOLFSSL */ #endif /* DEBUG_WOLFSSL */
#ifndef WOLFSSL_TLS13 #ifndef WOLFSSL_TLS13
@ -297,7 +339,7 @@ int tls_smp_server_task() {
/* /*
*************************************************************************** ***************************************************************************
* Create a socket that uses an internet IPv4 address, * Create a socket that uses an Internet IPv4 address,
* Sets the socket to be stream based (TCP), * Sets the socket to be stream based (TCP),
* 0 means choose the default protocol. * 0 means choose the default protocol.
* *
@ -325,9 +367,9 @@ int tls_smp_server_task() {
* Symbolic constants that can be used for the domain argument are * Symbolic constants that can be used for the domain argument are
* defined in the <sys/socket.h> header. * defined in the <sys/socket.h> header.
* *
* The type argument specifies the socket type, which determines the semantics * The type argument specifies the socket type, which determines the
* of communication over the socket. The following socket types are defined; * semantics of communication over the socket. The following socket types
* implementations may specify additional socket types: * are defined; implementations may specify additional socket types:
* *
* SOCK_STREAM Provides sequenced, reliable, bidirectional, * SOCK_STREAM Provides sequenced, reliable, bidirectional,
* connection-mode byte streams, and may provide a * connection-mode byte streams, and may provide a
@ -349,25 +391,32 @@ int tls_smp_server_task() {
* used. The protocols supported by the system are * used. The protocols supported by the system are
* implementation-defined. * implementation-defined.
* *
* The process may need to have appropriate privileges to use the socket() function or to create some sockets. * The process may need to have appropriate privileges to use the
* socket() function or to create some sockets.
* *
* Return Value * Return Value
* Upon successful completion, socket() shall return a non-negative integer, * Upon successful completion, socket() shall return a non-negative
* the socket file descriptor. Otherwise, a value of -1 shall be returned * integer, the socket file descriptor.
*
* Otherwise, a value of -1 shall be returned
* and errno set to indicate the error. * and errno set to indicate the error.
* *
* Errors; The socket() function shall fail if: * Errors; The socket() function shall fail if:
* *
* EAFNOSUPPORT The implementation does not support the specified address family. * EAFNOSUPPORT The implementation does not support the specified
* EMFILE No more file descriptors are available for this process. * address family.
* EMFILE No more file descriptors are available
* for this process.
* ENFILE No more file descriptors are available for the system. * ENFILE No more file descriptors are available for the system.
* EPROTONOSUPPORT The protocol is not supported by the address family, or the protocol is not supported by the implementation. * EPROTONOSUPPORT The protocol is not supported by the address family,
* or the protocol is not supported by the implementation.
* EPROTOTYPE The socket type is not supported by the protocol. * EPROTOTYPE The socket type is not supported by the protocol.
* *
* The socket() function may fail if: * The socket() function may fail if:
* *
* EACCES The process does not have appropriate privileges. * EACCES The process does not have appropriate privileges.
* ENOBUFS Insufficient resources were available in the system to perform the operation. * ENOBUFS Insufficient resources were available in the system to
* perform the operation.
* ENOMEM Insufficient memory was available to fulfill the request. * ENOMEM Insufficient memory was available to fulfill the request.
* *
* see: https://linux.die.net/man/3/socket * see: https://linux.die.net/man/3/socket
@ -421,12 +470,18 @@ int tls_smp_server_task() {
* be set to the protocol number of TCP * be set to the protocol number of TCP
* *
* Return Value * Return Value
* On success, zero is returned. On error, -1 is returned, and errno is set appropriately. * On success, zero is returned.
* On error, -1 is returned, and errno is set appropriately.
* *
* Errors * Errors
* EBADF The argument sockfd is not a valid descriptor. * EBADF The argument sockfd is not a valid descriptor.
* EFAULT The address pointed to by optval is not in a valid part of the process address space. For getsockopt(), this error may also be returned if optlen is not in a valid part of the process address space. * EFAULT The address pointed to by optval is not in a valid part of
* EINVAL optlen invalid in setsockopt(). In some cases this error can also occur for an invalid value in optval (e.g., for the IP_ADD_MEMBERSHIP option described in ip(7)). * the process address space. For getsockopt(), this error
* may also be returned if optlen is not in a valid part of
* the process address space.
* EINVAL optlen invalid in setsockopt(). In some cases this error
* can also occur for an invalid value in optval
* e.g., for the IP_ADD_MEMBERSHIP option described in ip(7)
* ENOPROTOOPT The option is unknown at the level indicated. * ENOPROTOOPT The option is unknown at the level indicated.
* ENOTSOCK The argument sockfd is a file, not a socket. * ENOTSOCK The argument sockfd is a file, not a socket.
* *
@ -446,7 +501,7 @@ int tls_smp_server_task() {
WOLFSSL_MSG("setsockopt re-use addr successful\n"); WOLFSSL_MSG("setsockopt re-use addr successful\n");
} }
else { else {
// TODO show errno ESP_LOGE(TAG, "setsockopt failed with code %i", soc_ret);
ret = WOLFSSL_FAILURE; ret = WOLFSSL_FAILURE;
WOLFSSL_ERROR_MSG("ERROR: failed to setsockopt addr on socket.\n"); WOLFSSL_ERROR_MSG("ERROR: failed to setsockopt addr on socket.\n");
} }
@ -468,10 +523,8 @@ int tls_smp_server_task() {
WOLFSSL_MSG("setsockopt re-use port successful\n"); WOLFSSL_MSG("setsockopt re-use port successful\n");
} }
else { else {
// TODO show errno WOLFSSL_MSG("Note: failed to setsockopt port on socket."
// ret = WOLFSSL_FAILURE; " >> IGNORED << \n");
// TODO what's up with the error?
WOLFSSL_ERROR_MSG("ERROR: failed to setsockopt port on socket. >> IGNORED << \n");
} }
} }
else { else {
@ -504,10 +557,12 @@ int tls_smp_server_task() {
* a SOCK_STREAM socket may receive connections. * a SOCK_STREAM socket may receive connections.
* *
* Return Value * Return Value
* On success, zero is returned. On error, -1 is returned, and errno is set appropriately. * On success, zero is returned.
* On error, -1 is returned, and errno is set appropriately.
* *
* Errors * Errors
* EACCES The address is protected, and the user is not the superuser. * EACCES The address is protected, and
* the user is not the superuser.
* EADDRINUSE The given address is already in use. * EADDRINUSE The given address is already in use.
* EBADF sockfd is not a valid descriptor. * EBADF sockfd is not a valid descriptor.
* EINVAL The socket is already bound to an address. * EINVAL The socket is already bound to an address.
@ -520,7 +575,11 @@ int tls_smp_server_task() {
*/ */
if (ret == WOLFSSL_SUCCESS) { if (ret == WOLFSSL_SUCCESS) {
/* Bind the server socket to our port */ /* Bind the server socket to our port */
int soc_ret = bind(sockfd, (struct sockaddr*)&servAddr, sizeof(servAddr)); int soc_ret = bind(sockfd,
(struct sockaddr*)&servAddr,
sizeof(servAddr)
);
if (soc_ret > -1) { if (soc_ret > -1) {
WOLFSSL_MSG("socket bind successful\n"); WOLFSSL_MSG("socket bind successful\n");
} }
@ -549,10 +608,10 @@ int tls_smp_server_task() {
* *
* The backlog argument defines the maximum length to which the queue of * The backlog argument defines the maximum length to which the queue of
* pending connections for sockfd may grow.If a connection request arrives * pending connections for sockfd may grow.If a connection request arrives
* when the queue is full, the client may receive an error with an indication * when the queue is full, the client may receive an error with an
* of ECONNREFUSED or, if the underlying protocol supports retransmission, * indication of ECONNREFUSED or, if the underlying protocol supports
* the request may be ignored so that a later reattempt at connection * retransmission, the request may be ignored so that a later reattempt
* succeeds. * at connection succeeds.
* *
* Return Value * Return Value
* On success, zero is returned. * On success, zero is returned.
@ -561,9 +620,10 @@ int tls_smp_server_task() {
* EADDRINUSE Another socket is already listening on the same port. * EADDRINUSE Another socket is already listening on the same port.
* EBADF The argument sockfd is not a valid descriptor. * EBADF The argument sockfd is not a valid descriptor.
* ENOTSOCK The argument sockfd is not a socket. * ENOTSOCK The argument sockfd is not a socket.
* EOPNOTSUPP The socket is not of a type that supports the listen() operation. * EOPNOTSUPP The socket is not of a type that supports
* the listen() operation.
* *
* ses: https://linux.die.net/man/2/listen * see: https://linux.die.net/man/2/listen
*/ */
if (ret == WOLFSSL_SUCCESS) { if (ret == WOLFSSL_SUCCESS) {
@ -620,11 +680,13 @@ int tls_smp_server_task() {
* SSL/TLS protocol method for input. * SSL/TLS protocol method for input.
* *
* Returns * Returns
* pointer If successful the call will return a pointer to the newly-created WOLFSSL_CTX. * pointer If successful the call will return a pointer
* to the newly-created WOLFSSL_CTX.
* NULL upon failure. * NULL upon failure.
* *
* Parameters * Parameters
* method pointer to the desired WOLFSSL_METHOD to use for the SSL context. * method pointer to the desired WOLFSSL_METHOD to use for SSL context.
* This is created using one of the wolfSSLvXX_XXXX_method() functions to * This is created using one of the wolfSSLvXX_XXXX_method() functions to
* specify SSL/TLS/DTLS protocol level. * specify SSL/TLS/DTLS protocol level.
* *
@ -635,7 +697,8 @@ int tls_smp_server_task() {
WOLFSSL_METHOD* method = wolfTLSv1_3_server_method(); WOLFSSL_METHOD* method = wolfTLSv1_3_server_method();
WOLFSSL_MSG("calling wolfTLSv1_3_server_method"); WOLFSSL_MSG("calling wolfTLSv1_3_server_method");
if (method == NULL) { if (method == NULL) {
WOLFSSL_ERROR_MSG("ERROR : failed to get wolfTLSv1_3_server_method.\n"); WOLFSSL_ERROR_MSG("ERROR : "
"failed to get wolfTLSv1_3_server_method.\n");
ret = WOLFSSL_FAILURE; ret = WOLFSSL_FAILURE;
} }
else { else {
@ -674,7 +737,8 @@ int tls_smp_server_task() {
* Returns * Returns
* SSL_SUCCESS upon success. * SSL_SUCCESS upon success.
* SSL_BAD_FILETYPE will be returned if the file is the wrong format. * SSL_BAD_FILETYPE will be returned if the file is the wrong format.
* SSL_BAD_FILE will be returned if the file doesnt exist, cant be read, or is corrupted. * SSL_BAD_FILE will be returned if the file doesnt exist,
* cant be read, or is corrupted.
* MEMORY_E will be returned if an out of memory condition occurs. * MEMORY_E will be returned if an out of memory condition occurs.
* ASN_INPUT_E will be returned if Base16 decoding fails on the file. * ASN_INPUT_E will be returned if Base16 decoding fails on the file.
* *
@ -682,7 +746,8 @@ int tls_smp_server_task() {
* ssl pointer to the SSL session, created with wolfSSL_new(). * ssl pointer to the SSL session, created with wolfSSL_new().
* in buffer containing certificate to load. * in buffer containing certificate to load.
* sz size of the certificate located in buffer. * sz size of the certificate located in buffer.
* format format of the certificate to be loaded. Possible values are SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM. * format format of the certificate to be loaded.
* Possible values are SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM.
* *
* *
* Pay attention to expiration dates and the current date setting * Pay attention to expiration dates and the current date setting
@ -701,7 +766,8 @@ int tls_smp_server_task() {
WOLFSSL_MSG("wolfSSL_CTX_use_certificate_buffer successful\n"); WOLFSSL_MSG("wolfSSL_CTX_use_certificate_buffer successful\n");
} }
else { else {
WOLFSSL_ERROR_MSG("ERROR: wolfSSL_CTX_use_certificate_buffer failed\n"); WOLFSSL_ERROR_MSG("ERROR: "
"wolfSSL_CTX_use_certificate_buffer failed\n");
} }
} }
else { else {
@ -732,16 +798,19 @@ int tls_smp_server_task() {
* Please see the examples for proper usage. * Please see the examples for proper usage.
* *
* Returns * Returns
* SSL_SUCCESS upon success * SSL_SUCCESS upon success.
* SSL_BAD_FILETYPE will be returned if the file is the wrong format. * SSL_BAD_FILETYPE returned if the file is the wrong format.
* SSL_BAD_FILE will be returned if the file doesnt exist, cant be read, or is corrupted. * SSL_BAD_FILE returned if the file doesnt exist,
* MEMORY_E will be returned if an out of memory condition occurs. * cant be read, or is corrupted.
* ASN_INPUT_E will be returned if Base16 decoding fails on the file. *
* NO_PASSWORD will be returned if the key file is encrypted but no password is provided. * MEMORY_E returned if an out of memory condition occurs.
* ASN_INPUT_E returned if Base16 decoding fails on the file.
* NO_PASSWORD returned if the key file is encrypted
* but no password is provided.
* *
* Parameters * Parameters
* ctx pointer to the SSL context, created with wolfSSL_CTX_new(). * ctx pointer to the SSL context, created with wolfSSL_CTX_new().
* inthe input buffer containing the private key to be loaded. * in the input buffer containing the private key to be loaded.
* *
* sz the size of the input buffer. * sz the size of the input buffer.
* *
@ -756,12 +825,14 @@ int tls_smp_server_task() {
KEY_FILE, KEY_FILE,
sizeof_KEY_FILE(), sizeof_KEY_FILE(),
WOLFSSL_FILETYPE_PEM); WOLFSSL_FILETYPE_PEM);
if (ret == WOLFSSL_SUCCESS) { if (ret == WOLFSSL_SUCCESS) {
WOLFSSL_MSG("wolfSSL_CTX_use_PrivateKey_buffer successful\n"); WOLFSSL_MSG("wolfSSL_CTX_use_PrivateKey_buffer successful\n");
} }
else { else {
/* TODO fetch and print expiration date since it is a common fail */ /* TODO fetch and print expiration date since it is a common fail */
WOLFSSL_ERROR_MSG("ERROR: wolfSSL_CTX_use_PrivateKey_buffer failed\n"); WOLFSSL_ERROR_MSG("ERROR: "
"wolfSSL_CTX_use_PrivateKey_buffer failed\n");
} }
} }
else { else {
@ -792,29 +863,38 @@ int tls_smp_server_task() {
* Returns * Returns
* *
* SSL_SUCCESS upon success * SSL_SUCCESS upon success
* SSL_BAD_FILETYPE will be returned if the file is the wrong format. * SSL_BAD_FILETYPE returned if the file is the wrong format.
* SSL_BAD_FILE will be returned if the file doesnt exist, cant be read, or is corrupted. * SSL_BAD_FILE returned if the file doesnt exist, cant be read,
* MEMORY_E will be returned if an out of memory condition occurs. * or is corrupted.
* ASN_INPUT_E will be returned if Base16 decoding fails on the file. * MEMORY_E returned if an out of memory condition occurs.
* BUFFER_E will be returned if a chain buffer is bigger than the receiving buffer. * ASN_INPUT_E returned if Base16 decoding fails on the file.
* BUFFER_E returned if a chain buffer is bigger than
* the receiving buffer.
* *
* Parameters * Parameters
* *
* ctx pointer to the SSL context, created with wolfSSL_CTX_new(). * ctx pointer to the SSL context, created with wolfSSL_CTX_new().
* in pointer to the CA certificate buffer. * in pointer to the CA certificate buffer.
* sz size of the input CA certificate buffer, in. * sz size of the input CA certificate buffer, in.
* format format of the buffer certificate, either SSL_FILETYPE_ASN1 or SSL_FILETYPE_PEM. * format format of the buffer certificate, either SSL_FILETYPE_ASN1
* or SSL_FILETYPE_PEM.
* *
* see https://www.wolfssl.com/doxygen/group__CertsKeys.html#gaa37539cce3388c628ac4672cf5606785 * see https://www.wolfssl.com/doxygen/group__CertsKeys.html#gaa37539cce3388c628ac4672cf5606785
*************************************************************************** ***************************************************************************
*/ */
if (ret == WOLFSSL_SUCCESS) { if (ret == WOLFSSL_SUCCESS) {
ret = wolfSSL_CTX_load_verify_buffer(ctx, CA_FILE, sizeof_CA_FILE(), WOLFSSL_FILETYPE_PEM); ret = wolfSSL_CTX_load_verify_buffer(ctx,
CA_FILE,
sizeof_CA_FILE(),
WOLFSSL_FILETYPE_PEM
);
if (ret == WOLFSSL_SUCCESS) { if (ret == WOLFSSL_SUCCESS) {
WOLFSSL_MSG("wolfSSL_CTX_load_verify_buffer successful\n"); WOLFSSL_MSG("wolfSSL_CTX_load_verify_buffer successful\n");
} }
else { else {
WOLFSSL_ERROR_MSG("ERROR: wolfSSL_CTX_load_verify_buffer failed\n"); WOLFSSL_ERROR_MSG("ERROR: "
"wolfSSL_CTX_load_verify_buffer failed\n");
} }
} }
else { else {
@ -826,9 +906,6 @@ int tls_smp_server_task() {
WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT, WOLFSSL_VERIFY_PEER | WOLFSSL_VERIFY_FAIL_IF_NO_PEER_CERT,
NULL); NULL);
/* Continue to accept clients until mShutdown is issued */ /* Continue to accept clients until mShutdown is issued */
while (!mShutdown && (ret == WOLFSSL_SUCCESS)) { while (!mShutdown && (ret == WOLFSSL_SUCCESS)) {
WOLFSSL_MSG("Waiting for a connection...\n"); WOLFSSL_MSG("Waiting for a connection...\n");
@ -836,19 +913,19 @@ int tls_smp_server_task() {
/* Accept client connections */ /* Accept client connections */
if ((mConnd = accept(sockfd, (struct sockaddr*)&clientAddr, &size)) if ((mConnd = accept(sockfd, (struct sockaddr*)&clientAddr, &size))
== -1) { == -1) {
// fprintf(stderr, "ERROR: failed to accept the connection\n\n");
ret = -1; ret = -1;
// TODO goto exit; goto exit;
WOLFSSL_ERROR_MSG("ERROR: failed socket accept\n"); WOLFSSL_ERROR_MSG("ERROR: failed socket connection accept\n");
ret = WOLFSSL_FAILURE; ret = WOLFSSL_FAILURE;
} }
/* Create a WOLFSSL object */ /* Create a WOLFSSL object */
if ((ssl = wolfSSL_new(ctx)) == NULL) { if ((ssl = wolfSSL_new(ctx)) == NULL) {
// fprintf(stderr, "ERROR: failed to create WOLFSSL object\n"); WOLFSSL_ERROR_MSG("ERROR: failed to create WOLFSSL object\n");
ret = -1; ret = -1;
//TODO goto exit; goto exit;
WOLFSSL_ERROR_MSG("ERROR: filed wolfSSL_new during loop\n"); WOLFSSL_ERROR_MSG("ERROR: failed wolfSSL_new during loop\n");
ret = WOLFSSL_FAILURE; ret = WOLFSSL_FAILURE;
} }
@ -868,17 +945,16 @@ int tls_smp_server_task() {
/* Establish TLS connection */ /* Establish TLS connection */
if ((ret = wolfSSL_accept(ssl)) != WOLFSSL_SUCCESS) { if ((ret = wolfSSL_accept(ssl)) != WOLFSSL_SUCCESS) {
WOLFSSL_ERROR_MSG("ERROR: wolfSSL_accept\n"); WOLFSSL_ERROR_MSG("ERROR: wolfSSL_accept\n");
ret = WOLFSSL_FAILURE; ret = WOLFSSL_FAILURE;
// fprintf(stderr, ESP_LOGE(TAG, "wolfSSL_accept error = %d\n",
// "wolfSSL_accept error = %d\n", wolfSSL_get_error(ssl, ret));
// wolfSSL_get_error(ssl, ret)); goto exit;
// TODO goto exit;
} }
else { else {
WOLFSSL_MSG("Client connected successfully\n"); WOLFSSL_MSG("Client connected successfully\n");
} }
#ifdef HAVE_SECRET_CALLBACK #ifdef HAVE_SECRET_CALLBACK
wolfSSL_FreeArrays(ssl); wolfSSL_FreeArrays(ssl);
#endif #endif
@ -886,16 +962,17 @@ int tls_smp_server_task() {
/* Read the client data into our buff array */ /* Read the client data into our buff array */
memset(buff, 0, sizeof(buff)); memset(buff, 0, sizeof(buff));
if ((ret = wolfSSL_read(ssl, buff, sizeof(buff) - 1)) < 0) { if ((ret = wolfSSL_read(ssl, buff, sizeof(buff) - 1)) < 0) {
// fprintf(stderr, "ERROR: failed to read\n"); ESP_LOGE(TAG, "wolfSSL_read error = %d\n",
//TODO goto exit; wolfSSL_get_error(ssl, ret));
goto exit;
} }
/* Print to stdout any data the client sends */ /* Print any data the client sends */
// printf("Client: %s\n", buff); ESP_LOGI(TAG, "Client: %s\n", buff);
/* Check for server shutdown command */ /* Check for server shutdown command */
if (strncmp(buff, "shutdown", 8) == 0) { if (strncmp(buff, "shutdown", 8) == 0) {
// printf("Shutdown command issued!\n"); ESP_LOGI(TAG, "Shutdown command issued!\n");
mShutdown = 1; mShutdown = 1;
} }
@ -906,8 +983,9 @@ int tls_smp_server_task() {
/* Reply back to the client */ /* Reply back to the client */
if ((ret = wolfSSL_write(ssl, buff, len)) != len) { if ((ret = wolfSSL_write(ssl, buff, len)) != len) {
// fprintf(stderr, "ERROR: failed to write\n"); ESP_LOGE(TAG, "wolfSSL_write error = %d\n",
// TODO goto exit; wolfSSL_get_error(ssl, ret));
goto exit;
} }
/* Cleanup after this connection */ /* Cleanup after this connection */
@ -931,6 +1009,7 @@ int tls_smp_server_task() {
* *
*************************************************************************** ***************************************************************************
*/ */
exit:
if (mConnd != SOCKET_INVALID) { if (mConnd != SOCKET_INVALID) {
close(mConnd); /* Close the connection to the client */ close(mConnd); /* Close the connection to the client */
mConnd = SOCKET_INVALID; mConnd = SOCKET_INVALID;
@ -958,7 +1037,21 @@ int tls_smp_server_task() {
void app_main(void) void app_main(void)
{ {
//Initialize NVS ESP_LOGI(TAG, "--------------------------------------------------------");
ESP_LOGI(TAG, "--------------------------------------------------------");
ESP_LOGI(TAG, "---------------------- BEGIN MAIN ----------------------");
ESP_LOGI(TAG, "--------------------------------------------------------");
ESP_LOGI(TAG, "--------------------------------------------------------");
ESP_LOGI(TAG, "LIBWOLFSSL_VERSION_STRING = %s", LIBWOLFSSL_VERSION_STRING);
ESP_LOGI(TAG, "CONFIG_IDF_TARGET = %s", CONFIG_IDF_TARGET);
ESP_LOGI(TAG, "CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ = %u MHz", CONFIG_ESP32_DEFAULT_CPU_FREQ_MHZ);
ESP_LOGI(TAG, "Xthal_have_ccount = %u", Xthal_have_ccount);
ESP_LOGI(TAG, "Stack HWM: %d\n", uxTaskGetStackHighWaterMark(NULL));
/* Initialize NVS */
esp_err_t ret = nvs_flash_init(); esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase()); ESP_ERROR_CHECK(nvs_flash_erase());
@ -975,9 +1068,12 @@ void app_main(void)
ESP_LOGI(TAG, "main loop"); ESP_LOGI(TAG, "main loop");
vTaskDelay(DelayTicks ? DelayTicks : 1); /* Minimum delay = 1 tick */ vTaskDelay(DelayTicks ? DelayTicks : 1); /* Minimum delay = 1 tick */
tls_smp_server_task(); tls_smp_server_task();
/* done. wait forever */
for (;;) for (;;)
{ {
vTaskDelay(DelayTicks ? DelayTicks : 1); /* Minimum delay = 1 tick */ vTaskDelay(DelayTicks ? DelayTicks : 1); /* Minimum delay = 1 tick
*/
} }
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,37 @@
#
# Default main stack size
#
# This is typically way bigger than needed for stack size. See user_settings.h
#
CONFIG_ESP_MAIN_TASK_STACK_SIZE=55000
# Legacy stack size for older ESP-IDF versions
CONFIG_MAIN_TASK_STACK_SIZE=55000
#
# Compiler options
#
CONFIG_COMPILER_OPTIMIZATION_DEFAULT=y
CONFIG_COMPILER_OPTIMIZATION_ASSERTIONS_ENABLE=y
CONFIG_COMPILER_OPTIMIZATION_ASSERTION_LEVEL=2
CONFIG_COMPILER_HIDE_PATHS_MACROS=y
CONFIG_COMPILER_STACK_CHECK_MODE_NORM=y
CONFIG_COMPILER_STACK_CHECK=y
# minimum C3 chip revision known to work is 2.
# rev 0 and 1 not available for testing.
# all revisions expected to work.
CONFIG_ESP32C3_REV_MIN_0=
CONFIG_ESP32C3_REV_MIN_1=
CONFIG_ESP32C3_REV_MIN_2=y
CONFIG_ESP32C3_REV_MIN_3=
#
# Partition Table
#
CONFIG_PARTITION_TABLE_SINGLE_APP_LARGE=y
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"
CONFIG_PARTITION_TABLE_FILENAME="partitions_singleapp_large.csv"
CONFIG_PARTITION_TABLE_OFFSET=0x8000
CONFIG_PARTITION_TABLE_MD5=y
# end of Partition Table