├── lib ├── AWS │ ├── tools │ │ ├── aws_config_quick_start │ │ │ ├── .gitignore │ │ │ ├── configure.json │ │ │ ├── policy_document.templ │ │ │ ├── policy.py │ │ │ ├── thing.py │ │ │ ├── README.md │ │ │ ├── certs.py │ │ │ └── misc.py │ │ └── aws_config_offline │ │ │ └── demo_config_generator.py │ └── directories.txt ├── ThirdParty │ ├── WinPCap │ │ ├── wpcap.lib │ │ ├── pcap │ │ │ ├── bluetooth.h │ │ │ ├── vlan.h │ │ │ ├── usb.h │ │ │ ├── namedb.h │ │ │ └── sll.h │ │ ├── netif.h │ │ ├── pcap-namedb.h │ │ ├── pcap.h │ │ ├── pcap-bpf.h │ │ ├── pcap-stdinc.h │ │ ├── Win32-Extensions.h │ │ ├── bittypes.h │ │ └── ip6_misc.h │ ├── directories.txt │ └── tinycbor │ │ └── src │ │ ├── tinycbor-version.h │ │ ├── LICENSE │ │ ├── README.md │ │ ├── cborencoder_close_container_checked.c │ │ ├── utf8_p.h │ │ ├── cborpretty_stdio.c │ │ ├── cborparser_dup_string.c │ │ └── cborinternal_p.h ├── FreeRTOS │ ├── mqtt-agent-interface │ │ ├── files.txt │ │ ├── freertos_agent_message.c │ │ ├── include │ │ │ ├── freertos_agent_message.h │ │ │ └── freertos_command_pool.h │ │ └── freertos_command_pool.c │ ├── network_transport │ │ ├── readme.txt │ │ └── freertos_plus_tcp │ │ │ ├── sockets_wrapper.h │ │ │ ├── using_plaintext │ │ │ ├── using_plaintext.h │ │ │ └── using_plaintext.c │ │ │ ├── sockets_wrapper.c │ │ │ └── using_mbedtls │ │ │ └── using_mbedtls.h │ ├── directories.txt │ └── utilities │ │ ├── readme.txt │ │ ├── mbedtls_freertos │ │ ├── threading_alt.h │ │ └── mbedtls_error.h │ │ └── crypto │ │ └── include │ │ └── iot_crypto.h └── directories.txt ├── directories.txt ├── CODE_OF_CONDUCT.md ├── .gitignore ├── source ├── cspell.config.yaml ├── directories.txt ├── configuration-files │ ├── shadow_config.h │ ├── aws_ota_codesigner_certificate.h │ ├── defender_config.h │ ├── core_mqtt_config.h │ ├── logging_config.h │ ├── mbedtls_config.h │ └── ota_config.h ├── defender-tools │ ├── report_builder.h │ └── metrics_collector.h ├── demo-tasks │ └── shadow_demo.c └── subscription-manager │ ├── subscription_manager.h │ └── subscription_manager.c ├── LICENSE.md ├── .gitmodules ├── .github ├── workflows │ ├── ci.yml │ └── build_demos.yml └── .cSpellWords.txt ├── CONTRIBUTING.md └── README.md /lib/AWS/tools/aws_config_quick_start/.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__ 2 | test* 3 | *_id_file 4 | *_pem_file 5 | *.pyc 6 | -------------------------------------------------------------------------------- /lib/ThirdParty/WinPCap/wpcap.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FreeRTOS/coreMQTT-Agent-Demos/HEAD/lib/ThirdParty/WinPCap/wpcap.lib -------------------------------------------------------------------------------- /lib/AWS/tools/aws_config_quick_start/configure.json: -------------------------------------------------------------------------------- 1 | { 2 | "FreeRTOS_source_dir": "../..", 3 | "thing_name": "$thing_name" 4 | } -------------------------------------------------------------------------------- /lib/ThirdParty/directories.txt: -------------------------------------------------------------------------------- 1 | This directory contains Git submodules of the third party libraries built by the 2 | demo contained in this Git repository. -------------------------------------------------------------------------------- /lib/ThirdParty/tinycbor/src/tinycbor-version.h: -------------------------------------------------------------------------------- 1 | #define TINYCBOR_VERSION_MAJOR 0 2 | #define TINYCBOR_VERSION_MINOR 5 3 | #define TINYCBOR_VERSION_PATCH 2 4 | -------------------------------------------------------------------------------- /directories.txt: -------------------------------------------------------------------------------- 1 | This file describes the subdirectories contained in this directory. 2 | 3 | build: Contains projects that build this demo - one per sub-directory. 4 | lib: Contains the libraries used by this demo. 5 | source: Contains the source files specific to this demo. -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | ## Code of Conduct 2 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 3 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 4 | opensource-codeofconduct@amazon.com with any additional questions or comments. 5 | -------------------------------------------------------------------------------- /lib/FreeRTOS/mqtt-agent-interface/files.txt: -------------------------------------------------------------------------------- 1 | This directory contains an implementation of the MQTT agent interface functions 2 | that are specific to FreeRTOS. The MQTT agent interface provides the functions 3 | that send messages into and receives messages from the MQTT agent task, as well 4 | as a thread safe pool of structures used with those functions. -------------------------------------------------------------------------------- /lib/FreeRTOS/network_transport/readme.txt: -------------------------------------------------------------------------------- 1 | Building a network transport implementation: 2 | 3 | 1. Go into the sub directory for the TCP/IP stack you are using (e.g. freertos_plus_tcp). 4 | 2. Build the wrapper file located in the directory (i.e. sockets_wrapper.c). 5 | 3. Select an additional folder based on the TLS stack you are using (e.g. using_mbedtls), or the using_plaintext folder if not using TLS. 6 | 4. Build and include all files from the selected folder. 7 | -------------------------------------------------------------------------------- /lib/FreeRTOS/directories.txt: -------------------------------------------------------------------------------- 1 | This directory contains Git submodules of the FreeRTOS and "core" libraries built 2 | by the demo contained in this Git repository. It also contains an implementation 3 | of the MQTT agent interface functions that are specific to FreeRTOS. The MQTT 4 | agent interface provides the functions that send messages into and receive messages 5 | from the MQTT agent task, as well as a thread safe pool of structures used with 6 | those functions. 7 | 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore macOS file system related. 2 | **/*.DS_Store* 3 | 4 | # Ignore build results 5 | [Dd]ebug/ 6 | [Dd]ebugPublic/ 7 | [Rr]elease/ 8 | [Rr]eleases/ 9 | [Bb]in/ 10 | [Oo]bj/ 11 | [Ll]og/ 12 | [Ll]ogs/ 13 | 14 | # Visual Studio cache/options directory 15 | .vs/ 16 | 17 | # Python Tools for Visual Studio (PTVS) 18 | __pycache__/ 19 | *.pyc 20 | 21 | # Build artifacts 22 | *.o 23 | *.d 24 | *.a 25 | *.map 26 | *.elf 27 | 28 | # Tool generated file 29 | lib/AWS/tools/aws_config_offline/demo_config.h 30 | -------------------------------------------------------------------------------- /lib/AWS/directories.txt: -------------------------------------------------------------------------------- 1 | This file describes the subdirectories contained in this directory. 2 | 3 | defender : Contains a Git sub-module of the AWS IoT Device Defender client library. 4 | ota : Contains a Git sub-module of the AWS IoT OTA client library. 5 | ota-pal : Contains implementations of the AWS IoT OTA client platform abstraction 6 | layers - one per subdirectory. 7 | shadow : Contains a Git sub-module of the AWS IoT Device Shadow client library. 8 | tools : Contains tools that automate setup and provisioning actions. 9 | -------------------------------------------------------------------------------- /lib/FreeRTOS/utilities/readme.txt: -------------------------------------------------------------------------------- 1 | Directories: 2 | 3 | + Utilities/exponential_backoff contains a utility that calculates an 4 | exponential back off time, with some jitter. It is used to ensure fleets of 5 | IoT devices that become disconnected don't all try and reconnect at the same 6 | time. 7 | 8 | + Utilities/logging contains header files for use with the core libraries logging 9 | macros. See https://www.FreeRTOS.org/logging.html. 10 | 11 | + Utililties/mbedtls_freertos contains a few FreeRTOS specifics required by 12 | mbedTLS. 13 | 14 | 15 | -------------------------------------------------------------------------------- /lib/directories.txt: -------------------------------------------------------------------------------- 1 | This file describes the subdirectories contained in this directory. 2 | 3 | AWS : Contains Git submodules of libraries specific to the AWS IoT 4 | services demonstrated by the projects contained in this Git 5 | repository. 6 | FreeRTOS : Contains Git submodules of generic and FreeRTOS specific libraries 7 | (including the FreeRTOS kernel) used by the projects contained in 8 | this Git repository. 9 | ThirdParty : Contains Git submodules of the ThirdParty libraries used by the 10 | projects contained in this Git repository. 11 | 12 | -------------------------------------------------------------------------------- /source/cspell.config.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | $schema: https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json 3 | version: '0.2' 4 | # Allows things like stringLength 5 | allowCompoundWords: true 6 | 7 | # Read files not to spell check from the git ignore 8 | useGitignore: true 9 | 10 | # Language settings for C 11 | languageSettings: 12 | - caseSensitive: false 13 | enabled: true 14 | languageId: c 15 | locale: "*" 16 | 17 | # Add a dictionary, and the path to the word list 18 | dictionaryDefinitions: 19 | - name: core-mqtt-agent-demos-words 20 | path: '.github/.cSpellWords.txt' 21 | addWords: true 22 | 23 | dictionaries: 24 | - core-mqtt-agent-demos-words 25 | 26 | # Paths and files to ignore 27 | ignorePaths: 28 | - 'directories.txt' -------------------------------------------------------------------------------- /source/directories.txt: -------------------------------------------------------------------------------- 1 | This file describes the subdirectories contained in this directory. 2 | 3 | configuration-files : Contains configuration files for the library used by the 4 | demo contained in this directory - as well as a configuration 5 | file for the demo itself. 6 | defender-tools : Contains utilities used by the AWS IoT Device Defender 7 | demo to collect metrics. 8 | demo-tasks : Contains the files that implement all the AWS IoT and 9 | generic connectivity demos that use the MQTT agent. 10 | subscription-manager: Contains a utility that tracks the subscriptions created 11 | by the demo so subscriptions can be recreated if necessitated 12 | by a disconnect. 13 | -------------------------------------------------------------------------------- /lib/AWS/tools/aws_config_quick_start/policy_document.templ: -------------------------------------------------------------------------------- 1 | { 2 | "Version": "2012-10-17", 3 | "Statement": [ 4 | { 5 | "Effect": "Allow", 6 | "Action": "iot:Connect", 7 | "Resource": "arn:aws:iot:::*" 8 | }, 9 | { 10 | "Effect": "Allow", 11 | "Action": "iot:Publish", 12 | "Resource": "arn:aws:iot:::*" 13 | }, 14 | { 15 | "Effect": "Allow", 16 | "Action": "iot:Subscribe", 17 | "Resource": "arn:aws:iot:::*" 18 | }, 19 | { 20 | "Effect": "Allow", 21 | "Action": "iot:Receive", 22 | "Resource": "arn:aws:iot:::*" 23 | } 24 | ] 25 | } -------------------------------------------------------------------------------- /lib/AWS/tools/aws_config_quick_start/policy.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import boto3 4 | import json 5 | 6 | 7 | class Policy(): 8 | def __init__(self, name, policy=''): 9 | self.name = name 10 | self.policy = policy 11 | self.client = boto3.client('iot') 12 | 13 | def create(self): 14 | assert not self.exists(), "Policy already exists" 15 | self.client.create_policy(policyName=self.name, 16 | policyDocument=self.policy) 17 | 18 | def delete(self): 19 | assert self.exists(), "Policy does not exist, cannot be deleted" 20 | self.client.delete_policy(policyName=self.name) 21 | 22 | def exists(self): 23 | policies = self.client.list_policies()['policies'] 24 | for policy in policies: 25 | if self.name == policy['policyName']: 26 | return True 27 | return False 28 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "lib/FreeRTOS/freertos-kernel"] 2 | path = lib/FreeRTOS/freertos-kernel 3 | url = https://github.com/FreeRTOS/FreeRTOS-Kernel.git 4 | [submodule "lib/FreeRTOS/freertos-plus-tcp"] 5 | path = lib/FreeRTOS/freertos-plus-tcp 6 | url = https://github.com/FreeRTOS/FreeRTOS-Plus-TCP.git 7 | [submodule "lib/ThirdParty/mbedtls"] 8 | path = lib/ThirdParty/mbedtls 9 | url = https://github.com/ARMmbed/mbedtls.git 10 | [submodule "lib/AWS/ota"] 11 | path = lib/AWS/ota 12 | url = https://github.com/aws/OTA-for-AWS-IoT-embedded-SDK 13 | [submodule "lib/FreeRTOS/utilities/backoffAlgorithm"] 14 | path = lib/FreeRTOS/utilities/backoffAlgorithm 15 | url = https://github.com/FreeRTOS/backoffAlgorithm 16 | [submodule "lib/AWS/defender"] 17 | path = lib/AWS/defender 18 | url = https://github.com/aws/Device-Defender-for-AWS-IoT-embedded-sdk.git 19 | [submodule "lib/FreeRTOS/coreMQTT-Agent"] 20 | path = lib/FreeRTOS/coreMQTT-Agent 21 | url = https://github.com/FreeRTOS/coreMQTT-Agent.git 22 | [submodule "lib/AWS/shadow"] 23 | path = lib/AWS/shadow 24 | url = https://github.com/aws/Device-Shadow-for-AWS-IoT-embedded-sdk 25 | -------------------------------------------------------------------------------- /lib/ThirdParty/tinycbor/src/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Intel Corporation 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI Checks 2 | on: 3 | push: 4 | branches: ["**"] 5 | pull_request: 6 | branches: [main] 7 | workflow_dispatch: 8 | jobs: 9 | spell-check: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/checkout@v2 13 | - name: Run spellings check 14 | uses: FreeRTOS/CI-CD-Github-Actions/spellings@main 15 | with: 16 | path: ./source/ 17 | formatting: 18 | runs-on: ubuntu-latest 19 | steps: 20 | - uses: actions/checkout@v2 21 | - name: Check formatting 22 | uses: FreeRTOS/CI-CD-Github-Actions/formatting@main 23 | with: 24 | path: ./source/ 25 | git-secrets: 26 | runs-on: ubuntu-latest 27 | steps: 28 | - uses: actions/checkout@v2 29 | - name: Checkout awslabs/git-secrets 30 | uses: actions/checkout@v2 31 | with: 32 | repository: awslabs/git-secrets 33 | ref: master 34 | path: git-secrets 35 | - name: Install git-secrets 36 | run: cd git-secrets && sudo make install && cd .. 37 | - name: Run git-secrets 38 | run: | 39 | git-secrets --register-aws 40 | git-secrets --scan 41 | -------------------------------------------------------------------------------- /.github/workflows/build_demos.yml: -------------------------------------------------------------------------------- 1 | name: Build Demos 2 | on: 3 | push: 4 | branches: ["**"] 5 | pull_request: 6 | branches: [main] 7 | workflow_dispatch: 8 | jobs: 9 | windows_simualtor: 10 | name: Windows Simulator 11 | runs-on: windows-2019 12 | steps: 13 | - name: Checkout Repository 14 | uses: actions/checkout@v2 15 | 16 | - name: Fetch Submodules 17 | run: git submodule update --checkout --init --recursive 18 | 19 | - name: Add msbuild to PATH 20 | uses: microsoft/setup-msbuild@v1.1 21 | # with: 22 | # vs-version: 16.0 23 | - name: Build 24 | run: msbuild build\VisualStudio\mqtt_multitask_demo.sln -t:rebuild -property:Configuration=Debug 25 | 26 | qemu_arm: 27 | name: ARM Cortex-M3 QEMU ( mps2-an385 ) 28 | runs-on: ubuntu-latest 29 | steps: 30 | - name: Checkout Repository 31 | uses: actions/checkout@v2 32 | 33 | - name: Fetch Submodules 34 | run: git submodule update --checkout --init --recursive 35 | 36 | - name: Install Build Preqrequisites 37 | run: sudo apt install build-essential gcc-arm-none-eabi libnewlib-arm-none-eabi 38 | 39 | - name: Build 40 | working-directory: build/Cortex-M3_MPS2_QEMU_GCC 41 | run: make 42 | -------------------------------------------------------------------------------- /source/configuration-files/shadow_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * AWS IoT Device SDK for Embedded C V202009.00 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | #ifndef SHADOW_CONFIG_H 24 | #define SHADOW_CONFIG_H 25 | 26 | 27 | 28 | #endif /* ifndef SHADOW_CONFIG_H */ 29 | -------------------------------------------------------------------------------- /lib/AWS/tools/aws_config_quick_start/thing.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import boto3 4 | import json 5 | 6 | 7 | class Thing(): 8 | def __init__(self, name): 9 | self.client = boto3.client('iot') 10 | self.name = name 11 | self.arn = '' 12 | 13 | def create(self): 14 | assert not self.exists(), "Thing already exists" 15 | result = self.client.create_thing(thingName=self.name) 16 | self.arn = result['thingArn'] 17 | 18 | def delete(self): 19 | assert self.exists(), "Thing does not exist" 20 | principals = self.list_principals() 21 | for principal in principals: 22 | self.detach_principal(principal) 23 | self.client.delete_thing(thingName=self.name) 24 | 25 | def exists(self): 26 | list_of_things = self.client.list_things()['things'] 27 | for thing in list_of_things: 28 | if thing['thingName'] == self.name: 29 | return True 30 | return False 31 | 32 | def attach_principal(self, arn): 33 | assert self.exists(), "Thing does not exist" 34 | self.client.attach_thing_principal(thingName=self.name, principal=arn) 35 | 36 | def detach_principal(self, arn): 37 | assert self.exists(), "Thing does not exist" 38 | self.client.detach_thing_principal(thingName=self.name, principal=arn) 39 | 40 | def list_principals(self): 41 | assert self.exists(), "Thing does not exist" 42 | principals = self.client.list_thing_principals(thingName=self.name) 43 | principals = principals['principals'] 44 | return principals 45 | -------------------------------------------------------------------------------- /lib/AWS/tools/aws_config_quick_start/README.md: -------------------------------------------------------------------------------- 1 | ## Script to setup the AWS resources through command line 2 | 3 | This script automates the process of [Prerequisites](https://docs.aws.amazon.com/freertos/latest/userguide/freertos-prereqs.html) and the configuring the files `demo_config.h` to connect to AWS IoT. 4 | 5 | Make sure you have `aws cli` configured on your machine with access_key, secret_key and region. 6 | 7 | Open the file `configure.json` and fill in the following details: 8 | * FreeRTOS_source_dir : Just enter "." to output demo_config.h into this directory then copy into your project 9 | * thing_name : Name of the thing you want to create 10 | 11 | **Options to use with the script** 12 | 1. To setup your Thing, and update credentials file, type the command: `python SetupAWS.py setup` 13 | 2. To cleanup the Thing you created with the script, and revert changes in credentials file, type the command: `python SetupAWS.py cleanup` 14 | 3. To only create thing, certificate and policy, type the command: `python SetupAWS.py prereq` 15 | 4. To update the files `demo_config.h` with thing name and the certificate keys, type the command `python SetupAWS.py update_creds` 16 | 5. To delete the thing, certificate and policy created by the script, type the command: `python SetupAWS.py delete_prereq` 17 | 6. To revert the changes in the file `demo_config.h`, type the command: `python SetupAWS.py cleanup_creds` 18 | 7. To list your certificates, type the command: `python SetupAWS.py list_certificates` 19 | 8. To list your policies, type the command: `python SetupAWS.py list_policies` 20 | 9. To list your things, type the command: `python SetupAWS.py list_things` 21 | -------------------------------------------------------------------------------- /source/configuration-files/aws_ota_codesigner_certificate.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Lab-Project-coreMQTT-Agent 201206 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * http://aws.amazon.com/freertos 23 | * http://www.FreeRTOS.org 24 | */ 25 | 26 | #ifndef __AWS_CODESIGN_KEYS__H__ 27 | #define __AWS_CODESIGN_KEYS__H__ 28 | 29 | /* 30 | * PEM-encoded code signer certificate 31 | * 32 | * Must include the PEM header and footer: 33 | * "-----BEGIN CERTIFICATE-----\n" 34 | * "...base64 data...\n" 35 | * "-----END CERTIFICATE-----\n"; 36 | */ 37 | static const char signingcredentialSIGNING_CERTIFICATE_PEM[] = "Paste code signing certificate here."; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /lib/ThirdParty/WinPCap/pcap/bluetooth.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006 Paolo Abeni (Italy) 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. The name of the author may not be used to endorse or promote 15 | * products derived from this software without specific prior written 16 | * permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | * bluetooth data struct 31 | * By Paolo Abeni 32 | * 33 | * @(#) $Header: /tcpdump/master/libpcap/pcap/bluetooth.h,v 1.1 2007/09/22 02:10:17 guy Exp $ 34 | */ 35 | 36 | #ifndef _PCAP_BLUETOOTH_STRUCTS_H__ 37 | #define _PCAP_BLUETOOTH_STRUCTS_H__ 38 | 39 | /* 40 | * Header prepended libpcap to each bluetooth h:4 frame. 41 | * fields are in network byte order 42 | */ 43 | typedef struct _pcap_bluetooth_h4_header { 44 | u_int32_t direction; /* if first bit is set direction is incoming */ 45 | } pcap_bluetooth_h4_header; 46 | 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /lib/ThirdParty/WinPCap/netif.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS Kernel V10.3.0 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * http://www.FreeRTOS.org 23 | * http://aws.amazon.com/freertos 24 | * 25 | * 1 tab == 4 spaces! 26 | */ 27 | 28 | #ifndef NET_IF_H 29 | #define NET_IF_H 30 | 31 | /* 32 | * Send uip_len bytes from uip_buf to the network interface selected by the 33 | * configNETWORK_INTERFACE_TO_USE constant (defined in FreeRTOSConfig.h). 34 | */ 35 | void vNetifTx( void ); 36 | 37 | /* 38 | * Receive bytes from the network interface selected by the 39 | * configNETWORK_INTERFACE_TO_USE constant (defined in FreeRTOSConfig.h). The 40 | * bytes are placed in uip_buf. The number of bytes copied into uip_buf is 41 | * returned. 42 | */ 43 | UBaseType_t uxNetifRx( void ); 44 | 45 | /* 46 | * Prepare a packet capture session. This will print out all the network 47 | * interfaces available, and the one actually used is set by the 48 | * configNETWORK_INTERFACE_TO_USE constant that is defined in 49 | * FreeRTOSConfig.h. */ 50 | BaseType_t xNetifInit( void ); 51 | 52 | #endif /* NET_IF_H */ 53 | -------------------------------------------------------------------------------- /lib/ThirdParty/tinycbor/src/README.md: -------------------------------------------------------------------------------- 1 | # Overview 2 | 3 | This is a copy of [intel/tinycbor](https://github.com/intel/tinycbor), except for the deviations listed herein. 4 | 5 | **The current version in this subdirectory is 0.5.2. As part of future updates, please merge/reapply the modifications described below.** 6 | 7 | ## Excluded "Cbor To Json" 8 | 9 | Three files are excluded: cborjson.h, cbortojson.c, open_memstream.c. 10 | 11 | - They are not required by FreeRTOS. 12 | - They don't compile with "make" in the Espressif build environment. 13 | - Not every compiler defines "FILE" data type. 14 | 15 | ## Modified "compilersupport_p.h" 16 | 17 | 1. Disable optimization for TI. 18 | 19 | ``` 20 | #if !defined(__TI_COMPILER_VERSION__) || __TI_COMPILER_VERSION__ < 18000000 21 | ``` 22 | 23 | 2. Comment out function mappint to standard ntohs or htons. 24 | 25 | ``` 26 | //# include 27 | //# define cbor_ntohs ntohs 28 | //# define cbor_htons htons 29 | ``` 30 | 31 | 3. Implement default cbor_ntohll with cbor_ntohl, instead of undefined ntohl. 32 | 33 | ``` 34 | define ntohll(x) ((cbor_ntohl((uint32_t)(x)) * UINT64_C(0x100000000)) + (cbor_ntohl((x) >> 32))) 35 | ``` 36 | 37 | 4. Add IAR compiler support. 38 | 39 | This code is copied from [ARMmbed/tinycbor](https://github.com/ARMmbed/tinycbor/blob/master/src/compilersupport_p.h) 40 | 41 | ``` 42 | #elif defined(__ICCARM__) 43 | # if __LITTLE_ENDIAN__ == 1 44 | # include 45 | # define ntohll(x) ((__REV((uint32_t)(x)) * UINT64_C(0x100000000)) + (__REV((x) >> 32))) 46 | # define htonll ntohll 47 | # define cbor_ntohl __REV 48 | # define cbor_htonl __REV 49 | # define cbor_ntohs __REVSH 50 | # define cbor_htons __REVSH 51 | # else 52 | # define cbor_ntohll 53 | # define cbor_htonll 54 | # define cbor_ntohl 55 | # define cbor_htonl 56 | # define cbor_ntohs 57 | # define cbor_htons 58 | # endif 59 | ``` 60 | 61 | ## Modified "cborvalidation.c" 62 | 63 | Initialize local variable in function validate_floating_point; otherwise it is a may-not-be-initialized error when compiling with "make" on ESP. 64 | ``` 65 | // In function: validate_floating_point(CborValue *it, CborType type, uint32_t flags) 66 | float valf = 0.0; 67 | ``` 68 | -------------------------------------------------------------------------------- /lib/ThirdParty/WinPCap/pcap-namedb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1994, 1996 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. All advertising materials mentioning features or use of this software 14 | * must display the following acknowledgement: 15 | * This product includes software developed by the Computer Systems 16 | * Engineering Group at Lawrence Berkeley Laboratory. 17 | * 4. Neither the name of the University nor of the Laboratory may be used 18 | * to endorse or promote products derived from this software without 19 | * specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 | * SUCH DAMAGE. 32 | * 33 | * @(#) $Header: /tcpdump/master/libpcap/pcap-namedb.h,v 1.13 2006/10/04 18:13:32 guy Exp $ (LBL) 34 | */ 35 | 36 | /* 37 | * For backwards compatibility. 38 | * 39 | * Note to OS vendors: do NOT get rid of this file! Some applications 40 | * might expect to be able to include . 41 | */ 42 | #include 43 | -------------------------------------------------------------------------------- /lib/ThirdParty/WinPCap/pcap/vlan.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. All advertising materials mentioning features or use of this software 14 | * must display the following acknowledgement: 15 | * This product includes software developed by the University of 16 | * California, Berkeley and its contributors. 17 | * 4. Neither the name of the University nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 | * SUCH DAMAGE. 32 | * 33 | * @(#) $Header: /tcpdump/master/libpcap/pcap/vlan.h,v 1.1.2.2 2008-08-06 07:45:59 guy Exp $ 34 | */ 35 | 36 | #ifndef lib_pcap_vlan_h 37 | #define lib_pcap_vlan_h 38 | 39 | struct vlan_tag { 40 | u_int16_t vlan_tpid; /* ETH_P_8021Q */ 41 | u_int16_t vlan_tci; /* VLAN TCI */ 42 | }; 43 | 44 | #define VLAN_TAG_LEN 4 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /lib/FreeRTOS/utilities/mbedtls_freertos/threading_alt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | * the Software, and to permit persons to whom the Software is furnished to do so, 9 | * subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | */ 21 | 22 | /** 23 | * @file threading_alt.h 24 | * @brief mbed TLS threading functions implemented for FreeRTOS. 25 | */ 26 | 27 | 28 | #ifndef MBEDTLS_THREADING_ALT_H_ 29 | #define MBEDTLS_THREADING_ALT_H_ 30 | 31 | /* FreeRTOS includes. */ 32 | #include "FreeRTOS.h" 33 | #include "semphr.h" 34 | 35 | /** 36 | * @brief mbed TLS mutex type. 37 | * 38 | * mbed TLS requires platform specific definition for the mutext type. Defining the type for 39 | * FreeRTOS with FreeRTOS semaphore 40 | * handle and semaphore storage as members. 41 | */ 42 | typedef struct mbedtls_threading_mutex 43 | { 44 | SemaphoreHandle_t mutexHandle; 45 | StaticSemaphore_t mutexStorage; 46 | } mbedtls_threading_mutex_t; 47 | 48 | /* mbed TLS mutex functions. */ 49 | void mbedtls_platform_mutex_init( mbedtls_threading_mutex_t * pMutex ); 50 | void mbedtls_platform_mutex_free( mbedtls_threading_mutex_t * pMutex ); 51 | int mbedtls_platform_mutex_lock( mbedtls_threading_mutex_t * pMutex ); 52 | int mbedtls_platform_mutex_unlock( mbedtls_threading_mutex_t * pMutex ); 53 | 54 | #endif /* ifndef MBEDTLS_THREADING_ALT_H_ */ 55 | -------------------------------------------------------------------------------- /lib/ThirdParty/tinycbor/src/cborencoder_close_container_checked.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2015 Intel Corporation 4 | ** 5 | ** Permission is hereby granted, free of charge, to any person obtaining a copy 6 | ** of this software and associated documentation files (the "Software"), to deal 7 | ** in the Software without restriction, including without limitation the rights 8 | ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | ** copies of the Software, and to permit persons to whom the Software is 10 | ** furnished to do so, subject to the following conditions: 11 | ** 12 | ** The above copyright notice and this permission notice shall be included in 13 | ** all copies or substantial portions of the Software. 14 | ** 15 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | ** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | ** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | ** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | ** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | ** THE SOFTWARE. 22 | ** 23 | ****************************************************************************/ 24 | 25 | #define _BSD_SOURCE 1 26 | #define _DEFAULT_SOURCE 1 27 | #ifndef __STDC_LIMIT_MACROS 28 | # define __STDC_LIMIT_MACROS 1 29 | #endif 30 | 31 | #include "cbor.h" 32 | 33 | /** 34 | * \addtogroup CborEncoding 35 | * @{ 36 | */ 37 | 38 | /** 39 | * @deprecated 40 | * 41 | * Closes the CBOR container (array or map) provided by \a containerEncoder and 42 | * updates the CBOR stream provided by \a encoder. Both parameters must be the 43 | * same as were passed to cbor_encoder_create_array() or 44 | * cbor_encoder_create_map(). 45 | * 46 | * Prior to version 0.5, cbor_encoder_close_container() did not check the 47 | * number of items added. Since that version, it does and now 48 | * cbor_encoder_close_container_checked() is no longer needed. 49 | * 50 | * \sa cbor_encoder_create_array(), cbor_encoder_create_map() 51 | */ 52 | CborError cbor_encoder_close_container_checked(CborEncoder *encoder, const CborEncoder *containerEncoder) 53 | { 54 | return cbor_encoder_close_container(encoder, containerEncoder); 55 | } 56 | 57 | /** @} */ 58 | -------------------------------------------------------------------------------- /lib/ThirdParty/WinPCap/pcap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1993, 1994, 1995, 1996, 1997 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. All advertising materials mentioning features or use of this software 14 | * must display the following acknowledgement: 15 | * This product includes software developed by the Computer Systems 16 | * Engineering Group at Lawrence Berkeley Laboratory. 17 | * 4. Neither the name of the University nor of the Laboratory may be used 18 | * to endorse or promote products derived from this software without 19 | * specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 | * SUCH DAMAGE. 32 | * 33 | * @(#) $Header: /tcpdump/master/libpcap/pcap.h,v 1.59 2006/10/04 18:09:22 guy Exp $ (LBL) 34 | */ 35 | 36 | /* 37 | * For backwards compatibility. 38 | * 39 | * Note to OS vendors: do NOT get rid of this file! Many applications 40 | * expect to be able to include , and at least some of them 41 | * go through contortions in their configure scripts to try to detect 42 | * OSes that have "helpfully" moved pcap.h to without 43 | * leaving behind a file. 44 | */ 45 | #include 46 | -------------------------------------------------------------------------------- /lib/ThirdParty/WinPCap/pcap-bpf.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * This code is derived from the Stanford/CMU enet packet filter, 6 | * (net/enet.c) distributed as part of 4.3BSD, and code contributed 7 | * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence 8 | * Berkeley Laboratory. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. All advertising materials mentioning features or use of this software 19 | * must display the following acknowledgement: 20 | * This product includes software developed by the University of 21 | * California, Berkeley and its contributors. 22 | * 4. Neither the name of the University nor the names of its contributors 23 | * may be used to endorse or promote products derived from this software 24 | * without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 | * SUCH DAMAGE. 37 | * 38 | * @(#) $Header: /tcpdump/master/libpcap/pcap-bpf.h,v 1.50 2007/04/01 21:43:55 guy Exp $ (LBL) 39 | */ 40 | 41 | /* 42 | * For backwards compatibility. 43 | * 44 | * Note to OS vendors: do NOT get rid of this file! Some applications 45 | * might expect to be able to include . 46 | */ 47 | #include 48 | -------------------------------------------------------------------------------- /source/configuration-files/defender_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS V202012.00 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | #ifndef DEFENDER_CONFIG_H_ 28 | #define DEFENDER_CONFIG_H_ 29 | 30 | 31 | /** 32 | * AWS IoT Device Defender Service supports both long and short names for keys 33 | * in the report sent by a device. For example, 34 | * 35 | * A device defender report using long key names: 36 | * { 37 | * "header": { 38 | * "report_id": 1530304554, 39 | * "version": "1.0" 40 | * }, 41 | * "metrics": { 42 | * "network_stats": { 43 | * "bytes_in": 29358693495, 44 | * "bytes_out": 26485035, 45 | * "packets_in": 10013573555, 46 | * "packets_out": 11382615 47 | * } 48 | * } 49 | * } 50 | * 51 | * An equivalent report using short key names: 52 | * { 53 | * "hed": { 54 | * "rid": 1530304554, 55 | * "v": "1.0" 56 | * }, 57 | * "met": { 58 | * "ns": { 59 | * "bi": 29358693495, 60 | * "bo": 26485035, 61 | * "pi": 10013573555, 62 | * "po": 11382615 63 | * } 64 | * } 65 | * } 66 | * 67 | * Set to 1 to enable use of long key names in the defender report. 68 | */ 69 | #define DEFENDER_USE_LONG_KEYS 0 70 | 71 | #endif /* ifndef DEFENDER_CONFIG_H_ */ 72 | -------------------------------------------------------------------------------- /lib/FreeRTOS/network_transport/freertos_plus_tcp/sockets_wrapper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | * the Software, and to permit persons to whom the Software is furnished to do so, 9 | * subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | */ 21 | 22 | /** 23 | * @file sockets_wrapper.h 24 | * @brief FreeRTOS Sockets connect and disconnect function wrapper. 25 | */ 26 | 27 | #ifndef SOCKETS_WRAPPER_H 28 | #define SOCKETS_WRAPPER_H 29 | 30 | /* FreeRTOS+TCP includes. */ 31 | #include "FreeRTOS_IP.h" 32 | #include "FreeRTOS_Sockets.h" 33 | #include "FreeRTOS_DNS.h" 34 | 35 | /** 36 | * @brief Establish a connection to server. 37 | * 38 | * @param[out] pTcpSocket The output parameter to return the created socket descriptor. 39 | * @param[in] pHostName Server hostname to connect to. 40 | * @param[in] pServerInfo Server port to connect to. 41 | * @param[in] receiveTimeoutMs Timeout (in milliseconds) for transport receive. 42 | * @param[in] sendTimeoutMs Timeout (in milliseconds) for transport send. 43 | * 44 | * @note A timeout of 0 means infinite timeout. 45 | * 46 | * @return Non-zero value on error, 0 on success. 47 | */ 48 | BaseType_t Sockets_Connect( Socket_t * pTcpSocket, 49 | const char * pHostName, 50 | uint16_t port, 51 | uint32_t receiveTimeoutMs, 52 | uint32_t sendTimeoutMs ); 53 | 54 | /** 55 | * @brief End connection to server. 56 | * 57 | * @param[in] tcpSocket The socket descriptor. 58 | */ 59 | void Sockets_Disconnect( Socket_t tcpSocket ); 60 | 61 | #endif /* ifndef SOCKETS_WRAPPER_H */ 62 | -------------------------------------------------------------------------------- /lib/FreeRTOS/utilities/mbedtls_freertos/mbedtls_error.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS Error Code Stringification utilities for mbed TLS v2.16.0 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | /** 24 | * @file mbedtls_error.h 25 | * @brief Stringification utilities for high-level and low-level codes of mbed TLS. 26 | */ 27 | 28 | #ifndef MBEDTLS_ERROR_H_ 29 | #define MBEDTLS_ERROR_H_ 30 | 31 | #include 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /** 38 | * @brief Translate an mbed TLS high level code into its string representation. 39 | * Result includes a terminating null byte. 40 | * 41 | * @param errnum The error code containing the high-level code. 42 | * @return The string representation if high-level code is present; otherwise NULL. 43 | * 44 | * @warning The string returned by this function must never be modified. 45 | */ 46 | const char * mbedtls_strerror_highlevel( int32_t errnum ); 47 | 48 | /** 49 | * @brief Translate an mbed TLS low level code into its string representation, 50 | * Result includes a terminating null byte. 51 | * 52 | * @param errnum The error code containing the low-level code. 53 | * @return The string representation if low-level code is present; otherwise NULL. 54 | * 55 | * @warning The string returned by this function must never be modified. 56 | */ 57 | const char * mbedtls_strerror_lowlevel( int32_t errnum ); 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | 63 | #endif /* ifndef MBEDTLS_ERROR_H_ */ 64 | -------------------------------------------------------------------------------- /lib/FreeRTOS/mqtt-agent-interface/freertos_agent_message.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS V202104.00 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | /** 28 | * @file freertos_agent_message.c 29 | * @brief Implements functions to interact with queues. 30 | */ 31 | 32 | /* Standard includes. */ 33 | #include 34 | #include 35 | 36 | /* Kernel includes. */ 37 | #include "FreeRTOS.h" 38 | #include "semphr.h" 39 | 40 | /* Header include. */ 41 | #include "freertos_agent_message.h" 42 | #include "core_mqtt_agent_message_interface.h" 43 | 44 | /*-----------------------------------------------------------*/ 45 | 46 | bool Agent_MessageSend( MQTTAgentMessageContext_t * pMsgCtx, 47 | MQTTAgentCommand_t * const * pCommandToSend, 48 | uint32_t blockTimeMs ) 49 | { 50 | BaseType_t queueStatus = pdFAIL; 51 | 52 | if( ( pMsgCtx != NULL ) && ( pCommandToSend != NULL ) ) 53 | { 54 | queueStatus = xQueueSendToBack( pMsgCtx->queue, pCommandToSend, pdMS_TO_TICKS( blockTimeMs ) ); 55 | } 56 | 57 | return ( queueStatus == pdPASS ) ? true : false; 58 | } 59 | 60 | /*-----------------------------------------------------------*/ 61 | 62 | bool Agent_MessageReceive( MQTTAgentMessageContext_t * pMsgCtx, 63 | MQTTAgentCommand_t ** pReceivedCommand, 64 | uint32_t blockTimeMs ) 65 | { 66 | BaseType_t queueStatus = pdFAIL; 67 | 68 | if( ( pMsgCtx != NULL ) && ( pReceivedCommand != NULL ) ) 69 | { 70 | queueStatus = xQueueReceive( pMsgCtx->queue, pReceivedCommand, pdMS_TO_TICKS( blockTimeMs ) ); 71 | } 72 | 73 | return ( queueStatus == pdPASS ) ? true : false; 74 | } 75 | -------------------------------------------------------------------------------- /lib/AWS/tools/aws_config_quick_start/certs.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import boto3 4 | import json 5 | 6 | 7 | class Certificate(): 8 | 9 | def __init__(self, certId=''): 10 | self.id = certId 11 | self.arn = '' 12 | self.client = boto3.client('iot') 13 | if (self.id != ''): 14 | result = self.client.describe_certificate(certificateId=self.id) 15 | self.arn = result['certificateDescription']['certificateArn'] 16 | 17 | def create(self): 18 | assert not self.exists(), "Cert already exists" 19 | cert = self.create_keys_and_certificate() 20 | self.id = cert["certificateId"] 21 | self.arn = cert["certificateArn"] 22 | return cert 23 | 24 | def create_keys_and_certificate(self): 25 | result = self.client.create_keys_and_certificate(setAsActive=True) 26 | return result 27 | 28 | def delete(self): 29 | cert_not_found = True 30 | # Detach Policies attached to the cert 31 | policies_attached = self.list_policies() 32 | for policy in policies_attached: 33 | self.detach_policy(policy['policyName']) 34 | 35 | # Detach Things attached to the cert 36 | things_attached = self.list_things() 37 | for thing in things_attached: 38 | self.detach_thing(thing) 39 | 40 | # Update the status of the certificate to INACTIVE 41 | try: 42 | self.client.update_certificate(certificateId=self.id, 43 | newStatus='INACTIVE') 44 | cert_not_found = False 45 | except self.client.exceptions.ResourceNotFoundException: 46 | cert_not_found = True 47 | return cert_not_found 48 | 49 | # Delete the certificate 50 | try: 51 | self.client.delete_certificate(certificateId=self.id) 52 | cert_not_found = False 53 | except self.client.exceptions.ResourceNotFoundException: 54 | cert_not_found = True 55 | return cert_not_found 56 | 57 | def exists(self): 58 | if self.id == '': 59 | return False 60 | else: 61 | return True 62 | 63 | def get_arn(self): 64 | return self.arn 65 | 66 | def list_policies(self): 67 | policies = self.client.list_principal_policies(principal=self.arn) 68 | policies = policies['policies'] 69 | return policies 70 | 71 | def attach_policy(self, policy_name): 72 | self.client.attach_policy(policyName=policy_name, target=self.arn) 73 | 74 | def detach_policy(self, policy_name): 75 | self.client.detach_policy(policyName=policy_name, target=self.arn) 76 | 77 | def list_things(self): 78 | things = self.client.list_principal_things(principal=self.arn) 79 | things = things['things'] 80 | return things 81 | 82 | def attach_thing(self, thing_name): 83 | self.client.attach_thing_principal(thingName=thing_name, 84 | principal=self.arn) 85 | 86 | def detach_thing(self, thing_name): 87 | self.client.detach_thing_principal(thingName=thing_name, 88 | principal=self.arn) 89 | -------------------------------------------------------------------------------- /lib/ThirdParty/WinPCap/pcap-stdinc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2002 - 2005 NetGroup, Politecnico di Torino (Italy) 3 | * Copyright (c) 2005 - 2009 CACE Technologies, Inc. Davis (California) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. Neither the name of the Politecnico di Torino nor the names of its 16 | * contributors may be used to endorse or promote products derived from 17 | * this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | * 31 | * @(#) $Header: /tcpdump/master/libpcap/pcap-stdinc.h,v 1.10.2.1 2008-10-06 15:38:39 gianluca Exp $ (LBL) 32 | */ 33 | 34 | #define SIZEOF_CHAR 1 35 | #define SIZEOF_SHORT 2 36 | #define SIZEOF_INT 4 37 | #ifndef _MSC_EXTENSIONS 38 | #define SIZEOF_LONG_LONG 8 39 | #endif 40 | 41 | /* 42 | * Avoids a compiler warning in case this was already defined 43 | * (someone defined _WINSOCKAPI_ when including 'windows.h', in order 44 | * to prevent it from including 'winsock.h') 45 | */ 46 | #ifdef _WINSOCKAPI_ 47 | #undef _WINSOCKAPI_ 48 | #endif 49 | #include 50 | 51 | #include 52 | 53 | #include "bittypes.h" 54 | #include 55 | #include 56 | 57 | #ifndef __MINGW32__ 58 | #include "ip6_misc.h" 59 | #endif 60 | 61 | #define caddr_t char* 62 | 63 | #if _MSC_VER < 1500 64 | #define snprintf _snprintf 65 | #define vsnprintf _vsnprintf 66 | #define strdup _strdup 67 | #endif 68 | 69 | #define inline __inline 70 | 71 | #ifdef __MINGW32__ 72 | #include 73 | #else /*__MINGW32__*/ 74 | /* MSVC compiler */ 75 | #ifndef _UINTPTR_T_DEFINED 76 | #ifdef _WIN64 77 | typedef unsigned __int64 uintptr_t; 78 | #else 79 | typedef _W64 unsigned int uintptr_t; 80 | #endif 81 | #define _UINTPTR_T_DEFINED 82 | #endif 83 | 84 | #ifndef _INTPTR_T_DEFINED 85 | #ifdef _WIN64 86 | typedef __int64 intptr_t; 87 | #else 88 | typedef _W64 int intptr_t; 89 | #endif 90 | #define _INTPTR_T_DEFINED 91 | #endif 92 | 93 | #endif /*__MINGW32__*/ 94 | -------------------------------------------------------------------------------- /lib/ThirdParty/WinPCap/pcap/usb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006 Paolo Abeni (Italy) 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 3. The name of the author may not be used to endorse or promote 15 | * products derived from this software without specific prior written 16 | * permission. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | * 30 | * Basic USB data struct 31 | * By Paolo Abeni 32 | * 33 | * @(#) $Header: /tcpdump/master/libpcap/pcap/usb.h,v 1.6 2007/09/22 02:06:08 guy Exp $ 34 | */ 35 | 36 | #ifndef _PCAP_USB_STRUCTS_H__ 37 | #define _PCAP_USB_STRUCTS_H__ 38 | 39 | /* 40 | * possible transfer mode 41 | */ 42 | #define URB_TRANSFER_IN 0x80 43 | #define URB_ISOCHRONOUS 0x0 44 | #define URB_INTERRUPT 0x1 45 | #define URB_CONTROL 0x2 46 | #define URB_BULK 0x3 47 | 48 | /* 49 | * possible event type 50 | */ 51 | #define URB_SUBMIT 'S' 52 | #define URB_COMPLETE 'C' 53 | #define URB_ERROR 'E' 54 | 55 | /* 56 | * USB setup header as defined in USB specification. 57 | * Appears at the front of each packet in DLT_USB captures. 58 | */ 59 | typedef struct _usb_setup { 60 | u_int8_t bmRequestType; 61 | u_int8_t bRequest; 62 | u_int16_t wValue; 63 | u_int16_t wIndex; 64 | u_int16_t wLength; 65 | } pcap_usb_setup; 66 | 67 | 68 | /* 69 | * Header prepended by linux kernel to each event. 70 | * Appears at the front of each packet in DLT_USB_LINUX captures. 71 | */ 72 | typedef struct _usb_header { 73 | u_int64_t id; 74 | u_int8_t event_type; 75 | u_int8_t transfer_type; 76 | u_int8_t endpoint_number; 77 | u_int8_t device_address; 78 | u_int16_t bus_id; 79 | char setup_flag;/*if !=0 the urb setup header is not present*/ 80 | char data_flag; /*if !=0 no urb data is present*/ 81 | int64_t ts_sec; 82 | int32_t ts_usec; 83 | int32_t status; 84 | u_int32_t urb_len; 85 | u_int32_t data_len; /* amount of urb data really present in this event*/ 86 | pcap_usb_setup setup; 87 | } pcap_usb_header; 88 | 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /lib/FreeRTOS/mqtt-agent-interface/include/freertos_agent_message.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS V202104.00 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | /** 28 | * @file freertos_core_mqtt_agent_message_interface.h 29 | * @brief Functions to interact with queues. 30 | */ 31 | #ifndef FREERTOS_AGENT_MESSAGE_H 32 | #define FREERTOS_AGENT_MESSAGE_H 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | /* FreeRTOS includes. */ 39 | #include "FreeRTOS.h" 40 | #include "queue.h" 41 | 42 | /* Include MQTT agent messaging interface. */ 43 | #include "core_mqtt_agent_message_interface.h" 44 | 45 | /** 46 | * @ingroup mqtt_agent_struct_types 47 | * @brief Context with which tasks may deliver messages to the agent. 48 | */ 49 | struct MQTTAgentMessageContext 50 | { 51 | QueueHandle_t queue; 52 | }; 53 | 54 | /*-----------------------------------------------------------*/ 55 | 56 | /** 57 | * @brief Send a message to the specified context. 58 | * Must be thread safe. 59 | * 60 | * @param[in] pMsgCtx An #MQTTAgentMessageContext_t. 61 | * @param[in] pCommandToSend Pointer to address to send to queue. 62 | * @param[in] blockTimeMs Block time to wait for a send. 63 | * 64 | * @return `true` if send was successful, else `false`. 65 | */ 66 | bool Agent_MessageSend( MQTTAgentMessageContext_t * pMsgCtx, 67 | MQTTAgentCommand_t * const * pCommandToSend, 68 | uint32_t blockTimeMs ); 69 | 70 | /** 71 | * @brief Receive a message from the specified context. 72 | * Must be thread safe. 73 | * 74 | * @param[in] pMsgCtx An #MQTTAgentMessageContext_t. 75 | * @param[in] pReceivedCommand Pointer to write address of received command. 76 | * @param[in] blockTimeMs Block time to wait for a receive. 77 | * 78 | * @return `true` if receive was successful, else `false`. 79 | */ 80 | bool Agent_MessageReceive( MQTTAgentMessageContext_t * pMsgCtx, 81 | MQTTAgentCommand_t ** pReceivedCommand, 82 | uint32_t blockTimeMs ); 83 | 84 | #endif /* FREERTOS_AGENT_MESSAGE_H */ 85 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional 4 | documentation, we greatly value feedback and contributions from our community. 5 | 6 | Please read through this document before submitting any issues or pull requests to ensure we have all the necessary 7 | information to effectively respond to your bug report or contribution. 8 | 9 | 10 | ## Reporting Bugs/Feature Requests 11 | 12 | We welcome you to use the GitHub issue tracker to report bugs or suggest features. 13 | 14 | When filing an issue, please check existing open, or recently closed, issues to make sure somebody else hasn't already 15 | reported the issue. Please try to include as much information as you can. Details like these are incredibly useful: 16 | 17 | * A reproducible test case or series of steps 18 | * The version of our code being used 19 | * Any modifications you've made relevant to the bug 20 | * Anything unusual about your environment or deployment 21 | 22 | 23 | ## Contributing via Pull Requests 24 | Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that: 25 | 26 | 1. You are working against the latest source on the *main* branch. 27 | 2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already. 28 | 3. You open an issue to discuss any significant work - we would hate for your time to be wasted. 29 | 30 | To send us a pull request, please: 31 | 32 | 1. Fork the repository. 33 | 2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change. 34 | 3. Ensure local tests pass. 35 | 4. Commit to your fork using clear commit messages. 36 | 5. Send us a pull request, answering any default questions in the pull request interface. 37 | 6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation. 38 | 39 | GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and 40 | [creating a pull request](https://help.github.com/articles/creating-a-pull-request/). 41 | 42 | 43 | ## Finding contributions to work on 44 | Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any 'help wanted' issues is a great place to start. 45 | 46 | 47 | ## Code of Conduct 48 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 49 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 50 | opensource-codeofconduct@amazon.com with any additional questions or comments. 51 | 52 | 53 | ## Security issue notifications 54 | If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue. 55 | 56 | 57 | ## Licensing 58 | 59 | See the [LICENSE](LICENSE.md) file for our project's licensing. We will ask you to confirm the licensing of your contribution. 60 | -------------------------------------------------------------------------------- /lib/ThirdParty/tinycbor/src/utf8_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2017 Intel Corporation 4 | ** 5 | ** Permission is hereby granted, free of charge, to any person obtaining a copy 6 | ** of this software and associated documentation files (the "Software"), to deal 7 | ** in the Software without restriction, including without limitation the rights 8 | ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | ** copies of the Software, and to permit persons to whom the Software is 10 | ** furnished to do so, subject to the following conditions: 11 | ** 12 | ** The above copyright notice and this permission notice shall be included in 13 | ** all copies or substantial portions of the Software. 14 | ** 15 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | ** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | ** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | ** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | ** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | ** THE SOFTWARE. 22 | ** 23 | ****************************************************************************/ 24 | 25 | #ifndef CBOR_UTF8_H 26 | #define CBOR_UTF8_H 27 | 28 | #include "compilersupport_p.h" 29 | 30 | #include 31 | 32 | static inline uint32_t get_utf8(const uint8_t **buffer, const uint8_t *end) 33 | { 34 | int charsNeeded; 35 | uint32_t uc, min_uc; 36 | uint8_t b; 37 | ptrdiff_t n = end - *buffer; 38 | if (n == 0) 39 | return ~0U; 40 | 41 | uc = *(*buffer)++; 42 | if (uc < 0x80) { 43 | /* single-byte UTF-8 */ 44 | return uc; 45 | } 46 | 47 | /* multi-byte UTF-8, decode it */ 48 | if (unlikely(uc <= 0xC1)) 49 | return ~0U; 50 | if (uc < 0xE0) { 51 | /* two-byte UTF-8 */ 52 | charsNeeded = 2; 53 | min_uc = 0x80; 54 | uc &= 0x1f; 55 | } else if (uc < 0xF0) { 56 | /* three-byte UTF-8 */ 57 | charsNeeded = 3; 58 | min_uc = 0x800; 59 | uc &= 0x0f; 60 | } else if (uc < 0xF5) { 61 | /* four-byte UTF-8 */ 62 | charsNeeded = 4; 63 | min_uc = 0x10000; 64 | uc &= 0x07; 65 | } else { 66 | return ~0U; 67 | } 68 | 69 | if (n < charsNeeded - 1) 70 | return ~0U; 71 | 72 | /* first continuation character */ 73 | b = *(*buffer)++; 74 | if ((b & 0xc0) != 0x80) 75 | return ~0U; 76 | uc <<= 6; 77 | uc |= b & 0x3f; 78 | 79 | if (charsNeeded > 2) { 80 | /* second continuation character */ 81 | b = *(*buffer)++; 82 | if ((b & 0xc0) != 0x80) 83 | return ~0U; 84 | uc <<= 6; 85 | uc |= b & 0x3f; 86 | 87 | if (charsNeeded > 3) { 88 | /* third continuation character */ 89 | b = *(*buffer)++; 90 | if ((b & 0xc0) != 0x80) 91 | return ~0U; 92 | uc <<= 6; 93 | uc |= b & 0x3f; 94 | } 95 | } 96 | 97 | /* overlong sequence? surrogate pair? out or range? */ 98 | if (uc < min_uc || uc - 0xd800U < 2048U || uc > 0x10ffff) 99 | return ~0U; 100 | 101 | return uc; 102 | } 103 | 104 | #endif /* CBOR_UTF8_H */ 105 | -------------------------------------------------------------------------------- /lib/AWS/tools/aws_config_quick_start/misc.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import os 4 | import boto3 5 | 6 | 7 | def describe_endpoint(): 8 | client = boto3.client('iot') 9 | endpoint = client.describe_endpoint(endpointType='iot:Data-ATS') 10 | return endpoint['endpointAddress'] 11 | 12 | 13 | def get_account_id(): 14 | client = boto3.client('sts') 15 | aws_account_id = client.get_caller_identity()['Account'] 16 | return aws_account_id.strip('\n') 17 | 18 | 19 | def get_aws_region(): 20 | my_session = boto3.session.Session() 21 | aws_region = my_session.region_name 22 | return aws_region.strip('\n') 23 | 24 | 25 | def create_policy_document(): 26 | this_file_directory = os.getcwd() 27 | policy_document = os.path.join(this_file_directory, 28 | 'policy_document.templ') 29 | region_name = str(get_aws_region()) 30 | aws_account_id = str(get_account_id()) 31 | with open(policy_document) as policy_document_file: 32 | policy_document_text = policy_document_file.read() 33 | 34 | # Replace Account ID and AWS Region 35 | policy_document_text = policy_document_text.replace('', 36 | region_name) 37 | policy_document_text = policy_document_text.replace('', 38 | aws_account_id) 39 | 40 | return policy_document_text 41 | 42 | 43 | def format_credential_keys_text(credential_text): 44 | credential_text_lines = credential_text.split('\n') 45 | formatted_credential_text_lines = [] 46 | 47 | for credential_text_line in credential_text_lines: 48 | if credential_text_line.strip(): 49 | formatted_credential_text_line = ' {:68s}'\ 50 | .format('"' + credential_text_line + '\\n"') 51 | formatted_credential_text_lines.append( 52 | formatted_credential_text_line) 53 | 54 | formatted_credential_text = ' \\\n'.join(formatted_credential_text_lines) 55 | return formatted_credential_text 56 | 57 | 58 | def write_client_credentials( 59 | source_dir, 60 | thing_name='', 61 | client_certificate_pem='', 62 | client_private_key_pem='', 63 | cleanup=False): 64 | 65 | file_to_modify = os.path.join('demo_config.h') 66 | file_text = '' 67 | 68 | if cleanup: 69 | filename = "demo_config_empty.templ" 70 | with open(filename, 'r') as template_file: 71 | file_text = template_file.read() 72 | 73 | else: 74 | endpoint = describe_endpoint() 75 | client_certificate_pem =\ 76 | format_credential_keys_text(client_certificate_pem) 77 | client_private_key_pem =\ 78 | format_credential_keys_text(client_private_key_pem) 79 | 80 | filename = "demo_config.templ" 81 | with open(filename, 'r') as template_file: 82 | file_text = template_file.read() 83 | file_text = file_text.replace("", 84 | "\"" + endpoint + "\"") 85 | file_text = file_text.replace("", 86 | "\"" + thing_name + "\"") 87 | file_text = file_text.replace("", 88 | client_certificate_pem) 89 | file_text = file_text.replace("", 90 | client_private_key_pem) 91 | 92 | header_file = open(str(file_to_modify), 'w') 93 | header_file.write(file_text) 94 | header_file.close() 95 | -------------------------------------------------------------------------------- /source/configuration-files/core_mqtt_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Lab-Project-coreMQTT-Agent 201215 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * http://www.FreeRTOS.org 23 | * http://aws.amazon.com/freertos 24 | * 25 | * 1 tab == 4 spaces! 26 | */ 27 | #ifndef CORE_MQTT_CONFIG_H 28 | #define CORE_MQTT_CONFIG_H 29 | 30 | /** 31 | * @brief The maximum number of MQTT PUBLISH messages that may be pending 32 | * acknowledgment at any time. 33 | * 34 | * QoS 1 and 2 MQTT PUBLISHes require acknowledgment from the server before 35 | * they can be completed. While they are awaiting the acknowledgment, the 36 | * client must maintain information about their state. The value of this 37 | * macro sets the limit on how many simultaneous PUBLISH states an MQTT 38 | * context maintains. 39 | */ 40 | #define MQTT_STATE_ARRAY_MAX_COUNT ( 20U ) 41 | #define MQTT_RECV_POLLING_TIMEOUT_MS ( 1000 ) 42 | 43 | /*_RB_ To document and add to the mqtt config defaults header file. */ 44 | #define MQTT_AGENT_COMMAND_QUEUE_LENGTH ( 25 ) 45 | #define MQTT_COMMAND_CONTEXTS_POOL_SIZE ( 10 ) 46 | 47 | /** 48 | * @brief The maximum number of subscriptions to track for a single connection. 49 | * 50 | * @note The MQTT agent keeps a record of all existing MQTT subscriptions. 51 | * MQTT_AGENT_MAX_SIMULTANEOUS_SUBSCRIPTIONS sets the maximum number of 52 | * subscriptions records that can be maintained at one time. The higher this 53 | * number is the greater the agent's RAM consumption will be. 54 | */ 55 | #define MQTT_AGENT_MAX_SIMULTANEOUS_SUBSCRIPTIONS ( 10 ) 56 | 57 | /** 58 | * @brief Size of statically allocated buffers for holding subscription filters. 59 | * 60 | * @note Subscription filters are strings such as "/my/topicname/#". These 61 | * strings are limited to a maximum of MQTT_AGENT_MAX_SUBSCRIPTION_FILTER_LENGTH 62 | * characters. The higher this number is the greater the agent's RAM consumption 63 | * will be. 64 | */ 65 | #define MQTT_AGENT_MAX_SUBSCRIPTION_FILTER_LENGTH ( 100 ) 66 | 67 | /** 68 | * @brief Dimensions the buffer used to serialize and deserialize MQTT packets. 69 | * @note Specified in bytes. Must be large enough to hold the maximum 70 | * anticipated MQTT payload. 71 | */ 72 | #define MQTT_AGENT_NETWORK_BUFFER_SIZE ( 5000 ) 73 | 74 | /** 75 | * @brief No custom config is used for the coreMQTT-Agent 76 | */ 77 | #define MQTT_AGENT_DO_NOT_USE_CUSTOM_CONFIG 78 | 79 | #endif /* ifndef CORE_MQTT_CONFIG_H */ 80 | -------------------------------------------------------------------------------- /lib/ThirdParty/WinPCap/pcap/namedb.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1994, 1996 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. All advertising materials mentioning features or use of this software 14 | * must display the following acknowledgement: 15 | * This product includes software developed by the Computer Systems 16 | * Engineering Group at Lawrence Berkeley Laboratory. 17 | * 4. Neither the name of the University nor of the Laboratory may be used 18 | * to endorse or promote products derived from this software without 19 | * specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 | * SUCH DAMAGE. 32 | * 33 | * @(#) $Header: /tcpdump/master/libpcap/pcap/namedb.h,v 1.1 2006/10/04 18:09:22 guy Exp $ (LBL) 34 | */ 35 | 36 | #ifndef lib_pcap_namedb_h 37 | #define lib_pcap_namedb_h 38 | 39 | #ifdef __cplusplus 40 | extern "C" { 41 | #endif 42 | 43 | /* 44 | * As returned by the pcap_next_etherent() 45 | * XXX this stuff doesn't belong in this interface, but this 46 | * library already must do name to address translation, so 47 | * on systems that don't have support for /etc/ethers, we 48 | * export these hooks since they'll 49 | */ 50 | struct pcap_etherent { 51 | u_char addr[6]; 52 | char name[122]; 53 | }; 54 | #ifndef PCAP_ETHERS_FILE 55 | #define PCAP_ETHERS_FILE "/etc/ethers" 56 | #endif 57 | struct pcap_etherent *pcap_next_etherent(FILE *); 58 | u_char *pcap_ether_hostton(const char*); 59 | u_char *pcap_ether_aton(const char *); 60 | 61 | bpf_u_int32 **pcap_nametoaddr(const char *); 62 | #ifdef INET6 63 | struct addrinfo *pcap_nametoaddrinfo(const char *); 64 | #endif 65 | bpf_u_int32 pcap_nametonetaddr(const char *); 66 | 67 | int pcap_nametoport(const char *, int *, int *); 68 | int pcap_nametoportrange(const char *, int *, int *, int *); 69 | int pcap_nametoproto(const char *); 70 | int pcap_nametoeproto(const char *); 71 | int pcap_nametollc(const char *); 72 | /* 73 | * If a protocol is unknown, PROTO_UNDEF is returned. 74 | * Also, pcap_nametoport() returns the protocol along with the port number. 75 | * If there are ambiguous entried in /etc/services (i.e. domain 76 | * can be either tcp or udp) PROTO_UNDEF is returned. 77 | */ 78 | #define PROTO_UNDEF -1 79 | 80 | /* XXX move these to pcap-int.h? */ 81 | int __pcap_atodn(const char *, bpf_u_int32 *); 82 | int __pcap_atoin(const char *, bpf_u_int32 *); 83 | u_short __pcap_nametodnaddr(const char *); 84 | 85 | #ifdef __cplusplus 86 | } 87 | #endif 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /lib/ThirdParty/tinycbor/src/cborpretty_stdio.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2017 Intel Corporation 4 | ** 5 | ** Permission is hereby granted, free of charge, to any person obtaining a copy 6 | ** of this software and associated documentation files (the "Software"), to deal 7 | ** in the Software without restriction, including without limitation the rights 8 | ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | ** copies of the Software, and to permit persons to whom the Software is 10 | ** furnished to do so, subject to the following conditions: 11 | ** 12 | ** The above copyright notice and this permission notice shall be included in 13 | ** all copies or substantial portions of the Software. 14 | ** 15 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | ** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | ** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | ** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | ** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | ** THE SOFTWARE. 22 | ** 23 | ****************************************************************************/ 24 | 25 | #include "cbor.h" 26 | #include 27 | #include 28 | 29 | static CborError cbor_fprintf(void *out, const char *fmt, ...) 30 | { 31 | int n; 32 | 33 | va_list list; 34 | va_start(list, fmt); 35 | n = vfprintf((FILE *)out, fmt, list); 36 | va_end(list); 37 | 38 | return n < 0 ? CborErrorIO : CborNoError; 39 | } 40 | 41 | /** 42 | * \fn CborError cbor_value_to_pretty(FILE *out, const CborValue *value) 43 | * 44 | * Converts the current CBOR type pointed to by \a value to its textual 45 | * representation and writes it to the \a out stream. If an error occurs, this 46 | * function returns an error code similar to CborParsing. 47 | * 48 | * \sa cbor_value_to_pretty_advance(), cbor_value_to_json_advance() 49 | */ 50 | 51 | /** 52 | * Converts the current CBOR type pointed to by \a value to its textual 53 | * representation and writes it to the \a out stream. If an error occurs, this 54 | * function returns an error code similar to CborParsing. 55 | * 56 | * If no error ocurred, this function advances \a value to the next element. 57 | * Often, concatenating the text representation of multiple elements can be 58 | * done by appending a comma to the output stream in between calls to this 59 | * function. 60 | * 61 | * \sa cbor_value_to_pretty(), cbor_value_to_pretty_stream(), cbor_value_to_json_advance() 62 | */ 63 | CborError cbor_value_to_pretty_advance(FILE *out, CborValue *value) 64 | { 65 | return cbor_value_to_pretty_stream(cbor_fprintf, out, value, CborPrettyDefaultFlags); 66 | } 67 | 68 | /** 69 | * Converts the current CBOR type pointed to by \a value to its textual 70 | * representation and writes it to the \a out stream. If an error occurs, this 71 | * function returns an error code similar to CborParsing. 72 | * 73 | * The textual representation can be controlled by the \a flags parameter (see 74 | * CborPrettyFlags for more information). 75 | * 76 | * If no error ocurred, this function advances \a value to the next element. 77 | * Often, concatenating the text representation of multiple elements can be 78 | * done by appending a comma to the output stream in between calls to this 79 | * function. 80 | * 81 | * \sa cbor_value_to_pretty_stream(), cbor_value_to_pretty(), cbor_value_to_json_advance() 82 | */ 83 | CborError cbor_value_to_pretty_advance_flags(FILE *out, CborValue *value, int flags) 84 | { 85 | return cbor_value_to_pretty_stream(cbor_fprintf, out, value, flags); 86 | } 87 | 88 | -------------------------------------------------------------------------------- /source/defender-tools/report_builder.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS V202012.00 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | #ifndef REPORT_BUILDER_H_ 28 | #define REPORT_BUILDER_H_ 29 | 30 | /* Metrics collector. */ 31 | #include "metrics_collector.h" 32 | 33 | /** 34 | * @brief Return codes from report builder APIs. 35 | */ 36 | typedef enum 37 | { 38 | eReportBuilderSuccess = 0, 39 | eReportBuilderBadParameter, 40 | eReportBuilderBufferTooSmall 41 | } eReportBuilderStatus; 42 | 43 | /** 44 | * @brief Represents metrics to be included in the report, including custom metrics. 45 | * 46 | * This demo demonstrates the use of the stack high water mark and list of 47 | * running task ids as custom metrics sent to AWS IoT Device Defender service. 48 | * 49 | * For more information on custom metrics, refer to the following AWS document: 50 | * https://docs.aws.amazon.com/iot/latest/developerguide/dd-detect-custom-metrics.html 51 | */ 52 | typedef struct ReportMetrics 53 | { 54 | NetworkStats_t * pxNetworkStats; 55 | uint16_t * pusOpenTcpPortsArray; 56 | uint32_t ulOpenTcpPortsArrayLength; 57 | uint16_t * pusOpenUdpPortsArray; 58 | uint32_t ulOpenUdpPortsArrayLength; 59 | Connection_t * pxEstablishedConnectionsArray; 60 | uint32_t ulEstablishedConnectionsArrayLength; 61 | /* Custom metrics */ 62 | uint32_t ulStackHighWaterMark; 63 | uint32_t * pulTaskIdsArray; 64 | uint32_t ulTaskIdsArrayLength; 65 | } ReportMetrics_t; 66 | 67 | /** 68 | * @brief Generate a report in the format expected by the AWS IoT Device Defender 69 | * Service. 70 | * 71 | * @param[in] pcBuffer The buffer to write the report into. 72 | * @param[in] ulBufferLength The length of the buffer. 73 | * @param[in] pxMetrics Metrics to write in the generated report. 74 | * @param[in] ulMajorReportVersion Major version of the report. 75 | * @param[in] ulMinorReportVersion Minor version of the report. 76 | * @param[in] ulReportId Value to be used as the ulReportId in the generated report. 77 | * @param[out] pulOutReportLength The length of the generated report. 78 | * 79 | * @return #ReportBuilderSuccess if the report is successfully generated; 80 | * #ReportBuilderBadParameter if invalid parameters are passed; 81 | * #ReportBuilderBufferTooSmall if the buffer cannot hold the full report. 82 | */ 83 | eReportBuilderStatus eGenerateJsonReport( char * pcBuffer, 84 | uint32_t ulBufferLength, 85 | const ReportMetrics_t * pxMetrics, 86 | uint32_t ulMajorReportVersion, 87 | uint32_t ulMinorReportVersion, 88 | uint32_t ulReportId, 89 | uint32_t * pulOutReportLength ); 90 | 91 | #endif /* ifndef REPORT_BUILDER_H_ */ 92 | -------------------------------------------------------------------------------- /lib/FreeRTOS/mqtt-agent-interface/include/freertos_command_pool.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS V202104.00 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | /** 28 | * @file freertos_command_pool.h 29 | * @brief Functions to obtain and release a command. 30 | */ 31 | #ifndef FREERTOS_COMMAND_POOL_H 32 | #define FREERTOS_COMMAND_POOL_H 33 | 34 | /* MQTT agent includes. */ 35 | #include "core_mqtt_agent.h" 36 | 37 | /** 38 | * @brief Initialize the common task pool. Not thread safe. 39 | */ 40 | void Agent_InitializePool( void ); 41 | 42 | /** 43 | * @brief Obtain a MQTTAgentCommand_t structure from the pool of structures managed by the agent. 44 | * 45 | * @note MQTTAgentCommand_t structures hold everything the MQTT agent needs to process a 46 | * command that originates from application. Examples of commands are PUBLISH and 47 | * SUBSCRIBE. The MQTTAgentCommand_t structure must persist for the duration of the command's 48 | * operation so are obtained from a pool of statically allocated structures when a 49 | * new command is created, and returned to the pool when the command is complete. 50 | * The MQTT_COMMAND_CONTEXTS_POOL_SIZE configuration file constant defines how many 51 | * structures the pool contains. 52 | * 53 | * @param[in] blockTimeMs The length of time the calling task should remain in the 54 | * Blocked state (so not consuming any CPU time) to wait for a MQTTAgentCommand_t structure to 55 | * become available should one not be immediately at the time of the call. 56 | * 57 | * @return A pointer to a MQTTAgentCommand_t structure if one becomes available before 58 | * blockTimeMs time expired, otherwise NULL. 59 | */ 60 | MQTTAgentCommand_t * Agent_GetCommand( uint32_t blockTimeMs ); 61 | 62 | /** 63 | * @brief Give a MQTTAgentCommand_t structure back to the the pool of structures managed by 64 | * the agent. 65 | * 66 | * @note MQTTAgentCommand_t structures hold everything the MQTT agent needs to process a 67 | * command that originates from application. Examples of commands are PUBLISH and 68 | * SUBSCRIBE. The MQTTAgentCommand_t structure must persist for the duration of the command's 69 | * operation so are obtained from a pool of statically allocated structures when a 70 | * new command is created, and returned to the pool when the command is complete. 71 | * The MQTT_COMMAND_CONTEXTS_POOL_SIZE configuration file constant defines how many 72 | * structures the pool contains. 73 | * 74 | * @param[in] pCommandToRelease A pointer to the MQTTAgentCommand_t structure to return to 75 | * the pool. The structure must first have been obtained by calling 76 | * Agent_GetCommand(), otherwise Agent_ReleaseCommand() will 77 | * have no effect. 78 | * 79 | * @return true if the MQTTAgentCommand_t structure was returned to the pool, otherwise false. 80 | */ 81 | bool Agent_ReleaseCommand( MQTTAgentCommand_t * pCommandToRelease ); 82 | 83 | #endif /* FREERTOS_COMMAND_POOL_H */ 84 | -------------------------------------------------------------------------------- /lib/ThirdParty/WinPCap/Win32-Extensions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1999 - 2005 NetGroup, Politecnico di Torino (Italy) 3 | * Copyright (c) 2005 - 2006 CACE Technologies, Davis (California) 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. Neither the name of the Politecnico di Torino, CACE Technologies 16 | * nor the names of its contributors may be used to endorse or promote 17 | * products derived from this software without specific prior written 18 | * permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | */ 33 | 34 | 35 | #ifndef __WIN32_EXTENSIONS_H__ 36 | #define __WIN32_EXTENSIONS_H__ 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | /* Definitions */ 43 | 44 | /*! 45 | \brief A queue of raw packets that will be sent to the network with pcap_sendqueue_transmit(). 46 | */ 47 | struct pcap_send_queue 48 | { 49 | u_int maxlen; ///< Maximum size of the the queue, in bytes. This variable contains the size of the buffer field. 50 | u_int len; ///< Current size of the queue, in bytes. 51 | char *buffer; ///< Buffer containing the packets to be sent. 52 | }; 53 | 54 | typedef struct pcap_send_queue pcap_send_queue; 55 | 56 | /*! 57 | \brief This typedef is a support for the pcap_get_airpcap_handle() function 58 | */ 59 | #if !defined(AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_) 60 | #define AIRPCAP_HANDLE__EAE405F5_0171_9592_B3C2_C19EC426AD34__DEFINED_ 61 | typedef struct _AirpcapHandle *PAirpcapHandle; 62 | #endif 63 | 64 | #define BPF_MEM_EX_IMM 0xc0 65 | #define BPF_MEM_EX_IND 0xe0 66 | 67 | /*used for ST*/ 68 | #define BPF_MEM_EX 0xc0 69 | #define BPF_TME 0x08 70 | 71 | #define BPF_LOOKUP 0x90 72 | #define BPF_EXECUTE 0xa0 73 | #define BPF_INIT 0xb0 74 | #define BPF_VALIDATE 0xc0 75 | #define BPF_SET_ACTIVE 0xd0 76 | #define BPF_RESET 0xe0 77 | #define BPF_SET_MEMORY 0x80 78 | #define BPF_GET_REGISTER_VALUE 0x70 79 | #define BPF_SET_REGISTER_VALUE 0x60 80 | #define BPF_SET_WORKING 0x50 81 | #define BPF_SET_ACTIVE_READ 0x40 82 | #define BPF_SET_AUTODELETION 0x30 83 | #define BPF_SEPARATION 0xff 84 | 85 | /* Prototypes */ 86 | pcap_send_queue* pcap_sendqueue_alloc(u_int memsize); 87 | 88 | void pcap_sendqueue_destroy(pcap_send_queue* queue); 89 | 90 | int pcap_sendqueue_queue(pcap_send_queue* queue, const struct pcap_pkthdr *pkt_header, const u_char *pkt_data); 91 | 92 | u_int pcap_sendqueue_transmit(pcap_t *p, pcap_send_queue* queue, int sync); 93 | 94 | HANDLE pcap_getevent(pcap_t *p); 95 | 96 | struct pcap_stat *pcap_stats_ex(pcap_t *p, int *pcap_stat_size); 97 | 98 | int pcap_setuserbuffer(pcap_t *p, int size); 99 | 100 | int pcap_live_dump(pcap_t *p, char *filename, int maxsize, int maxpacks); 101 | 102 | int pcap_live_dump_ended(pcap_t *p, int sync); 103 | 104 | int pcap_offline_filter(struct bpf_program *prog, const struct pcap_pkthdr *header, const u_char *pkt_data); 105 | 106 | int pcap_start_oem(char* err_str, int flags); 107 | 108 | PAirpcapHandle pcap_get_airpcap_handle(pcap_t *p); 109 | 110 | #ifdef __cplusplus 111 | } 112 | #endif 113 | 114 | #endif //__WIN32_EXTENSIONS_H__ 115 | -------------------------------------------------------------------------------- /lib/FreeRTOS/utilities/crypto/include/iot_crypto.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS Crypto V1.1.1 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * http://aws.amazon.com/freertos 23 | * http://www.FreeRTOS.org 24 | */ 25 | 26 | #ifndef __AWS_CRYPTO__H__ 27 | #define __AWS_CRYPTO__H__ 28 | 29 | #include "FreeRTOS.h" 30 | 31 | /** 32 | * @brief Commonly used buffer sizes for storing cryptographic hash computation 33 | * results. 34 | */ 35 | #define cryptoSHA1_DIGEST_BYTES 20 36 | #define cryptoSHA256_DIGEST_BYTES 32 37 | 38 | /** 39 | * @brief Initializes the heap and threading functions for cryptography libraries. 40 | */ 41 | void CRYPTO_Init( void ); 42 | 43 | /** 44 | * @brief Initializes the mbedTLS mutex functions. 45 | * 46 | * Provides mbedTLS access to mutex create, destroy, take and free. 47 | * 48 | * @see MBEDTLS_THREADING_ALT 49 | */ 50 | void CRYPTO_ConfigureThreading( void ); 51 | 52 | /** 53 | * @brief Library-independent cryptographic algorithm identifiers. 54 | */ 55 | #define cryptoHASH_ALGORITHM_SHA1 1 56 | #define cryptoHASH_ALGORITHM_SHA256 2 57 | #define cryptoASYMMETRIC_ALGORITHM_RSA 1 58 | #define cryptoASYMMETRIC_ALGORITHM_ECDSA 2 59 | 60 | /** 61 | * @brief Initializes digital signature verification. 62 | * 63 | * @param[out] ppvContext Opaque context structure. 64 | * @param[in] xAsymmetricAlgorithm Cryptographic public key cryptosystem. 65 | * @param[in] xHashAlgorithm Cryptographic hash algorithm that was used for signing. 66 | * 67 | * @return pdTRUE if initialization succeeds, or pdFALSE otherwise. 68 | */ 69 | BaseType_t CRYPTO_SignatureVerificationStart( void ** ppvContext, 70 | BaseType_t xAsymmetricAlgorithm, 71 | BaseType_t xHashAlgorithm ); 72 | 73 | /** 74 | * @brief Updates a cryptographic hash computation with the specified byte array. 75 | * 76 | * @param[in] pvContext Opaque context structure. 77 | * @param[in] pucData Byte array that was signed. 78 | * @param[in] xDataLength Length in bytes of data that was signed. 79 | */ 80 | void CRYPTO_SignatureVerificationUpdate( void * pvContext, 81 | const uint8_t * pucData, 82 | size_t xDataLength ); 83 | 84 | /** 85 | * @brief Verifies a digital signature computation using the public key from the 86 | * specified certificate. 87 | * 88 | * @param[in] pvContext Opaque context structure. 89 | * @param[in] pucSignerCertificate Base64 and DER encoded X.509 certificate of the 90 | * signer. 91 | * @param[in] xSignerCertificateLength Length in bytes of the certificate. 92 | * @param[in] pucSignature Digital signature result to verify. 93 | * @param[in] xSignatureLength in bytes of digital signature result. 94 | * 95 | * @return pdTRUE if the signature is correct or pdFALSE if the signature is invalid. 96 | */ 97 | BaseType_t CRYPTO_SignatureVerificationFinal( void * pvContext, 98 | char * pcSignerCertificate, 99 | size_t xSignerCertificateLength, 100 | uint8_t * pucSignature, 101 | size_t xSignatureLength ); 102 | 103 | #endif /* ifndef __AWS_CRYPTO__H__ */ 104 | -------------------------------------------------------------------------------- /lib/ThirdParty/WinPCap/bittypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 1999 WIDE Project. 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of the project nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | */ 29 | #ifndef _BITTYPES_H 30 | #define _BITTYPES_H 31 | 32 | #ifndef HAVE_U_INT8_T 33 | 34 | #if SIZEOF_CHAR == 1 35 | typedef unsigned char u_int8_t; 36 | typedef signed char _int8_t; 37 | #elif SIZEOF_INT == 1 38 | typedef unsigned int u_int8_t; 39 | typedef signed int int8_t; 40 | #else /* XXX */ 41 | #error "there's no appropriate type for u_int8_t" 42 | #endif 43 | #define HAVE_U_INT8_T 1 44 | #define HAVE_INT8_T 1 45 | 46 | #endif /* HAVE_U_INT8_T */ 47 | 48 | #ifndef HAVE_U_INT16_T 49 | 50 | #if SIZEOF_SHORT == 2 51 | typedef unsigned short u_int16_t; 52 | typedef signed short _int16_t; 53 | #elif SIZEOF_INT == 2 54 | typedef unsigned int u_int16_t; 55 | typedef signed int int16_t; 56 | #elif SIZEOF_CHAR == 2 57 | typedef unsigned char u_int16_t; 58 | typedef signed char int16_t; 59 | #else /* XXX */ 60 | #error "there's no appropriate type for u_int16_t" 61 | #endif 62 | #define HAVE_U_INT16_T 1 63 | #define HAVE_INT16_T 1 64 | 65 | #endif /* HAVE_U_INT16_T */ 66 | 67 | #ifndef HAVE_U_INT32_T 68 | 69 | #if SIZEOF_INT == 4 70 | typedef unsigned int u_int32_t; 71 | typedef signed int _int32_t; 72 | #elif SIZEOF_LONG == 4 73 | typedef unsigned long u_int32_t; 74 | typedef signed long int32_t; 75 | #elif SIZEOF_SHORT == 4 76 | typedef unsigned short u_int32_t; 77 | typedef signed short int32_t; 78 | #else /* XXX */ 79 | #error "there's no appropriate type for u_int32_t" 80 | #endif 81 | #define HAVE_U_INT32_T 1 82 | #define HAVE_INT32_T 1 83 | 84 | #endif /* HAVE_U_INT32_T */ 85 | 86 | #ifndef HAVE_U_INT64_T 87 | #if SIZEOF_LONG_LONG == 8 88 | typedef unsigned long long u_int64_t; 89 | typedef long long int64_t; 90 | #elif defined(_MSC_EXTENSIONS) 91 | typedef unsigned _int64 u_int64_t; 92 | typedef _int64 int64_t; 93 | #elif SIZEOF_INT == 8 94 | typedef unsigned int u_int64_t; 95 | #elif SIZEOF_LONG == 8 96 | typedef unsigned long u_int64_t; 97 | #elif SIZEOF_SHORT == 8 98 | typedef unsigned short u_int64_t; 99 | #else /* XXX */ 100 | #error "there's no appropriate type for u_int64_t" 101 | #endif 102 | 103 | #endif /* HAVE_U_INT64_T */ 104 | 105 | #ifndef PRId64 106 | #ifdef _MSC_EXTENSIONS 107 | #define PRId64 "I64d" 108 | #else /* _MSC_EXTENSIONS */ 109 | #define PRId64 "lld" 110 | #endif /* _MSC_EXTENSIONS */ 111 | #endif /* PRId64 */ 112 | 113 | #ifndef PRIo64 114 | #ifdef _MSC_EXTENSIONS 115 | #define PRIo64 "I64o" 116 | #else /* _MSC_EXTENSIONS */ 117 | #define PRIo64 "llo" 118 | #endif /* _MSC_EXTENSIONS */ 119 | #endif /* PRIo64 */ 120 | 121 | #ifndef PRIx64 122 | #ifdef _MSC_EXTENSIONS 123 | #define PRIx64 "I64x" 124 | #else /* _MSC_EXTENSIONS */ 125 | #define PRIx64 "llx" 126 | #endif /* _MSC_EXTENSIONS */ 127 | #endif /* PRIx64 */ 128 | 129 | #ifndef PRIu64 130 | #ifdef _MSC_EXTENSIONS 131 | #define PRIu64 "I64u" 132 | #else /* _MSC_EXTENSIONS */ 133 | #define PRIu64 "llu" 134 | #endif /* _MSC_EXTENSIONS */ 135 | #endif /* PRIu64 */ 136 | 137 | #endif /* _BITTYPES_H */ 138 | -------------------------------------------------------------------------------- /lib/FreeRTOS/network_transport/freertos_plus_tcp/using_plaintext/using_plaintext.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | * the Software, and to permit persons to whom the Software is furnished to do so, 9 | * subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | */ 21 | 22 | #ifndef USING_PLAINTEXT_H 23 | #define USING_PLAINTEXT_H 24 | 25 | /* FreeRTOS+TCP include. */ 26 | #include "FreeRTOS_Sockets.h" 27 | 28 | /* Transport interface include. */ 29 | #include "transport_interface.h" 30 | 31 | /** 32 | * @brief Network context definition for FreeRTOS sockets. 33 | */ 34 | struct NetworkContext 35 | { 36 | Socket_t tcpSocket; 37 | }; 38 | 39 | /** 40 | * @brief Plain text transport Connect / Disconnect return status. 41 | */ 42 | typedef enum PlaintextTransportStatus 43 | { 44 | PLAINTEXT_TRANSPORT_SUCCESS = 1, /**< Function successfully completed. */ 45 | PLAINTEXT_TRANSPORT_INVALID_PARAMETER = 2, /**< At least one parameter was invalid. */ 46 | PLAINTEXT_TRANSPORT_CONNECT_FAILURE = 3 /**< Initial connection to the server failed. */ 47 | } PlaintextTransportStatus_t; 48 | 49 | /** 50 | * @brief Create a TCP connection with FreeRTOS sockets. 51 | * 52 | * @param[out] pNetworkContext Pointer to a network context to contain the 53 | * initialized socket handle. 54 | * @param[in] pHostName The hostname of the remote endpoint. 55 | * @param[in] port The destination port. 56 | * @param[in] receiveTimeoutMs Receive socket timeout. 57 | * 58 | * @return #PLAINTEXT_TRANSPORT_SUCCESS, #PLAINTEXT_TRANSPORT_INVALID_PARAMETER, 59 | * or #PLAINTEXT_TRANSPORT_CONNECT_FAILURE. 60 | */ 61 | PlaintextTransportStatus_t Plaintext_FreeRTOS_Connect( NetworkContext_t * pNetworkContext, 62 | const char * pHostName, 63 | uint16_t port, 64 | uint32_t receiveTimeoutMs, 65 | uint32_t sendTimeoutMs ); 66 | 67 | /** 68 | * @brief Gracefully disconnect an established TCP connection. 69 | * 70 | * @param[in] pNetworkContext Network context containing the TCP socket handle. 71 | * 72 | * @return #PLAINTEXT_TRANSPORT_SUCCESS, or #PLAINTEXT_TRANSPORT_INVALID_PARAMETER. 73 | */ 74 | PlaintextTransportStatus_t Plaintext_FreeRTOS_Disconnect( const NetworkContext_t * pNetworkContext ); 75 | 76 | /** 77 | * @brief Receives data from an established TCP connection. 78 | * 79 | * @param[in] pNetworkContext The network context containing the TCP socket 80 | * handle. 81 | * @param[out] pBuffer Buffer to receive bytes into. 82 | * @param[in] bytesToRecv Number of bytes to receive from the network. 83 | * 84 | * @return Number of bytes received if successful; 0 if the socket times out; 85 | * Negative value on error. 86 | */ 87 | int32_t Plaintext_FreeRTOS_recv( NetworkContext_t * pNetworkContext, 88 | void * pBuffer, 89 | size_t bytesToRecv ); 90 | 91 | /** 92 | * @brief Sends data over an established TCP connection. 93 | * 94 | * @param[in] pNetworkContext The network context containing the TCP socket 95 | * handle. 96 | * @param[in] pBuffer Buffer containing the bytes to send. 97 | * @param[in] bytesToSend Number of bytes to send from the buffer. 98 | * 99 | * @return Number of bytes sent on success; else a negative value. 100 | */ 101 | int32_t Plaintext_FreeRTOS_send( NetworkContext_t * pNetworkContext, 102 | const void * pBuffer, 103 | size_t bytesToSend ); 104 | 105 | #endif /* ifndef USING_PLAINTEXT_H */ 106 | -------------------------------------------------------------------------------- /source/configuration-files/logging_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Lab-Project-coreMQTT-Agent 201215 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * http://www.FreeRTOS.org 23 | * http://aws.amazon.com/freertos 24 | * 25 | * 1 tab == 4 spaces! 26 | */ 27 | 28 | #ifndef LOGGING_CONFIG_H 29 | #define LOGGING_CONFIG_H 30 | 31 | /**************************************************/ 32 | 33 | /* Helpful macros to make changing logging levels 34 | * easier. */ 35 | /**************************************************/ 36 | #define LOG_NONE 0 37 | #define LOG_ERROR 1 38 | #define LOG_WARN 2 39 | #define LOG_INFO 3 40 | #define LOG_DEBUG 4 41 | /**************************************************/ 42 | 43 | /* 44 | * Change the following macro to set the demo logging level. 45 | */ 46 | #define LOG_LEVEL LOG_DEBUG 47 | 48 | /* 49 | * Logging configuration. 50 | * 51 | * This example uses two function calls per logged message. First 52 | * xLoggingPrintMetadata() attempts to obtain a mutex that grants it access to 53 | * the output port before outputting metadata about the log. Second 54 | * vLoggingPrintf() writes the log message itself before releasing the mutex. 55 | * These are the prototypes of the functions and the definitions of the macros 56 | * that call them - there is one macro per severity level. 57 | * 58 | * If you want to print out additional metadata then update the 59 | * xLoggingPrintMetadata() function prototype and implementation so it accepts 60 | * more parameters, then update the implementation of the macros before to pass 61 | * the additional information. For example, if you want the logs to print out 62 | * the name of the function that called the logging macro then add an additional 63 | * char * parameter to xLoggingPrintMetadata() function: 64 | * 65 | * extern int xLoggingPrintMetadata( const char * const pcLevel, 66 | * const char * const pcFunctionName ); << new parameter 67 | * 68 | * Then update the call to xLoggingPrintMetadata to pass the additional parameter: 69 | * 70 | * xLoggingPrintMetadata( "ERROR", __FUNCTION__ ); << Added __FUNCTION__ as second parameter. 71 | * 72 | * ....and of course update the implementation of xLoggingPrintMetadata() to 73 | * actually print the function name passed in to it. 74 | */ 75 | void vLoggingPrintf( const char * const pcFormatString, 76 | ... ); 77 | int32_t xLoggingPrintMetadata( const char * const pcLevel ); 78 | void vLoggingInit( void ); 79 | 80 | /* See comments immediately above for instructions on changing the verboseness 81 | * of the logging and adding data such as the function that called the logging 82 | * macro to the logged output. 83 | */ 84 | #if LOG_LEVEL >= LOG_ERROR 85 | #define LogError( message ) do { xLoggingPrintMetadata( "ERROR" ); vLoggingPrintf message; } while( 0 ) 86 | #else 87 | #define LogError( message ) 88 | #endif 89 | 90 | #if LOG_LEVEL >= LOG_WARN 91 | #define LogWarn( message ) do { xLoggingPrintMetadata( "WARN" ); vLoggingPrintf message; } while( 0 ) 92 | #else 93 | #define LogWarn( message ) 94 | #endif 95 | 96 | #if LOG_LEVEL >= LOG_INFO 97 | #define LogInfo( message ) do { xLoggingPrintMetadata( "INFO" ); vLoggingPrintf message; } while( 0 ) 98 | #else 99 | #define LogInfo( message ) 100 | #endif 101 | 102 | #if LOG_LEVEL >= LOG_DEBUG 103 | #define LogDebug( message ) do { xLoggingPrintMetadata( "DEBUG" ); vLoggingPrintf message; } while( 0 ) 104 | #else 105 | #define LogDebug( message ) 106 | #endif 107 | 108 | #endif /* LOGGING_CONFIG_H */ 109 | -------------------------------------------------------------------------------- /.github/.cSpellWords.txt: -------------------------------------------------------------------------------- 1 | ack 2 | acked 3 | acks 4 | aes 5 | alpn 6 | api 7 | apis 8 | auth 9 | aws 10 | backoff 11 | bi 12 | bo 13 | boston 14 | ca 15 | cbor 16 | certs 17 | cli 18 | clientauthentication 19 | clientidentifierlength 20 | clienttoken 21 | cmdcompletecallback 22 | com 23 | config 24 | configs 25 | connack 26 | connectmanager 27 | const 28 | coremqtt 29 | corepkcs 30 | cpu 31 | dd 32 | defenderjsonreportaccepted 33 | defendersuccess 34 | deserialize 35 | deserialized 36 | developerguide 37 | dhcp 38 | doesn 39 | emetricscollectorbadparameter 40 | emetricscollectorcollectionfailed 41 | emetricscollectorsuccess 42 | endif 43 | ethernet 44 | freertos 45 | freertosconfig 46 | getdeviceserialnumber 47 | github 48 | gpl 49 | hed 50 | html 51 | http 52 | https 53 | ifdef 54 | ifndef 55 | inc 56 | init 57 | int 58 | iot 59 | ip 60 | json 61 | keepalive 62 | logdebug 63 | mac 64 | mbed 65 | metadata 66 | mosquitto 67 | mqtt 68 | mqttbadparameter 69 | mqttsuccess 70 | msgsize 71 | mutex 72 | noninfringement 73 | ns 74 | org 75 | os 76 | ota 77 | otamqttsuccess 78 | packetid 79 | pactopic 80 | palpnprotos 81 | param 82 | pbincomingpublishcallbackcontext 83 | pc 84 | pcbuffer 85 | pcdefenderresponse 86 | pcfunctionname 87 | pclevel 88 | pclientidentifier 89 | pcreceivedpublishpayload 90 | pctaskname 91 | pctopicfilterstring 92 | pdata 93 | pdfail 94 | pdfalse 95 | pdpass 96 | pdtrue 97 | pdvgettimems 98 | pem 99 | pingreq 100 | plaintext 101 | pmqttagentcontext 102 | pmsg 103 | po 104 | poweron 105 | ppublishinfo 106 | ppxidletaskstackbuffer 107 | ppxtimertaskstackbuffer 108 | presigned 109 | prvconnectandcreatedemotasks 110 | prvdefenderdemotask 111 | prvgettimems 112 | prvincomingpublish 113 | prvincomingpublishcallback 114 | prvincomingpublishupdateacceptedcallback 115 | prvincomingpublishupdatedeltacallback 116 | prvincomingpublishupdaterejectedcallback 117 | prvlargemessagesubscribepublishtask 118 | prvmqttagenttask 119 | prvsimplesubscribepublishtask 120 | prvstartmqttagentdemo 121 | prvstartsimplemqttdemos 122 | prvsubscribecommandcallback 123 | prvsubscribetodefendertopics 124 | pthingname 125 | ptopic 126 | ptopicfilter 127 | puback 128 | pulnotifiedvalue 129 | pulnumber 130 | puloutcharswritten 131 | puloutnumestablishedconnections 132 | puloutnumtcpopenports 133 | puloutnumudpopenports 134 | puloutreportlength 135 | pultaskidsarray 136 | pultaskidsarraylength 137 | pusopenportsarray 138 | pusoutnumestablishedconnections 139 | pusouttcpportsarray 140 | pusoutudpportsarray 141 | putoutcharswritten 142 | putoutreportlength 143 | pvincomingpublishcallbackcontext 144 | pvparam 145 | pvparameters 146 | pvparamters 147 | pvtag 148 | pxbuffer 149 | pxcommandcontext 150 | pxconnectionsarray 151 | pxincomingpublishcallback 152 | pxmetrics 153 | pxmqttcontext 154 | pxnetworkcontext 155 | pxoutconnectionsarray 156 | pxoutnetworkstats 157 | pxpublishinfo 158 | pxreturninfo 159 | pxsocket 160 | pxsubscriptioncontext 161 | pxsubscriptionlist 162 | qos 163 | receivedechopayload 164 | reportbuilderbadparameter 165 | reportbuilderbuffertoosmall 166 | reportbuildersuccess 167 | reportid 168 | resubscribe 169 | resubscribes 170 | rfc 171 | rom 172 | rsa 173 | rtos 174 | sdk 175 | sdklog 176 | shadowdevice 177 | shadowupdate 178 | sni 179 | snprintf 180 | spdx 181 | ssl 182 | strlen 183 | struct 184 | suback 185 | sublicense 186 | tcp 187 | thingname 188 | thingnamelength 189 | tls 190 | todo 191 | topicbuffer 192 | topicfilter 193 | topicfilterlength 194 | topiclen 195 | topiclength 196 | topicname 197 | topicnamelength 198 | trng 199 | txt 200 | ucqos 201 | udp 202 | ulblockvariable 203 | ulbufferlength 204 | ulbytesreceived 205 | ulbytessent 206 | ulclienttoken 207 | ulconnectionsarraylength 208 | ulcurrentversion 209 | uldefenderresponselength 210 | ulglobalentrytimems 211 | ulmajorreportversion 212 | ulminorreportversion 213 | ulnextsubscribemessageid 214 | ulnotification 215 | ulnotificationvalue 216 | ulopenportsarraylength 217 | ulpacketsreceived 218 | ulpacketssent 219 | ulrecievedtoken 220 | ulreportid 221 | ulreportlength 222 | ultasknotificationtake 223 | ultasknotifytake 224 | ultcpportsarraylength 225 | uludpportsarraylength 226 | usa 227 | ustopicfilterlength 228 | uxpriority 229 | uxstacksize 230 | uxtasksize 231 | vapplicationgetidletaskmemory 232 | vapplicationgettimertaskmemory 233 | vapplicationipnetworkeventhook 234 | ve 235 | vloggingprintf 236 | vshadowdevicetask 237 | vshadowupdatetask 238 | vsimplesubscribepublishtask 239 | winsim 240 | wireshark 241 | www 242 | xbuffersize 243 | xcleansession 244 | xcommandparams 245 | xcommandqueue 246 | xloggingprintmetadata 247 | xlogtofile 248 | xlogtostdout 249 | xlogtoudp 250 | xqos 251 | xreturnstatus 252 | xtaskcreate 253 | xtaskgettickcount 254 | xtasknotify 255 | xtasktonotify 256 | optim 257 | drbg 258 | ecdh 259 | mqttexample 260 | otaexample -------------------------------------------------------------------------------- /source/demo-tasks/shadow_demo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS V202012.00 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | /* 28 | * Demo for showing how to use the Device Shadow library with the MQTT Agent. The Device 29 | * Shadow library provides macros and helper functions for assembling MQTT topics 30 | * strings, and for determining whether an incoming MQTT message is related to the 31 | * device shadow. 32 | * 33 | * This demo contains two tasks. The first demonstrates typical use of the Device Shadow library 34 | * by keeping the shadow up to date and reacting to changes made to the shadow. 35 | * If enabled, the second task uses the Device Shadow library to request change to the device 36 | * shadow. This serves to create events for the first task to react to for demonstration purposes. 37 | */ 38 | 39 | /* Kernel includes. */ 40 | #include "FreeRTOS.h" 41 | #include "task.h" 42 | 43 | /* Demo config. */ 44 | #include "demo_config.h" 45 | 46 | /** 47 | * democonfigCLIENT_IDENTIFIER is required. Throw compilation error if it is not defined. 48 | */ 49 | #ifndef democonfigCLIENT_IDENTIFIER 50 | #error "Please define democonfigCLIENT_IDENTIFIER in demo_config.h to the thing name registered with AWS IoT Core." 51 | #endif 52 | 53 | /** 54 | * Enable/disable the task that sends desired state requests to the Device Shadow service for 55 | * demonstration purposes. 56 | */ 57 | #define shadowexampleENABLE_UPDATE_TASK 1 58 | 59 | /*-----------------------------------------------------------*/ 60 | 61 | /** 62 | * @brief The task used to demonstrate using the Shadow API on a device. 63 | * 64 | * @param[in] pvParameters Parameters as passed at the time of task creation. Not 65 | * used in this example. 66 | */ 67 | extern void vShadowDeviceTask( void * pvParameters ); 68 | 69 | /** 70 | * @brief The task used to request changes to the device's shadow. 71 | * 72 | * @param[in] pvParameters Parameters as passed at the time of task creation. Not 73 | * used in this example. 74 | */ 75 | extern void vShadowUpdateTask( void * pvParameters ); 76 | 77 | /*-----------------------------------------------------------*/ 78 | 79 | /* 80 | * @brief Create the tasks that demonstrate the Device Shadow library API. 81 | */ 82 | void vStartShadowDemo( configSTACK_DEPTH_TYPE uxStackSize, 83 | UBaseType_t uxPriority ) 84 | { 85 | xTaskCreate( vShadowDeviceTask, /* Function that implements the task. */ 86 | "ShadowDevice", /* Text name for the task - only used for debugging. */ 87 | uxStackSize, /* Size of stack (in words, not bytes) to allocate for the task. */ 88 | NULL, /* Task parameter - not used in this case. */ 89 | uxPriority, /* Task priority, must be between 0 and configMAX_PRIORITIES - 1. */ 90 | NULL ); /* Used to pass out a handle to the created task - not used in this case. */ 91 | 92 | #if ( shadowexampleENABLE_UPDATE_TASK == 1 ) 93 | xTaskCreate( vShadowUpdateTask, /* Function that implements the task. */ 94 | "ShadowUpdate", /* Text name for the task - only used for debugging. */ 95 | uxStackSize, /* Size of stack (in words, not bytes) to allocate for the task. */ 96 | NULL, /* Task parameter - not used in this case. */ 97 | uxPriority, /* Task priority, must be between 0 and configMAX_PRIORITIES - 1. */ 98 | NULL ); /* Used to pass out a handle to the created task - not used in this case. */ 99 | #endif 100 | } 101 | 102 | /*-----------------------------------------------------------*/ 103 | -------------------------------------------------------------------------------- /lib/ThirdParty/tinycbor/src/cborparser_dup_string.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2016 Intel Corporation 4 | ** 5 | ** Permission is hereby granted, free of charge, to any person obtaining a copy 6 | ** of this software and associated documentation files (the "Software"), to deal 7 | ** in the Software without restriction, including without limitation the rights 8 | ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | ** copies of the Software, and to permit persons to whom the Software is 10 | ** furnished to do so, subject to the following conditions: 11 | ** 12 | ** The above copyright notice and this permission notice shall be included in 13 | ** all copies or substantial portions of the Software. 14 | ** 15 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | ** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | ** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | ** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | ** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | ** THE SOFTWARE. 22 | ** 23 | ****************************************************************************/ 24 | 25 | #ifndef _BSD_SOURCE 26 | #define _BSD_SOURCE 1 27 | #endif 28 | #ifndef _DEFAULT_SOURCE 29 | #define _DEFAULT_SOURCE 1 30 | #endif 31 | #ifndef __STDC_LIMIT_MACROS 32 | # define __STDC_LIMIT_MACROS 1 33 | #endif 34 | 35 | #include "cbor.h" 36 | #include "compilersupport_p.h" 37 | #include 38 | 39 | /** 40 | * \fn CborError cbor_value_dup_text_string(const CborValue *value, char **buffer, size_t *buflen, CborValue *next) 41 | * 42 | * Allocates memory for the string pointed by \a value and copies it into this 43 | * buffer. The pointer to the buffer is stored in \a buffer and the number of 44 | * bytes copied is stored in \a buflen (those variables must not be NULL). 45 | * 46 | * If the iterator \a value does not point to a text string, the behaviour is 47 | * undefined, so checking with \ref cbor_value_get_type or \ref 48 | * cbor_value_is_text_string is recommended. 49 | * 50 | * If \c malloc returns a NULL pointer, this function will return error 51 | * condition \ref CborErrorOutOfMemory. 52 | * 53 | * On success, \c{*buffer} will contain a valid pointer that must be freed by 54 | * calling \c{free()}. This is the case even for zero-length strings. 55 | * 56 | * The \a next pointer, if not null, will be updated to point to the next item 57 | * after this string. If \a value points to the last item, then \a next will be 58 | * invalid. 59 | * 60 | * This function may not run in constant time (it will run in O(n) time on the 61 | * number of chunks). It requires constant memory (O(1)) in addition to the 62 | * malloc'ed block. 63 | * 64 | * \note This function does not perform UTF-8 validation on the incoming text 65 | * string. 66 | * 67 | * \sa cbor_value_get_text_string_chunk(), cbor_value_copy_text_string(), cbor_value_dup_byte_string() 68 | */ 69 | 70 | /** 71 | * \fn CborError cbor_value_dup_byte_string(const CborValue *value, uint8_t **buffer, size_t *buflen, CborValue *next) 72 | * 73 | * Allocates memory for the string pointed by \a value and copies it into this 74 | * buffer. The pointer to the buffer is stored in \a buffer and the number of 75 | * bytes copied is stored in \a buflen (those variables must not be NULL). 76 | * 77 | * If the iterator \a value does not point to a byte string, the behaviour is 78 | * undefined, so checking with \ref cbor_value_get_type or \ref 79 | * cbor_value_is_byte_string is recommended. 80 | * 81 | * If \c malloc returns a NULL pointer, this function will return error 82 | * condition \ref CborErrorOutOfMemory. 83 | * 84 | * On success, \c{*buffer} will contain a valid pointer that must be freed by 85 | * calling \c{free()}. This is the case even for zero-length strings. 86 | * 87 | * The \a next pointer, if not null, will be updated to point to the next item 88 | * after this string. If \a value points to the last item, then \a next will be 89 | * invalid. 90 | * 91 | * This function may not run in constant time (it will run in O(n) time on the 92 | * number of chunks). It requires constant memory (O(1)) in addition to the 93 | * malloc'ed block. 94 | * 95 | * \sa cbor_value_get_text_string_chunk(), cbor_value_copy_byte_string(), cbor_value_dup_text_string() 96 | */ 97 | CborError _cbor_value_dup_string(const CborValue *value, void **buffer, size_t *buflen, CborValue *next) 98 | { 99 | CborError err; 100 | cbor_assert(buffer); 101 | cbor_assert(buflen); 102 | *buflen = SIZE_MAX; 103 | err = _cbor_value_copy_string(value, NULL, buflen, NULL); 104 | if (err) 105 | return err; 106 | 107 | ++*buflen; 108 | *buffer = malloc(*buflen); 109 | if (!*buffer) { 110 | /* out of memory */ 111 | return CborErrorOutOfMemory; 112 | } 113 | err = _cbor_value_copy_string(value, *buffer, buflen, next); 114 | if (err) { 115 | free(*buffer); 116 | return err; 117 | } 118 | return CborNoError; 119 | } 120 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## coreMQTT Agent and Demo Tasks (including OTA) 2 | 3 | This repository demonstrates examples of using AWS IoT Device Shadow, Device Defender, and OTA from multiple threads. It uses FreeRTOS and the [coreMQTT Agent library](https://github.com/FreeRTOS/coreMQTT-Agent), an extension on top of [coreMQTT](https://github.com/FreeRTOS/coreMQTT) that provides MQTT APIs with thread safety. The examples here share a single MQTT connection amongst multiple concurrent tasks, without requiring the management of any synchronization primitives from the application. 4 | 5 | ## Cloning this repository 6 | This repo uses [Git Submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules) to bring in dependent components. 7 | 8 | **Note:** If you download the ZIP file provided by the GitHub UI, you will not get the contents of the submodules. (The ZIP file is also not a valid git repository) 9 | 10 | To clone using HTTPS: 11 | ``` 12 | git clone https://github.com/FreeRTOS/coreMQTT-Agent-Demos.git --recurse-submodules 13 | ``` 14 | Using SSH: 15 | ``` 16 | git clone git@github.com:FreeRTOS/coreMQTT-Agent-Demos.git --recurse-submodules 17 | ``` 18 | 19 | If you have downloaded the repo without using the `--recurse-submodules` argument, you need to run: 20 | ``` 21 | git submodule update --init --recursive 22 | ``` 23 | 24 | ## Getting started 25 | The [documentation page](https://freertos.org/mqtt/mqtt-agent-demo.html) for this repository contains information on the MQTT agent and the contained demo project. There is also a [supplemental documentation page](https://freertos.org/ota/ota-mqtt-agent-demo.html) that describes how to run an Over-the-Air (OTA) update agent as one of the RTOS tasks that share the same MQTT connection. 26 | 27 | ## Building Demos 28 | This repository contains both a Visual Studio project that uses the FreeRTOS Windows port and can be built using the free [Community version of Visual Studio](https://visualstudio.microsoft.com/vs/community/), and a GCC/makefile project that build the FreeRTOS ARM Cortex-M3 port and targets the [QEMU hardware emulator](https://www.qemu.org/). The makefile can be built from the command line or the provided Eclipse project, and works on both Windows and Linux hosts. 29 | 30 | ### Visual Studio 31 | 32 | 1. Ensure to follow the instructions on the above linked demo documentation page to configure the build as required to access your network. 33 | 34 | 1. From the Visual Studio IDE, open the `mqtt_multitask_demo.sln` Visual Studio solution file in the `build/VisualStudio/` directory. 35 | 36 | 1. Select **Build Solution** from the IDE's **Build** menu. 37 | 38 | 39 | ### QEMU Cortex-M3 40 | 41 | **Command Line** 42 | 43 | 1. Ensure that `arm-none-eabi-gcc` from the [GNU ARM Embedded Toolchain](https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads) and GNU `make` are in your path. 44 | 45 | 1. From the `build/Cortex-M3_MPS2_QEMU_GCC` directory, run `make`. 46 | 47 | **Eclipse IDE** 48 | 49 | 1. Ensure that `arm-none-eabi-gcc` from the [GNU ARM Embedded Toolchain](https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads) and GNU `make` are in your path. 50 | 51 | 1. Open the `build/Cortex-M3_MPS2_QEMU_GCC` directory as an Eclipse project. 52 | 53 | 1. Select `Project -> Build Project` from the Eclipse menu. 54 | 55 | In both cases, the generated executable can be found at `build/Cortex-M3_MPS2_QEMU_GCC/output/RTOSDemo.elf`. 56 | 57 | **Running the Makefile build in QEMU** 58 | 59 | Use the QEMU command contained in the [start_qemu.bat](build/Cortex-M3_MPS2_QEMU_GCC/start_qemu.bat) batch file to run the generated `RTOSDemo.elf` file directly. Alternatively, use the command contained in the [start_qemu_and_wait.bat](build/Cortex-M3_MPS2_QEMU_GCC/start_qemu_and_wait.bat) batch file to start QEMU and wait for a GDB connection on port 1234. The Eclipse project contains a configuration suitable for debugging. 60 | 61 | Note that these QEMU commands assume there is a network tap driver called "TAP0". 62 | 63 | **Obtaining network access from QEMU on Windows** 64 | 65 | 1. Install the [OpenVPN TAP driver for Windows](https://openvpn.net/). 66 | 67 | 1. Name the installed TAP interface "TAP0". This can be done by selecting "Change adapter settings" from Windows' Network Properties window (Control Panel\Network and Internet\Network Connections) to view all network adapters, selecting the installed TAP adapter, and then pressing F2 to edit the adapter's name. 68 | 69 | 1. From the same window, configure a real wired network interface to have a static IP address that is within the range of IP addresses allocated by your local DHCP server. 70 | 71 | 1. Still in the same window, select both the real network adapter and the TAP adapter at the same, then right click, and select "Bridge Connections" from the pop up menu. 72 | 73 | ## Getting help 74 | You can use your Github login to get support from both the FreeRTOS community and directly from the primary FreeRTOS developers on our [active support forum](https://forums.freertos.org). You can also find a list of frequently asked questions [here](https://www.freertos.org/FAQ.html). 75 | 76 | ## Security 77 | 78 | See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information. 79 | 80 | ## License 81 | 82 | This library is licensed under the MIT License. See the [LICENSE](LICENSE.md) file. 83 | -------------------------------------------------------------------------------- /source/configuration-files/mbedtls_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006-2018, ARM Limited, All Rights Reserved 3 | * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later 4 | * 5 | * This file is provided under the Apache License 2.0, or the 6 | * GNU General Public License v2.0 or later. 7 | * 8 | * ********** 9 | * Apache License 2.0: 10 | * 11 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 12 | * not use this file except in compliance with the License. 13 | * You may obtain a copy of the License at 14 | * 15 | * http://www.apache.org/licenses/LICENSE-2.0 16 | * 17 | * Unless required by applicable law or agreed to in writing, software 18 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 19 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 | * See the License for the specific language governing permissions and 21 | * limitations under the License. 22 | * 23 | * ********** 24 | * 25 | * ********** 26 | * GNU General Public License v2.0 or later: 27 | * 28 | * This program is free software; you can redistribute it and/or modify 29 | * it under the terms of the GNU General Public License as published by 30 | * the Free Software Foundation; either version 2 of the License, or 31 | * (at your option) any later version. 32 | * 33 | * This program is distributed in the hope that it will be useful, 34 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 35 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 36 | * GNU General Public License for more details. 37 | * 38 | * You should have received a copy of the GNU General Public License along 39 | * with this program; if not, write to the Free Software Foundation, Inc., 40 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 41 | * 42 | * ********** 43 | * 44 | * This repository uses Mbed TLS under Apache 2.0 45 | */ 46 | 47 | /* This file configures mbed TLS for FreeRTOS. */ 48 | 49 | #ifndef MBEDTLS_CONFIG_H 50 | #define MBEDTLS_CONFIG_H 51 | 52 | #include 53 | #include 54 | 55 | #define MBEDTLS_DEBUG_C 56 | #define MBEDTLS_DEBUG_THRESHOLD 5 /* 0 to 5. */ 57 | 58 | /* Generate errors if deprecated functions are used. */ 59 | #define MBEDTLS_DEPRECATED_REMOVED 60 | 61 | /* Place AES tables in ROM. */ 62 | #define MBEDTLS_AES_ROM_TABLES 63 | 64 | /* Enable the following cipher modes. */ 65 | #define MBEDTLS_CIPHER_MODE_CBC 66 | #define MBEDTLS_CIPHER_MODE_CFB 67 | #define MBEDTLS_CIPHER_MODE_CTR 68 | 69 | /* Enable the following cipher padding modes. */ 70 | #define MBEDTLS_CIPHER_PADDING_PKCS7 71 | #define MBEDTLS_CIPHER_PADDING_ONE_AND_ZEROS 72 | #define MBEDTLS_CIPHER_PADDING_ZEROS_AND_LEN 73 | #define MBEDTLS_CIPHER_PADDING_ZEROS 74 | 75 | /* Cipher suite configuration. */ 76 | #define MBEDTLS_REMOVE_ARC4_CIPHERSUITES 77 | #define MBEDTLS_ECP_DP_SECP256R1_ENABLED 78 | #define MBEDTLS_ECP_NIST_OPTIM 79 | #define MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED 80 | #define MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED 81 | 82 | /* Enable all SSL alert messages. */ 83 | #define MBEDTLS_SSL_ALL_ALERT_MESSAGES 84 | 85 | /* Enable the following SSL features. */ 86 | #define MBEDTLS_SSL_ENCRYPT_THEN_MAC 87 | #define MBEDTLS_SSL_EXTENDED_MASTER_SECRET 88 | #define MBEDTLS_SSL_MAX_FRAGMENT_LENGTH 89 | #define MBEDTLS_SSL_PROTO_TLS1_2 90 | #define MBEDTLS_SSL_ALPN 91 | #define MBEDTLS_SSL_SERVER_NAME_INDICATION 92 | 93 | /* Check certificate key usage. */ 94 | #define MBEDTLS_X509_CHECK_KEY_USAGE 95 | #define MBEDTLS_X509_CHECK_EXTENDED_KEY_USAGE 96 | 97 | /* Disable platform entropy functions. */ 98 | #define MBEDTLS_NO_PLATFORM_ENTROPY 99 | 100 | /* Enable the following mbed TLS features. */ 101 | #define MBEDTLS_AES_C 102 | #define MBEDTLS_ASN1_PARSE_C 103 | #define MBEDTLS_ASN1_WRITE_C 104 | #define MBEDTLS_BASE64_C 105 | #define MBEDTLS_BIGNUM_C 106 | #define MBEDTLS_CIPHER_C 107 | #define MBEDTLS_CTR_DRBG_C 108 | #define MBEDTLS_ECDH_C 109 | #define MBEDTLS_ECDSA_C 110 | #define MBEDTLS_ECP_C 111 | #define MBEDTLS_ENTROPY_C 112 | #define MBEDTLS_GCM_C 113 | #define MBEDTLS_MD_C 114 | #define MBEDTLS_OID_C 115 | #define MBEDTLS_PEM_PARSE_C 116 | #define MBEDTLS_PK_C 117 | #define MBEDTLS_PK_PARSE_C 118 | #define MBEDTLS_PKCS1_V15 119 | #define MBEDTLS_PLATFORM_C 120 | #define MBEDTLS_RSA_C 121 | #define MBEDTLS_SHA1_C 122 | #define MBEDTLS_SHA256_C 123 | #define MBEDTLS_SSL_CLI_C 124 | #define MBEDTLS_SSL_TLS_C 125 | #define MBEDTLS_THREADING_ALT 126 | #define MBEDTLS_THREADING_C 127 | #define MBEDTLS_X509_USE_C 128 | #define MBEDTLS_X509_CRT_PARSE_C 129 | 130 | /* Set the memory allocation functions on FreeRTOS. */ 131 | void * mbedtls_platform_calloc( size_t nmemb, 132 | size_t size ); 133 | void mbedtls_platform_free( void * ptr ); 134 | 135 | #define MBEDTLS_PLATFORM_MEMORY 136 | #define MBEDTLS_PLATFORM_CALLOC_MACRO mbedtls_platform_calloc 137 | #define MBEDTLS_PLATFORM_FREE_MACRO mbedtls_platform_free 138 | 139 | /* The network send and receive functions on FreeRTOS. */ 140 | int mbedtls_platform_send( void * ctx, 141 | const unsigned char * buf, 142 | size_t len ); 143 | int mbedtls_platform_recv( void * ctx, 144 | unsigned char * buf, 145 | size_t len ); 146 | 147 | /* The entropy poll function. */ 148 | int mbedtls_platform_entropy_poll( void * data, 149 | unsigned char * output, 150 | size_t len, 151 | size_t * olen ); 152 | 153 | #include "mbedtls/check_config.h" 154 | 155 | #endif /* ifndef MBEDTLS_CONFIG_H */ 156 | -------------------------------------------------------------------------------- /source/subscription-manager/subscription_manager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS V202011.00 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://aws.amazon.com/freertos 24 | * 25 | */ 26 | 27 | /** 28 | * @file subscription_manager.h 29 | * @brief Functions for managing MQTT subscriptions. 30 | */ 31 | #ifndef SUBSCRIPTION_MANAGER_H 32 | #define SUBSCRIPTION_MANAGER_H 33 | 34 | 35 | /* Demo config include. */ 36 | #include "demo_config.h" 37 | 38 | /* core MQTT include. */ 39 | #include "core_mqtt.h" 40 | #include "core_mqtt_config_defaults.h" 41 | 42 | /** 43 | * @brief Maximum number of subscriptions maintained by the subscription manager 44 | * simultaneously in a list. 45 | */ 46 | #ifndef SUBSCRIPTION_MANAGER_MAX_SUBSCRIPTIONS 47 | #define SUBSCRIPTION_MANAGER_MAX_SUBSCRIPTIONS 10U 48 | #endif 49 | 50 | /** 51 | * @brief Callback function called when receiving a publish. 52 | * 53 | * @param[in] pvIncomingPublishCallbackContext The incoming publish callback context. 54 | * @param[in] pxPublishInfo Deserialized publish information. 55 | */ 56 | typedef void (* IncomingPubCallback_t )( void * pvIncomingPublishCallbackContext, 57 | MQTTPublishInfo_t * pxPublishInfo ); 58 | 59 | /** 60 | * @brief An element in the list of subscriptions. 61 | * 62 | * This subscription manager implementation expects that the array of the 63 | * subscription elements used for storing subscriptions to be initialized to 0. 64 | * 65 | * @note This implementation allows multiple tasks to subscribe to the same topic. 66 | * In this case, another element is added to the subscription list, differing 67 | * in the intended publish callback. Also note that the topic filters are not 68 | * copied in the subscription manager and hence the topic filter strings need to 69 | * stay in scope until unsubscribed. 70 | */ 71 | typedef struct subscriptionElement 72 | { 73 | IncomingPubCallback_t pxIncomingPublishCallback; 74 | void * pvIncomingPublishCallbackContext; 75 | uint16_t usFilterStringLength; 76 | const char * pcSubscriptionFilterString; 77 | } SubscriptionElement_t; 78 | 79 | /** 80 | * @brief Add a subscription to the subscription list. 81 | * 82 | * @note Multiple tasks can be subscribed to the same topic with different 83 | * context-callback pairs. However, a single context-callback pair may only be 84 | * associated to the same topic filter once. 85 | * 86 | * @param[in] pxSubscriptionList The pointer to the subscription list array. 87 | * @param[in] pcTopicFilterString Topic filter string of subscription. 88 | * @param[in] usTopicFilterLength Length of topic filter string. 89 | * @param[in] pxIncomingPublishCallback Callback function for the subscription. 90 | * @param[in] pvIncomingPublishCallbackContext Context for the subscription callback. 91 | * 92 | * @return `true` if subscription added or exists, `false` if insufficient memory. 93 | */ 94 | bool addSubscription( SubscriptionElement_t * pxSubscriptionList, 95 | const char * pcTopicFilterString, 96 | uint16_t usTopicFilterLength, 97 | IncomingPubCallback_t pxIncomingPublishCallback, 98 | void * pvIncomingPublishCallbackContext ); 99 | 100 | /** 101 | * @brief Remove a subscription from the subscription list. 102 | * 103 | * @note If the topic filter exists multiple times in the subscription list, 104 | * then every instance of the subscription will be removed. 105 | * 106 | * @param[in] pxSubscriptionList The pointer to the subscription list array. 107 | * @param[in] pcTopicFilterString Topic filter of subscription. 108 | * @param[in] usTopicFilterLength Length of topic filter. 109 | */ 110 | void removeSubscription( SubscriptionElement_t * pxSubscriptionList, 111 | const char * pcTopicFilterString, 112 | uint16_t usTopicFilterLength ); 113 | 114 | /** 115 | * @brief Handle incoming publishes by invoking the callbacks registered 116 | * for the incoming publish's topic filter. 117 | * 118 | * @param[in] pxSubscriptionList The pointer to the subscription list array. 119 | * @param[in] pxPublishInfo Info of incoming publish. 120 | * 121 | * @return `true` if an application callback could be invoked; 122 | * `false` otherwise. 123 | */ 124 | bool handleIncomingPublishes( SubscriptionElement_t * pxSubscriptionList, 125 | MQTTPublishInfo_t * pxPublishInfo ); 126 | 127 | #endif /* SUBSCRIPTION_MANAGER_H */ 128 | -------------------------------------------------------------------------------- /lib/FreeRTOS/mqtt-agent-interface/freertos_command_pool.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS V202104.00 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | /** 28 | * @file freertos_command_pool.c 29 | * @brief Implements functions to obtain and release commands. 30 | */ 31 | 32 | /* Standard includes. */ 33 | #include 34 | #include 35 | 36 | /* Kernel includes. */ 37 | #include "FreeRTOS.h" 38 | #include "semphr.h" 39 | 40 | /* Header include. */ 41 | #include "freertos_command_pool.h" 42 | #include "freertos_agent_message.h" 43 | 44 | /*-----------------------------------------------------------*/ 45 | 46 | #define QUEUE_NOT_INITIALIZED ( 0U ) 47 | #define QUEUE_INITIALIZED ( 1U ) 48 | 49 | /** 50 | * @brief The pool of command structures used to hold information on commands (such 51 | * as PUBLISH or SUBSCRIBE) between the command being created by an API call and 52 | * completion of the command by the execution of the command's callback. 53 | */ 54 | static MQTTAgentCommand_t commandStructurePool[ MQTT_COMMAND_CONTEXTS_POOL_SIZE ]; 55 | 56 | /** 57 | * @brief The message context used to guard the pool of MQTTAgentCommand_t structures. 58 | * For FreeRTOS, this is implemented with a queue. Structures may be 59 | * obtained by receiving a pointer from the queue, and returned by 60 | * sending the pointer back into it. 61 | */ 62 | static MQTTAgentMessageContext_t commandStructMessageCtx; 63 | 64 | /** 65 | * @brief Initialization status of the queue. 66 | */ 67 | static volatile uint8_t initStatus = QUEUE_NOT_INITIALIZED; 68 | 69 | /*-----------------------------------------------------------*/ 70 | 71 | void Agent_InitializePool( void ) 72 | { 73 | size_t i; 74 | MQTTAgentCommand_t * pCommand; 75 | static uint8_t staticQueueStorageArea[ MQTT_COMMAND_CONTEXTS_POOL_SIZE * sizeof( MQTTAgentCommand_t * ) ]; 76 | static StaticQueue_t staticQueueStructure; 77 | bool commandAdded = false; 78 | 79 | if( initStatus == QUEUE_NOT_INITIALIZED ) 80 | { 81 | memset( ( void * ) commandStructurePool, 0x00, sizeof( commandStructurePool ) ); 82 | commandStructMessageCtx.queue = xQueueCreateStatic( MQTT_COMMAND_CONTEXTS_POOL_SIZE, 83 | sizeof( MQTTAgentCommand_t * ), 84 | staticQueueStorageArea, 85 | &staticQueueStructure ); 86 | configASSERT( commandStructMessageCtx.queue ); 87 | 88 | /* Populate the queue. */ 89 | for( i = 0; i < MQTT_COMMAND_CONTEXTS_POOL_SIZE; i++ ) 90 | { 91 | /* Store the address as a variable. */ 92 | pCommand = &commandStructurePool[ i ]; 93 | /* Send the pointer to the queue. */ 94 | commandAdded = Agent_MessageSend( &commandStructMessageCtx, &pCommand, 0U ); 95 | configASSERT( commandAdded ); 96 | } 97 | 98 | initStatus = QUEUE_INITIALIZED; 99 | } 100 | } 101 | 102 | /*-----------------------------------------------------------*/ 103 | 104 | MQTTAgentCommand_t * Agent_GetCommand( uint32_t blockTimeMs ) 105 | { 106 | MQTTAgentCommand_t * structToUse = NULL; 107 | bool structRetrieved = false; 108 | 109 | /* Check queue has been created. */ 110 | configASSERT( initStatus == QUEUE_INITIALIZED ); 111 | 112 | /* Retrieve a struct from the queue. */ 113 | structRetrieved = Agent_MessageReceive( &commandStructMessageCtx, &( structToUse ), blockTimeMs ); 114 | 115 | if( !structRetrieved ) 116 | { 117 | LogError( ( "No command structure available." ) ); 118 | } 119 | 120 | return structToUse; 121 | } 122 | 123 | /*-----------------------------------------------------------*/ 124 | 125 | bool Agent_ReleaseCommand( MQTTAgentCommand_t * pCommandToRelease ) 126 | { 127 | bool structReturned = false; 128 | 129 | configASSERT( initStatus == QUEUE_INITIALIZED ); 130 | 131 | /* See if the structure being returned is actually from the pool. */ 132 | if( ( pCommandToRelease >= commandStructurePool ) && 133 | ( pCommandToRelease < ( commandStructurePool + MQTT_COMMAND_CONTEXTS_POOL_SIZE ) ) ) 134 | { 135 | structReturned = Agent_MessageSend( &commandStructMessageCtx, &pCommandToRelease, 0U ); 136 | 137 | /* The send should not fail as the queue was created to hold every command 138 | * in the pool. */ 139 | configASSERT( structReturned ); 140 | LogDebug( ( "Returned Command Context %d to pool", 141 | ( int ) ( pCommandToRelease - commandStructurePool ) ) ); 142 | } 143 | 144 | return structReturned; 145 | } 146 | -------------------------------------------------------------------------------- /lib/ThirdParty/tinycbor/src/cborinternal_p.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | ** 3 | ** Copyright (C) 2017 Intel Corporation 4 | ** 5 | ** Permission is hereby granted, free of charge, to any person obtaining a copy 6 | ** of this software and associated documentation files (the "Software"), to deal 7 | ** in the Software without restriction, including without limitation the rights 8 | ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | ** copies of the Software, and to permit persons to whom the Software is 10 | ** furnished to do so, subject to the following conditions: 11 | ** 12 | ** The above copyright notice and this permission notice shall be included in 13 | ** all copies or substantial portions of the Software. 14 | ** 15 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | ** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | ** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | ** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | ** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | ** THE SOFTWARE. 22 | ** 23 | ****************************************************************************/ 24 | 25 | #ifndef CBORINTERNAL_P_H 26 | #define CBORINTERNAL_P_H 27 | 28 | #include "compilersupport_p.h" 29 | 30 | #ifndef CBOR_NO_FLOATING_POINT 31 | # include 32 | # include 33 | #else 34 | # ifndef CBOR_NO_HALF_FLOAT_TYPE 35 | # define CBOR_NO_HALF_FLOAT_TYPE 1 36 | # endif 37 | #endif 38 | 39 | #ifndef CBOR_NO_HALF_FLOAT_TYPE 40 | # ifdef __F16C__ 41 | # include 42 | static inline unsigned short encode_half(double val) 43 | { 44 | return _cvtss_sh((float)val, 3); 45 | } 46 | static inline double decode_half(unsigned short half) 47 | { 48 | return _cvtsh_ss(half); 49 | } 50 | # else 51 | /* software implementation of float-to-fp16 conversions */ 52 | static inline unsigned short encode_half(double val) 53 | { 54 | uint64_t v; 55 | int sign, exp, mant; 56 | memcpy(&v, &val, sizeof(v)); 57 | sign = v >> 63 << 15; 58 | exp = (v >> 52) & 0x7ff; 59 | mant = v << 12 >> 12 >> (53-11); /* keep only the 11 most significant bits of the mantissa */ 60 | exp -= 1023; 61 | if (exp == 1024) { 62 | /* infinity or NaN */ 63 | exp = 16; 64 | mant >>= 1; 65 | } else if (exp >= 16) { 66 | /* overflow, as largest number */ 67 | exp = 15; 68 | mant = 1023; 69 | } else if (exp >= -14) { 70 | /* regular normal */ 71 | } else if (exp >= -24) { 72 | /* subnormal */ 73 | mant |= 1024; 74 | mant >>= -(exp + 14); 75 | exp = -15; 76 | } else { 77 | /* underflow, make zero */ 78 | return 0; 79 | } 80 | 81 | /* safe cast here as bit operations above guarantee not to overflow */ 82 | return (unsigned short)(sign | ((exp + 15) << 10) | mant); 83 | } 84 | 85 | /* this function was copied & adapted from RFC 7049 Appendix D */ 86 | static inline double decode_half(unsigned short half) 87 | { 88 | int exp = (half >> 10) & 0x1f; 89 | int mant = half & 0x3ff; 90 | double val; 91 | if (exp == 0) val = ldexp(mant, -24); 92 | else if (exp != 31) val = ldexp(mant + 1024, exp - 25); 93 | else val = mant == 0 ? INFINITY : NAN; 94 | return half & 0x8000 ? -val : val; 95 | } 96 | # endif 97 | #endif /* CBOR_NO_HALF_FLOAT_TYPE */ 98 | 99 | #ifndef CBOR_INTERNAL_API 100 | # define CBOR_INTERNAL_API 101 | #endif 102 | 103 | #ifndef CBOR_PARSER_MAX_RECURSIONS 104 | # define CBOR_PARSER_MAX_RECURSIONS 1024 105 | #endif 106 | 107 | /* 108 | * CBOR Major types 109 | * Encoded in the high 3 bits of the descriptor byte 110 | * See http://tools.ietf.org/html/rfc7049#section-2.1 111 | */ 112 | typedef enum CborMajorTypes { 113 | UnsignedIntegerType = 0U, 114 | NegativeIntegerType = 1U, 115 | ByteStringType = 2U, 116 | TextStringType = 3U, 117 | ArrayType = 4U, 118 | MapType = 5U, /* a.k.a. object */ 119 | TagType = 6U, 120 | SimpleTypesType = 7U 121 | } CborMajorTypes; 122 | 123 | /* 124 | * CBOR simple and floating point types 125 | * Encoded in the low 8 bits of the descriptor byte when the 126 | * Major Type is 7. 127 | */ 128 | typedef enum CborSimpleTypes { 129 | FalseValue = 20, 130 | TrueValue = 21, 131 | NullValue = 22, 132 | UndefinedValue = 23, 133 | SimpleTypeInNextByte = 24, /* not really a simple type */ 134 | HalfPrecisionFloat = 25, /* ditto */ 135 | SinglePrecisionFloat = 26, /* ditto */ 136 | DoublePrecisionFloat = 27, /* ditto */ 137 | Break = 31 138 | } CborSimpleTypes; 139 | 140 | enum { 141 | SmallValueBitLength = 5U, 142 | SmallValueMask = (1U << SmallValueBitLength) - 1, /* 31 */ 143 | Value8Bit = 24U, 144 | Value16Bit = 25U, 145 | Value32Bit = 26U, 146 | Value64Bit = 27U, 147 | IndefiniteLength = 31U, 148 | 149 | MajorTypeShift = SmallValueBitLength, 150 | MajorTypeMask = (int) (~0U << MajorTypeShift), 151 | 152 | BreakByte = (unsigned)Break | (SimpleTypesType << MajorTypeShift) 153 | }; 154 | 155 | CBOR_INTERNAL_API CborError CBOR_INTERNAL_API_CC _cbor_value_extract_number(const uint8_t **ptr, const uint8_t *end, uint64_t *len); 156 | CBOR_INTERNAL_API CborError CBOR_INTERNAL_API_CC _cbor_value_prepare_string_iteration(CborValue *it); 157 | CBOR_INTERNAL_API CborError CBOR_INTERNAL_API_CC _cbor_value_get_string_chunk(const CborValue *value, const void **bufferptr, 158 | size_t *len, CborValue *next); 159 | 160 | 161 | #endif /* CBORINTERNAL_P_H */ 162 | -------------------------------------------------------------------------------- /lib/ThirdParty/WinPCap/pcap/sll.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * This code is derived from the Stanford/CMU enet packet filter, 6 | * (net/enet.c) distributed as part of 4.3BSD, and code contributed 7 | * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence 8 | * Berkeley Laboratory. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. All advertising materials mentioning features or use of this software 19 | * must display the following acknowledgement: 20 | * This product includes software developed by the University of 21 | * California, Berkeley and its contributors. 22 | * 4. Neither the name of the University nor the names of its contributors 23 | * may be used to endorse or promote products derived from this software 24 | * without specific prior written permission. 25 | * 26 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 | * SUCH DAMAGE. 37 | * 38 | * @(#) $Header: /tcpdump/master/libpcap/pcap/sll.h,v 1.2.2.1 2008-05-30 01:36:06 guy Exp $ (LBL) 39 | */ 40 | 41 | /* 42 | * For captures on Linux cooked sockets, we construct a fake header 43 | * that includes: 44 | * 45 | * a 2-byte "packet type" which is one of: 46 | * 47 | * LINUX_SLL_HOST packet was sent to us 48 | * LINUX_SLL_BROADCAST packet was broadcast 49 | * LINUX_SLL_MULTICAST packet was multicast 50 | * LINUX_SLL_OTHERHOST packet was sent to somebody else 51 | * LINUX_SLL_OUTGOING packet was sent *by* us; 52 | * 53 | * a 2-byte Ethernet protocol field; 54 | * 55 | * a 2-byte link-layer type; 56 | * 57 | * a 2-byte link-layer address length; 58 | * 59 | * an 8-byte source link-layer address, whose actual length is 60 | * specified by the previous value. 61 | * 62 | * All fields except for the link-layer address are in network byte order. 63 | * 64 | * DO NOT change the layout of this structure, or change any of the 65 | * LINUX_SLL_ values below. If you must change the link-layer header 66 | * for a "cooked" Linux capture, introduce a new DLT_ type (ask 67 | * "tcpdump-workers@lists.tcpdump.org" for one, so that you don't give it 68 | * a value that collides with a value already being used), and use the 69 | * new header in captures of that type, so that programs that can 70 | * handle DLT_LINUX_SLL captures will continue to handle them correctly 71 | * without any change, and so that capture files with different headers 72 | * can be told apart and programs that read them can dissect the 73 | * packets in them. 74 | */ 75 | 76 | #ifndef lib_pcap_sll_h 77 | #define lib_pcap_sll_h 78 | 79 | /* 80 | * A DLT_LINUX_SLL fake link-layer header. 81 | */ 82 | #define SLL_HDR_LEN 16 /* total header length */ 83 | #define SLL_ADDRLEN 8 /* length of address field */ 84 | 85 | struct sll_header { 86 | u_int16_t sll_pkttype; /* packet type */ 87 | u_int16_t sll_hatype; /* link-layer address type */ 88 | u_int16_t sll_halen; /* link-layer address length */ 89 | u_int8_t sll_addr[SLL_ADDRLEN]; /* link-layer address */ 90 | u_int16_t sll_protocol; /* protocol */ 91 | }; 92 | 93 | /* 94 | * The LINUX_SLL_ values for "sll_pkttype"; these correspond to the 95 | * PACKET_ values on Linux, but are defined here so that they're 96 | * available even on systems other than Linux, and so that they 97 | * don't change even if the PACKET_ values change. 98 | */ 99 | #define LINUX_SLL_HOST 0 100 | #define LINUX_SLL_BROADCAST 1 101 | #define LINUX_SLL_MULTICAST 2 102 | #define LINUX_SLL_OTHERHOST 3 103 | #define LINUX_SLL_OUTGOING 4 104 | 105 | /* 106 | * The LINUX_SLL_ values for "sll_protocol"; these correspond to the 107 | * ETH_P_ values on Linux, but are defined here so that they're 108 | * available even on systems other than Linux. We assume, for now, 109 | * that the ETH_P_ values won't change in Linux; if they do, then: 110 | * 111 | * if we don't translate them in "pcap-linux.c", capture files 112 | * won't necessarily be readable if captured on a system that 113 | * defines ETH_P_ values that don't match these values; 114 | * 115 | * if we do translate them in "pcap-linux.c", that makes life 116 | * unpleasant for the BPF code generator, as the values you test 117 | * for in the kernel aren't the values that you test for when 118 | * reading a capture file, so the fixup code run on BPF programs 119 | * handed to the kernel ends up having to do more work. 120 | * 121 | * Add other values here as necessary, for handling packet types that 122 | * might show up on non-Ethernet, non-802.x networks. (Not all the ones 123 | * in the Linux "if_ether.h" will, I suspect, actually show up in 124 | * captures.) 125 | */ 126 | #define LINUX_SLL_P_802_3 0x0001 /* Novell 802.3 frames without 802.2 LLC header */ 127 | #define LINUX_SLL_P_802_2 0x0004 /* 802.2 frames (not D/I/X Ethernet) */ 128 | 129 | #endif 130 | -------------------------------------------------------------------------------- /lib/FreeRTOS/network_transport/freertos_plus_tcp/using_plaintext/using_plaintext.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | * the Software, and to permit persons to whom the Software is furnished to do so, 9 | * subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | */ 21 | 22 | /* Standard includes. */ 23 | #include 24 | 25 | /* FreeRTOS includes. */ 26 | #include "FreeRTOS.h" 27 | 28 | /* FreeRTOS+TCP includes. */ 29 | #include "FreeRTOS_IP.h" 30 | #include "FreeRTOS_Sockets.h" 31 | 32 | /* FreeRTOS Socket wrapper include. */ 33 | #include "sockets_wrapper.h" 34 | 35 | /* Transport interface include. */ 36 | #include "using_plaintext.h" 37 | 38 | PlaintextTransportStatus_t Plaintext_FreeRTOS_Connect( NetworkContext_t * pNetworkContext, 39 | const char * pHostName, 40 | uint16_t port, 41 | uint32_t receiveTimeoutMs, 42 | uint32_t sendTimeoutMs ) 43 | { 44 | PlaintextTransportStatus_t plaintextStatus = PLAINTEXT_TRANSPORT_SUCCESS; 45 | BaseType_t socketStatus = 0; 46 | 47 | if( ( pNetworkContext == NULL ) || ( pHostName == NULL ) ) 48 | { 49 | LogError( ( "Invalid input parameter(s): Arguments cannot be NULL. pNetworkContext=%p, " 50 | "pHostName=%p.", 51 | pNetworkContext, 52 | pHostName ) ); 53 | plaintextStatus = PLAINTEXT_TRANSPORT_INVALID_PARAMETER; 54 | } 55 | else 56 | { 57 | /* Establish a TCP connection with the server. */ 58 | socketStatus = Sockets_Connect( &( pNetworkContext->tcpSocket ), 59 | pHostName, 60 | port, 61 | receiveTimeoutMs, 62 | sendTimeoutMs ); 63 | 64 | /* A non zero status is an error. */ 65 | if( socketStatus != 0 ) 66 | { 67 | LogError( ( "Failed to connect to %s with error %d.", 68 | pHostName, 69 | socketStatus ) ); 70 | plaintextStatus = PLAINTEXT_TRANSPORT_CONNECT_FAILURE; 71 | } 72 | } 73 | 74 | return plaintextStatus; 75 | } 76 | 77 | PlaintextTransportStatus_t Plaintext_FreeRTOS_Disconnect( const NetworkContext_t * pNetworkContext ) 78 | { 79 | PlaintextTransportStatus_t plaintextStatus = PLAINTEXT_TRANSPORT_SUCCESS; 80 | 81 | if( pNetworkContext == NULL ) 82 | { 83 | LogError( ( "pNetworkContext cannot be NULL." ) ); 84 | plaintextStatus = PLAINTEXT_TRANSPORT_INVALID_PARAMETER; 85 | } 86 | else if( pNetworkContext->tcpSocket == FREERTOS_INVALID_SOCKET ) 87 | { 88 | LogError( ( "pNetworkContext->tcpSocket cannot be an invalid socket." ) ); 89 | plaintextStatus = PLAINTEXT_TRANSPORT_INVALID_PARAMETER; 90 | } 91 | else 92 | { 93 | /* Call socket disconnect function to close connection. */ 94 | Sockets_Disconnect( pNetworkContext->tcpSocket ); 95 | } 96 | 97 | return plaintextStatus; 98 | } 99 | 100 | int32_t Plaintext_FreeRTOS_recv( NetworkContext_t * pNetworkContext, 101 | void * pBuffer, 102 | size_t bytesToRecv ) 103 | { 104 | int32_t socketStatus; 105 | 106 | /* The TCP socket may have a receive block time. If bytesToRecv is greater 107 | * than 1 then a frame is likely already part way through reception and 108 | * blocking to wait for the desired number of bytes to be available is the 109 | * most efficient thing to do. If bytesToRecv is 1 then this may be a 110 | * speculative call to read to find the start of a new frame, in which case 111 | * blocking is not desirable as it could block an entire protocol agent 112 | * task for the duration of the read block time and therefore negatively 113 | * impact performance. So if bytesToRecv is 1 then don't call recv unless 114 | * it is known that bytes are already available. */ 115 | if( ( bytesToRecv > 1 ) || ( FreeRTOS_recvcount( pNetworkContext->tcpSocket ) > 0 ) ) 116 | { 117 | socketStatus = FreeRTOS_recv( pNetworkContext->tcpSocket, pBuffer, bytesToRecv, 0 ); 118 | } 119 | else 120 | { 121 | socketStatus = 0; 122 | } 123 | 124 | return socketStatus; 125 | } 126 | 127 | int32_t Plaintext_FreeRTOS_send( NetworkContext_t * pNetworkContext, 128 | const void * pBuffer, 129 | size_t bytesToSend ) 130 | { 131 | int32_t socketStatus = 0; 132 | 133 | socketStatus = FreeRTOS_send( pNetworkContext->tcpSocket, pBuffer, bytesToSend, 0 ); 134 | 135 | if( socketStatus == -pdFREERTOS_ERRNO_ENOSPC ) 136 | { 137 | /* The TCP buffers could not accept any more bytes so zero bytes were sent 138 | * but this is not necessarily an error that should cause a disconnect 139 | * unless it persists. */ 140 | socketStatus = 0; 141 | } 142 | 143 | return socketStatus; 144 | } 145 | -------------------------------------------------------------------------------- /lib/AWS/tools/aws_config_offline/demo_config_generator.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import os 4 | import re 5 | import argparse 6 | from enum import Enum 7 | 8 | 9 | THIS_FILE_DIR = os.path.dirname(os.path.abspath(__file__)) 10 | DEMO_CONFIG_FILE_PATH = os.path.abspath(os.path.join(THIS_FILE_DIR, '..', '..', '..', '..', 'source', 'configuration-files', 'demo_config.h')) 11 | GENERATED_DEMO_CONFIG_FILE_PATH = os.path.join(THIS_FILE_DIR, 'demo_config.h') 12 | 13 | 14 | class CredentialType(Enum): 15 | PRIV_KEY = 1 16 | CERT = 2 17 | ROOT_CA = 3 18 | THING_NAME = 4 19 | ENDPOINT = 5 20 | 21 | 22 | CREDS_IDENTIFIER_MAP = { 23 | CredentialType.PRIV_KEY: '#define democonfigCLIENT_PRIVATE_KEY_PEM', 24 | CredentialType.CERT: '#define democonfigCLIENT_CERTIFICATE_PEM', 25 | CredentialType.ROOT_CA: '#define democonfigROOT_CA_PEM', 26 | CredentialType.THING_NAME: '#define democonfigCLIENT_IDENTIFIER', 27 | CredentialType.ENDPOINT: '#define democonfigMQTT_BROKER_ENDPOINT' 28 | } 29 | 30 | 31 | def prepare_cred_string(cred_file): 32 | with open(cred_file, 'r') as f: 33 | cred_file_content = f.read() 34 | 35 | cred_lines = cred_file_content.rstrip('\n').split('\n') 36 | cred_string = '' 37 | for cred_line in cred_lines[:-1]: 38 | cred_string += f'"{cred_line}\\n" \\\n' 39 | cred_string += f'"{cred_lines[-1]}\\n"\n' 40 | 41 | return cred_string 42 | 43 | 44 | def prepare_priv_key_string(priv_key_file): 45 | return f'{CREDS_IDENTIFIER_MAP[CredentialType.PRIV_KEY]} \\\n{prepare_cred_string(priv_key_file)}' 46 | 47 | 48 | def prepare_cert_string(cert_file): 49 | return f'{CREDS_IDENTIFIER_MAP[CredentialType.CERT]} \\\n{prepare_cred_string(cert_file)}' 50 | 51 | 52 | def prepare_root_ca_string(root_ca_file): 53 | return f'{CREDS_IDENTIFIER_MAP[CredentialType.ROOT_CA]} \\\n{prepare_cred_string(root_ca_file)}' 54 | 55 | 56 | def prepare_endpoint_string(endpoint): 57 | return f'{CREDS_IDENTIFIER_MAP[CredentialType.ENDPOINT]} "{endpoint}"\n' 58 | 59 | 60 | def prepare_thing_name_string(thing_name): 61 | return f'{CREDS_IDENTIFIER_MAP[CredentialType.THING_NAME]} "{thing_name}"\n' 62 | 63 | 64 | def replace_identifier_with_string(content_lines, identifier, string): 65 | pattern = re.compile(f'^{identifier} .*$') 66 | 67 | modified_content_lines = [] 68 | for line in content_lines: 69 | if pattern.match(line): 70 | modified_content_lines.append(string) 71 | else: 72 | modified_content_lines.append(line) 73 | 74 | return modified_content_lines 75 | 76 | 77 | def generate_demo_config_file(priv_key_string, 78 | cert_string, 79 | root_ca_string, 80 | thing_name_string, 81 | endpoint_string): 82 | with open(DEMO_CONFIG_FILE_PATH, 'r') as f: 83 | demo_config_lines = f.readlines() 84 | 85 | modified_demo_config_lines = replace_identifier_with_string(demo_config_lines, 86 | CREDS_IDENTIFIER_MAP[CredentialType.PRIV_KEY], 87 | priv_key_string) 88 | modified_demo_config_lines = replace_identifier_with_string(modified_demo_config_lines, 89 | CREDS_IDENTIFIER_MAP[CredentialType.CERT], 90 | cert_string) 91 | modified_demo_config_lines = replace_identifier_with_string(modified_demo_config_lines, 92 | CREDS_IDENTIFIER_MAP[CredentialType.ROOT_CA], 93 | root_ca_string) 94 | modified_demo_config_lines = replace_identifier_with_string(modified_demo_config_lines, 95 | CREDS_IDENTIFIER_MAP[CredentialType.THING_NAME], 96 | thing_name_string) 97 | modified_demo_config_lines = replace_identifier_with_string(modified_demo_config_lines, 98 | CREDS_IDENTIFIER_MAP[CredentialType.ENDPOINT], 99 | endpoint_string) 100 | 101 | with open(GENERATED_DEMO_CONFIG_FILE_PATH, 'w') as f: 102 | f.writelines(modified_demo_config_lines) 103 | 104 | 105 | def parse_args(): 106 | parser = argparse.ArgumentParser(description='Generate the demo_config.h file.') 107 | parser.add_argument('-p', '--priv-key-file', type=str, required=True, help='The path (relative or absolute) to Device Private Key file.') 108 | parser.add_argument('-c', '--cert-file', type=str, required=True, help='The path (relative or absolute) to Device Certificate File.') 109 | parser.add_argument('-r', '--root-ca-file', type=str, required=True, help='The path (relative or absolute) to the Server Root CA file.') 110 | parser.add_argument('-t', '--thing-name', type=str, required=True, help='The AWS IoT thing name.') 111 | parser.add_argument('-e', '--endpoint', type=str, required=True, help='The AWS IoT end point.') 112 | 113 | args = parser.parse_args() 114 | return args 115 | 116 | 117 | def main(): 118 | args = parse_args() 119 | priv_key_string = prepare_priv_key_string(args.priv_key_file) 120 | cert_string = prepare_cert_string(args.cert_file) 121 | root_ca_string = prepare_root_ca_string(args.root_ca_file) 122 | thing_name_string = prepare_thing_name_string(args.thing_name) 123 | endpoint_string = prepare_endpoint_string(args.endpoint) 124 | 125 | generate_demo_config_file(priv_key_string, 126 | cert_string, 127 | root_ca_string, 128 | thing_name_string, 129 | endpoint_string) 130 | 131 | print('===================================') 132 | print(f'Replace {DEMO_CONFIG_FILE_PATH} with {GENERATED_DEMO_CONFIG_FILE_PATH}.') 133 | print('===================================') 134 | 135 | 136 | if __name__ == "__main__": 137 | main() 138 | -------------------------------------------------------------------------------- /lib/ThirdParty/WinPCap/ip6_misc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1993, 1994, 1997 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that: (1) source code distributions 7 | * retain the above copyright notice and this paragraph in its entirety, (2) 8 | * distributions including binary code include the above copyright notice and 9 | * this paragraph in its entirety in the documentation or other materials 10 | * provided with the distribution, and (3) all advertising materials mentioning 11 | * features or use of this software display the following acknowledgement: 12 | * ``This product includes software developed by the University of California, 13 | * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of 14 | * the University nor the names of its contributors may be used to endorse 15 | * or promote products derived from this software without specific prior 16 | * written permission. 17 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED 18 | * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 19 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 20 | * 21 | * @(#) $Header: /tcpdump/master/libpcap/Win32/Include/ip6_misc.h,v 1.5 2006-01-22 18:02:18 gianluca Exp $ (LBL) 22 | */ 23 | 24 | /* 25 | * This file contains a collage of declarations for IPv6 from FreeBSD not present in Windows 26 | */ 27 | 28 | #include 29 | 30 | #include 31 | 32 | #ifndef __MINGW32__ 33 | #define IN_MULTICAST(a) IN_CLASSD(a) 34 | #endif 35 | 36 | #define IN_EXPERIMENTAL(a) ((((u_int32_t) (a)) & 0xf0000000) == 0xf0000000) 37 | 38 | #define IN_LOOPBACKNET 127 39 | 40 | #if defined(__MINGW32__) && defined(DEFINE_ADDITIONAL_IPV6_STUFF) 41 | /* IPv6 address */ 42 | struct in6_addr 43 | { 44 | union 45 | { 46 | u_int8_t u6_addr8[16]; 47 | u_int16_t u6_addr16[8]; 48 | u_int32_t u6_addr32[4]; 49 | } in6_u; 50 | #define s6_addr in6_u.u6_addr8 51 | #define s6_addr16 in6_u.u6_addr16 52 | #define s6_addr32 in6_u.u6_addr32 53 | #define s6_addr64 in6_u.u6_addr64 54 | }; 55 | 56 | #define IN6ADDR_ANY_INIT { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } 57 | #define IN6ADDR_LOOPBACK_INIT { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } 58 | #endif /* __MINGW32__ */ 59 | 60 | 61 | #if (defined _MSC_VER) || (defined(__MINGW32__) && defined(DEFINE_ADDITIONAL_IPV6_STUFF)) 62 | typedef unsigned short sa_family_t; 63 | #endif 64 | 65 | 66 | #if defined(__MINGW32__) && defined(DEFINE_ADDITIONAL_IPV6_STUFF) 67 | 68 | #define __SOCKADDR_COMMON(sa_prefix) \ 69 | sa_family_t sa_prefix##family 70 | 71 | /* Ditto, for IPv6. */ 72 | struct sockaddr_in6 73 | { 74 | __SOCKADDR_COMMON (sin6_); 75 | u_int16_t sin6_port; /* Transport layer port # */ 76 | u_int32_t sin6_flowinfo; /* IPv6 flow information */ 77 | struct in6_addr sin6_addr; /* IPv6 address */ 78 | }; 79 | 80 | #define IN6_IS_ADDR_V4MAPPED(a) \ 81 | ((((u_int32_t *) (a))[0] == 0) && (((u_int32_t *) (a))[1] == 0) && \ 82 | (((u_int32_t *) (a))[2] == htonl (0xffff))) 83 | 84 | #define IN6_IS_ADDR_MULTICAST(a) (((u_int8_t *) (a))[0] == 0xff) 85 | 86 | #define IN6_IS_ADDR_LINKLOCAL(a) \ 87 | ((((u_int32_t *) (a))[0] & htonl (0xffc00000)) == htonl (0xfe800000)) 88 | 89 | #define IN6_IS_ADDR_LOOPBACK(a) \ 90 | (((u_int32_t *) (a))[0] == 0 && ((u_int32_t *) (a))[1] == 0 && \ 91 | ((u_int32_t *) (a))[2] == 0 && ((u_int32_t *) (a))[3] == htonl (1)) 92 | #endif /* __MINGW32__ */ 93 | 94 | #define ip6_vfc ip6_ctlun.ip6_un2_vfc 95 | #define ip6_flow ip6_ctlun.ip6_un1.ip6_un1_flow 96 | #define ip6_plen ip6_ctlun.ip6_un1.ip6_un1_plen 97 | #define ip6_nxt ip6_ctlun.ip6_un1.ip6_un1_nxt 98 | #define ip6_hlim ip6_ctlun.ip6_un1.ip6_un1_hlim 99 | #define ip6_hops ip6_ctlun.ip6_un1.ip6_un1_hlim 100 | 101 | #define nd_rd_type nd_rd_hdr.icmp6_type 102 | #define nd_rd_code nd_rd_hdr.icmp6_code 103 | #define nd_rd_cksum nd_rd_hdr.icmp6_cksum 104 | #define nd_rd_reserved nd_rd_hdr.icmp6_data32[0] 105 | 106 | /* 107 | * IPV6 extension headers 108 | */ 109 | #define IPPROTO_HOPOPTS 0 /* IPv6 hop-by-hop options */ 110 | #define IPPROTO_IPV6 41 /* IPv6 header. */ 111 | #define IPPROTO_ROUTING 43 /* IPv6 routing header */ 112 | #define IPPROTO_FRAGMENT 44 /* IPv6 fragmentation header */ 113 | #define IPPROTO_ESP 50 /* encapsulating security payload */ 114 | #define IPPROTO_AH 51 /* authentication header */ 115 | #define IPPROTO_ICMPV6 58 /* ICMPv6 */ 116 | #define IPPROTO_NONE 59 /* IPv6 no next header */ 117 | #define IPPROTO_DSTOPTS 60 /* IPv6 destination options */ 118 | #define IPPROTO_PIM 103 /* Protocol Independent Multicast. */ 119 | 120 | #define IPV6_RTHDR_TYPE_0 0 121 | 122 | /* Option types and related macros */ 123 | #define IP6OPT_PAD1 0x00 /* 00 0 00000 */ 124 | #define IP6OPT_PADN 0x01 /* 00 0 00001 */ 125 | #define IP6OPT_JUMBO 0xC2 /* 11 0 00010 = 194 */ 126 | #define IP6OPT_JUMBO_LEN 6 127 | #define IP6OPT_ROUTER_ALERT 0x05 /* 00 0 00101 */ 128 | 129 | #define IP6OPT_RTALERT_LEN 4 130 | #define IP6OPT_RTALERT_MLD 0 /* Datagram contains an MLD message */ 131 | #define IP6OPT_RTALERT_RSVP 1 /* Datagram contains an RSVP message */ 132 | #define IP6OPT_RTALERT_ACTNET 2 /* contains an Active Networks msg */ 133 | #define IP6OPT_MINLEN 2 134 | 135 | #define IP6OPT_BINDING_UPDATE 0xc6 /* 11 0 00110 */ 136 | #define IP6OPT_BINDING_ACK 0x07 /* 00 0 00111 */ 137 | #define IP6OPT_BINDING_REQ 0x08 /* 00 0 01000 */ 138 | #define IP6OPT_HOME_ADDRESS 0xc9 /* 11 0 01001 */ 139 | #define IP6OPT_EID 0x8a /* 10 0 01010 */ 140 | 141 | #define IP6OPT_TYPE(o) ((o) & 0xC0) 142 | #define IP6OPT_TYPE_SKIP 0x00 143 | #define IP6OPT_TYPE_DISCARD 0x40 144 | #define IP6OPT_TYPE_FORCEICMP 0x80 145 | #define IP6OPT_TYPE_ICMP 0xC0 146 | 147 | #define IP6OPT_MUTABLE 0x20 148 | 149 | 150 | #if defined(__MINGW32__) && defined(DEFINE_ADDITIONAL_IPV6_STUFF) 151 | #ifndef EAI_ADDRFAMILY 152 | struct addrinfo { 153 | int ai_flags; /* AI_PASSIVE, AI_CANONNAME */ 154 | int ai_family; /* PF_xxx */ 155 | int ai_socktype; /* SOCK_xxx */ 156 | int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ 157 | size_t ai_addrlen; /* length of ai_addr */ 158 | char *ai_canonname; /* canonical name for hostname */ 159 | struct sockaddr *ai_addr; /* binary address */ 160 | struct addrinfo *ai_next; /* next structure in linked list */ 161 | }; 162 | #endif 163 | #endif /* __MINGW32__ */ 164 | -------------------------------------------------------------------------------- /source/defender-tools/metrics_collector.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS V202012.00 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://github.com/FreeRTOS 24 | * 25 | */ 26 | 27 | /** 28 | * @file metrics_collector.h 29 | * 30 | * @brief Functions used by the defender demo to collect metrics on the 31 | * device's open ports and sockets. 32 | */ 33 | 34 | #ifndef METRICS_COLLECTOR_H_ 35 | #define METRICS_COLLECTOR_H_ 36 | 37 | #include 38 | 39 | /** 40 | * @brief Return codes from metrics collector APIs. 41 | */ 42 | typedef enum 43 | { 44 | eMetricsCollectorSuccess = 0, 45 | eMetricsCollectorBadParameter, 46 | eMetricsCollectorCollectionFailed 47 | } eMetricsCollectorStatus; 48 | 49 | /** 50 | * @brief Represents network stats. 51 | */ 52 | typedef struct NetworkStats 53 | { 54 | uint32_t ulBytesReceived; /**< Number of bytes received. */ 55 | uint32_t ulBytesSent; /**< Number of bytes sent. */ 56 | uint32_t ulPacketsReceived; /**< Number of packets (ethernet frames) received. */ 57 | uint32_t ulPacketsSent; /**< Number of packets (ethernet frames) sent. */ 58 | } NetworkStats_t; 59 | 60 | /** 61 | * @brief Represents a network connection. 62 | */ 63 | typedef struct Connection 64 | { 65 | uint32_t ulLocalIp; 66 | uint32_t ulRemoteIp; 67 | uint16_t usLocalPort; 68 | uint16_t usRemotePort; 69 | } Connection_t; 70 | 71 | /** 72 | * @brief Get network stats. 73 | * 74 | * This function returns the network stats. 75 | * 76 | * @param[out] pxOutNetworkStats The network stats. 77 | * 78 | * @return #eMetricsCollectorSuccess if the network stats are successfully obtained; 79 | * #eMetricsCollectorBadParameter if invalid parameters are passed; 80 | * #eMetricsCollectorCollectionFailed if the collection methods failed. 81 | */ 82 | eMetricsCollectorStatus eGetNetworkStats( NetworkStats_t * pxOutNetworkStats ); 83 | 84 | /** 85 | * @brief Get a list of the open TCP ports. 86 | * 87 | * This function finds the open TCP ports. It can be called with 88 | * @p pusOutTcpPortsArray NULL to get the number of the open TCP ports. 89 | * 90 | * @param[out] pusOutTcpPortsArray The array to write the open TCP ports into. This 91 | * can be NULL, if only the number of open ports is needed. 92 | * @param[in] ulTcpPortsArrayLength Length of the pusOutTcpPortsArray, if it is not 93 | * NULL. 94 | * @param[out] pulOutNumTcpOpenPorts Number of open TCP ports if @p 95 | * pusOutTcpPortsArray NULL, else number of TCP ports written. 96 | * 97 | * @return #eMetricsCollectorSuccess if open TCP ports are successfully obtained; 98 | * #eMetricsCollectorBadParameter if invalid parameters are passed; 99 | * #eMetricsCollectorCollectionFailed if the collection methods failed. 100 | */ 101 | eMetricsCollectorStatus eGetOpenTcpPorts( uint16_t * pusOutTcpPortsArray, 102 | uint32_t ulTcpPortsArrayLength, 103 | uint32_t * pulOutNumTcpOpenPorts ); 104 | 105 | /** 106 | * @brief Get a list of the open UDP ports. 107 | * 108 | * This function finds the open UDP ports. It can be called with 109 | * @p pusOutUdpPortsArray NULL to get the number of the open UDP ports. 110 | * 111 | * @param[out] pusOutUdpPortsArray The array to write the open UDP ports into. Can 112 | * be NULL, if only number of open ports is needed. 113 | * @param[in] ulUdpPortsArrayLength Length of the pusOutUdpPortsArray, if it is not 114 | * NULL. 115 | * @param[out] pulOutNumUdpOpenPorts Number of open UDP ports if @p 116 | * pusOutUdpPortsArray NULL, else number of UDP ports written. 117 | * 118 | * @return #eMetricsCollectorSuccess if open UDP ports are successfully obtained; 119 | * #eMetricsCollectorBadParameter if invalid parameters are passed; 120 | * #eMetricsCollectorCollectionFailed if the collection methods failed. 121 | */ 122 | eMetricsCollectorStatus eGetOpenUdpPorts( uint16_t * pusOutUdpPortsArray, 123 | uint32_t ulUdpPortsArrayLength, 124 | uint32_t * pulOutNumUdpOpenPorts ); 125 | 126 | /** 127 | * @brief Get a list of established connections. 128 | * 129 | * This function finds the established TCP connections. 130 | * It can be called with @p pxOutConnectionsArray NULL to get the number of 131 | * established connections. 132 | * 133 | * @param[out] pxOutConnectionsArray The array to write the established connections 134 | * into. This can be NULL, if only the number of established connections is 135 | * needed. 136 | * @param[in] ulConnectionsArrayLength Length of the pxOutConnectionsArray, if it 137 | * is not NULL. 138 | * @param[out] pulOutNumEstablishedConnections Number of established connections if @p 139 | * pusOutNumEstablishedConnections NULL, else number of established connections written. 140 | * 141 | * @return #eMetricsCollectorSuccess if established connections are successfully obtained; 142 | * #eMetricsCollectorBadParameter if invalid parameters are passed; 143 | * #eMetricsCollectorCollectionFailed if the collection methods failed. 144 | */ 145 | eMetricsCollectorStatus eGetEstablishedConnections( Connection_t * pxOutConnectionsArray, 146 | uint32_t ulConnectionsArrayLength, 147 | uint32_t * pulOutNumEstablishedConnections ); 148 | 149 | #endif /* ifndef METRICS_COLLECTOR_H_ */ 150 | -------------------------------------------------------------------------------- /lib/FreeRTOS/network_transport/freertos_plus_tcp/sockets_wrapper.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | * the Software, and to permit persons to whom the Software is furnished to do so, 9 | * subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | */ 21 | 22 | /** 23 | * @file sockets_wrapper.c 24 | * @brief FreeRTOS Sockets connect and disconnect wrapper implementation. 25 | */ 26 | 27 | /* Standard includes. */ 28 | #include 29 | 30 | /* FreeRTOS includes. */ 31 | #include "FreeRTOS.h" 32 | 33 | #include "sockets_wrapper.h" 34 | 35 | /*-----------------------------------------------------------*/ 36 | 37 | /* Maximum number of times to call FreeRTOS_recv when initiating a graceful shutdown. */ 38 | #ifndef FREERTOS_SOCKETS_WRAPPER_SHUTDOWN_LOOPS 39 | #define FREERTOS_SOCKETS_WRAPPER_SHUTDOWN_LOOPS ( 3 ) 40 | #endif 41 | 42 | /* A negative error code indicating a network failure. */ 43 | #define FREERTOS_SOCKETS_WRAPPER_NETWORK_ERROR ( -1 ) 44 | 45 | /*-----------------------------------------------------------*/ 46 | 47 | BaseType_t Sockets_Connect( Socket_t * pTcpSocket, 48 | const char * pHostName, 49 | uint16_t port, 50 | uint32_t receiveTimeoutMs, 51 | uint32_t sendTimeoutMs ) 52 | { 53 | Socket_t tcpSocket = FREERTOS_INVALID_SOCKET; 54 | BaseType_t socketStatus = 0; 55 | struct freertos_sockaddr serverAddress = { 0 }; 56 | TickType_t transportTimeout = 0; 57 | 58 | /* Create a new TCP socket. */ 59 | tcpSocket = FreeRTOS_socket( FREERTOS_AF_INET, FREERTOS_SOCK_STREAM, FREERTOS_IPPROTO_TCP ); 60 | 61 | if( tcpSocket == FREERTOS_INVALID_SOCKET ) 62 | { 63 | LogError( ( "Failed to create new socket." ) ); 64 | socketStatus = FREERTOS_SOCKETS_WRAPPER_NETWORK_ERROR; 65 | } 66 | else 67 | { 68 | LogDebug( ( "Created new TCP socket." ) ); 69 | 70 | /* Connection parameters. */ 71 | serverAddress.sin_family = FREERTOS_AF_INET; 72 | serverAddress.sin_port = FreeRTOS_htons( port ); 73 | serverAddress.sin_addr = ( uint32_t ) FreeRTOS_gethostbyname( pHostName ); 74 | serverAddress.sin_len = ( uint8_t ) sizeof( serverAddress ); 75 | 76 | /* Check for errors from DNS lookup. */ 77 | if( serverAddress.sin_addr == 0U ) 78 | { 79 | LogError( ( "Failed to connect to server: DNS resolution failed: Hostname=%s.", 80 | pHostName ) ); 81 | socketStatus = FREERTOS_SOCKETS_WRAPPER_NETWORK_ERROR; 82 | } 83 | } 84 | 85 | if( socketStatus == 0 ) 86 | { 87 | /* Establish connection. */ 88 | LogDebug( ( "Creating TCP Connection to %s.", pHostName ) ); 89 | socketStatus = FreeRTOS_connect( tcpSocket, &serverAddress, sizeof( serverAddress ) ); 90 | 91 | if( socketStatus != 0 ) 92 | { 93 | LogError( ( "Failed to connect to server: FreeRTOS_Connect failed: ReturnCode=%d," 94 | " Hostname=%s, Port=%u.", 95 | socketStatus, 96 | pHostName, 97 | port ) ); 98 | } 99 | } 100 | 101 | if( socketStatus == 0 ) 102 | { 103 | /* Set socket receive timeout. */ 104 | transportTimeout = pdMS_TO_TICKS( receiveTimeoutMs ); 105 | /* Setting the receive block time cannot fail. */ 106 | ( void ) FreeRTOS_setsockopt( tcpSocket, 107 | 0, 108 | FREERTOS_SO_RCVTIMEO, 109 | &transportTimeout, 110 | sizeof( TickType_t ) ); 111 | 112 | /* Set socket send timeout. */ 113 | transportTimeout = pdMS_TO_TICKS( sendTimeoutMs ); 114 | /* Setting the send block time cannot fail. */ 115 | ( void ) FreeRTOS_setsockopt( tcpSocket, 116 | 0, 117 | FREERTOS_SO_SNDTIMEO, 118 | &transportTimeout, 119 | sizeof( TickType_t ) ); 120 | } 121 | 122 | /* Clean up on failure. */ 123 | if( socketStatus != 0 ) 124 | { 125 | if( tcpSocket != FREERTOS_INVALID_SOCKET ) 126 | { 127 | ( void ) FreeRTOS_closesocket( tcpSocket ); 128 | } 129 | } 130 | else 131 | { 132 | /* Set the socket. */ 133 | *pTcpSocket = tcpSocket; 134 | LogInfo( ( "Established TCP connection with %s.", pHostName ) ); 135 | } 136 | 137 | return socketStatus; 138 | } 139 | 140 | /*-----------------------------------------------------------*/ 141 | 142 | void Sockets_Disconnect( Socket_t tcpSocket ) 143 | { 144 | BaseType_t waitForShutdownLoopCount = 0; 145 | uint8_t pDummyBuffer[ 2 ]; 146 | 147 | if( tcpSocket != FREERTOS_INVALID_SOCKET ) 148 | { 149 | /* Initiate graceful shutdown. */ 150 | ( void ) FreeRTOS_shutdown( tcpSocket, FREERTOS_SHUT_RDWR ); 151 | 152 | /* Wait for the socket to disconnect gracefully (indicated by FreeRTOS_recv() 153 | * returning a FREERTOS_EINVAL error) before closing the socket. */ 154 | while( FreeRTOS_recv( tcpSocket, pDummyBuffer, sizeof( pDummyBuffer ), 0 ) >= 0 ) 155 | { 156 | /* We don't need to delay since FreeRTOS_recv should already have a timeout. */ 157 | 158 | if( ++waitForShutdownLoopCount >= FREERTOS_SOCKETS_WRAPPER_SHUTDOWN_LOOPS ) 159 | { 160 | break; 161 | } 162 | } 163 | 164 | ( void ) FreeRTOS_closesocket( tcpSocket ); 165 | } 166 | } 167 | 168 | /*-----------------------------------------------------------*/ 169 | -------------------------------------------------------------------------------- /source/configuration-files/ota_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Lab-Project-coreMQTT-Agent 201206 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | 23 | /** 24 | * @file ota_config.h 25 | * @brief OTA user configurable settings. 26 | */ 27 | 28 | #ifndef OTA_CONFIG_H_ 29 | #define OTA_CONFIG_H_ 30 | 31 | /** 32 | * @brief Log base 2 of the size of the file data block message (excluding the header). 33 | * 34 | * 10 bits yields a data block size of 1KB. 35 | */ 36 | #define otaconfigLOG2_FILE_BLOCK_SIZE 11UL 37 | 38 | /** 39 | * @brief Size of the file data block message (excluding the header). 40 | * 41 | */ 42 | #define otaconfigFILE_BLOCK_SIZE ( 1UL << otaconfigLOG2_FILE_BLOCK_SIZE ) 43 | 44 | /** 45 | * @brief Milliseconds to wait for the self test phase to succeed before we force reset. 46 | */ 47 | #define otaconfigSELF_TEST_RESPONSE_WAIT_MS 16000U 48 | 49 | /** 50 | * @brief Milliseconds to wait before requesting data blocks from the OTA service if nothing is happening. 51 | * 52 | * The wait timer is reset whenever a data block is received from the OTA service so we will only send 53 | * the request message after being idle for this amount of time. 54 | */ 55 | #define otaconfigFILE_REQUEST_WAIT_MS 10000U 56 | 57 | /** 58 | * @brief The maximum allowed length of the thing name used by the OTA agent. 59 | * 60 | * AWS IoT requires Thing names to be unique for each device that connects to the broker. 61 | * Likewise, the OTA agent requires the developer to construct and pass in the Thing name when 62 | * initializing the OTA agent. The agent uses this size to allocate static storage for the 63 | * Thing name used in all OTA base topics. Namely $aws/things/ 64 | */ 65 | #define otaconfigMAX_THINGNAME_LEN 128U 66 | 67 | /** 68 | * @brief The maximum number of data blocks requested from OTA streaming service. 69 | * 70 | * This configuration parameter is sent with data requests and represents the maximum number of 71 | * data blocks the service will send in response. The maximum limit for this must be calculated 72 | * from the maximum data response limit (128 KB from service) divided by the block size. 73 | * For example if block size is set as 1 KB then the maximum number of data blocks that we can 74 | * request is 128/1 = 128 blocks. Configure this parameter to this maximum limit or lower based on 75 | * how many data blocks response is expected for each data requests. 76 | * Please note that this must be set larger than zero. 77 | * 78 | */ 79 | #define otaconfigMAX_NUM_BLOCKS_REQUEST 4U 80 | 81 | /** 82 | * @brief The maximum number of requests allowed to send without a response before we abort. 83 | * 84 | * This configuration parameter sets the maximum number of times the requests are made over 85 | * the selected communication channel before aborting and returning error. 86 | * 87 | */ 88 | #define otaconfigMAX_NUM_REQUEST_MOMENTUM 32U 89 | 90 | /** 91 | * @brief The number of data buffers reserved by the OTA agent. 92 | * 93 | * This configurations parameter sets the maximum number of static data buffers used by 94 | * the OTA agent for job and file data blocks received. 95 | */ 96 | #define otaconfigMAX_NUM_OTA_DATA_BUFFERS 5U 97 | 98 | /** 99 | * @brief How frequently the device will report its OTA progress to the cloud. 100 | * 101 | * Device will update the job status with the number of blocks it has received every certain 102 | * number of blocks it receives. For example, 25 means device will update job status every 25 blocks 103 | * it receives. 104 | */ 105 | #define otaconfigOTA_UPDATE_STATUS_FREQUENCY 25U 106 | 107 | 108 | 109 | /** 110 | * @brief Allow update to same or lower version. 111 | * 112 | * Set this to 1 to allow downgrade or same version update.This configurations parameter 113 | * disables version check and allows update to a same or lower version.This is provided for 114 | * testing purpose and it is recommended to always update to higher version and keep this 115 | * configuration disabled. 116 | */ 117 | #define otaconfigAllowDowngrade 0U 118 | 119 | /** 120 | * @brief The protocol selected for OTA control operations. 121 | * 122 | * This configurations parameter sets the default protocol for all the OTA control 123 | * operations like requesting OTA job, updating the job status etc. 124 | * 125 | * Note - Only MQTT is supported at this time for control operations. 126 | */ 127 | #define configENABLED_CONTROL_PROTOCOL ( OTA_CONTROL_OVER_MQTT ) 128 | 129 | /** 130 | * @brief The protocol selected for OTA data operations. 131 | * 132 | * This configurations parameter sets the protocols selected for the data operations 133 | * like requesting file blocks from the service. 134 | * 135 | * Note - Both MQTT and HTTP is supported for data transfer. This configuration parameter 136 | * can be set to following - 137 | * Enable data over MQTT - ( OTA_DATA_OVER_MQTT ) 138 | * Enable data over HTTP - ( OTA_DATA_OVER_HTTP) 139 | * Enable data over both MQTT & HTTP ( OTA_DATA_OVER_MQTT | OTA_DATA_OVER_HTTP ) 140 | */ 141 | #define configENABLED_DATA_PROTOCOLS ( OTA_DATA_OVER_MQTT ) 142 | 143 | /** 144 | * @brief The preferred protocol selected for OTA data operations. 145 | * 146 | * Primary data protocol will be the protocol used for downloading file if more than 147 | * one protocol is selected while creating OTA job. Default primary data protocol is MQTT 148 | * and following update here to switch to HTTP as primary. 149 | * 150 | * Note - use OTA_DATA_OVER_HTTP for HTTP as primary data protocol. 151 | */ 152 | 153 | #define configOTA_PRIMARY_DATA_PROTOCOL ( OTA_DATA_OVER_MQTT ) 154 | 155 | #endif /* OTA_CONFIG_H_ */ 156 | -------------------------------------------------------------------------------- /source/subscription-manager/subscription_manager.c: -------------------------------------------------------------------------------- 1 | /* 2 | * FreeRTOS V202011.00 3 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | * this software and associated documentation files (the "Software"), to deal in 7 | * the Software without restriction, including without limitation the rights to 8 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | * the Software, and to permit persons to whom the Software is furnished to do so, 10 | * subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice shall be included in all 13 | * copies or substantial portions of the Software. 14 | * 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | * https://www.FreeRTOS.org 23 | * https://aws.amazon.com/freertos 24 | * 25 | */ 26 | 27 | /** 28 | * @file subscription_manager.c 29 | * @brief Functions for managing MQTT subscriptions. 30 | */ 31 | 32 | /* Standard includes. */ 33 | #include 34 | 35 | /* Subscription manager header include. */ 36 | #include "subscription_manager.h" 37 | 38 | 39 | bool addSubscription( SubscriptionElement_t * pxSubscriptionList, 40 | const char * pcTopicFilterString, 41 | uint16_t usTopicFilterLength, 42 | IncomingPubCallback_t pxIncomingPublishCallback, 43 | void * pvIncomingPublishCallbackContext ) 44 | { 45 | int32_t lIndex = 0; 46 | size_t xAvailableIndex = SUBSCRIPTION_MANAGER_MAX_SUBSCRIPTIONS; 47 | bool xReturnStatus = false; 48 | 49 | if( ( pxSubscriptionList == NULL ) || 50 | ( pcTopicFilterString == NULL ) || 51 | ( usTopicFilterLength == 0U ) || 52 | ( pxIncomingPublishCallback == NULL ) ) 53 | { 54 | LogError( ( "Invalid parameter. pxSubscriptionList=%p, pcTopicFilterString=%p," 55 | " usTopicFilterLength=%u, pxIncomingPublishCallback=%p.", 56 | pxSubscriptionList, 57 | pcTopicFilterString, 58 | ( unsigned int ) usTopicFilterLength, 59 | pxIncomingPublishCallback ) ); 60 | } 61 | else 62 | { 63 | /* Start at end of array, so that we will insert at the first available index. 64 | * Scans backwards to find duplicates. */ 65 | for( lIndex = ( int32_t ) SUBSCRIPTION_MANAGER_MAX_SUBSCRIPTIONS - 1; lIndex >= 0; lIndex-- ) 66 | { 67 | if( pxSubscriptionList[ lIndex ].usFilterStringLength == 0 ) 68 | { 69 | xAvailableIndex = lIndex; 70 | } 71 | else if( ( pxSubscriptionList[ lIndex ].usFilterStringLength == usTopicFilterLength ) && 72 | ( strncmp( pcTopicFilterString, pxSubscriptionList[ lIndex ].pcSubscriptionFilterString, ( size_t ) usTopicFilterLength ) == 0 ) ) 73 | { 74 | /* If a subscription already exists, don't do anything. */ 75 | if( ( pxSubscriptionList[ lIndex ].pxIncomingPublishCallback == pxIncomingPublishCallback ) && 76 | ( pxSubscriptionList[ lIndex ].pvIncomingPublishCallbackContext == pvIncomingPublishCallbackContext ) ) 77 | { 78 | LogWarn( ( "Subscription already exists.\n" ) ); 79 | xAvailableIndex = SUBSCRIPTION_MANAGER_MAX_SUBSCRIPTIONS; 80 | xReturnStatus = true; 81 | break; 82 | } 83 | } 84 | } 85 | 86 | if( xAvailableIndex < SUBSCRIPTION_MANAGER_MAX_SUBSCRIPTIONS ) 87 | { 88 | pxSubscriptionList[ xAvailableIndex ].pcSubscriptionFilterString = pcTopicFilterString; 89 | pxSubscriptionList[ xAvailableIndex ].usFilterStringLength = usTopicFilterLength; 90 | pxSubscriptionList[ xAvailableIndex ].pxIncomingPublishCallback = pxIncomingPublishCallback; 91 | pxSubscriptionList[ xAvailableIndex ].pvIncomingPublishCallbackContext = pvIncomingPublishCallbackContext; 92 | xReturnStatus = true; 93 | } 94 | } 95 | 96 | return xReturnStatus; 97 | } 98 | 99 | /*-----------------------------------------------------------*/ 100 | 101 | void removeSubscription( SubscriptionElement_t * pxSubscriptionList, 102 | const char * pcTopicFilterString, 103 | uint16_t usTopicFilterLength ) 104 | { 105 | uint32_t ulIndex = 0; 106 | 107 | if( ( pxSubscriptionList == NULL ) || 108 | ( pcTopicFilterString == NULL ) || 109 | ( usTopicFilterLength == 0U ) ) 110 | { 111 | LogError( ( "Invalid parameter. pxSubscriptionList=%p, pcTopicFilterString=%p," 112 | " usTopicFilterLength=%u.", 113 | pxSubscriptionList, 114 | pcTopicFilterString, 115 | ( unsigned int ) usTopicFilterLength ) ); 116 | } 117 | else 118 | { 119 | for( ulIndex = 0U; ulIndex < SUBSCRIPTION_MANAGER_MAX_SUBSCRIPTIONS; ulIndex++ ) 120 | { 121 | if( pxSubscriptionList[ ulIndex ].usFilterStringLength == usTopicFilterLength ) 122 | { 123 | if( strncmp( pxSubscriptionList[ ulIndex ].pcSubscriptionFilterString, pcTopicFilterString, usTopicFilterLength ) == 0 ) 124 | { 125 | memset( &( pxSubscriptionList[ ulIndex ] ), 0x00, sizeof( SubscriptionElement_t ) ); 126 | } 127 | } 128 | } 129 | } 130 | } 131 | 132 | /*-----------------------------------------------------------*/ 133 | 134 | bool handleIncomingPublishes( SubscriptionElement_t * pxSubscriptionList, 135 | MQTTPublishInfo_t * pxPublishInfo ) 136 | { 137 | uint32_t ulIndex = 0; 138 | bool isMatched = false, publishHandled = false; 139 | 140 | if( ( pxSubscriptionList == NULL ) || 141 | ( pxPublishInfo == NULL ) ) 142 | { 143 | LogError( ( "Invalid parameter. pxSubscriptionList=%p, pxPublishInfo=%p,", 144 | pxSubscriptionList, 145 | pxPublishInfo ) ); 146 | } 147 | else 148 | { 149 | for( ulIndex = 0U; ulIndex < SUBSCRIPTION_MANAGER_MAX_SUBSCRIPTIONS; ulIndex++ ) 150 | { 151 | if( pxSubscriptionList[ ulIndex ].usFilterStringLength > 0 ) 152 | { 153 | MQTT_MatchTopic( pxPublishInfo->pTopicName, 154 | pxPublishInfo->topicNameLength, 155 | pxSubscriptionList[ ulIndex ].pcSubscriptionFilterString, 156 | pxSubscriptionList[ ulIndex ].usFilterStringLength, 157 | &isMatched ); 158 | 159 | if( isMatched == true ) 160 | { 161 | pxSubscriptionList[ ulIndex ].pxIncomingPublishCallback( pxSubscriptionList[ ulIndex ].pvIncomingPublishCallbackContext, 162 | pxPublishInfo ); 163 | publishHandled = true; 164 | } 165 | } 166 | } 167 | } 168 | 169 | return publishHandled; 170 | } 171 | -------------------------------------------------------------------------------- /lib/FreeRTOS/network_transport/freertos_plus_tcp/using_mbedtls/using_mbedtls.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of 5 | * this software and associated documentation files (the "Software"), to deal in 6 | * the Software without restriction, including without limitation the rights to 7 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 8 | * the Software, and to permit persons to whom the Software is furnished to do so, 9 | * subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 16 | * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 17 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 18 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 | */ 21 | 22 | /** 23 | * @file tls_freertos.h 24 | * @brief TLS transport interface header. 25 | */ 26 | 27 | #ifndef USING_MBEDTLS 28 | #define USING_MBEDTLS 29 | 30 | 31 | /* FreeRTOS+TCP include. */ 32 | #include "FreeRTOS_Sockets.h" 33 | 34 | /* Transport interface include. */ 35 | #include "transport_interface.h" 36 | 37 | /* mbed TLS includes. */ 38 | #include "mbedtls/ctr_drbg.h" 39 | #include "mbedtls/entropy.h" 40 | #include "mbedtls/ssl.h" 41 | #include "mbedtls/threading.h" 42 | #include "mbedtls/x509.h" 43 | 44 | /** 45 | * @brief Secured connection context. 46 | */ 47 | typedef struct SSLContext 48 | { 49 | mbedtls_ssl_config config; /**< @brief SSL connection configuration. */ 50 | mbedtls_ssl_context context; /**< @brief SSL connection context */ 51 | mbedtls_x509_crt_profile certProfile; /**< @brief Certificate security profile for this connection. */ 52 | mbedtls_x509_crt rootCa; /**< @brief Root CA certificate context. */ 53 | mbedtls_x509_crt clientCert; /**< @brief Client certificate context. */ 54 | mbedtls_pk_context privKey; /**< @brief Client private key context. */ 55 | mbedtls_entropy_context entropyContext; /**< @brief Entropy context for random number generation. */ 56 | mbedtls_ctr_drbg_context ctrDrgbContext; /**< @brief CTR DRBG context for random number generation. */ 57 | } SSLContext_t; 58 | 59 | /** 60 | * @brief Definition of the network context for the transport interface 61 | * implementation that uses mbedTLS and FreeRTOS+TLS sockets. 62 | */ 63 | struct NetworkContext 64 | { 65 | Socket_t tcpSocket; 66 | SSLContext_t sslContext; 67 | }; 68 | 69 | /** 70 | * @brief Contains the credentials necessary for tls connection setup. 71 | */ 72 | typedef struct NetworkCredentials 73 | { 74 | /** 75 | * @brief To use ALPN, set this to a NULL-terminated list of supported 76 | * protocols in decreasing order of preference. 77 | * 78 | * See [this link] 79 | * (https://aws.amazon.com/blogs/iot/mqtt-with-tls-client-authentication-on-port-443-why-it-is-useful-and-how-it-works/) 80 | * for more information. 81 | */ 82 | const char ** pAlpnProtos; 83 | 84 | /** 85 | * @brief Disable server name indication (SNI) for a TLS session. 86 | */ 87 | BaseType_t disableSni; 88 | 89 | const uint8_t * pRootCa; /**< @brief String representing a trusted server root certificate. */ 90 | size_t rootCaSize; /**< @brief Size associated with #NetworkCredentials.pRootCa. */ 91 | const uint8_t * pClientCert; /**< @brief String representing the client certificate. */ 92 | size_t clientCertSize; /**< @brief Size associated with #NetworkCredentials.pClientCert. */ 93 | const uint8_t * pPrivateKey; /**< @brief String representing the client certificate's private key. */ 94 | size_t privateKeySize; /**< @brief Size associated with #NetworkCredentials.pPrivateKey. */ 95 | } NetworkCredentials_t; 96 | 97 | /** 98 | * @brief TLS Connect / Disconnect return status. 99 | */ 100 | typedef enum TlsTransportStatus 101 | { 102 | TLS_TRANSPORT_SUCCESS = 0, /**< Function successfully completed. */ 103 | TLS_TRANSPORT_INVALID_PARAMETER, /**< At least one parameter was invalid. */ 104 | TLS_TRANSPORT_INSUFFICIENT_MEMORY, /**< Insufficient memory required to establish connection. */ 105 | TLS_TRANSPORT_INVALID_CREDENTIALS, /**< Provided credentials were invalid. */ 106 | TLS_TRANSPORT_HANDSHAKE_FAILED, /**< Performing TLS handshake with server failed. */ 107 | TLS_TRANSPORT_INTERNAL_ERROR, /**< A call to a system API resulted in an internal error. */ 108 | TLS_TRANSPORT_CONNECT_FAILURE /**< Initial connection to the server failed. */ 109 | } TlsTransportStatus_t; 110 | 111 | /** 112 | * @brief Create a TLS connection with FreeRTOS sockets. 113 | * 114 | * @param[out] pNetworkContext Pointer to a network context to contain the 115 | * initialized socket handle. 116 | * @param[in] pHostName The hostname of the remote endpoint. 117 | * @param[in] port The destination port. 118 | * @param[in] pNetworkCredentials Credentials for the TLS connection. 119 | * @param[in] receiveTimeoutMs Receive socket timeout. 120 | * @param[in] sendTimeoutMs Send socket timeout. 121 | * 122 | * @return #TLS_TRANSPORT_SUCCESS, #TLS_TRANSPORT_INSUFFICIENT_MEMORY, #TLS_TRANSPORT_INVALID_CREDENTIALS, 123 | * #TLS_TRANSPORT_HANDSHAKE_FAILED, #TLS_TRANSPORT_INTERNAL_ERROR, or #TLS_TRANSPORT_CONNECT_FAILURE. 124 | */ 125 | TlsTransportStatus_t TLS_FreeRTOS_Connect( NetworkContext_t * pNetworkContext, 126 | const char * pHostName, 127 | uint16_t port, 128 | const NetworkCredentials_t * pNetworkCredentials, 129 | uint32_t receiveTimeoutMs, 130 | uint32_t sendTimeoutMs ); 131 | 132 | /** 133 | * @brief Gracefully disconnect an established TLS connection. 134 | * 135 | * @param[in] pNetworkContext Network context. 136 | */ 137 | void TLS_FreeRTOS_Disconnect( NetworkContext_t * pNetworkContext ); 138 | 139 | /** 140 | * @brief Receives data from an established TLS connection. 141 | * 142 | * This is the TLS version of the transport interface's 143 | * #TransportRecv_t function. 144 | * 145 | * @param[in] pNetworkContext The Network context. 146 | * @param[out] pBuffer Buffer to receive bytes into. 147 | * @param[in] bytesToRecv Number of bytes to receive from the network. 148 | * 149 | * @return Number of bytes (> 0) received if successful; 150 | * 0 if the socket times out without reading any bytes; 151 | * negative value on error. 152 | */ 153 | int32_t TLS_FreeRTOS_recv( NetworkContext_t * pNetworkContext, 154 | void * pBuffer, 155 | size_t bytesToRecv ); 156 | 157 | /** 158 | * @brief Sends data over an established TLS connection. 159 | * 160 | * This is the TLS version of the transport interface's 161 | * #TransportSend_t function. 162 | * 163 | * @param[in] pNetworkContext The network context. 164 | * @param[in] pBuffer Buffer containing the bytes to send. 165 | * @param[in] bytesToSend Number of bytes to send from the buffer. 166 | * 167 | * @return Number of bytes (> 0) sent on success; 168 | * 0 if the socket times out without sending any bytes; 169 | * else a negative value to represent error. 170 | */ 171 | int32_t TLS_FreeRTOS_send( NetworkContext_t * pNetworkContext, 172 | const void * pBuffer, 173 | size_t bytesToSend ); 174 | 175 | #endif /* ifndef USING_MBEDTLS */ 176 | --------------------------------------------------------------------------------