Use CI-CD-Github-Actions for spelling and formatting, add in the bot formatting action, update the CI-CD workflow files. Fix incorrect spelling and formatting on files. (#1083)

* Use new version of CI-CD Actions,  checkout@v3 instead of checkout@v2 on all jobs
* Use cSpell spell check, and use ubuntu-20.04 for formatting check
* Add in bot formatting action
* Update freertos_demo.yml and freertos_plus_demo.yml files to increase github log readability
* Add in a Qemu demo onto the workflows.
pull/1087/head
Soren Ptak 1 year ago committed by GitHub
parent 537007d96c
commit 3a2f6646f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

File diff suppressed because it is too large Load Diff

@ -1,7 +1,7 @@
#!/usr/bin/env python3
# /*
# * FreeRTOS V202212.00
# * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
# * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
# *
# * Permission is hereby granted, free of charge, to any person obtaining a copy of
# * this software and associated documentation files (the "Software"), to deal in

@ -1,14 +1,14 @@
certifi==2023.7.22
chardet==4.0.0
Deprecated
GitPython
PyGithub
PyJWT
PyYAML
certifi
chardet
colorama
Deprecated==1.2.10
gitdb==4.0.5
GitPython==3.1.32
idna==2.10
PyGithub==1.55
PyJWT==2.4.0
PyYAML==5.4
gitdb
idna
requests
smmap==3.0.4
urllib3==1.26.5
wrapt==1.12.1
smmap
urllib3
wrapt

@ -119,6 +119,7 @@ FREERTOS_IGNORED_EXTENSIONS = [
'.ipcf',
'.ise',
'.jlink',
'.js',
'.json',
'.la',
'.launch',
@ -172,6 +173,7 @@ FREERTOS_IGNORED_EXTENSIONS = [
'.pl',
'.plg',
'.png',
'.props',
'.prc',
'.pref',
'.prefs',
@ -216,6 +218,7 @@ FREERTOS_IGNORED_EXTENSIONS = [
'.tags',
'.tcl',
'.tdt',
'.templ',
'.template',
'.tgt',
'.tps',
@ -250,14 +253,12 @@ FREERTOS_IGNORED_EXTENSIONS = [
'.xmsgs',
'.xsl',
'.yml',
'.md',
'.zip'
]
FREERTOS_IGNORED_PATTERNS = [
r'.*\.git.*',
r'.*mbedtls_config\.h.*',
r'.*mbedtls_config\.h.*',
r'.*CMSIS.*',
r'.*/Nordic_Code/*',
r'.*/Nuvoton_Code/*',
@ -275,8 +276,40 @@ FREERTOS_IGNORED_PATTERNS = [
r'.*/trcKernelPortSnapshotConfig\.h.*',
r'.*/MicroZed_hw_platform.*',
r'.*/ThirdParty/.*',
r'FreeRTOS\-Plus/Demo/Common/WinPCap/.*',
r'FreeRTOS\-Plus/Source/FreeRTOS-Plus-Trace/.*',
r'.*/WinPCap/.*',
r'.*/DRIVERS/.*',
r'.*/FreeRTOS-Plus-Trace/.*',
r'.*/Reliance-Edge/.*',
r'.*/HCS12_CodeWarrior_banked/.*',
r'.*/ARM7_STR75x_GCC/.*',
r'.*/ARM7_STR75x_IAR/.*',
r'.*/lwip-1.4.0/.*',
r'.*/lwip-1.1.0/.*',
r'.*/MSP430X_MSP430F5438_CCS/.*',
r'.*/Atmel/.*',
r'.*/drivers/.*',
r'.*/lwIP/.*',
r'.*/ARM7_AT91FR40008_GCC/.*',
r'.*/ARM7_AT91SAM7S64_IAR/.*',
r'.*/ARM7_LPC2106_GCC/.*',
r'.*/CORTEX_A9_Cyclone_V_SoC_DK/.*',
r'.*/CORTEX_A9_Zynq_ZC702/.*',
r'.*/FreeRTOS-Plus/Demo/FreeRTOS_Plus_Reliance_Edge_and_CLI_Windows_Simulator/ConfigurationFiles//.*',
r'.*/ARM7_AT91FR40008_GCC/.*',
r'.*/ARM7_STR71x_IAR/.*',
r'FreeRTOS/Demo/HCS12_GCC_banked/.*',
r'FreeRTOS/Demo/CORTEX_LM3S102_GCC/hw_include/.*',
r'FreeRTOS/Demo/CORTEX_LM3S102_GCC/hw_include/.*',
r'FreeRTOS/Demo/CORTEX_STM32L152_Discovery_IAR/include/.*',
r'FreeRTOS/Demo/CORTEX_M0_Infineon_XMC1000_IAR_Keil_GCC/.*',
r'FreeRTOS/Demo/CORTEX_M4F_Infineon_XMC4000_Keil/.*',
r'FreeRTOS/Demo/AVR_ATMega4809_Atmel_Studio/RTOSDemo/.*',
r'FreeRTOS/Demo/AVR32_UC3/.*',
r'FreeRTOS/Demo/ARM7_STR75x_GCC/STLibrary/inc/.*',
r'FreeRTOS/Demo/ARM7_STR75x_IAR/STLibrary/inc/.*',
r'FreeRTOS/Demo/CORTEX_R4F_RZ_T_GCC_IAR/System/GCC/inc/.*',
r'FreeRTOS/Demo/CORTEX_A5_SAMA5D2x_Xplained_IAR/AtmelFiles/drivers/misc/.*',
r'FreeRTOS/Demo/CORTEX_ATSAM3X_Atmel_Studio/src/.*',
r'FreeRTOS-Plus/Demo/FreeRTOS_Plus_CLI_with_Trace_Windows_Simulator/Trace_Recorder_Configuration/.*',
r'FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_IPv6_Demo/common/WinPCap/.*',
r'FreeRTOS-Plus/Demo/FreeRTOS_Plus_TCP_IPv6_Demo/common/WinPCap/pcap/.*',
@ -291,6 +324,7 @@ FREERTOS_IGNORED_PATTERNS = [
]
FREERTOS_IGNORED_FILES = [
'cspell.config.yaml',
'.cproject',
'.project',
'fyi-another-way-to-ignore-file.txt',
@ -310,12 +344,28 @@ FREERTOS_IGNORED_FILES = [
'reg_test.S',
'gdbinit',
'libslirp-version.h',
'LPC21xx.h',
'lpc221x.h',
'winbase.h',
'windows.h',
'direct.h',
'stm32f10x_conf.h',
'lwipopts.h',
'lwipopts.h',
'xil_assert.h',
'alt_i2c.h',
'alt_clkmgr.h',
'hal_lcd.c',
'adc.h',
'redconf.c',
'redconf.h',
'redtypes.h',
]
FREERTOS_HEADER = [
'/*\n',
' * FreeRTOS V202212.00\n',
' * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n',
' * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n',
' *\n',
' * Permission is hereby granted, free of charge, to any person obtaining a copy of\n',
' * this software and associated documentation files (the "Software"), to deal in\n',
@ -340,7 +390,7 @@ FREERTOS_HEADER = [
' */\n',
]
FREERTOS_COPYRIGHT_REGEX = r"^( *(\/\*|\*|#|\/\/))? Copyright \(C\) 20\d\d Amazon.com, Inc. or its affiliates. All Rights Reserved\.( \*\/)?$"
FREERTOS_COPYRIGHT_REGEX = r"^( *(\/\*|\*|#|\/\/))? Copyright \(C\) 20\d\d Amazon.com, Inc. or its affiliates. All Rights Reserved\.( \*\/)?$"
def main():
parser = HeaderChecker.configArgParser()

@ -0,0 +1,38 @@
#include <stdio.h>
#include <stdlib.h>
int main( int argc, char * argv[] )
{
setvbuf( stdout, NULL, _IONBF, 0 );
FILE * fp;
char path[ 256 ];
char cmd[ 256 ];
/* Open the command for reading. */
fp = popen("find . -name RTOSDemo.out", "r");
/* Read the output a line at a time - output it. */
while( fgets( path, sizeof( path ), fp ) != NULL )
{
printf( "Path: %s\n", path );
}
sprintf(cmd, "qemu-system-arm -machine mps2-an385 -monitor null -semihosting --semihosting-config enable=on,target=native -serial stdio -nographic -kernel %s", path);
printf("cmd= %s\n", cmd);
fp = popen( cmd, "r" );
if( fp == NULL )
{
printf( "Failed to run command\n" );
exit( 1 );
}
/* Read the output a line at a time - output it. */
while( fgets( path, sizeof( path ), fp ) != NULL )
{
printf( "%s", path );
}
/* close */
pclose( fp );
return 0;
}

@ -1,13 +1,14 @@
certifi>=2020.12.5
chardet>=3.0.4
Deprecated>=1.2.10
gitdb>=4.0.5
GitPython>=3.1.11
idna>=2.10
PyGithub>=1.54
PyJWT>=1.7.1
PyYAML>=5.3.1
requests>=2.24.0
smmap>=3.0.4
urllib3>=1.25.11
wrapt>=1.12.1
Deprecated
GitPython
PyGithub
PyJWT
PyYAML
certifi
chardet
colorama
gitdb
idna
requests
smmap
urllib3
wrapt

@ -26,13 +26,13 @@ jobs:
# Source the release tools from FreeRTOS/FreeRTOS
- name: Checkout FreeRTOS Release Tools
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
path: tools
# Simpler git auth if we use checkout action and forward the repo to release script
- name: Checkout FreeRTOS
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
path: local_core
fetch-depth: 0

@ -1,93 +1,80 @@
name: CI Checks
env:
bashPass: \033[32;1mPASSED -
bashWarn: \033[33;1mWARNING -
bashFail: \033[31;1mFAILED -
bashEnd: \033[0m
on:
push:
pull_request:
workflow_dispatch:
push:
pull_request:
workflow_dispatch:
jobs:
git-secrets:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
submodules: recursive
submodules: recursive
- name: Checkout awslabs/git-secrets
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
repository: awslabs/git-secrets
ref: master
path: git-secrets
repository: awslabs/git-secrets
ref: master
path: git-secrets
- name: Install git-secrets
run: cd git-secrets && sudo make install && cd ..
- name: Run git-secrets
run: |
git-secrets --register-aws
git-secrets --scan
git-secrets --register-aws
git-secrets --scan
formatting:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Install Uncrustify
run: sudo apt-get install uncrustify=0.69.0+dfsg1-1build1
- name: Run Uncrustify
run: |
# Uncrustify on C files while ignoring symlinks.
# Make a collapsible section in the log to run uncrustify
echo "::group::Uncrustify Check"
# GitHub automtically use "set -e" which causes scripts to fail on the first exit code
# This would mean the first time a file fails the check that we exit without formatting all files.
set +e
uncrustify --version
find FreeRTOS/Demo/Common FreeRTOS/Test \( -name ethernet -o -name drivers -o -path 'FreeRTOS/Test/CMock/CMock' \) -prune -false -o -name "*.[hc]" | xargs uncrustify --no-backup --replace --if-changed -c tools/uncrustify.cfg -l C
echo "::endgroup::"
# Run a git diff to print the differences if any exist, return an error code if there are any
git diff --exit-code
if [ "$?" = "0" ]; then
echo -e "\033[32;3mUncrustify check passed\033[0m"
exit 0
else
echo -e "\033[32;31mFormatting check (using Uncrustify) failed...\033[0m"
# If there is an error, set this flag high again so the exit 1 fails the run
set -e
exit 1
fi
- name: Check For Trailing Whitespace
run: |
# Trailing Whitespace Check
set +e
ERROR=0
find . \( -name '.git' -o -path "./FreeRTOS/Test/CBMC/patches" -o -path "./FreeRTOS-Plus" -o -path "./FreeRTOS/Source" -o -path "./FreeRTOS/Test/CMock/CMock" -o -path "./FreeRTOS/Demo" \) -prune -false -o -type f -a -name "*" -exec grep -In -e "[[:blank:]]$" {} +
if [ "$?" = "0" ]; then
ERROR=1
fi
find FreeRTOS/Demo/Common \( -name "ethernet" \) -prune -o -false -o -type f -a -name "*" -exec grep --color=yes -In -e "[[:blank:]]$" {} +
if [ "$?" = "0" ]; then
echo -e "\033[32;31mFiles have trailing whitespace.\033[0m"
exit 1
else
if [ "$ERROR" -eq "1" ]; then
echo -e "\033[32;31mFiles have trailing whitespace.\033[0m"
exit 1
fi
echo -e "\033[32;3mTrailing whitespace check passed\033[0m"
exit 0
fi
- uses: actions/checkout@v3
- name: Check Formatting of Common Demo Files
uses: FreeRTOS/CI-CD-Github-Actions/formatting@main
with:
path: FreeRTOS/Demo/Common
exclude-dirs: ethernet, drivers
- name: Check Formatting
uses: FreeRTOS/CI-CD-Github-Actions/formatting@main
with:
exclude-dirs: ethernet, drivers, FreeRTOS/Demo
spell-check:
runs-on: ubuntu-latest
steps:
- name: Checkout Parent Repo
uses: actions/checkout@v3
- name: Check Spelling of Common Demo Files
uses: FreeRTOS/CI-CD-GitHub-Actions/spellings@main
with:
path: FreeRTOS/Demo/Common
exclude-dirs: ethernet, drivers
- name: Check Spelling
uses: FreeRTOS/CI-CD-GitHub-Actions/spellings@main
with:
exclude-dirs: ethernet, drivers, FreeRTOS/Demo
doxygen:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- name: Clone repository
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
submodules: recursive
path: freertos
- name: Install Python3
uses: actions/setup-python@v2
with:
python-version: '3.8'
uses: actions/setup-python@v3
- name: Download tag dependency of coreMQTT-Agent
run: |
# We don't need to generate the coreMQTT docs, we only need the tag file.
@ -95,8 +82,9 @@ jobs:
mkdir -p freertos/FreeRTOS-Plus/Source/Application-Protocols/coreMQTT-Agent/source/dependency/coreMQTT/docs/doxygen/output
wget -O freertos/FreeRTOS-Plus/Source/Application-Protocols/coreMQTT-Agent/source/dependency/coreMQTT/docs/doxygen/output/mqtt.tag \
"https://freertos.org/Documentation/api-ref/coreMQTT/docs/doxygen/output/mqtt.tag"
- name: Generate doxygen ZIP
uses: FreeRTOS/CI-CD-GitHub-Actions/doxygen@main
uses: FreeRTOS/CI-CD-Github-Actions/doxygen@main
with:
path: ./freertos
# List of directories containing libraries whose doxygen output will be generated.
@ -112,77 +100,49 @@ jobs:
path: ./freertos/doxygen.zip
retention-days: 2
spell-check:
runs-on: ubuntu-20.04
steps:
- name: Checkout Parent Repo
uses: actions/checkout@v2
with:
ref: main
repository: FreeRTOS/CI-CD-Github-Actions
path: commonCI
- name: Clone This Repo
uses: actions/checkout@v2
with:
path: ./FreeRTOS
- name: Install spell
run: |
sudo apt-get install spell
sudo apt-get install util-linux
- name: Check spelling
run: |
# Add path to the tool to the environment variable.
PATH=$PATH:commonCI/spellings/tools
# Make sure that only Amazon licenced files are checked.
sed -i 's/`find $DIRNAME \\( -iname \\\*\.\[ch\] -o -iname \\\*\.dox \\) -type f`/`grep -ril "copyright \(c\) \[0-9\]\[0-9\]\[0-9\]\[0-9\] amazon.com" | grep "\\.\[ch\]" | grep -v "FreeRTOS\/FreeRTOS\/Test\/VeriFast"`/g' commonCI/spellings/tools/find-unknown-comment-words
# Run the spell check script.
find-unknown-comment-words --directory FreeRTOS/ --lexicon FreeRTOS/lexicon.txt
# Check the exit status.
if [ "$?" = "0" ]; then
exit 0
else
exit 1
fi
verify-manifest:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
submodules: true
fetch-depth: 0
- name: Install Python3
uses: actions/setup-python@v2
with:
python-version: '3.x'
- name: Run manifest verifier
uses: FreeRTOS/CI-CD-Github-Actions/manifest-verifier@main
uses: FreeRTOS/CI-CD-GitHub-Actions/manifest-verifier@v2
with:
path: ./
exclude-submodules: FreeRTOS-Plus/Test/CMock,FreeRTOS/Test/CMock/CMock,FreeRTOS/Test/litani
fail-on-incorrect-version: true
memory-statistics:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
env:
ARM_GCC_TOOLCHAIN_URL: "https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2020q2/gcc-arm-none-eabi-9-2020-q2-update-x86_64-linux.tar.bz2?revision=05382cca-1721-44e1-ae19-1e7c3dc96118&la=en&hash=D7C9D18FCA2DD9F894FD9F3C3DC9228498FA281A"
steps:
- name: Install ARM GCC
run: wget -qO- "${{ env.ARM_GCC_TOOLCHAIN_URL }}" | sudo tar --strip-components=1 -xj -C /usr/local
run:
wget -qO- "${{ env.ARM_GCC_TOOLCHAIN_URL }}" | sudo tar
--strip-components=1 -xj -C /usr/local
- name: Clone FreeRTOS Repository with submodules
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
submodules: recursive
- name: Clone mbedTLS submodule from corePKCS11
run: git submodule update --init --recursive --checkout -- FreeRTOS-Plus/Source/corePKCS11
run:
git submodule update --init --recursive --checkout --
FreeRTOS-Plus/Source/corePKCS11
- name: Clone CI-CD-Github-Actions repository
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
repository: FreeRTOS/CI-CD-Github-Actions
repository: FreeRTOS/CI-CD-GitHub-Actions
path: tools
- name: Run script to generate JSON memory statistics
run: tools/memory_statistics/memory_statistics.py --json_report --config tools/memory_statistics/paths.json --output freertos_lts_memory_estimates.json
- name: Upload memory size report as artifact (for main and release-candidate ONLY)
run:
tools/memory_statistics/memory_statistics.py --json_report
--config tools/memory_statistics/paths.json --output
freertos_lts_memory_estimates.json
- name:
Upload memory size report as artifact (for main and
release-candidate ONLY)
if: success() && ( github.ref == 'refs/heads/main' || github.ref == 'refs/heads/release-candidate' )
uses: actions/upload-artifact@v2
with:
@ -191,16 +151,24 @@ jobs:
retention-days: 2
proof_ci:
if: ${{ github.event.pull_request }}
runs-on: cbmc_ubuntu-latest_16-core
steps:
- uses: actions/checkout@v2
- run: |
- uses: actions/checkout@v3
- env:
stepName: Install Dependencies
run: |
echo -e "::group::${{ env.stepName }}"
git submodule update --init --checkout --recursive --depth 1
sudo apt-get update
sudo apt-get install --yes --no-install-recommends gcc-multilib
echo -e "::endgroup::"
echo -e "${{ env.bashPass }} ${{env.stepName}} ${{ env.bashEnd }}"
- name: Set up CBMC runner
uses: FreeRTOS/CI-CD-Github-Actions/set_up_cbmc_runner@main
- name: Run CBMC
uses: FreeRTOS/CI-CD-Github-Actions/run_cbmc@main
with:
proofs_dir: FreeRTOS/Test/CBMC/proofs
proofs_dir: FreeRTOS/Test/CBMC/proofs

@ -18,14 +18,14 @@ jobs:
# Use the checks as defined by the user, so they can locally adjust as needed
- name: Checkout FreeRTOS Tools
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
path: tools
# Checkout user pull request changes
- name: Checkout Pull Request
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
path: inspect

@ -0,0 +1,23 @@
name: Format Pull Request Files
on:
issue_comment:
types: [created]
env:
bashPass: \033[32;1mPASSED -
bashInfo: \033[33;1mINFO -
bashFail: \033[31;1mFAILED -
bashEnd: \033[0m
jobs:
Formatting:
name: Run Formatting Check
if: ${{ github.event.issue.pull_request }} &&
( ( github.event.comment.body == '/bot run uncrustify' ) ||
( github.event.comment.body == '/bot run formatting' ) )
runs-on: ubuntu-20.04
steps:
- name: Apply Formatting Fix
uses: FreeRTOS/CI-CD-Github-Actions/formatting-bot@main
id: check-formatting

@ -1,195 +1,230 @@
name: FreeRTOS Demos
on:
push:
pull_request:
workflow_dispatch:
push:
pull_request:
workflow_dispatch:
env:
bashPass: \033[32;1mPASSED -
bashWarn: \033[33;1mWARNING -
bashFail: \033[31;1mFAILED -
bashEnd: \033[0m
pwshPass: "`e[32;1mPASSED -"
pwshWarn: "`e[33;1mWARNING -"
pwshFail: "`e[31;1mFAILED -"
pwshEnd: "`e[0m"
jobs:
WIN32-MSVC:
name: WIN32 MSVC
runs-on: windows-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Fetch Kernel Submodule
- env:
stepName: Checkout Repository
name: ${{ env.stepName }}
uses: actions/checkout@v3
- env:
stepName: Fetch Kernel Submodule
name: ${{ env.stepName }}
shell: bash
run: |
# Fetch Kernel Submodule
echo "::group::Fetch Kernel Submodule"
# ${{ env.stepName }}
echo -e "::group::${{ env.stepName }}"
set +e
git submodule update --checkout --init --depth 1 FreeRTOS/Source
echo "::endgroup::"
if [[ "$?" = "0" ]]
then
echo -e "\033[32;3mCloned the Kernel\033[0m"
exitStatus=$?
set -e
echo -e "::endgroup::"
if [ $exitStatus -eq 0 ]; then
echo -e "${{ env.bashPass }} ${{env.stepName}} ${{ env.bashEnd }}"
else
echo -e "\033[32;31mKernel Clone Failed...\033[0m"
echo -e "${{ env.bashFail }} ${{env.stepName}} ${{ env.bashEnd }}"
exit 1
fi
- name: Add msbuild to PATH
- env:
stepName: Add msbuild to PATH
name: ${{ env.stepName }}
uses: microsoft/setup-msbuild@v1.1
- name: Build WIN32-MSVC Full Demo
- env:
stepName: Build WIN32-MSVC Full Demo
name: ${{ env.stepName }}
id: build-win32-msvs-full-demo
working-directory: FreeRTOS/Demo/WIN32-MSVC
run: |
# Build WIN32-MSVC Full Demo
echo "::group::Build WIN32-MSVC Full Demo"
# ${{ env.stepName }}
echo "::group::${{ env.stepName }}"
$content = Get-Content -Path 'main.c' -Raw
$newContent = $content -replace 'int\s+main(.*?)void(.*?)\r?\n\s*{', 'int main( void ){setvbuf( stdout, NULL, _IONBF, 0 );'
$newContent | Set-Content -Path 'main.c'
msbuild WIN32.sln -t:rebuild
$exitStatus = $?
echo "::endgroup::"
if($? -eq 1) {
Write-Host -ForegroundColor green "Built the WIN32-MSVC Full Demo"
if($exitStatus -eq 1) {
echo "${{ env.pwshPass }} ${{env.stepName}} ${{ env.pwshEnd }}"
}else {
Write-Host -ForegroundColor red "Build WIN32-MSVC Full Demo Failed..."
echo "${{ env.pwshFail }} ${{env.stepName}} ${{ env.pwshEnd }}"
exit 1
}
- name: Run and monitor WIN32-MSVC Full Demo
if: success() || failure() && steps.build-win32-msvs-full-demo.outcome == 'success'
- env:
stepName: Run and monitor WIN32-MSVC Full Demo
name: ${{ env.stepName }}
uses: FreeRTOS/CI-CD-GitHub-Actions/executable-monitor@main
with:
exe-path: FreeRTOS/Demo/WIN32-MSVC/Debug/RTOSDemo.exe
log-dir: demo_run_logs
timeout-seconds: 60
success-line: "No errors - tick count"
retry-attempts: 3
- name: Build WIN32-MSVC Blinky Demo
- env:
stepName: Build WIN32-MSVC Blinky Demo
name: ${{ env.stepName }}
id: build-win32-msvs-blinky-demo
working-directory: FreeRTOS/Demo/WIN32-MSVC
run: |
# Build WIN32-MSVC Blinky Demo
echo "::group::MSBuild of WIN32-MSVC Blinky Demo"
# ${{ env.stepName }}
echo "::group::${{ env.stepName }}"
$content = Get-Content -Path 'main.c' -Raw
$newContent = $content -replace '#define\s+mainCREATE_SIMPLE_BLINKY_DEMO_ONLY\s+0', '#define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 1'
$newContent | Set-Content -Path 'main.c'
# Perform MSBuild of WIN32-MSVC Blinky Demo
msbuild WIN32.sln -t:rebuild
echo "::endgroup::"
if($? -eq 1) {
Write-Host -ForegroundColor green "Built the WIN32-MSVC Blinky Demo"
$exitStatus = $?
if($exitStatus -eq 1) {
echo "${{ env.pwshPass }} ${{ env.stepName }} ${{ env.pwshEnd }}"
}else {
Write-Host -ForegroundColor red "Build WIN32-MSVC Blinky Demo Failed..."
echo "${{ env.pwshFail }} ${{ env.stepName }} ${{ env.pwshEnd }}"
exit 1
}
- name: Run and monitor WIN32-MSVC Blinky Demo
if: success() || failure() && steps.build-win32-msvs-blinky-demo.outcome == 'success'
- env:
stepName: Run and monitor WIN32-MSVC Blinky Demo
name: ${{ env.stepName }}
uses: FreeRTOS/CI-CD-GitHub-Actions/executable-monitor@main
with:
exe-path: FreeRTOS/Demo/WIN32-MSVC/Debug/RTOSDemo.exe
log-dir: demo_run_logs
timeout-seconds: 60
success-line: "Message received from software timer"
- name: Build WIN32-MSVC-Static-Allocation-Only Demo
exe-path: FreeRTOS/Demo/WIN32-MSVC/Debug/RTOSDemo.exe
timeout-seconds: 60
success-line: "Message received from software timer"
retry-attempts: 3
- env:
stepName: Build WIN32-MSVC-Static-Allocation-Only Demo
name: ${{ env.stepName }}
id: build-win32-msvs-static-allocation-only-demo
working-directory: FreeRTOS/Demo/WIN32-MSVC-Static-Allocation-Only
run: |
# Build WIN32-MSVC-Static-Allocation-Only Demo
echo "::group::Build WIN32-MSVC-Static-Allocation-Only Demo"
# ${{ env.stepName }}
echo "::group::${{ env.stepName }}"
$content = Get-Content -Path 'main.c' -Raw
$newContent = $content -replace 'int\s+main(.*?)void(.*?)\r?\n\s*{', 'int main( void ){setvbuf( stdout, NULL, _IONBF, 0 );'
$newContent | Set-Content -Path 'main.c'
msbuild WIN32.sln -t:rebuild
$exitStatus = $?
echo "::endgroup::"
if($? -eq 1) {
Write-Host -ForegroundColor green "Built the WIN32-MSVC-Static-Allocation-Only Demo"
if($exitStatus -eq 1) {
echo "${{ env.pwshPass }} ${{ env.stepName }} ${{ env.pwshEnd }}"
}else {
Write-Host -ForegroundColor red "Build WIN32-MSVC-Static-Allocation-Only Demo Failed..."
echo "${{ env.pwshFail }} ${{ env.stepName }} ${{ env.pwshEnd }}"
exit 1
}
- name: Run and monitor WIN32-MSVC-Static-Allocation-Only Demo
if: success() || failure() && steps.build-win32-msvs-static-allocation-only-demo.outcome == 'success'
- env:
stepName:
Run and monitor WIN32-MSVC-Static-Allocation-Only Demo
name: ${{ env.stepName }}
uses: FreeRTOS/CI-CD-GitHub-Actions/executable-monitor@main
with:
exe-path: FreeRTOS/Demo/WIN32-MSVC-Static-Allocation-Only/Debug/RTOSDemo.exe
log-dir: demo_run_logs
timeout-seconds: 60
success-line: "No errors - tick count"
exe-path: FreeRTOS/Demo/WIN32-MSVC-Static-Allocation-Only/Debug/RTOSDemo.exe
timeout-seconds: 60
success-line: "No errors - tick count"
retry-attempts: 3
WIN32-MingW:
name: WIN32 MingW
runs-on: windows-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Fetch Kernel Submodule
- env:
stepName: Checkout Repository
name: ${{ env.stepName }}
uses: actions/checkout@v3
- env:
stepName: Fetch Kernel Submodule
name: ${{ env.stepName }}
shell: bash
run: |
# Fetch Kernel Submodule
echo "::group::Fetch Kernel Submodule"
# ${{ env.stepName }}
echo -e "::group::${{ env.stepName }}"
git submodule update --checkout --init --depth 1 FreeRTOS/Source
echo "::endgroup::"
if [[ "$?" = "0" ]]
then
echo -e "\033[32;3mCloned the Kernel\033[0m"
else
echo -e "\033[32;31mKernel Clone Failed...\033[0m"
exit 1
fi
echo -e "::endgroup::"
echo -e "${{ env.bashPass }} ${{env.stepName}} ${{ env.bashEnd }}"
- name: Build WIN32-MingW Full Demo
- env:
stepName: Build WIN32-MingW Full Demo
name: ${{ env.stepName }}
id: build-win32-mingw-full-demo
working-directory: FreeRTOS/Demo/WIN32-MingW
run: |
# Build WIN32-MingW Full Demo
echo "::group::Build WIN32-MingW Full Demo"
# ${{ env.stepName }}
echo "::group::${{ env.stepName }}"
$content = Get-Content -Path 'main.c' -Raw
$newContent = $content -replace 'int\s+main(.*?)void(.*?)\r?\n\s*{', 'int main( void ){setvbuf( stdout, NULL, _IONBF, 0 );'
$newContent | Set-Content -Path 'main.c'
gcc --version
make --version
make
$exitStatus = $?
echo "::endgroup::"
if($? -eq 1) {
Write-Host -ForegroundColor green "Built the WIN32-MingW Full Demo"
if($exitStatus -eq 1) {
echo "${{ env.pwshPass }} ${{ env.stepName }} ${{env.pwshEnd}}"
}else {
Write-Host -ForegroundColor red "Build WIN32-MingW Full Demo Failed..."
echo "${{ env.pwshFail }} ${{ env.stepName }} ${{env.pwshEnd}}"
exit 1
}
- name: Run and monitor WIN32-MingW Full Demo
if: success() || failure() && steps.build-win32-mingw-full-demo.outcome == 'success'
- env:
stepName: Run and monitor WIN32-MingW Full Demo
name: ${{ env.stepName }}
uses: FreeRTOS/CI-CD-GitHub-Actions/executable-monitor@main
with:
exe-path: FreeRTOS/Demo/WIN32-MingW/build/RTOSDemo.exe
log-dir: demo_run_logs
timeout-seconds: 60
success-line: "No errors - tick count"
- name: Build WIN32-MingW Blinky Demo
- env:
stepName: Build WIN32-MingW Blinky Demo
name: ${{ env.stepName }}
id: build-win32-mingw-blinky-demo
working-directory: FreeRTOS/Demo/WIN32-MingW
run: |
# Build WIN32-MingW Blinky Demo
echo "::group::Build WIN32-MingW Blinky Demo"
# ${{ env.stepName }}
echo "::group::${{ env.stepName }}"
$content = Get-Content -Path 'main.c' -Raw
$newContent = $content -replace '#define\s+mainCREATE_SIMPLE_BLINKY_DEMO_ONLY\s+0', '#define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 1'
$newContent = $newContent -replace 'int\s+main(.*?)void(.*?)\r?\n\s*{', 'int main( void ){setvbuf( stdout, NULL, _IONBF, 0 );'
$newContent | Set-Content -Path 'main.c'
gcc --version
make --version
make
$exitStatus = $?
echo "::endgroup::"
if($? -eq 1) {
Write-Host -ForegroundColor green "Built the WIN32-MingW Blinky Demo"
if($exitStatus -eq 1) {
echo "${{ env.pwshPass }} ${{ env.stepName }} ${{ env.pwshEnd }}"
}else {
Write-Host -ForegroundColor red "Build WIN32-MingW Blinky Demo Failed..."
echo "${{ env.pwshFail }} ${{ env.stepName }} ${{ env.pwshEnd }}"
exit 1
}
- name: Run and monitor WIN32-MingW Blinky Demo
if: success() || failure() && steps.build-win32-mingw-blinky-demo.outcome == 'success'
- env:
stepName: Run and monitor WIN32-MingW Blinky Demo
name: ${{ env.stepName }}
uses: FreeRTOS/CI-CD-GitHub-Actions/executable-monitor@main
with:
exe-path: FreeRTOS/Demo/WIN32-MingW/build/RTOSDemo.exe
log-dir: demo_run_logs
timeout-seconds: 60
success-line: "Message received from software timer"
@ -197,96 +232,111 @@ jobs:
name: Posix GCC
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Fetch Kernel Submodule
- env:
stepName: Checkout Repository
name: ${{ env.stepName }}
uses: actions/checkout@v3
- env:
stepName: Fetch Kernel Submodule
name: ${{ env.stepName }}
shell: bash
run: |
# Fetch Kernel Submodule
echo "::group::Fetch Kernel Submodule"
# ${{ env.stepName }}
echo -e "::group::${{ env.stepName }}"
set +e
git submodule update --checkout --init --depth 1 FreeRTOS/Source
echo "::endgroup::"
if [ "$?" = "0" ]; then
echo -e "\033[32;3mCloned the Kernel\033[0m"
set -e
exitStatus=$?
set -e
echo -e "::endgroup::"
if [ $exitStatus -eq 0 ]; then
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"
else
echo -e "\033[32;31mKernel Clone Failed...\033[0m"
echo -e "${{ env.bashFail }} ${{ env.stepName }} ${{ env.bashEnd }}"
exit 1
fi
- name: Install GCC
- env:
stepName: Install GCC
name: ${{ env.stepName }}
shell: bash
run: |
# Install GCC
echo "::group::Install GCC"
# ${{ env.stepName }}
echo -e "::group::${{ env.stepName }}"
set +e
sudo apt-get -y update
sudo apt-get -y install build-essential
echo "::endgroup::"
if [ "$?" = "0" ]; then
echo -e "\e[0;32mInstall GCC Passed\e[0m"
exitStatus=$?
set -e
echo -e "::endgroup::"
if [ $exitStatus -eq 0 ]; then
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"
else
echo -e "\e[0;32mInstall GCC Failed\e[0m"
# If there is an error, set this flag high again so the exit 1 fails the run
set -e
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"
exit 1
fi
- name: Build Posix_GCC Demo for Coverage Test
shell: bash
working-directory: FreeRTOS/Demo/Posix_GCC
run: make -j COVERAGE_TEST=1
- name: Build Posix_GCC Full Demo
- env:
stepName: Build Posix_GCC Full Demo
name: ${{ env.stepName }}
id: build-posix-gcc-full-demo
shell: bash
working-directory: FreeRTOS/Demo/Posix_GCC
run: |
# Build Posix_GCC Full Demo
echo "::group::Build Posix_GCC Full Demo"
# ${{ env.stepName }}
echo -e "::group::${{ env.stepName }}"
set +e
sed -i -z "s/int[[:space:]]*main[[:space:]]*([[:space:]]*void[[:space:]]*)\n{/int main( void ){setvbuf( stdout, NULL, _IONBF, 0 );/g" main.c
make clean
make -j
echo "::endgroup::"
if [ "$?" = "0" ]; then
echo -e "\033[32;3mBuild Posix_GCC Full Demo Passed\033[0m"
exitStatus=$?
set -e
echo -e "::endgroup::"
if [ $exitStatus -eq 0 ]; then
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"
else
echo -e "\033[32;31mBuild Posix_GCC Full Demo Failed...\033[0m"
echo -e "${{ env.bashFail }} ${{ env.stepName }} ${{ env.bashEnd }}"
exit 1
fi
- name: Run and monitor Posix_GCC Full Demo
if: success() || failure() && steps.build-posix-gcc-full-demo.outcome == 'success'
- env:
stepName: Run and monitor Posix_GCC Full Demo
name: ${{ env.stepName }}
uses: FreeRTOS/CI-CD-GitHub-Actions/executable-monitor@main
with:
exe-path: FreeRTOS/Demo/Posix_GCC/build/posix_demo
log-dir: demo_run_logs
timeout-seconds: 60
success-line: "OK: No errors"
- name: Build Posix_GCC Blinky Demo
exe-path: FreeRTOS/Demo/Posix_GCC/build/posix_demo
timeout-seconds: 60
success-line: "OK: No errors"
retry-attempts: 3
- env:
stepName: Build Posix_GCC Blinky Demo
name: ${{ env.stepName }}
id: build-posix-gcc-blinky-demo
if: success() || failure()
shell: bash
working-directory: FreeRTOS/Demo/Posix_GCC
run: |
# Build Posix_GCC Blinky Demo
echo "::group::Build Posix_GCC Blinky Demo"
# ${{ env.stepName }}
echo -e "::group::${{ env.stepName }}"
rm -rf build
set +e
make -j USER_DEMO=BLINKY_DEMO
echo "::endgroup::"
if [ "$?" = "0" ]; then
echo -e "\033[32;3mBuilt the Posix_GCC Blinky Demo\033[0m"
exitStatus=$?
set -e
echo -e "::endgroup::"
if [ $exitStatus -eq 0 ]; then
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"
else
echo -e "\033[32;31mBuild Posix_GCC Blinky Demo Failed...\033[0m"
echo -e "${{ env.bashFail }} ${{env.stepName}} ${{ env.bashEnd }}"
exit 1
fi
- name: Run and monitor Posix_GCC Blinky Demo
if: success() || failure() && steps.build-posix-gcc-blinky-demo.outcome == 'success'
- env:
stepName: Run and monitor Posix_GCC Blinky Demo
name: ${{ env.stepName }}
uses: FreeRTOS/CI-CD-GitHub-Actions/executable-monitor@main
with:
exe-path: FreeRTOS/Demo/Posix_GCC/build/posix_demo
log-dir: demo_run_logs
timeout-seconds: 60
success-line: "Message received from software timer"
@ -294,208 +344,290 @@ jobs:
name: GNU MSP430 Toolchain
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Fetch Kernel Submodule
shell: bash
run: |
# Fetch Kernel Submodule
echo "::group::Fetch Kernel Submodule"
git submodule update --checkout --init --depth 1 FreeRTOS/Source
echo "::endgroup::"
if [ "$?" = "0" ]; then
echo -e "\033[32;3mCloned the Kernel\033[0m"
else
echo -e "\033[32;31mKernel Clone Failed...\033[0m"
exit 1
fi
- name: Install MSP430 Toolchain
shell: bash
run: |
# Install MSP430 Toolchain
echo "::group::Install MSP430 Toolchain"
sudo apt-get -y update
sudo apt-get -y install gcc-msp430 build-essential
echo "::endgroup::"
if [ "$?" = "0" ]; then
echo -e "\033[32;3mInstalled the MSP430 Toolchain\033[0m"
else
echo -e "\033[32;31mInstalling the MSP430 ToolchainFailed...\033[0m"
exit 1
fi
- name: Build msp430_GCC Demo
shell: bash
working-directory: FreeRTOS/Demo/msp430_GCC
run: |
# Build msp430_GCC Demo
echo "::group::Build msp430_GCC Demo"
make -j
echo "::endgroup::"
if [ "$?" = "0" ]; then
echo -e "\033[32;3mBuilt the msp430_GCC Demo\033[0m"
else
echo -e "\033[32;31mBuilding the msp430_GCC Demo Failed...\033[0m"
exit 1
fi
- env:
stepName: Checkout Repository
name: ${{ env.stepName }}
uses: actions/checkout@v3
with:
submodules: true
- env:
stepName: Fetch Kernel Submodule
name: ${{ env.stepName }}
shell: bash
run: |
# ${{ env.stepName }}
echo -e "::group::${{ env.stepName }}"
set +e
git submodule update --checkout --init --depth 1 FreeRTOS/Source
exitStatus=$?
set -e
echo -e "::endgroup::"
if [ $exitStatus -eq 0 ]; then
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"
else
echo -e "${{ env.bashFail }} ${{ env.stepName }} ${{ env.bashEnd }}"
exit 1
fi
- env:
stepName: Install MSP430 Toolchain
name: ${{ env.stepName }}
shell: bash
run: |
# ${{ env.stepName }}
echo -e "::group::${{ env.stepName }}"
set +e
sudo apt-get -y update
sudo apt-get -y install gcc-msp430 build-essential
exitStatus=$?
set -e
echo -e "::endgroup::"
if [ $exitStatus -eq 0 ]; then
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"
else
echo -e "${{ env.bashFail }} ${{ env.stepName }} ${{ env.bashEnd }}"
exit 1
fi
- env:
stepName: Build msp430_GCC Demo
name: ${{ env.stepName }}
shell: bash
working-directory: FreeRTOS/Demo/msp430_GCC
run: |
# ${{ env.stepName }}
echo -e "::group::${{ env.stepName }}"
set +e
make -j
exitStatus=$?
set -e
echo -e "::endgroup::"
if [ $exitStatus -eq 0 ]; then
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"
else
echo -e "${{ env.bashFail }} ${{ env.stepName }} ${{ env.bashEnd }}"
exit 1
fi
ARM-GCC:
name: GNU ARM Toolchain
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v2
- name: Fetch Kernel Submodule
- env:
stepName: Checkout Repository
name: ${{ env.stepName }}
uses: actions/checkout@v3
- env:
stepName: Fetch Kernel Submodule
name: ${{ env.stepName }}
shell: bash
run: |
# Fetch Kernel Submodule
echo "::group::Fetch Kernel Submodule"
git submodule update --checkout --init --depth 1 FreeRTOS/Source
echo "::endgroup::"
if [ "$?" = "0" ]; then
echo -e "\033[32;3mCloned the Kernel\033[0m"
# ${{ env.stepName }}
echo -e "::group::${{ env.stepName }}"
set +e
git submodule update --checkout --init --depth 1 FreeRTOS/Source FreeRTOS/Demo/ThirdParty/Community-Supported-Demos
exitStatus=$?
set -e
echo -e "::endgroup::"
if [ $exitStatus -eq 0 ]; then
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"
else
echo -e "\033[32;31mKernel Clone Failed...\033[0m"
echo -e "${{ env.bashFail }} ${{ env.stepName }} ${{ env.bashEnd }}"
exit 1
fi
- name: Fetch Community-Supported-Demos Submodule
- env:
stepName: Install GNU ARM Toolchain
name: Install GNU ARM Toolchain
shell: bash
run: |
# Fetch Community-Supported-Demos Submodule
echo "::group::Fetch Community-Supported-Demos Submodule"
git submodule update --checkout --init --depth 1 FreeRTOS/Demo/ThirdParty/Community-Supported-Demos
echo "::engdroup::"
if [ "$?" = "0" ]; then
echo -e "\033[32;3mCloned the Community-Supported-Demos\033[0m"
else
echo -e "\033[32;31mCommunity-Supported-Demos Clone Failed...\033[0m"
exit 1
fi
- name: Install GNU ARM Toolchain
shell: bash
run: |
# Install GNU ARM Toolchain
echo "::group::Install GNU ARM Toolchain"
# ${{ env.stepName }}
echo -e "::group::${{ env.stepName }}"
set +e
sudo apt-get -y update
sudo apt-get -y install gcc-arm-none-eabi build-essential cmake git ninja-build python3-minimal
echo "::endgroup::"
if [ "$?" = "0" ]; then
echo -e "\033[32;3mInstalled the GNU ARM Toolchain\033[0m"
sudo apt-get -y install qemu-system-arm qemu-efi
exitStatus=$?
set -e
echo -e "::endgroup::"
if [ $exitStatus -eq 0 ]; then
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"
else
echo -e "\033[32;31mInstalling GNU ARM Toolchain Failed...\033[0m"
echo -e "${{ env.bashFail }} ${{ env.stepName }} ${{ env.bashEnd }}"
exit 1
fi
- name: Build CORTEX_MPU_M3_MPS2_QEMU_GCC Demo
- env:
stepName: Build CORTEX_MPU_M3_MPS2_QEMU_GCC Demo
name: ${{ env.stepName }}
shell: bash
working-directory: FreeRTOS/Demo/CORTEX_MPU_M3_MPS2_QEMU_GCC
run: |
# Build CORTEX_MPU_M3_MPS2_QEMU_GCC Demo
echo "::group::Build CORTEX_MPU_M3_MPS2_QEMU_GCC Demo"
# ${{ env.stepName }}
echo -e "::group::${{ env.stepName }}"
set +e
make -j
echo "::endgroup::"
if [ "$?" = "0" ]; then
echo -e "\033[32;3mBuild CORTEX_MPU_M3_MPS2_QEMU_GCC Demo\033[0m"
exitStatus=$?
set -e
echo -e "::endgroup::"
if [ $exitStatus -eq 0 ]; then
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"
else
echo -e "\033[32;31mBuild CORTEX_MPU_M3_MPS2_QEMU_GCC Demo Failed...\033[0m"
echo -e "${{ env.bashFail }} ${{ env.stepName }} ${{ env.bashEnd }}"
exit 1
fi
- name: Build CORTEX_LM3S102_GCC Demo
- env:
stepName: Build CORTEX_LM3S102_GCC Demo
name: ${{ env.stepName }}
shell: bash
working-directory: FreeRTOS/Demo/CORTEX_LM3S102_GCC
run: |
# Build CORTEX_LM3S102_GCC Demo
echo "::group::Build CORTEX_LM3S102_GCC Demo"
# ${{ env.stepName }}
echo -e "::group::${{ env.stepName }}"
set +e
make clean
make -j
echo "::endgroup::"
if [ "$?" = "0" ]; then
echo -e "\033[32;3mBuilt the CORTEX_LM3S102_GCC Demo Kernel\033[0m"
exitStatus=$?
set -e
echo -e "::endgroup::"
if [ $exitStatus -eq 0 ]; then
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"
else
echo -e "\033[32;31mBuild CORTEX_LM3S102_GCC Demo Failed...\033[0m"
echo -e "${{ env.bashFail }} ${{ env.stepName }} ${{ env.bashEnd }}"
exit 1
fi
- name: Build CORTEX_M3_MPS2_QEMU_GCC Demo
- env:
stepName: Build CORTEX_M3_MPS2_QEMU_GCC Demo
name: ${{ env.stepName }}
shell: bash
working-directory: FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC
run: |
# Build CORTEX_M3_MPS2_QEMU_GCC Demo
echo "::group::Build CORTEX_M3_MPS2_QEMU_GCC Demo"
# ${{ env.stepName }}
echo -e "::group::${{ env.stepName }}"
set +e
make clean
make -j
echo "::endgroup::"
if [ "$?" = "0" ]; then
echo -e "\033[32;3mBuilt the CORTEX_M3_MPS2_QEMU_GCC Demo\033[0m"
exitStatus=$?
set -e
echo -e "::endgroup::"
if [ $exitStatus -eq 0 ]; then
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"
else
echo -e "\033[32;31mBuild CORTEX_M3_MPS2_QEMU_GCC Demo Failed...\033[0m"
echo -e "${{ env.bashFail }} ${{ env.stepName }} ${{ env.bashEnd }}"
exit 1
fi
- name: Build CORTEX_M3_MPS2_QEMU_GCC Full Demo
- env:
stepName: Build CORTEX_M3_MPS2_QEMU_GCC Full Demo
name: ${{ env.stepName }}
shell: bash
working-directory: FreeRTOS/Demo/CORTEX_M3_MPS2_QEMU_GCC
run: |
# Build CORTEX_M3_MPS2_QEMU_GCC Full Demo
echo "::group::Build CORTEX_M3_MPS2_QEMU_GCC Full Demo"
# ${{ env.stepName }}
echo -e "::group::${{ env.stepName }}"
set +e
make clean
make FULL_DEMO=1 -j
echo "::endgroup::"
if [ "$?" = "0" ]; then
echo -e "\033[32;3mBuilt the CORTEX_M3_MPS2_QEMU_GCC Full Demo\033[0m"
exitStatus=$?
set -e
echo -e "::endgroup::"
if [ $exitStatus -eq 0 ]; then
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"
else
echo -e "\033[32;31mBuild CORTEX_M3_MPS2_QEMU_GCC Full Demo Failed...\033[0m"
echo -e "${{ env.bashFail }} ${{ env.stepName }} ${{ env.bashEnd }}"
exit 1
fi
- name: Build CORTEX_LM3S811_GCC Demo
- env:
stepName: Build CORTEX_LM3S811_GCC Demo
name: ${{ env.stepName }}
shell: bash
working-directory: FreeRTOS/Demo/CORTEX_LM3S811_GCC
run: |
# Build CORTEX_LM3S811_GCC Demo
echo "::group::Build CORTEX_LM3S811_GCC Demo"
# ${{ env.stepName }}
echo -e "::group::${{ env.stepName }}"
set +e
make -j
echo "::endgroup::"
if [ "$?" = "0" ]; then
echo -e "\033[32;3mBuilt the CORTEX_LM3S811_GCC Demo\033[0m"
exitStatus=$?
set -e
echo -e "::endgroup::"
if [ $exitStatus -eq 0 ]; then
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"
else
echo -e "\033[32;31mBuild CORTEX_LM3S811_GCC Demo Failed...\033[0m"
echo -e "${{ env.bashFail }} ${{ env.stepName }} ${{ env.bashEnd }}"
exit 1
fi
- name: Build CORTEX_M0+_RP2040 Demos
- env:
stepName: Build CORTEX_M0+_RP2040 Demos
name: ${{ env.stepName }}
shell: bash
working-directory: FreeRTOS/Demo/ThirdParty/Community-Supported-Demos/CORTEX_M0+_RP2040
run: |
# Build CORTEX_M0+_RP2040 Demos
echo "::group::Build CORTEX_M0+_RP2040 Demos"
git clone https://github.com/raspberrypi/pico-sdk.git
cmake -B build -DPICO_SDK_PATH=pico-sdk -GNinja
ninja -C build --verbose
echo "::endgroup::"
if [ "$?" = "0" ]; then
echo -e "\033[32;3mBuilt CORTEX_M0+_RP2040 Demos\033[0m"
# ${{ env.stepName }}
echo -e "::group::${{ env.stepName }}"
set +e
git clone https://github.com/raspberrypi/pico-sdk.git
cmake -B build -DPICO_SDK_PATH=pico-sdk -GNinja
ninja -C build --verbose
exitStatus=$?
set -e
echo -e "::endgroup::"
if [ $exitStatus -eq 0 ]; then
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"
else
echo -e "${{ env.bashFail }} ${{ env.stepName }} ${{ env.bashEnd }}"
exit 1
fi
- env:
stepName: Build Qemu Runner File
name: ${{ env.stepName }}
shell: bash
working-directory: .github/scripts
run: |
# ${{ env.stepName }}
echo -e "::group::${{ env.stepName }}"
gcc qemu_reader.c -o ../../FreeRTOS/Demo/CORTEX_MPS2_QEMU_IAR_GCC/qemu_reader.out
exitStatus=$?
echo -e "::endgroup::"
if [ $exitStatus -eq 0 ]; then
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"
else
echo -e "\033[32;31mBuild CORTEX_M0+_RP2040 Demos Failed...\033[0m"
echo -e "${{ env.bashFail }} ${{ env.stepName }} ${{ env.bashEnd }}"
exit 1
fi
- name: Build CORTEX_MPS2_QEMU_IAR_GCC Demo
- env:
stepName: Build CORTEX_MPS2_QEMU_IAR_GCC Demo
name: ${{ env.stepName }}
shell: bash
working-directory: FreeRTOS/Demo/CORTEX_MPS2_QEMU_IAR_GCC
run: |
# Build CORTEX_MPS2_QEMU_IAR_GCC Demo
echo "::group::Build CORTEX_MPS2_QEMU_IAR_GCC Demo"
# ${{ env.stepName }}
echo -e "::group::${{ env.stepName }}"
set +e
make -C build/gcc -j
echo "::endgroup::"
if [ "$?" = "0" ]; then
echo -e "\033[32;3mBuilt the CORTEX_MPS2_QEMU_IAR_GCC Demo\033[0m"
exitStatus=$?
set -e
echo -e "::endgroup::"
if [ $exitStatus -eq 0 ]; then
echo -e "${{ env.bashPass }} ${{ env.stepName }} ${{ env.bashEnd }}"
else
echo -e "\033[32;31mBuild CORTEX_MPS2_QEMU_IAR_GCC Demo Failed...\033[0m"
echo -e "${{ env.bashFail }} ${{ env.stepName }} ${{ env.bashEnd }}"
exit 1
fi
- env:
stepName: Run and monitor CORTEX_MPS2_QEMU_IAR_GCC Demo
name: ${{ env.stepName }}
uses: FreeRTOS/CI-CD-GitHub-Actions/executable-monitor@main
with:
exe-path: FreeRTOS/Demo/CORTEX_MPS2_QEMU_IAR_GCC/qemu_reader.out
timeout-seconds: 20
success-line: "Message received from software timer"
retry-attempts: 1

File diff suppressed because it is too large Load Diff

@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-20.04
steps:
- name: Checkout Repository
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
submodules: 'recursive'
fetch-depth: 5
@ -42,12 +42,12 @@ jobs:
runs-on: ubuntu-20.04
steps:
- name: Checkout Repository
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
submodules: 'recursive'
fetch-depth: 5
- name: Checkout the main branch from the FreeRTOS-Kernel repository
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
path: ./FreeRTOS/Source
ref: main

@ -1,5 +1,5 @@
[{000214A0-0000-0000-C000-000000000046}]
Prop3=19,2
[InternetShortcut]
URL=http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/index.html
IDList=
[{000214A0-0000-0000-C000-000000000046}]
Prop3=19,2
[InternetShortcut]
URL=http://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/index.html
IDList=

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in

@ -1,4 +1,4 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31205.134

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
@ -160,8 +160,8 @@ static eReportBuilderStatus prvWritePortsArray( char * pcBuffer,
lCharactersWritten = snprintf( pcCurrentWritePos,
xRemainingBufferLength,
"{"
"\"" DEFENDER_REPORT_PORT_KEY "\":%u"
"},",
"\"" DEFENDER_REPORT_PORT_KEY "\":%u"
"},",
( unsigned int ) pusOpenPortsArray[ uxIdx ] );
if( !reportbuilderSNPRINTF_SUCCESS( lCharactersWritten, xRemainingBufferLength ) )
@ -238,9 +238,9 @@ static eReportBuilderStatus prvWriteConnectionsArray( char * pcBuffer,
lCharactersWritten = snprintf( pcCurrentWritePos,
xRemainingBufferLength,
"{"
"\""DEFENDER_REPORT_LOCAL_PORT_KEY"\": %u,"
"\""DEFENDER_REPORT_REMOTE_ADDR_KEY"\": \"%u.%u.%u.%u:%u\""
"},",
"\""DEFENDER_REPORT_LOCAL_PORT_KEY "\": %u,"
"\""DEFENDER_REPORT_REMOTE_ADDR_KEY "\": \"%u.%u.%u.%u:%u\""
"},",
( unsigned int ) pxConn->usLocalPort,
( unsigned int ) ( pxConn->ulRemoteIp >> 24 ) & 0xFF,
( unsigned int ) ( pxConn->ulRemoteIp >> 16 ) & 0xFF,
@ -399,13 +399,13 @@ eReportBuilderStatus eGenerateJsonReport( char * pcBuffer,
lCharactersWritten = snprintf( pcCurrentWritePos,
xRemainingBufferLength,
"{"
"\""DEFENDER_REPORT_HEADER_KEY"\": {"
"\""DEFENDER_REPORT_ID_KEY"\": %u,"
"\""DEFENDER_REPORT_VERSION_KEY"\": \"%u.%u\""
"},"
"\""DEFENDER_REPORT_METRICS_KEY"\": {"
"\""DEFENDER_REPORT_TCP_LISTENING_PORTS_KEY"\": {"
"\""DEFENDER_REPORT_PORTS_KEY"\": ",
"\""DEFENDER_REPORT_HEADER_KEY "\": {"
"\""DEFENDER_REPORT_ID_KEY "\": %u,"
"\""DEFENDER_REPORT_VERSION_KEY "\": \"%u.%u\""
"},"
"\""DEFENDER_REPORT_METRICS_KEY "\": {"
"\""DEFENDER_REPORT_TCP_LISTENING_PORTS_KEY "\": {"
"\""DEFENDER_REPORT_PORTS_KEY "\": ",
( unsigned int ) ulReportId,
( unsigned int ) ulMajorReportVersion,
( unsigned int ) ulMinorReportVersion );
@ -447,11 +447,11 @@ eReportBuilderStatus eGenerateJsonReport( char * pcBuffer,
{
lCharactersWritten = snprintf( pcCurrentWritePos,
xRemainingBufferLength,
","
"\""DEFENDER_REPORT_TOTAL_KEY"\": %u"
"},"
"\""DEFENDER_REPORT_UDP_LISTENING_PORTS_KEY"\": {"
"\""DEFENDER_REPORT_PORTS_KEY"\": ",
","
"\""DEFENDER_REPORT_TOTAL_KEY "\": %u"
"},"
"\""DEFENDER_REPORT_UDP_LISTENING_PORTS_KEY "\": {"
"\""DEFENDER_REPORT_PORTS_KEY "\": ",
( unsigned int ) pxMetrics->xOpenTcpPortsArrayLength );
if( !reportbuilderSNPRINTF_SUCCESS( lCharactersWritten, xRemainingBufferLength ) )
@ -491,18 +491,18 @@ eReportBuilderStatus eGenerateJsonReport( char * pcBuffer,
{
lCharactersWritten = snprintf( pcCurrentWritePos,
xRemainingBufferLength,
","
"\""DEFENDER_REPORT_TOTAL_KEY"\": %u"
"},"
"\""DEFENDER_REPORT_NETWORK_STATS_KEY"\": {"
"\""DEFENDER_REPORT_BYTES_IN_KEY"\": %u,"
"\""DEFENDER_REPORT_BYTES_OUT_KEY"\": %u,"
"\""DEFENDER_REPORT_PKTS_IN_KEY"\": %u,"
"\""DEFENDER_REPORT_PKTS_OUT_KEY"\": %u"
"},"
"\""DEFENDER_REPORT_TCP_CONNECTIONS_KEY"\": {"
"\""DEFENDER_REPORT_ESTABLISHED_CONNECTIONS_KEY"\": {"
"\""DEFENDER_REPORT_CONNECTIONS_KEY"\": ",
","
"\""DEFENDER_REPORT_TOTAL_KEY "\": %u"
"},"
"\""DEFENDER_REPORT_NETWORK_STATS_KEY "\": {"
"\""DEFENDER_REPORT_BYTES_IN_KEY "\": %u,"
"\""DEFENDER_REPORT_BYTES_OUT_KEY "\": %u,"
"\""DEFENDER_REPORT_PKTS_IN_KEY "\": %u,"
"\""DEFENDER_REPORT_PKTS_OUT_KEY "\": %u"
"},"
"\""DEFENDER_REPORT_TCP_CONNECTIONS_KEY "\": {"
"\""DEFENDER_REPORT_ESTABLISHED_CONNECTIONS_KEY "\": {"
"\""DEFENDER_REPORT_CONNECTIONS_KEY "\": ",
( unsigned int ) pxMetrics->xOpenUdpPortsArrayLength,
( unsigned int ) pxMetrics->pxNetworkStats->uxBytesReceived,
( unsigned int ) pxMetrics->pxNetworkStats->uxBytesSent,
@ -546,20 +546,20 @@ eReportBuilderStatus eGenerateJsonReport( char * pcBuffer,
{
lCharactersWritten = snprintf( pcCurrentWritePos,
xRemainingBufferLength,
","
"\""DEFENDER_REPORT_TOTAL_KEY"\": %u"
"}"
"}"
"},"
"\""DEFENDER_REPORT_CUSTOM_METRICS_KEY"\": {"
"\"stack_high_water_mark\": ["
"{"
"\""DEFENDER_REPORT_NUMBER_KEY"\": %u"
"}"
"],"
"\"task_numbers\": ["
"{"
"\""DEFENDER_REPORT_NUMBER_LIST_KEY"\": ",
","
"\""DEFENDER_REPORT_TOTAL_KEY "\": %u"
"}"
"}"
"},"
"\""DEFENDER_REPORT_CUSTOM_METRICS_KEY "\": {"
"\"stack_high_water_mark\": ["
"{"
"\""DEFENDER_REPORT_NUMBER_KEY "\": %u"
"}"
"],"
"\"task_numbers\": ["
"{"
"\""DEFENDER_REPORT_NUMBER_LIST_KEY "\": ",
( unsigned int ) pxMetrics->xEstablishedConnectionsArrayLength,
( unsigned int ) pxMetrics->ulStackHighWaterMark );
@ -600,9 +600,9 @@ eReportBuilderStatus eGenerateJsonReport( char * pcBuffer,
{
lCharactersWritten = snprintf( pcCurrentWritePos,
xRemainingBufferLength,
"}"
"]"
"}"
"}"
"]"
"}"
"}" );
if( !reportbuilderSNPRINTF_SUCCESS( lCharactersWritten, xRemainingBufferLength ) )

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
@ -20,8 +20,10 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://aws.amazon.com/freertos
* https://github.com/FreeRTOS
*
*/
#ifndef CORE_MQTT_CONFIG_H
#define CORE_MQTT_CONFIG_H

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
@ -220,7 +220,7 @@ extern void vLoggingPrintf( const char * pcFormatString,
* @brief The name of the MQTT library used and its version, following an "@"
* symbol.
*/
#include "core_mqtt.h" /* Include coreMQTT header for MQTT_LIBRARY_VERSION macro. */
#include "core_mqtt.h" /* Include coreMQTT header for MQTT_LIBRARY_VERSION macro. */
#define democonfigMQTT_LIB "core-mqtt@"MQTT_LIBRARY_VERSION
/**

@ -1,6 +1,6 @@
/*
* AWS IoT Device SDK for Embedded C V202009.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
@ -18,6 +18,10 @@
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
#ifndef SHADOW_CONFIG_H

@ -1,4 +1,4 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31205.134

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
@ -316,11 +316,11 @@ static void prvProvisioningPublishCallback( MQTTContext_t * pxMqttContext,
configASSERT( pxDeserializedInfo->pPublishInfo != NULL );
pxPublishInfo = pxDeserializedInfo->pPublishInfo;
xStatus = FleetProvisioning_MatchTopic(pxPublishInfo->pTopicName,
pxPublishInfo->topicNameLength,
&xApi);
xStatus = FleetProvisioning_MatchTopic( pxPublishInfo->pTopicName,
pxPublishInfo->topicNameLength,
&xApi );
if (xStatus != FleetProvisioningSuccess)
if( xStatus != FleetProvisioningSuccess )
{
LogWarn( ( "Unexpected publish message received. Topic: %.*s.",
( int ) pxPublishInfo->topicNameLength,
@ -328,7 +328,7 @@ static void prvProvisioningPublishCallback( MQTTContext_t * pxMqttContext,
}
else
{
if (xApi == FleetProvCborCreateCertFromCsrAccepted)
if( xApi == FleetProvCborCreateCertFromCsrAccepted )
{
LogInfo( ( "Received accepted response from Fleet Provisioning CreateCertificateFromCsr API." ) );
@ -341,13 +341,13 @@ static void prvProvisioningPublishCallback( MQTTContext_t * pxMqttContext,
xPayloadLength = pxPublishInfo->payloadLength;
}
else if (xApi == FleetProvCborCreateCertFromCsrRejected)
else if( xApi == FleetProvCborCreateCertFromCsrRejected )
{
LogError( ( "Received rejected response from Fleet Provisioning CreateCertificateFromCsr API." ) );
xResponseStatus = ResponseRejected;
}
else if (xApi == FleetProvCborRegisterThingAccepted)
else if( xApi == FleetProvCborRegisterThingAccepted )
{
LogInfo( ( "Received accepted response from Fleet Provisioning RegisterThing API." ) );
@ -360,7 +360,7 @@ static void prvProvisioningPublishCallback( MQTTContext_t * pxMqttContext,
xPayloadLength = pxPublishInfo->payloadLength;
}
else if (xApi == FleetProvCborRegisterThingRejected)
else if( xApi == FleetProvCborRegisterThingRejected )
{
LogError( ( "Received rejected response from Fleet Provisioning RegisterThing API." ) );
@ -804,7 +804,7 @@ int prvFleetProvisioningTask( void * pvParameters )
}
else
{
LogInfo( ( "Sucessfully established connection with provisioned credentials." ) );
LogInfo( ( "Successfully established connection with provisioned credentials." ) );
xConnectionEstablished = true;
}
}

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in

@ -1,4 +1,4 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.33027.164

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source">

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
@ -20,8 +20,10 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://aws.amazon.com/freertos
* https://github.com/FreeRTOS
*
*/
#ifndef CORE_MQTT_CONFIG_H
#define CORE_MQTT_CONFIG_H

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
@ -213,7 +213,7 @@ extern void vLoggingPrintf( const char * pcFormatString,
* @brief The name of the MQTT library used and its version, following an "@"
* symbol.
*/
#include "core_mqtt.h" /* Include coreMQTT header for MQTT_LIBRARY_VERSION macro. */
#include "core_mqtt.h" /* Include coreMQTT header for MQTT_LIBRARY_VERSION macro. */
#define democonfigMQTT_LIB "core-mqtt@"MQTT_LIBRARY_VERSION
/**

@ -1,4 +1,4 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31205.134

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
@ -379,26 +379,28 @@ static TlsTransportStatus_t prvConnectToServerWithBackoffRetries( NetworkContext
uint16_t usNextRetryBackOff = 0U;
#if defined( democonfigCLIENT_USERNAME )
/*
* When democonfigCLIENT_USERNAME is defined, use the "mqtt" alpn to connect
* to AWS IoT Core with Custom Authentication on port 443.
*
* Custom Authentication uses the contents of the username and password
* fields of the MQTT CONNECT packet to authenticate the client.
*
* For more information, refer to the documentation at:
* https://docs.aws.amazon.com/iot/latest/developerguide/custom-authentication.html
*/
static const char * ppcAlpnProtocols[] = { "mqtt", NULL };
#if democonfigMQTT_BROKER_PORT != 443U
#error "Connections to AWS IoT Core with custom authentication must connect to TCP port 443 with the \"mqtt\" alpn."
#endif /* democonfigMQTT_BROKER_PORT != 443U */
/*
* When democonfigCLIENT_USERNAME is defined, use the "mqtt" alpn to connect
* to AWS IoT Core with Custom Authentication on port 443.
*
* Custom Authentication uses the contents of the username and password
* fields of the MQTT CONNECT packet to authenticate the client.
*
* For more information, refer to the documentation at:
* https://docs.aws.amazon.com/iot/latest/developerguide/custom-authentication.html
*/
static const char * ppcAlpnProtocols[] = { "mqtt", NULL };
#if democonfigMQTT_BROKER_PORT != 443U
#error "Connections to AWS IoT Core with custom authentication must connect to TCP port 443 with the \"mqtt\" alpn."
#endif /* democonfigMQTT_BROKER_PORT != 443U */
#else /* if !defined( democonfigCLIENT_USERNAME ) */
/*
* Otherwise, use the "x-amzn-mqtt-ca" alpn to connect to AWS IoT Core using
* x509 Certificate Authentication.
*/
static const char * ppcAlpnProtocols[] = { "x-amzn-mqtt-ca", NULL };
/*
* Otherwise, use the "x-amzn-mqtt-ca" alpn to connect to AWS IoT Core using
* x509 Certificate Authentication.
*/
static const char * ppcAlpnProtocols[] = { "x-amzn-mqtt-ca", NULL };
#endif /* !defined( democonfigCLIENT_USERNAME ) */
/*

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
@ -377,26 +377,28 @@ static TlsTransportStatus_t prvConnectToServerWithBackoffRetries( NetworkContext
uint16_t usNextRetryBackOff = 0U;
#if defined( democonfigCLIENT_USERNAME )
/*
* When democonfigCLIENT_USERNAME is defined, use the "mqtt" alpn to connect
* to AWS IoT Core with Custom Authentication on port 443.
*
* Custom Authentication uses the contents of the username and password
* fields of the MQTT CONNECT packet to authenticate the client.
*
* For more information, refer to the documentation at:
* https://docs.aws.amazon.com/iot/latest/developerguide/custom-authentication.html
*/
static const char * ppcAlpnProtocols[] = { "mqtt", NULL };
#if democonfigMQTT_BROKER_PORT != 443U
#error "Connections to AWS IoT Core with custom authentication must connect to TCP port 443 with the \"mqtt\" alpn."
#endif /* democonfigMQTT_BROKER_PORT != 443U */
/*
* When democonfigCLIENT_USERNAME is defined, use the "mqtt" alpn to connect
* to AWS IoT Core with Custom Authentication on port 443.
*
* Custom Authentication uses the contents of the username and password
* fields of the MQTT CONNECT packet to authenticate the client.
*
* For more information, refer to the documentation at:
* https://docs.aws.amazon.com/iot/latest/developerguide/custom-authentication.html
*/
static const char * ppcAlpnProtocols[] = { "mqtt", NULL };
#if democonfigMQTT_BROKER_PORT != 443U
#error "Connections to AWS IoT Core with custom authentication must connect to TCP port 443 with the \"mqtt\" alpn."
#endif /* democonfigMQTT_BROKER_PORT != 443U */
#else /* if !defined( democonfigCLIENT_USERNAME ) */
/*
* Otherwise, use the "x-amzn-mqtt-ca" alpn to connect to AWS IoT Core using
* x509 Certificate Authentication.
*/
static const char * ppcAlpnProtocols[] = { "x-amzn-mqtt-ca", NULL };
/*
* Otherwise, use the "x-amzn-mqtt-ca" alpn to connect to AWS IoT Core using
* x509 Certificate Authentication.
*/
static const char * ppcAlpnProtocols[] = { "x-amzn-mqtt-ca", NULL };
#endif /* !defined( democonfigCLIENT_USERNAME ) */
/*

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
@ -63,8 +63,8 @@
/*-----------------------------------------------------------*/
/**
* @brief Each compilation unit that consumes the NetworkContext must define it.
/**
* @brief Each compilation unit that consumes the NetworkContext must define it.
* It should contain a single pointer to the type of your desired transport.
* This utility is used by both TLS and plaintext HTTP demos, so define this pointer as void *.
*

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
@ -24,14 +24,14 @@
*
*/
/**
* @file aws_ota_codesigner_certificate.h
* @brief Code signer certificate as char array.
*
* Define this char array containing the PEM encode signing certificate.
* Note - It is highly recommended to use this for demo purpose and store
* certificates in secure location in production devices.
*/
/**
* @file aws_ota_codesigner_certificate.h
* @brief Code signer certificate as char array.
*
* Define this char array containing the PEM encode signing certificate.
* Note - It is highly recommended to use this for demo purpose and store
* certificates in secure location in production devices.
*/
#ifndef __CODESIGNER_CERTIFICATE__H__
#define __CODESIGNER_CERTIFICATE__H__

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
@ -24,22 +24,22 @@
*
*/
/**
* @file code_signature_verification.h
* @brief Interface for code signature verification functions.
*
*/
/**
* @file code_signature_verification.h
* @brief Interface for code signature verification functions.
*
*/
#ifndef CODE_SIGNATURE_VERIFICATION_H
#define CODE_SIGNATURE_VERIFICATION_H
#include "FreeRTOS.h"
/**
/**
* @brief Validate the integrity of the new image to be activated.
* @param[in] pFileContext pointer to File context
* @return OtaPalMainStatus_t , OtaPalSuccess if the signature of the image is valid.
*/
OtaPalMainStatus_t xValidateImageSignature( OtaFileContext_t* const pFileContext );
OtaPalMainStatus_t xValidateImageSignature( OtaFileContext_t * const pFileContext );
#endif

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
@ -24,25 +24,25 @@
*
*/
/**
* @file code_signature_verification_mbedtls.c
* @brief Code signature verification using mbedtls crypto.
*
* The file demonstrates implements the code signature verification functionality on
* the specified file using mbedtls for SHA256 ECDSA.
*/
/**
* @file code_signature_verification_mbedtls.c
* @brief Code signature verification using mbedtls crypto.
*
* The file demonstrates implements the code signature verification functionality on
* the specified file using mbedtls for SHA256 ECDSA.
*/
/* C runtime includes. */
/* C runtime includes. */
#include <string.h>
/* FreeRTOS includes. */
/* FreeRTOS includes. */
#include "FreeRTOS.h"
/* mbedTLS includes. */
#if !defined( MBEDTLS_CONFIG_FILE )
#include "mbedtls_config_v3.2.1.h"
#include "mbedtls_config_v3.2.1.h"
#else
#include MBEDTLS_CONFIG_FILE
#include MBEDTLS_CONFIG_FILE
#endif
#include "mbedtls/platform.h"
#include "mbedtls/sha256.h"
@ -60,10 +60,10 @@
/**
* @brief SHA256 buffer size for storing cryptographic hash computation results.
*/
#define SHA256_DIGEST_BYTES 32
#define SHA256_DIGEST_BYTES 32
/* Size of buffer used in file operations on this platform (Windows). */
#define OTA_PAL_WIN_BUF_SIZE ( ( size_t ) 4096UL )
/* Size of buffer used in file operations on this platform (Windows). */
#define OTA_PAL_WIN_BUF_SIZE ( ( size_t ) 4096UL )
/**
* @brief Library-independent cryptographic algorithm identifiers.
@ -73,9 +73,9 @@
#define ASYMMETRIC_ALGORITHM_RSA 1
#define ASYMMETRIC_ALGORITHM_ECDSA 2
/**
* @brief Internal signature verification context structure.
*/
/**
* @brief Internal signature verification context structure.
*/
typedef struct SignatureVerificationState
{
BaseType_t xAsymmetricAlgorithm;
@ -92,9 +92,9 @@ typedef struct SignatureVerificationState
*
* @return pdTRUE if initialization succeeds, or pdFALSE otherwise.
*/
static BaseType_t prvSignatureVerificationStart(void** ppvContext,
BaseType_t xAsymmetricAlgorithm,
BaseType_t xHashAlgorithm);
static BaseType_t prvSignatureVerificationStart( void ** ppvContext,
BaseType_t xAsymmetricAlgorithm,
BaseType_t xHashAlgorithm );
/**
* @brief Updates a cryptographic hash computation with the specified byte array.
@ -103,9 +103,9 @@ static BaseType_t prvSignatureVerificationStart(void** ppvContext,
* @param[in] pucData Byte array that was signed.
* @param[in] xDataLength Length in bytes of data that was signed.
*/
static void prvSignatureVerificationUpdate(void* pvContext,
const uint8_t* pucData,
size_t xDataLength);
static void prvSignatureVerificationUpdate( void * pvContext,
const uint8_t * pucData,
size_t xDataLength );
/**
* @brief Verifies a digital signature computation using the public key from the
@ -120,41 +120,41 @@ static void prvSignatureVerificationUpdate(void* pvContext,
*
* @return pdTRUE if the signature is correct or pdFALSE if the signature is invalid.
*/
static BaseType_t prvSignatureVerificationFinal(void* pvContext,
char* pcSignerCertificate,
size_t xSignerCertificateLength,
uint8_t* pucSignature,
size_t xSignatureLength);
static BaseType_t prvSignatureVerificationFinal( void * pvContext,
char * pcSignerCertificate,
size_t xSignerCertificateLength,
uint8_t * pucSignature,
size_t xSignatureLength );
/* Read the specified signer certificate from the filesystem into a local buffer. The allocated
* memory becomes the property of the caller who is responsible for freeing it.
*/
static uint8_t* otaPal_ReadAndAssumeCertificate(const uint8_t* const pucCertName,
uint32_t* const ulSignerCertSize)
static uint8_t * otaPal_ReadAndAssumeCertificate( const uint8_t * const pucCertName,
uint32_t * const ulSignerCertSize )
{
FILE* pFile;
uint8_t* pucSignerCert = NULL;
uint8_t* pucCertData = NULL;
FILE * pFile;
uint8_t * pucSignerCert = NULL;
uint8_t * pucCertData = NULL;
int32_t lSize = 0; /* For MISRA mandatory. */
int32_t lWindowsError;
pFile = fopen((const char*)pucCertName, "rb"); /*lint !e586
* C standard library call is being used for portability. */
pFile = fopen( ( const char * ) pucCertName, "rb" ); /*lint !e586
* C standard library call is being used for portability. */
if (pFile != NULL)
if( pFile != NULL )
{
lWindowsError = fseek(pFile, 0, SEEK_END); /*lint !e586
* C standard library call is being used for portability. */
lWindowsError = fseek( pFile, 0, SEEK_END ); /*lint !e586
* C standard library call is being used for portability. */
if (lWindowsError == 0) /* fseek returns a non-zero value on error. */
if( lWindowsError == 0 ) /* fseek returns a non-zero value on error. */
{
lSize = (int32_t)ftell(pFile); /*lint !e586 Allow call in this context. */
lSize = ( int32_t ) ftell( pFile ); /*lint !e586 Allow call in this context. */
if (lSize != -1L) /* ftell returns -1 on error. */
if( lSize != -1L ) /* ftell returns -1 on error. */
{
lWindowsError = fseek(pFile, 0, SEEK_SET); /*lint !e586
* C standard library call is being used for portability. */
lWindowsError = fseek( pFile, 0, SEEK_SET ); /*lint !e586
* C standard library call is being used for portability. */
}
else /* ftell returned an error, pucSignerCert remains NULL. */
{
@ -162,60 +162,60 @@ static uint8_t* otaPal_ReadAndAssumeCertificate(const uint8_t* const pucCertName
}
} /* else fseek returned an error, pucSignerCert remains NULL. */
if (lWindowsError == 0)
if( lWindowsError == 0 )
{
/* Allocate memory for the signer certificate plus a terminating zero so we can load and return it to the caller. */
pucSignerCert = pvPortMalloc(lSize + 1); /*lint !e732 !e9034 !e9079 Allow conversion. */
pucSignerCert = pvPortMalloc( lSize + 1 ); /*lint !e732 !e9034 !e9079 Allow conversion. */
}
if (pucSignerCert != NULL)
if( pucSignerCert != NULL )
{
if (fread(pucSignerCert, 1, lSize, pFile) == (size_t)lSize) /*lint !e586 !e732 !e9034
* C standard library call is being used for portability. */
if( fread( pucSignerCert, 1, lSize, pFile ) == ( size_t ) lSize ) /*lint !e586 !e732 !e9034
* C standard library call is being used for portability. */
{
/* The crypto code requires the terminating zero to be part of the length so add 1 to the size. */
*ulSignerCertSize = lSize + 1;
pucSignerCert[lSize] = 0;
pucSignerCert[ lSize ] = 0;
}
else
{ /* There was a problem reading the certificate file so free the memory and abort. */
vPortFree(pucSignerCert);
{ /* There was a problem reading the certificate file so free the memory and abort. */
vPortFree( pucSignerCert );
pucSignerCert = NULL;
}
}
else
{
LogError(("Failed to allocate memory for signer cert contents.\r\n"));
LogError( ( "Failed to allocate memory for signer cert contents.\r\n" ) );
/* Nothing special to do. */
}
lWindowsError = fclose(pFile); /*lint !e586
* C standard library call is being used for portability. */
lWindowsError = fclose( pFile ); /*lint !e586
* C standard library call is being used for portability. */
if (lWindowsError != 0)
if( lWindowsError != 0 )
{
LogError(("File pointer operation failed.\r\n"));
LogError( ( "File pointer operation failed.\r\n" ) );
pucSignerCert = NULL;
}
}
else
{
LogError(("No such certificate file: %s. Using aws_ota_codesigner_certificate.h.\r\n",
(const char*)pucCertName));
LogError( ( "No such certificate file: %s. Using aws_ota_codesigner_certificate.h.\r\n",
( const char * ) pucCertName ) );
/* Allocate memory for the signer certificate plus a terminating zero so we can copy it and return to the caller. */
lSize = sizeof(signingcredentialSIGNING_CERTIFICATE_PEM);
pucSignerCert = pvPortMalloc(lSize); /*lint !e9029 !e9079 !e838 malloc proto requires void*. */
pucCertData = (uint8_t*)signingcredentialSIGNING_CERTIFICATE_PEM; /*lint !e9005 we don't modify the cert but it could be set by PKCS11 so it's not const. */
lSize = sizeof( signingcredentialSIGNING_CERTIFICATE_PEM );
pucSignerCert = pvPortMalloc( lSize ); /*lint !e9029 !e9079 !e838 malloc proto requires void*. */
pucCertData = ( uint8_t * ) signingcredentialSIGNING_CERTIFICATE_PEM; /*lint !e9005 we don't modify the cert but it could be set by PKCS11 so it's not const. */
if (pucSignerCert != NULL)
if( pucSignerCert != NULL )
{
memcpy(pucSignerCert, pucCertData, lSize);
memcpy( pucSignerCert, pucCertData, lSize );
*ulSignerCertSize = lSize;
}
else
{
LogError(("No memory for certificate of size %d!\r\n", lSize));
LogError( ( "No memory for certificate of size %d!\r\n", lSize ) );
}
}
@ -226,29 +226,29 @@ static uint8_t* otaPal_ReadAndAssumeCertificate(const uint8_t* const pucCertName
* @brief Verifies a cryptographic signature based on the signer
* certificate, hash algorithm, and the data that was signed.
*/
static BaseType_t prvVerifySignature(char* pcSignerCertificate,
size_t xSignerCertificateLength,
BaseType_t xHashAlgorithm,
uint8_t* pucHash,
size_t xHashLength,
uint8_t* pucSignature,
size_t xSignatureLength)
static BaseType_t prvVerifySignature( char * pcSignerCertificate,
size_t xSignerCertificateLength,
BaseType_t xHashAlgorithm,
uint8_t * pucHash,
size_t xHashLength,
uint8_t * pucSignature,
size_t xSignatureLength )
{
BaseType_t xResult = pdTRUE;
mbedtls_x509_crt xCertCtx;
mbedtls_md_type_t xMbedHashAlg = MBEDTLS_MD_SHA256;
(void)xHashAlgorithm;
( void ) xHashAlgorithm;
memset(&xCertCtx, 0, sizeof(mbedtls_x509_crt));
memset( &xCertCtx, 0, sizeof( mbedtls_x509_crt ) );
/*
* Decode and create a certificate context
*/
mbedtls_x509_crt_init(&xCertCtx);
mbedtls_x509_crt_init( &xCertCtx );
if (0 != mbedtls_x509_crt_parse(
&xCertCtx, (const unsigned char*)pcSignerCertificate, xSignerCertificateLength))
if( 0 != mbedtls_x509_crt_parse(
&xCertCtx, ( const unsigned char * ) pcSignerCertificate, xSignerCertificateLength ) )
{
xResult = pdFALSE;
}
@ -256,15 +256,15 @@ static BaseType_t prvVerifySignature(char* pcSignerCertificate,
/*
* Verify the signature using the public key from the decoded certificate
*/
if (pdTRUE == xResult)
if( pdTRUE == xResult )
{
if (0 != mbedtls_pk_verify(
&xCertCtx.pk,
xMbedHashAlg,
pucHash,
xHashLength,
pucSignature,
xSignatureLength))
if( 0 != mbedtls_pk_verify(
&xCertCtx.pk,
xMbedHashAlg,
pucHash,
xHashLength,
pucSignature,
xSignatureLength ) )
{
xResult = pdFALSE;
}
@ -273,7 +273,7 @@ static BaseType_t prvVerifySignature(char* pcSignerCertificate,
/*
* Clean-up
*/
mbedtls_x509_crt_free(&xCertCtx);
mbedtls_x509_crt_free( &xCertCtx );
return xResult;
}
@ -283,23 +283,23 @@ static BaseType_t prvVerifySignature(char* pcSignerCertificate,
/**
* @brief Creates signature verification context.
*/
static BaseType_t prvSignatureVerificationStart(void** ppvContext,
BaseType_t xAsymmetricAlgorithm,
BaseType_t xHashAlgorithm)
static BaseType_t prvSignatureVerificationStart( void ** ppvContext,
BaseType_t xAsymmetricAlgorithm,
BaseType_t xHashAlgorithm )
{
BaseType_t xResult = pdTRUE;
SignatureVerificationState_t* pxCtx = NULL;
SignatureVerificationState_t * pxCtx = NULL;
/*
* Allocate the context
*/
if (NULL == (pxCtx = (SignatureVerificationStatePtr_t)pvPortMalloc(
sizeof(*pxCtx)))) /*lint !e9087 Allow casting void* to other types. */
if( NULL == ( pxCtx = ( SignatureVerificationStatePtr_t ) pvPortMalloc(
sizeof( *pxCtx ) ) ) ) /*lint !e9087 Allow casting void* to other types. */
{
xResult = pdFALSE;
}
if (pdTRUE == xResult)
if( pdTRUE == xResult )
{
*ppvContext = pxCtx;
@ -312,8 +312,8 @@ static BaseType_t prvSignatureVerificationStart(void** ppvContext,
/*
* Initialize the requested hash type
*/
mbedtls_sha256_init(&pxCtx->xSHA256Context);
(void)mbedtls_sha256_starts(&pxCtx->xSHA256Context, 0);
mbedtls_sha256_init( &pxCtx->xSHA256Context );
( void ) mbedtls_sha256_starts( &pxCtx->xSHA256Context, 0 );
}
return xResult;
@ -322,59 +322,58 @@ static BaseType_t prvSignatureVerificationStart(void** ppvContext,
/**
* @brief Adds bytes to an in-progress hash for subsequent signature verification.
*/
static void prvSignatureVerificationUpdate(void* pvContext,
const uint8_t* pucData,
size_t xDataLength)
static void prvSignatureVerificationUpdate( void * pvContext,
const uint8_t * pucData,
size_t xDataLength )
{
SignatureVerificationState_t* pxCtx = (SignatureVerificationStatePtr_t)pvContext; /*lint !e9087 Allow casting void* to other types. */
SignatureVerificationState_t * pxCtx = ( SignatureVerificationStatePtr_t ) pvContext; /*lint !e9087 Allow casting void* to other types. */
/*
* Add the data to the hash of the requested type
*/
(void)mbedtls_sha256_update(&pxCtx->xSHA256Context, pucData, xDataLength);
( void ) mbedtls_sha256_update( &pxCtx->xSHA256Context, pucData, xDataLength );
}
/**
* @brief Performs signature verification on a cryptographic hash.
*/
static BaseType_t prvSignatureVerificationFinal(void* pvContext,
char* pcSignerCertificate,
size_t xSignerCertificateLength,
uint8_t* pucSignature,
size_t xSignatureLength)
static BaseType_t prvSignatureVerificationFinal( void * pvContext,
char * pcSignerCertificate,
size_t xSignerCertificateLength,
uint8_t * pucSignature,
size_t xSignatureLength )
{
BaseType_t xResult = pdFALSE;
if (pvContext != NULL)
if( pvContext != NULL )
{
SignatureVerificationStatePtr_t pxCtx = (SignatureVerificationStatePtr_t)pvContext; /*lint !e9087 Allow casting void* to other types. */
uint8_t ucSHA256[SHA256_DIGEST_BYTES]; /* Reserve enough space for the larger for SHA256 results. */
uint8_t* pucHash = NULL;
SignatureVerificationStatePtr_t pxCtx = ( SignatureVerificationStatePtr_t ) pvContext; /*lint !e9087 Allow casting void* to other types. */
uint8_t ucSHA256[ SHA256_DIGEST_BYTES ]; /* Reserve enough space for the larger for SHA256 results. */
uint8_t * pucHash = NULL;
size_t xHashLength = 0;
if ((pcSignerCertificate != NULL) &&
(pucSignature != NULL) &&
(xSignerCertificateLength > 0UL) &&
(xSignatureLength > 0UL))
if( ( pcSignerCertificate != NULL ) &&
( pucSignature != NULL ) &&
( xSignerCertificateLength > 0UL ) &&
( xSignatureLength > 0UL ) )
{
/*
* Finish the hash.
*/
(void)mbedtls_sha256_finish(&pxCtx->xSHA256Context, ucSHA256);
( void ) mbedtls_sha256_finish( &pxCtx->xSHA256Context, ucSHA256 );
pucHash = ucSHA256;
xHashLength = SHA256_DIGEST_BYTES;
/*
* Verify the signature.
*/
xResult = prvVerifySignature(pcSignerCertificate,
xSignerCertificateLength,
pxCtx->xHashAlgorithm,
pucHash,
xHashLength,
pucSignature,
xSignatureLength);
xResult = prvVerifySignature( pcSignerCertificate,
xSignerCertificateLength,
pxCtx->xHashAlgorithm,
pucHash,
xHashLength,
pucSignature,
xSignatureLength );
}
else
{
@ -384,82 +383,83 @@ static BaseType_t prvSignatureVerificationFinal(void* pvContext,
/*
* Clean-up
*/
vPortFree(pxCtx);
vPortFree( pxCtx );
}
return xResult;
}
/* Verify the signature of the specified file. */
OtaPalMainStatus_t xValidateImageSignature(OtaFileContext_t* const C)
OtaPalMainStatus_t xValidateImageSignature( OtaFileContext_t * const C )
{
OtaPalMainStatus_t eResult = OtaPalSuccess;
uint32_t ulBytesRead;
uint32_t ulSignerCertSize;
uint8_t* pucBuf, * pucSignerCert;
void* pvSigVerifyContext;
uint8_t * pucBuf, * pucSignerCert;
void * pvSigVerifyContext;
/* Verify an ECDSA-SHA256 signature. */
if (pdFALSE == prvSignatureVerificationStart(&pvSigVerifyContext, ASYMMETRIC_ALGORITHM_ECDSA, HASH_ALGORITHM_SHA256))
{
eResult = OtaPalSignatureCheckFailed;
}
else
/* Verify an ECDSA-SHA256 signature. */
if( pdFALSE == prvSignatureVerificationStart( &pvSigVerifyContext, ASYMMETRIC_ALGORITHM_ECDSA, HASH_ALGORITHM_SHA256 ) )
{
eResult = OtaPalSignatureCheckFailed;
}
else
{
LogInfo( ( "Started %s signature verification, file: %s\r\n",
OTA_JsonFileSignatureKey, ( const char * ) C->pCertFilepath ) );
pucSignerCert = otaPal_ReadAndAssumeCertificate( ( const uint8_t * const ) C->pCertFilepath, &ulSignerCertSize );
if( pucSignerCert != NULL )
{
LogInfo(("Started %s signature verification, file: %s\r\n",
OTA_JsonFileSignatureKey, (const char*)C->pCertFilepath));
pucSignerCert = otaPal_ReadAndAssumeCertificate((const uint8_t* const)C->pCertFilepath, &ulSignerCertSize);
pucBuf = pvPortMalloc( OTA_PAL_WIN_BUF_SIZE ); /*lint !e9079 Allow conversion. */
if (pucSignerCert != NULL)
if( pucBuf != NULL )
{
pucBuf = pvPortMalloc( OTA_PAL_WIN_BUF_SIZE ); /*lint !e9079 Allow conversion. */
if (pucBuf != NULL)
/* Rewind the received file to the beginning. */
if( fseek( C->pFile, 0L, SEEK_SET ) == 0 ) /*lint !e586
* C standard library call is being used for portability. */
{
/* Rewind the received file to the beginning. */
if (fseek(C->pFile, 0L, SEEK_SET) == 0) /*lint !e586
* C standard library call is being used for portability. */
do
{
do
{
ulBytesRead = fread(pucBuf, 1, OTA_PAL_WIN_BUF_SIZE, C->pFile); /*lint !e586
* C standard library call is being used for portability. */
/* Include the file chunk in the signature validation. Zero size is OK. */
prvSignatureVerificationUpdate(pvSigVerifyContext, pucBuf, ulBytesRead);
} while (ulBytesRead > 0UL);
if (pdFALSE == prvSignatureVerificationFinal(pvSigVerifyContext,
(char*)pucSignerCert,
(size_t)ulSignerCertSize,
C->pSignature->data,
C->pSignature->size)) /*lint !e732 !e9034 Allow comparison in this context. */
{
eResult = OtaPalSignatureCheckFailed;
}
pvSigVerifyContext = NULL; /* The context has been freed by prvSignatureVerificationFinal(). */
}
else
ulBytesRead = fread( pucBuf, 1, OTA_PAL_WIN_BUF_SIZE, C->pFile ); /*lint !e586
* C standard library call is being used for portability. */
/* Include the file chunk in the signature validation. Zero size is OK. */
prvSignatureVerificationUpdate( pvSigVerifyContext, pucBuf, ulBytesRead );
} while( ulBytesRead > 0UL );
if( pdFALSE == prvSignatureVerificationFinal( pvSigVerifyContext,
( char * ) pucSignerCert,
( size_t ) ulSignerCertSize,
C->pSignature->data,
C->pSignature->size ) ) /*lint !e732 !e9034 Allow comparison in this context. */
{
/* Nothing special to do. */
eResult = OtaPalSignatureCheckFailed;
}
/* Free the temporary file page buffer. */
vPortFree(pucBuf);
pvSigVerifyContext = NULL; /* The context has been freed by prvSignatureVerificationFinal(). */
}
else
{
LogError(("Failed to allocate buffer memory.\r\n"));
eResult = OtaPalOutOfMemory;
/* Nothing special to do. */
}
/* Free the signer certificate that we now own after prvReadAndAssumeCertificate(). */
vPortFree(pucSignerCert);
/* Free the temporary file page buffer. */
vPortFree( pucBuf );
}
else
{
eResult = OtaPalBadSignerCert;
LogError( ( "Failed to allocate buffer memory.\r\n" ) );
eResult = OtaPalOutOfMemory;
}
/* Free the signer certificate that we now own after prvReadAndAssumeCertificate(). */
vPortFree( pucSignerCert );
}
else
{
eResult = OtaPalBadSignerCert;
}
}
return eResult;
}
}

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
@ -52,7 +52,7 @@ static OtaPalMainStatus_t otaPal_CheckFileSignature( OtaFileContext_t * const C
/*-----------------------------------------------------------*/
static inline BaseType_t prvContextValidate( OtaFileContext_t* pFileContext )
static inline BaseType_t prvContextValidate( OtaFileContext_t * pFileContext )
{
return( ( pFileContext != NULL ) &&
( pFileContext->pFile != NULL ) ); /*lint !e9034 Comparison is correct for file pointer type. */
@ -63,19 +63,19 @@ static inline BaseType_t prvContextValidate( OtaFileContext_t* pFileContext )
/* Attempt to create a new receive file for the file chunks as they come in. */
OtaPalStatus_t otaPal_CreateFileForRx( OtaFileContext_t* const C )
OtaPalStatus_t otaPal_CreateFileForRx( OtaFileContext_t * const C )
{
OtaPalMainStatus_t mainErr = OtaPalUninitialized;
OtaPalSubStatus_t subErr = 0;
if( C != NULL )
{
if ( C->pFilePath != NULL )
if( C->pFilePath != NULL )
{
C->pFile = fopen( ( const char * )C->pFilePath, "w+b" ); /*lint !e586
* C standard library call is being used for portability. */
C->pFile = fopen( ( const char * ) C->pFilePath, "w+b" ); /*lint !e586
* C standard library call is being used for portability. */
if ( C->pFile != NULL )
if( C->pFile != NULL )
{
mainErr = OtaPalSuccess;
LogInfo( ( "Receive file created.\r\n" ) );
@ -99,7 +99,7 @@ OtaPalStatus_t otaPal_CreateFileForRx( OtaFileContext_t* const C )
LogError( ( "ERROR - Invalid file context provided.\r\n" ) );
}
return OTA_PAL_COMBINE_ERR(mainErr,subErr);
return OTA_PAL_COMBINE_ERR( mainErr, subErr );
}
@ -118,7 +118,7 @@ OtaPalStatus_t otaPal_Abort( OtaFileContext_t * const C )
if( NULL != C->pFile )
{
lFileCloseResult = fclose( C->pFile ); /*lint !e482 !e586
* Context file handle state is managed by this API. */
* Context file handle state is managed by this API. */
C->pFile = NULL;
if( 0 == lFileCloseResult )
@ -145,7 +145,7 @@ OtaPalStatus_t otaPal_Abort( OtaFileContext_t * const C )
mainErr = OtaPalFileAbort;
}
return OTA_PAL_COMBINE_ERR(mainErr,subErr);
return OTA_PAL_COMBINE_ERR( mainErr, subErr );
}
/* Write a block of data to the specified file. */
@ -159,12 +159,12 @@ int16_t otaPal_WriteBlock( OtaFileContext_t * const C,
if( prvContextValidate( C ) == pdTRUE )
{
lResult = fseek( C->pFile, ulOffset, SEEK_SET ); /*lint !e586 !e713 !e9034
* C standard library call is being used for portability. */
* C standard library call is being used for portability. */
if( 0 == lResult )
{
lResult = fwrite( pacData, 1, ulBlockSize, C->pFile ); /*lint !e586 !e713 !e9034
* C standard library call is being used for portability. */
* C standard library call is being used for portability. */
if( lResult < 0 )
{
@ -216,7 +216,7 @@ OtaPalStatus_t otaPal_CloseFile( OtaFileContext_t * const C )
/* Close the file. */
lWindowsError = fclose( C->pFile ); /*lint !e482 !e586
* C standard library call is being used for portability. */
* C standard library call is being used for portability. */
C->pFile = NULL;
if( lWindowsError != 0 )
@ -233,11 +233,10 @@ OtaPalStatus_t otaPal_CloseFile( OtaFileContext_t * const C )
else
{
LogError( ( "Failed to pass %s signature verification: %d.\r\n",
OTA_JsonFileSignatureKey, OTA_PAL_COMBINE_ERR(mainErr,subErr) ) );
OTA_JsonFileSignatureKey, OTA_PAL_COMBINE_ERR( mainErr, subErr ) ) );
/* If we fail to verify the file signature that means the image is not valid. We need to set the image state to aborted. */
otaPal_SetPlatformImageState( C, OtaImageStateAborted );
}
}
else /* Invalid OTA Context. */
@ -247,17 +246,17 @@ OtaPalStatus_t otaPal_CloseFile( OtaFileContext_t * const C )
mainErr = OtaPalFileClose;
}
return OTA_PAL_COMBINE_ERR(mainErr,subErr);
return OTA_PAL_COMBINE_ERR( mainErr, subErr );
}
/* Verify the signature of the specified file. */
static OtaPalMainStatus_t otaPal_CheckFileSignature( OtaFileContext_t* const C )
static OtaPalMainStatus_t otaPal_CheckFileSignature( OtaFileContext_t * const C )
{
OtaPalMainStatus_t eResult = OtaPalSignatureCheckFailed;
if ( prvContextValidate( C ) == pdTRUE )
if( prvContextValidate( C ) == pdTRUE )
{
eResult = xValidateImageSignature( C );
}
@ -271,40 +270,41 @@ static OtaPalMainStatus_t otaPal_CheckFileSignature( OtaFileContext_t* const C )
/*-----------------------------------------------------------*/
OtaPalStatus_t otaPal_ResetDevice( OtaFileContext_t* const pFileContext )
OtaPalStatus_t otaPal_ResetDevice( OtaFileContext_t * const pFileContext )
{
(void)pFileContext;
( void ) pFileContext;
/* Return no error. Windows implementation does not reset device. */
return OTA_PAL_COMBINE_ERR(OtaPalSuccess,0);
return OTA_PAL_COMBINE_ERR( OtaPalSuccess, 0 );
}
/*-----------------------------------------------------------*/
OtaPalStatus_t otaPal_ActivateNewImage( OtaFileContext_t* const pFileContext )
OtaPalStatus_t otaPal_ActivateNewImage( OtaFileContext_t * const pFileContext )
{
(void)pFileContext;
( void ) pFileContext;
/* Return no error. Windows implementation simply does nothing on activate.
* To run the new firmware image, double click the newly downloaded exe */
return OTA_PAL_COMBINE_ERR(OtaPalSuccess,0);
return OTA_PAL_COMBINE_ERR( OtaPalSuccess, 0 );
}
/*
* Set the final state of the last transferred (final) OTA file (or bundle).
* On Windows, the state of the OTA image is stored in PlaformImageState.txt.
* On Windows, the state of the OTA image is stored in PlatformImageState.txt.
*/
OtaPalStatus_t otaPal_SetPlatformImageState( OtaFileContext_t * const pFileContext, OtaImageState_t eState )
OtaPalStatus_t otaPal_SetPlatformImageState( OtaFileContext_t * const pFileContext,
OtaImageState_t eState )
{
(void)pFileContext;
( void ) pFileContext;
OtaPalMainStatus_t mainErr = OtaPalSuccess;
OtaPalSubStatus_t subErr = 0;
FILE * pstPlatformImageState;
if( eState != OtaImageStateUnknown && eState <= OtaLastImageState )
if( ( eState != OtaImageStateUnknown ) && ( eState <= OtaLastImageState ) )
{
pstPlatformImageState = fopen( "PlatformImageState.txt", "w+b" ); /*lint !e586
* C standard library call is being used for portability. */
@ -313,7 +313,7 @@ OtaPalStatus_t otaPal_SetPlatformImageState( OtaFileContext_t * const pFileConte
{
/* Write the image state to PlatformImageState.txt. */
if( 1 != fwrite( &eState, sizeof( OtaImageState_t ), 1, pstPlatformImageState ) ) /*lint !e586 !e9029
* C standard library call is being used for portability. */
* C standard library call is being used for portability. */
{
LogError( ( "Unable to write to image state file.\r\n" ) );
mainErr = OtaPalBadImageState;
@ -334,14 +334,14 @@ OtaPalStatus_t otaPal_SetPlatformImageState( OtaFileContext_t * const pFileConte
mainErr = OtaPalBadImageState;
subErr = errno;
}
} /*lint !e481 Allow fopen and fclose calls in this context. */
} /*lint !e481 Allow fopen and fclose calls in this context. */
else /* Image state invalid. */
{
LogError( ( "ERROR - Invalid image state provided.\r\n" ) );
mainErr = OtaPalBadImageState;
}
return OTA_PAL_COMBINE_ERR(mainErr,subErr);
return OTA_PAL_COMBINE_ERR( mainErr, subErr );
}
/* Get the state of the currently running image.
@ -358,7 +358,7 @@ OtaPalStatus_t otaPal_SetPlatformImageState( OtaFileContext_t * const pFileConte
*/
OtaPalImageState_t otaPal_GetPlatformImageState( OtaFileContext_t * const pFileContext )
{
(void)pFileContext;
( void ) pFileContext;
FILE * pstPlatformImageState;
OtaImageState_t eSavedAgentState = OtaImageStateUnknown;
@ -369,23 +369,25 @@ OtaPalImageState_t otaPal_GetPlatformImageState( OtaFileContext_t * const pFileC
if( pstPlatformImageState != NULL )
{
if( 1 != fread( &eSavedAgentState, sizeof(OtaImageState_t), 1, pstPlatformImageState ) ) /*lint !e586 !e9029
* C standard library call is being used for portability. */
if( 1 != fread( &eSavedAgentState, sizeof( OtaImageState_t ), 1, pstPlatformImageState ) ) /*lint !e586 !e9029
* C standard library call is being used for portability. */
{
/* If an error occurred reading the file, mark the state as aborted. */
LogError( ( "Unable to read image state file.\r\n" ) );
ePalState = ( OtaPalImageStateInvalid | (errno & OTA_PAL_ERR_MASK) );
ePalState = ( OtaPalImageStateInvalid | ( errno & OTA_PAL_ERR_MASK ) );
}
else
{
switch (eSavedAgentState)
switch( eSavedAgentState )
{
case OtaImageStateTesting:
ePalState = OtaPalImageStatePendingCommit;
break;
case OtaImageStateAccepted:
ePalState = OtaPalImageStateValid;
break;
case OtaImageStateRejected:
case OtaImageStateAborted:
default:
@ -394,12 +396,11 @@ OtaPalImageState_t otaPal_GetPlatformImageState( OtaFileContext_t * const pFileC
}
}
if( 0 != fclose( pstPlatformImageState ) ) /*lint !e586
* C standard library call is being used for portability. */
{
LogError( ( "Unable to close image state file.\r\n" ) );
ePalState = (OtaPalImageStateInvalid | ( errno & OTA_PAL_ERR_MASK ) );
ePalState = ( OtaPalImageStateInvalid | ( errno & OTA_PAL_ERR_MASK ) );
}
}
else
@ -415,5 +416,5 @@ OtaPalImageState_t otaPal_GetPlatformImageState( OtaFileContext_t * const pFileC
/* Provide access to private members for testing. */
#ifdef FREERTOS_ENABLE_UNIT_TESTS
#include "aws_ota_pal_test_access_define.h"
#include "aws_ota_pal_test_access_define.h"
#endif

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
@ -26,7 +26,7 @@
/**
* @file ota_pal.h
* @brief Function declarations for ota_ptal.c.
* @brief Function declarations for ota_pal.c.
*/
#ifndef _OTA_PAL_H_
@ -54,7 +54,7 @@
* OTA_ERR_NONE is returned when aborting access to the open file was successful.
* OTA_ERR_FILE_ABORT is returned when aborting access to the open file context was unsuccessful.
*/
OtaPalStatus_t otaPal_Abort( OtaFileContext_t * const C );
OtaPalStatus_t otaPal_Abort( OtaFileContext_t * const C );
/**
* @brief Create a new receive file for the data chunks as they come in.
@ -79,7 +79,7 @@ OtaPalStatus_t otaPal_Abort( OtaFileContext_t * const C );
* OTA_ERR_BOOT_INFO_CREATE_FAILED is returned if the bootloader information file creation fails.
* OTA_ERR_RX_FILE_CREATE_FAILED is returned for other errors creating the file in the device's non-volatile memory.
*/
OtaPalStatus_t otaPal_CreateFileForRx( OtaFileContext_t * const C );
OtaPalStatus_t otaPal_CreateFileForRx( OtaFileContext_t * const C );
/* @brief Authenticate and close the underlying receive file in the specified OTA context.
*
@ -104,7 +104,7 @@ OtaPalStatus_t otaPal_CreateFileForRx( OtaFileContext_t * const C );
* OTA_ERR_BAD_SIGNER_CERT is returned for errors in the certificate itself.
* OTA_ERR_FILE_CLOSE is returned when closing the file fails.
*/
OtaPalStatus_t otaPal_CloseFile( OtaFileContext_t * const C );
OtaPalStatus_t otaPal_CloseFile( OtaFileContext_t * const C );
/**
* @brief Write a block of data to the specified file at the given offset.
@ -141,7 +141,7 @@ int16_t otaPal_WriteBlock( OtaFileContext_t * const C,
* @return The OTA PAL layer error code combined with the MCU specific error code. See OTA Agent
* error codes information in ota.h.
*/
OtaPalStatus_t otaPal_ActivateNewImage( OtaFileContext_t * const C );
OtaPalStatus_t otaPal_ActivateNewImage( OtaFileContext_t * const C );
/**
* @brief Reset the device.
@ -155,7 +155,7 @@ OtaPalStatus_t otaPal_ActivateNewImage( OtaFileContext_t * const C );
* error codes information in ota.h.
*/
OtaPalStatus_t otaPal_ResetDevice( OtaFileContext_t * const C );
OtaPalStatus_t otaPal_ResetDevice( OtaFileContext_t * const C );
/**
* @brief Attempt to set the state of the OTA update image.
@ -176,8 +176,8 @@ OtaPalStatus_t otaPal_ResetDevice( OtaFileContext_t * const C );
* OTA_ERR_REJECT_FAILED: failed to roll back the update image as requested by OtaImageStateRejected.
* OTA_ERR_COMMIT_FAILED: failed to make the update image permanent as requested by OtaImageStateAccepted.
*/
OtaPalStatus_t otaPal_SetPlatformImageState( OtaFileContext_t * const C,
OtaImageState_t eState );
OtaPalStatus_t otaPal_SetPlatformImageState( OtaFileContext_t * const C,
OtaImageState_t eState );
/**
* @brief Get the state of the OTA update image.
@ -202,4 +202,4 @@ OtaPalStatus_t otaPal_SetPlatformImageState( OtaFileContext_t * const C,
*/
OtaPalImageState_t otaPal_GetPlatformImageState( OtaFileContext_t * const C );
#endif /* ifndef _OTA_PAL_H_ */
#endif /* ifndef _OTA_PAL_H_ */

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
@ -672,7 +672,7 @@ static void prvMQTTAgentTask( void * pParam );
*
* The implementation uses MQTT agent to queue a publish request. It then waits
* for the request complete notification from the agent. The notification along with result of the
* operation is sent back to the caller task using xTaksNotify API. For publishes involving QOS 1 and
* operation is sent back to the caller task using xTaskNotify API. For publishes involving QOS 1 and
* QOS2 the operation is complete once an acknowledgment (PUBACK) is received. OTA agent uses this function
* to fetch new job, provide status update and send other control related messages to the MQTT broker.
*
@ -808,7 +808,7 @@ static void prvMqttDataCallback( void * pContext,
*
* The callback is not subscribed with MQTT broker, but only with local subscription manager.
* A wildcard OTA job topic is used for subscription so that all unsolicited messages related to OTA is
* forwarded to this callback for filteration. Right now the callback is used to filter responses to job requests
* forwarded to this callback for filtration. Right now the callback is used to filter responses to job requests
* from the OTA service.
*
* @param[in] pvIncomingPublishCallbackContext MQTT context which stores the connection.
@ -1186,12 +1186,12 @@ static void prvCommandCallback( MQTTAgentCommandContext_t * pxCommandContext,
static void prvMQTTSubscribeCompleteCallback( MQTTAgentCommandContext_t * pxCommandContext,
MQTTAgentReturnInfo_t * pxReturnInfo )
{
MQTTAgentSubscribeArgs_t * pSubsribeArgs;
MQTTAgentSubscribeArgs_t * pSubscribeArgs;
if( pxReturnInfo->returnCode == MQTTSuccess )
{
pSubsribeArgs = ( MQTTAgentSubscribeArgs_t * ) ( pxCommandContext->pArgs );
prvRegisterOTACallback( pSubsribeArgs->pSubscribeInfo->pTopicFilter, pSubsribeArgs->pSubscribeInfo->topicFilterLength );
pSubscribeArgs = ( MQTTAgentSubscribeArgs_t * ) ( pxCommandContext->pArgs );
prvRegisterOTACallback( pSubscribeArgs->pSubscribeInfo->pTopicFilter, pSubscribeArgs->pSubscribeInfo->topicFilterLength );
}
/* Store the result in the application defined context so the task that
@ -1431,41 +1431,43 @@ static BaseType_t prvSocketConnect( NetworkContext_t * pxNetworkContext )
NetworkCredentials_t xNetworkCredentials = { 0 };
#if defined( democonfigUSE_AWS_IOT_CORE_BROKER )
#if defined( democonfigCLIENT_USERNAME )
/*
* When democonfigCLIENT_USERNAME is defined, use the "mqtt" alpn to connect
* to AWS IoT Core with Custom Authentication on port 443.
*
* Custom Authentication uses the contents of the username and password
* fields of the MQTT CONNECT packet to authenticate the client.
*
* For more information, refer to the documentation at:
* https://docs.aws.amazon.com/iot/latest/developerguide/custom-authentication.html
*/
static const char * ppcAlpnProtocols[] = { "mqtt", NULL };
#if democonfigMQTT_BROKER_PORT != 443U
#error "Connections to AWS IoT Core with custom authentication must connect to TCP port 443 with the \"mqtt\" alpn."
#endif /* democonfigMQTT_BROKER_PORT != 443U */
#else /* if !defined( democonfigCLIENT_USERNAME ) */
/*
* Otherwise, use the "x-amzn-mqtt-ca" alpn to connect to AWS IoT Core using
* x509 Certificate Authentication.
*/
static const char * ppcAlpnProtocols[] = { "x-amzn-mqtt-ca", NULL };
#endif /* !defined( democonfigCLIENT_USERNAME ) */
#if defined( democonfigCLIENT_USERNAME )
/*
* An ALPN identifier is only required when connecting to AWS IoT core on port 443.
* https://docs.aws.amazon.com/iot/latest/developerguide/protocols.html
* When democonfigCLIENT_USERNAME is defined, use the "mqtt" alpn to connect
* to AWS IoT Core with Custom Authentication on port 443.
*
* Custom Authentication uses the contents of the username and password
* fields of the MQTT CONNECT packet to authenticate the client.
*
* For more information, refer to the documentation at:
* https://docs.aws.amazon.com/iot/latest/developerguide/custom-authentication.html
*/
#if democonfigMQTT_BROKER_PORT == 443U
xNetworkCredentials.pAlpnProtos = ppcAlpnProtocols;
#elif democonfigMQTT_BROKER_PORT == 8883U
xNetworkCredentials.pAlpnProtos = NULL;
#else /* democonfigMQTT_BROKER_PORT != 8883U */
xNetworkCredentials.pAlpnProtos = NULL;
#error "MQTT connections to AWS IoT Core are only allowed on ports 443 and 8883."
static const char * ppcAlpnProtocols[] = { "mqtt", NULL };
#if democonfigMQTT_BROKER_PORT != 443U
#error "Connections to AWS IoT Core with custom authentication must connect to TCP port 443 with the \"mqtt\" alpn."
#endif /* democonfigMQTT_BROKER_PORT != 443U */
#else /* if !defined( democonfigCLIENT_USERNAME ) */
/*
* Otherwise, use the "x-amzn-mqtt-ca" alpn to connect to AWS IoT Core using
* x509 Certificate Authentication.
*/
static const char * ppcAlpnProtocols[] = { "x-amzn-mqtt-ca", NULL };
#endif /* !defined( democonfigCLIENT_USERNAME ) */
/*
* An ALPN identifier is only required when connecting to AWS IoT core on port 443.
* https://docs.aws.amazon.com/iot/latest/developerguide/protocols.html
*/
#if democonfigMQTT_BROKER_PORT == 443U
xNetworkCredentials.pAlpnProtos = ppcAlpnProtocols;
#elif democonfigMQTT_BROKER_PORT == 8883U
xNetworkCredentials.pAlpnProtos = NULL;
#else /* democonfigMQTT_BROKER_PORT != 8883U */
xNetworkCredentials.pAlpnProtos = NULL;
#error "MQTT connections to AWS IoT Core are only allowed on ports 443 and 8883."
#endif /* democonfigMQTT_BROKER_PORT != 443U */
#else /* !defined( democonfigUSE_AWS_IOT_CORE_BROKER ) */
xNetworkCredentials.pAlpnProtos = NULL;
#endif /* !defined( democonfigUSE_AWS_IOT_CORE_BROKER ) */
@ -2501,7 +2503,7 @@ static BaseType_t prvRunOTADemo( void )
}
/**
* Remvove callback for receiving messages intended for OTA agent from broker,
* Remove callback for receiving messages intended for OTA agent from broker,
* for which the topic has not been subscribed for.
*/
removeSubscription( ( SubscriptionElement_t * ) xGlobalMqttAgentContext.pIncomingCallbackContext,

@ -1,249 +1,249 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{4be4e103-5bf4-4a85-9656-ec20852a2b8e}</ProjectGuid>
<RootNamespace>OtaOverHttpDemo</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<TargetName>RTOSDemo</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<TargetName>RTOSDemo</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<TargetName>RTOSDemo</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<TargetName>RTOSDemo</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>false</SDLCheck>
<PreprocessorDefinitions>MQTT_AGENT_DO_NOT_USE_CUSTOM_CONFIG;WIN32;__little_endian__=1;_DEBUG;_CONSOLE;WIN32;MBEDTLS_CONFIG_FILE="mbedtls_config_v3.2.1.h";%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>..\Common\HTTP_Utils;..\..\..\..\Source\Application-Protocols\network_transport\tcp_sockets_wrapper\include;..\..\..\..\Source\Application-Protocols\network_transport;..\..\..\Common\coreMQTT_Agent_Interface\include;..\..\..\..\ThirdParty\tinycbor\src;..\..\..\..\Source\Utilities\backoff_algorithm\source\include;..\..\..\..\Source\coreJSON\source\include;..\..\..\..\Source\AWS\ota\source\include;..\..\..\..\Source\AWS\ota\source\portable\os;..\..\..\..\Source\Application-Protocols\coreMQTT-Agent\source\include;..\..\..\..\Source\Application-Protocols\coreMQTT\source\interface;..\..\..\..\Source\Application-Protocols\coreMQTT\source\include;..\Common\Ota_PAL\Win32\Code_Signature_Verification;..\Common\Ota_PAL\Win32;..\Common\subscription-manager;.\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>false</SDLCheck>
<PreprocessorDefinitions>MQTT_AGENT_DO_NOT_USE_CUSTOM_CONFIG;WIN32;__little_endian__=1;WIN32;NDEBUG;_CONSOLE;MBEDTLS_CONFIG_FILE="mbedtls_config_v3.2.1.h";%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>..\Common\HTTP_Utils;..\..\..\..\Source\Application-Protocols\network_transport\tcp_sockets_wrapper\include;..\..\..\..\Source\Application-Protocols\network_transport;..\..\..\Common\coreMQTT_Agent_Interface\include;..\..\..\..\ThirdParty\tinycbor\src;..\..\..\..\Source\Utilities\backoff_algorithm\source\include;..\..\..\..\Source\coreJSON\source\include;..\..\..\..\Source\AWS\ota\source\include;..\..\..\..\Source\AWS\ota\source\portable\os;..\..\..\..\Source\Application-Protocols\coreMQTT-Agent\source\include;..\..\..\..\Source\Application-Protocols\coreMQTT\source\interface;..\..\..\..\Source\Application-Protocols\coreMQTT\source\include;..\Common\Ota_PAL\Win32\Code_Signature_Verification;..\Common\Ota_PAL\Win32;..\Common\subscription-manager;.\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>false</SDLCheck>
<PreprocessorDefinitions>MQTT_AGENT_DO_NOT_USE_CUSTOM_CONFIG;WIN32;__little_endian__=1;_DEBUG;_CONSOLE;MBEDTLS_CONFIG_FILE="mbedtls_config_v3.2.1.h";%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>..\Common\HTTP_Utils;..\..\..\..\Source\Application-Protocols\network_transport\tcp_sockets_wrapper\include;..\..\..\..\Source\Application-Protocols\network_transport;..\..\..\Common\coreMQTT_Agent_Interface\include;..\..\..\..\ThirdParty\tinycbor\src;..\..\..\..\Source\Utilities\backoff_algorithm\source\include;..\..\..\..\Source\coreJSON\source\include;..\..\..\..\Source\AWS\ota\source\include;..\..\..\..\Source\AWS\ota\source\portable\os;..\..\..\..\Source\Application-Protocols\coreMQTT-Agent\source\include;..\..\..\..\Source\Application-Protocols\coreMQTT\source\interface;..\..\..\..\Source\Application-Protocols\coreMQTT\source\include;..\Common\Ota_PAL\Win32\Code_Signature_Verification;..\Common\Ota_PAL\Win32;..\Common\subscription-manager;.\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>false</SDLCheck>
<PreprocessorDefinitions>MQTT_AGENT_DO_NOT_USE_CUSTOM_CONFIG;WIN32;__little_endian__=1;NDEBUG;_CONSOLE;MBEDTLS_CONFIG_FILE="mbedtls_config_v3.2.1.h";%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>..\Common\HTTP_Utils;..\..\..\..\Source\Application-Protocols\network_transport\tcp_sockets_wrapper\include;..\..\..\..\Source\Application-Protocols\network_transport;..\..\..\Common\coreMQTT_Agent_Interface\include;..\..\..\..\ThirdParty\tinycbor\src;..\..\..\..\Source\Utilities\backoff_algorithm\source\include;..\..\..\..\Source\coreJSON\source\include;..\..\..\..\Source\AWS\ota\source\include;..\..\..\..\Source\AWS\ota\source\portable\os;..\..\..\..\Source\Application-Protocols\coreMQTT-Agent\source\include;..\..\..\..\Source\Application-Protocols\coreMQTT\source\interface;..\..\..\..\Source\Application-Protocols\coreMQTT\source\include;..\Common\Ota_PAL\Win32\Code_Signature_Verification;..\Common\Ota_PAL\Win32;..\Common\subscription-manager;.\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\VisualStudio_StaticProjects\coreHTTP\coreHTTP.vcxproj">
<Project>{ee39fa0f-cefb-4c29-a571-05a28fdd47fd}</Project>
</ProjectReference>
<ProjectReference Include="..\..\..\..\VisualStudio_StaticProjects\FreeRTOS+TCP\FreeRTOS+TCP.vcxproj">
<Project>{c90e6cc5-818b-4c97-8876-0986d989387c}</Project>
</ProjectReference>
<ProjectReference Include="..\..\..\..\VisualStudio_StaticProjects\FreeRTOS-Kernel\FreeRTOS-Kernel.vcxproj">
<Project>{72c209c4-49a4-4942-a201-44706c9d77ec}</Project>
</ProjectReference>
<ProjectReference Include="..\..\..\..\VisualStudio_StaticProjects\Logging\Logging.vcxproj">
<Project>{be362ac0-b10b-4276-b84e-6304652ba228}</Project>
</ProjectReference>
<ProjectReference Include="..\..\..\..\VisualStudio_StaticProjects\MbedTLS\MbedTLS.vcxproj">
<Project>{e1016f3e-94e9-4864-9fd8-1d7c1fefbfd7}</Project>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\..\..\Source\Application-Protocols\coreMQTT-Agent\source\core_mqtt_agent.c" />
<ClCompile Include="..\..\..\..\Source\Application-Protocols\coreMQTT-Agent\source\core_mqtt_agent_command_functions.c" />
<ClCompile Include="..\..\..\..\Source\Application-Protocols\coreMQTT\source\core_mqtt.c" />
<ClCompile Include="..\..\..\..\Source\Application-Protocols\coreMQTT\source\core_mqtt_serializer.c" />
<ClCompile Include="..\..\..\..\Source\Application-Protocols\coreMQTT\source\core_mqtt_state.c" />
<ClCompile Include="..\..\..\..\Source\Application-Protocols\network_transport\mbedtls_bio_tcp_sockets_wrapper.c" />
<ClCompile Include="..\..\..\..\Source\Application-Protocols\network_transport\tcp_sockets_wrapper\ports\freertos_plus_tcp\tcp_sockets_wrapper.c" />
<ClCompile Include="..\..\..\..\Source\Application-Protocols\network_transport\transport_mbedtls.c" />
<ClCompile Include="..\..\..\..\Source\AWS\ota\source\ota.c" />
<ClCompile Include="..\..\..\..\Source\AWS\ota\source\ota_base64.c" />
<ClCompile Include="..\..\..\..\Source\AWS\ota\source\ota_cbor.c" />
<ClCompile Include="..\..\..\..\Source\AWS\ota\source\ota_http.c" />
<ClCompile Include="..\..\..\..\Source\AWS\ota\source\ota_interface.c" />
<ClCompile Include="..\..\..\..\Source\AWS\ota\source\ota_mqtt.c" />
<ClCompile Include="..\..\..\..\Source\AWS\ota\source\portable\os\ota_os_freertos.c" />
<ClCompile Include="..\..\..\..\Source\coreJSON\source\core_json.c" />
<ClCompile Include="..\..\..\..\Source\Utilities\backoff_algorithm\source\backoff_algorithm.c" />
<ClCompile Include="..\..\..\..\ThirdParty\tinycbor\src\cborencoder.c" />
<ClCompile Include="..\..\..\..\ThirdParty\tinycbor\src\cborencoder_close_container_checked.c" />
<ClCompile Include="..\..\..\..\ThirdParty\tinycbor\src\cborerrorstrings.c" />
<ClCompile Include="..\..\..\..\ThirdParty\tinycbor\src\cborparser.c" />
<ClCompile Include="..\..\..\..\ThirdParty\tinycbor\src\cborparser_dup_string.c" />
<ClCompile Include="..\..\..\..\ThirdParty\tinycbor\src\cborpretty.c" />
<ClCompile Include="..\..\..\..\ThirdParty\tinycbor\src\cborpretty_stdio.c" />
<ClCompile Include="..\..\..\..\ThirdParty\tinycbor\src\cborvalidation.c" />
<ClCompile Include="..\..\..\Common\coreMQTT_Agent_Interface\freertos_agent_message.c" />
<ClCompile Include="..\..\..\Common\coreMQTT_Agent_Interface\freertos_command_pool.c" />
<ClCompile Include="..\Common\HTTP_Utils\http_demo_utils.c" />
<ClCompile Include="..\Common\Ota_PAL\Win32\Code_Signature_Verification\code_signature_verification_mbedtls.c" />
<ClCompile Include="..\Common\Ota_PAL\Win32\ota_pal.c" />
<ClCompile Include="..\Common\subscription-manager\subscription_manager.c" />
<ClCompile Include="DemoTasks\OtaOverHttpDemoExample.c" />
<ClCompile Include="main.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\..\Source\Application-Protocols\coreMQTT-Agent\source\include\core_mqtt_agent.h" />
<ClInclude Include="..\..\..\..\Source\Application-Protocols\coreMQTT-Agent\source\include\core_mqtt_agent_command_functions.h" />
<ClInclude Include="..\..\..\..\Source\Application-Protocols\coreMQTT-Agent\source\include\core_mqtt_agent_message_interface.h" />
<ClInclude Include="..\..\..\..\Source\Application-Protocols\coreMQTT\source\include\core_mqtt.h" />
<ClInclude Include="..\..\..\..\Source\Application-Protocols\coreMQTT\source\include\core_mqtt_config_defaults.h" />
<ClInclude Include="..\..\..\..\Source\Application-Protocols\coreMQTT\source\include\core_mqtt_serializer.h" />
<ClInclude Include="..\..\..\..\Source\Application-Protocols\coreMQTT\source\include\core_mqtt_state.h" />
<ClInclude Include="..\..\..\..\Source\Application-Protocols\coreMQTT\source\interface\transport_interface.h" />
<ClInclude Include="..\..\..\..\Source\Application-Protocols\network_transport\mbedtls_bio_tcp_sockets_wrapper.h" />
<ClInclude Include="..\..\..\..\Source\Application-Protocols\network_transport\tcp_sockets_wrapper\include\tcp_sockets_wrapper.h" />
<ClInclude Include="..\..\..\..\Source\Application-Protocols\network_transport\transport_mbedtls.h" />
<ClInclude Include="..\..\..\..\Source\AWS\ota\source\include\ota.h" />
<ClInclude Include="..\..\..\..\Source\AWS\ota\source\include\ota_appversion32.h" />
<ClInclude Include="..\..\..\..\Source\AWS\ota\source\include\ota_base64_private.h" />
<ClInclude Include="..\..\..\..\Source\AWS\ota\source\include\ota_cbor_private.h" />
<ClInclude Include="..\..\..\..\Source\AWS\ota\source\include\ota_config_defaults.h" />
<ClInclude Include="..\..\..\..\Source\AWS\ota\source\include\ota_http_interface.h" />
<ClInclude Include="..\..\..\..\Source\AWS\ota\source\include\ota_http_private.h" />
<ClInclude Include="..\..\..\..\Source\AWS\ota\source\include\ota_interface_private.h" />
<ClInclude Include="..\..\..\..\Source\AWS\ota\source\include\ota_mqtt_interface.h" />
<ClInclude Include="..\..\..\..\Source\AWS\ota\source\include\ota_mqtt_private.h" />
<ClInclude Include="..\..\..\..\Source\AWS\ota\source\include\ota_os_interface.h" />
<ClInclude Include="..\..\..\..\Source\AWS\ota\source\include\ota_platform_interface.h" />
<ClInclude Include="..\..\..\..\Source\AWS\ota\source\include\ota_private.h" />
<ClInclude Include="..\..\..\..\Source\AWS\ota\source\portable\os\ota_os_freertos.h" />
<ClInclude Include="..\..\..\..\Source\coreJSON\source\include\core_json.h" />
<ClInclude Include="..\..\..\..\Source\Utilities\backoff_algorithm\source\include\backoff_algorithm.h" />
<ClInclude Include="..\..\..\..\ThirdParty\tinycbor\src\cbor.h" />
<ClInclude Include="..\..\..\..\ThirdParty\tinycbor\src\cborinternal_p.h" />
<ClInclude Include="..\..\..\..\ThirdParty\tinycbor\src\cborjson.h" />
<ClInclude Include="..\..\..\..\ThirdParty\tinycbor\src\compilersupport_p.h" />
<ClInclude Include="..\..\..\..\ThirdParty\tinycbor\src\tinycbor-version.h" />
<ClInclude Include="..\..\..\..\ThirdParty\tinycbor\src\utf8_p.h" />
<ClInclude Include="..\..\..\Common\coreMQTT_Agent_Interface\include\freertos_agent_message.h" />
<ClInclude Include="..\..\..\Common\coreMQTT_Agent_Interface\include\freertos_command_pool.h" />
<ClInclude Include="..\Common\HTTP_Utils\http_demo_utils.h" />
<ClInclude Include="..\Common\Ota_PAL\Win32\Code_Signature_Verification\aws_ota_codesigner_certificate.h" />
<ClInclude Include="..\Common\Ota_PAL\Win32\Code_Signature_Verification\code_signature_verification.h" />
<ClInclude Include="..\Common\Ota_PAL\Win32\ota_pal.h" />
<ClInclude Include="..\Common\subscription-manager\subscription_manager.h" />
<ClInclude Include="core_mqtt_config.h" />
<ClInclude Include="demo_config.h" />
<ClInclude Include="ota_config.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{4be4e103-5bf4-4a85-9656-ec20852a2b8e}</ProjectGuid>
<RootNamespace>OtaOverHttpDemo</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<TargetName>RTOSDemo</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<TargetName>RTOSDemo</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<TargetName>RTOSDemo</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<TargetName>RTOSDemo</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>false</SDLCheck>
<PreprocessorDefinitions>MQTT_AGENT_DO_NOT_USE_CUSTOM_CONFIG;WIN32;__little_endian__=1;_DEBUG;_CONSOLE;WIN32;MBEDTLS_CONFIG_FILE="mbedtls_config_v3.2.1.h";%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>..\Common\HTTP_Utils;..\..\..\..\Source\Application-Protocols\network_transport\tcp_sockets_wrapper\include;..\..\..\..\Source\Application-Protocols\network_transport;..\..\..\Common\coreMQTT_Agent_Interface\include;..\..\..\..\ThirdParty\tinycbor\src;..\..\..\..\Source\Utilities\backoff_algorithm\source\include;..\..\..\..\Source\coreJSON\source\include;..\..\..\..\Source\AWS\ota\source\include;..\..\..\..\Source\AWS\ota\source\portable\os;..\..\..\..\Source\Application-Protocols\coreMQTT-Agent\source\include;..\..\..\..\Source\Application-Protocols\coreMQTT\source\interface;..\..\..\..\Source\Application-Protocols\coreMQTT\source\include;..\Common\Ota_PAL\Win32\Code_Signature_Verification;..\Common\Ota_PAL\Win32;..\Common\subscription-manager;.\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>false</SDLCheck>
<PreprocessorDefinitions>MQTT_AGENT_DO_NOT_USE_CUSTOM_CONFIG;WIN32;__little_endian__=1;WIN32;NDEBUG;_CONSOLE;MBEDTLS_CONFIG_FILE="mbedtls_config_v3.2.1.h";%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>..\Common\HTTP_Utils;..\..\..\..\Source\Application-Protocols\network_transport\tcp_sockets_wrapper\include;..\..\..\..\Source\Application-Protocols\network_transport;..\..\..\Common\coreMQTT_Agent_Interface\include;..\..\..\..\ThirdParty\tinycbor\src;..\..\..\..\Source\Utilities\backoff_algorithm\source\include;..\..\..\..\Source\coreJSON\source\include;..\..\..\..\Source\AWS\ota\source\include;..\..\..\..\Source\AWS\ota\source\portable\os;..\..\..\..\Source\Application-Protocols\coreMQTT-Agent\source\include;..\..\..\..\Source\Application-Protocols\coreMQTT\source\interface;..\..\..\..\Source\Application-Protocols\coreMQTT\source\include;..\Common\Ota_PAL\Win32\Code_Signature_Verification;..\Common\Ota_PAL\Win32;..\Common\subscription-manager;.\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>false</SDLCheck>
<PreprocessorDefinitions>MQTT_AGENT_DO_NOT_USE_CUSTOM_CONFIG;WIN32;__little_endian__=1;_DEBUG;_CONSOLE;MBEDTLS_CONFIG_FILE="mbedtls_config_v3.2.1.h";%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>..\Common\HTTP_Utils;..\..\..\..\Source\Application-Protocols\network_transport\tcp_sockets_wrapper\include;..\..\..\..\Source\Application-Protocols\network_transport;..\..\..\Common\coreMQTT_Agent_Interface\include;..\..\..\..\ThirdParty\tinycbor\src;..\..\..\..\Source\Utilities\backoff_algorithm\source\include;..\..\..\..\Source\coreJSON\source\include;..\..\..\..\Source\AWS\ota\source\include;..\..\..\..\Source\AWS\ota\source\portable\os;..\..\..\..\Source\Application-Protocols\coreMQTT-Agent\source\include;..\..\..\..\Source\Application-Protocols\coreMQTT\source\interface;..\..\..\..\Source\Application-Protocols\coreMQTT\source\include;..\Common\Ota_PAL\Win32\Code_Signature_Verification;..\Common\Ota_PAL\Win32;..\Common\subscription-manager;.\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>false</SDLCheck>
<PreprocessorDefinitions>MQTT_AGENT_DO_NOT_USE_CUSTOM_CONFIG;WIN32;__little_endian__=1;NDEBUG;_CONSOLE;MBEDTLS_CONFIG_FILE="mbedtls_config_v3.2.1.h";%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<AdditionalIncludeDirectories>..\Common\HTTP_Utils;..\..\..\..\Source\Application-Protocols\network_transport\tcp_sockets_wrapper\include;..\..\..\..\Source\Application-Protocols\network_transport;..\..\..\Common\coreMQTT_Agent_Interface\include;..\..\..\..\ThirdParty\tinycbor\src;..\..\..\..\Source\Utilities\backoff_algorithm\source\include;..\..\..\..\Source\coreJSON\source\include;..\..\..\..\Source\AWS\ota\source\include;..\..\..\..\Source\AWS\ota\source\portable\os;..\..\..\..\Source\Application-Protocols\coreMQTT-Agent\source\include;..\..\..\..\Source\Application-Protocols\coreMQTT\source\interface;..\..\..\..\Source\Application-Protocols\coreMQTT\source\include;..\Common\Ota_PAL\Win32\Code_Signature_Verification;..\Common\Ota_PAL\Win32;..\Common\subscription-manager;.\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\VisualStudio_StaticProjects\coreHTTP\coreHTTP.vcxproj">
<Project>{ee39fa0f-cefb-4c29-a571-05a28fdd47fd}</Project>
</ProjectReference>
<ProjectReference Include="..\..\..\..\VisualStudio_StaticProjects\FreeRTOS+TCP\FreeRTOS+TCP.vcxproj">
<Project>{c90e6cc5-818b-4c97-8876-0986d989387c}</Project>
</ProjectReference>
<ProjectReference Include="..\..\..\..\VisualStudio_StaticProjects\FreeRTOS-Kernel\FreeRTOS-Kernel.vcxproj">
<Project>{72c209c4-49a4-4942-a201-44706c9d77ec}</Project>
</ProjectReference>
<ProjectReference Include="..\..\..\..\VisualStudio_StaticProjects\Logging\Logging.vcxproj">
<Project>{be362ac0-b10b-4276-b84e-6304652ba228}</Project>
</ProjectReference>
<ProjectReference Include="..\..\..\..\VisualStudio_StaticProjects\MbedTLS\MbedTLS.vcxproj">
<Project>{e1016f3e-94e9-4864-9fd8-1d7c1fefbfd7}</Project>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\..\..\Source\Application-Protocols\coreMQTT-Agent\source\core_mqtt_agent.c" />
<ClCompile Include="..\..\..\..\Source\Application-Protocols\coreMQTT-Agent\source\core_mqtt_agent_command_functions.c" />
<ClCompile Include="..\..\..\..\Source\Application-Protocols\coreMQTT\source\core_mqtt.c" />
<ClCompile Include="..\..\..\..\Source\Application-Protocols\coreMQTT\source\core_mqtt_serializer.c" />
<ClCompile Include="..\..\..\..\Source\Application-Protocols\coreMQTT\source\core_mqtt_state.c" />
<ClCompile Include="..\..\..\..\Source\Application-Protocols\network_transport\mbedtls_bio_tcp_sockets_wrapper.c" />
<ClCompile Include="..\..\..\..\Source\Application-Protocols\network_transport\tcp_sockets_wrapper\ports\freertos_plus_tcp\tcp_sockets_wrapper.c" />
<ClCompile Include="..\..\..\..\Source\Application-Protocols\network_transport\transport_mbedtls.c" />
<ClCompile Include="..\..\..\..\Source\AWS\ota\source\ota.c" />
<ClCompile Include="..\..\..\..\Source\AWS\ota\source\ota_base64.c" />
<ClCompile Include="..\..\..\..\Source\AWS\ota\source\ota_cbor.c" />
<ClCompile Include="..\..\..\..\Source\AWS\ota\source\ota_http.c" />
<ClCompile Include="..\..\..\..\Source\AWS\ota\source\ota_interface.c" />
<ClCompile Include="..\..\..\..\Source\AWS\ota\source\ota_mqtt.c" />
<ClCompile Include="..\..\..\..\Source\AWS\ota\source\portable\os\ota_os_freertos.c" />
<ClCompile Include="..\..\..\..\Source\coreJSON\source\core_json.c" />
<ClCompile Include="..\..\..\..\Source\Utilities\backoff_algorithm\source\backoff_algorithm.c" />
<ClCompile Include="..\..\..\..\ThirdParty\tinycbor\src\cborencoder.c" />
<ClCompile Include="..\..\..\..\ThirdParty\tinycbor\src\cborencoder_close_container_checked.c" />
<ClCompile Include="..\..\..\..\ThirdParty\tinycbor\src\cborerrorstrings.c" />
<ClCompile Include="..\..\..\..\ThirdParty\tinycbor\src\cborparser.c" />
<ClCompile Include="..\..\..\..\ThirdParty\tinycbor\src\cborparser_dup_string.c" />
<ClCompile Include="..\..\..\..\ThirdParty\tinycbor\src\cborpretty.c" />
<ClCompile Include="..\..\..\..\ThirdParty\tinycbor\src\cborpretty_stdio.c" />
<ClCompile Include="..\..\..\..\ThirdParty\tinycbor\src\cborvalidation.c" />
<ClCompile Include="..\..\..\Common\coreMQTT_Agent_Interface\freertos_agent_message.c" />
<ClCompile Include="..\..\..\Common\coreMQTT_Agent_Interface\freertos_command_pool.c" />
<ClCompile Include="..\Common\HTTP_Utils\http_demo_utils.c" />
<ClCompile Include="..\Common\Ota_PAL\Win32\Code_Signature_Verification\code_signature_verification_mbedtls.c" />
<ClCompile Include="..\Common\Ota_PAL\Win32\ota_pal.c" />
<ClCompile Include="..\Common\subscription-manager\subscription_manager.c" />
<ClCompile Include="DemoTasks\OtaOverHttpDemoExample.c" />
<ClCompile Include="main.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\..\..\Source\Application-Protocols\coreMQTT-Agent\source\include\core_mqtt_agent.h" />
<ClInclude Include="..\..\..\..\Source\Application-Protocols\coreMQTT-Agent\source\include\core_mqtt_agent_command_functions.h" />
<ClInclude Include="..\..\..\..\Source\Application-Protocols\coreMQTT-Agent\source\include\core_mqtt_agent_message_interface.h" />
<ClInclude Include="..\..\..\..\Source\Application-Protocols\coreMQTT\source\include\core_mqtt.h" />
<ClInclude Include="..\..\..\..\Source\Application-Protocols\coreMQTT\source\include\core_mqtt_config_defaults.h" />
<ClInclude Include="..\..\..\..\Source\Application-Protocols\coreMQTT\source\include\core_mqtt_serializer.h" />
<ClInclude Include="..\..\..\..\Source\Application-Protocols\coreMQTT\source\include\core_mqtt_state.h" />
<ClInclude Include="..\..\..\..\Source\Application-Protocols\coreMQTT\source\interface\transport_interface.h" />
<ClInclude Include="..\..\..\..\Source\Application-Protocols\network_transport\mbedtls_bio_tcp_sockets_wrapper.h" />
<ClInclude Include="..\..\..\..\Source\Application-Protocols\network_transport\tcp_sockets_wrapper\include\tcp_sockets_wrapper.h" />
<ClInclude Include="..\..\..\..\Source\Application-Protocols\network_transport\transport_mbedtls.h" />
<ClInclude Include="..\..\..\..\Source\AWS\ota\source\include\ota.h" />
<ClInclude Include="..\..\..\..\Source\AWS\ota\source\include\ota_appversion32.h" />
<ClInclude Include="..\..\..\..\Source\AWS\ota\source\include\ota_base64_private.h" />
<ClInclude Include="..\..\..\..\Source\AWS\ota\source\include\ota_cbor_private.h" />
<ClInclude Include="..\..\..\..\Source\AWS\ota\source\include\ota_config_defaults.h" />
<ClInclude Include="..\..\..\..\Source\AWS\ota\source\include\ota_http_interface.h" />
<ClInclude Include="..\..\..\..\Source\AWS\ota\source\include\ota_http_private.h" />
<ClInclude Include="..\..\..\..\Source\AWS\ota\source\include\ota_interface_private.h" />
<ClInclude Include="..\..\..\..\Source\AWS\ota\source\include\ota_mqtt_interface.h" />
<ClInclude Include="..\..\..\..\Source\AWS\ota\source\include\ota_mqtt_private.h" />
<ClInclude Include="..\..\..\..\Source\AWS\ota\source\include\ota_os_interface.h" />
<ClInclude Include="..\..\..\..\Source\AWS\ota\source\include\ota_platform_interface.h" />
<ClInclude Include="..\..\..\..\Source\AWS\ota\source\include\ota_private.h" />
<ClInclude Include="..\..\..\..\Source\AWS\ota\source\portable\os\ota_os_freertos.h" />
<ClInclude Include="..\..\..\..\Source\coreJSON\source\include\core_json.h" />
<ClInclude Include="..\..\..\..\Source\Utilities\backoff_algorithm\source\include\backoff_algorithm.h" />
<ClInclude Include="..\..\..\..\ThirdParty\tinycbor\src\cbor.h" />
<ClInclude Include="..\..\..\..\ThirdParty\tinycbor\src\cborinternal_p.h" />
<ClInclude Include="..\..\..\..\ThirdParty\tinycbor\src\cborjson.h" />
<ClInclude Include="..\..\..\..\ThirdParty\tinycbor\src\compilersupport_p.h" />
<ClInclude Include="..\..\..\..\ThirdParty\tinycbor\src\tinycbor-version.h" />
<ClInclude Include="..\..\..\..\ThirdParty\tinycbor\src\utf8_p.h" />
<ClInclude Include="..\..\..\Common\coreMQTT_Agent_Interface\include\freertos_agent_message.h" />
<ClInclude Include="..\..\..\Common\coreMQTT_Agent_Interface\include\freertos_command_pool.h" />
<ClInclude Include="..\Common\HTTP_Utils\http_demo_utils.h" />
<ClInclude Include="..\Common\Ota_PAL\Win32\Code_Signature_Verification\aws_ota_codesigner_certificate.h" />
<ClInclude Include="..\Common\Ota_PAL\Win32\Code_Signature_Verification\code_signature_verification.h" />
<ClInclude Include="..\Common\Ota_PAL\Win32\ota_pal.h" />
<ClInclude Include="..\Common\subscription-manager\subscription_manager.h" />
<ClInclude Include="core_mqtt_config.h" />
<ClInclude Include="demo_config.h" />
<ClInclude Include="ota_config.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
@ -23,7 +23,7 @@
* https://github.com/FreeRTOS
*
*/
#ifndef CORE_MQTT_CONFIG_H
#define CORE_MQTT_CONFIG_H
@ -76,33 +76,34 @@ extern void vLoggingPrintf( const char * pcFormatString,
*/
#define MQTT_STATE_ARRAY_MAX_COUNT 10U
/*********************** coreMQTT Agent Configurations **********************/
/**
* @brief The maximum number of pending acknowledgments to track for a single
* connection.
*
* @note The MQTT agent tracks MQTT commands (such as PUBLISH and SUBSCRIBE) th
* at are still waiting to be acknowledged. MQTT_AGENT_MAX_OUTSTANDING_ACKS set
* the maximum number of acknowledgments that can be outstanding at any one time.
* The higher this number is the greater the agent's RAM consumption will be.
*/
/*********************** coreMQTT Agent Configurations **********************/
/**
* @brief The maximum number of pending acknowledgments to track for a single
* connection.
*
* @note The MQTT agent tracks MQTT commands (such as PUBLISH and SUBSCRIBE) th
* at are still waiting to be acknowledged. MQTT_AGENT_MAX_OUTSTANDING_ACKS set
* the maximum number of acknowledgments that can be outstanding at any one time.
* The higher this number is the greater the agent's RAM consumption will be.
*/
#define MQTT_AGENT_MAX_OUTSTANDING_ACKS ( 20U )
/**
* @brief Time in MS that the MQTT agent task will wait in the Blocked state (so
* not using any CPU time) for a command to arrive in its command queue before
* exiting the blocked state so it can call MQTT_ProcessLoop().
*
* @note It is important MQTT_ProcessLoop() is called often if there is known
* MQTT traffic, but calling it too often can take processing time away from
* lower priority tasks and waste CPU time and power.
*/
/**
* @brief Time in MS that the MQTT agent task will wait in the Blocked state (so
* not using any CPU time) for a command to arrive in its command queue before
* exiting the blocked state so it can call MQTT_ProcessLoop().
*
* @note It is important MQTT_ProcessLoop() is called often if there is known
* MQTT traffic, but calling it too often can take processing time away from
* lower priority tasks and waste CPU time and power.
*/
#define MQTT_AGENT_MAX_EVENT_QUEUE_WAIT_TIME ( 1000 )
/**
* @brief The number of command structures to allocate in the pool
* for the agent.
*/
/**
* @brief The number of command structures to allocate in the pool
* for the agent.
*/
#define MQTT_COMMAND_CONTEXTS_POOL_SIZE 10

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
@ -179,8 +179,8 @@ extern void vLoggingPrintf( const char * pcFormatString,
* can be set to following -
* Enable data over MQTT - ( OTA_DATA_OVER_MQTT )
* Enable data over HTTP - ( OTA_DATA_OVER_HTTP)
*
* Note - Please check the OTA over MQTT demo which has the MQTT data transfer functionality and
*
* Note - Please check the OTA over MQTT demo which has the MQTT data transfer functionality and
* and this configuration is set to OTA_DATA_OVER_MQTT.
*/
#define configENABLED_DATA_PROTOCOLS ( OTA_DATA_OVER_HTTP )

@ -1,116 +1,116 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31205.134
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Ota_Over_Http_Demo", "Ota_Over_Http_Demo.vcxproj", "{4BE4E103-5BF4-4A85-9656-EC20852A2B8E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Statically Linked Libraries", "Statically Linked Libraries", "{9799AFF4-25E2-43CD-8829-C066177E3748}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FreeRTOS+TCP", "..\..\..\..\VisualStudio_StaticProjects\FreeRTOS+TCP\FreeRTOS+TCP.vcxproj", "{C90E6CC5-818B-4C97-8876-0986D989387C}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ww", "..\..\..\..\VisualStudio_StaticProjects\FreeRTOS-Kernel\FreeRTOS-Kernel.vcxproj", "{72C209C4-49A4-4942-A201-44706C9D77EC}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Logging", "..\..\..\..\VisualStudio_StaticProjects\Logging\Logging.vcxproj", "{BE362AC0-B10B-4276-B84E-6304652BA228}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MbedTLS", "..\..\..\..\VisualStudio_StaticProjects\MbedTLS\MbedTLS.vcxproj", "{E1016F3E-94E9-4864-9FD8-1D7C1FEFBFD7}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "coreHTTP", "..\..\..\..\VisualStudio_StaticProjects\coreHTTP\coreHTTP.vcxproj", "{EE39FA0F-CEFB-4C29-A571-05A28FDD47FD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Win32 = Release|Win32
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4BE4E103-5BF4-4A85-9656-EC20852A2B8E}.Debug|Win32.ActiveCfg = Debug|Win32
{4BE4E103-5BF4-4A85-9656-EC20852A2B8E}.Debug|Win32.Build.0 = Debug|Win32
{4BE4E103-5BF4-4A85-9656-EC20852A2B8E}.Debug|x64.ActiveCfg = Debug|x64
{4BE4E103-5BF4-4A85-9656-EC20852A2B8E}.Debug|x64.Build.0 = Debug|x64
{4BE4E103-5BF4-4A85-9656-EC20852A2B8E}.Debug|x86.ActiveCfg = Debug|Win32
{4BE4E103-5BF4-4A85-9656-EC20852A2B8E}.Debug|x86.Build.0 = Debug|Win32
{4BE4E103-5BF4-4A85-9656-EC20852A2B8E}.Release|Win32.ActiveCfg = Release|Win32
{4BE4E103-5BF4-4A85-9656-EC20852A2B8E}.Release|Win32.Build.0 = Release|Win32
{4BE4E103-5BF4-4A85-9656-EC20852A2B8E}.Release|x64.ActiveCfg = Release|x64
{4BE4E103-5BF4-4A85-9656-EC20852A2B8E}.Release|x64.Build.0 = Release|x64
{4BE4E103-5BF4-4A85-9656-EC20852A2B8E}.Release|x86.ActiveCfg = Release|Win32
{4BE4E103-5BF4-4A85-9656-EC20852A2B8E}.Release|x86.Build.0 = Release|Win32
{C90E6CC5-818B-4C97-8876-0986D989387C}.Debug|Win32.ActiveCfg = Debug|Win32
{C90E6CC5-818B-4C97-8876-0986D989387C}.Debug|Win32.Build.0 = Debug|Win32
{C90E6CC5-818B-4C97-8876-0986D989387C}.Debug|x64.ActiveCfg = Debug|x64
{C90E6CC5-818B-4C97-8876-0986D989387C}.Debug|x64.Build.0 = Debug|x64
{C90E6CC5-818B-4C97-8876-0986D989387C}.Debug|x86.ActiveCfg = Debug|Win32
{C90E6CC5-818B-4C97-8876-0986D989387C}.Debug|x86.Build.0 = Debug|Win32
{C90E6CC5-818B-4C97-8876-0986D989387C}.Release|Win32.ActiveCfg = Release|Win32
{C90E6CC5-818B-4C97-8876-0986D989387C}.Release|Win32.Build.0 = Release|Win32
{C90E6CC5-818B-4C97-8876-0986D989387C}.Release|x64.ActiveCfg = Release|x64
{C90E6CC5-818B-4C97-8876-0986D989387C}.Release|x64.Build.0 = Release|x64
{C90E6CC5-818B-4C97-8876-0986D989387C}.Release|x86.ActiveCfg = Release|Win32
{C90E6CC5-818B-4C97-8876-0986D989387C}.Release|x86.Build.0 = Release|Win32
{72C209C4-49A4-4942-A201-44706C9D77EC}.Debug|Win32.ActiveCfg = Debug|Win32
{72C209C4-49A4-4942-A201-44706C9D77EC}.Debug|Win32.Build.0 = Debug|Win32
{72C209C4-49A4-4942-A201-44706C9D77EC}.Debug|x64.ActiveCfg = Debug|x64
{72C209C4-49A4-4942-A201-44706C9D77EC}.Debug|x64.Build.0 = Debug|x64
{72C209C4-49A4-4942-A201-44706C9D77EC}.Debug|x86.ActiveCfg = Debug|Win32
{72C209C4-49A4-4942-A201-44706C9D77EC}.Debug|x86.Build.0 = Debug|Win32
{72C209C4-49A4-4942-A201-44706C9D77EC}.Release|Win32.ActiveCfg = Release|Win32
{72C209C4-49A4-4942-A201-44706C9D77EC}.Release|Win32.Build.0 = Release|Win32
{72C209C4-49A4-4942-A201-44706C9D77EC}.Release|x64.ActiveCfg = Release|x64
{72C209C4-49A4-4942-A201-44706C9D77EC}.Release|x64.Build.0 = Release|x64
{72C209C4-49A4-4942-A201-44706C9D77EC}.Release|x86.ActiveCfg = Release|Win32
{72C209C4-49A4-4942-A201-44706C9D77EC}.Release|x86.Build.0 = Release|Win32
{BE362AC0-B10B-4276-B84E-6304652BA228}.Debug|Win32.ActiveCfg = Debug|Win32
{BE362AC0-B10B-4276-B84E-6304652BA228}.Debug|Win32.Build.0 = Debug|Win32
{BE362AC0-B10B-4276-B84E-6304652BA228}.Debug|x64.ActiveCfg = Debug|x64
{BE362AC0-B10B-4276-B84E-6304652BA228}.Debug|x64.Build.0 = Debug|x64
{BE362AC0-B10B-4276-B84E-6304652BA228}.Debug|x86.ActiveCfg = Debug|Win32
{BE362AC0-B10B-4276-B84E-6304652BA228}.Debug|x86.Build.0 = Debug|Win32
{BE362AC0-B10B-4276-B84E-6304652BA228}.Release|Win32.ActiveCfg = Release|Win32
{BE362AC0-B10B-4276-B84E-6304652BA228}.Release|Win32.Build.0 = Release|Win32
{BE362AC0-B10B-4276-B84E-6304652BA228}.Release|x64.ActiveCfg = Release|x64
{BE362AC0-B10B-4276-B84E-6304652BA228}.Release|x64.Build.0 = Release|x64
{BE362AC0-B10B-4276-B84E-6304652BA228}.Release|x86.ActiveCfg = Release|Win32
{BE362AC0-B10B-4276-B84E-6304652BA228}.Release|x86.Build.0 = Release|Win32
{E1016F3E-94E9-4864-9FD8-1D7C1FEFBFD7}.Debug|Win32.ActiveCfg = Debug|Win32
{E1016F3E-94E9-4864-9FD8-1D7C1FEFBFD7}.Debug|Win32.Build.0 = Debug|Win32
{E1016F3E-94E9-4864-9FD8-1D7C1FEFBFD7}.Debug|x64.ActiveCfg = Debug|x64
{E1016F3E-94E9-4864-9FD8-1D7C1FEFBFD7}.Debug|x64.Build.0 = Debug|x64
{E1016F3E-94E9-4864-9FD8-1D7C1FEFBFD7}.Debug|x86.ActiveCfg = Debug|Win32
{E1016F3E-94E9-4864-9FD8-1D7C1FEFBFD7}.Debug|x86.Build.0 = Debug|Win32
{E1016F3E-94E9-4864-9FD8-1D7C1FEFBFD7}.Release|Win32.ActiveCfg = Release|Win32
{E1016F3E-94E9-4864-9FD8-1D7C1FEFBFD7}.Release|Win32.Build.0 = Release|Win32
{E1016F3E-94E9-4864-9FD8-1D7C1FEFBFD7}.Release|x64.ActiveCfg = Release|x64
{E1016F3E-94E9-4864-9FD8-1D7C1FEFBFD7}.Release|x64.Build.0 = Release|x64
{E1016F3E-94E9-4864-9FD8-1D7C1FEFBFD7}.Release|x86.ActiveCfg = Release|Win32
{E1016F3E-94E9-4864-9FD8-1D7C1FEFBFD7}.Release|x86.Build.0 = Release|Win32
{EE39FA0F-CEFB-4C29-A571-05A28FDD47FD}.Debug|Win32.ActiveCfg = Debug|Win32
{EE39FA0F-CEFB-4C29-A571-05A28FDD47FD}.Debug|Win32.Build.0 = Debug|Win32
{EE39FA0F-CEFB-4C29-A571-05A28FDD47FD}.Debug|x64.ActiveCfg = Debug|x64
{EE39FA0F-CEFB-4C29-A571-05A28FDD47FD}.Debug|x64.Build.0 = Debug|x64
{EE39FA0F-CEFB-4C29-A571-05A28FDD47FD}.Debug|x86.ActiveCfg = Debug|Win32
{EE39FA0F-CEFB-4C29-A571-05A28FDD47FD}.Debug|x86.Build.0 = Debug|Win32
{EE39FA0F-CEFB-4C29-A571-05A28FDD47FD}.Release|Win32.ActiveCfg = Release|Win32
{EE39FA0F-CEFB-4C29-A571-05A28FDD47FD}.Release|Win32.Build.0 = Release|Win32
{EE39FA0F-CEFB-4C29-A571-05A28FDD47FD}.Release|x64.ActiveCfg = Release|x64
{EE39FA0F-CEFB-4C29-A571-05A28FDD47FD}.Release|x64.Build.0 = Release|x64
{EE39FA0F-CEFB-4C29-A571-05A28FDD47FD}.Release|x86.ActiveCfg = Release|Win32
{EE39FA0F-CEFB-4C29-A571-05A28FDD47FD}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{C90E6CC5-818B-4C97-8876-0986D989387C} = {9799AFF4-25E2-43CD-8829-C066177E3748}
{72C209C4-49A4-4942-A201-44706C9D77EC} = {9799AFF4-25E2-43CD-8829-C066177E3748}
{BE362AC0-B10B-4276-B84E-6304652BA228} = {9799AFF4-25E2-43CD-8829-C066177E3748}
{E1016F3E-94E9-4864-9FD8-1D7C1FEFBFD7} = {9799AFF4-25E2-43CD-8829-C066177E3748}
{EE39FA0F-CEFB-4C29-A571-05A28FDD47FD} = {9799AFF4-25E2-43CD-8829-C066177E3748}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {03800DFF-BAFA-4654-8E51-C4E654A54416}
EndGlobalSection
EndGlobal
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31205.134
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Ota_Over_Http_Demo", "Ota_Over_Http_Demo.vcxproj", "{4BE4E103-5BF4-4A85-9656-EC20852A2B8E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Statically Linked Libraries", "Statically Linked Libraries", "{9799AFF4-25E2-43CD-8829-C066177E3748}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FreeRTOS+TCP", "..\..\..\..\VisualStudio_StaticProjects\FreeRTOS+TCP\FreeRTOS+TCP.vcxproj", "{C90E6CC5-818B-4C97-8876-0986D989387C}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ww", "..\..\..\..\VisualStudio_StaticProjects\FreeRTOS-Kernel\FreeRTOS-Kernel.vcxproj", "{72C209C4-49A4-4942-A201-44706C9D77EC}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Logging", "..\..\..\..\VisualStudio_StaticProjects\Logging\Logging.vcxproj", "{BE362AC0-B10B-4276-B84E-6304652BA228}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MbedTLS", "..\..\..\..\VisualStudio_StaticProjects\MbedTLS\MbedTLS.vcxproj", "{E1016F3E-94E9-4864-9FD8-1D7C1FEFBFD7}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "coreHTTP", "..\..\..\..\VisualStudio_StaticProjects\coreHTTP\coreHTTP.vcxproj", "{EE39FA0F-CEFB-4C29-A571-05A28FDD47FD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Win32 = Release|Win32
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4BE4E103-5BF4-4A85-9656-EC20852A2B8E}.Debug|Win32.ActiveCfg = Debug|Win32
{4BE4E103-5BF4-4A85-9656-EC20852A2B8E}.Debug|Win32.Build.0 = Debug|Win32
{4BE4E103-5BF4-4A85-9656-EC20852A2B8E}.Debug|x64.ActiveCfg = Debug|x64
{4BE4E103-5BF4-4A85-9656-EC20852A2B8E}.Debug|x64.Build.0 = Debug|x64
{4BE4E103-5BF4-4A85-9656-EC20852A2B8E}.Debug|x86.ActiveCfg = Debug|Win32
{4BE4E103-5BF4-4A85-9656-EC20852A2B8E}.Debug|x86.Build.0 = Debug|Win32
{4BE4E103-5BF4-4A85-9656-EC20852A2B8E}.Release|Win32.ActiveCfg = Release|Win32
{4BE4E103-5BF4-4A85-9656-EC20852A2B8E}.Release|Win32.Build.0 = Release|Win32
{4BE4E103-5BF4-4A85-9656-EC20852A2B8E}.Release|x64.ActiveCfg = Release|x64
{4BE4E103-5BF4-4A85-9656-EC20852A2B8E}.Release|x64.Build.0 = Release|x64
{4BE4E103-5BF4-4A85-9656-EC20852A2B8E}.Release|x86.ActiveCfg = Release|Win32
{4BE4E103-5BF4-4A85-9656-EC20852A2B8E}.Release|x86.Build.0 = Release|Win32
{C90E6CC5-818B-4C97-8876-0986D989387C}.Debug|Win32.ActiveCfg = Debug|Win32
{C90E6CC5-818B-4C97-8876-0986D989387C}.Debug|Win32.Build.0 = Debug|Win32
{C90E6CC5-818B-4C97-8876-0986D989387C}.Debug|x64.ActiveCfg = Debug|x64
{C90E6CC5-818B-4C97-8876-0986D989387C}.Debug|x64.Build.0 = Debug|x64
{C90E6CC5-818B-4C97-8876-0986D989387C}.Debug|x86.ActiveCfg = Debug|Win32
{C90E6CC5-818B-4C97-8876-0986D989387C}.Debug|x86.Build.0 = Debug|Win32
{C90E6CC5-818B-4C97-8876-0986D989387C}.Release|Win32.ActiveCfg = Release|Win32
{C90E6CC5-818B-4C97-8876-0986D989387C}.Release|Win32.Build.0 = Release|Win32
{C90E6CC5-818B-4C97-8876-0986D989387C}.Release|x64.ActiveCfg = Release|x64
{C90E6CC5-818B-4C97-8876-0986D989387C}.Release|x64.Build.0 = Release|x64
{C90E6CC5-818B-4C97-8876-0986D989387C}.Release|x86.ActiveCfg = Release|Win32
{C90E6CC5-818B-4C97-8876-0986D989387C}.Release|x86.Build.0 = Release|Win32
{72C209C4-49A4-4942-A201-44706C9D77EC}.Debug|Win32.ActiveCfg = Debug|Win32
{72C209C4-49A4-4942-A201-44706C9D77EC}.Debug|Win32.Build.0 = Debug|Win32
{72C209C4-49A4-4942-A201-44706C9D77EC}.Debug|x64.ActiveCfg = Debug|x64
{72C209C4-49A4-4942-A201-44706C9D77EC}.Debug|x64.Build.0 = Debug|x64
{72C209C4-49A4-4942-A201-44706C9D77EC}.Debug|x86.ActiveCfg = Debug|Win32
{72C209C4-49A4-4942-A201-44706C9D77EC}.Debug|x86.Build.0 = Debug|Win32
{72C209C4-49A4-4942-A201-44706C9D77EC}.Release|Win32.ActiveCfg = Release|Win32
{72C209C4-49A4-4942-A201-44706C9D77EC}.Release|Win32.Build.0 = Release|Win32
{72C209C4-49A4-4942-A201-44706C9D77EC}.Release|x64.ActiveCfg = Release|x64
{72C209C4-49A4-4942-A201-44706C9D77EC}.Release|x64.Build.0 = Release|x64
{72C209C4-49A4-4942-A201-44706C9D77EC}.Release|x86.ActiveCfg = Release|Win32
{72C209C4-49A4-4942-A201-44706C9D77EC}.Release|x86.Build.0 = Release|Win32
{BE362AC0-B10B-4276-B84E-6304652BA228}.Debug|Win32.ActiveCfg = Debug|Win32
{BE362AC0-B10B-4276-B84E-6304652BA228}.Debug|Win32.Build.0 = Debug|Win32
{BE362AC0-B10B-4276-B84E-6304652BA228}.Debug|x64.ActiveCfg = Debug|x64
{BE362AC0-B10B-4276-B84E-6304652BA228}.Debug|x64.Build.0 = Debug|x64
{BE362AC0-B10B-4276-B84E-6304652BA228}.Debug|x86.ActiveCfg = Debug|Win32
{BE362AC0-B10B-4276-B84E-6304652BA228}.Debug|x86.Build.0 = Debug|Win32
{BE362AC0-B10B-4276-B84E-6304652BA228}.Release|Win32.ActiveCfg = Release|Win32
{BE362AC0-B10B-4276-B84E-6304652BA228}.Release|Win32.Build.0 = Release|Win32
{BE362AC0-B10B-4276-B84E-6304652BA228}.Release|x64.ActiveCfg = Release|x64
{BE362AC0-B10B-4276-B84E-6304652BA228}.Release|x64.Build.0 = Release|x64
{BE362AC0-B10B-4276-B84E-6304652BA228}.Release|x86.ActiveCfg = Release|Win32
{BE362AC0-B10B-4276-B84E-6304652BA228}.Release|x86.Build.0 = Release|Win32
{E1016F3E-94E9-4864-9FD8-1D7C1FEFBFD7}.Debug|Win32.ActiveCfg = Debug|Win32
{E1016F3E-94E9-4864-9FD8-1D7C1FEFBFD7}.Debug|Win32.Build.0 = Debug|Win32
{E1016F3E-94E9-4864-9FD8-1D7C1FEFBFD7}.Debug|x64.ActiveCfg = Debug|x64
{E1016F3E-94E9-4864-9FD8-1D7C1FEFBFD7}.Debug|x64.Build.0 = Debug|x64
{E1016F3E-94E9-4864-9FD8-1D7C1FEFBFD7}.Debug|x86.ActiveCfg = Debug|Win32
{E1016F3E-94E9-4864-9FD8-1D7C1FEFBFD7}.Debug|x86.Build.0 = Debug|Win32
{E1016F3E-94E9-4864-9FD8-1D7C1FEFBFD7}.Release|Win32.ActiveCfg = Release|Win32
{E1016F3E-94E9-4864-9FD8-1D7C1FEFBFD7}.Release|Win32.Build.0 = Release|Win32
{E1016F3E-94E9-4864-9FD8-1D7C1FEFBFD7}.Release|x64.ActiveCfg = Release|x64
{E1016F3E-94E9-4864-9FD8-1D7C1FEFBFD7}.Release|x64.Build.0 = Release|x64
{E1016F3E-94E9-4864-9FD8-1D7C1FEFBFD7}.Release|x86.ActiveCfg = Release|Win32
{E1016F3E-94E9-4864-9FD8-1D7C1FEFBFD7}.Release|x86.Build.0 = Release|Win32
{EE39FA0F-CEFB-4C29-A571-05A28FDD47FD}.Debug|Win32.ActiveCfg = Debug|Win32
{EE39FA0F-CEFB-4C29-A571-05A28FDD47FD}.Debug|Win32.Build.0 = Debug|Win32
{EE39FA0F-CEFB-4C29-A571-05A28FDD47FD}.Debug|x64.ActiveCfg = Debug|x64
{EE39FA0F-CEFB-4C29-A571-05A28FDD47FD}.Debug|x64.Build.0 = Debug|x64
{EE39FA0F-CEFB-4C29-A571-05A28FDD47FD}.Debug|x86.ActiveCfg = Debug|Win32
{EE39FA0F-CEFB-4C29-A571-05A28FDD47FD}.Debug|x86.Build.0 = Debug|Win32
{EE39FA0F-CEFB-4C29-A571-05A28FDD47FD}.Release|Win32.ActiveCfg = Release|Win32
{EE39FA0F-CEFB-4C29-A571-05A28FDD47FD}.Release|Win32.Build.0 = Release|Win32
{EE39FA0F-CEFB-4C29-A571-05A28FDD47FD}.Release|x64.ActiveCfg = Release|x64
{EE39FA0F-CEFB-4C29-A571-05A28FDD47FD}.Release|x64.Build.0 = Release|x64
{EE39FA0F-CEFB-4C29-A571-05A28FDD47FD}.Release|x86.ActiveCfg = Release|Win32
{EE39FA0F-CEFB-4C29-A571-05A28FDD47FD}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{C90E6CC5-818B-4C97-8876-0986D989387C} = {9799AFF4-25E2-43CD-8829-C066177E3748}
{72C209C4-49A4-4942-A201-44706C9D77EC} = {9799AFF4-25E2-43CD-8829-C066177E3748}
{BE362AC0-B10B-4276-B84E-6304652BA228} = {9799AFF4-25E2-43CD-8829-C066177E3748}
{E1016F3E-94E9-4864-9FD8-1D7C1FEFBFD7} = {9799AFF4-25E2-43CD-8829-C066177E3748}
{EE39FA0F-CEFB-4C29-A571-05A28FDD47FD} = {9799AFF4-25E2-43CD-8829-C066177E3748}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {03800DFF-BAFA-4654-8E51-C4E654A54416}
EndGlobalSection
EndGlobal

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
@ -304,13 +304,13 @@
#ifndef democonfigCLIENT_IDENTIFIER
/**
* @brief The MQTT client identifier used in this example. Each client identifier
* must be unique so edit as required to ensure no two clients connecting to the
* same broker use the same client identifier. Using a #define is for convenience
* of demonstration only - production devices should use something unique to the
* device that can be read from software - such as a production serial number.
*/
/**
* @brief The MQTT client identifier used in this example. Each client identifier
* must be unique so edit as required to ensure no two clients connecting to the
* same broker use the same client identifier. Using a #define is for convenience
* of demonstration only - production devices should use something unique to the
* device that can be read from software - such as a production serial number.
*/
#error "Please define democonfigCLIENT_IDENTIFIER in demo_config.h to something unique for this device."
#endif
@ -320,14 +320,14 @@
#error "Please define Root CA certificate of the MQTT broker(democonfigROOT_CA_PEM) in demo_config.h."
#endif
/* If no username is defined, then a client certificate/key is required. */
/* If no username is defined, then a client certificate/key is required. */
#ifndef democonfigCLIENT_USERNAME
/*
*!!! Please note democonfigCLIENT_PRIVATE_KEY_PEM in used for
*!!! convenience of demonstration only. Production devices should
*!!! store keys securely, such as within a secure element.
*/
/*
*!!! Please note democonfigCLIENT_PRIVATE_KEY_PEM in used for
*!!! convenience of demonstration only. Production devices should
*!!! store keys securely, such as within a secure element.
*/
#ifndef democonfigCLIENT_CERTIFICATE_PEM
#error "Please define client certificate(democonfigCLIENT_CERTIFICATE_PEM) in demo_config.h."
@ -337,14 +337,14 @@
#endif
#else
/* If a username is defined, a client password also would need to be defined for
* client authentication. */
/* If a username is defined, a client password also would need to be defined for
* client authentication. */
#ifndef democonfigCLIENT_PASSWORD
#error "Please define client password(democonfigCLIENT_PASSWORD) in demo_config.h for client authentication based on username/password."
#endif
/* AWS IoT MQTT broker port needs to be 443 for client authentication based on
* username/password. */
/* AWS IoT MQTT broker port needs to be 443 for client authentication based on
* username/password. */
#if defined( democonfigUSE_AWS_IOT_CORE_BROKER ) && democonfigMQTT_BROKER_PORT != 443
#error "Broker port(democonfigMQTT_BROKER_PORT) should be defined as 443 in demo_config.h for client authentication based on username/password in AWS IoT Core."
#endif
@ -529,7 +529,7 @@ static void prvMQTTAgentTask( void * pParam );
*
* The implementation uses MQTT agent to queue a publish request. It then waits
* for the request complete notification from the agent. The notification along with result of the
* operation is sent back to the caller task using xTaksNotify API. For publishes involving QOS 1 and
* operation is sent back to the caller task using xTaskNotify API. For publishes involving QOS 1 and
* QOS2 the operation is complete once an acknowledgment (PUBACK) is received. OTA agent uses this function
* to fetch new job, provide status update and send other control related messages to the MQTT broker.
*
@ -593,7 +593,7 @@ static OtaMqttStatus_t prvMQTTUnsubscribe( const char * pTopicFilter,
* within ota_config.h. This function is used to fetch a free buffer from the pool for processing
* by the OTA agent task. It uses a mutex for thread safe access to the pool.
*
* @return A pointer to an unusued buffer. NULL if there are no buffers available.
* @return A pointer to an unused buffer. NULL if there are no buffers available.
*/
static OtaEventData_t * prvOTAEventBufferGet( void );
@ -667,7 +667,7 @@ static void prvMqttDataCallback( void * pContext,
*
* The callback is not subscribed with MQTT broker, but only with local subscription manager.
* A wildcard OTA job topic is used for subscription so that all unsolicited messages related to OTA is
* forwarded to this callback for filteration. Right now the callback is used to filter responses to job requests
* forwarded to this callback for filtration. Right now the callback is used to filter responses to job requests
* from the OTA service.
*
* @param[in] pvIncomingPublishCallbackContext MQTT context which stores the connection.
@ -1043,12 +1043,12 @@ static void prvCommandCallback( MQTTAgentCommandContext_t * pxCommandContext,
static void prvMQTTSubscribeCompleteCallback( MQTTAgentCommandContext_t * pxCommandContext,
MQTTAgentReturnInfo_t * pxReturnInfo )
{
MQTTAgentSubscribeArgs_t * pSubsribeArgs;
MQTTAgentSubscribeArgs_t * pSubscribeArgs;
if( pxReturnInfo->returnCode == MQTTSuccess )
{
pSubsribeArgs = ( MQTTAgentSubscribeArgs_t * ) ( pxCommandContext->pArgs );
prvRegisterOTACallback( pSubsribeArgs->pSubscribeInfo->pTopicFilter, pSubsribeArgs->pSubscribeInfo->topicFilterLength );
pSubscribeArgs = ( MQTTAgentSubscribeArgs_t * ) ( pxCommandContext->pArgs );
prvRegisterOTACallback( pSubscribeArgs->pSubscribeInfo->pTopicFilter, pSubscribeArgs->pSubscribeInfo->topicFilterLength );
}
/* Store the result in the application defined context so the task that
@ -1288,42 +1288,43 @@ static BaseType_t prvSocketConnect( NetworkContext_t * pxNetworkContext )
NetworkCredentials_t xNetworkCredentials = { 0 };
#if defined( democonfigUSE_AWS_IOT_CORE_BROKER )
#if defined( democonfigCLIENT_USERNAME )
/*
* When democonfigCLIENT_USERNAME is defined, use the "mqtt" alpn to connect
* to AWS IoT Core with Custom Authentication on port 443.
*
* Custom Authentication uses the contents of the username and password
* fields of the MQTT CONNECT packet to authenticate the client.
*
* For more information, refer to the documentation at:
* https://docs.aws.amazon.com/iot/latest/developerguide/custom-authentication.html
*/
static const char * ppcAlpnProtocols[] = { "mqtt", NULL };
#if democonfigMQTT_BROKER_PORT != 443U
#error "Connections to AWS IoT Core with custom authentication must connect to TCP port 443 with the \"mqtt\" alpn."
#endif /* democonfigMQTT_BROKER_PORT != 443U */
#else /* if !defined( democonfigCLIENT_USERNAME ) */
/*
* Otherwise, use the "x-amzn-mqtt-ca" alpn to connect to AWS IoT Core using
* x509 Certificate Authentication.
*/
static const char * ppcAlpnProtocols[] = { "x-amzn-mqtt-ca", NULL };
#endif /* !defined( democonfigCLIENT_USERNAME ) */
#if defined( democonfigCLIENT_USERNAME )
/*
* An ALPN identifier is only required when connecting to AWS IoT core on port 443.
* https://docs.aws.amazon.com/iot/latest/developerguide/protocols.html
*/
#if democonfigMQTT_BROKER_PORT == 443U
xNetworkCredentials.pAlpnProtos = ppcAlpnProtocols;
#elif democonfigMQTT_BROKER_PORT == 8883U
xNetworkCredentials.pAlpnProtos = NULL;
#else /* democonfigMQTT_BROKER_PORT != 8883U */
xNetworkCredentials.pAlpnProtos = NULL;
#error "MQTT connections to AWS IoT Core are only allowed on ports 443 and 8883."
* When democonfigCLIENT_USERNAME is defined, use the "mqtt" alpn to connect
* to AWS IoT Core with Custom Authentication on port 443.
*
* Custom Authentication uses the contents of the username and password
* fields of the MQTT CONNECT packet to authenticate the client.
*
* For more information, refer to the documentation at:
* https://docs.aws.amazon.com/iot/latest/developerguide/custom-authentication.html
*/
static const char * ppcAlpnProtocols[] = { "mqtt", NULL };
#if democonfigMQTT_BROKER_PORT != 443U
#error "Connections to AWS IoT Core with custom authentication must connect to TCP port 443 with the \"mqtt\" alpn."
#endif /* democonfigMQTT_BROKER_PORT != 443U */
#else /* if !defined( democonfigCLIENT_USERNAME ) */
/*
* Otherwise, use the "x-amzn-mqtt-ca" alpn to connect to AWS IoT Core using
* x509 Certificate Authentication.
*/
static const char * ppcAlpnProtocols[] = { "x-amzn-mqtt-ca", NULL };
#endif /* !defined( democonfigCLIENT_USERNAME ) */
/*
* An ALPN identifier is only required when connecting to AWS IoT core on port 443.
* https://docs.aws.amazon.com/iot/latest/developerguide/protocols.html
*/
#if democonfigMQTT_BROKER_PORT == 443U
xNetworkCredentials.pAlpnProtos = ppcAlpnProtocols;
#elif democonfigMQTT_BROKER_PORT == 8883U
xNetworkCredentials.pAlpnProtos = NULL;
#else /* democonfigMQTT_BROKER_PORT != 8883U */
xNetworkCredentials.pAlpnProtos = NULL;
#error "MQTT connections to AWS IoT Core are only allowed on ports 443 and 8883."
#endif /* democonfigMQTT_BROKER_PORT != 443U */
#else /* !defined( democonfigUSE_AWS_IOT_CORE_BROKER ) */
xNetworkCredentials.pAlpnProtos = NULL;
#endif /* !defined( democonfigUSE_AWS_IOT_CORE_BROKER ) */
@ -2037,7 +2038,7 @@ static BaseType_t prvRunOTADemo( void )
}
/**
* Remvove callback for receiving messages intended for OTA agent from broker,
* Remove callback for receiving messages intended for OTA agent from broker,
* for which the topic has not been subscribed for.
*/
removeSubscription( ( SubscriptionElement_t * ) xGlobalMqttAgentContext.pIncomingCallbackContext,
@ -2086,6 +2087,7 @@ void vOtaDemoTask( void * pvParam )
if( xPlatformIsNetworkUp() == pdFALSE )
{
LogInfo( ( "Waiting for the network link up event..." ) );
while( xPlatformIsNetworkUp() == pdFALSE )
{
vTaskDelay( pdMS_TO_TICKS( 1000U ) );

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
@ -23,7 +23,7 @@
* https://github.com/FreeRTOS
*
*/
#ifndef CORE_MQTT_CONFIG_H
#define CORE_MQTT_CONFIG_H
@ -76,33 +76,34 @@ extern void vLoggingPrintf( const char * pcFormatString,
*/
#define MQTT_STATE_ARRAY_MAX_COUNT 10U
/*********************** coreMQTT Agent Configurations **********************/
/**
* @brief The maximum number of pending acknowledgments to track for a single
* connection.
*
* @note The MQTT agent tracks MQTT commands (such as PUBLISH and SUBSCRIBE) th
* at are still waiting to be acknowledged. MQTT_AGENT_MAX_OUTSTANDING_ACKS set
* the maximum number of acknowledgments that can be outstanding at any one time.
* The higher this number is the greater the agent's RAM consumption will be.
*/
/*********************** coreMQTT Agent Configurations **********************/
/**
* @brief The maximum number of pending acknowledgments to track for a single
* connection.
*
* @note The MQTT agent tracks MQTT commands (such as PUBLISH and SUBSCRIBE) th
* at are still waiting to be acknowledged. MQTT_AGENT_MAX_OUTSTANDING_ACKS set
* the maximum number of acknowledgments that can be outstanding at any one time.
* The higher this number is the greater the agent's RAM consumption will be.
*/
#define MQTT_AGENT_MAX_OUTSTANDING_ACKS ( 20U )
/**
* @brief Time in MS that the MQTT agent task will wait in the Blocked state (so
* not using any CPU time) for a command to arrive in its command queue before
* exiting the blocked state so it can call MQTT_ProcessLoop().
*
* @note It is important MQTT_ProcessLoop() is called often if there is known
* MQTT traffic, but calling it too often can take processing time away from
* lower priority tasks and waste CPU time and power.
*/
/**
* @brief Time in MS that the MQTT agent task will wait in the Blocked state (so
* not using any CPU time) for a command to arrive in its command queue before
* exiting the blocked state so it can call MQTT_ProcessLoop().
*
* @note It is important MQTT_ProcessLoop() is called often if there is known
* MQTT traffic, but calling it too often can take processing time away from
* lower priority tasks and waste CPU time and power.
*/
#define MQTT_AGENT_MAX_EVENT_QUEUE_WAIT_TIME ( 1000 )
/**
* @brief The number of command structures to allocate in the pool
* for the agent.
*/
/**
* @brief The number of command structures to allocate in the pool
* for the agent.
*/
#define MQTT_COMMAND_CONTEXTS_POOL_SIZE 10

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in

@ -1,6 +1,6 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
@ -179,8 +179,8 @@ extern void vLoggingPrintf( const char * pcFormatString,
* can be set to following -
* Enable data over MQTT - ( OTA_DATA_OVER_MQTT )
* Enable data over HTTP - ( OTA_DATA_OVER_HTTP)
*
* Note - Please check the OTA over HTTP demo which has the HTTP data transfer functionality and
*
* Note - Please check the OTA over HTTP demo which has the HTTP data transfer functionality and
* and this configuration is set to OTA_DATA_OVER_HTTP.
*/
#define configENABLED_DATA_PROTOCOLS ( OTA_DATA_OVER_MQTT )

@ -1,4 +1,4 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31205.134

@ -1,5 +1,5 @@
[{000214A0-0000-0000-C000-000000000046}]
Prop3=19,2
[InternetShortcut]
URL=http://www.freertos.org/labs
IDList=
[{000214A0-0000-0000-C000-000000000046}]
Prop3=19,2
[InternetShortcut]
URL=http://www.freertos.org/labs
IDList=

@ -1,372 +1,385 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
/* Standard includes. */
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "task.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_Sockets.h"
#include "FreeRTOS_TCP_server.h"
#include "FreeRTOS_server_private.h"
/* Remove the entire file if TCP is not being used. */
#if( ipconfigUSE_TCP == 1 ) && ( ( ipconfigUSE_HTTP == 1 ) || ( ipconfigUSE_FTP == 1 ) )
#if !defined( ARRAY_SIZE )
#define ARRAY_SIZE(x) ( BaseType_t ) (sizeof( x ) / sizeof( x )[ 0 ] )
#endif
static void prvReceiveNewClient( TCPServer_t *pxServer, BaseType_t xIndex, Socket_t xNexSocket );
static char *strnew( const char *pcString );
/* Remove slashes at the end of a path. */
static void prvRemoveSlash( char *pcDir );
TCPServer_t *FreeRTOS_CreateTCPServer( const struct xSERVER_CONFIG *pxConfigs, BaseType_t xCount )
{
TCPServer_t *pxServer;
SocketSet_t xSocketSet;
/* Create a new server.
xPort / xPortAlt : Make the service available on 1 or 2 public port numbers. */
xSocketSet = FreeRTOS_CreateSocketSet();
if( xSocketSet != NULL )
{
BaseType_t xSize;
xSize = sizeof( *pxServer ) - sizeof( pxServer->xServers ) + xCount * sizeof( pxServer->xServers[ 0 ] );
pxServer = ( TCPServer_t * ) pvPortMallocLarge( xSize );
if( pxServer != NULL )
{
struct freertos_sockaddr xAddress;
BaseType_t xNoTimeout = 0;
BaseType_t xIndex;
memset( pxServer, '\0', xSize );
pxServer->xServerCount = xCount;
pxServer->xSocketSet = xSocketSet;
for( xIndex = 0; xIndex < xCount; xIndex++ )
{
BaseType_t xPortNumber = pxConfigs[ xIndex ].xPortNumber;
if( xPortNumber > 0 )
{
Socket_t xSocket;
xSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP );
FreeRTOS_printf( ( "TCP socket on port %d\n", ( int )xPortNumber ) );
if( xSocket != FREERTOS_INVALID_SOCKET )
{
#if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 )
{
xAddress.sin_address.ulIP_IPv4 = FreeRTOS_GetIPAddress(); /* Single NIC, currently not used */
}
#else
{
xAddress.sin_addr = FreeRTOS_GetIPAddress(); /* Single NIC, currently not used */
}
#endif /* defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 ) */
xAddress.sin_port = FreeRTOS_htons( xPortNumber );
xAddress.sin_family = FREERTOS_AF_INET;
FreeRTOS_bind( xSocket, &xAddress, sizeof( xAddress ) );
FreeRTOS_listen( xSocket, pxConfigs[ xIndex ].xBackLog );
FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_RCVTIMEO, ( void * ) &xNoTimeout, sizeof( BaseType_t ) );
FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_SNDTIMEO, ( void * ) &xNoTimeout, sizeof( BaseType_t ) );
#if( ipconfigHTTP_RX_BUFSIZE > 0 )
{
if( pxConfigs[ xIndex ].eType == eSERVER_HTTP )
{
WinProperties_t xWinProps;
memset( &xWinProps, '\0', sizeof( xWinProps ) );
/* The parent socket itself won't get connected. The properties below
will be inherited by each new child socket. */
xWinProps.lTxBufSize = ipconfigHTTP_TX_BUFSIZE;
xWinProps.lTxWinSize = ipconfigHTTP_TX_WINSIZE;
xWinProps.lRxBufSize = ipconfigHTTP_RX_BUFSIZE;
xWinProps.lRxWinSize = ipconfigHTTP_RX_WINSIZE;
/* Set the window and buffer sizes. */
FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_WIN_PROPERTIES, ( void * ) &xWinProps, sizeof( xWinProps ) );
}
}
#endif
FreeRTOS_FD_SET( xSocket, xSocketSet, eSELECT_READ|eSELECT_EXCEPT );
pxServer->xServers[ xIndex ].xSocket = xSocket;
pxServer->xServers[ xIndex ].eType = pxConfigs[ xIndex ].eType;
pxServer->xServers[ xIndex ].pcRootDir = strnew( pxConfigs[ xIndex ].pcRootDir );
prvRemoveSlash( ( char * ) pxServer->xServers[ xIndex ].pcRootDir );
}
}
}
}
else
{
/* Could not allocate the server, delete the socket set */
FreeRTOS_DeleteSocketSet( xSocketSet );
}
}
else
{
/* Could not create a socket set, return NULL */
pxServer = NULL;
}
return pxServer;
}
/*-----------------------------------------------------------*/
static void prvReceiveNewClient( TCPServer_t *pxServer, BaseType_t xIndex, Socket_t xNexSocket )
{
TCPClient_t *pxClient = NULL;
BaseType_t xSize = 0;
FTCPWorkFunction fWorkFunc = NULL;
FTCPDeleteFunction fDeleteFunc = NULL;
const char *pcType = "Unknown";
/*_RB_ Can the work and delete functions be part of the xSERVER_CONFIG structure
becomes generic, with no pre-processing required? */
#if( ipconfigUSE_HTTP != 0 )
{
if( pxServer->xServers[ xIndex ].eType == eSERVER_HTTP )
{
xSize = sizeof( HTTPClient_t );
fWorkFunc = xHTTPClientWork;
fDeleteFunc = vHTTPClientDelete;
pcType = "HTTP";
}
}
#endif /* ipconfigUSE_HTTP != 0 */
#if( ipconfigUSE_FTP != 0 )
{
if( pxServer->xServers[ xIndex ].eType == eSERVER_FTP )
{
xSize = sizeof( FTPClient_t );
fWorkFunc = xFTPClientWork;
fDeleteFunc = vFTPClientDelete;
pcType = "FTP";
}
}
#endif /* ipconfigUSE_FTP != 0 */
/* Malloc enough space for a new HTTP-client */
if( xSize )
{
pxClient = ( TCPClient_t* ) pvPortMallocLarge( xSize );
}
if( pxClient != NULL )
{
memset( pxClient, '\0', xSize );
/* Put the new client in front of the list. */
pxClient->eType = pxServer->xServers[ xIndex ].eType;
pxClient->pcRootDir = pxServer->xServers[ xIndex ].pcRootDir;
pxClient->pxParent = pxServer;
pxClient->xSocket = xNexSocket;
pxClient->pxNextClient = pxServer->pxClients;
pxClient->fWorkFunction = fWorkFunc;
pxClient->fDeleteFunction = fDeleteFunc;
pxServer->pxClients = pxClient;
FreeRTOS_FD_SET( xNexSocket, pxServer->xSocketSet, eSELECT_READ|eSELECT_EXCEPT );
}
else
{
pcType = "closed";
FreeRTOS_closesocket( xNexSocket );
}
{
struct freertos_sockaddr xRemoteAddress;
FreeRTOS_GetRemoteAddress( pxClient->xSocket, &xRemoteAddress );
#if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 )
{
FreeRTOS_printf( ( "TPC-server: new %s client %xip\n", pcType, (unsigned)FreeRTOS_ntohl( xRemoteAddress.sin_address.ulIP_IPv4 ) ) );
}
#else
{
FreeRTOS_printf( ( "TPC-server: new %s client %xip\n", pcType, (unsigned)FreeRTOS_ntohl( xRemoteAddress.sin_addr ) ) );
}
#endif /* defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 ) */
}
/* Remove compiler warnings in case FreeRTOS_printf() is not used. */
( void ) pcType;
}
/*-----------------------------------------------------------*/
void FreeRTOS_TCPServerWork( TCPServer_t *pxServer, TickType_t xBlockingTime )
{
TCPClient_t **ppxClient;
BaseType_t xIndex;
BaseType_t xRc;
/* Let the server do one working cycle */
xRc = FreeRTOS_select( pxServer->xSocketSet, xBlockingTime );
if( xRc != 0 )
{
for( xIndex = 0; xIndex < pxServer->xServerCount; xIndex++ )
{
struct freertos_sockaddr xAddress;
Socket_t xNexSocket;
socklen_t xSocketLength;
if( pxServer->xServers[ xIndex ].xSocket == FREERTOS_NO_SOCKET )
{
continue;
}
xSocketLength = sizeof( xAddress );
xNexSocket = FreeRTOS_accept( pxServer->xServers[ xIndex ].xSocket, &xAddress, &xSocketLength);
if( ( xNexSocket != FREERTOS_NO_SOCKET ) && ( xNexSocket != FREERTOS_INVALID_SOCKET ) )
{
prvReceiveNewClient( pxServer, xIndex, xNexSocket );
}
}
}
ppxClient = &pxServer->pxClients;
while( ( * ppxClient ) != NULL )
{
TCPClient_t *pxThis = *ppxClient;
/* Almost C++ */
xRc = pxThis->fWorkFunction( pxThis );
if (xRc < 0 )
{
*ppxClient = pxThis->pxNextClient;
/* Close handles, resources */
pxThis->fDeleteFunction( pxThis );
/* Free the space */
vPortFreeLarge( pxThis );
}
else
{
ppxClient = &( pxThis->pxNextClient );
}
}
}
/*-----------------------------------------------------------*/
static char *strnew( const char *pcString )
{
BaseType_t xLength;
char *pxBuffer;
xLength = strlen( pcString ) + 1;
pxBuffer = ( char * ) pvPortMalloc( xLength );
if( pxBuffer != NULL )
{
memcpy( pxBuffer, pcString, xLength );
}
return pxBuffer;
}
/*-----------------------------------------------------------*/
static void prvRemoveSlash( char *pcDir )
{
BaseType_t xLength = strlen( pcDir );
while( ( xLength > 0 ) && ( pcDir[ xLength - 1 ] == '/' ) )
{
pcDir[ --xLength ] = '\0';
}
}
/*-----------------------------------------------------------*/
#if( ipconfigSUPPORT_SIGNALS != 0 )
/* FreeRTOS_TCPServerWork() calls select().
The two functions below provide a possibility to interrupt
the call to select(). After the interruption, resume
by calling FreeRTOS_TCPServerWork() again. */
BaseType_t FreeRTOS_TCPServerSignal( TCPServer_t *pxServer )
{
BaseType_t xIndex;
BaseType_t xResult = pdFALSE;
for( xIndex = 0; xIndex < pxServer->xServerCount; xIndex++ )
{
if( pxServer->xServers[ xIndex ].xSocket != FREERTOS_NO_SOCKET )
{
FreeRTOS_SignalSocket( pxServer->xServers[ xIndex ].xSocket );
xResult = pdTRUE;
break;
}
}
return xResult;
}
#endif /* ipconfigSUPPORT_SIGNALS */
/*-----------------------------------------------------------*/
#if( ipconfigSUPPORT_SIGNALS != 0 )
/* Same as above: this function may be called from an ISR,
for instance a GPIO interrupt. */
BaseType_t FreeRTOS_TCPServerSignalFromISR( TCPServer_t *pxServer, BaseType_t *pxHigherPriorityTaskWoken )
{
BaseType_t xIndex;
BaseType_t xResult = pdFALSE;
for( xIndex = 0; xIndex < pxServer->xServerCount; xIndex++ )
{
if( pxServer->xServers[ xIndex ].xSocket != FREERTOS_NO_SOCKET )
{
FreeRTOS_SignalSocketFromISR( pxServer->xServers[ xIndex ].xSocket, pxHigherPriorityTaskWoken );
xResult = pdTRUE;
break;
}
}
return xResult;
}
#endif /* ipconfigSUPPORT_SIGNALS */
/*-----------------------------------------------------------*/
#endif /* ( ipconfigUSE_TCP == 1 ) && ( ( ipconfigUSE_HTTP == 1 ) || ( ipconfigUSE_FTP == 1 ) ) */
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
/* Standard includes. */
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "task.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_Sockets.h"
#include "FreeRTOS_TCP_server.h"
#include "FreeRTOS_server_private.h"
/* Remove the entire file if TCP is not being used. */
#if ( ipconfigUSE_TCP == 1 ) && ( ( ipconfigUSE_HTTP == 1 ) || ( ipconfigUSE_FTP == 1 ) )
#if !defined( ARRAY_SIZE )
#define ARRAY_SIZE( x ) ( BaseType_t ) ( sizeof( x ) / sizeof( x )[ 0 ] )
#endif
static void prvReceiveNewClient( TCPServer_t * pxServer,
BaseType_t xIndex,
Socket_t xNexSocket );
static char * strnew( const char * pcString );
/* Remove slashes at the end of a path. */
static void prvRemoveSlash( char * pcDir );
TCPServer_t * FreeRTOS_CreateTCPServer( const struct xSERVER_CONFIG * pxConfigs,
BaseType_t xCount )
{
TCPServer_t * pxServer;
SocketSet_t xSocketSet;
/* Create a new server.
* xPort / xPortAlt : Make the service available on 1 or 2 public port numbers. */
xSocketSet = FreeRTOS_CreateSocketSet();
if( xSocketSet != NULL )
{
BaseType_t xSize;
xSize = sizeof( *pxServer ) - sizeof( pxServer->xServers ) + xCount * sizeof( pxServer->xServers[ 0 ] );
pxServer = ( TCPServer_t * ) pvPortMallocLarge( xSize );
if( pxServer != NULL )
{
struct freertos_sockaddr xAddress;
BaseType_t xNoTimeout = 0;
BaseType_t xIndex;
memset( pxServer, '\0', xSize );
pxServer->xServerCount = xCount;
pxServer->xSocketSet = xSocketSet;
for( xIndex = 0; xIndex < xCount; xIndex++ )
{
BaseType_t xPortNumber = pxConfigs[ xIndex ].xPortNumber;
if( xPortNumber > 0 )
{
Socket_t xSocket;
xSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP );
FreeRTOS_printf( ( "TCP socket on port %d\n", ( int ) xPortNumber ) );
if( xSocket != FREERTOS_INVALID_SOCKET )
{
#if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 )
{
xAddress.sin_address.ulIP_IPv4 = FreeRTOS_GetIPAddress(); /* Single NIC, currently not used */
}
#else
{
xAddress.sin_addr = FreeRTOS_GetIPAddress(); /* Single NIC, currently not used */
}
#endif /* defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 ) */
xAddress.sin_port = FreeRTOS_htons( xPortNumber );
xAddress.sin_family = FREERTOS_AF_INET;
FreeRTOS_bind( xSocket, &xAddress, sizeof( xAddress ) );
FreeRTOS_listen( xSocket, pxConfigs[ xIndex ].xBackLog );
FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_RCVTIMEO, ( void * ) &xNoTimeout, sizeof( BaseType_t ) );
FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_SNDTIMEO, ( void * ) &xNoTimeout, sizeof( BaseType_t ) );
#if ( ipconfigHTTP_RX_BUFSIZE > 0 )
{
if( pxConfigs[ xIndex ].eType == eSERVER_HTTP )
{
WinProperties_t xWinProps;
memset( &xWinProps, '\0', sizeof( xWinProps ) );
/* The parent socket itself won't get connected. The properties below
* will be inherited by each new child socket. */
xWinProps.lTxBufSize = ipconfigHTTP_TX_BUFSIZE;
xWinProps.lTxWinSize = ipconfigHTTP_TX_WINSIZE;
xWinProps.lRxBufSize = ipconfigHTTP_RX_BUFSIZE;
xWinProps.lRxWinSize = ipconfigHTTP_RX_WINSIZE;
/* Set the window and buffer sizes. */
FreeRTOS_setsockopt( xSocket, 0, FREERTOS_SO_WIN_PROPERTIES, ( void * ) &xWinProps, sizeof( xWinProps ) );
}
}
#endif /* if ( ipconfigHTTP_RX_BUFSIZE > 0 ) */
FreeRTOS_FD_SET( xSocket, xSocketSet, eSELECT_READ | eSELECT_EXCEPT );
pxServer->xServers[ xIndex ].xSocket = xSocket;
pxServer->xServers[ xIndex ].eType = pxConfigs[ xIndex ].eType;
pxServer->xServers[ xIndex ].pcRootDir = strnew( pxConfigs[ xIndex ].pcRootDir );
prvRemoveSlash( ( char * ) pxServer->xServers[ xIndex ].pcRootDir );
}
}
}
}
else
{
/* Could not allocate the server, delete the socket set */
FreeRTOS_DeleteSocketSet( xSocketSet );
}
}
else
{
/* Could not create a socket set, return NULL */
pxServer = NULL;
}
return pxServer;
}
/*-----------------------------------------------------------*/
static void prvReceiveNewClient( TCPServer_t * pxServer,
BaseType_t xIndex,
Socket_t xNexSocket )
{
TCPClient_t * pxClient = NULL;
BaseType_t xSize = 0;
FTCPWorkFunction fWorkFunc = NULL;
FTCPDeleteFunction fDeleteFunc = NULL;
const char * pcType = "Unknown";
/*_RB_ Can the work and delete functions be part of the xSERVER_CONFIG structure
* becomes generic, with no pre-processing required? */
#if ( ipconfigUSE_HTTP != 0 )
{
if( pxServer->xServers[ xIndex ].eType == eSERVER_HTTP )
{
xSize = sizeof( HTTPClient_t );
fWorkFunc = xHTTPClientWork;
fDeleteFunc = vHTTPClientDelete;
pcType = "HTTP";
}
}
#endif /* ipconfigUSE_HTTP != 0 */
#if ( ipconfigUSE_FTP != 0 )
{
if( pxServer->xServers[ xIndex ].eType == eSERVER_FTP )
{
xSize = sizeof( FTPClient_t );
fWorkFunc = xFTPClientWork;
fDeleteFunc = vFTPClientDelete;
pcType = "FTP";
}
}
#endif /* ipconfigUSE_FTP != 0 */
/* Malloc enough space for a new HTTP-client */
if( xSize )
{
pxClient = ( TCPClient_t * ) pvPortMallocLarge( xSize );
}
if( pxClient != NULL )
{
memset( pxClient, '\0', xSize );
/* Put the new client in front of the list. */
pxClient->eType = pxServer->xServers[ xIndex ].eType;
pxClient->pcRootDir = pxServer->xServers[ xIndex ].pcRootDir;
pxClient->pxParent = pxServer;
pxClient->xSocket = xNexSocket;
pxClient->pxNextClient = pxServer->pxClients;
pxClient->fWorkFunction = fWorkFunc;
pxClient->fDeleteFunction = fDeleteFunc;
pxServer->pxClients = pxClient;
FreeRTOS_FD_SET( xNexSocket, pxServer->xSocketSet, eSELECT_READ | eSELECT_EXCEPT );
}
else
{
pcType = "closed";
FreeRTOS_closesocket( xNexSocket );
}
{
struct freertos_sockaddr xRemoteAddress;
FreeRTOS_GetRemoteAddress( pxClient->xSocket, &xRemoteAddress );
#if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 )
{
FreeRTOS_printf( ( "TPC-server: new %s client %xip\n", pcType, ( unsigned ) FreeRTOS_ntohl( xRemoteAddress.sin_address.ulIP_IPv4 ) ) );
}
#else
{
FreeRTOS_printf( ( "TPC-server: new %s client %xip\n", pcType, ( unsigned ) FreeRTOS_ntohl( xRemoteAddress.sin_addr ) ) );
}
#endif /* defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 ) */
}
/* Remove compiler warnings in case FreeRTOS_printf() is not used. */
( void ) pcType;
}
/*-----------------------------------------------------------*/
void FreeRTOS_TCPServerWork( TCPServer_t * pxServer,
TickType_t xBlockingTime )
{
TCPClient_t ** ppxClient;
BaseType_t xIndex;
BaseType_t xRc;
/* Let the server do one working cycle */
xRc = FreeRTOS_select( pxServer->xSocketSet, xBlockingTime );
if( xRc != 0 )
{
for( xIndex = 0; xIndex < pxServer->xServerCount; xIndex++ )
{
struct freertos_sockaddr xAddress;
Socket_t xNexSocket;
socklen_t xSocketLength;
if( pxServer->xServers[ xIndex ].xSocket == FREERTOS_NO_SOCKET )
{
continue;
}
xSocketLength = sizeof( xAddress );
xNexSocket = FreeRTOS_accept( pxServer->xServers[ xIndex ].xSocket, &xAddress, &xSocketLength );
if( ( xNexSocket != FREERTOS_NO_SOCKET ) && ( xNexSocket != FREERTOS_INVALID_SOCKET ) )
{
prvReceiveNewClient( pxServer, xIndex, xNexSocket );
}
}
}
ppxClient = &pxServer->pxClients;
while( ( *ppxClient ) != NULL )
{
TCPClient_t * pxThis = *ppxClient;
/* Almost C++ */
xRc = pxThis->fWorkFunction( pxThis );
if( xRc < 0 )
{
*ppxClient = pxThis->pxNextClient;
/* Close handles, resources */
pxThis->fDeleteFunction( pxThis );
/* Free the space */
vPortFreeLarge( pxThis );
}
else
{
ppxClient = &( pxThis->pxNextClient );
}
}
}
/*-----------------------------------------------------------*/
static char * strnew( const char * pcString )
{
BaseType_t xLength;
char * pxBuffer;
xLength = strlen( pcString ) + 1;
pxBuffer = ( char * ) pvPortMalloc( xLength );
if( pxBuffer != NULL )
{
memcpy( pxBuffer, pcString, xLength );
}
return pxBuffer;
}
/*-----------------------------------------------------------*/
static void prvRemoveSlash( char * pcDir )
{
BaseType_t xLength = strlen( pcDir );
while( ( xLength > 0 ) && ( pcDir[ xLength - 1 ] == '/' ) )
{
pcDir[ --xLength ] = '\0';
}
}
/*-----------------------------------------------------------*/
#if ( ipconfigSUPPORT_SIGNALS != 0 )
/* FreeRTOS_TCPServerWork() calls select().
* The two functions below provide a possibility to interrupt
* the call to select(). After the interruption, resume
* by calling FreeRTOS_TCPServerWork() again. */
BaseType_t FreeRTOS_TCPServerSignal( TCPServer_t * pxServer )
{
BaseType_t xIndex;
BaseType_t xResult = pdFALSE;
for( xIndex = 0; xIndex < pxServer->xServerCount; xIndex++ )
{
if( pxServer->xServers[ xIndex ].xSocket != FREERTOS_NO_SOCKET )
{
FreeRTOS_SignalSocket( pxServer->xServers[ xIndex ].xSocket );
xResult = pdTRUE;
break;
}
}
return xResult;
}
#endif /* ipconfigSUPPORT_SIGNALS */
/*-----------------------------------------------------------*/
#if ( ipconfigSUPPORT_SIGNALS != 0 )
/* Same as above: this function may be called from an ISR,
* for instance a GPIO interrupt. */
BaseType_t FreeRTOS_TCPServerSignalFromISR( TCPServer_t * pxServer,
BaseType_t * pxHigherPriorityTaskWoken )
{
BaseType_t xIndex;
BaseType_t xResult = pdFALSE;
for( xIndex = 0; xIndex < pxServer->xServerCount; xIndex++ )
{
if( pxServer->xServers[ xIndex ].xSocket != FREERTOS_NO_SOCKET )
{
FreeRTOS_SignalSocketFromISR( pxServer->xServers[ xIndex ].xSocket, pxHigherPriorityTaskWoken );
xResult = pdTRUE;
break;
}
}
return xResult;
}
#endif /* ipconfigSUPPORT_SIGNALS */
/*-----------------------------------------------------------*/
#endif /* ( ipconfigUSE_TCP == 1 ) && ( ( ipconfigUSE_HTTP == 1 ) || ( ipconfigUSE_FTP == 1 ) ) */

@ -1,74 +1,75 @@
/*
* FreeRTOS+TCP V2.0.3
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://aws.amazon.com/freertos
* https://www.FreeRTOS.org
*/
/* FreeRTOS includes. */
#include "FreeRTOS.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_FTP_commands.h"
const FTPCommand_t xFTPCommands[ FTP_CMD_COUNT ] =
{
/* cmdLen cmdName[7] cmdType checkLogin checkNullArg */
{ 4, "USER", ECMD_USER, pdFALSE, pdFALSE },
{ 4, "PASS", ECMD_PASS, pdFALSE, pdFALSE },
{ 4, "ACCT", ECMD_ACCT, pdTRUE, pdFALSE },
{ 3, "CWD", ECMD_CWD, pdTRUE, pdTRUE },
{ 4, "CDUP", ECMD_CDUP, pdTRUE, pdFALSE },
{ 4, "SMNT", ECMD_SMNT, pdTRUE, pdFALSE },
{ 4, "QUIT", ECMD_QUIT, pdTRUE, pdFALSE },
{ 4, "REIN", ECMD_REIN, pdTRUE, pdFALSE },
{ 4, "PORT", ECMD_PORT, pdTRUE, pdFALSE },
{ 4, "PASV", ECMD_PASV, pdTRUE, pdFALSE },
{ 4, "TYPE", ECMD_TYPE, pdTRUE, pdFALSE },
{ 4, "STRU", ECMD_STRU, pdTRUE, pdFALSE },
{ 4, "MODE", ECMD_MODE, pdTRUE, pdFALSE },
{ 4, "RETR", ECMD_RETR, pdTRUE, pdTRUE },
{ 4, "STOR", ECMD_STOR, pdTRUE, pdTRUE },
{ 4, "STOU", ECMD_STOU, pdTRUE, pdFALSE },
{ 4, "APPE", ECMD_APPE, pdTRUE, pdFALSE },
{ 4, "ALLO", ECMD_ALLO, pdTRUE, pdFALSE },
{ 4, "REST", ECMD_REST, pdTRUE, pdFALSE },
{ 4, "RNFR", ECMD_RNFR, pdTRUE, pdTRUE },
{ 4, "RNTO", ECMD_RNTO, pdTRUE, pdTRUE },
{ 4, "ABOR", ECMD_ABOR, pdTRUE, pdFALSE },
{ 4, "SIZE", ECMD_SIZE, pdTRUE, pdTRUE },
{ 4, "MDTM", ECMD_MDTM, pdTRUE, pdTRUE },
{ 4, "DELE", ECMD_DELE, pdTRUE, pdTRUE },
{ 3, "RMD", ECMD_RMD, pdTRUE, pdTRUE },
{ 3, "MKD", ECMD_MKD, pdTRUE, pdTRUE },
{ 3, "PWD", ECMD_PWD, pdTRUE, pdFALSE },
{ 4, "LIST", ECMD_LIST, pdTRUE, pdFALSE },
{ 4, "NLST", ECMD_NLST, pdTRUE, pdFALSE },
{ 4, "SITE", ECMD_SITE, pdTRUE, pdFALSE },
{ 4, "SYST", ECMD_SYST, pdFALSE, pdFALSE },
{ 4, "FEAT", ECMD_FEAT, pdFALSE, pdFALSE },
{ 4, "STAT", ECMD_STAT, pdTRUE, pdFALSE },
{ 4, "HELP", ECMD_HELP, pdFALSE, pdFALSE },
{ 4, "NOOP", ECMD_NOOP, pdFALSE, pdFALSE },
{ 4, "EMPT", ECMD_EMPTY, pdFALSE, pdFALSE },
{ 4, "CLOS", ECMD_CLOSE, pdTRUE, pdFALSE },
{ 4, "UNKN", ECMD_UNKNOWN, pdFALSE, pdFALSE },
};
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
/* FreeRTOS includes. */
#include "FreeRTOS.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_FTP_commands.h"
const FTPCommand_t xFTPCommands[ FTP_CMD_COUNT ] =
{
/* cmdLen cmdName[7] cmdType checkLogin checkNullArg */
{ 4, "USER", ECMD_USER, pdFALSE, pdFALSE },
{ 4, "PASS", ECMD_PASS, pdFALSE, pdFALSE },
{ 4, "ACCT", ECMD_ACCT, pdTRUE, pdFALSE },
{ 3, "CWD", ECMD_CWD, pdTRUE, pdTRUE },
{ 4, "CDUP", ECMD_CDUP, pdTRUE, pdFALSE },
{ 4, "SMNT", ECMD_SMNT, pdTRUE, pdFALSE },
{ 4, "QUIT", ECMD_QUIT, pdTRUE, pdFALSE },
{ 4, "REIN", ECMD_REIN, pdTRUE, pdFALSE },
{ 4, "PORT", ECMD_PORT, pdTRUE, pdFALSE },
{ 4, "PASV", ECMD_PASV, pdTRUE, pdFALSE },
{ 4, "TYPE", ECMD_TYPE, pdTRUE, pdFALSE },
{ 4, "STRU", ECMD_STRU, pdTRUE, pdFALSE },
{ 4, "MODE", ECMD_MODE, pdTRUE, pdFALSE },
{ 4, "RETR", ECMD_RETR, pdTRUE, pdTRUE },
{ 4, "STOR", ECMD_STOR, pdTRUE, pdTRUE },
{ 4, "STOU", ECMD_STOU, pdTRUE, pdFALSE },
{ 4, "APPE", ECMD_APPE, pdTRUE, pdFALSE },
{ 4, "ALLO", ECMD_ALLO, pdTRUE, pdFALSE },
{ 4, "REST", ECMD_REST, pdTRUE, pdFALSE },
{ 4, "RNFR", ECMD_RNFR, pdTRUE, pdTRUE },
{ 4, "RNTO", ECMD_RNTO, pdTRUE, pdTRUE },
{ 4, "ABOR", ECMD_ABOR, pdTRUE, pdFALSE },
{ 4, "SIZE", ECMD_SIZE, pdTRUE, pdTRUE },
{ 4, "MDTM", ECMD_MDTM, pdTRUE, pdTRUE },
{ 4, "DELE", ECMD_DELE, pdTRUE, pdTRUE },
{ 3, "RMD", ECMD_RMD, pdTRUE, pdTRUE },
{ 3, "MKD", ECMD_MKD, pdTRUE, pdTRUE },
{ 3, "PWD", ECMD_PWD, pdTRUE, pdFALSE },
{ 4, "LIST", ECMD_LIST, pdTRUE, pdFALSE },
{ 4, "NLST", ECMD_NLST, pdTRUE, pdFALSE },
{ 4, "SITE", ECMD_SITE, pdTRUE, pdFALSE },
{ 4, "SYST", ECMD_SYST, pdFALSE, pdFALSE },
{ 4, "FEAT", ECMD_FEAT, pdFALSE, pdFALSE },
{ 4, "STAT", ECMD_STAT, pdTRUE, pdFALSE },
{ 4, "HELP", ECMD_HELP, pdFALSE, pdFALSE },
{ 4, "NOOP", ECMD_NOOP, pdFALSE, pdFALSE },
{ 4, "EMPT", ECMD_EMPTY, pdFALSE, pdFALSE },
{ 4, "CLOS", ECMD_CLOSE, pdTRUE, pdFALSE },
{ 4, "UNKN", ECMD_UNKNOWN, pdFALSE, pdFALSE },
};

@ -1,76 +1,87 @@
/*
*!
*! The protocols implemented in this file are intended to be demo quality only,
*! and not for production devices.
*!
*
* FreeRTOS+TCP V2.0.3
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://aws.amazon.com/freertos
* https://www.FreeRTOS.org
*/
/* Standard includes. */
#include <stdio.h>
#include <stdlib.h>
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "FreeRTOS_HTTP_commands.h"
const struct xWEB_COMMAND xWebCommands[ WEB_CMD_COUNT ] =
{
{ 3, "GET", ECMD_GET },
{ 4, "HEAD", ECMD_HEAD },
{ 4, "POST", ECMD_POST },
{ 3, "PUT", ECMD_PUT },
{ 6, "DELETE", ECMD_DELETE },
{ 5, "TRACE", ECMD_TRACE },
{ 7, "OPTIONS", ECMD_OPTIONS },
{ 7, "CONNECT", ECMD_CONNECT },
{ 5, "PATCH", ECMD_PATCH },
{ 4, "UNKN", ECMD_UNK },
};
const char *webCodename (int aCode)
{
switch (aCode) {
case WEB_REPLY_OK: // = 200,
return "OK";
case WEB_NO_CONTENT: // 204
return "No content";
case WEB_BAD_REQUEST: // = 400,
return "Bad request";
case WEB_UNAUTHORIZED: // = 401,
return "Authorization Required";
case WEB_NOT_FOUND: // = 404,
return "Not Found";
case WEB_GONE: // = 410,
return "Done";
case WEB_PRECONDITION_FAILED: // = 412,
return "Precondition Failed";
case WEB_INTERNAL_SERVER_ERROR: // = 500,
return "Internal Server Error";
}
return "Unknown";
}
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
/**
*!
*! The protocols implemented in this file are intended to be demo quality only,
*! and not for production devices.
*!
*/
/* Standard includes. */
#include <stdio.h>
#include <stdlib.h>
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "FreeRTOS_HTTP_commands.h"
const struct xWEB_COMMAND xWebCommands[ WEB_CMD_COUNT ] =
{
{ 3, "GET", ECMD_GET },
{ 4, "HEAD", ECMD_HEAD },
{ 4, "POST", ECMD_POST },
{ 3, "PUT", ECMD_PUT },
{ 6, "DELETE", ECMD_DELETE },
{ 5, "TRACE", ECMD_TRACE },
{ 7, "OPTIONS", ECMD_OPTIONS },
{ 7, "CONNECT", ECMD_CONNECT },
{ 5, "PATCH", ECMD_PATCH },
{ 4, "UNKN", ECMD_UNK },
};
const char * webCodename( int aCode )
{
switch( aCode )
{
case WEB_REPLY_OK: /* = 200, */
return "OK";
case WEB_NO_CONTENT: /* 204 */
return "No content";
case WEB_BAD_REQUEST: /* = 400, */
return "Bad request";
case WEB_UNAUTHORIZED: /* = 401, */
return "Authorization Required";
case WEB_NOT_FOUND: /* = 404, */
return "Not Found";
case WEB_GONE: /* = 410, */
return "Done";
case WEB_PRECONDITION_FAILED: /* = 412, */
return "Precondition Failed";
case WEB_INTERNAL_SERVER_ERROR: /* = 500, */
return "Internal Server Error";
}
return "Unknown";
}

@ -1,433 +1,464 @@
/*
*!
*! The protocols implemented in this file are intended to be demo quality only,
*! and not for production devices.
*!
*
* FreeRTOS+TCP V2.0.3
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://aws.amazon.com/freertos
* https://www.FreeRTOS.org
*/
/* Standard includes. */
#include <stdio.h>
#include <stdlib.h>
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "task.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_Sockets.h"
/* FreeRTOS Protocol includes. */
#include "FreeRTOS_HTTP_commands.h"
#include "FreeRTOS_TCP_server.h"
#include "FreeRTOS_server_private.h"
/* Remove the whole file if HTTP is not supported. */
#if( ipconfigUSE_HTTP == 1 )
/* FreeRTOS+FAT includes. */
#include "ff_stdio.h"
#ifndef HTTP_SERVER_BACKLOG
#define HTTP_SERVER_BACKLOG ( 12 )
#endif
#ifndef USE_HTML_CHUNKS
#define USE_HTML_CHUNKS ( 0 )
#endif
#if !defined( ARRAY_SIZE )
#define ARRAY_SIZE(x) ( BaseType_t ) (sizeof( x ) / sizeof( x )[ 0 ] )
#endif
/* Some defines to make the code more readbale */
#define pcCOMMAND_BUFFER pxClient->pxParent->pcCommandBuffer
#define pcNEW_DIR pxClient->pxParent->pcNewDir
#define pcFILE_BUFFER pxClient->pxParent->pcFileBuffer
#ifndef ipconfigHTTP_REQUEST_CHARACTER
#define ipconfigHTTP_REQUEST_CHARACTER '?'
#endif
/*_RB_ Need comment block, although fairly self evident. */
static void prvFileClose( HTTPClient_t *pxClient );
static BaseType_t prvProcessCmd( HTTPClient_t *pxClient, BaseType_t xIndex );
static const char *pcGetContentsType( const char *apFname );
static BaseType_t prvOpenURL( HTTPClient_t *pxClient );
static BaseType_t prvSendFile( HTTPClient_t *pxClient );
static BaseType_t prvSendReply( HTTPClient_t *pxClient, BaseType_t xCode );
static const char pcEmptyString[1] = { '\0' };
typedef struct xTYPE_COUPLE
{
const char *pcExtension;
const char *pcType;
} TypeCouple_t;
static TypeCouple_t pxTypeCouples[ ] =
{
{ "html", "text/html" },
{ "css", "text/css" },
{ "js", "text/javascript" },
{ "png", "image/png" },
{ "jpg", "image/jpeg" },
{ "gif", "image/gif" },
{ "txt", "text/plain" },
{ "mp3", "audio/mpeg3" },
{ "wav", "audio/wav" },
{ "flac", "audio/ogg" },
{ "pdf", "application/pdf" },
{ "ttf", "application/x-font-ttf" },
{ "ttc", "application/x-font-ttf" }
};
void vHTTPClientDelete( TCPClient_t *pxTCPClient )
{
HTTPClient_t *pxClient = ( HTTPClient_t * ) pxTCPClient;
/* This HTTP client stops, close / release all resources. */
if( pxClient->xSocket != FREERTOS_NO_SOCKET )
{
FreeRTOS_FD_CLR( pxClient->xSocket, pxClient->pxParent->xSocketSet, eSELECT_ALL );
FreeRTOS_closesocket( pxClient->xSocket );
pxClient->xSocket = FREERTOS_NO_SOCKET;
}
prvFileClose( pxClient );
}
/*-----------------------------------------------------------*/
static void prvFileClose( HTTPClient_t *pxClient )
{
if( pxClient->pxFileHandle != NULL )
{
FreeRTOS_printf( ( "Closing file: %s\n", pxClient->pcCurrentFilename ) );
ff_fclose( pxClient->pxFileHandle );
pxClient->pxFileHandle = NULL;
}
}
/*-----------------------------------------------------------*/
static BaseType_t prvSendReply( HTTPClient_t *pxClient, BaseType_t xCode )
{
struct xTCP_SERVER *pxParent = pxClient->pxParent;
BaseType_t xRc;
/* A normal command reply on the main socket (port 21). */
char *pcBuffer = pxParent->pcFileBuffer;
xRc = snprintf( pcBuffer, sizeof( pxParent->pcFileBuffer ),
"HTTP/1.1 %d %s\r\n"
#if USE_HTML_CHUNKS
"Transfer-Encoding: chunked\r\n"
#endif
"Content-Type: %s\r\n"
"Connection: keep-alive\r\n"
"%s\r\n",
( int ) xCode,
webCodename (xCode),
pxParent->pcContentsType[0] ? pxParent->pcContentsType : "text/html",
pxParent->pcExtraContents );
pxParent->pcContentsType[0] = '\0';
pxParent->pcExtraContents[0] = '\0';
xRc = FreeRTOS_send( pxClient->xSocket, ( const void * ) pcBuffer, xRc, 0 );
pxClient->bits.bReplySent = pdTRUE_UNSIGNED;
return xRc;
}
/*-----------------------------------------------------------*/
static BaseType_t prvSendFile( HTTPClient_t *pxClient )
{
size_t uxSpace;
size_t uxCount;
BaseType_t xRc = 0;
if( pxClient->bits.bReplySent == pdFALSE_UNSIGNED )
{
pxClient->bits.bReplySent = pdTRUE_UNSIGNED;
strcpy( pxClient->pxParent->pcContentsType, pcGetContentsType( pxClient->pcCurrentFilename ) );
snprintf( pxClient->pxParent->pcExtraContents, sizeof( pxClient->pxParent->pcExtraContents ),
"Content-Length: %d\r\n", ( int ) pxClient->uxBytesLeft );
/* "Requested file action OK". */
xRc = prvSendReply( pxClient, WEB_REPLY_OK );
}
if( xRc >= 0 ) do
{
uxSpace = FreeRTOS_tx_space( pxClient->xSocket );
if( pxClient->uxBytesLeft < uxSpace )
{
uxCount = pxClient->uxBytesLeft;
}
else
{
uxCount = uxSpace;
}
if( uxCount > 0u )
{
if( uxCount > sizeof( pxClient->pxParent->pcFileBuffer ) )
{
uxCount = sizeof( pxClient->pxParent->pcFileBuffer );
}
ff_fread( pxClient->pxParent->pcFileBuffer, 1, uxCount, pxClient->pxFileHandle );
pxClient->uxBytesLeft -= uxCount;
xRc = FreeRTOS_send( pxClient->xSocket, pxClient->pxParent->pcFileBuffer, uxCount, 0 );
if( xRc < 0 )
{
break;
}
}
} while( uxCount > 0u );
if( pxClient->uxBytesLeft == 0u )
{
/* Writing is ready, no need for further 'eSELECT_WRITE' events. */
FreeRTOS_FD_CLR( pxClient->xSocket, pxClient->pxParent->xSocketSet, eSELECT_WRITE );
prvFileClose( pxClient );
}
else
{
/* Wake up the TCP task as soon as this socket may be written to. */
FreeRTOS_FD_SET( pxClient->xSocket, pxClient->pxParent->xSocketSet, eSELECT_WRITE );
}
return xRc;
}
/*-----------------------------------------------------------*/
static BaseType_t prvOpenURL( HTTPClient_t *pxClient )
{
BaseType_t xRc;
char pcSlash[ 2 ];
pxClient->bits.ulFlags = 0;
#if( ipconfigHTTP_HAS_HANDLE_REQUEST_HOOK != 0 )
{
if( strchr( pxClient->pcUrlData, ipconfigHTTP_REQUEST_CHARACTER ) != NULL )
{
size_t xResult;
xResult = uxApplicationHTTPHandleRequestHook( pxClient->pcUrlData, pxClient->pcCurrentFilename, sizeof( pxClient->pcCurrentFilename ) );
if( xResult > 0 )
{
strcpy( pxClient->pxParent->pcContentsType, "text/html" );
snprintf( pxClient->pxParent->pcExtraContents, sizeof( pxClient->pxParent->pcExtraContents ),
"Content-Length: %d\r\n", ( int ) xResult );
xRc = prvSendReply( pxClient, WEB_REPLY_OK ); /* "Requested file action OK" */
if( xRc > 0 )
{
xRc = FreeRTOS_send( pxClient->xSocket, pxClient->pcCurrentFilename, xResult, 0 );
}
/* Although against the coding standard of FreeRTOS, a return is
done here to simplify this conditional code. */
return xRc;
}
}
}
#endif /* ipconfigHTTP_HAS_HANDLE_REQUEST_HOOK */
if( pxClient->pcUrlData[ 0 ] != '/' )
{
/* Insert a slash before the file name. */
pcSlash[ 0 ] = '/';
pcSlash[ 1 ] = '\0';
}
else
{
/* The browser provided a starting '/' already. */
pcSlash[ 0 ] = '\0';
}
snprintf( pxClient->pcCurrentFilename, sizeof( pxClient->pcCurrentFilename ), "%s%s%s",
pxClient->pcRootDir,
pcSlash,
pxClient->pcUrlData);
pxClient->pxFileHandle = ff_fopen( pxClient->pcCurrentFilename, "rb" );
FreeRTOS_printf( ( "Open file '%s': %s\n", pxClient->pcCurrentFilename,
pxClient->pxFileHandle != NULL ? "Ok" : strerror( stdioGET_ERRNO() ) ) );
if( pxClient->pxFileHandle == NULL )
{
/* "404 File not found". */
xRc = prvSendReply( pxClient, WEB_NOT_FOUND );
}
else
{
pxClient->uxBytesLeft = ( size_t ) pxClient->pxFileHandle->ulFileSize;
xRc = prvSendFile( pxClient );
}
return xRc;
}
/*-----------------------------------------------------------*/
static BaseType_t prvProcessCmd( HTTPClient_t *pxClient, BaseType_t xIndex )
{
BaseType_t xResult = 0;
/* A new command has been received. Process it. */
switch( xIndex )
{
case ECMD_GET:
xResult = prvOpenURL( pxClient );
break;
case ECMD_HEAD:
case ECMD_POST:
case ECMD_PUT:
case ECMD_DELETE:
case ECMD_TRACE:
case ECMD_OPTIONS:
case ECMD_CONNECT:
case ECMD_PATCH:
case ECMD_UNK:
{
FreeRTOS_printf( ( "prvProcessCmd: Not implemented: %s\n",
xWebCommands[xIndex].pcCommandName ) );
}
break;
}
return xResult;
}
/*-----------------------------------------------------------*/
BaseType_t xHTTPClientWork( TCPClient_t *pxTCPClient )
{
BaseType_t xRc;
HTTPClient_t *pxClient = ( HTTPClient_t * ) pxTCPClient;
if( pxClient->pxFileHandle != NULL )
{
prvSendFile( pxClient );
}
xRc = FreeRTOS_recv( pxClient->xSocket, ( void * )pcCOMMAND_BUFFER, sizeof( pcCOMMAND_BUFFER ), 0 );
if( xRc > 0 )
{
BaseType_t xIndex;
const char *pcEndOfCmd;
const struct xWEB_COMMAND *curCmd;
char *pcBuffer = pcCOMMAND_BUFFER;
if( xRc < ( BaseType_t ) sizeof( pcCOMMAND_BUFFER ) )
{
pcBuffer[ xRc ] = '\0';
}
while( xRc && ( pcBuffer[ xRc - 1 ] == 13 || pcBuffer[ xRc - 1 ] == 10 ) )
{
pcBuffer[ --xRc ] = '\0';
}
pcEndOfCmd = pcBuffer + xRc;
curCmd = xWebCommands;
/* Pointing to "/index.html HTTP/1.1". */
pxClient->pcUrlData = pcBuffer;
/* Pointing to "HTTP/1.1". */
pxClient->pcRestData = pcEmptyString;
/* Last entry is "ECMD_UNK". */
for( xIndex = 0; xIndex < WEB_CMD_COUNT - 1; xIndex++, curCmd++ )
{
BaseType_t xLength;
xLength = curCmd->xCommandLength;
if( ( xRc >= xLength ) && ( memcmp( curCmd->pcCommandName, pcBuffer, xLength ) == 0 ) )
{
char *pcLastPtr;
pxClient->pcUrlData += xLength + 1;
for( pcLastPtr = (char *)pxClient->pcUrlData; pcLastPtr < pcEndOfCmd; pcLastPtr++ )
{
char ch = *pcLastPtr;
if( ( ch == '\0' ) || ( strchr( "\n\r \t", ch ) != NULL ) )
{
*pcLastPtr = '\0';
pxClient->pcRestData = pcLastPtr + 1;
break;
}
}
break;
}
}
if( xIndex < ( WEB_CMD_COUNT - 1 ) )
{
xRc = prvProcessCmd( pxClient, xIndex );
}
}
else if( xRc < 0 )
{
/* The connection will be closed and the client will be deleted. */
FreeRTOS_printf( ( "xHTTPClientWork: rc = %ld\n", xRc ) );
}
return xRc;
}
/*-----------------------------------------------------------*/
static const char *pcGetContentsType (const char *apFname)
{
const char *slash = NULL;
const char *dot = NULL;
const char *ptr;
const char *pcResult = "text/html";
BaseType_t x;
for( ptr = apFname; *ptr; ptr++ )
{
if (*ptr == '.') dot = ptr;
if (*ptr == '/') slash = ptr;
}
if( dot > slash )
{
dot++;
for( x = 0; x < ARRAY_SIZE( pxTypeCouples ); x++ )
{
if( strcasecmp( dot, pxTypeCouples[ x ].pcExtension ) == 0 )
{
pcResult = pxTypeCouples[ x ].pcType;
break;
}
}
}
return pcResult;
}
#endif /* ipconfigUSE_HTTP */
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
/**
*!
*! The protocols implemented in this file are intended to be demo quality only,
*! and not for production devices.
*!
*/
/* Standard includes. */
#include <stdio.h>
#include <stdlib.h>
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "task.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_Sockets.h"
/* FreeRTOS Protocol includes. */
#include "FreeRTOS_HTTP_commands.h"
#include "FreeRTOS_TCP_server.h"
#include "FreeRTOS_server_private.h"
/* Remove the whole file if HTTP is not supported. */
#if ( ipconfigUSE_HTTP == 1 )
/* FreeRTOS+FAT includes. */
#include "ff_stdio.h"
#ifndef HTTP_SERVER_BACKLOG
#define HTTP_SERVER_BACKLOG ( 12 )
#endif
#ifndef USE_HTML_CHUNKS
#define USE_HTML_CHUNKS ( 0 )
#endif
#if !defined( ARRAY_SIZE )
#define ARRAY_SIZE( x ) ( BaseType_t ) ( sizeof( x ) / sizeof( x )[ 0 ] )
#endif
/* Some defines to make the code more readbale */
#define pcCOMMAND_BUFFER pxClient->pxParent->pcCommandBuffer
#define pcNEW_DIR pxClient->pxParent->pcNewDir
#define pcFILE_BUFFER pxClient->pxParent->pcFileBuffer
#ifndef ipconfigHTTP_REQUEST_CHARACTER
#define ipconfigHTTP_REQUEST_CHARACTER '?'
#endif
/*_RB_ Need comment block, although fairly self evident. */
static void prvFileClose( HTTPClient_t * pxClient );
static BaseType_t prvProcessCmd( HTTPClient_t * pxClient,
BaseType_t xIndex );
static const char * pcGetContentsType( const char * apFname );
static BaseType_t prvOpenURL( HTTPClient_t * pxClient );
static BaseType_t prvSendFile( HTTPClient_t * pxClient );
static BaseType_t prvSendReply( HTTPClient_t * pxClient,
BaseType_t xCode );
static const char pcEmptyString[ 1 ] = { '\0' };
typedef struct xTYPE_COUPLE
{
const char * pcExtension;
const char * pcType;
} TypeCouple_t;
static TypeCouple_t pxTypeCouples[] =
{
{ "html", "text/html" },
{ "css", "text/css" },
{ "js", "text/javascript" },
{ "png", "image/png" },
{ "jpg", "image/jpeg" },
{ "gif", "image/gif" },
{ "txt", "text/plain" },
{ "mp3", "audio/mpeg3" },
{ "wav", "audio/wav" },
{ "flac", "audio/ogg" },
{ "pdf", "application/pdf" },
{ "ttf", "application/x-font-ttf" },
{ "ttc", "application/x-font-ttf" }
};
void vHTTPClientDelete( TCPClient_t * pxTCPClient )
{
HTTPClient_t * pxClient = ( HTTPClient_t * ) pxTCPClient;
/* This HTTP client stops, close / release all resources. */
if( pxClient->xSocket != FREERTOS_NO_SOCKET )
{
FreeRTOS_FD_CLR( pxClient->xSocket, pxClient->pxParent->xSocketSet, eSELECT_ALL );
FreeRTOS_closesocket( pxClient->xSocket );
pxClient->xSocket = FREERTOS_NO_SOCKET;
}
prvFileClose( pxClient );
}
/*-----------------------------------------------------------*/
static void prvFileClose( HTTPClient_t * pxClient )
{
if( pxClient->pxFileHandle != NULL )
{
FreeRTOS_printf( ( "Closing file: %s\n", pxClient->pcCurrentFilename ) );
ff_fclose( pxClient->pxFileHandle );
pxClient->pxFileHandle = NULL;
}
}
/*-----------------------------------------------------------*/
static BaseType_t prvSendReply( HTTPClient_t * pxClient,
BaseType_t xCode )
{
struct xTCP_SERVER * pxParent = pxClient->pxParent;
BaseType_t xRc;
/* A normal command reply on the main socket (port 21). */
char * pcBuffer = pxParent->pcFileBuffer;
xRc = snprintf( pcBuffer, sizeof( pxParent->pcFileBuffer ),
"HTTP/1.1 %d %s\r\n"
#if USE_HTML_CHUNKS
"Transfer-Encoding: chunked\r\n"
#endif
"Content-Type: %s\r\n"
"Connection: keep-alive\r\n"
"%s\r\n",
( int ) xCode,
webCodename( xCode ),
pxParent->pcContentsType[ 0 ] ? pxParent->pcContentsType : "text/html",
pxParent->pcExtraContents );
pxParent->pcContentsType[ 0 ] = '\0';
pxParent->pcExtraContents[ 0 ] = '\0';
xRc = FreeRTOS_send( pxClient->xSocket, ( const void * ) pcBuffer, xRc, 0 );
pxClient->bits.bReplySent = pdTRUE_UNSIGNED;
return xRc;
}
/*-----------------------------------------------------------*/
static BaseType_t prvSendFile( HTTPClient_t * pxClient )
{
size_t uxSpace;
size_t uxCount;
BaseType_t xRc = 0;
if( pxClient->bits.bReplySent == pdFALSE_UNSIGNED )
{
pxClient->bits.bReplySent = pdTRUE_UNSIGNED;
strcpy( pxClient->pxParent->pcContentsType, pcGetContentsType( pxClient->pcCurrentFilename ) );
snprintf( pxClient->pxParent->pcExtraContents, sizeof( pxClient->pxParent->pcExtraContents ),
"Content-Length: %d\r\n", ( int ) pxClient->uxBytesLeft );
/* "Requested file action OK". */
xRc = prvSendReply( pxClient, WEB_REPLY_OK );
}
if( xRc >= 0 )
{
do
{
uxSpace = FreeRTOS_tx_space( pxClient->xSocket );
if( pxClient->uxBytesLeft < uxSpace )
{
uxCount = pxClient->uxBytesLeft;
}
else
{
uxCount = uxSpace;
}
if( uxCount > 0u )
{
if( uxCount > sizeof( pxClient->pxParent->pcFileBuffer ) )
{
uxCount = sizeof( pxClient->pxParent->pcFileBuffer );
}
ff_fread( pxClient->pxParent->pcFileBuffer, 1, uxCount, pxClient->pxFileHandle );
pxClient->uxBytesLeft -= uxCount;
xRc = FreeRTOS_send( pxClient->xSocket, pxClient->pxParent->pcFileBuffer, uxCount, 0 );
if( xRc < 0 )
{
break;
}
}
} while( uxCount > 0u );
}
if( pxClient->uxBytesLeft == 0u )
{
/* Writing is ready, no need for further 'eSELECT_WRITE' events. */
FreeRTOS_FD_CLR( pxClient->xSocket, pxClient->pxParent->xSocketSet, eSELECT_WRITE );
prvFileClose( pxClient );
}
else
{
/* Wake up the TCP task as soon as this socket may be written to. */
FreeRTOS_FD_SET( pxClient->xSocket, pxClient->pxParent->xSocketSet, eSELECT_WRITE );
}
return xRc;
}
/*-----------------------------------------------------------*/
static BaseType_t prvOpenURL( HTTPClient_t * pxClient )
{
BaseType_t xRc;
char pcSlash[ 2 ];
pxClient->bits.ulFlags = 0;
#if ( ipconfigHTTP_HAS_HANDLE_REQUEST_HOOK != 0 )
{
if( strchr( pxClient->pcUrlData, ipconfigHTTP_REQUEST_CHARACTER ) != NULL )
{
size_t xResult;
xResult = uxApplicationHTTPHandleRequestHook( pxClient->pcUrlData, pxClient->pcCurrentFilename, sizeof( pxClient->pcCurrentFilename ) );
if( xResult > 0 )
{
strcpy( pxClient->pxParent->pcContentsType, "text/html" );
snprintf( pxClient->pxParent->pcExtraContents, sizeof( pxClient->pxParent->pcExtraContents ),
"Content-Length: %d\r\n", ( int ) xResult );
xRc = prvSendReply( pxClient, WEB_REPLY_OK ); /* "Requested file action OK" */
if( xRc > 0 )
{
xRc = FreeRTOS_send( pxClient->xSocket, pxClient->pcCurrentFilename, xResult, 0 );
}
/* Although against the coding standard of FreeRTOS, a return is
* done here to simplify this conditional code. */
return xRc;
}
}
}
#endif /* ipconfigHTTP_HAS_HANDLE_REQUEST_HOOK */
if( pxClient->pcUrlData[ 0 ] != '/' )
{
/* Insert a slash before the file name. */
pcSlash[ 0 ] = '/';
pcSlash[ 1 ] = '\0';
}
else
{
/* The browser provided a starting '/' already. */
pcSlash[ 0 ] = '\0';
}
snprintf( pxClient->pcCurrentFilename, sizeof( pxClient->pcCurrentFilename ), "%s%s%s",
pxClient->pcRootDir,
pcSlash,
pxClient->pcUrlData );
pxClient->pxFileHandle = ff_fopen( pxClient->pcCurrentFilename, "rb" );
FreeRTOS_printf( ( "Open file '%s': %s\n", pxClient->pcCurrentFilename,
pxClient->pxFileHandle != NULL ? "Ok" : strerror( stdioGET_ERRNO() ) ) );
if( pxClient->pxFileHandle == NULL )
{
/* "404 File not found". */
xRc = prvSendReply( pxClient, WEB_NOT_FOUND );
}
else
{
pxClient->uxBytesLeft = ( size_t ) pxClient->pxFileHandle->ulFileSize;
xRc = prvSendFile( pxClient );
}
return xRc;
}
/*-----------------------------------------------------------*/
static BaseType_t prvProcessCmd( HTTPClient_t * pxClient,
BaseType_t xIndex )
{
BaseType_t xResult = 0;
/* A new command has been received. Process it. */
switch( xIndex )
{
case ECMD_GET:
xResult = prvOpenURL( pxClient );
break;
case ECMD_HEAD:
case ECMD_POST:
case ECMD_PUT:
case ECMD_DELETE:
case ECMD_TRACE:
case ECMD_OPTIONS:
case ECMD_CONNECT:
case ECMD_PATCH:
case ECMD_UNK:
FreeRTOS_printf( ( "prvProcessCmd: Not implemented: %s\n",
xWebCommands[ xIndex ].pcCommandName ) );
break;
}
return xResult;
}
/*-----------------------------------------------------------*/
BaseType_t xHTTPClientWork( TCPClient_t * pxTCPClient )
{
BaseType_t xRc;
HTTPClient_t * pxClient = ( HTTPClient_t * ) pxTCPClient;
if( pxClient->pxFileHandle != NULL )
{
prvSendFile( pxClient );
}
xRc = FreeRTOS_recv( pxClient->xSocket, ( void * ) pcCOMMAND_BUFFER, sizeof( pcCOMMAND_BUFFER ), 0 );
if( xRc > 0 )
{
BaseType_t xIndex;
const char * pcEndOfCmd;
const struct xWEB_COMMAND * curCmd;
char * pcBuffer = pcCOMMAND_BUFFER;
if( xRc < ( BaseType_t ) sizeof( pcCOMMAND_BUFFER ) )
{
pcBuffer[ xRc ] = '\0';
}
while( xRc && ( pcBuffer[ xRc - 1 ] == 13 || pcBuffer[ xRc - 1 ] == 10 ) )
{
pcBuffer[ --xRc ] = '\0';
}
pcEndOfCmd = pcBuffer + xRc;
curCmd = xWebCommands;
/* Pointing to "/index.html HTTP/1.1". */
pxClient->pcUrlData = pcBuffer;
/* Pointing to "HTTP/1.1". */
pxClient->pcRestData = pcEmptyString;
/* Last entry is "ECMD_UNK". */
for( xIndex = 0; xIndex < WEB_CMD_COUNT - 1; xIndex++, curCmd++ )
{
BaseType_t xLength;
xLength = curCmd->xCommandLength;
if( ( xRc >= xLength ) && ( memcmp( curCmd->pcCommandName, pcBuffer, xLength ) == 0 ) )
{
char * pcLastPtr;
pxClient->pcUrlData += xLength + 1;
for( pcLastPtr = ( char * ) pxClient->pcUrlData; pcLastPtr < pcEndOfCmd; pcLastPtr++ )
{
char ch = *pcLastPtr;
if( ( ch == '\0' ) || ( strchr( "\n\r \t", ch ) != NULL ) )
{
*pcLastPtr = '\0';
pxClient->pcRestData = pcLastPtr + 1;
break;
}
}
break;
}
}
if( xIndex < ( WEB_CMD_COUNT - 1 ) )
{
xRc = prvProcessCmd( pxClient, xIndex );
}
}
else if( xRc < 0 )
{
/* The connection will be closed and the client will be deleted. */
FreeRTOS_printf( ( "xHTTPClientWork: rc = %ld\n", xRc ) );
}
return xRc;
}
/*-----------------------------------------------------------*/
static const char * pcGetContentsType( const char * apFname )
{
const char * slash = NULL;
const char * dot = NULL;
const char * ptr;
const char * pcResult = "text/html";
BaseType_t x;
for( ptr = apFname; *ptr; ptr++ )
{
if( *ptr == '.' )
{
dot = ptr;
}
if( *ptr == '/' )
{
slash = ptr;
}
}
if( dot > slash )
{
dot++;
for( x = 0; x < ARRAY_SIZE( pxTypeCouples ); x++ )
{
if( strcasecmp( dot, pxTypeCouples[ x ].pcExtension ) == 0 )
{
pcResult = pxTypeCouples[ x ].pcType;
break;
}
}
}
return pcResult;
}
#endif /* ipconfigUSE_HTTP */

@ -1,469 +1,498 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
/*
*!
*! The protocols implemented in this file are intended to be demo quality only,
*! and not for production devices.
*!
*
* NTPDemo.c
*
* An example of how to lookup a domain using DNS
* And also how to send and receive UDP messages to get the NTP time
*
*/
/* Standard includes. */
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_Sockets.h"
#include "FreeRTOS_DNS.h"
#include "FreeRTOS_Stream_Buffer.h"
/* Use the date & time functions from +FAT. */
#include "ff_time.h"
#include "NTPDemo.h"
#include "ntpClient.h"
#include "date_and_time.h"
enum EStatus {
EStatusLookup,
EStatusAsking,
EStatusPause,
EStatusFailed,
};
static struct SNtpPacket xNTPPacket;
#if( ipconfigUSE_CALLBACKS == 0 )
static char cRecvBuffer[ sizeof( struct SNtpPacket ) + 64 ];
#endif
static enum EStatus xStatus = EStatusLookup;
static const char *pcTimeServers[] = {
"0.asia.pool.ntp.org",
"0.europe.pool.ntp.org",
"0.id.pool.ntp.org",
"0.south-america.pool.ntp.org",
"0.oceania.pool.ntp.org",
"0.north-america.pool.ntp.org"
};
static SemaphoreHandle_t xNTPWakeupSem = NULL;
static uint32_t ulIPAddressFound;
static Socket_t xUDPSocket = NULL;
static TaskHandle_t xNTPTaskhandle = NULL;
static TickType_t uxSendTime;
static void prvNTPTask( void *pvParameters );
static void vSignalTask( void )
{
#if( ipconfigUSE_CALLBACKS == 0 )
if( xUDPSocket != NULL )
{
/* Send a signal to the socket so that the
FreeRTOS_recvfrom will get interrupted. */
FreeRTOS_SignalSocket( xUDPSocket );
}
else
#endif
if( xNTPWakeupSem != NULL )
{
xSemaphoreGive( xNTPWakeupSem );
}
}
void vStartNTPTask( uint16_t usTaskStackSize, UBaseType_t uxTaskPriority )
{
/* The only public function in this module: start a task to contact
some NTP server. */
if( xNTPTaskhandle != NULL )
{
switch( xStatus )
{
case EStatusPause:
xStatus = EStatusAsking;
vSignalTask();
break;
case EStatusLookup:
FreeRTOS_printf( ( "NTP looking up server\n" ) );
break;
case EStatusAsking:
FreeRTOS_printf( ( "NTP still asking\n" ) );
break;
case EStatusFailed:
FreeRTOS_printf( ( "NTP failed somehow\n" ) );
ulIPAddressFound = 0ul;
xStatus = EStatusLookup;
vSignalTask();
break;
}
}
else
{
xUDPSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP );
if( xUDPSocket != FREERTOS_INVALID_SOCKET )
{
struct freertos_sockaddr xAddress;
#if( ipconfigUSE_CALLBACKS != 0 )
BaseType_t xReceiveTimeOut = pdMS_TO_TICKS( 0 );
#else
BaseType_t xReceiveTimeOut = pdMS_TO_TICKS( 5000 );
#endif
#if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 )
{
xAddress.sin_address.ulIP_IPv4 = 0ul;
}
#else
{
xAddress.sin_addr = 0ul;
}
#endif /* defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 ) */
xAddress.sin_port = FreeRTOS_htons( NTP_PORT );
xAddress.sin_family = FREERTOS_AF_INET;
FreeRTOS_bind( xUDPSocket, &xAddress, sizeof( xAddress ) );
FreeRTOS_setsockopt( xUDPSocket, 0, FREERTOS_SO_RCVTIMEO, &xReceiveTimeOut, sizeof( xReceiveTimeOut ) );
xTaskCreate( prvNTPTask, /* The function that implements the task. */
( const char * ) "NTP client", /* Just a text name for the task to aid debugging. */
usTaskStackSize, /* The stack size is defined in FreeRTOSIPConfig.h. */
NULL, /* The task parameter, not used in this case. */
uxTaskPriority, /* The priority assigned to the task is defined in FreeRTOSConfig.h. */
&xNTPTaskhandle ); /* The task handle. */
}
else
{
FreeRTOS_printf( ( "Creating socket failed\n" ) );
}
}
}
/*-----------------------------------------------------------*/
static void vDNS_callback( const char *pcName, void *pvSearchID, uint32_t ulIPAddress )
{
char pcBuf[16];
/* The DNS lookup has a result, or it has reached the time-out. */
FreeRTOS_inet_ntoa( ulIPAddress, pcBuf );
FreeRTOS_printf( ( "IP address of %s found: %s\n", pcName, pcBuf ) );
if( ulIPAddressFound == 0ul )
{
ulIPAddressFound = ulIPAddress;
}
/* For testing: in case DNS doen't respond, still try some NTP server
with a known IP-address. */
if( ulIPAddressFound == 0ul )
{
ulIPAddressFound = FreeRTOS_inet_addr_quick( 184, 105, 182, 7 );
/* ulIPAddressFound = FreeRTOS_inet_addr_quick( 103, 242, 70, 4 ); */
}
xStatus = EStatusAsking;
vSignalTask();
}
/*-----------------------------------------------------------*/
static void prvSwapFields( struct SNtpPacket *pxPacket)
{
/* NTP messages are big-endian */
pxPacket->rootDelay = FreeRTOS_htonl( pxPacket->rootDelay );
pxPacket->rootDispersion = FreeRTOS_htonl( pxPacket->rootDispersion );
pxPacket->referenceTimestamp.seconds = FreeRTOS_htonl( pxPacket->referenceTimestamp.seconds );
pxPacket->referenceTimestamp.fraction = FreeRTOS_htonl( pxPacket->referenceTimestamp.fraction );
pxPacket->originateTimestamp.seconds = FreeRTOS_htonl( pxPacket->originateTimestamp.seconds );
pxPacket->originateTimestamp.fraction = FreeRTOS_htonl( pxPacket->originateTimestamp.fraction );
pxPacket->receiveTimestamp.seconds = FreeRTOS_htonl( pxPacket->receiveTimestamp.seconds );
pxPacket->receiveTimestamp.fraction = FreeRTOS_htonl( pxPacket->receiveTimestamp.fraction );
pxPacket->transmitTimestamp.seconds = FreeRTOS_htonl( pxPacket->transmitTimestamp.seconds );
pxPacket->transmitTimestamp.fraction = FreeRTOS_htonl( pxPacket->transmitTimestamp.fraction );
}
/*-----------------------------------------------------------*/
static void prvNTPPacketInit( )
{
memset (&xNTPPacket, '\0', sizeof( xNTPPacket ) );
xNTPPacket.flags = 0xDB; /* value 0xDB : mode 3 (client), version 3, leap indicator unknown 3 */
xNTPPacket.poll = 10; /* 10 means 1 << 10 = 1024 seconds */
xNTPPacket.precision = 0xFA; /* = 250 = 0.015625 seconds */
xNTPPacket.rootDelay = 0x5D2E; /* 0x5D2E = 23854 or (23854/65535)= 0.3640 sec */
xNTPPacket.rootDispersion = 0x0008CAC8; /* 0x0008CAC8 = 8.7912 seconds */
/* use the recorded NTP time */
time_t uxSecs = FreeRTOS_time( NULL );/* apTime may be NULL, returns seconds */
xNTPPacket.referenceTimestamp.seconds = uxSecs; /* Current time */
xNTPPacket.transmitTimestamp.seconds = uxSecs + 3;
/* Transform the contents of the fields from native to big endian. */
prvSwapFields( &xNTPPacket );
}
/*-----------------------------------------------------------*/
static void prvReadTime( struct SNtpPacket * pxPacket )
{
FF_TimeStruct_t xTimeStruct;
time_t uxPreviousSeconds;
time_t uxPreviousMS;
time_t uxCurrentSeconds;
time_t uxCurrentMS;
const char *pcTimeUnit;
int32_t ilDiff;
TickType_t uxTravelTime;
uxTravelTime = xTaskGetTickCount() - uxSendTime;
/* Transform the contents of the fields from big to native endian. */
prvSwapFields( pxPacket );
uxCurrentSeconds = pxPacket->receiveTimestamp.seconds - TIME1970;
uxCurrentMS = pxPacket->receiveTimestamp.fraction / 4294967;
uxCurrentSeconds += uxCurrentMS / 1000;
uxCurrentMS = uxCurrentMS % 1000;
// Get the last time recorded
uxPreviousSeconds = FreeRTOS_get_secs_msec( &uxPreviousMS );
// Set the new time with precision in msec. */
FreeRTOS_set_secs_msec( &uxCurrentSeconds, &uxCurrentMS );
if( uxCurrentSeconds >= uxPreviousSeconds )
{
ilDiff = ( int32_t ) ( uxCurrentSeconds - uxPreviousSeconds );
}
else
{
ilDiff = 0 - ( int32_t ) ( uxPreviousSeconds - uxCurrentSeconds );
}
if( ( ilDiff < -5 ) || ( ilDiff > 5 ) )
{
/* More than 5 seconds difference. */
pcTimeUnit = "sec";
}
else
{
/* Less than or equal to 5 second difference. */
pcTimeUnit = "ms";
uint32_t ulLowest = ( uxCurrentSeconds <= uxPreviousSeconds ) ? uxCurrentSeconds : uxPreviousSeconds;
int32_t iCurMS = 1000 * ( uxCurrentSeconds - ulLowest ) + uxCurrentMS;
int32_t iPrevMS = 1000 * ( uxPreviousSeconds - ulLowest ) + uxPreviousMS;
ilDiff = iCurMS - iPrevMS;
}
uxCurrentSeconds -= iTimeZone;
FreeRTOS_gmtime_r( &uxCurrentSeconds, &xTimeStruct );
/*
378.067 [NTP client] NTP time: 9/11/2015 16:11:19.559 Diff -20 ms (289 ms)
379.441 [NTP client] NTP time: 9/11/2015 16:11:20.933 Diff 0 ms (263 ms)
*/
FreeRTOS_printf( ("NTP time: %d/%d/%02d %2d:%02d:%02d.%03u Diff %d %s (%lu ms)\n",
xTimeStruct.tm_mday,
xTimeStruct.tm_mon + 1,
xTimeStruct.tm_year + 1900,
xTimeStruct.tm_hour,
xTimeStruct.tm_min,
xTimeStruct.tm_sec,
( unsigned )uxCurrentMS,
( unsigned )ilDiff,
pcTimeUnit,
uxTravelTime ) );
/* Remove compiler warnings in case FreeRTOS_printf() is not used. */
( void ) pcTimeUnit;
( void ) uxTravelTime;
}
/*-----------------------------------------------------------*/
#if( ipconfigUSE_CALLBACKS != 0 )
static BaseType_t xOnUDPReceive( Socket_t xSocket, void * pvData, size_t xLength,
const struct freertos_sockaddr *pxFrom, const struct freertos_sockaddr *pxDest )
{
if( xLength >= sizeof( xNTPPacket ) )
{
prvReadTime( ( struct SNtpPacket *)pvData );
if( xStatus != EStatusPause )
{
xStatus = EStatusPause;
}
}
vSignalTask();
/* Tell the driver not to store the RX data */
return 1;
}
/*-----------------------------------------------------------*/
#endif /* ipconfigUSE_CALLBACKS != 0 */
static void prvNTPTask( void *pvParameters )
{
BaseType_t xServerIndex = 3;
struct freertos_sockaddr xAddress;
#if( ipconfigUSE_CALLBACKS != 0 )
F_TCP_UDP_Handler_t xHandler;
#endif /* ipconfigUSE_CALLBACKS != 0 */
xStatus = EStatusLookup;
#if( ipconfigSOCKET_HAS_USER_SEMAPHORE != 0 ) || ( ipconfigUSE_CALLBACKS != 0 )
{
xNTPWakeupSem = xSemaphoreCreateBinary();
}
#endif
#if( ipconfigUSE_CALLBACKS != 0 )
{
memset( &xHandler, '\0', sizeof( xHandler ) );
xHandler.pxOnUDPReceive = xOnUDPReceive;
FreeRTOS_setsockopt( xUDPSocket, 0, FREERTOS_SO_UDP_RECV_HANDLER, ( void * ) &xHandler, sizeof( xHandler ) );
}
#endif
#if( ipconfigSOCKET_HAS_USER_SEMAPHORE != 0 )
{
FreeRTOS_setsockopt( xUDPSocket, 0, FREERTOS_SO_SET_SEMAPHORE, ( void * ) &xNTPWakeupSem, sizeof( xNTPWakeupSem ) );
}
#endif
for( ; ; )
{
switch( xStatus )
{
case EStatusLookup:
if( ( ulIPAddressFound == 0ul ) || ( ulIPAddressFound == ~0ul ) )
{
if( ++xServerIndex == sizeof( pcTimeServers ) / sizeof( pcTimeServers[ 0 ] ) )
{
xServerIndex = 0;
}
FreeRTOS_printf( ( "Looking up server '%s'\n", pcTimeServers[ xServerIndex ] ) );
FreeRTOS_gethostbyname_a( pcTimeServers[ xServerIndex ], vDNS_callback, (void *)NULL, 1200 );
}
else
{
xStatus = EStatusAsking;
}
break;
case EStatusAsking:
{
char pcBuf[16];
prvNTPPacketInit( );
#if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 )
{
xAddress.sin_address.ulIP_IPv4 = ulIPAddressFound;
xAddress.sin_port = FreeRTOS_htons( NTP_PORT );
FreeRTOS_inet_ntoa( xAddress.sin_address.ulIP_IPv4, pcBuf );
}
#else
{
xAddress.sin_addr = ulIPAddressFound;
xAddress.sin_port = FreeRTOS_htons( NTP_PORT );
FreeRTOS_inet_ntoa( xAddress.sin_addr, pcBuf );
}
#endif /* defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 ) */
xAddress.sin_family = FREERTOS_AF_INET;
FreeRTOS_printf( ( "Sending UDP message to %s:%u\n",
pcBuf,
FreeRTOS_ntohs( xAddress.sin_port ) ) );
uxSendTime = xTaskGetTickCount( );
FreeRTOS_sendto( xUDPSocket, ( void * )&xNTPPacket, sizeof( xNTPPacket ), 0, &xAddress, sizeof( xAddress ) );
}
break;
case EStatusPause:
break;
case EStatusFailed:
break;
}
#if( ipconfigUSE_CALLBACKS != 0 )
{
xSemaphoreTake( xNTPWakeupSem, 5000 );
}
#else
{
uint32_t xAddressSize;
BaseType_t xReturned;
xAddressSize = sizeof( xAddress );
xReturned = FreeRTOS_recvfrom( xUDPSocket, ( void * ) cRecvBuffer, sizeof( cRecvBuffer ), 0, &xAddress, &xAddressSize );
switch( xReturned )
{
case 0:
case -pdFREERTOS_ERRNO_EAGAIN:
case -pdFREERTOS_ERRNO_EINTR:
break;
default:
if( xReturned < sizeof( xNTPPacket ) )
{
FreeRTOS_printf( ( "FreeRTOS_recvfrom: returns %ld\n", xReturned ) );
}
else
{
prvReadTime( ( struct SNtpPacket *)cRecvBuffer );
if( xStatus != EStatusPause )
{
xStatus = EStatusPause;
}
}
break;
}
}
#endif
}
}
/*-----------------------------------------------------------*/
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
/*
*!
*! The protocols implemented in this file are intended to be demo quality only,
*! and not for production devices.
*!
*
* NTPDemo.c
*
* An example of how to lookup a domain using DNS
* And also how to send and receive UDP messages to get the NTP time
*
*/
/* Standard includes. */
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"
/* FreeRTOS+TCP includes. */
#include "FreeRTOS_IP.h"
#include "FreeRTOS_Sockets.h"
#include "FreeRTOS_DNS.h"
#include "FreeRTOS_Stream_Buffer.h"
/* Use the date & time functions from +FAT. */
#include "ff_time.h"
#include "NTPDemo.h"
#include "ntpClient.h"
#include "date_and_time.h"
enum EStatus
{
EStatusLookup,
EStatusAsking,
EStatusPause,
EStatusFailed,
};
static struct SNtpPacket xNTPPacket;
#if ( ipconfigUSE_CALLBACKS == 0 )
static char cRecvBuffer[ sizeof( struct SNtpPacket ) + 64 ];
#endif
static enum EStatus xStatus = EStatusLookup;
static const char * pcTimeServers[] =
{
"0.asia.pool.ntp.org",
"0.europe.pool.ntp.org",
"0.id.pool.ntp.org",
"0.south-america.pool.ntp.org",
"0.oceania.pool.ntp.org",
"0.north-america.pool.ntp.org"
};
static SemaphoreHandle_t xNTPWakeupSem = NULL;
static uint32_t ulIPAddressFound;
static Socket_t xUDPSocket = NULL;
static TaskHandle_t xNTPTaskhandle = NULL;
static TickType_t uxSendTime;
static void prvNTPTask( void * pvParameters );
static void vSignalTask( void )
{
#if ( ipconfigUSE_CALLBACKS == 0 )
if( xUDPSocket != NULL )
{
/* Send a signal to the socket so that the
* FreeRTOS_recvfrom will get interrupted. */
FreeRTOS_SignalSocket( xUDPSocket );
}
else
#endif
if( xNTPWakeupSem != NULL )
{
xSemaphoreGive( xNTPWakeupSem );
}
}
void vStartNTPTask( uint16_t usTaskStackSize,
UBaseType_t uxTaskPriority )
{
/* The only public function in this module: start a task to contact
* some NTP server. */
if( xNTPTaskhandle != NULL )
{
switch( xStatus )
{
case EStatusPause:
xStatus = EStatusAsking;
vSignalTask();
break;
case EStatusLookup:
FreeRTOS_printf( ( "NTP looking up server\n" ) );
break;
case EStatusAsking:
FreeRTOS_printf( ( "NTP still asking\n" ) );
break;
case EStatusFailed:
FreeRTOS_printf( ( "NTP failed somehow\n" ) );
ulIPAddressFound = 0ul;
xStatus = EStatusLookup;
vSignalTask();
break;
}
}
else
{
xUDPSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_DGRAM, FREERTOS_IPPROTO_UDP );
if( xUDPSocket != FREERTOS_INVALID_SOCKET )
{
struct freertos_sockaddr xAddress;
#if ( ipconfigUSE_CALLBACKS != 0 )
BaseType_t xReceiveTimeOut = pdMS_TO_TICKS( 0 );
#else
BaseType_t xReceiveTimeOut = pdMS_TO_TICKS( 5000 );
#endif
#if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 )
{
xAddress.sin_address.ulIP_IPv4 = 0ul;
}
#else
{
xAddress.sin_addr = 0ul;
}
#endif /* defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 ) */
xAddress.sin_port = FreeRTOS_htons( NTP_PORT );
xAddress.sin_family = FREERTOS_AF_INET;
FreeRTOS_bind( xUDPSocket, &xAddress, sizeof( xAddress ) );
FreeRTOS_setsockopt( xUDPSocket, 0, FREERTOS_SO_RCVTIMEO, &xReceiveTimeOut, sizeof( xReceiveTimeOut ) );
xTaskCreate( prvNTPTask, /* The function that implements the task. */
( const char * ) "NTP client", /* Just a text name for the task to aid debugging. */
usTaskStackSize, /* The stack size is defined in FreeRTOSIPConfig.h. */
NULL, /* The task parameter, not used in this case. */
uxTaskPriority, /* The priority assigned to the task is defined in FreeRTOSConfig.h. */
&xNTPTaskhandle ); /* The task handle. */
}
else
{
FreeRTOS_printf( ( "Creating socket failed\n" ) );
}
}
}
/*-----------------------------------------------------------*/
static void vDNS_callback( const char * pcName,
void * pvSearchID,
uint32_t ulIPAddress )
{
char pcBuf[ 16 ];
/* The DNS lookup has a result, or it has reached the time-out. */
FreeRTOS_inet_ntoa( ulIPAddress, pcBuf );
FreeRTOS_printf( ( "IP address of %s found: %s\n", pcName, pcBuf ) );
if( ulIPAddressFound == 0ul )
{
ulIPAddressFound = ulIPAddress;
}
/* For testing: in case DNS doesn't respond, still try some NTP server
* with a known IP-address. */
if( ulIPAddressFound == 0ul )
{
ulIPAddressFound = FreeRTOS_inet_addr_quick( 184, 105, 182, 7 );
/* ulIPAddressFound = FreeRTOS_inet_addr_quick( 103, 242, 70, 4 ); */
}
xStatus = EStatusAsking;
vSignalTask();
}
/*-----------------------------------------------------------*/
static void prvSwapFields( struct SNtpPacket * pxPacket )
{
/* NTP messages are big-endian */
pxPacket->rootDelay = FreeRTOS_htonl( pxPacket->rootDelay );
pxPacket->rootDispersion = FreeRTOS_htonl( pxPacket->rootDispersion );
pxPacket->referenceTimestamp.seconds = FreeRTOS_htonl( pxPacket->referenceTimestamp.seconds );
pxPacket->referenceTimestamp.fraction = FreeRTOS_htonl( pxPacket->referenceTimestamp.fraction );
pxPacket->originateTimestamp.seconds = FreeRTOS_htonl( pxPacket->originateTimestamp.seconds );
pxPacket->originateTimestamp.fraction = FreeRTOS_htonl( pxPacket->originateTimestamp.fraction );
pxPacket->receiveTimestamp.seconds = FreeRTOS_htonl( pxPacket->receiveTimestamp.seconds );
pxPacket->receiveTimestamp.fraction = FreeRTOS_htonl( pxPacket->receiveTimestamp.fraction );
pxPacket->transmitTimestamp.seconds = FreeRTOS_htonl( pxPacket->transmitTimestamp.seconds );
pxPacket->transmitTimestamp.fraction = FreeRTOS_htonl( pxPacket->transmitTimestamp.fraction );
}
/*-----------------------------------------------------------*/
static void prvNTPPacketInit()
{
memset( &xNTPPacket, '\0', sizeof( xNTPPacket ) );
xNTPPacket.flags = 0xDB; /* value 0xDB : mode 3 (client), version 3, leap indicator unknown 3 */
xNTPPacket.poll = 10; /* 10 means 1 << 10 = 1024 seconds */
xNTPPacket.precision = 0xFA; /* = 250 = 0.015625 seconds */
xNTPPacket.rootDelay = 0x5D2E; /* 0x5D2E = 23854 or (23854/65535)= 0.3640 sec */
xNTPPacket.rootDispersion = 0x0008CAC8; /* 0x0008CAC8 = 8.7912 seconds */
/* use the recorded NTP time */
time_t uxSecs = FreeRTOS_time( NULL ); /* apTime may be NULL, returns seconds */
xNTPPacket.referenceTimestamp.seconds = uxSecs; /* Current time */
xNTPPacket.transmitTimestamp.seconds = uxSecs + 3;
/* Transform the contents of the fields from native to big endian. */
prvSwapFields( &xNTPPacket );
}
/*-----------------------------------------------------------*/
static void prvReadTime( struct SNtpPacket * pxPacket )
{
FF_TimeStruct_t xTimeStruct;
time_t uxPreviousSeconds;
time_t uxPreviousMS;
time_t uxCurrentSeconds;
time_t uxCurrentMS;
const char * pcTimeUnit;
int32_t ilDiff;
TickType_t uxTravelTime;
uxTravelTime = xTaskGetTickCount() - uxSendTime;
/* Transform the contents of the fields from big to native endian. */
prvSwapFields( pxPacket );
uxCurrentSeconds = pxPacket->receiveTimestamp.seconds - TIME1970;
uxCurrentMS = pxPacket->receiveTimestamp.fraction / 4294967;
uxCurrentSeconds += uxCurrentMS / 1000;
uxCurrentMS = uxCurrentMS % 1000;
/* Get the last time recorded */
uxPreviousSeconds = FreeRTOS_get_secs_msec( &uxPreviousMS );
/* Set the new time with precision in msec. * / */
FreeRTOS_set_secs_msec( &uxCurrentSeconds, &uxCurrentMS );
if( uxCurrentSeconds >= uxPreviousSeconds )
{
ilDiff = ( int32_t ) ( uxCurrentSeconds - uxPreviousSeconds );
}
else
{
ilDiff = 0 - ( int32_t ) ( uxPreviousSeconds - uxCurrentSeconds );
}
if( ( ilDiff < -5 ) || ( ilDiff > 5 ) )
{
/* More than 5 seconds difference. */
pcTimeUnit = "sec";
}
else
{
/* Less than or equal to 5 second difference. */
pcTimeUnit = "ms";
uint32_t ulLowest = ( uxCurrentSeconds <= uxPreviousSeconds ) ? uxCurrentSeconds : uxPreviousSeconds;
int32_t iCurMS = 1000 * ( uxCurrentSeconds - ulLowest ) + uxCurrentMS;
int32_t iPrevMS = 1000 * ( uxPreviousSeconds - ulLowest ) + uxPreviousMS;
ilDiff = iCurMS - iPrevMS;
}
uxCurrentSeconds -= iTimeZone;
FreeRTOS_gmtime_r( &uxCurrentSeconds, &xTimeStruct );
/*
* 378.067 [NTP client] NTP time: 9/11/2015 16:11:19.559 Diff -20 ms (289 ms)
* 379.441 [NTP client] NTP time: 9/11/2015 16:11:20.933 Diff 0 ms (263 ms)
*/
FreeRTOS_printf( ( "NTP time: %d/%d/%02d %2d:%02d:%02d.%03u Diff %d %s (%lu ms)\n",
xTimeStruct.tm_mday,
xTimeStruct.tm_mon + 1,
xTimeStruct.tm_year + 1900,
xTimeStruct.tm_hour,
xTimeStruct.tm_min,
xTimeStruct.tm_sec,
( unsigned ) uxCurrentMS,
( unsigned ) ilDiff,
pcTimeUnit,
uxTravelTime ) );
/* Remove compiler warnings in case FreeRTOS_printf() is not used. */
( void ) pcTimeUnit;
( void ) uxTravelTime;
}
/*-----------------------------------------------------------*/
#if ( ipconfigUSE_CALLBACKS != 0 )
static BaseType_t xOnUDPReceive( Socket_t xSocket,
void * pvData,
size_t xLength,
const struct freertos_sockaddr * pxFrom,
const struct freertos_sockaddr * pxDest )
{
if( xLength >= sizeof( xNTPPacket ) )
{
prvReadTime( ( struct SNtpPacket * ) pvData );
if( xStatus != EStatusPause )
{
xStatus = EStatusPause;
}
}
vSignalTask();
/* Tell the driver not to store the RX data */
return 1;
}
/*-----------------------------------------------------------*/
#endif /* ipconfigUSE_CALLBACKS != 0 */
static void prvNTPTask( void * pvParameters )
{
BaseType_t xServerIndex = 3;
struct freertos_sockaddr xAddress;
#if ( ipconfigUSE_CALLBACKS != 0 )
F_TCP_UDP_Handler_t xHandler;
#endif /* ipconfigUSE_CALLBACKS != 0 */
xStatus = EStatusLookup;
#if ( ipconfigSOCKET_HAS_USER_SEMAPHORE != 0 ) || ( ipconfigUSE_CALLBACKS != 0 )
{
xNTPWakeupSem = xSemaphoreCreateBinary();
}
#endif
#if ( ipconfigUSE_CALLBACKS != 0 )
{
memset( &xHandler, '\0', sizeof( xHandler ) );
xHandler.pxOnUDPReceive = xOnUDPReceive;
FreeRTOS_setsockopt( xUDPSocket, 0, FREERTOS_SO_UDP_RECV_HANDLER, ( void * ) &xHandler, sizeof( xHandler ) );
}
#endif
#if ( ipconfigSOCKET_HAS_USER_SEMAPHORE != 0 )
{
FreeRTOS_setsockopt( xUDPSocket, 0, FREERTOS_SO_SET_SEMAPHORE, ( void * ) &xNTPWakeupSem, sizeof( xNTPWakeupSem ) );
}
#endif
for( ; ; )
{
switch( xStatus )
{
case EStatusLookup:
if( ( ulIPAddressFound == 0ul ) || ( ulIPAddressFound == ~0ul ) )
{
if( ++xServerIndex == sizeof( pcTimeServers ) / sizeof( pcTimeServers[ 0 ] ) )
{
xServerIndex = 0;
}
FreeRTOS_printf( ( "Looking up server '%s'\n", pcTimeServers[ xServerIndex ] ) );
FreeRTOS_gethostbyname_a( pcTimeServers[ xServerIndex ], vDNS_callback, ( void * ) NULL, 1200 );
}
else
{
xStatus = EStatusAsking;
}
break;
case EStatusAsking:
{
char pcBuf[ 16 ];
prvNTPPacketInit();
#if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 )
{
xAddress.sin_address.ulIP_IPv4 = ulIPAddressFound;
xAddress.sin_port = FreeRTOS_htons( NTP_PORT );
FreeRTOS_inet_ntoa( xAddress.sin_address.ulIP_IPv4, pcBuf );
}
#else
{
xAddress.sin_addr = ulIPAddressFound;
xAddress.sin_port = FreeRTOS_htons( NTP_PORT );
FreeRTOS_inet_ntoa( xAddress.sin_addr, pcBuf );
}
#endif /* defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 ) */
xAddress.sin_family = FREERTOS_AF_INET;
FreeRTOS_printf( ( "Sending UDP message to %s:%u\n",
pcBuf,
FreeRTOS_ntohs( xAddress.sin_port ) ) );
uxSendTime = xTaskGetTickCount();
FreeRTOS_sendto( xUDPSocket, ( void * ) &xNTPPacket, sizeof( xNTPPacket ), 0, &xAddress, sizeof( xAddress ) );
}
break;
case EStatusPause:
break;
case EStatusFailed:
break;
}
#if ( ipconfigUSE_CALLBACKS != 0 )
{
xSemaphoreTake( xNTPWakeupSem, 5000 );
}
#else
{
uint32_t xAddressSize;
BaseType_t xReturned;
xAddressSize = sizeof( xAddress );
xReturned = FreeRTOS_recvfrom( xUDPSocket, ( void * ) cRecvBuffer, sizeof( cRecvBuffer ), 0, &xAddress, &xAddressSize );
switch( xReturned )
{
case 0:
case -pdFREERTOS_ERRNO_EAGAIN:
case -pdFREERTOS_ERRNO_EINTR:
break;
default:
if( xReturned < sizeof( xNTPPacket ) )
{
FreeRTOS_printf( ( "FreeRTOS_recvfrom: returns %ld\n", xReturned ) );
}
else
{
prvReadTime( ( struct SNtpPacket * ) cRecvBuffer );
if( xStatus != EStatusPause )
{
xStatus = EStatusPause;
}
}
break;
}
}
#endif /* if ( ipconfigUSE_CALLBACKS != 0 ) */
}
}
/*-----------------------------------------------------------*/

@ -1,5 +1,5 @@
FreeRTOS 2020107.00 adds a new SNTPv4 client library, [FreeRTOS/coreSNTP](https://github.com/FreeRTOS/coreSNTP),
and an [accompanying demo](..\..\..\coreSNTP_Windows_Simulator) to showcase the setup of an SNTP client and system
wall-clock time using the library. Refer to
and an [accompanying demo](..\..\..\coreSNTP_Windows_Simulator) to showcase the setup of an SNTP client and system
wall-clock time using the library. Refer to
The protocols implemented in this directory are intended to be demo quality
examples only. They are not intended for inclusion in production devices.

@ -1,133 +1,136 @@
/*
* FreeRTOS+TCP V2.0.1
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://aws.amazon.com/freertos
* https://www.FreeRTOS.org
*/
#ifndef __FTPCMD_H__
#define __FTPCMD_H__
#define REPL_110 "110 Restart marker reply.\r\n"
#define REPL_120 "120 Try again in 2 minutes.\r\n"
#define REPL_125 "125 Data connection already open; transfer starting.\r\n"
#define REPL_150 "150 File status okay; about to open data connection.\r\n"
#define REPL_200 "200 NOOP command successful.\r\n"
#define REPL_200_PROGRESS "200 NOOP: data transfer in progress.\r\n"
#define REPL_202 "202 Command not implemented, superfluous at this site.\r\n"
#define REPL_211 "221 System status, or system help reply.\r\n"
#define REPL_211_STATUS "221-status of %s.\r\n"
#define REPL_211_END "221 End of status.\r\n"
#define REPL_212 "212 Directory status.\r\n"
#define REPL_213 "213 File status.\r\n"
#define REPL_214 "214 Help message.\r\n"
#define REPL_214_END "214 End Help message.\r\n"
#define REPL_215 "215 %s system type.\r\n"
#define REPL_220 "220 Service ready for new user.\r\n"
#define REPL_221 "221 Service closing control connection.\r\n"
#define REPL_225 "225 Data connection open; no transfer in progress.\r\n"
#define REPL_226 "226 Closing data connection.\r\n"
#define REPL_227 "227 Entering Passive Mode (%s,%s,%s,%s,%s,%s).\r\n"
#define REPL_227_D "227 Entering Passive Mode (%u,%u,%u,%u,%u,%u).\r\n"
#define REPL_230 "230 User logged in, proceed.\r\n"
#define REPL_250 "250 Requested file action okay, completed.\r\n"
#define REPL_257 "257 %s created.\r\n"
// #define REPL_257_PWD "257 \"%s\" is current working dir.\r\n"
#define REPL_257_PWD "257 \"%s\"\r\n"
#define REPL_331 "331 Only anonymous user is accepted.\r\n"
#define REPL_331_ANON "331 Anonymous login okay\r\n"
#define REPL_332 "332 Need account for login.\r\n"
#define REPL_350 "350 Requested file action pending further information.\r\n"
#define REPL_421 "421 Service not available, closing control connection.\r\n"
#define REPL_425 "425 Can't open data connection.\r\n"
#define REPL_426 "426 Connection closed; transfer aborted.\r\n"
#define REPL_450 "450 Requested file action not taken.\r\n"
#define REPL_451 "451 Requested action aborted. Local error in processing.\r\n"
#define REPL_452 "452 Requested action not taken.\r\n"
#define REPL_500 "500 Syntax error, command unrecognized.\r\n"
#define REPL_501 "501 Syntax error in parameters or arguments.\r\n"
#define REPL_502 "502 Command not implemented.\r\n"
#define REPL_503 "503 Bad sequence of commands.\r\n"
#define REPL_504 "504 Command not implemented for that parameter.\r\n"
#define REPL_530 "530 Not logged in.\r\n"
#define REPL_532 "532 Need account for storing files.\r\n"
#define REPL_550 "550 Requested action not taken.\r\n"
#define REPL_551 "551 Requested action aborted. Page type unknown.\r\n"
#define REPL_552 "552 Requested file action aborted.\r\n"
#define REPL_553 "553 Requested action not taken.\r\n"
#define REPL_553_READ_ONLY "553 Read-only file-system.\r\n"
enum EFTPCommand {
ECMD_USER,
ECMD_PASS,
ECMD_ACCT,
ECMD_CWD,
ECMD_CDUP,
ECMD_SMNT,
ECMD_QUIT,
ECMD_REIN,
ECMD_PORT,
ECMD_PASV,
ECMD_TYPE,
ECMD_STRU,
ECMD_MODE,
ECMD_RETR,
ECMD_STOR,
ECMD_STOU,
ECMD_APPE,
ECMD_ALLO,
ECMD_REST,
ECMD_RNFR,
ECMD_RNTO,
ECMD_ABOR,
ECMD_SIZE,
ECMD_MDTM,
ECMD_DELE,
ECMD_RMD,
ECMD_MKD,
ECMD_PWD,
ECMD_LIST,
ECMD_NLST,
ECMD_SITE,
ECMD_SYST,
ECMD_FEAT,
ECMD_STAT,
ECMD_HELP,
ECMD_NOOP,
ECMD_EMPTY,
ECMD_CLOSE,
ECMD_UNKNOWN,
};
typedef struct xFTP_COMMAND {
BaseType_t xCommandLength;
const char pcCommandName[7];
const unsigned char ucCommandType;
const unsigned char checkLogin;
const unsigned char checkNullArg;
} FTPCommand_t;
#define FTP_CMD_COUNT (ECMD_UNKNOWN+1)
extern const FTPCommand_t xFTPCommands[ FTP_CMD_COUNT ];
#endif // __FTPCMD_H__
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
#ifndef __FTPCMD_H__
#define __FTPCMD_H__
#define REPL_110 "110 Restart marker reply.\r\n"
#define REPL_120 "120 Try again in 2 minutes.\r\n"
#define REPL_125 "125 Data connection already open; transfer starting.\r\n"
#define REPL_150 "150 File status okay; about to open data connection.\r\n"
#define REPL_200 "200 NOOP command successful.\r\n"
#define REPL_200_PROGRESS "200 NOOP: data transfer in progress.\r\n"
#define REPL_202 "202 Command not implemented, superfluous at this site.\r\n"
#define REPL_211 "221 System status, or system help reply.\r\n"
#define REPL_211_STATUS "221-status of %s.\r\n"
#define REPL_211_END "221 End of status.\r\n"
#define REPL_212 "212 Directory status.\r\n"
#define REPL_213 "213 File status.\r\n"
#define REPL_214 "214 Help message.\r\n"
#define REPL_214_END "214 End Help message.\r\n"
#define REPL_215 "215 %s system type.\r\n"
#define REPL_220 "220 Service ready for new user.\r\n"
#define REPL_221 "221 Service closing control connection.\r\n"
#define REPL_225 "225 Data connection open; no transfer in progress.\r\n"
#define REPL_226 "226 Closing data connection.\r\n"
#define REPL_227 "227 Entering Passive Mode (%s,%s,%s,%s,%s,%s).\r\n"
#define REPL_227_D "227 Entering Passive Mode (%u,%u,%u,%u,%u,%u).\r\n"
#define REPL_230 "230 User logged in, proceed.\r\n"
#define REPL_250 "250 Requested file action okay, completed.\r\n"
#define REPL_257 "257 %s created.\r\n"
/* #define REPL_257_PWD "257 \"%s\" is current working dir.\r\n" */
#define REPL_257_PWD "257 \"%s\"\r\n"
#define REPL_331 "331 Only anonymous user is accepted.\r\n"
#define REPL_331_ANON "331 Anonymous login okay\r\n"
#define REPL_332 "332 Need account for login.\r\n"
#define REPL_350 "350 Requested file action pending further information.\r\n"
#define REPL_421 "421 Service not available, closing control connection.\r\n"
#define REPL_425 "425 Can't open data connection.\r\n"
#define REPL_426 "426 Connection closed; transfer aborted.\r\n"
#define REPL_450 "450 Requested file action not taken.\r\n"
#define REPL_451 "451 Requested action aborted. Local error in processing.\r\n"
#define REPL_452 "452 Requested action not taken.\r\n"
#define REPL_500 "500 Syntax error, command unrecognized.\r\n"
#define REPL_501 "501 Syntax error in parameters or arguments.\r\n"
#define REPL_502 "502 Command not implemented.\r\n"
#define REPL_503 "503 Bad sequence of commands.\r\n"
#define REPL_504 "504 Command not implemented for that parameter.\r\n"
#define REPL_530 "530 Not logged in.\r\n"
#define REPL_532 "532 Need account for storing files.\r\n"
#define REPL_550 "550 Requested action not taken.\r\n"
#define REPL_551 "551 Requested action aborted. Page type unknown.\r\n"
#define REPL_552 "552 Requested file action aborted.\r\n"
#define REPL_553 "553 Requested action not taken.\r\n"
#define REPL_553_READ_ONLY "553 Read-only file-system.\r\n"
enum EFTPCommand
{
ECMD_USER,
ECMD_PASS,
ECMD_ACCT,
ECMD_CWD,
ECMD_CDUP,
ECMD_SMNT,
ECMD_QUIT,
ECMD_REIN,
ECMD_PORT,
ECMD_PASV,
ECMD_TYPE,
ECMD_STRU,
ECMD_MODE,
ECMD_RETR,
ECMD_STOR,
ECMD_STOU,
ECMD_APPE,
ECMD_ALLO,
ECMD_REST,
ECMD_RNFR,
ECMD_RNTO,
ECMD_ABOR,
ECMD_SIZE,
ECMD_MDTM,
ECMD_DELE,
ECMD_RMD,
ECMD_MKD,
ECMD_PWD,
ECMD_LIST,
ECMD_NLST,
ECMD_SITE,
ECMD_SYST,
ECMD_FEAT,
ECMD_STAT,
ECMD_HELP,
ECMD_NOOP,
ECMD_EMPTY,
ECMD_CLOSE,
ECMD_UNKNOWN,
};
typedef struct xFTP_COMMAND
{
BaseType_t xCommandLength;
const char pcCommandName[ 7 ];
const unsigned char ucCommandType;
const unsigned char checkLogin;
const unsigned char checkNullArg;
} FTPCommand_t;
#define FTP_CMD_COUNT ( ECMD_UNKNOWN + 1 )
extern const FTPCommand_t xFTPCommands[ FTP_CMD_COUNT ];
#endif // __FTPCMD_H__

@ -1,67 +1,68 @@
/*
* FreeRTOS+TCP V2.0.3
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://aws.amazon.com/freertos
* https://www.FreeRTOS.org
*/
#ifndef FREERTOS_HTTP_COMMANDS_H
#define FREERTOS_HTTP_COMMANDS_H
enum {
WEB_REPLY_OK = 200,
WEB_NO_CONTENT = 204,
WEB_BAD_REQUEST = 400,
WEB_UNAUTHORIZED = 401,
WEB_NOT_FOUND = 404,
WEB_GONE = 410,
WEB_PRECONDITION_FAILED = 412,
WEB_INTERNAL_SERVER_ERROR = 500,
};
enum EWebCommand {
ECMD_GET,
ECMD_HEAD,
ECMD_POST,
ECMD_PUT,
ECMD_DELETE,
ECMD_TRACE,
ECMD_OPTIONS,
ECMD_CONNECT,
ECMD_PATCH,
ECMD_UNK,
};
struct xWEB_COMMAND
{
BaseType_t xCommandLength;
const char *pcCommandName;
const unsigned char ucCommandType;
};
#define WEB_CMD_COUNT (ECMD_UNK+1)
extern const struct xWEB_COMMAND xWebCommands[WEB_CMD_COUNT];
extern const char *webCodename (int aCode);
#endif /* FREERTOS_HTTP_COMMANDS_H */
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
#ifndef FREERTOS_HTTP_COMMANDS_H
#define FREERTOS_HTTP_COMMANDS_H
enum
{
WEB_REPLY_OK = 200,
WEB_NO_CONTENT = 204,
WEB_BAD_REQUEST = 400,
WEB_UNAUTHORIZED = 401,
WEB_NOT_FOUND = 404,
WEB_GONE = 410,
WEB_PRECONDITION_FAILED = 412,
WEB_INTERNAL_SERVER_ERROR = 500,
};
enum EWebCommand
{
ECMD_GET,
ECMD_HEAD,
ECMD_POST,
ECMD_PUT,
ECMD_DELETE,
ECMD_TRACE,
ECMD_OPTIONS,
ECMD_CONNECT,
ECMD_PATCH,
ECMD_UNK,
};
struct xWEB_COMMAND
{
BaseType_t xCommandLength;
const char * pcCommandName;
const unsigned char ucCommandType;
};
#define WEB_CMD_COUNT ( ECMD_UNK + 1 )
extern const struct xWEB_COMMAND xWebCommands[ WEB_CMD_COUNT ];
extern const char * webCodename( int aCode );
#endif /* FREERTOS_HTTP_COMMANDS_H */

@ -1,125 +1,141 @@
/*
* FreeRTOS+TCP V2.0.3
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://aws.amazon.com/freertos
* https://www.FreeRTOS.org
*/
/*
Some code which is common to TCP servers like HTTP en FTP
*/
#ifndef FREERTOS_TCP_SERVER_H
#define FREERTOS_TCP_SERVER_H
#ifdef __cplusplus
extern "C" {
#endif
#ifndef FTP_SERVER_USES_RELATIVE_DIRECTORY
#define FTP_SERVER_USES_RELATIVE_DIRECTORY 0
#endif
enum eSERVER_TYPE
{
eSERVER_NONE,
eSERVER_HTTP,
eSERVER_FTP,
};
struct xFTP_CLIENT;
#if( ipconfigFTP_HAS_RECEIVED_HOOK != 0 )
extern void vApplicationFTPReceivedHook( const char *pcFileName, uint32_t ulSize, struct xFTP_CLIENT *pxFTPClient );
extern void vFTPReplyMessage( struct xFTP_CLIENT *pxFTPClient, const char *pcMessage );
#endif /* ipconfigFTP_HAS_RECEIVED_HOOK != 0 */
#if( ipconfigFTP_HAS_USER_PASSWORD_HOOK != 0 )
/*
* Function is called when a user name has been submitted.
* The function may return a string such as: "331 Please enter your password"
* or return NULL to use the default reply.
*/
extern const char *pcApplicationFTPUserHook( const char *pcUserName );
#endif /* ipconfigFTP_HAS_USER_PASSWORD_HOOK */
#if( ipconfigFTP_HAS_USER_PASSWORD_HOOK != 0 )
/*
* Function is called when a password was received.
* Return positive value to allow the user
*/
extern BaseType_t xApplicationFTPPasswordHook( const char *pcUserName, const char *pcPassword );
#endif /* ipconfigFTP_HAS_USER_PASSWORD_HOOK */
#if( ipconfigFTP_HAS_USER_PROPERTIES_HOOK != 0 )
/*
* The FTP server is asking for user-specific properties
*/
typedef struct
{
uint16_t usPortNumber; /* For reference only. Host-endian. */
const char *pcRootDir;
BaseType_t xReadOnly;
}
FTPUserProperties_t;
extern void vApplicationFTPUserPropertiesHook( const char *pcUserName, FTPUserProperties_t *pxProperties );
#endif /* ipconfigFTP_HAS_USER_PASSWORD_HOOK */
#if( ipconfigHTTP_HAS_HANDLE_REQUEST_HOOK != 0 )
/*
* A GET request is received containing a special character,
* usually a question mark.
* const char *pcURLData; // A request, e.g. "/request?limit=75"
* char *pcBuffer; // Here the answer can be written
* size_t uxBufferLength; // Size of the buffer
*
*/
extern size_t uxApplicationHTTPHandleRequestHook( const char *pcURLData, char *pcBuffer, size_t uxBufferLength );
#endif /* ipconfigHTTP_HAS_HANDLE_REQUEST_HOOK */
struct xSERVER_CONFIG
{
enum eSERVER_TYPE eType; /* eSERVER_HTTP | eSERVER_FTP */
BaseType_t xPortNumber; /* e.g. 80, 8080, 21 */
BaseType_t xBackLog; /* e.g. 10, maximum number of connected TCP clients */
const char * const pcRootDir; /* Treat this directory as the root directory */
};
struct xTCP_SERVER;
typedef struct xTCP_SERVER TCPServer_t;
TCPServer_t *FreeRTOS_CreateTCPServer( const struct xSERVER_CONFIG *pxConfigs, BaseType_t xCount );
void FreeRTOS_TCPServerWork( TCPServer_t *pxServer, TickType_t xBlockingTime );
#if( ipconfigSUPPORT_SIGNALS != 0 )
/* FreeRTOS_TCPServerWork() calls select().
The two functions below provide a possibility to interrupt
the call to select(). After the interruption, resume
by calling FreeRTOS_TCPServerWork() again. */
BaseType_t FreeRTOS_TCPServerSignal( TCPServer_t *pxServer );
BaseType_t FreeRTOS_TCPServerSignalFromISR( TCPServer_t *pxServer, BaseType_t *pxHigherPriorityTaskWoken );
#endif
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* FREERTOS_TCP_SERVER_H */
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
/*
* Some code which is common to TCP servers like HTTP en FTP
*/
#ifndef FREERTOS_TCP_SERVER_H
#define FREERTOS_TCP_SERVER_H
#ifdef __cplusplus
extern "C" {
#endif
#ifndef FTP_SERVER_USES_RELATIVE_DIRECTORY
#define FTP_SERVER_USES_RELATIVE_DIRECTORY 0
#endif
enum eSERVER_TYPE
{
eSERVER_NONE,
eSERVER_HTTP,
eSERVER_FTP,
};
struct xFTP_CLIENT;
#if ( ipconfigFTP_HAS_RECEIVED_HOOK != 0 )
extern void vApplicationFTPReceivedHook( const char * pcFileName,
uint32_t ulSize,
struct xFTP_CLIENT * pxFTPClient );
extern void vFTPReplyMessage( struct xFTP_CLIENT * pxFTPClient,
const char * pcMessage );
#endif /* ipconfigFTP_HAS_RECEIVED_HOOK != 0 */
#if ( ipconfigFTP_HAS_USER_PASSWORD_HOOK != 0 )
/*
* Function is called when a user name has been submitted.
* The function may return a string such as: "331 Please enter your password"
* or return NULL to use the default reply.
*/
extern const char * pcApplicationFTPUserHook( const char * pcUserName );
#endif /* ipconfigFTP_HAS_USER_PASSWORD_HOOK */
#if ( ipconfigFTP_HAS_USER_PASSWORD_HOOK != 0 )
/*
* Function is called when a password was received.
* Return positive value to allow the user
*/
extern BaseType_t xApplicationFTPPasswordHook( const char * pcUserName,
const char * pcPassword );
#endif /* ipconfigFTP_HAS_USER_PASSWORD_HOOK */
#if ( ipconfigFTP_HAS_USER_PROPERTIES_HOOK != 0 )
/*
* The FTP server is asking for user-specific properties
*/
typedef struct
{
uint16_t usPortNumber; /* For reference only. Host-endian. */
const char * pcRootDir;
BaseType_t xReadOnly;
}
FTPUserProperties_t;
extern void vApplicationFTPUserPropertiesHook( const char * pcUserName,
FTPUserProperties_t * pxProperties );
#endif /* ipconfigFTP_HAS_USER_PASSWORD_HOOK */
#if ( ipconfigHTTP_HAS_HANDLE_REQUEST_HOOK != 0 )
/*
* A GET request is received containing a special character,
* usually a question mark.
* const char *pcURLData; // A request, e.g. "/request?limit=75"
* char *pcBuffer; // Here the answer can be written
* size_t uxBufferLength; // Size of the buffer
*
*/
extern size_t uxApplicationHTTPHandleRequestHook( const char * pcURLData,
char * pcBuffer,
size_t uxBufferLength );
#endif /* ipconfigHTTP_HAS_HANDLE_REQUEST_HOOK */
struct xSERVER_CONFIG
{
enum eSERVER_TYPE eType; /* eSERVER_HTTP | eSERVER_FTP */
BaseType_t xPortNumber; /* e.g. 80, 8080, 21 */
BaseType_t xBackLog; /* e.g. 10, maximum number of connected TCP clients */
const char * const pcRootDir; /* Treat this directory as the root directory */
};
struct xTCP_SERVER;
typedef struct xTCP_SERVER TCPServer_t;
TCPServer_t * FreeRTOS_CreateTCPServer( const struct xSERVER_CONFIG * pxConfigs,
BaseType_t xCount );
void FreeRTOS_TCPServerWork( TCPServer_t * pxServer,
TickType_t xBlockingTime );
#if ( ipconfigSUPPORT_SIGNALS != 0 )
/* FreeRTOS_TCPServerWork() calls select().
* The two functions below provide a possibility to interrupt
* the call to select(). After the interruption, resume
* by calling FreeRTOS_TCPServerWork() again. */
BaseType_t FreeRTOS_TCPServerSignal( TCPServer_t * pxServer );
BaseType_t FreeRTOS_TCPServerSignalFromISR( TCPServer_t * pxServer,
BaseType_t * pxHigherPriorityTaskWoken );
#endif
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* FREERTOS_TCP_SERVER_H */

@ -1,185 +1,201 @@
/*
* FreeRTOS+TCP V2.0.3
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://aws.amazon.com/freertos
* https://www.FreeRTOS.org
*/
/*
Some code which is common to TCP servers like HTTP and FTP
*/
#ifndef FREERTOS_SERVER_PRIVATE_H
#define FREERTOS_SERVER_PRIVATE_H
#define FREERTOS_NO_SOCKET NULL
/* FreeRTOS+FAT */
#include "ff_stdio.h"
/* Each HTTP server has 1, at most 2 sockets */
#define HTTP_SOCKET_COUNT 2
/*
* ipconfigTCP_COMMAND_BUFFER_SIZE sets the size of:
* pcCommandBuffer': a buffer to receive and send TCP commands
*
* ipconfigTCP_FILE_BUFFER_SIZE sets the size of:
* pcFileBuffer' : a buffer to access the file system: read or write data.
*
* The buffers are both used for FTP as well as HTTP.
*/
#ifndef ipconfigTCP_COMMAND_BUFFER_SIZE
#define ipconfigTCP_COMMAND_BUFFER_SIZE ( 2048 )
#endif
#ifndef ipconfigTCP_FILE_BUFFER_SIZE
#define ipconfigTCP_FILE_BUFFER_SIZE ( 2048 )
#endif
struct xTCP_CLIENT;
typedef BaseType_t ( * FTCPWorkFunction ) ( struct xTCP_CLIENT * /* pxClient */ );
typedef void ( * FTCPDeleteFunction ) ( struct xTCP_CLIENT * /* pxClient */ );
#define TCP_CLIENT_FIELDS \
enum eSERVER_TYPE eType; \
struct xTCP_SERVER *pxParent; \
Socket_t xSocket; \
const char *pcRootDir; \
FTCPWorkFunction fWorkFunction; \
FTCPDeleteFunction fDeleteFunction; \
struct xTCP_CLIENT *pxNextClient
typedef struct xTCP_CLIENT
{
/* This define contains fields which must come first within each of the client structs */
TCP_CLIENT_FIELDS;
/* --- Keep at the top --- */
} TCPClient_t;
struct xHTTP_CLIENT
{
/* This define contains fields which must come first within each of the client structs */
TCP_CLIENT_FIELDS;
/* --- Keep at the top --- */
const char *pcUrlData;
const char *pcRestData;
char pcCurrentFilename[ ffconfigMAX_FILENAME ];
size_t uxBytesLeft;
FF_FILE *pxFileHandle;
union {
struct {
uint32_t
bReplySent : 1;
};
uint32_t ulFlags;
} bits;
};
typedef struct xHTTP_CLIENT HTTPClient_t;
struct xFTP_CLIENT
{
/* This define contains fields which must come first within each of the client structs */
TCP_CLIENT_FIELDS;
/* --- Keep at the top --- */
uint32_t ulRestartOffset;
uint32_t ulRecvBytes;
size_t uxBytesLeft; /* Bytes left to send */
uint32_t ulClientIP;
TickType_t xStartTime;
uint16_t usClientPort;
Socket_t xTransferSocket;
BaseType_t xTransType;
BaseType_t xDirCount;
FF_FindData_t xFindData;
FF_FILE *pxReadHandle;
FF_FILE *pxWriteHandle;
char pcCurrentDir[ ffconfigMAX_FILENAME ];
char pcFileName[ ffconfigMAX_FILENAME ];
char pcConnectionAck[ 128 ];
char pcClientAck[ 128 ];
union {
struct {
uint32_t
bHelloSent : 1,
bLoggedIn : 1,
bStatusUser : 1,
bInRename : 1,
bReadOnly : 1;
};
uint32_t ulFTPFlags;
} bits;
union {
struct {
uint32_t
bIsListen : 1, /* pdTRUE for passive data connections (using list()). */
bDirHasEntry : 1, /* pdTRUE if ff_findfirst() was successful. */
bClientConnected : 1, /* pdTRUE after connect() or accept() has succeeded. */
bEmptyFile : 1, /* pdTRUE if a connection-without-data was received. */
bHadError : 1; /* pdTRUE if a transfer got aborted because of an error. */
};
uint32_t ulConnFlags;
} bits1;
};
typedef struct xFTP_CLIENT FTPClient_t;
BaseType_t xHTTPClientWork( TCPClient_t *pxClient );
BaseType_t xFTPClientWork( TCPClient_t *pxClient );
void vHTTPClientDelete( TCPClient_t *pxClient );
void vFTPClientDelete( TCPClient_t *pxClient );
BaseType_t xMakeAbsolute( struct xFTP_CLIENT *pxClient, char *pcBuffer, BaseType_t xBufferLength, const char *pcFileName );
BaseType_t xMakeRelative( FTPClient_t *pxClient, char *pcBuffer, BaseType_t xBufferLength, const char *pcFileName );
struct xTCP_SERVER
{
SocketSet_t xSocketSet;
/* A buffer to receive and send TCP commands, either HTTP of FTP. */
char pcCommandBuffer[ ipconfigTCP_COMMAND_BUFFER_SIZE ];
/* A buffer to access the file system: read or write data. */
char pcFileBuffer[ ipconfigTCP_FILE_BUFFER_SIZE ];
#if( ipconfigUSE_FTP != 0 )
char pcNewDir[ ffconfigMAX_FILENAME ];
#endif
#if( ipconfigUSE_HTTP != 0 )
char pcContentsType[40]; /* Space for the msg: "text/javascript" */
char pcExtraContents[40]; /* Space for the msg: "Content-Length: 346500" */
#endif
BaseType_t xServerCount;
TCPClient_t *pxClients;
struct xSERVER
{
enum eSERVER_TYPE eType; /* eSERVER_HTTP | eSERVER_FTP */
const char *pcRootDir;
Socket_t xSocket;
} xServers[ 1 ];
};
#endif /* FREERTOS_SERVER_PRIVATE_H */
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
/*
* Some code which is common to TCP servers like HTTP and FTP
*/
#ifndef FREERTOS_SERVER_PRIVATE_H
#define FREERTOS_SERVER_PRIVATE_H
#define FREERTOS_NO_SOCKET NULL
/* FreeRTOS+FAT */
#include "ff_stdio.h"
/* Each HTTP server has 1, at most 2 sockets */
#define HTTP_SOCKET_COUNT 2
/*
* ipconfigTCP_COMMAND_BUFFER_SIZE sets the size of:
* pcCommandBuffer': a buffer to receive and send TCP commands
*
* ipconfigTCP_FILE_BUFFER_SIZE sets the size of:
* pcFileBuffer' : a buffer to access the file system: read or write data.
*
* The buffers are both used for FTP as well as HTTP.
*/
#ifndef ipconfigTCP_COMMAND_BUFFER_SIZE
#define ipconfigTCP_COMMAND_BUFFER_SIZE ( 2048 )
#endif
#ifndef ipconfigTCP_FILE_BUFFER_SIZE
#define ipconfigTCP_FILE_BUFFER_SIZE ( 2048 )
#endif
struct xTCP_CLIENT;
typedef BaseType_t ( * FTCPWorkFunction ) ( struct xTCP_CLIENT * /* pxClient */ );
typedef void ( * FTCPDeleteFunction ) ( struct xTCP_CLIENT * /* pxClient */ );
#define TCP_CLIENT_FIELDS \
enum eSERVER_TYPE eType; \
struct xTCP_SERVER * pxParent; \
Socket_t xSocket; \
const char * pcRootDir; \
FTCPWorkFunction fWorkFunction; \
FTCPDeleteFunction fDeleteFunction; \
struct xTCP_CLIENT * pxNextClient
typedef struct xTCP_CLIENT
{
/* This define contains fields which must come first within each of the client structs */
TCP_CLIENT_FIELDS;
/* --- Keep at the top --- */
} TCPClient_t;
struct xHTTP_CLIENT
{
/* This define contains fields which must come first within each of the client structs */
TCP_CLIENT_FIELDS;
/* --- Keep at the top --- */
const char * pcUrlData;
const char * pcRestData;
char pcCurrentFilename[ ffconfigMAX_FILENAME ];
size_t uxBytesLeft;
FF_FILE * pxFileHandle;
union
{
struct
{
uint32_t
bReplySent : 1;
};
uint32_t ulFlags;
}
bits;
};
typedef struct xHTTP_CLIENT HTTPClient_t;
struct xFTP_CLIENT
{
/* This define contains fields which must come first within each of the client structs */
TCP_CLIENT_FIELDS;
/* --- Keep at the top --- */
uint32_t ulRestartOffset;
uint32_t ulRecvBytes;
size_t uxBytesLeft; /* Bytes left to send */
uint32_t ulClientIP;
TickType_t xStartTime;
uint16_t usClientPort;
Socket_t xTransferSocket;
BaseType_t xTransType;
BaseType_t xDirCount;
FF_FindData_t xFindData;
FF_FILE * pxReadHandle;
FF_FILE * pxWriteHandle;
char pcCurrentDir[ ffconfigMAX_FILENAME ];
char pcFileName[ ffconfigMAX_FILENAME ];
char pcConnectionAck[ 128 ];
char pcClientAck[ 128 ];
union
{
struct
{
uint32_t
bHelloSent : 1,
bLoggedIn : 1,
bStatusUser : 1,
bInRename : 1,
bReadOnly : 1;
};
uint32_t ulFTPFlags;
}
bits;
union
{
struct
{
uint32_t
bIsListen : 1, /* pdTRUE for passive data connections (using list()). */
bDirHasEntry : 1, /* pdTRUE if ff_findfirst() was successful. */
bClientConnected : 1, /* pdTRUE after connect() or accept() has succeeded. */
bEmptyFile : 1, /* pdTRUE if a connection-without-data was received. */
bHadError : 1; /* pdTRUE if a transfer got aborted because of an error. */
};
uint32_t ulConnFlags;
}
bits1;
};
typedef struct xFTP_CLIENT FTPClient_t;
BaseType_t xHTTPClientWork( TCPClient_t * pxClient );
BaseType_t xFTPClientWork( TCPClient_t * pxClient );
void vHTTPClientDelete( TCPClient_t * pxClient );
void vFTPClientDelete( TCPClient_t * pxClient );
BaseType_t xMakeAbsolute( struct xFTP_CLIENT * pxClient,
char * pcBuffer,
BaseType_t xBufferLength,
const char * pcFileName );
BaseType_t xMakeRelative( FTPClient_t * pxClient,
char * pcBuffer,
BaseType_t xBufferLength,
const char * pcFileName );
struct xTCP_SERVER
{
SocketSet_t xSocketSet;
/* A buffer to receive and send TCP commands, either HTTP of FTP. */
char pcCommandBuffer[ ipconfigTCP_COMMAND_BUFFER_SIZE ];
/* A buffer to access the file system: read or write data. */
char pcFileBuffer[ ipconfigTCP_FILE_BUFFER_SIZE ];
#if ( ipconfigUSE_FTP != 0 )
char pcNewDir[ ffconfigMAX_FILENAME ];
#endif
#if ( ipconfigUSE_HTTP != 0 )
char pcContentsType[ 40 ]; /* Space for the msg: "text/javascript" */
char pcExtraContents[ 40 ]; /* Space for the msg: "Content-Length: 346500" */
#endif
BaseType_t xServerCount;
TCPClient_t * pxClients;
struct xSERVER
{
enum eSERVER_TYPE eType; /* eSERVER_HTTP | eSERVER_FTP */
const char * pcRootDir;
Socket_t xSocket;
}
xServers[ 1 ];
};
#endif /* FREERTOS_SERVER_PRIVATE_H */

@ -1,71 +1,98 @@
//
// ntpClient.h
//
#ifndef __NTPCLIENT_H__
#define __NTPCLIENT_H__
#define NTP_PORT 123
typedef uint32_t quint32;
typedef int32_t qint32;
typedef uint8_t quint8;
typedef int8_t qint8;
typedef union _SNtpFlags SNtpFlags;
/**
* 64-bit NTP timestamp.
*/
struct __attribute__ ((__packed__)) _SNtpTimestamp {
/** Number of seconds passed since Jan 1 1900, in big-endian format. */
quint32 seconds;
/** Fractional time part, in <tt>1/0xFFFFFFFF</tt>s of a second. */
quint32 fraction;
};
typedef struct _SNtpTimestamp SNtpTimestamp;
/**
* Mandatory part of an NTP packet
*/
struct SNtpPacket {
/** Flags. */
unsigned char flags; // value 0xDB : mode 3 (client), version 3, leap indicator unknown 3
/** Stratum of the clock. */
quint8 stratum; // value 0 : unspecified
/** Maximum interval between successive messages, in log2 seconds. Note that the value is signed. */
qint8 poll; // 10 means 1 << 10 = 1024 seconds
/** Precision of the clock, in log2 seconds. Note that the value is signed. */
qint8 precision; // 0xFA = 250 = 0.015625 seconds
/** Round trip time to the primary reference source, in NTP short format. */
qint32 rootDelay; // 0x5D2E = 23854 or (23854/65535)= 0.3640 sec
/** Nominal error relative to the primary reference source. */
qint32 rootDispersion; // 0x0008 CAC8 = 8.7912 seconds
/** Reference identifier (either a 4 character string or an IP address). */
qint8 referenceID[4]; // or just 0000
/** The time at which the clock was last set or corrected. */
SNtpTimestamp referenceTimestamp; // Current time
/** The time at which the request departed the client for the server. */
SNtpTimestamp originateTimestamp; // Keep 0
/** The time at which the request arrived at the server. */
SNtpTimestamp receiveTimestamp; // Keep 0
/** The time at which the reply departed the server for client. */
SNtpTimestamp transmitTimestamp;
};
/* Add this number to get secs since 1-1-1900 */
#define TIME1970 2208988800UL
#endif // __NTPCLIENT_H__
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
/* ntpClient.h */
#ifndef __NTPCLIENT_H__
#define __NTPCLIENT_H__
#define NTP_PORT 123
typedef uint32_t quint32;
typedef int32_t qint32;
typedef uint8_t quint8;
typedef int8_t qint8;
typedef union _SNtpFlags SNtpFlags;
/**
* 64-bit NTP timestamp.
*/
struct __attribute__( ( __packed__ ) ) _SNtpTimestamp
{
/** Number of seconds passed since Jan 1 1900, in big-endian format. */
quint32 seconds;
/** Fractional time part, in <tt>1/0xFFFFFFFF</tt>s of a second. */
quint32 fraction;
};
typedef struct _SNtpTimestamp SNtpTimestamp;
/**
* Mandatory part of an NTP packet
*/
struct SNtpPacket
{
/** Flags. */
unsigned char flags; /* value 0xDB : mode 3 (client), version 3, leap indicator unknown 3 */
/** Stratum of the clock. */
quint8 stratum; /* value 0 : unspecified */
/** Maximum interval between successive messages, in log2 seconds. Note that the value is signed. */
qint8 poll; /* 10 means 1 << 10 = 1024 seconds */
/** Precision of the clock, in log2 seconds. Note that the value is signed. */
qint8 precision; /* 0xFA = 250 = 0.015625 seconds */
/** Round trip time to the primary reference source, in NTP short format. */
qint32 rootDelay; /* 0x5D2E = 23854 or (23854/65535)= 0.3640 sec */
/** Nominal error relative to the primary reference source. */
qint32 rootDispersion; /* 0x0008 CAC8 = 8.7912 seconds */
/** Reference identifier (either a 4 character string or an IP address). */
qint8 referenceID[ 4 ]; /* or just 0000 */
/** The time at which the clock was last set or corrected. */
SNtpTimestamp referenceTimestamp; /* Current time */
/** The time at which the request departed the client for the server. */
SNtpTimestamp originateTimestamp; /* Keep 0 */
/** The time at which the request arrived at the server. */
SNtpTimestamp receiveTimestamp; /* Keep 0 */
/** The time at which the reply departed the server for client. */
SNtpTimestamp transmitTimestamp;
};
/* Add this number to get secs since 1-1-1900 */
#define TIME1970 2208988800UL
#endif // __NTPCLIENT_H__

@ -1,11 +1,34 @@
/*
* A simple demo for NTP using FreeRTOS+TCP
*/
#ifndef NTPDEMO_H
#define NTPDEMO_H
void vStartNTPTask( uint16_t usTaskStackSize, UBaseType_t uxTaskPriority );
#endif
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
#ifndef NTPDEMO_H
#define NTPDEMO_H
void vStartNTPTask( uint16_t usTaskStackSize,
UBaseType_t uxTaskPriority );
#endif

@ -1,479 +1,507 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://aws.amazon.com/freertos
*
*/
/******************************************************************************
*
* https://www.FreeRTOS.org/cli
*
******************************************************************************/
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "task.h"
/* Standard includes. */
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* FreeRTOS+CLI includes. */
#include "FreeRTOS_CLI.h"
#ifndef configINCLUDE_TRACE_RELATED_CLI_COMMANDS
#define configINCLUDE_TRACE_RELATED_CLI_COMMANDS 0
#endif
#ifndef configINCLUDE_QUERY_HEAP_COMMAND
#define configINCLUDE_QUERY_HEAP_COMMAND 0
#endif
/*
* The function that registers the commands that are defined within this file.
*/
void vRegisterSampleCLICommands( void );
/*
* Implements the task-stats command.
*/
static BaseType_t prvTaskStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
/*
* Implements the run-time-stats command.
*/
#if( configGENERATE_RUN_TIME_STATS == 1 )
static BaseType_t prvRunTimeStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
#endif /* configGENERATE_RUN_TIME_STATS */
/*
* Implements the echo-three-parameters command.
*/
static BaseType_t prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
/*
* Implements the echo-parameters command.
*/
static BaseType_t prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
/*
* Implements the "query heap" command.
*/
#if( configINCLUDE_QUERY_HEAP_COMMAND == 1 )
static BaseType_t prvQueryHeapCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
#endif
/*
* Implements the "trace start" and "trace stop" commands;
*/
#if( configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1 )
static BaseType_t prvStartStopTraceCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
#endif
/* Structure that defines the "task-stats" command line command. This generates
a table that gives information on each task in the system. */
static const CLI_Command_Definition_t xTaskStats =
{
"task-stats", /* The command string to type. */
"\r\ntask-stats:\r\n Displays a table showing the state of each FreeRTOS task\r\n",
prvTaskStatsCommand, /* The function to run. */
0 /* No parameters are expected. */
};
/* Structure that defines the "echo_3_parameters" command line command. This
takes exactly three parameters that the command simply echos back one at a
time. */
static const CLI_Command_Definition_t xThreeParameterEcho =
{
"echo-3-parameters",
"\r\necho-3-parameters <param1> <param2> <param3>:\r\n Expects three parameters, echos each in turn\r\n",
prvThreeParameterEchoCommand, /* The function to run. */
3 /* Three parameters are expected, which can take any value. */
};
/* Structure that defines the "echo_parameters" command line command. This
takes a variable number of parameters that the command simply echos back one at
a time. */
static const CLI_Command_Definition_t xParameterEcho =
{
"echo-parameters",
"\r\necho-parameters <...>:\r\n Take variable number of parameters, echos each in turn\r\n",
prvParameterEchoCommand, /* The function to run. */
-1 /* The user can enter any number of commands. */
};
#if( configGENERATE_RUN_TIME_STATS == 1 )
/* Structure that defines the "run-time-stats" command line command. This
generates a table that shows how much run time each task has */
static const CLI_Command_Definition_t xRunTimeStats =
{
"run-time-stats", /* The command string to type. */
"\r\nrun-time-stats:\r\n Displays a table showing how much processing time each FreeRTOS task has used\r\n",
prvRunTimeStatsCommand, /* The function to run. */
0 /* No parameters are expected. */
};
#endif /* configGENERATE_RUN_TIME_STATS */
#if( configINCLUDE_QUERY_HEAP_COMMAND == 1 )
/* Structure that defines the "query_heap" command line command. */
static const CLI_Command_Definition_t xQueryHeap =
{
"query-heap",
"\r\nquery-heap:\r\n Displays the free heap space, and minimum ever free heap space.\r\n",
prvQueryHeapCommand, /* The function to run. */
0 /* The user can enter any number of commands. */
};
#endif /* configQUERY_HEAP_COMMAND */
#if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
/* Structure that defines the "trace" command line command. This takes a single
parameter, which can be either "start" or "stop". */
static const CLI_Command_Definition_t xStartStopTrace =
{
"trace",
"\r\ntrace [start | stop]:\r\n Starts or stops a trace recording for viewing in FreeRTOS+Trace\r\n",
prvStartStopTraceCommand, /* The function to run. */
1 /* One parameter is expected. Valid values are "start" and "stop". */
};
#endif /* configINCLUDE_TRACE_RELATED_CLI_COMMANDS */
/*-----------------------------------------------------------*/
void vRegisterSampleCLICommands( void )
{
/* Register all the command line commands defined immediately above. */
FreeRTOS_CLIRegisterCommand( &xTaskStats );
FreeRTOS_CLIRegisterCommand( &xThreeParameterEcho );
FreeRTOS_CLIRegisterCommand( &xParameterEcho );
#if( configGENERATE_RUN_TIME_STATS == 1 )
{
FreeRTOS_CLIRegisterCommand( &xRunTimeStats );
}
#endif
#if( configINCLUDE_QUERY_HEAP_COMMAND == 1 )
{
FreeRTOS_CLIRegisterCommand( &xQueryHeap );
}
#endif
#if( configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1 )
{
FreeRTOS_CLIRegisterCommand( &xStartStopTrace );
}
#endif
}
/*-----------------------------------------------------------*/
static BaseType_t prvTaskStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
{
const char *const pcHeader = " State Priority Stack #\r\n************************************************\r\n";
BaseType_t xSpacePadding;
/* Remove compile time warnings about unused parameters, and check the
write buffer is not NULL. NOTE - for simplicity, this example assumes the
write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString;
( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer );
/* Generate a table of task stats. */
strcpy( pcWriteBuffer, "Task" );
pcWriteBuffer += strlen( pcWriteBuffer );
/* Minus three for the null terminator and half the number of characters in
"Task" so the column lines up with the centre of the heading. */
configASSERT( configMAX_TASK_NAME_LEN > 3 );
for( xSpacePadding = strlen( "Task" ); xSpacePadding < ( configMAX_TASK_NAME_LEN - 3 ); xSpacePadding++ )
{
/* Add a space to align columns after the task's name. */
*pcWriteBuffer = ' ';
pcWriteBuffer++;
/* Ensure always terminated. */
*pcWriteBuffer = 0x00;
}
strcpy( pcWriteBuffer, pcHeader );
vTaskList( pcWriteBuffer + strlen( pcHeader ) );
/* There is no more data to return after this single string, so return
pdFALSE. */
return pdFALSE;
}
/*-----------------------------------------------------------*/
#if( configINCLUDE_QUERY_HEAP_COMMAND == 1 )
static BaseType_t prvQueryHeapCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
{
/* Remove compile time warnings about unused parameters, and check the
write buffer is not NULL. NOTE - for simplicity, this example assumes the
write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString;
( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer );
sprintf( pcWriteBuffer, "Current free heap %d bytes, minimum ever free heap %d bytes\r\n", ( int ) xPortGetFreeHeapSize(), ( int ) xPortGetMinimumEverFreeHeapSize() );
/* There is no more data to return after this single string, so return
pdFALSE. */
return pdFALSE;
}
#endif /* configINCLUDE_QUERY_HEAP */
/*-----------------------------------------------------------*/
#if( configGENERATE_RUN_TIME_STATS == 1 )
static BaseType_t prvRunTimeStatsCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
{
const char * const pcHeader = " Abs Time % Time\r\n****************************************\r\n";
BaseType_t xSpacePadding;
/* Remove compile time warnings about unused parameters, and check the
write buffer is not NULL. NOTE - for simplicity, this example assumes the
write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString;
( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer );
/* Generate a table of task stats. */
strcpy( pcWriteBuffer, "Task" );
pcWriteBuffer += strlen( pcWriteBuffer );
/* Pad the string "task" with however many bytes necessary to make it the
length of a task name. Minus three for the null terminator and half the
number of characters in "Task" so the column lines up with the centre of
the heading. */
for( xSpacePadding = strlen( "Task" ); xSpacePadding < ( configMAX_TASK_NAME_LEN - 3 ); xSpacePadding++ )
{
/* Add a space to align columns after the task's name. */
*pcWriteBuffer = ' ';
pcWriteBuffer++;
/* Ensure always terminated. */
*pcWriteBuffer = 0x00;
}
strcpy( pcWriteBuffer, pcHeader );
vTaskGetRunTimeStats( pcWriteBuffer + strlen( pcHeader ) );
/* There is no more data to return after this single string, so return
pdFALSE. */
return pdFALSE;
}
#endif /* configGENERATE_RUN_TIME_STATS */
/*-----------------------------------------------------------*/
static BaseType_t prvThreeParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
{
const char *pcParameter;
BaseType_t xParameterStringLength, xReturn;
static UBaseType_t uxParameterNumber = 0;
/* Remove compile time warnings about unused parameters, and check the
write buffer is not NULL. NOTE - for simplicity, this example assumes the
write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString;
( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer );
if( uxParameterNumber == 0 )
{
/* The first time the function is called after the command has been
entered just a header string is returned. */
sprintf( pcWriteBuffer, "The three parameters were:\r\n" );
/* Next time the function is called the first parameter will be echoed
back. */
uxParameterNumber = 1U;
/* There is more data to be returned as no parameters have been echoed
back yet. */
xReturn = pdPASS;
}
else
{
/* Obtain the parameter string. */
pcParameter = FreeRTOS_CLIGetParameter
(
pcCommandString, /* The command string itself. */
uxParameterNumber, /* Return the next parameter. */
&xParameterStringLength /* Store the parameter string length. */
);
/* Sanity check something was returned. */
configASSERT( pcParameter );
/* Return the parameter string. */
memset( pcWriteBuffer, 0x00, xWriteBufferLen );
sprintf( pcWriteBuffer, "%d: ", ( int ) uxParameterNumber );
strncat( pcWriteBuffer, pcParameter, ( size_t ) xParameterStringLength );
strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) );
/* If this is the last of the three parameters then there are no more
strings to return after this one. */
if( uxParameterNumber == 3U )
{
/* If this is the last of the three parameters then there are no more
strings to return after this one. */
xReturn = pdFALSE;
uxParameterNumber = 0;
}
else
{
/* There are more parameters to return after this one. */
xReturn = pdTRUE;
uxParameterNumber++;
}
}
return xReturn;
}
/*-----------------------------------------------------------*/
static BaseType_t prvParameterEchoCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
{
const char *pcParameter;
BaseType_t xParameterStringLength, xReturn;
static UBaseType_t uxParameterNumber = 0;
/* Remove compile time warnings about unused parameters, and check the
write buffer is not NULL. NOTE - for simplicity, this example assumes the
write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString;
( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer );
if( uxParameterNumber == 0 )
{
/* The first time the function is called after the command has been
entered just a header string is returned. */
sprintf( pcWriteBuffer, "The parameters were:\r\n" );
/* Next time the function is called the first parameter will be echoed
back. */
uxParameterNumber = 1U;
/* There is more data to be returned as no parameters have been echoed
back yet. */
xReturn = pdPASS;
}
else
{
/* Obtain the parameter string. */
pcParameter = FreeRTOS_CLIGetParameter
(
pcCommandString, /* The command string itself. */
uxParameterNumber, /* Return the next parameter. */
&xParameterStringLength /* Store the parameter string length. */
);
if( pcParameter != NULL )
{
/* Return the parameter string. */
memset( pcWriteBuffer, 0x00, xWriteBufferLen );
sprintf( pcWriteBuffer, "%d: ", ( int ) uxParameterNumber );
strncat( pcWriteBuffer, ( char * ) pcParameter, ( size_t ) xParameterStringLength );
strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) );
/* There might be more parameters to return after this one. */
xReturn = pdTRUE;
uxParameterNumber++;
}
else
{
/* No more parameters were found. Make sure the write buffer does
not contain a valid string. */
pcWriteBuffer[ 0 ] = 0x00;
/* No more data to return. */
xReturn = pdFALSE;
/* Start over the next time this command is executed. */
uxParameterNumber = 0;
}
}
return xReturn;
}
/*-----------------------------------------------------------*/
#if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
static BaseType_t prvStartStopTraceCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
{
const char *pcParameter;
BaseType_t lParameterStringLength;
/* Remove compile time warnings about unused parameters, and check the
write buffer is not NULL. NOTE - for simplicity, this example assumes the
write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString;
( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer );
/* Obtain the parameter string. */
pcParameter = FreeRTOS_CLIGetParameter
(
pcCommandString, /* The command string itself. */
1, /* Return the first parameter. */
&lParameterStringLength /* Store the parameter string length. */
);
/* Sanity check something was returned. */
configASSERT( pcParameter );
/* There are only two valid parameter values. */
if( strncmp( pcParameter, "start", strlen( "start" ) ) == 0 )
{
/* Start or restart the trace. */
vTraceStop();
vTraceClear();
vTraceStart();
sprintf( pcWriteBuffer, "Trace recording (re)started.\r\n" );
}
else if( strncmp( pcParameter, "stop", strlen( "stop" ) ) == 0 )
{
/* End the trace, if one is running. */
vTraceStop();
sprintf( pcWriteBuffer, "Stopping trace recording.\r\n" );
}
else
{
sprintf( pcWriteBuffer, "Valid parameters are 'start' and 'stop'.\r\n" );
}
/* There is no more data to return after this single string, so return
pdFALSE. */
return pdFALSE;
}
#endif /* configINCLUDE_TRACE_RELATED_CLI_COMMANDS */
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
/******************************************************************************
*
* https://www.FreeRTOS.org/cli
*
******************************************************************************/
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "task.h"
/* Standard includes. */
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* FreeRTOS+CLI includes. */
#include "FreeRTOS_CLI.h"
#ifndef configINCLUDE_TRACE_RELATED_CLI_COMMANDS
#define configINCLUDE_TRACE_RELATED_CLI_COMMANDS 0
#endif
#ifndef configINCLUDE_QUERY_HEAP_COMMAND
#define configINCLUDE_QUERY_HEAP_COMMAND 0
#endif
/*
* The function that registers the commands that are defined within this file.
*/
void vRegisterSampleCLICommands( void );
/*
* Implements the task-stats command.
*/
static BaseType_t prvTaskStatsCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString );
/*
* Implements the run-time-stats command.
*/
#if ( configGENERATE_RUN_TIME_STATS == 1 )
static BaseType_t prvRunTimeStatsCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString );
#endif /* configGENERATE_RUN_TIME_STATS */
/*
* Implements the echo-three-parameters command.
*/
static BaseType_t prvThreeParameterEchoCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString );
/*
* Implements the echo-parameters command.
*/
static BaseType_t prvParameterEchoCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString );
/*
* Implements the "query heap" command.
*/
#if ( configINCLUDE_QUERY_HEAP_COMMAND == 1 )
static BaseType_t prvQueryHeapCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString );
#endif
/*
* Implements the "trace start" and "trace stop" commands;
*/
#if ( configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1 )
static BaseType_t prvStartStopTraceCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString );
#endif
/* Structure that defines the "task-stats" command line command. This generates
* a table that gives information on each task in the system. */
static const CLI_Command_Definition_t xTaskStats =
{
"task-stats", /* The command string to type. */
"\r\ntask-stats:\r\n Displays a table showing the state of each FreeRTOS task\r\n",
prvTaskStatsCommand, /* The function to run. */
0 /* No parameters are expected. */
};
/* Structure that defines the "echo_3_parameters" command line command. This
* takes exactly three parameters that the command simply echos back one at a
* time. */
static const CLI_Command_Definition_t xThreeParameterEcho =
{
"echo-3-parameters",
"\r\necho-3-parameters <param1> <param2> <param3>:\r\n Expects three parameters, echos each in turn\r\n",
prvThreeParameterEchoCommand, /* The function to run. */
3 /* Three parameters are expected, which can take any value. */
};
/* Structure that defines the "echo_parameters" command line command. This
* takes a variable number of parameters that the command simply echos back one at
* a time. */
static const CLI_Command_Definition_t xParameterEcho =
{
"echo-parameters",
"\r\necho-parameters <...>:\r\n Take variable number of parameters, echos each in turn\r\n",
prvParameterEchoCommand, /* The function to run. */
-1 /* The user can enter any number of commands. */
};
#if ( configGENERATE_RUN_TIME_STATS == 1 )
/* Structure that defines the "run-time-stats" command line command. This
* generates a table that shows how much run time each task has */
static const CLI_Command_Definition_t xRunTimeStats =
{
"run-time-stats", /* The command string to type. */
"\r\nrun-time-stats:\r\n Displays a table showing how much processing time each FreeRTOS task has used\r\n",
prvRunTimeStatsCommand, /* The function to run. */
0 /* No parameters are expected. */
};
#endif /* configGENERATE_RUN_TIME_STATS */
#if ( configINCLUDE_QUERY_HEAP_COMMAND == 1 )
/* Structure that defines the "query_heap" command line command. */
static const CLI_Command_Definition_t xQueryHeap =
{
"query-heap",
"\r\nquery-heap:\r\n Displays the free heap space, and minimum ever free heap space.\r\n",
prvQueryHeapCommand, /* The function to run. */
0 /* The user can enter any number of commands. */
};
#endif /* configQUERY_HEAP_COMMAND */
#if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
/* Structure that defines the "trace" command line command. This takes a single
* parameter, which can be either "start" or "stop". */
static const CLI_Command_Definition_t xStartStopTrace =
{
"trace",
"\r\ntrace [start | stop]:\r\n Starts or stops a trace recording for viewing in FreeRTOS+Trace\r\n",
prvStartStopTraceCommand, /* The function to run. */
1 /* One parameter is expected. Valid values are "start" and "stop". */
};
#endif /* configINCLUDE_TRACE_RELATED_CLI_COMMANDS */
/*-----------------------------------------------------------*/
void vRegisterSampleCLICommands( void )
{
/* Register all the command line commands defined immediately above. */
FreeRTOS_CLIRegisterCommand( &xTaskStats );
FreeRTOS_CLIRegisterCommand( &xThreeParameterEcho );
FreeRTOS_CLIRegisterCommand( &xParameterEcho );
#if ( configGENERATE_RUN_TIME_STATS == 1 )
{
FreeRTOS_CLIRegisterCommand( &xRunTimeStats );
}
#endif
#if ( configINCLUDE_QUERY_HEAP_COMMAND == 1 )
{
FreeRTOS_CLIRegisterCommand( &xQueryHeap );
}
#endif
#if ( configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1 )
{
FreeRTOS_CLIRegisterCommand( &xStartStopTrace );
}
#endif
}
/*-----------------------------------------------------------*/
static BaseType_t prvTaskStatsCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString )
{
const char * const pcHeader = " State Priority Stack #\r\n************************************************\r\n";
BaseType_t xSpacePadding;
/* Remove compile time warnings about unused parameters, and check the
* write buffer is not NULL. NOTE - for simplicity, this example assumes the
* write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString;
( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer );
/* Generate a table of task stats. */
strcpy( pcWriteBuffer, "Task" );
pcWriteBuffer += strlen( pcWriteBuffer );
/* Minus three for the null terminator and half the number of characters in
* "Task" so the column lines up with the centre of the heading. */
configASSERT( configMAX_TASK_NAME_LEN > 3 );
for( xSpacePadding = strlen( "Task" ); xSpacePadding < ( configMAX_TASK_NAME_LEN - 3 ); xSpacePadding++ )
{
/* Add a space to align columns after the task's name. */
*pcWriteBuffer = ' ';
pcWriteBuffer++;
/* Ensure always terminated. */
*pcWriteBuffer = 0x00;
}
strcpy( pcWriteBuffer, pcHeader );
vTaskList( pcWriteBuffer + strlen( pcHeader ) );
/* There is no more data to return after this single string, so return
* pdFALSE. */
return pdFALSE;
}
/*-----------------------------------------------------------*/
#if ( configINCLUDE_QUERY_HEAP_COMMAND == 1 )
static BaseType_t prvQueryHeapCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString )
{
/* Remove compile time warnings about unused parameters, and check the
* write buffer is not NULL. NOTE - for simplicity, this example assumes the
* write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString;
( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer );
sprintf( pcWriteBuffer, "Current free heap %d bytes, minimum ever free heap %d bytes\r\n", ( int ) xPortGetFreeHeapSize(), ( int ) xPortGetMinimumEverFreeHeapSize() );
/* There is no more data to return after this single string, so return
* pdFALSE. */
return pdFALSE;
}
#endif /* configINCLUDE_QUERY_HEAP */
/*-----------------------------------------------------------*/
#if ( configGENERATE_RUN_TIME_STATS == 1 )
static BaseType_t prvRunTimeStatsCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString )
{
const char * const pcHeader = " Abs Time % Time\r\n****************************************\r\n";
BaseType_t xSpacePadding;
/* Remove compile time warnings about unused parameters, and check the
* write buffer is not NULL. NOTE - for simplicity, this example assumes the
* write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString;
( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer );
/* Generate a table of task stats. */
strcpy( pcWriteBuffer, "Task" );
pcWriteBuffer += strlen( pcWriteBuffer );
/* Pad the string "task" with however many bytes necessary to make it the
* length of a task name. Minus three for the null terminator and half the
* number of characters in "Task" so the column lines up with the centre of
* the heading. */
for( xSpacePadding = strlen( "Task" ); xSpacePadding < ( configMAX_TASK_NAME_LEN - 3 ); xSpacePadding++ )
{
/* Add a space to align columns after the task's name. */
*pcWriteBuffer = ' ';
pcWriteBuffer++;
/* Ensure always terminated. */
*pcWriteBuffer = 0x00;
}
strcpy( pcWriteBuffer, pcHeader );
vTaskGetRunTimeStats( pcWriteBuffer + strlen( pcHeader ) );
/* There is no more data to return after this single string, so return
* pdFALSE. */
return pdFALSE;
}
#endif /* configGENERATE_RUN_TIME_STATS */
/*-----------------------------------------------------------*/
static BaseType_t prvThreeParameterEchoCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString )
{
const char * pcParameter;
BaseType_t xParameterStringLength, xReturn;
static UBaseType_t uxParameterNumber = 0;
/* Remove compile time warnings about unused parameters, and check the
* write buffer is not NULL. NOTE - for simplicity, this example assumes the
* write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString;
( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer );
if( uxParameterNumber == 0 )
{
/* The first time the function is called after the command has been
* entered just a header string is returned. */
sprintf( pcWriteBuffer, "The three parameters were:\r\n" );
/* Next time the function is called the first parameter will be echoed
* back. */
uxParameterNumber = 1U;
/* There is more data to be returned as no parameters have been echoed
* back yet. */
xReturn = pdPASS;
}
else
{
/* Obtain the parameter string. */
pcParameter = FreeRTOS_CLIGetParameter
(
pcCommandString, /* The command string itself. */
uxParameterNumber, /* Return the next parameter. */
&xParameterStringLength /* Store the parameter string length. */
);
/* Sanity check something was returned. */
configASSERT( pcParameter );
/* Return the parameter string. */
memset( pcWriteBuffer, 0x00, xWriteBufferLen );
sprintf( pcWriteBuffer, "%d: ", ( int ) uxParameterNumber );
strncat( pcWriteBuffer, pcParameter, ( size_t ) xParameterStringLength );
strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) );
/* If this is the last of the three parameters then there are no more
* strings to return after this one. */
if( uxParameterNumber == 3U )
{
/* If this is the last of the three parameters then there are no more
* strings to return after this one. */
xReturn = pdFALSE;
uxParameterNumber = 0;
}
else
{
/* There are more parameters to return after this one. */
xReturn = pdTRUE;
uxParameterNumber++;
}
}
return xReturn;
}
/*-----------------------------------------------------------*/
static BaseType_t prvParameterEchoCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString )
{
const char * pcParameter;
BaseType_t xParameterStringLength, xReturn;
static UBaseType_t uxParameterNumber = 0;
/* Remove compile time warnings about unused parameters, and check the
* write buffer is not NULL. NOTE - for simplicity, this example assumes the
* write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString;
( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer );
if( uxParameterNumber == 0 )
{
/* The first time the function is called after the command has been
* entered just a header string is returned. */
sprintf( pcWriteBuffer, "The parameters were:\r\n" );
/* Next time the function is called the first parameter will be echoed
* back. */
uxParameterNumber = 1U;
/* There is more data to be returned as no parameters have been echoed
* back yet. */
xReturn = pdPASS;
}
else
{
/* Obtain the parameter string. */
pcParameter = FreeRTOS_CLIGetParameter
(
pcCommandString, /* The command string itself. */
uxParameterNumber, /* Return the next parameter. */
&xParameterStringLength /* Store the parameter string length. */
);
if( pcParameter != NULL )
{
/* Return the parameter string. */
memset( pcWriteBuffer, 0x00, xWriteBufferLen );
sprintf( pcWriteBuffer, "%d: ", ( int ) uxParameterNumber );
strncat( pcWriteBuffer, ( char * ) pcParameter, ( size_t ) xParameterStringLength );
strncat( pcWriteBuffer, "\r\n", strlen( "\r\n" ) );
/* There might be more parameters to return after this one. */
xReturn = pdTRUE;
uxParameterNumber++;
}
else
{
/* No more parameters were found. Make sure the write buffer does
* not contain a valid string. */
pcWriteBuffer[ 0 ] = 0x00;
/* No more data to return. */
xReturn = pdFALSE;
/* Start over the next time this command is executed. */
uxParameterNumber = 0;
}
}
return xReturn;
}
/*-----------------------------------------------------------*/
#if configINCLUDE_TRACE_RELATED_CLI_COMMANDS == 1
static BaseType_t prvStartStopTraceCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString )
{
const char * pcParameter;
BaseType_t lParameterStringLength;
/* Remove compile time warnings about unused parameters, and check the
* write buffer is not NULL. NOTE - for simplicity, this example assumes the
* write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString;
( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer );
/* Obtain the parameter string. */
pcParameter = FreeRTOS_CLIGetParameter
(
pcCommandString, /* The command string itself. */
1, /* Return the first parameter. */
&lParameterStringLength /* Store the parameter string length. */
);
/* Sanity check something was returned. */
configASSERT( pcParameter );
/* There are only two valid parameter values. */
if( strncmp( pcParameter, "start", strlen( "start" ) ) == 0 )
{
/* Start or restart the trace. */
vTraceStop();
vTraceClear();
vTraceStart();
sprintf( pcWriteBuffer, "Trace recording (re)started.\r\n" );
}
else if( strncmp( pcParameter, "stop", strlen( "stop" ) ) == 0 )
{
/* End the trace, if one is running. */
vTraceStop();
sprintf( pcWriteBuffer, "Stopping trace recording.\r\n" );
}
else
{
sprintf( pcWriteBuffer, "Valid parameters are 'start' and 'stop'.\r\n" );
}
/* There is no more data to return after this single string, so return
* pdFALSE. */
return pdFALSE;
}
#endif /* configINCLUDE_TRACE_RELATED_CLI_COMMANDS */

@ -1,225 +1,227 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://aws.amazon.com/freertos
*
*/
/*
* NOTE: This file uses a third party USB CDC driver.
*/
/* Standard includes. */
#include "string.h"
#include "stdio.h"
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"
/* Example includes. */
#include "FreeRTOS_CLI.h"
/* Demo application includes. */
#include "serial.h"
/* Dimensions the buffer into which input characters are placed. */
#define cmdMAX_INPUT_SIZE 50
/* Dimentions a buffer to be used by the UART driver, if the UART driver uses a
buffer at all. */
#define cmdQUEUE_LENGTH 25
/* DEL acts as a backspace. */
#define cmdASCII_DEL ( 0x7F )
/* The maximum time to wait for the mutex that guards the UART to become
available. */
#define cmdMAX_MUTEX_WAIT pdMS_TO_TICKS( 300 )
#ifndef configCLI_BAUD_RATE
#define configCLI_BAUD_RATE 115200
#endif
/*-----------------------------------------------------------*/
/*
* The task that implements the command console processing.
*/
static void prvUARTCommandConsoleTask( void *pvParameters );
void vUARTCommandConsoleStart( uint16_t usStackSize, UBaseType_t uxPriority );
/*-----------------------------------------------------------*/
/* Const messages output by the command console. */
static const char * const pcWelcomeMessage = "FreeRTOS command server.\r\nType Help to view a list of registered commands.\r\n\r\n>";
static const char * const pcEndOfOutputMessage = "\r\n[Press ENTER to execute the previous command again]\r\n>";
static const char * const pcNewLine = "\r\n";
/* Used to guard access to the UART in case messages are sent to the UART from
more than one task. */
static SemaphoreHandle_t xTxMutex = NULL;
/* The handle to the UART port, which is not used by all ports. */
static xComPortHandle xPort = 0;
/*-----------------------------------------------------------*/
void vUARTCommandConsoleStart( uint16_t usStackSize, UBaseType_t uxPriority )
{
/* Create the semaphore used to access the UART Tx. */
xTxMutex = xSemaphoreCreateMutex();
configASSERT( xTxMutex );
/* Create that task that handles the console itself. */
xTaskCreate( prvUARTCommandConsoleTask, /* The task that implements the command console. */
"CLI", /* Text name assigned to the task. This is just to assist debugging. The kernel does not use this name itself. */
usStackSize, /* The size of the stack allocated to the task. */
NULL, /* The parameter is not used, so NULL is passed. */
uxPriority, /* The priority allocated to the task. */
NULL ); /* A handle is not required, so just pass NULL. */
}
/*-----------------------------------------------------------*/
static void prvUARTCommandConsoleTask( void *pvParameters )
{
signed char cRxedChar;
uint8_t ucInputIndex = 0;
char *pcOutputString;
static char cInputString[ cmdMAX_INPUT_SIZE ], cLastInputString[ cmdMAX_INPUT_SIZE ];
BaseType_t xReturned;
xComPortHandle xPort;
( void ) pvParameters;
/* Obtain the address of the output buffer. Note there is no mutual
exclusion on this buffer as it is assumed only one command console interface
will be used at any one time. */
pcOutputString = FreeRTOS_CLIGetOutputBuffer();
/* Initialise the UART. */
xPort = xSerialPortInitMinimal( configCLI_BAUD_RATE, cmdQUEUE_LENGTH );
/* Send the welcome message. */
vSerialPutString( xPort, ( signed char * ) pcWelcomeMessage, ( unsigned short ) strlen( pcWelcomeMessage ) );
for( ;; )
{
/* Wait for the next character. The while loop is used in case
INCLUDE_vTaskSuspend is not set to 1 - in which case portMAX_DELAY will
be a genuine block time rather than an infinite block time. */
while( xSerialGetChar( xPort, &cRxedChar, portMAX_DELAY ) != pdPASS );
/* Ensure exclusive access to the UART Tx. */
if( xSemaphoreTake( xTxMutex, cmdMAX_MUTEX_WAIT ) == pdPASS )
{
/* Echo the character back. */
xSerialPutChar( xPort, cRxedChar, portMAX_DELAY );
/* Was it the end of the line? */
if( cRxedChar == '\n' || cRxedChar == '\r' )
{
/* Just to space the output from the input. */
vSerialPutString( xPort, ( signed char * ) pcNewLine, ( unsigned short ) strlen( pcNewLine ) );
/* See if the command is empty, indicating that the last command
is to be executed again. */
if( ucInputIndex == 0 )
{
/* Copy the last command back into the input string. */
strcpy( cInputString, cLastInputString );
}
/* Pass the received command to the command interpreter. The
command interpreter is called repeatedly until it returns
pdFALSE (indicating there is no more output) as it might
generate more than one string. */
do
{
/* Get the next output string from the command interpreter. */
xReturned = FreeRTOS_CLIProcessCommand( cInputString, pcOutputString, configCOMMAND_INT_MAX_OUTPUT_SIZE );
/* Write the generated string to the UART. */
vSerialPutString( xPort, ( signed char * ) pcOutputString, ( unsigned short ) strlen( pcOutputString ) );
} while( xReturned != pdFALSE );
/* All the strings generated by the input command have been
sent. Clear the input string ready to receive the next command.
Remember the command that was just processed first in case it is
to be processed again. */
strcpy( cLastInputString, cInputString );
ucInputIndex = 0;
memset( cInputString, 0x00, cmdMAX_INPUT_SIZE );
vSerialPutString( xPort, ( signed char * ) pcEndOfOutputMessage, ( unsigned short ) strlen( pcEndOfOutputMessage ) );
}
else
{
if( cRxedChar == '\r' )
{
/* Ignore the character. */
}
else if( ( cRxedChar == '\b' ) || ( cRxedChar == cmdASCII_DEL ) )
{
/* Backspace was pressed. Erase the last character in the
string - if any. */
if( ucInputIndex > 0 )
{
ucInputIndex--;
cInputString[ ucInputIndex ] = '\0';
}
}
else
{
/* A character was entered. Add it to the string entered so
far. When a \n is entered the complete string will be
passed to the command interpreter. */
if( ( cRxedChar >= ' ' ) && ( cRxedChar <= '~' ) )
{
if( ucInputIndex < cmdMAX_INPUT_SIZE )
{
cInputString[ ucInputIndex ] = cRxedChar;
ucInputIndex++;
}
}
}
}
/* Must ensure to give the mutex back. */
xSemaphoreGive( xTxMutex );
}
}
}
/*-----------------------------------------------------------*/
void vOutputString( const char * const pcMessage )
{
if( xSemaphoreTake( xTxMutex, cmdMAX_MUTEX_WAIT ) == pdPASS )
{
vSerialPutString( xPort, ( signed char * ) pcMessage, ( unsigned short ) strlen( pcMessage ) );
xSemaphoreGive( xTxMutex );
}
}
/*-----------------------------------------------------------*/
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
/*
* NOTE: This file uses a third party USB CDC driver.
*/
/* Standard includes. */
#include "string.h"
#include "stdio.h"
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"
/* Example includes. */
#include "FreeRTOS_CLI.h"
/* Demo application includes. */
#include "serial.h"
/* Dimensions the buffer into which input characters are placed. */
#define cmdMAX_INPUT_SIZE 50
/* Dimensions a buffer to be used by the UART driver, if the UART driver uses a
* buffer at all. */
#define cmdQUEUE_LENGTH 25
/* DEL acts as a backspace. */
#define cmdASCII_DEL ( 0x7F )
/* The maximum time to wait for the mutex that guards the UART to become
* available. */
#define cmdMAX_MUTEX_WAIT pdMS_TO_TICKS( 300 )
#ifndef configCLI_BAUD_RATE
#define configCLI_BAUD_RATE 115200
#endif
/*-----------------------------------------------------------*/
/*
* The task that implements the command console processing.
*/
static void prvUARTCommandConsoleTask( void * pvParameters );
void vUARTCommandConsoleStart( uint16_t usStackSize,
UBaseType_t uxPriority );
/*-----------------------------------------------------------*/
/* Const messages output by the command console. */
static const char * const pcWelcomeMessage = "FreeRTOS command server.\r\nType Help to view a list of registered commands.\r\n\r\n>";
static const char * const pcEndOfOutputMessage = "\r\n[Press ENTER to execute the previous command again]\r\n>";
static const char * const pcNewLine = "\r\n";
/* Used to guard access to the UART in case messages are sent to the UART from
* more than one task. */
static SemaphoreHandle_t xTxMutex = NULL;
/* The handle to the UART port, which is not used by all ports. */
static xComPortHandle xPort = 0;
/*-----------------------------------------------------------*/
void vUARTCommandConsoleStart( uint16_t usStackSize,
UBaseType_t uxPriority )
{
/* Create the semaphore used to access the UART Tx. */
xTxMutex = xSemaphoreCreateMutex();
configASSERT( xTxMutex );
/* Create that task that handles the console itself. */
xTaskCreate( prvUARTCommandConsoleTask, /* The task that implements the command console. */
"CLI", /* Text name assigned to the task. This is just to assist debugging. The kernel does not use this name itself. */
usStackSize, /* The size of the stack allocated to the task. */
NULL, /* The parameter is not used, so NULL is passed. */
uxPriority, /* The priority allocated to the task. */
NULL ); /* A handle is not required, so just pass NULL. */
}
/*-----------------------------------------------------------*/
static void prvUARTCommandConsoleTask( void * pvParameters )
{
signed char cRxedChar;
uint8_t ucInputIndex = 0;
char * pcOutputString;
static char cInputString[ cmdMAX_INPUT_SIZE ], cLastInputString[ cmdMAX_INPUT_SIZE ];
BaseType_t xReturned;
xComPortHandle xPort;
( void ) pvParameters;
/* Obtain the address of the output buffer. Note there is no mutual
* exclusion on this buffer as it is assumed only one command console interface
* will be used at any one time. */
pcOutputString = FreeRTOS_CLIGetOutputBuffer();
/* Initialise the UART. */
xPort = xSerialPortInitMinimal( configCLI_BAUD_RATE, cmdQUEUE_LENGTH );
/* Send the welcome message. */
vSerialPutString( xPort, ( signed char * ) pcWelcomeMessage, ( unsigned short ) strlen( pcWelcomeMessage ) );
for( ; ; )
{
/* Wait for the next character. The while loop is used in case
* INCLUDE_vTaskSuspend is not set to 1 - in which case portMAX_DELAY will
* be a genuine block time rather than an infinite block time. */
while( xSerialGetChar( xPort, &cRxedChar, portMAX_DELAY ) != pdPASS )
{
}
/* Ensure exclusive access to the UART Tx. */
if( xSemaphoreTake( xTxMutex, cmdMAX_MUTEX_WAIT ) == pdPASS )
{
/* Echo the character back. */
xSerialPutChar( xPort, cRxedChar, portMAX_DELAY );
/* Was it the end of the line? */
if( ( cRxedChar == '\n' ) || ( cRxedChar == '\r' ) )
{
/* Just to space the output from the input. */
vSerialPutString( xPort, ( signed char * ) pcNewLine, ( unsigned short ) strlen( pcNewLine ) );
/* See if the command is empty, indicating that the last command
* is to be executed again. */
if( ucInputIndex == 0 )
{
/* Copy the last command back into the input string. */
strcpy( cInputString, cLastInputString );
}
/* Pass the received command to the command interpreter. The
* command interpreter is called repeatedly until it returns
* pdFALSE (indicating there is no more output) as it might
* generate more than one string. */
do
{
/* Get the next output string from the command interpreter. */
xReturned = FreeRTOS_CLIProcessCommand( cInputString, pcOutputString, configCOMMAND_INT_MAX_OUTPUT_SIZE );
/* Write the generated string to the UART. */
vSerialPutString( xPort, ( signed char * ) pcOutputString, ( unsigned short ) strlen( pcOutputString ) );
} while( xReturned != pdFALSE );
/* All the strings generated by the input command have been
* sent. Clear the input string ready to receive the next command.
* Remember the command that was just processed first in case it is
* to be processed again. */
strcpy( cLastInputString, cInputString );
ucInputIndex = 0;
memset( cInputString, 0x00, cmdMAX_INPUT_SIZE );
vSerialPutString( xPort, ( signed char * ) pcEndOfOutputMessage, ( unsigned short ) strlen( pcEndOfOutputMessage ) );
}
else
{
if( cRxedChar == '\r' )
{
/* Ignore the character. */
}
else if( ( cRxedChar == '\b' ) || ( cRxedChar == cmdASCII_DEL ) )
{
/* Backspace was pressed. Erase the last character in the
* string - if any. */
if( ucInputIndex > 0 )
{
ucInputIndex--;
cInputString[ ucInputIndex ] = '\0';
}
}
else
{
/* A character was entered. Add it to the string entered so
* far. When a \n is entered the complete string will be
* passed to the command interpreter. */
if( ( cRxedChar >= ' ' ) && ( cRxedChar <= '~' ) )
{
if( ucInputIndex < cmdMAX_INPUT_SIZE )
{
cInputString[ ucInputIndex ] = cRxedChar;
ucInputIndex++;
}
}
}
}
/* Must ensure to give the mutex back. */
xSemaphoreGive( xTxMutex );
}
}
}
/*-----------------------------------------------------------*/
void vOutputString( const char * const pcMessage )
{
if( xSemaphoreTake( xTxMutex, cmdMAX_MUTEX_WAIT ) == pdPASS )
{
vSerialPutString( xPort, ( signed char * ) pcMessage, ( unsigned short ) strlen( pcMessage ) );
xSemaphoreGive( xTxMutex );
}
}
/*-----------------------------------------------------------*/

@ -1,328 +1,339 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
/******************************************************************************
*
* See the following URL for information on the commands defined in this file:
* https://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/Embedded_Ethernet_Examples/Ethernet_Related_CLI_Commands.shtml
*
******************************************************************************/
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "task.h"
/* Standard includes. */
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
/* FreeRTOS+CLI includes. */
#include "FreeRTOS_CLI.h"
/* FreeRTOS+UDP includes, just to make the stats available to the CLI
commands. */
#include "FreeRTOS_UDP_IP.h"
#include "FreeRTOS_Sockets.h"
/*
* Defines a command that prints out IP address information.
*/
static BaseType_t prvDisplayIPConfig( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
/*
* Defines a command that prints out the gathered demo debug stats.
*/
static BaseType_t prvDisplayIPDebugStats( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
/*
* Defines a command that sends an ICMP ping request to an IP address.
*/
static BaseType_t prvPingCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
/* Structure that defines the "ip-config" command line command. */
static const CLI_Command_Definition_t xIPConfig =
{
"ip-config",
"ip-config:\r\n Displays IP address configuration\r\n\r\n",
prvDisplayIPConfig,
0
};
#if configINCLUDE_DEMO_DEBUG_STATS != 0
/* Structure that defines the "ip-debug-stats" command line command. */
static const CLI_Command_Definition_t xIPDebugStats =
{
"ip-debug-stats", /* The command string to type. */
"ip-debug-stats:\r\n Shows some IP stack stats useful for debug - an example only.\r\n\r\n",
prvDisplayIPDebugStats, /* The function to run. */
0 /* No parameters are expected. */
};
#endif /* configINCLUDE_DEMO_DEBUG_STATS */
#if ipconfigSUPPORT_OUTGOING_PINGS == 1
/* Structure that defines the "ping" command line command. This takes an IP
address or host name and (optionally) the number of bytes to ping as
parameters. */
static const CLI_Command_Definition_t xPing =
{
"ping",
"ping <ipaddress> <optional:bytes to send>:\r\n for example, ping 192.168.0.3 8, or ping www.example.com\r\n\r\n",
prvPingCommand, /* The function to run. */
-1 /* Ping can take either one or two parameter, so the number of parameters has to be determined by the ping command implementation. */
};
#endif /* ipconfigSUPPORT_OUTGOING_PINGS */
/*-----------------------------------------------------------*/
void vRegisterUDPCLICommands( void )
{
/* Register all the command line commands defined immediately above. */
FreeRTOS_CLIRegisterCommand( &xIPConfig );
#if configINCLUDE_DEMO_DEBUG_STATS == 1
{
FreeRTOS_CLIRegisterCommand( &xIPDebugStats );
}
#endif /* configINCLUDE_DEMO_DEBUG_STATS */
#if ipconfigSUPPORT_OUTGOING_PINGS == 1
{
FreeRTOS_CLIRegisterCommand( &xPing );
}
#endif /* ipconfigSUPPORT_OUTGOING_PINGS */
}
/*-----------------------------------------------------------*/
#if ipconfigSUPPORT_OUTGOING_PINGS == 1
static BaseType_t prvPingCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
{
char * pcParameter;
BaseType_t lParameterStringLength, xReturn;
uint32_t ulIPAddress, ulBytesToPing;
const uint32_t ulDefaultBytesToPing = 8UL;
char cBuffer[ 16 ];
/* Remove compile time warnings about unused parameters, and check the
write buffer is not NULL. NOTE - for simplicity, this example assumes the
write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString;
( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer );
/* Start with an empty string. */
pcWriteBuffer[ 0 ] = 0x00;
/* Obtain the number of bytes to ping. */
pcParameter = ( char * ) FreeRTOS_CLIGetParameter
(
pcCommandString, /* The command string itself. */
2, /* Return the second parameter. */
&lParameterStringLength /* Store the parameter string length. */
);
if( pcParameter == NULL )
{
/* The number of bytes was not specified, so default it. */
ulBytesToPing = ulDefaultBytesToPing;
}
else
{
ulBytesToPing = atol( pcParameter );
}
/* Obtain the IP address string. */
pcParameter = ( char * ) FreeRTOS_CLIGetParameter
(
pcCommandString, /* The command string itself. */
1, /* Return the first parameter. */
&lParameterStringLength /* Store the parameter string length. */
);
/* Sanity check something was returned. */
configASSERT( pcParameter );
/* Attempt to obtain the IP address. If the first character is not a
digit, assume the host name has been passed in. */
if( ( *pcParameter >= '0' ) && ( *pcParameter <= '9' ) )
{
ulIPAddress = FreeRTOS_inet_addr( pcParameter );
}
else
{
/* Terminate the host name. */
pcParameter[ lParameterStringLength ] = 0x00;
/* Attempt to resolve host. */
ulIPAddress = FreeRTOS_gethostbyname( pcParameter );
}
/* Convert IP address, which may have come from a DNS lookup, to string. */
FreeRTOS_inet_ntoa( ulIPAddress, cBuffer );
if( ulIPAddress != 0 )
{
xReturn = FreeRTOS_SendPingRequest( ulIPAddress, ( uint16_t ) ulBytesToPing, portMAX_DELAY );
}
else
{
xReturn = pdFALSE;
}
if( xReturn == pdFALSE )
{
sprintf( pcWriteBuffer, "%s", "Could not send ping request\r\n" );
}
else
{
sprintf( pcWriteBuffer, "Ping sent to %s with identifier %d\r\n", cBuffer, ( int ) xReturn );
}
return pdFALSE;
}
/*-----------------------------------------------------------*/
#endif /* ipconfigSUPPORT_OUTGOING_PINGS */
#if configINCLUDE_DEMO_DEBUG_STATS != 0
static BaseType_t prvDisplayIPDebugStats( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
{
static BaseType_t xIndex = -1;
extern xExampleDebugStatEntry_t xIPTraceValues[];
BaseType_t xReturn;
/* Remove compile time warnings about unused parameters, and check the
write buffer is not NULL. NOTE - for simplicity, this example assumes the
write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString;
( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer );
xIndex++;
if( xIndex < xExampleDebugStatEntries() )
{
sprintf( pcWriteBuffer, "%s %d\r\n", ( char * ) xIPTraceValues[ xIndex ].pucDescription, ( int ) xIPTraceValues[ xIndex ].ulData );
xReturn = pdPASS;
}
else
{
/* Reset the index for the next time it is called. */
xIndex = -1;
/* Ensure nothing remains in the write buffer. */
pcWriteBuffer[ 0 ] = 0x00;
xReturn = pdFALSE;
}
return xReturn;
}
/*-----------------------------------------------------------*/
#endif /* configINCLUDE_DEMO_DEBUG_STATS */
static BaseType_t prvDisplayIPConfig( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
{
static BaseType_t xIndex = 0;
BaseType_t xReturn;
uint32_t ulAddress;
/* Remove compile time warnings about unused parameters, and check the
write buffer is not NULL. NOTE - for simplicity, this example assumes the
write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString;
( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer );
switch( xIndex )
{
case 0 :
#if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 )
FreeRTOS_GetEndPointConfiguration( &ulAddress, NULL, NULL, NULL, pxNetworkEndPoints );
#else
FreeRTOS_GetAddressConfiguration( &ulAddress, NULL, NULL, NULL );
#endif /* defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 ) */
sprintf( pcWriteBuffer, "\r\nIP address " );
xReturn = pdTRUE;
xIndex++;
break;
case 1 :
#if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 )
FreeRTOS_GetEndPointConfiguration( NULL, &ulAddress, NULL, NULL, pxNetworkEndPoints );
#else
FreeRTOS_GetAddressConfiguration( NULL, &ulAddress, NULL, NULL );
#endif /* defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 ) */
sprintf( pcWriteBuffer, "\r\nNet mask " );
xReturn = pdTRUE;
xIndex++;
break;
case 2 :
#if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 )
FreeRTOS_GetEndPointConfiguration( NULL, NULL, &ulAddress, NULL, pxNetworkEndPoints );
#else
FreeRTOS_GetAddressConfiguration( NULL, NULL, &ulAddress, NULL );
#endif /* defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 ) */
sprintf( pcWriteBuffer, "\r\nGateway address " );
xReturn = pdTRUE;
xIndex++;
break;
case 3 :
#if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 )
FreeRTOS_GetEndPointConfiguration( NULL, NULL, NULL, &ulAddress, pxNetworkEndPoints );
#else
FreeRTOS_GetAddressConfiguration( NULL, NULL, NULL, &ulAddress );
#endif /* defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 ) */
sprintf( pcWriteBuffer, "\r\nDNS server address " );
xReturn = pdTRUE;
xIndex++;
break;
default :
ulAddress = 0;
sprintf( pcWriteBuffer, "\r\n\r\n" );
xReturn = pdFALSE;
xIndex = 0;
break;
}
if( ulAddress != 0 )
{
FreeRTOS_inet_ntoa( ulAddress, ( &( pcWriteBuffer[ strlen( pcWriteBuffer ) ] ) ) );
}
return xReturn;
}
/*-----------------------------------------------------------*/
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
/******************************************************************************
*
* See the following URL for information on the commands defined in this file:
* https://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/Embedded_Ethernet_Examples/Ethernet_Related_CLI_Commands.shtml
*
******************************************************************************/
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "task.h"
/* Standard includes. */
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
/* FreeRTOS+CLI includes. */
#include "FreeRTOS_CLI.h"
/* FreeRTOS+UDP includes, just to make the stats available to the CLI
* commands. */
#include "FreeRTOS_UDP_IP.h"
#include "FreeRTOS_Sockets.h"
/*
* Defines a command that prints out IP address information.
*/
static BaseType_t prvDisplayIPConfig( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString );
/*
* Defines a command that prints out the gathered demo debug stats.
*/
static BaseType_t prvDisplayIPDebugStats( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString );
/*
* Defines a command that sends an ICMP ping request to an IP address.
*/
static BaseType_t prvPingCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString );
/* Structure that defines the "ip-config" command line command. */
static const CLI_Command_Definition_t xIPConfig =
{
"ip-config",
"ip-config:\r\n Displays IP address configuration\r\n\r\n",
prvDisplayIPConfig,
0
};
#if configINCLUDE_DEMO_DEBUG_STATS != 0
/* Structure that defines the "ip-debug-stats" command line command. */
static const CLI_Command_Definition_t xIPDebugStats =
{
"ip-debug-stats", /* The command string to type. */
"ip-debug-stats:\r\n Shows some IP stack stats useful for debug - an example only.\r\n\r\n",
prvDisplayIPDebugStats, /* The function to run. */
0 /* No parameters are expected. */
};
#endif /* configINCLUDE_DEMO_DEBUG_STATS */
#if ipconfigSUPPORT_OUTGOING_PINGS == 1
/* Structure that defines the "ping" command line command. This takes an IP
* address or host name and (optionally) the number of bytes to ping as
* parameters. */
static const CLI_Command_Definition_t xPing =
{
"ping",
"ping <ipaddress> <optional:bytes to send>:\r\n for example, ping 192.168.0.3 8, or ping www.example.com\r\n\r\n",
prvPingCommand, /* The function to run. */
-1 /* Ping can take either one or two parameter, so the number of parameters has to be determined by the ping command implementation. */
};
#endif /* ipconfigSUPPORT_OUTGOING_PINGS */
/*-----------------------------------------------------------*/
void vRegisterUDPCLICommands( void )
{
/* Register all the command line commands defined immediately above. */
FreeRTOS_CLIRegisterCommand( &xIPConfig );
#if configINCLUDE_DEMO_DEBUG_STATS == 1
{
FreeRTOS_CLIRegisterCommand( &xIPDebugStats );
}
#endif /* configINCLUDE_DEMO_DEBUG_STATS */
#if ipconfigSUPPORT_OUTGOING_PINGS == 1
{
FreeRTOS_CLIRegisterCommand( &xPing );
}
#endif /* ipconfigSUPPORT_OUTGOING_PINGS */
}
/*-----------------------------------------------------------*/
#if ipconfigSUPPORT_OUTGOING_PINGS == 1
static BaseType_t prvPingCommand( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString )
{
char * pcParameter;
BaseType_t lParameterStringLength, xReturn;
uint32_t ulIPAddress, ulBytesToPing;
const uint32_t ulDefaultBytesToPing = 8UL;
char cBuffer[ 16 ];
/* Remove compile time warnings about unused parameters, and check the
* write buffer is not NULL. NOTE - for simplicity, this example assumes the
* write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString;
( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer );
/* Start with an empty string. */
pcWriteBuffer[ 0 ] = 0x00;
/* Obtain the number of bytes to ping. */
pcParameter = ( char * ) FreeRTOS_CLIGetParameter
(
pcCommandString, /* The command string itself. */
2, /* Return the second parameter. */
&lParameterStringLength /* Store the parameter string length. */
);
if( pcParameter == NULL )
{
/* The number of bytes was not specified, so default it. */
ulBytesToPing = ulDefaultBytesToPing;
}
else
{
ulBytesToPing = atol( pcParameter );
}
/* Obtain the IP address string. */
pcParameter = ( char * ) FreeRTOS_CLIGetParameter
(
pcCommandString, /* The command string itself. */
1, /* Return the first parameter. */
&lParameterStringLength /* Store the parameter string length. */
);
/* Sanity check something was returned. */
configASSERT( pcParameter );
/* Attempt to obtain the IP address. If the first character is not a
* digit, assume the host name has been passed in. */
if( ( *pcParameter >= '0' ) && ( *pcParameter <= '9' ) )
{
ulIPAddress = FreeRTOS_inet_addr( pcParameter );
}
else
{
/* Terminate the host name. */
pcParameter[ lParameterStringLength ] = 0x00;
/* Attempt to resolve host. */
ulIPAddress = FreeRTOS_gethostbyname( pcParameter );
}
/* Convert IP address, which may have come from a DNS lookup, to string. */
FreeRTOS_inet_ntoa( ulIPAddress, cBuffer );
if( ulIPAddress != 0 )
{
xReturn = FreeRTOS_SendPingRequest( ulIPAddress, ( uint16_t ) ulBytesToPing, portMAX_DELAY );
}
else
{
xReturn = pdFALSE;
}
if( xReturn == pdFALSE )
{
sprintf( pcWriteBuffer, "%s", "Could not send ping request\r\n" );
}
else
{
sprintf( pcWriteBuffer, "Ping sent to %s with identifier %d\r\n", cBuffer, ( int ) xReturn );
}
return pdFALSE;
}
/*-----------------------------------------------------------*/
#endif /* ipconfigSUPPORT_OUTGOING_PINGS */
#if configINCLUDE_DEMO_DEBUG_STATS != 0
static BaseType_t prvDisplayIPDebugStats( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString )
{
static BaseType_t xIndex = -1;
extern xExampleDebugStatEntry_t xIPTraceValues[];
BaseType_t xReturn;
/* Remove compile time warnings about unused parameters, and check the
* write buffer is not NULL. NOTE - for simplicity, this example assumes the
* write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString;
( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer );
xIndex++;
if( xIndex < xExampleDebugStatEntries() )
{
sprintf( pcWriteBuffer, "%s %d\r\n", ( char * ) xIPTraceValues[ xIndex ].pucDescription, ( int ) xIPTraceValues[ xIndex ].ulData );
xReturn = pdPASS;
}
else
{
/* Reset the index for the next time it is called. */
xIndex = -1;
/* Ensure nothing remains in the write buffer. */
pcWriteBuffer[ 0 ] = 0x00;
xReturn = pdFALSE;
}
return xReturn;
}
/*-----------------------------------------------------------*/
#endif /* configINCLUDE_DEMO_DEBUG_STATS */
static BaseType_t prvDisplayIPConfig( char * pcWriteBuffer,
size_t xWriteBufferLen,
const char * pcCommandString )
{
static BaseType_t xIndex = 0;
BaseType_t xReturn;
uint32_t ulAddress;
/* Remove compile time warnings about unused parameters, and check the
* write buffer is not NULL. NOTE - for simplicity, this example assumes the
* write buffer length is adequate, so does not check for buffer overflows. */
( void ) pcCommandString;
( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer );
switch( xIndex )
{
case 0:
#if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 )
FreeRTOS_GetEndPointConfiguration( &ulAddress, NULL, NULL, NULL, pxNetworkEndPoints );
#else
FreeRTOS_GetAddressConfiguration( &ulAddress, NULL, NULL, NULL );
#endif /* defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 ) */
sprintf( pcWriteBuffer, "\r\nIP address " );
xReturn = pdTRUE;
xIndex++;
break;
case 1:
#if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 )
FreeRTOS_GetEndPointConfiguration( NULL, &ulAddress, NULL, NULL, pxNetworkEndPoints );
#else
FreeRTOS_GetAddressConfiguration( NULL, &ulAddress, NULL, NULL );
#endif /* defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 ) */
sprintf( pcWriteBuffer, "\r\nNet mask " );
xReturn = pdTRUE;
xIndex++;
break;
case 2:
#if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 )
FreeRTOS_GetEndPointConfiguration( NULL, NULL, &ulAddress, NULL, pxNetworkEndPoints );
#else
FreeRTOS_GetAddressConfiguration( NULL, NULL, &ulAddress, NULL );
#endif /* defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 ) */
sprintf( pcWriteBuffer, "\r\nGateway address " );
xReturn = pdTRUE;
xIndex++;
break;
case 3:
#if defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 )
FreeRTOS_GetEndPointConfiguration( NULL, NULL, NULL, &ulAddress, pxNetworkEndPoints );
#else
FreeRTOS_GetAddressConfiguration( NULL, NULL, NULL, &ulAddress );
#endif /* defined( ipconfigIPv4_BACKWARD_COMPATIBLE ) && ( ipconfigIPv4_BACKWARD_COMPATIBLE == 0 ) */
sprintf( pcWriteBuffer, "\r\nDNS server address " );
xReturn = pdTRUE;
xIndex++;
break;
default:
ulAddress = 0;
sprintf( pcWriteBuffer, "\r\n\r\n" );
xReturn = pdFALSE;
xIndex = 0;
break;
}
if( ulAddress != 0 )
{
FreeRTOS_inet_ntoa( ulAddress, ( &( pcWriteBuffer[ strlen( pcWriteBuffer ) ] ) ) );
}
return xReturn;
}
/*-----------------------------------------------------------*/

@ -1,320 +1,316 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://aws.amazon.com/freertos
*
*/
/*******************************************************************************
* See the URL in the comments within main.c for the location of the online
* documentation.
******************************************************************************/
/* Standard includes. */
#include <stdio.h>
#include <string.h>
/* FreeRTOS includes. */
#include "FreeRTOS.h"
/* File system includes. */
#include "fat_sl.h"
#include "api_mdriver_ram.h"
/* 8.3 format, plus null terminator. */
#define fsMAX_FILE_NAME_LEN 13
/* The number of bytes read/written to the example files at a time. */
#define fsRAM_BUFFER_SIZE 200
/* The number of bytes written to the file that uses f_putc() and f_getc(). */
#define fsPUTC_FILE_SIZE 100
/*-----------------------------------------------------------*/
/*
* Creates and verifies different files on the volume, demonstrating the use of
* various different API functions.
*/
void vCreateAndVerifySampleFiles( void );
/*
* Create a set of example files in the root directory of the volume using
* f_write().
*/
static void prvCreateDemoFilesUsing_f_write( void );
/*
* Use f_read() to read back and verify the files that were created by
* prvCreateDemoFilesUsing_f_write().
*/
static void prvVerifyDemoFileUsing_f_read( void );
/*
* Create an example file in a sub-directory using f_putc().
*/
static void prvCreateDemoFileUsing_f_putc( void );
/*
* Use f_getc() to read back and verify the file that was created by
* prvCreateDemoFileUsing_f_putc().
*/
static void prvVerifyDemoFileUsing_f_getc( void );
/*-----------------------------------------------------------*/
/* A buffer used to both create content to write to disk, and read content back
from a disk. Note there is no mutual exclusion on this buffer. */
static char cRAMBuffer[ fsRAM_BUFFER_SIZE ];
/* Names of directories that are created. */
static const char *pcRoot = "/", *pcDirectory1 = "SUB1", *pcDirectory2 = "SUB2", *pcFullPath = "/SUB1/SUB2";
/*-----------------------------------------------------------*/
void vCreateAndVerifySampleFiles( void )
{
unsigned char ucStatus;
/* First create the volume. */
ucStatus = f_initvolume( ram_initfunc );
/* It is expected that the volume is not formatted. */
if( ucStatus == F_ERR_NOTFORMATTED )
{
/* Format the created volume. */
ucStatus = f_format( F_FAT12_MEDIA );
}
if( ucStatus == F_NO_ERROR )
{
/* Create a set of files using f_write(). */
prvCreateDemoFilesUsing_f_write();
/* Read back and verify the files that were created using f_write(). */
prvVerifyDemoFileUsing_f_read();
/* Create sub directories two deep then create a file using putc. */
prvCreateDemoFileUsing_f_putc();
/* Read back and verify the file created by
prvCreateDemoFileUsing_f_putc(). */
prvVerifyDemoFileUsing_f_getc();
}
}
/*-----------------------------------------------------------*/
static void prvCreateDemoFilesUsing_f_write( void )
{
BaseType_t xFileNumber, xWriteNumber;
char cFileName[ fsMAX_FILE_NAME_LEN ];
const BaseType_t xMaxFiles = 5;
long lItemsWritten;
F_FILE *pxFile;
/* Create xMaxFiles files. Each created file will be
( xFileNumber * fsRAM_BUFFER_SIZE ) bytes in length, and filled
with a different repeating character. */
for( xFileNumber = 1; xFileNumber <= xMaxFiles; xFileNumber++ )
{
/* Generate a file name. */
sprintf( cFileName, "root%03d.txt", ( int ) xFileNumber );
/* Obtain the current working directory and print out the file name and
the directory into which the file is being written. */
f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE );
/* Open the file, creating the file if it does not already exist. */
pxFile = f_open( cFileName, "w" );
configASSERT( pxFile );
/* Fill the RAM buffer with data that will be written to the file. This
is just a repeating ascii character that indicates the file number. */
memset( cRAMBuffer, ( int ) ( '0' + xFileNumber ), fsRAM_BUFFER_SIZE );
/* Write the RAM buffer to the opened file a number of times. The
number of times the RAM buffer is written to the file depends on the
file number, so the length of each created file will be different. */
for( xWriteNumber = 0; xWriteNumber < xFileNumber; xWriteNumber++ )
{
lItemsWritten = f_write( cRAMBuffer, fsRAM_BUFFER_SIZE, 1, pxFile );
configASSERT( lItemsWritten == 1 );
}
/* Close the file so another file can be created. */
f_close( pxFile );
}
}
/*-----------------------------------------------------------*/
static void prvVerifyDemoFileUsing_f_read( void )
{
BaseType_t xFileNumber, xReadNumber;
char cFileName[ fsMAX_FILE_NAME_LEN ];
const BaseType_t xMaxFiles = 5;
long lItemsRead, lChar;
F_FILE *pxFile;
/* Read back the files that were created by
prvCreateDemoFilesUsing_f_write(). */
for( xFileNumber = 1; xFileNumber <= xMaxFiles; xFileNumber++ )
{
/* Generate the file name. */
sprintf( cFileName, "root%03d.txt", ( int ) xFileNumber );
/* Obtain the current working directory and print out the file name and
the directory from which the file is being read. */
f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE );
/* Open the file for reading. */
pxFile = f_open( cFileName, "r" );
configASSERT( pxFile );
/* Read the file into the RAM buffer, checking the file contents are as
expected. The size of the file depends on the file number. */
for( xReadNumber = 0; xReadNumber < xFileNumber; xReadNumber++ )
{
/* Start with the RAM buffer clear. */
memset( cRAMBuffer, 0x00, fsRAM_BUFFER_SIZE );
lItemsRead = f_read( cRAMBuffer, fsRAM_BUFFER_SIZE, 1, pxFile );
configASSERT( lItemsRead == 1 );
/* Check the RAM buffer is filled with the expected data. Each
file contains a different repeating ascii character that indicates
the number of the file. */
for( lChar = 0; lChar < fsRAM_BUFFER_SIZE; lChar++ )
{
configASSERT( cRAMBuffer[ lChar ] == ( '0' + ( char ) xFileNumber ) );
}
}
/* Close the file. */
f_close( pxFile );
}
}
/*-----------------------------------------------------------*/
static void prvCreateDemoFileUsing_f_putc( void )
{
unsigned char ucReturn;
int iByte, iReturned;
F_FILE *pxFile;
char cFileName[ fsMAX_FILE_NAME_LEN ];
/* Obtain and print out the working directory. */
f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE );
/* Create a sub directory. */
ucReturn = f_mkdir( pcDirectory1 );
configASSERT( ucReturn == F_NO_ERROR );
/* Move into the created sub-directory. */
ucReturn = f_chdir( pcDirectory1 );
configASSERT( ucReturn == F_NO_ERROR );
/* Obtain and print out the working directory. */
f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE );
/* Create a subdirectory in the new directory. */
ucReturn = f_mkdir( pcDirectory2 );
configASSERT( ucReturn == F_NO_ERROR );
/* Move into the directory just created - now two directories down from
the root. */
ucReturn = f_chdir( pcDirectory2 );
configASSERT( ucReturn == F_NO_ERROR );
/* Obtain and print out the working directory. */
f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE );
configASSERT( strcmp( cRAMBuffer, pcFullPath ) == 0 );
/* Generate the file name. */
sprintf( cFileName, "%s.txt", pcDirectory2 );
/* Print out the file name and the directory into which the file is being
written. */
pxFile = f_open( cFileName, "w" );
/* Create a file 1 byte at a time. The file is filled with incrementing
ascii characters starting from '0'. */
for( iByte = 0; iByte < fsPUTC_FILE_SIZE; iByte++ )
{
iReturned = f_putc( ( ( int ) '0' + iByte ), pxFile );
configASSERT( iReturned == ( ( int ) '0' + iByte ) );
}
/* Finished so close the file. */
f_close( pxFile );
/* Move back to the root directory. */
ucReturn = f_chdir( "../.." );
configASSERT( ucReturn == F_NO_ERROR );
/* Obtain and print out the working directory. */
f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE );
configASSERT( strcmp( cRAMBuffer, pcRoot ) == 0 );
}
/*-----------------------------------------------------------*/
static void prvVerifyDemoFileUsing_f_getc( void )
{
unsigned char ucReturn;
int iByte, iReturned;
F_FILE *pxFile;
char cFileName[ fsMAX_FILE_NAME_LEN ];
/* Move into the directory in which the file was created. */
ucReturn = f_chdir( pcFullPath );
configASSERT( ucReturn == F_NO_ERROR );
/* Obtain and print out the working directory. */
f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE );
configASSERT( strcmp( cRAMBuffer, pcFullPath ) == 0 );
/* Generate the file name. */
sprintf( cFileName, "%s.txt", pcDirectory2 );
/* This time the file is opened for reading. */
pxFile = f_open( cFileName, "r" );
/* Read the file 1 byte at a time. */
for( iByte = 0; iByte < fsPUTC_FILE_SIZE; iByte++ )
{
iReturned = f_getc( pxFile );
configASSERT( iReturned == ( ( int ) '0' + iByte ) );
}
/* Finished so close the file. */
f_close( pxFile );
/* Move back to the root directory. */
ucReturn = f_chdir( "../.." );
configASSERT( ucReturn == F_NO_ERROR );
/* Obtain and print out the working directory. */
f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE );
}
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
/*******************************************************************************
* See the URL in the comments within main.c for the location of the online
* documentation.
******************************************************************************/
/* Standard includes. */
#include <stdio.h>
#include <string.h>
/* FreeRTOS includes. */
#include "FreeRTOS.h"
/* File system includes. */
#include "fat_sl.h"
#include "api_mdriver_ram.h"
/* 8.3 format, plus null terminator. */
#define fsMAX_FILE_NAME_LEN 13
/* The number of bytes read/written to the example files at a time. */
#define fsRAM_BUFFER_SIZE 200
/* The number of bytes written to the file that uses f_putc() and f_getc(). */
#define fsPUTC_FILE_SIZE 100
/*-----------------------------------------------------------*/
/*
* Creates and verifies different files on the volume, demonstrating the use of
* various different API functions.
*/
void vCreateAndVerifySampleFiles( void );
/*
* Create a set of example files in the root directory of the volume using
* f_write().
*/
static void prvCreateDemoFilesUsing_f_write( void );
/*
* Use f_read() to read back and verify the files that were created by
* prvCreateDemoFilesUsing_f_write().
*/
static void prvVerifyDemoFileUsing_f_read( void );
/*
* Create an example file in a sub-directory using f_putc().
*/
static void prvCreateDemoFileUsing_f_putc( void );
/*
* Use f_getc() to read back and verify the file that was created by
* prvCreateDemoFileUsing_f_putc().
*/
static void prvVerifyDemoFileUsing_f_getc( void );
/*-----------------------------------------------------------*/
/* A buffer used to both create content to write to disk, and read content back
* from a disk. Note there is no mutual exclusion on this buffer. */
static char cRAMBuffer[ fsRAM_BUFFER_SIZE ];
/* Names of directories that are created. */
static const char * pcRoot = "/", * pcDirectory1 = "SUB1", * pcDirectory2 = "SUB2", * pcFullPath = "/SUB1/SUB2";
/*-----------------------------------------------------------*/
void vCreateAndVerifySampleFiles( void )
{
unsigned char ucStatus;
/* First create the volume. */
ucStatus = f_initvolume( ram_initfunc );
/* It is expected that the volume is not formatted. */
if( ucStatus == F_ERR_NOTFORMATTED )
{
/* Format the created volume. */
ucStatus = f_format( F_FAT12_MEDIA );
}
if( ucStatus == F_NO_ERROR )
{
/* Create a set of files using f_write(). */
prvCreateDemoFilesUsing_f_write();
/* Read back and verify the files that were created using f_write(). */
prvVerifyDemoFileUsing_f_read();
/* Create sub directories two deep then create a file using putc. */
prvCreateDemoFileUsing_f_putc();
/* Read back and verify the file created by
* prvCreateDemoFileUsing_f_putc(). */
prvVerifyDemoFileUsing_f_getc();
}
}
/*-----------------------------------------------------------*/
static void prvCreateDemoFilesUsing_f_write( void )
{
BaseType_t xFileNumber, xWriteNumber;
char cFileName[ fsMAX_FILE_NAME_LEN ];
const BaseType_t xMaxFiles = 5;
long lItemsWritten;
F_FILE * pxFile;
/* Create xMaxFiles files. Each created file will be
* ( xFileNumber * fsRAM_BUFFER_SIZE ) bytes in length, and filled
* with a different repeating character. */
for( xFileNumber = 1; xFileNumber <= xMaxFiles; xFileNumber++ )
{
/* Generate a file name. */
sprintf( cFileName, "root%03d.txt", ( int ) xFileNumber );
/* Obtain the current working directory and print out the file name and
* the directory into which the file is being written. */
f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE );
/* Open the file, creating the file if it does not already exist. */
pxFile = f_open( cFileName, "w" );
configASSERT( pxFile );
/* Fill the RAM buffer with data that will be written to the file. This
* is just a repeating ascii character that indicates the file number. */
memset( cRAMBuffer, ( int ) ( '0' + xFileNumber ), fsRAM_BUFFER_SIZE );
/* Write the RAM buffer to the opened file a number of times. The
* number of times the RAM buffer is written to the file depends on the
* file number, so the length of each created file will be different. */
for( xWriteNumber = 0; xWriteNumber < xFileNumber; xWriteNumber++ )
{
lItemsWritten = f_write( cRAMBuffer, fsRAM_BUFFER_SIZE, 1, pxFile );
configASSERT( lItemsWritten == 1 );
}
/* Close the file so another file can be created. */
f_close( pxFile );
}
}
/*-----------------------------------------------------------*/
static void prvVerifyDemoFileUsing_f_read( void )
{
BaseType_t xFileNumber, xReadNumber;
char cFileName[ fsMAX_FILE_NAME_LEN ];
const BaseType_t xMaxFiles = 5;
long lItemsRead, lChar;
F_FILE * pxFile;
/* Read back the files that were created by
* prvCreateDemoFilesUsing_f_write(). */
for( xFileNumber = 1; xFileNumber <= xMaxFiles; xFileNumber++ )
{
/* Generate the file name. */
sprintf( cFileName, "root%03d.txt", ( int ) xFileNumber );
/* Obtain the current working directory and print out the file name and
* the directory from which the file is being read. */
f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE );
/* Open the file for reading. */
pxFile = f_open( cFileName, "r" );
configASSERT( pxFile );
/* Read the file into the RAM buffer, checking the file contents are as
* expected. The size of the file depends on the file number. */
for( xReadNumber = 0; xReadNumber < xFileNumber; xReadNumber++ )
{
/* Start with the RAM buffer clear. */
memset( cRAMBuffer, 0x00, fsRAM_BUFFER_SIZE );
lItemsRead = f_read( cRAMBuffer, fsRAM_BUFFER_SIZE, 1, pxFile );
configASSERT( lItemsRead == 1 );
/* Check the RAM buffer is filled with the expected data. Each
* file contains a different repeating ascii character that indicates
* the number of the file. */
for( lChar = 0; lChar < fsRAM_BUFFER_SIZE; lChar++ )
{
configASSERT( cRAMBuffer[ lChar ] == ( '0' + ( char ) xFileNumber ) );
}
}
/* Close the file. */
f_close( pxFile );
}
}
/*-----------------------------------------------------------*/
static void prvCreateDemoFileUsing_f_putc( void )
{
unsigned char ucReturn;
int iByte, iReturned;
F_FILE * pxFile;
char cFileName[ fsMAX_FILE_NAME_LEN ];
/* Obtain and print out the working directory. */
f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE );
/* Create a sub directory. */
ucReturn = f_mkdir( pcDirectory1 );
configASSERT( ucReturn == F_NO_ERROR );
/* Move into the created sub-directory. */
ucReturn = f_chdir( pcDirectory1 );
configASSERT( ucReturn == F_NO_ERROR );
/* Obtain and print out the working directory. */
f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE );
/* Create a subdirectory in the new directory. */
ucReturn = f_mkdir( pcDirectory2 );
configASSERT( ucReturn == F_NO_ERROR );
/* Move into the directory just created - now two directories down from
* the root. */
ucReturn = f_chdir( pcDirectory2 );
configASSERT( ucReturn == F_NO_ERROR );
/* Obtain and print out the working directory. */
f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE );
configASSERT( strcmp( cRAMBuffer, pcFullPath ) == 0 );
/* Generate the file name. */
sprintf( cFileName, "%s.txt", pcDirectory2 );
/* Print out the file name and the directory into which the file is being
* written. */
pxFile = f_open( cFileName, "w" );
/* Create a file 1 byte at a time. The file is filled with incrementing
* ascii characters starting from '0'. */
for( iByte = 0; iByte < fsPUTC_FILE_SIZE; iByte++ )
{
iReturned = f_putc( ( ( int ) '0' + iByte ), pxFile );
configASSERT( iReturned == ( ( int ) '0' + iByte ) );
}
/* Finished so close the file. */
f_close( pxFile );
/* Move back to the root directory. */
ucReturn = f_chdir( "../.." );
configASSERT( ucReturn == F_NO_ERROR );
/* Obtain and print out the working directory. */
f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE );
configASSERT( strcmp( cRAMBuffer, pcRoot ) == 0 );
}
/*-----------------------------------------------------------*/
static void prvVerifyDemoFileUsing_f_getc( void )
{
unsigned char ucReturn;
int iByte, iReturned;
F_FILE * pxFile;
char cFileName[ fsMAX_FILE_NAME_LEN ];
/* Move into the directory in which the file was created. */
ucReturn = f_chdir( pcFullPath );
configASSERT( ucReturn == F_NO_ERROR );
/* Obtain and print out the working directory. */
f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE );
configASSERT( strcmp( cRAMBuffer, pcFullPath ) == 0 );
/* Generate the file name. */
sprintf( cFileName, "%s.txt", pcDirectory2 );
/* This time the file is opened for reading. */
pxFile = f_open( cFileName, "r" );
/* Read the file 1 byte at a time. */
for( iByte = 0; iByte < fsPUTC_FILE_SIZE; iByte++ )
{
iReturned = f_getc( pxFile );
configASSERT( iReturned == ( ( int ) '0' + iByte ) );
}
/* Finished so close the file. */
f_close( pxFile );
/* Move back to the root directory. */
ucReturn = f_chdir( "../.." );
configASSERT( ucReturn == F_NO_ERROR );
/* Obtain and print out the working directory. */
f_getcwd( cRAMBuffer, fsRAM_BUFFER_SIZE );
}

@ -1,32 +1,34 @@
/*
* FreeRTOS V202212.00
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://aws.amazon.com/freertos
*
*/
#ifndef UDP_COMMAND_INTERPRETER_H
#define UDP_COMMAND_INTERPRETER_H
void vStartUDPCommandInterpreterTask( uint16_t usStackSize, uint32_t ulPort, UBaseType_t uxPriority );
#endif /* UDP_COMMAND_INTERPRETER_H */
/*
* FreeRTOS V202212.00
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* https://www.FreeRTOS.org
* https://github.com/FreeRTOS
*
*/
#ifndef UDP_COMMAND_INTERPRETER_H
#define UDP_COMMAND_INTERPRETER_H
void vStartUDPCommandInterpreterTask( uint16_t usStackSize,
uint32_t ulPort,
UBaseType_t uxPriority );
#endif /* UDP_COMMAND_INTERPRETER_H */

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save