├── .github └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── CppUTestMakefileWorker.mk ├── LICENSE ├── LICENSE.txt ├── Makefile ├── NOTICE ├── NOTICE.txt ├── PortingGuide.md ├── README.md ├── certs └── README.txt ├── external_libs ├── CppUTest │ └── README.txt ├── jsmn │ ├── jsmn.c │ └── jsmn.h ├── mbedTLS │ └── README.txt └── tinycbor │ └── README ├── filterGcov.sh ├── include ├── aws_iot_download_agent.h ├── aws_iot_download_agent_config.h ├── aws_iot_download_cbor.h ├── aws_iot_download_cbor_internal.h ├── aws_iot_error.h ├── aws_iot_jobs_interface.h ├── aws_iot_jobs_json.h ├── aws_iot_jobs_topics.h ├── aws_iot_jobs_types.h ├── aws_iot_json_utils.h ├── aws_iot_log.h ├── aws_iot_mqtt_client.h ├── aws_iot_mqtt_client_common_internal.h ├── aws_iot_mqtt_client_interface.h ├── aws_iot_shadow_actions.h ├── aws_iot_shadow_interface.h ├── aws_iot_shadow_json.h ├── aws_iot_shadow_json_data.h ├── aws_iot_shadow_key.h ├── aws_iot_shadow_records.h ├── aws_iot_version.h ├── network_interface.h ├── threads_interface.h └── timer_interface.h ├── platform └── linux │ ├── common │ ├── timer.c │ └── timer_platform.h │ ├── mbedtls │ ├── network_mbedtls_wrapper.c │ └── network_platform.h │ ├── openssl │ ├── network_openssl_wrapper.c │ └── network_platform.h │ └── pthread │ ├── threads_platform.h │ └── threads_pthread_wrapper.c ├── samples ├── README.md └── linux │ ├── download_agent_sample │ ├── Makefile │ ├── README.md │ ├── aws_iot_config.h │ └── download_agent_sample.c │ ├── execute_cmd_jobs_sample │ ├── Makefile │ ├── README.md │ ├── aws_iot_config.h │ ├── execute_cmd_job_sample.c │ └── images │ │ ├── check_the_job_execution_status_01.png │ │ ├── create_a_job_01.png │ │ ├── create_a_job_02.png │ │ ├── create_a_job_03.png │ │ ├── create_a_job_04.png │ │ ├── create_a_job_05.png │ │ ├── upload_a_file_to_aws_s3_01.png │ │ ├── upload_a_file_to_aws_s3_02.png │ │ ├── upload_a_file_to_aws_s3_03.png │ │ ├── upload_a_file_to_aws_s3_04.png │ │ ├── upload_a_file_to_aws_s3_05.png │ │ └── upload_a_file_to_aws_s3_06.png │ ├── jobs_sample │ ├── Makefile │ ├── aws_iot_config.h │ └── jobs_sample.c │ ├── shadow_sample │ ├── Makefile │ ├── aws_iot_config.h │ └── shadow_sample.c │ ├── shadow_sample_console_echo │ ├── Makefile │ ├── aws_iot_config.h │ └── shadow_console_echo.c │ ├── subscribe_publish_library_sample │ ├── Makefile │ ├── aws_iot_config.h │ └── subscribe_publish_library_sample.c │ └── subscribe_publish_sample │ ├── Makefile │ ├── aws_iot_config.h │ └── subscribe_publish_sample.c ├── src ├── aws_iot_download_agent.c ├── aws_iot_download_cbor.c ├── aws_iot_jobs_interface.c ├── aws_iot_jobs_json.c ├── aws_iot_jobs_topics.c ├── aws_iot_jobs_types.c ├── aws_iot_json_utils.c ├── aws_iot_mqtt_client.c ├── aws_iot_mqtt_client_common_internal.c ├── aws_iot_mqtt_client_connect.c ├── aws_iot_mqtt_client_publish.c ├── aws_iot_mqtt_client_subscribe.c ├── aws_iot_mqtt_client_unsubscribe.c ├── aws_iot_mqtt_client_yield.c ├── aws_iot_shadow.c ├── aws_iot_shadow_actions.c ├── aws_iot_shadow_json.c └── aws_iot_shadow_records.c └── tests ├── README.md ├── integration ├── Makefile ├── README.md ├── include │ ├── aws_iot_config.h │ ├── aws_iot_integ_tests_config.h │ └── aws_iot_test_integration_common.h ├── multithreadingTest │ └── aws_iot_test_multithreading_validation.c └── src │ ├── aws_iot_test_auto_reconnect.c │ ├── aws_iot_test_basic_connectivity.c │ ├── aws_iot_test_download_agent.c │ ├── aws_iot_test_integration_runner.c │ ├── aws_iot_test_jobs_api.c │ └── aws_iot_test_multiple_clients.c └── unit ├── README.md ├── include ├── aws_iot_config.h ├── aws_iot_tests_unit_helper_functions.h └── aws_iot_tests_unit_shadow_helper.h ├── src ├── aws_iot_tests_unit_common_tests.cpp ├── aws_iot_tests_unit_common_tests_helper.c ├── aws_iot_tests_unit_connect.cpp ├── aws_iot_tests_unit_connect_helper.c ├── aws_iot_tests_unit_disconnect.cpp ├── aws_iot_tests_unit_disconnect_helper.c ├── aws_iot_tests_unit_download_cbor.cpp ├── aws_iot_tests_unit_download_cbor_helper.c ├── aws_iot_tests_unit_helper_functions.c ├── aws_iot_tests_unit_jobs.cpp ├── aws_iot_tests_unit_jobs_interface.c ├── aws_iot_tests_unit_jobs_json.c ├── aws_iot_tests_unit_jobs_topics.c ├── aws_iot_tests_unit_jobs_types.c ├── aws_iot_tests_unit_json_utils.cpp ├── aws_iot_tests_unit_json_utils_helper.c ├── aws_iot_tests_unit_publish.cpp ├── aws_iot_tests_unit_publish_helper.c ├── aws_iot_tests_unit_runner.cpp ├── aws_iot_tests_unit_shadow_action.cpp ├── aws_iot_tests_unit_shadow_action_helper.c ├── aws_iot_tests_unit_shadow_delta.cpp ├── aws_iot_tests_unit_shadow_delta_helper.c ├── aws_iot_tests_unit_shadow_json_builder.cpp ├── aws_iot_tests_unit_shadow_json_builder_helper.c ├── aws_iot_tests_unit_shadow_null_fields.cpp ├── aws_iot_tests_unit_shadow_null_fields_helper.c ├── aws_iot_tests_unit_subscribe.cpp ├── aws_iot_tests_unit_subscribe_helper.c ├── aws_iot_tests_unit_unsubscribe.cpp ├── aws_iot_tests_unit_unsubscribe_helper.c ├── aws_iot_tests_unit_yield.cpp └── aws_iot_tests_unit_yield_helper.c ├── test_files ├── getStreamResponse_0.cbor ├── getStreamResponse_1.cbor ├── getStreamResponse_2.cbor ├── getStreamResponse_3.cbor ├── getStreamResponse_4.cbor ├── getStreamResponse_5.cbor ├── getStreamResponse_6.cbor └── getStreamResponse_7.cbor └── tls_mock ├── aws_iot_tests_unit_mock_tls.c ├── aws_iot_tests_unit_mock_tls_params.c ├── aws_iot_tests_unit_mock_tls_params.h └── network_platform.h /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | *Issue #, if available:* 2 | 3 | *Description of changes:* 4 | 5 | 6 | By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license. 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore executables 2 | *.o 3 | IotSdkC_tests 4 | samples/linux/jobs_sample/jobs_sample 5 | samples/linux/shadow_sample/shadow_sample 6 | samples/linux/shadow_sample_console_echo/shadow_console_echo 7 | samples/linux/subscribe_publish_library_sample/libAwsIotSdk.a 8 | samples/linux/subscribe_publish_library_sample/subscribe_publish_library_sample 9 | samples/linux/subscribe_publish_sample/subscribe_publish_sample 10 | tests/integration/integration_tests_mbedtls 11 | tests/integration/integration_tests_mbedtls_mt 12 | 13 | # Ignore test artifacts 14 | objs/* 15 | testLibs/* 16 | 17 | # Ignore CppUTest and mbed TLS 18 | external_libs/CppUTest/* 19 | external_libs/mbedTLS/* 20 | external_libs/tinycbor/* 21 | 22 | # Ignore credentials 23 | certs/* 24 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | 3 | install: 4 | # Remove placeholders. 5 | - rm external_libs/CppUTest/* 6 | - rm external_libs/mbedTLS/* 7 | 8 | # Get mbedtls. 9 | - wget -qO- https://github.com/ARMmbed/mbedtls/archive/mbedtls-2.18.1.tar.gz | tar xvz -C external_libs/mbedTLS --strip-components=1 10 | - wget -qO- https://github.com/ARMmbed/mbed-crypto/archive/mbedcrypto-1.1.1.tar.gz | tar xvz -C external_libs/mbedTLS/crypto --strip-components=1 11 | 12 | # Get CppUTest. 13 | - wget -qO- https://github.com/cpputest/cpputest/archive/v3.6.tar.gz | tar xvz -C external_libs/CppUTest --strip-components=1 14 | 15 | script: 16 | # Verify that the samples build. 17 | - cd samples/linux/jobs_sample 18 | - make -j2 19 | - cd ../shadow_sample 20 | - make -j2 21 | - cd ../shadow_sample_console_echo 22 | - make -j2 23 | - cd ../subscribe_publish_library_sample 24 | - make -j2 25 | - cd ../subscribe_publish_sample 26 | - make -j2 27 | 28 | # Build and run unit tests. 29 | - cd ../../../ 30 | - make build-cpputest -j2 31 | - make all_no_tests -j2 32 | - ./IotSdkC_tests -v 33 | 34 | # Set up integration tests if not a pull request. 35 | - if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then cd tests/integration; fi 36 | - if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then sed -i 's/^.*#define AWS_IOT_MQTT_HOST.*$/#define AWS_IOT_MQTT_HOST "'"$AWS_IOT_ENDPOINT"'"/' include/aws_iot_config.h; fi 37 | - if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then make app -j2; fi 38 | 39 | # Import credentials for integration tests. 40 | - if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then wget https://www.amazontrust.com/repository/AmazonRootCA1.pem -O ../../certs/rootCA.crt; fi 41 | - if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then echo -e $AWS_IOT_CLIENT_CERT > ../../certs/cert.pem; fi 42 | - if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then echo -e $AWS_IOT_PRIVATE_KEY > ../../certs/privkey.pem; fi 43 | 44 | # Run integration tests. 45 | - if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then ./integration_tests_mbedtls; fi 46 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 2 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 3 | opensource-codeofconduct@amazon.com with any additional questions or comments. 4 | -------------------------------------------------------------------------------- /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 *master* 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'](https://github.com/aws/aws-iot-device-sdk-embedded-C/labels/help%20wanted) 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) file for our project's licensing. We will ask you to confirm the licensing of your contribution. 60 | 61 | We may ask you to sign a [Contributor License Agreement (CLA)](http://en.wikipedia.org/wiki/Contributor_License_Agreement) for larger changes. 62 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | #This target is to ensure accidental execution of Makefile as a bash script will not execute commands like rm in unexpected directories and exit gracefully. 2 | .prevent_execution: 3 | exit 0 4 | 5 | #Set this to @ to keep the makefile quiet 6 | ifndef SILENCE 7 | SILENCE = @ 8 | endif 9 | 10 | CC = gcc 11 | RM = rm 12 | 13 | DEBUG = 14 | 15 | #--- Inputs ----# 16 | COMPONENT_NAME = IotSdkC 17 | 18 | ALL_TARGETS := build-cpputest 19 | ALL_TARGETS_CLEAN := 20 | 21 | CPPUTEST_USE_EXTENSIONS = Y 22 | CPP_PLATFORM = Gcc 23 | CPPUTEST_CFLAGS += -std=gnu99 24 | CPPUTEST_LDFLAGS += -lpthread 25 | CPPUTEST_CFLAGS += -D__USE_BSD 26 | CPPUTEST_CFLAGS += -DENABLE_TINYCBOR 27 | CPPUTEST_USE_GCOV = Y 28 | 29 | #IoT client directory 30 | IOT_CLIENT_DIR = . 31 | 32 | APP_DIR = $(IOT_CLIENT_DIR)/tests/unit 33 | APP_NAME = aws_iot_sdk_unit_tests 34 | APP_SRC_FILES = $(shell find $(APP_DIR)/src -name '*.cpp') 35 | APP_SRC_FILES += $(shell find $(APP_DIR)/src -name '*.c') 36 | APP_INCLUDE_DIRS = -I $(APP_DIR)/include 37 | 38 | CPPUTEST_DIR = $(IOT_CLIENT_DIR)/external_libs/CppUTest 39 | 40 | # Provide paths for CppUTest to run Unit Tests otherwise build will fail 41 | ifndef CPPUTEST_INCLUDE 42 | CPPUTEST_INCLUDE = $(CPPUTEST_DIR)/include 43 | endif 44 | 45 | ifndef CPPUTEST_BUILD_LIB 46 | CPPUTEST_BUILD_LIB = $(CPPUTEST_DIR) 47 | endif 48 | 49 | CPPUTEST_LDFLAGS += -ldl $(CPPUTEST_BUILD_LIB)/libCppUTest.a 50 | 51 | PLATFORM_DIR = $(IOT_CLIENT_DIR)/platform/linux 52 | 53 | #MbedTLS directory 54 | TEMP_MBEDTLS_SRC_DIR = $(APP_DIR)/tls_mock 55 | TLS_LIB_DIR = $(TEMP_MBEDTLS_SRC_DIR) 56 | TLS_INCLUDE_DIR = -I $(TEMP_MBEDTLS_SRC_DIR) 57 | 58 | #CBOR - tinycbor 59 | TINYCBOR_DIR = $(IOT_CLIENT_DIR)/external_libs/tinycbor 60 | CBOR_LIB_DIR = $(TINYCBOR_DIR)/lib 61 | CBOR_INCLUDE_DIR = -I $(TINYCBOR_DIR)/src 62 | 63 | CPPUTEST_LDFLAGS += $(CBOR_LIB_DIR)/libtinycbor.a 64 | 65 | # Logging level control 66 | #LOG_FLAGS += -DENABLE_IOT_DEBUG 67 | #LOG_FLAGS += -DENABLE_IOT_TRACE 68 | #LOG_FLAGS += -DENABLE_IOT_INFO 69 | #LOG_FLAGS += -DENABLE_IOT_WARN 70 | #LOG_FLAGS += -DENABLE_IOT_ERROR 71 | COMPILER_FLAGS += $(LOG_FLAGS) 72 | 73 | EXTERNAL_LIBS += -L$(CPPUTEST_BUILD_LIB) 74 | EXTERNAL_LIBS += -L$(CBOR_LIB_DIR) 75 | 76 | #IoT client directory 77 | PLATFORM_COMMON_DIR = $(PLATFORM_DIR)/common 78 | 79 | IOT_INCLUDE_DIRS = -I $(PLATFORM_COMMON_DIR) 80 | IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/include 81 | IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/external_libs/jsmn 82 | 83 | IOT_SRC_FILES += $(shell find $(PLATFORM_COMMON_DIR)/ -name '*.c') 84 | IOT_SRC_FILES += $(shell find $(IOT_CLIENT_DIR)/src/ -name '*.c') 85 | IOT_SRC_FILES += $(shell find $(IOT_CLIENT_DIR)/external_libs/jsmn/ -name '*.c') 86 | 87 | #Aggregate all include and src directories 88 | INCLUDE_DIRS += $(IOT_INCLUDE_DIRS) 89 | INCLUDE_DIRS += $(APP_INCLUDE_DIRS) 90 | INCLUDE_DIRS += $(TLS_INCLUDE_DIR) 91 | INCLUDE_DIRS += $(CBOR_INCLUDE_DIR) 92 | INCLUDE_DIRS += $(CPPUTEST_INCLUDE) 93 | 94 | TEST_SRC_DIRS = $(APP_DIR)/src 95 | 96 | SRC_FILES += $(APP_SRC_FILES) 97 | SRC_FILES += $(IOT_SRC_FILES) 98 | 99 | COMPILER_FLAGS += -g 100 | COMPILER_FLAGS += $(LOG_FLAGS) 101 | PRE_MAKE_CMDS = cd $(CPPUTEST_DIR) && 102 | PRE_MAKE_CMDS += cmake CMakeLists.txt && 103 | PRE_MAKE_CMDS += make && 104 | PRE_MAKE_CMDS += cd - && 105 | PRE_MAKE_CMDS += pwd && 106 | PRE_MAKE_CMDS += cp -f $(CPPUTEST_DIR)/src/CppUTest/libCppUTest.a $(CPPUTEST_DIR)/libCppUTest.a && 107 | PRE_MAKE_CMDS += cp -f $(CPPUTEST_DIR)/src/CppUTestExt/libCppUTestExt.a $(CPPUTEST_DIR)/libCppUTestExt.a && 108 | PRE_MAKE_CMDS += $(MAKE) -C $(TINYCBOR_DIR) 109 | 110 | # Using TLS Mock for running Unit Tests 111 | MOCKS_SRC += $(APP_DIR)/tls_mock/aws_iot_tests_unit_mock_tls_params.c 112 | MOCKS_SRC += $(APP_DIR)/tls_mock/aws_iot_tests_unit_mock_tls.c 113 | 114 | ISYSTEM_HEADERS += $(IOT_ISYSTEM_HEADERS) 115 | CPPUTEST_CPPFLAGS += $(ISYSTEM_HEADERS) 116 | CPPUTEST_CPPFLAGS += $(LOG_FLAGS) 117 | 118 | LCOV_EXCLUDE_PATTERN = "tests/unit/*" 119 | LCOV_EXCLUDE_PATTERN += "tests/integration/*" 120 | LCOV_EXCLUDE_PATTERN += "external_libs/*" 121 | 122 | #use this section for running a specific group of tests, comment this to run all 123 | #ONLY FOR TESTING PURPOSE 124 | #COMMAND_LINE_ARGUMENTS += -g CommonTests 125 | #COMMAND_LINE_ARGUMENTS += -v 126 | 127 | build-cpputest: 128 | $(PRE_MAKE_CMDS) 129 | 130 | include CppUTestMakefileWorker.mk 131 | 132 | .PHONY: run-unit-tests 133 | run-unit-tests: $(ALL_TARGETS) 134 | @echo $(ALL_TARGETS) 135 | 136 | .PHONY: clean 137 | clean: 138 | $(MAKE) -C $(CPPUTEST_DIR) clean 139 | $(RM) -rf build_output 140 | $(RM) -rf gcov 141 | $(RM) -rf objs 142 | $(RM) -rf testLibs 143 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | -------------------------------------------------------------------------------- /NOTICE.txt: -------------------------------------------------------------------------------- 1 | AWS C SDK for Internet of Things Service 2 | Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | 4 | This product includes software developed by 5 | Amazon Inc (http://www.amazon.com/). 6 | 7 | ********************** 8 | THIRD PARTY COMPONENTS 9 | ********************** 10 | This software includes third party software subject to the following licensing: 11 | - Embedded C MQTT Client - From the Eclipse Paho Project - EPL v1.0 12 | - mbedTLS (external library, included in tarball or downloaded separately) - Apache 2.0 13 | - jsmn (JSON Parsing) - MIT 14 | - cURL (hostname verification) - MIT 15 | 16 | The licenses for these third party components are included in LICENSE.txt 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## MQTT Download Agent 2 | 3 | ### This project contains a library for downloading files from AWS IoT over a MQTT connection. 4 | 5 | The library has been pre-integrated with [aws-iot-device-sdk-embedded-C](https://github.com/aws/aws-iot-device-sdk-embedded-C). There is also a [sample application](https://github.com/aws-samples/aws-iot-mqtt-download-agent/tree/master/samples/linux/download_agent_sample) that demonstrates how to use the library’s API. 6 | 7 | The theory of operations and API of this library is documented in [`include/aws_iot_download_agent.h`](https://github.com/aws-samples/aws-iot-mqtt-download-agent/blob/master/include/aws_iot_download_agent.h). 8 | 9 | For instruction on how to create a stream in AWS IoT to supply the file for downloading, see [`samples/linux/download_agent_sample/README.md`](https://github.com/aws-samples/aws-iot-mqtt-download-agent/blob/master/samples/linux/download_agent_sample/README.md). 10 | 11 | To learn how to use this library’s API, see [`samples/linux/download_agent_sample/download_agent_sample.c.`](https://github.com/aws-samples/aws-iot-mqtt-download-agent/blob/master/samples/linux/download_agent_sample/download_agent_sample.c) 12 | 13 | This project is based on the master branch of [aws-iot-device-sdk-embedded-C](https://github.com/aws/aws-iot-device-sdk-embedded-C). It added/modified the following files: 14 | - external_libs/tinycbor/README added – Pointer to where to download tinycbor, the externally depended library. 15 | - include/aws_iot_download_agent.h added – External API of the library. 16 | - include/aws_iot_download_agent_config.h added – Configuration parameters used by the library. These can be changed for your own system. 17 | - include/aws_iot_download_cbor.h added – Wrapper API for the cbor protocol. You do not need to change this. 18 | - include/aws_iot_download_cbor_internal.h added - Wrapper API for the cbor protocol. You do not need to change this. 19 | - include/aws_iot_error.h (15 added, 1 deleted) – Error codes returned by the library’s API. 20 | - samples/README.md (4 added, 1 deleted) – A brief description of the sample application. 21 | - samples/linux/download_agent_sample/Makefile added – Makefile for building the sample application. 22 | - samples/linux/download_agent_sample/README.md added - User manual for creating streams in AWS IoT cloud, from which this library can download files. 23 | - samples/linux/download_agent_sample/aws_iot_config.h added – Configuration parameters for building the sample application. You must edit this file and input values for your own AWS IoT account, certificate and private key for the IoT thing, etc. 24 | - samples/linux/download_agent_sample/download_agent_sample.c added – The sample application that use the library to download a file. 25 | - src/aws_iot_download_agent.c added – Source code of the library. 26 | - src/aws_iot_download_cbor.c added – Source code of the wrapper for cbor. 27 | 28 | ### Building the example 29 | 30 | #### Linux Ubuntu 16.04 LTS 31 | All development and testing of the MQTT Download Agent Sample has been performed on Linux Ubuntu 16.04 LTS. 32 | 33 | #### Installing Dependencies 34 | ``` 35 | sudo apt-get update 36 | sudo apt-get install build-essential \ 37 | python \ 38 | clang 39 | ``` 40 | 41 | #### Get mbedtls and tinyCBOR 42 | ``` 43 | wget -qO- https://github.com/ARMmbed/mbedtls/archive/mbedtls-2.18.1.tar.gz | tar xvz -C external_libs/mbedTLS --strip-components=1 44 | wget -qO- https://github.com/ARMmbed/mbed-crypto/archive/mbedcrypto-1.1.1.tar.gz | tar xvz -C external_libs/mbedTLS/crypto --strip-components=1 45 | wget -qO- https://github.com/intel/tinycbor/archive/v0.5.2.tar.gz | tar xvz -C external_libs/tinycbor --strip-components=1 46 | ``` 47 | 48 | #### Configure the SDK with your device parameters 49 | 1. [Create and Activate a Device Certificate](https://docs.aws.amazon.com/iot/latest/developerguide/create-device-certificate.html) 50 | 51 | 2. Copy the certificate, private key, and root CA certificate you created into the [`/certs`](https://github.com/aws-samples/aws-iot-mqtt-download-agent/tree/master/certs) directory. 52 | 53 | 3. You must configure the sample with your own AWS IoT endpoint, private key, certificate, and root CA certificate. Make those changes in the [`samples/linux/download_agent_sample/aws_iot_config.h`](https://github.com/aws-samples/aws-iot-mqtt-download-agent/blob/master/samples/linux/download_agent_sample/aws_iot_config.h) file. Open the `aws_iot_config.h` file, update the values for the following: 54 | ``` 55 | // Get from console 56 | // ================================================= 57 | #define AWS_IOT_MQTT_HOST "YOUR_ENDPOINT_HERE" ///< Customer specific MQTT HOST. The same will be used for Thing Shadow 58 | #define AWS_IOT_MQTT_PORT 443 ///< default port for MQTT/S 59 | #define AWS_IOT_MQTT_CLIENT_ID "YOUR_CLIENT_ID" ///< MQTT client ID should be unique for every device 60 | #define AWS_IOT_MY_THING_NAME "YOUR_THING_NAME" ///< Thing Name of the Shadow this device is associated with 61 | #define AWS_IOT_ROOT_CA_FILENAME "rootCA.crt" ///< Root CA file name 62 | #define AWS_IOT_CERTIFICATE_FILENAME "cert.pem" ///< device signed certificate file name 63 | #define AWS_IOT_PRIVATE_KEY_FILENAME "privkey.pem" ///< Device private key filename 64 | // ================================================= 65 | ``` 66 | 67 | #### Building the download agent sample 68 | ``` 69 | cd samples/linux/download_agent_sample 70 | make -j4 71 | ./download_agent_sample 72 | ``` 73 | 74 | ## License 75 | 76 | This project is licensed under the Apache-2.0 License. 77 | -------------------------------------------------------------------------------- /certs/README.txt: -------------------------------------------------------------------------------- 1 | # Copy certificates for running the samples and tests provided with the SDK into this directory 2 | # Certificates can be created and downloaded from the AWS IoT Console 3 | # The IoT Client takes the full path of the certificates as an input parameter while initializing 4 | # This is the default folder for the certificates only for samples and tests. A different path can be specified if required. -------------------------------------------------------------------------------- /external_libs/CppUTest/README.txt: -------------------------------------------------------------------------------- 1 | # Copy source code for CppUTest into this directory 2 | # The SDK was tested internally with CppUTest v3.6 which can be found here - https://github.com/cpputest/cpputest/releases/tag/v3.6 -------------------------------------------------------------------------------- /external_libs/jsmn/jsmn.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 Serge A. Zaitsev 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all 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, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | * THE SOFTWARE. 21 | */ 22 | 23 | /** 24 | * @file jsmn.h 25 | * @brief Definition of the JSMN (Jasmine) JSON parser. 26 | * 27 | * For more information on JSMN: 28 | * @see http://zserge.com/jsmn.html 29 | */ 30 | 31 | #ifndef __JSMN_H_ 32 | #define __JSMN_H_ 33 | 34 | #include 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | /** 41 | * JSON type identifier. Basic types are: 42 | * o Object 43 | * o Array 44 | * o String 45 | * o Other primitive: number, boolean (true/false) or null 46 | */ 47 | typedef enum { 48 | JSMN_UNDEFINED = 0, 49 | JSMN_OBJECT = 1, 50 | JSMN_ARRAY = 2, 51 | JSMN_STRING = 3, 52 | JSMN_PRIMITIVE = 4 53 | } jsmntype_t; 54 | 55 | enum jsmnerr { 56 | /* Not enough tokens were provided */ 57 | JSMN_ERROR_NOMEM = -1, 58 | /* Invalid character inside JSON string */ 59 | JSMN_ERROR_INVAL = -2, 60 | /* The string is not a full JSON packet, more bytes expected */ 61 | JSMN_ERROR_PART = -3 62 | }; 63 | 64 | /** 65 | * JSON token description. 66 | * type type (object, array, string etc.) 67 | * start start position in JSON data string 68 | * end end position in JSON data string 69 | */ 70 | typedef struct { 71 | jsmntype_t type; 72 | int start; 73 | int end; 74 | int size; 75 | #ifdef JSMN_PARENT_LINKS 76 | int parent; 77 | #endif 78 | } jsmntok_t; 79 | 80 | /** 81 | * JSON parser. Contains an array of token blocks available. Also stores 82 | * the string being parsed now and current position in that string 83 | */ 84 | typedef struct { 85 | unsigned int pos; /* offset in the JSON string */ 86 | unsigned int toknext; /* next token to allocate */ 87 | int toksuper; /* superior token node, e.g parent object or array */ 88 | } jsmn_parser; 89 | 90 | /** 91 | * Create JSON parser over an array of tokens 92 | */ 93 | void jsmn_init(jsmn_parser *parser); 94 | 95 | /** 96 | * Run JSON parser. It parses a JSON data string into and array of tokens, each describing 97 | * a single JSON object. 98 | */ 99 | int jsmn_parse(jsmn_parser *parser, const char *js, size_t len, 100 | jsmntok_t *tokens, unsigned int num_tokens); 101 | 102 | #ifdef __cplusplus 103 | } 104 | #endif 105 | 106 | #endif /* __JSMN_H_ */ 107 | -------------------------------------------------------------------------------- /external_libs/mbedTLS/README.txt: -------------------------------------------------------------------------------- 1 | # Copy source code for mbedTLS into this directory 2 | # 3 | # You'll need to download mbedTLS from the official ARMmbed repository and 4 | # place the files here. We recommend that you pick the latest version in 5 | # order to have up-to-date security fixes. 6 | -------------------------------------------------------------------------------- /external_libs/tinycbor/README: -------------------------------------------------------------------------------- 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.2s.** -------------------------------------------------------------------------------- /filterGcov.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | INPUT_FILE=$1 3 | TEMP_FILE1=${INPUT_FILE}1.tmp 4 | TEMP_FILE2=${INPUT_FILE}2.tmp 5 | TEMP_FILE3=${INPUT_FILE}3.tmp 6 | ERROR_FILE=$2 7 | OUTPUT_FILE=$3 8 | HTML_OUTPUT_FILE=$3.html 9 | TEST_RESULTS=$4 10 | 11 | flattenGcovOutput() { 12 | while read line1 13 | do 14 | read line2 15 | echo $line2 " " $line1 16 | read junk 17 | read junk 18 | done < ${INPUT_FILE} 19 | } 20 | 21 | getRidOfCruft() { 22 | sed '-e s/^Lines.*://g' \ 23 | '-e s/^[0-9]\./ &/g' \ 24 | '-e s/^[0-9][0-9]\./ &/g' \ 25 | '-e s/of.*File/ /g' \ 26 | "-e s/'//g" \ 27 | '-e s/^.*\/usr\/.*$//g' \ 28 | '-e s/^.*\.$//g' 29 | } 30 | 31 | flattenPaths() { 32 | sed \ 33 | -e 's/\/[^/][^/]*\/[^/][^/]*\/\.\.\/\.\.\//\//g' \ 34 | -e 's/\/[^/][^/]*\/[^/][^/]*\/\.\.\/\.\.\//\//g' \ 35 | -e 's/\/[^/][^/]*\/[^/][^/]*\/\.\.\/\.\.\//\//g' \ 36 | -e 's/\/[^/][^/]*\/\.\.\//\//g' 37 | } 38 | 39 | getFileNameRootFromErrorFile() { 40 | sed '-e s/gc..:cannot open .* file//g' ${ERROR_FILE} 41 | } 42 | 43 | writeEachNoTestCoverageFile() { 44 | while read line 45 | do 46 | echo " 0.00% " ${line} 47 | done 48 | } 49 | 50 | createHtmlOutput() { 51 | echo "" 52 | echo "" 53 | sed "-e s/.*% /
CoverageFile
&<\/td>/" \ 54 | "-e s/[a-zA-Z0-9_]*\.[ch][a-z]*/&<\/a><\/td><\/tr>/" 55 | echo "
" 56 | sed "-e s/.*/&
/g" < ${TEST_RESULTS} 57 | } 58 | 59 | flattenGcovOutput | getRidOfCruft | flattenPaths > ${TEMP_FILE1} 60 | getFileNameRootFromErrorFile | writeEachNoTestCoverageFile | flattenPaths > ${TEMP_FILE2} 61 | cat ${TEMP_FILE1} ${TEMP_FILE2} | sort | uniq > ${OUTPUT_FILE} 62 | createHtmlOutput < ${OUTPUT_FILE} > ${HTML_OUTPUT_FILE} 63 | rm -f ${TEMP_FILE1} ${TEMP_FILE2} 64 | -------------------------------------------------------------------------------- /include/aws_iot_download_agent_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file aws_iot_download_agent_config.h 18 | * @brief AWS IoT download agent configuration file 19 | */ 20 | 21 | #ifndef AWS_IOT_DOWNLOAD_AGENT_CONFIG_H_ 22 | #define AWS_IOT_DOWNLOAD_AGENT_CONFIG_H_ 23 | 24 | #define DLA_MAX_BLOCK_BITMAP_SIZE 128U /* Max allowed number of bytes to track all blocks of a file. Adjust block size if more range is needed. */ 25 | #define DLA_MAX_TOPIC_LEN 256U /* Max length of a dynamically generated topic string (usually on the stack). */ 26 | 27 | #endif /* AWS_IOT_DOWNLOAD_AGENT_H_ */ 28 | -------------------------------------------------------------------------------- /include/aws_iot_download_cbor.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Amazon FreeRTOS OTA V1.0.2 3 | * Copyright (C) 2018 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_OTACBOR__H__ 27 | #define __AWS_OTACBOR__H__ 28 | 29 | /** 30 | * @brief Decode a Get Stream response message from AWS IoT OTA. 31 | */ 32 | int OTA_CBOR_Decode_GetStreamResponseMessage( const uint8_t * pucMessageBuffer, 33 | size_t xMessageSize, 34 | int32_t * plFileId, 35 | int32_t * plBlockId, 36 | int32_t * plBlockSize, 37 | uint8_t * pucPayload, 38 | size_t * pxPayloadSize ); 39 | 40 | /** 41 | * @brief Create an encoded Get Stream Request message for the AWS IoT OTA 42 | * service. 43 | */ 44 | int OTA_CBOR_Encode_GetStreamRequestMessage( uint8_t * pucMessageBuffer, 45 | size_t xMessageBufferSize, 46 | size_t * pxEncodedMessageSize, 47 | const char * pcClientToken, 48 | int32_t lFileId, 49 | int32_t lBlockSize, 50 | int32_t lBlockOffset, 51 | uint8_t * pucBlockBitmap, 52 | size_t xBlockBitmapSize ); 53 | 54 | #endif /* ifndef __AWS_OTACBOR__H__ */ 55 | -------------------------------------------------------------------------------- /include/aws_iot_download_cbor_internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Amazon FreeRTOS OTA V1.0.2 3 | * Copyright (C) 2018 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 | /** 27 | * @file aws_ota_cbor_internal.h 28 | * @brief Macros, enums, variables, and definitions internal to the OTA CBOR module and 29 | * shared by the testing files. 30 | */ 31 | 32 | #ifndef _AWS_OTA_CBOR_INTERNAL_H_ 33 | #define _AWS_OTA_CBOR_INTERNAL_H_ 34 | 35 | /** 36 | * @brief Message field definitions, per the server specification. These are 37 | * not part of the library interface but are included here for testability. 38 | */ 39 | #define OTA_CBOR_CLIENTTOKEN_KEY "c" 40 | #define OTA_CBOR_FILEID_KEY "f" 41 | #define OTA_CBOR_BLOCKSIZE_KEY "l" 42 | #define OTA_CBOR_BLOCKOFFSET_KEY "o" 43 | #define OTA_CBOR_BLOCKBITMAP_KEY "b" 44 | #define OTA_CBOR_STREAMDESCRIPTION_KEY "d" 45 | #define OTA_CBOR_STREAMFILES_KEY "r" 46 | #define OTA_CBOR_FILESIZE_KEY "z" 47 | #define OTA_CBOR_BLOCKID_KEY "i" 48 | #define OTA_CBOR_BLOCKPAYLOAD_KEY "p" 49 | 50 | #endif /* ifndef _AWS_OTA_CBOR_INTERNAL_H_ */ 51 | -------------------------------------------------------------------------------- /include/aws_iot_jobs_json.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file aws_iot_jobs_json.h 18 | * @brief Functions for mapping between json and the AWS Iot Job data structures. 19 | */ 20 | 21 | #ifdef DISABLE_IOT_JOBS 22 | #error "Jobs API is disabled" 23 | #endif 24 | 25 | #ifndef AWS_IOT_JOBS_JSON_H_ 26 | #define AWS_IOT_JOBS_JSON_H_ 27 | 28 | #include 29 | #include "jsmn.h" 30 | #include "aws_iot_jobs_types.h" 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /** 37 | * Serialize a job execution update request into a json string. 38 | * 39 | * \param requestBuffer buffer to contain the serialized request. If null 40 | * this function will return the size of the buffer required 41 | * \param bufferSize the size of the buffer. If this is smaller than the required 42 | * length the string will be truncated to fit. 43 | * \request the request to serialize. 44 | * \return The size of the json string to store the serialized request or -1 45 | * if the request is invalid. Note that the return value should be checked against 46 | * the size of the buffer and if its larger handle the fact that the string has 47 | * been truncated. 48 | */ 49 | int aws_iot_jobs_json_serialize_update_job_execution_request( 50 | char *requestBuffer, size_t bufferSize, 51 | const AwsIotJobExecutionUpdateRequest *request); 52 | 53 | /** 54 | * Serialize a job API request that contains only a client token. 55 | * 56 | * \param requestBuffer buffer to contain the serialized request. If null 57 | * this function will return the size of the buffer required 58 | * \param bufferSize the size of the buffer. If this is smaller than the required 59 | * length the string will be truncated to fit. 60 | * \param clientToken the client token to use for the request. 61 | * \return The size of the json string to store the serialized request or -1 62 | * if the request is invalid. Note that the return value should be checked against 63 | * the size of the buffer and if its larger handle the fact that the string has 64 | * been truncated. 65 | */ 66 | int aws_iot_jobs_json_serialize_client_token_only_request( 67 | char *requestBuffer, size_t bufferSize, 68 | const char *clientToken); 69 | 70 | /** 71 | * Serialize describe job execution request into json string. 72 | * 73 | * \param requestBuffer buffer to contain the serialized request. If null 74 | * this function will return the size of the buffer required 75 | * \param bufferSize the size of the buffer. If this is smaller than the required 76 | * length the string will be truncated to fit. 77 | * \param request the request to serialize. 78 | * \return The size of the json string to store the serialized request or -1 79 | * if the request is invalid. Note that the return value should be checked against 80 | * the size of the buffer and if its larger handle the fact that the string has 81 | * been truncated. 82 | */ 83 | int aws_iot_jobs_json_serialize_describe_job_execution_request( 84 | char *requestBuffer, size_t bufferSize, 85 | const AwsIotDescribeJobExecutionRequest *request); 86 | 87 | /** 88 | * Serialize start next job execution request into json string. 89 | * 90 | * \param requestBuffer buffer to contain the serialized request. If null 91 | * this function will return the size of the buffer required 92 | * \param bufferSize the size of the buffer. If this is smaller than the required 93 | * length the string will be truncated to fit. 94 | * \param request the start-next request to serialize. 95 | * \return The size of the json string to store the serialized request or -1 96 | * if the request is invalid. Note that the return value should be checked against 97 | * the size of the buffer and if its larger handle the fact that the string has 98 | * been truncated. 99 | */ 100 | int aws_iot_jobs_json_serialize_start_next_job_execution_request( 101 | char *requestBuffer, size_t bufferSize, 102 | const AwsIotStartNextPendingJobExecutionRequest *request); 103 | 104 | #ifdef __cplusplus 105 | } 106 | #endif 107 | 108 | #endif /* AWS_IOT_JOBS_JSON_H_ */ 109 | -------------------------------------------------------------------------------- /include/aws_iot_jobs_topics.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file aws_iot_job_topics.h 18 | * @brief Functions for parsing and creating MQTT topics used by the AWS IoT Jobs system. 19 | */ 20 | 21 | #ifdef DISABLE_IOT_JOBS 22 | #error "Jobs API is disabled" 23 | #endif 24 | 25 | #ifndef AWS_IOT_JOBS_TOPICS_H_ 26 | #define AWS_IOT_JOBS_TOPICS_H_ 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | #define JOB_ID_NEXT "$next" 37 | #define JOB_ID_WILDCARD "+" 38 | 39 | /** 40 | * The type of job topic. 41 | */ 42 | typedef enum { 43 | JOB_UNRECOGNIZED_TOPIC = 0, 44 | JOB_GET_PENDING_TOPIC, 45 | JOB_START_NEXT_TOPIC, 46 | JOB_DESCRIBE_TOPIC, 47 | JOB_UPDATE_TOPIC, 48 | JOB_NOTIFY_TOPIC, 49 | JOB_NOTIFY_NEXT_TOPIC, 50 | JOB_WILDCARD_TOPIC 51 | } AwsIotJobExecutionTopicType; 52 | 53 | /** 54 | * The type of reply topic, or #JOB_REQUEST_TYPE for 55 | * topics that are not replies. 56 | */ 57 | typedef enum { 58 | JOB_UNRECOGNIZED_TOPIC_TYPE = 0, 59 | JOB_REQUEST_TYPE, 60 | JOB_ACCEPTED_REPLY_TYPE, 61 | JOB_REJECTED_REPLY_TYPE, 62 | JOB_WILDCARD_REPLY_TYPE 63 | } AwsIotJobExecutionTopicReplyType; 64 | 65 | /** 66 | * @brief Get the topic matching the provided details and put into the provided buffer. 67 | * 68 | * If the buffer is not large enough to store the full topic the topic will be truncated 69 | * to fit, with the last character always being a null terminator. 70 | * 71 | * \param buffer the buffer to put the results into 72 | * \param bufferSize the size of the buffer 73 | * \param topicType the type of the topic 74 | * \param replyType the reply type of the topic 75 | * \param thingName the name of the thing in the topic 76 | * \param jobId the name of the job id in the topic 77 | * \return the number of characters in the topic excluding the null terminator. A return 78 | * value of bufferSize or more means that the topic string was truncated. 79 | */ 80 | int aws_iot_jobs_get_api_topic(char *buffer, size_t bufferSize, 81 | AwsIotJobExecutionTopicType topicType, AwsIotJobExecutionTopicReplyType replyType, 82 | const char* thingName, const char* jobId); 83 | 84 | #ifdef __cplusplus 85 | } 86 | #endif 87 | 88 | #endif /* AWS_IOT_JOBS_TOPICS_H_ */ 89 | -------------------------------------------------------------------------------- /include/aws_iot_jobs_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file aws_iot_jobs_types.h 18 | * @brief Structures defining the interface with the AWS IoT Jobs system 19 | * 20 | * This file defines the structures returned by and sent to the AWS IoT Jobs system. 21 | * 22 | */ 23 | 24 | #ifdef DISABLE_IOT_JOBS 25 | #error "Jobs API is disabled" 26 | #endif 27 | 28 | #ifndef AWS_IOT_JOBS_TYPES_H_ 29 | #define AWS_IOT_JOBS_TYPES_H_ 30 | 31 | #include 32 | #include 33 | #include "jsmn.h" 34 | #include "timer_interface.h" 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | typedef enum { 41 | JOB_EXECUTION_STATUS_NOT_SET = 0, 42 | JOB_EXECUTION_QUEUED, 43 | JOB_EXECUTION_IN_PROGRESS, 44 | JOB_EXECUTION_FAILED, 45 | JOB_EXECUTION_SUCCEEDED, 46 | JOB_EXECUTION_CANCELED, 47 | JOB_EXECUTION_REJECTED, 48 | /*** 49 | * Used for any status not in the supported list of statuses 50 | */ 51 | JOB_EXECUTION_UNKNOWN_STATUS = 99 52 | } JobExecutionStatus; 53 | 54 | extern const char *JOB_EXECUTION_QUEUED_STR; 55 | extern const char *JOB_EXECUTION_IN_PROGRESS_STR; 56 | extern const char *JOB_EXECUTION_FAILED_STR; 57 | extern const char *JOB_EXECUTION_SUCCESS_STR; 58 | extern const char *JOB_EXECUTION_CANCELED_STR; 59 | extern const char *JOB_EXECUTION_REJECTED_STR; 60 | 61 | /** 62 | * Convert a string to its matching status. 63 | * 64 | * \return the matching status, or JOB_EXECUTION_UNKNOWN_STATUS if the string was not recognized. 65 | */ 66 | JobExecutionStatus aws_iot_jobs_map_string_to_job_status(const char *str); 67 | 68 | /** 69 | * Convert a status to its string. 70 | * 71 | * \return a string representing the status, or null if the status is not recognized. 72 | */ 73 | const char *aws_iot_jobs_map_status_to_string(JobExecutionStatus status); 74 | 75 | /** 76 | * A request to update the status of a job execution. 77 | */ 78 | typedef struct { 79 | int64_t expectedVersion; // set to 0 to ignore 80 | int64_t executionNumber; // set to 0 to ignore 81 | JobExecutionStatus status; 82 | const char *statusDetails; 83 | bool includeJobExecutionState; 84 | bool includeJobDocument; 85 | const char *clientToken; 86 | } AwsIotJobExecutionUpdateRequest; 87 | 88 | /** 89 | * A request to get the status of a job execution. 90 | */ 91 | typedef struct { 92 | int64_t executionNumber; // set to 0 to ignore 93 | bool includeJobDocument; 94 | const char *clientToken; 95 | } AwsIotDescribeJobExecutionRequest; 96 | 97 | /** 98 | * A request to get and start the next pending (not in a terminal state) job execution for a Thing. 99 | */ 100 | typedef struct { 101 | const char *statusDetails; 102 | const char *clientToken; 103 | } AwsIotStartNextPendingJobExecutionRequest; 104 | 105 | #ifdef __cplusplus 106 | } 107 | #endif 108 | 109 | #endif /* AWS_IOT_JOBS_TYPES_H_ */ 110 | -------------------------------------------------------------------------------- /include/aws_iot_log.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file aws_iot_log.h 18 | * @brief Logging macros for the SDK. 19 | * This file defines common logging macros with log levels to be used within the SDK. 20 | * These macros can also be used in the IoT application code as a common way to output 21 | * logs. The log levels can be tuned by modifying the makefile. Removing (commenting 22 | * out) the IOT_* statement in the makefile disables that log level. 23 | * 24 | * It is expected that the macros below will be modified or replaced when porting to 25 | * specific hardware platforms as printf may not be the desired behavior. 26 | */ 27 | 28 | #ifndef _IOT_LOG_H 29 | #define _IOT_LOG_H 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | #include 36 | #include 37 | 38 | /** 39 | * @brief Debug level logging macro. 40 | * 41 | * Macro to expose function, line number as well as desired log message. 42 | */ 43 | #ifdef ENABLE_IOT_DEBUG 44 | #define IOT_DEBUG(...) \ 45 | {\ 46 | printf("DEBUG: %s L#%d ", __func__, __LINE__); \ 47 | printf(__VA_ARGS__); \ 48 | printf("\n"); \ 49 | } 50 | #else 51 | #define IOT_DEBUG(...) 52 | #endif 53 | 54 | /** 55 | * @brief Debug level trace logging macro. 56 | * 57 | * Macro to print message function entry and exit 58 | */ 59 | #ifdef ENABLE_IOT_TRACE 60 | #define FUNC_ENTRY \ 61 | {\ 62 | printf("FUNC_ENTRY: %s L#%d \n", __func__, __LINE__); \ 63 | } 64 | #define FUNC_EXIT \ 65 | {\ 66 | printf("FUNC_EXIT: %s L#%d \n", __func__, __LINE__); \ 67 | } 68 | #define FUNC_EXIT_RC(x) \ 69 | {\ 70 | printf("FUNC_EXIT: %s L#%d Return Code : %d \n", __func__, __LINE__, x); \ 71 | return x; \ 72 | } 73 | #else 74 | #define FUNC_ENTRY 75 | 76 | #define FUNC_EXIT 77 | #define FUNC_EXIT_RC(x) { return x; } 78 | #endif 79 | 80 | /** 81 | * @brief Info level logging macro. 82 | * 83 | * Macro to expose desired log message. Info messages do not include automatic function names and line numbers. 84 | */ 85 | #ifdef ENABLE_IOT_INFO 86 | #define IOT_INFO(...) \ 87 | {\ 88 | printf(__VA_ARGS__); \ 89 | printf("\n"); \ 90 | } 91 | #else 92 | #define IOT_INFO(...) 93 | #endif 94 | 95 | /** 96 | * @brief Warn level logging macro. 97 | * 98 | * Macro to expose function, line number as well as desired log message. 99 | */ 100 | #ifdef ENABLE_IOT_WARN 101 | #define IOT_WARN(...) \ 102 | { \ 103 | printf("WARN: %s L#%d ", __func__, __LINE__); \ 104 | printf(__VA_ARGS__); \ 105 | printf("\n"); \ 106 | } 107 | #else 108 | #define IOT_WARN(...) 109 | #endif 110 | 111 | /** 112 | * @brief Error level logging macro. 113 | * 114 | * Macro to expose function, line number as well as desired log message. 115 | */ 116 | #ifdef ENABLE_IOT_ERROR 117 | #define IOT_ERROR(...) \ 118 | { \ 119 | printf("ERROR: %s L#%d ", __func__, __LINE__); \ 120 | printf(__VA_ARGS__); \ 121 | printf("\n"); \ 122 | } 123 | #else 124 | #define IOT_ERROR(...) 125 | #endif 126 | 127 | #ifdef __cplusplus 128 | } 129 | #endif 130 | 131 | #endif // _IOT_LOG_H 132 | -------------------------------------------------------------------------------- /include/aws_iot_mqtt_client_common_internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | // Based on Eclipse Paho. 17 | /******************************************************************************* 18 | * Copyright (c) 2014 IBM Corp. 19 | * 20 | * All rights reserved. This program and the accompanying materials 21 | * are made available under the terms of the Eclipse Public License v1.0 22 | * and Eclipse Distribution License v1.0 which accompany this distribution. 23 | * 24 | * The Eclipse Public License is available at 25 | * http://www.eclipse.org/legal/epl-v10.html 26 | * and the Eclipse Distribution License is available at 27 | * http://www.eclipse.org/org/documents/edl-v10.php. 28 | * 29 | * Contributors: 30 | * Ian Craggs - initial API and implementation and/or initial documentation 31 | * Xiang Rong - 442039 Add makefile to Embedded C client 32 | *******************************************************************************/ 33 | 34 | /** 35 | * @file aws_iot_mqtt_client_common_internal.h 36 | * @brief Internal MQTT functions not exposed to application 37 | */ 38 | 39 | #ifndef AWS_IOT_SDK_SRC_IOT_COMMON_INTERNAL_H 40 | #define AWS_IOT_SDK_SRC_IOT_COMMON_INTERNAL_H 41 | 42 | #ifdef __cplusplus 43 | extern "C" { 44 | #endif 45 | 46 | #include 47 | #include 48 | #include 49 | 50 | #include "aws_iot_log.h" 51 | #include "aws_iot_mqtt_client_interface.h" 52 | 53 | /* Enum order should match the packet ids array defined in MQTTFormat.c */ 54 | typedef enum msgTypes { 55 | UNKNOWN = -1, 56 | CONNECT = 1, 57 | CONNACK = 2, 58 | PUBLISH = 3, 59 | PUBACK = 4, 60 | PUBREC = 5, 61 | PUBREL = 6, 62 | PUBCOMP = 7, 63 | SUBSCRIBE = 8, 64 | SUBACK = 9, 65 | UNSUBSCRIBE = 10, 66 | UNSUBACK = 11, 67 | PINGREQ = 12, 68 | PINGRESP = 13, 69 | DISCONNECT = 14 70 | } MessageTypes; 71 | 72 | /* Macros for parsing header fields from incoming MQTT frame. */ 73 | #define MQTT_HEADER_FIELD_TYPE(_byte) ((_byte >> 4) & 0x0F) 74 | #define MQTT_HEADER_FIELD_DUP(_byte) ((_byte & (1 << 3)) >> 3) 75 | #define MQTT_HEADER_FIELD_QOS(_byte) ((_byte & (3 << 1)) >> 1) 76 | #define MQTT_HEADER_FIELD_RETAIN(_byte) ((_byte & (1 << 0)) >> 0) 77 | 78 | /** 79 | * Bitfields for the MQTT header byte. 80 | */ 81 | typedef union { 82 | unsigned char byte; /**< the whole byte */ 83 | } MQTTHeader; 84 | 85 | IoT_Error_t aws_iot_mqtt_internal_init_header(MQTTHeader *pHeader, MessageTypes message_type, 86 | QoS qos, uint8_t dup, uint8_t retained); 87 | 88 | IoT_Error_t aws_iot_mqtt_internal_serialize_ack(unsigned char *pTxBuf, size_t txBufLen, 89 | MessageTypes msgType, uint8_t dup, uint16_t packetId, 90 | uint32_t *pSerializedLen); 91 | IoT_Error_t aws_iot_mqtt_internal_deserialize_ack(unsigned char *, unsigned char *, 92 | uint16_t *, unsigned char *, size_t); 93 | 94 | uint32_t aws_iot_mqtt_internal_get_final_packet_length_from_remaining_length(uint32_t rem_len); 95 | 96 | size_t aws_iot_mqtt_internal_write_len_to_buffer(unsigned char *buf, uint32_t length); 97 | IoT_Error_t aws_iot_mqtt_internal_decode_remaining_length_from_buffer(unsigned char *buf, uint32_t *decodedLen, 98 | uint32_t *readBytesLen); 99 | 100 | uint16_t aws_iot_mqtt_internal_read_uint16_t(unsigned char **pptr); 101 | void aws_iot_mqtt_internal_write_uint_16(unsigned char **pptr, uint16_t anInt); 102 | 103 | unsigned char aws_iot_mqtt_internal_read_char(unsigned char **pptr); 104 | void aws_iot_mqtt_internal_write_char(unsigned char **pptr, unsigned char c); 105 | void aws_iot_mqtt_internal_write_utf8_string(unsigned char **pptr, const char *string, uint16_t stringLen); 106 | 107 | IoT_Error_t aws_iot_mqtt_internal_flushBuffers( AWS_IoT_Client *pClient ); 108 | IoT_Error_t aws_iot_mqtt_internal_send_packet(AWS_IoT_Client *pClient, size_t length, Timer *pTimer); 109 | IoT_Error_t aws_iot_mqtt_internal_cycle_read(AWS_IoT_Client *pClient, Timer *pTimer, uint8_t *pPacketType); 110 | IoT_Error_t aws_iot_mqtt_internal_wait_for_read(AWS_IoT_Client *pClient, uint8_t packetType, Timer *pTimer); 111 | IoT_Error_t aws_iot_mqtt_internal_serialize_zero(unsigned char *pTxBuf, size_t txBufLen, 112 | MessageTypes packetType, size_t *pSerializedLength); 113 | IoT_Error_t aws_iot_mqtt_internal_deserialize_publish(uint8_t *dup, QoS *qos, 114 | uint8_t *retained, uint16_t *pPacketId, 115 | char **pTopicName, uint16_t *topicNameLen, 116 | unsigned char **payload, size_t *payloadLen, 117 | unsigned char *pRxBuf, size_t rxBufLen); 118 | 119 | IoT_Error_t aws_iot_mqtt_set_client_state(AWS_IoT_Client *pClient, ClientState expectedCurrentState, 120 | ClientState newState); 121 | 122 | #ifdef _ENABLE_THREAD_SUPPORT_ 123 | 124 | IoT_Error_t aws_iot_mqtt_client_lock_mutex(AWS_IoT_Client *pClient, IoT_Mutex_t *pMutex); 125 | 126 | IoT_Error_t aws_iot_mqtt_client_unlock_mutex(AWS_IoT_Client *pClient, IoT_Mutex_t *pMutex); 127 | 128 | #endif 129 | 130 | #ifdef __cplusplus 131 | } 132 | #endif 133 | 134 | #endif /* AWS_IOT_SDK_SRC_IOT_COMMON_INTERNAL_H */ 135 | -------------------------------------------------------------------------------- /include/aws_iot_shadow_actions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | #ifndef SRC_SHADOW_AWS_IOT_SHADOW_ACTIONS_H_ 17 | #define SRC_SHADOW_AWS_IOT_SHADOW_ACTIONS_H_ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #include "aws_iot_shadow_interface.h" 24 | 25 | IoT_Error_t aws_iot_shadow_internal_action(const char *pThingName, ShadowActions_t action, 26 | const char *pJsonDocumentToBeSent, size_t jsonSize, fpActionCallback_t callback, 27 | void *pCallbackContext, uint32_t timeout_seconds, bool isSticky); 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | 33 | #endif /* SRC_SHADOW_AWS_IOT_SHADOW_ACTIONS_H_ */ 34 | -------------------------------------------------------------------------------- /include/aws_iot_shadow_json.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | #ifndef AWS_IOT_SDK_SRC_IOT_SHADOW_JSON_H_ 16 | #define AWS_IOT_SDK_SRC_IOT_SHADOW_JSON_H_ 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | #include "aws_iot_error.h" 27 | #include "aws_iot_shadow_json_data.h" 28 | 29 | bool isJsonValidAndParse(const char *pJsonDocument, size_t jsonSize, void *pJsonHandler, int32_t *pTokenCount); 30 | 31 | bool isJsonKeyMatchingAndUpdateValue(const char *pJsonDocument, void *pJsonHandler, int32_t tokenCount, 32 | jsonStruct_t *pDataStruct, uint32_t *pDataLength, int32_t *pDataPosition); 33 | 34 | IoT_Error_t aws_iot_shadow_internal_get_request_json(char *pBuffer, size_t bufferSize); 35 | 36 | IoT_Error_t aws_iot_shadow_internal_delete_request_json(char *pBuffer, size_t bufferSize); 37 | 38 | void resetClientTokenSequenceNum(void); 39 | 40 | 41 | bool isReceivedJsonValid(const char *pJsonDocument, size_t jsonSize); 42 | 43 | bool extractClientToken(const char *pJsonDocument, size_t jsonSize, char *pExtractedClientToken, size_t clientTokenSize); 44 | 45 | bool extractVersionNumber(const char *pJsonDocument, void *pJsonHandler, int32_t tokenCount, uint32_t *pVersionNumber); 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | #endif // AWS_IOT_SDK_SRC_IOT_SHADOW_JSON_H_ 52 | -------------------------------------------------------------------------------- /include/aws_iot_shadow_key.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | #ifndef SRC_SHADOW_AWS_IOT_SHADOW_KEY_H_ 17 | #define SRC_SHADOW_AWS_IOT_SHADOW_KEY_H_ 18 | 19 | #define SHADOW_CLIENT_TOKEN_STRING "clientToken" 20 | #define SHADOW_VERSION_STRING "version" 21 | 22 | #endif /* SRC_SHADOW_AWS_IOT_SHADOW_KEY_H_ */ 23 | -------------------------------------------------------------------------------- /include/aws_iot_shadow_records.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | #ifndef SRC_SHADOW_AWS_IOT_SHADOW_RECORDS_H_ 17 | #define SRC_SHADOW_AWS_IOT_SHADOW_RECORDS_H_ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #include 24 | 25 | #include "aws_iot_shadow_interface.h" 26 | #include "aws_iot_config.h" 27 | 28 | 29 | extern uint32_t shadowJsonVersionNum; 30 | extern bool shadowDiscardOldDeltaFlag; 31 | 32 | extern char myThingName[MAX_SIZE_OF_THING_NAME]; 33 | extern uint16_t myThingNameLen; 34 | extern char mqttClientID[MAX_SIZE_OF_UNIQUE_CLIENT_ID_BYTES]; 35 | extern uint16_t mqttClientIDLen; 36 | 37 | void initializeRecords(AWS_IoT_Client *pClient); 38 | bool isSubscriptionPresent(const char *pThingName, ShadowActions_t action); 39 | IoT_Error_t subscribeToShadowActionAcks(const char *pThingName, ShadowActions_t action, bool isSticky); 40 | void incrementSubscriptionCnt(const char *pThingName, ShadowActions_t action, bool isSticky); 41 | 42 | IoT_Error_t publishToShadowAction(const char *pThingName, ShadowActions_t action, const char *pJsonDocumentToBeSent); 43 | void addToAckWaitList(uint8_t indexAckWaitList, const char *pThingName, ShadowActions_t action, 44 | const char *pExtractedClientToken, fpActionCallback_t callback, void *pCallbackContext, 45 | uint32_t timeout_seconds); 46 | bool getNextFreeIndexOfAckWaitList(uint8_t *pIndex); 47 | void HandleExpiredResponseCallbacks(void); 48 | void initDeltaTokens(void); 49 | IoT_Error_t registerJsonTokenOnDelta(jsonStruct_t *pStruct); 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | #endif /* SRC_SHADOW_AWS_IOT_SHADOW_RECORDS_H_ */ 56 | -------------------------------------------------------------------------------- /include/aws_iot_version.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file aws_iot_version.h 18 | * @brief Constants defining the release version of the SDK. 19 | * 20 | * This file contains constants defining the release version of the SDK. 21 | * This file is modified by AWS upon release of the SDK and should not be 22 | * modified by the consumer of the SDK. The provided samples show example 23 | * usage of these constants. 24 | * 25 | * Versioning of the SDK follows the MAJOR.MINOR.PATCH Semantic Versioning guidelines. 26 | * @see http://semver.org/ 27 | */ 28 | #ifndef SRC_UTILS_AWS_IOT_VERSION_H_ 29 | #define SRC_UTILS_AWS_IOT_VERSION_H_ 30 | 31 | /** 32 | * @brief MAJOR version, incremented when incompatible API changes are made. 33 | */ 34 | #define VERSION_MAJOR 3 35 | /** 36 | * @brief MINOR version when functionality is added in a backwards-compatible manner. 37 | */ 38 | #define VERSION_MINOR 0 39 | /** 40 | * @brief PATCH version when backwards-compatible bug fixes are made. 41 | */ 42 | #define VERSION_PATCH 1 43 | /** 44 | * @brief TAG is an (optional) tag appended to the version if a more descriptive verion is needed. 45 | */ 46 | #define VERSION_TAG "" 47 | 48 | #endif /* SRC_UTILS_AWS_IOT_VERSION_H_ */ 49 | -------------------------------------------------------------------------------- /include/threads_interface.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file threads_interface.h 18 | * @brief Thread interface definition for MQTT client. 19 | * 20 | * Defines an interface that can be used by system components for multithreaded situations. 21 | * Starting point for porting the SDK to the threading hardware layer of a new platform. 22 | */ 23 | 24 | #include "aws_iot_config.h" 25 | 26 | #ifdef _ENABLE_THREAD_SUPPORT_ 27 | #ifndef __THREADS_INTERFACE_H_ 28 | #define __THREADS_INTERFACE_H_ 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | /** 35 | * The platform specific timer header that defines the Timer struct 36 | */ 37 | #include "threads_platform.h" 38 | 39 | #include 40 | 41 | /** 42 | * @brief Mutex Type 43 | * 44 | * Forward declaration of a mutex struct. The definition of this struct is 45 | * platform dependent. When porting to a new platform add this definition 46 | * in "threads_platform.h". 47 | * 48 | */ 49 | typedef struct _IoT_Mutex_t IoT_Mutex_t; 50 | 51 | /** 52 | * @brief Initialize the provided mutex 53 | * 54 | * Call this function to initialize the mutex 55 | * 56 | * @param IoT_Mutex_t - pointer to the mutex to be initialized 57 | * @return IoT_Error_t - error code indicating result of operation 58 | */ 59 | IoT_Error_t aws_iot_thread_mutex_init(IoT_Mutex_t *); 60 | 61 | /** 62 | * @brief Lock the provided mutex 63 | * 64 | * Call this function to lock the mutex before performing a state change 65 | * This is a blocking call. 66 | * 67 | * @param IoT_Mutex_t - pointer to the mutex to be locked 68 | * @return IoT_Error_t - error code indicating result of operation 69 | */ 70 | IoT_Error_t aws_iot_thread_mutex_lock(IoT_Mutex_t *); 71 | 72 | /** 73 | * @brief Lock the provided mutex 74 | * 75 | * Call this function to lock the mutex before performing a state change. 76 | * This is not a blocking call. 77 | * 78 | * @param IoT_Mutex_t - pointer to the mutex to be locked 79 | * @return IoT_Error_t - error code indicating result of operation 80 | */ 81 | IoT_Error_t aws_iot_thread_mutex_trylock(IoT_Mutex_t *); 82 | 83 | /** 84 | * @brief Unlock the provided mutex 85 | * 86 | * Call this function to unlock the mutex before performing a state change 87 | * 88 | * @param IoT_Mutex_t - pointer to the mutex to be unlocked 89 | * @return IoT_Error_t - error code indicating result of operation 90 | */ 91 | IoT_Error_t aws_iot_thread_mutex_unlock(IoT_Mutex_t *); 92 | 93 | /** 94 | * @brief Destroy the provided mutex 95 | * 96 | * Call this function to destroy the mutex 97 | * 98 | * @param IoT_Mutex_t - pointer to the mutex to be destroyed 99 | * @return IoT_Error_t - error code indicating result of operation 100 | */ 101 | IoT_Error_t aws_iot_thread_mutex_destroy(IoT_Mutex_t *); 102 | 103 | #ifdef __cplusplus 104 | } 105 | #endif 106 | 107 | #endif /*__THREADS_INTERFACE_H_*/ 108 | #endif /*_ENABLE_THREAD_SUPPORT_*/ 109 | -------------------------------------------------------------------------------- /include/timer_interface.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2014 IBM Corp. 3 | * 4 | * All rights reserved. This program and the accompanying materials 5 | * are made available under the terms of the Eclipse Public License v1.0 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. 7 | * 8 | * The Eclipse Public License is available at 9 | * http://www.eclipse.org/legal/epl-v10.html 10 | * and the Eclipse Distribution License is available at 11 | * http://www.eclipse.org/org/documents/edl-v10.php. 12 | * 13 | * Contributors: 14 | * Allan Stockdill-Mander - initial API and implementation and/or initial documentation 15 | *******************************************************************************/ 16 | 17 | /** 18 | * @file timer_interface.h 19 | * @brief Timer interface definition for MQTT client. 20 | * 21 | * Defines an interface to timers that can be used by other system 22 | * components. MQTT client requires timers to handle timeouts and 23 | * MQTT keep alive. 24 | * Starting point for porting the SDK to the timer hardware layer of a new platform. 25 | */ 26 | 27 | #ifndef __TIMER_INTERFACE_H_ 28 | #define __TIMER_INTERFACE_H_ 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | /** 35 | * The platform specific timer header that defines the Timer struct 36 | */ 37 | #include "timer_platform.h" 38 | 39 | #include 40 | #include 41 | 42 | /** 43 | * @brief Timer Type 44 | * 45 | * Forward declaration of a timer struct. The definition of this struct is 46 | * platform dependent. When porting to a new platform add this definition 47 | * in "timer_.h" and include that file above. 48 | * 49 | */ 50 | typedef struct Timer Timer; 51 | 52 | /** 53 | * @brief Check if a timer is expired 54 | * 55 | * Call this function passing in a timer to check if that timer has expired. 56 | * 57 | * @param Timer - pointer to the timer to be checked for expiration 58 | * @return bool - true = timer expired, false = timer not expired 59 | */ 60 | bool has_timer_expired(Timer *); 61 | 62 | /** 63 | * @brief Create a timer (milliseconds) 64 | * 65 | * Sets the timer to expire in a specified number of milliseconds. 66 | * 67 | * @param Timer - pointer to the timer to be set to expire in milliseconds 68 | * @param uint32_t - set the timer to expire in this number of milliseconds 69 | */ 70 | void countdown_ms(Timer *, uint32_t); 71 | 72 | /** 73 | * @brief Create a timer (seconds) 74 | * 75 | * Sets the timer to expire in a specified number of seconds. 76 | * 77 | * @param Timer - pointer to the timer to be set to expire in seconds 78 | * @param uint32_t - set the timer to expire in this number of seconds 79 | */ 80 | void countdown_sec(Timer *, uint32_t); 81 | 82 | /** 83 | * @brief Check the time remaining on a given timer 84 | * 85 | * Checks the input timer and returns the number of milliseconds remaining on the timer. 86 | * 87 | * @param Timer - pointer to the timer to be set to checked 88 | * @return int - milliseconds left on the countdown timer 89 | */ 90 | uint32_t left_ms(Timer *); 91 | 92 | /** 93 | * @brief Initialize a timer 94 | * 95 | * Performs any initialization required to the timer passed in. 96 | * 97 | * @param Timer - pointer to the timer to be initialized 98 | */ 99 | void init_timer(Timer *); 100 | 101 | #ifdef __cplusplus 102 | } 103 | #endif 104 | 105 | #endif //__TIMER_INTERFACE_H_ 106 | -------------------------------------------------------------------------------- /platform/linux/common/timer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file timer.c 18 | * @brief Linux implementation of the timer interface. 19 | */ 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | #include "timer_platform.h" 32 | 33 | bool has_timer_expired(Timer *timer) { 34 | struct timeval now, res; 35 | gettimeofday(&now, NULL); 36 | timersub(&timer->end_time, &now, &res); 37 | return res.tv_sec < 0 || (res.tv_sec == 0 && res.tv_usec <= 0); 38 | } 39 | 40 | void countdown_ms(Timer *timer, uint32_t timeout) { 41 | struct timeval now; 42 | #ifdef __cplusplus 43 | struct timeval interval = {timeout / 1000, static_cast((timeout % 1000) * 1000)}; 44 | #else 45 | struct timeval interval = {timeout / 1000, (int)((timeout % 1000) * 1000)}; 46 | #endif 47 | gettimeofday(&now, NULL); 48 | timeradd(&now, &interval, &timer->end_time); 49 | } 50 | 51 | uint32_t left_ms(Timer *timer) { 52 | struct timeval now, res; 53 | uint32_t result_ms = 0; 54 | gettimeofday(&now, NULL); 55 | timersub(&timer->end_time, &now, &res); 56 | if(res.tv_sec >= 0) { 57 | result_ms = (uint32_t) (res.tv_sec * 1000 + res.tv_usec / 1000); 58 | } 59 | return result_ms; 60 | } 61 | 62 | void countdown_sec(Timer *timer, uint32_t timeout) { 63 | struct timeval now; 64 | struct timeval interval = {timeout, 0}; 65 | gettimeofday(&now, NULL); 66 | timeradd(&now, &interval, &timer->end_time); 67 | } 68 | 69 | void init_timer(Timer *timer) { 70 | timer->end_time = (struct timeval) {0, 0}; 71 | } 72 | 73 | void delay(unsigned milliseconds) 74 | { 75 | useconds_t sleepTime = (useconds_t)(milliseconds * 1000); 76 | 77 | usleep(sleepTime); 78 | } 79 | 80 | #ifdef __cplusplus 81 | } 82 | #endif 83 | -------------------------------------------------------------------------------- /platform/linux/common/timer_platform.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | #ifndef SRC_PROTOCOL_MQTT_AWS_IOT_EMBEDDED_CLIENT_WRAPPER_PLATFORM_LINUX_COMMON_TIMER_PLATFORM_H_ 17 | #define SRC_PROTOCOL_MQTT_AWS_IOT_EMBEDDED_CLIENT_WRAPPER_PLATFORM_LINUX_COMMON_TIMER_PLATFORM_H_ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | /** 24 | * @file timer_platform.h 25 | */ 26 | #include 27 | #include 28 | #include "timer_interface.h" 29 | 30 | /** 31 | * definition of the Timer struct. Platform specific 32 | */ 33 | struct Timer { 34 | struct timeval end_time; 35 | }; 36 | 37 | /** 38 | * @brief Delay (sleep) for the specified number of milliseconds. 39 | * 40 | * @param milliseconds The number of milliseconds to sleep. 41 | */ 42 | void delay(unsigned milliseconds); 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif 47 | 48 | #endif /* SRC_PROTOCOL_MQTT_AWS_IOT_EMBEDDED_CLIENT_WRAPPER_PLATFORM_LINUX_COMMON_TIMER_PLATFORM_H_ */ 49 | -------------------------------------------------------------------------------- /platform/linux/mbedtls/network_platform.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | #ifndef IOTSDKC_NETWORK_MBEDTLS_PLATFORM_H_H 17 | 18 | #include "mbedtls/config.h" 19 | 20 | #include "mbedtls/platform.h" 21 | #include "mbedtls/net.h" 22 | #include "mbedtls/ssl.h" 23 | #include "mbedtls/entropy.h" 24 | #include "mbedtls/ctr_drbg.h" 25 | #include "mbedtls/certs.h" 26 | #include "mbedtls/x509.h" 27 | #include "mbedtls/error.h" 28 | #include "mbedtls/debug.h" 29 | #include "mbedtls/timing.h" 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | /** 36 | * @brief TLS Connection Parameters 37 | * 38 | * Defines a type containing TLS specific parameters to be passed down to the 39 | * TLS networking layer to create a TLS secured socket. 40 | */ 41 | typedef struct _TLSDataParams { 42 | mbedtls_entropy_context entropy; 43 | mbedtls_ctr_drbg_context ctr_drbg; 44 | mbedtls_ssl_context ssl; 45 | mbedtls_ssl_config conf; 46 | uint32_t flags; 47 | mbedtls_x509_crt cacert; 48 | mbedtls_x509_crt clicert; 49 | mbedtls_pk_context pkey; 50 | mbedtls_net_context server_fd; 51 | }TLSDataParams; 52 | 53 | #define IOTSDKC_NETWORK_MBEDTLS_PLATFORM_H_H 54 | 55 | #ifdef __cplusplus 56 | } 57 | #endif 58 | 59 | #endif //IOTSDKC_NETWORK_MBEDTLS_PLATFORM_H_H 60 | -------------------------------------------------------------------------------- /platform/linux/openssl/network_platform.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | #ifndef IOTSDKC_NETWORK_OPENSSL_PLATFORM_H_H 17 | 18 | #include "openssl/ssl.h" 19 | #include "openssl/err.h" 20 | #include "openssl/crypto.h" 21 | #include "openssl/opensslv.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /** 28 | * @brief TLS Connection Parameters 29 | * 30 | * Defines a type containing TLS specific parameters to be passed down to the 31 | * TLS networking layer to create a TLS secured socket. 32 | */ 33 | typedef struct _TLSDataParams 34 | { 35 | int32_t xTcpSocket; 36 | SSL * pSsl; 37 | uint32_t flags; 38 | } TLSDataParams; 39 | 40 | #define IOTSDKC_NETWORK_OPENSSL_PLATFORM_H_H 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | 46 | #endif //IOTSDKC_NETWORK_OPENSSL_PLATFORM_H_H 47 | -------------------------------------------------------------------------------- /platform/linux/pthread/threads_platform.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | #include "threads_interface.h" 17 | #ifdef _ENABLE_THREAD_SUPPORT_ 18 | #ifndef IOTSDKC_THREADS_PLATFORM_H_H 19 | #define IOTSDKC_THREADS_PLATFORM_H_H 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | #include 26 | 27 | /** 28 | * @brief Mutex Type 29 | * 30 | * definition of the Mutex struct. Platform specific 31 | * 32 | */ 33 | struct _IoT_Mutex_t { 34 | pthread_mutex_t lock; 35 | }; 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif /* IOTSDKC_THREADS_PLATFORM_H_H */ 42 | #endif /* _ENABLE_THREAD_SUPPORT_ */ 43 | 44 | -------------------------------------------------------------------------------- /platform/linux/pthread/threads_pthread_wrapper.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | #include "threads_platform.h" 17 | #ifdef _ENABLE_THREAD_SUPPORT_ 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | /** 24 | * @brief Initialize the provided mutex 25 | * 26 | * Call this function to initialize the mutex 27 | * 28 | * @param IoT_Mutex_t - pointer to the mutex to be initialized 29 | * @return IoT_Error_t - error code indicating result of operation 30 | */ 31 | IoT_Error_t aws_iot_thread_mutex_init(IoT_Mutex_t *pMutex) { 32 | if(0 != pthread_mutex_init(&(pMutex->lock), NULL)) { 33 | return MUTEX_INIT_ERROR; 34 | } 35 | 36 | return SUCCESS; 37 | } 38 | 39 | /** 40 | * @brief Lock the provided mutex 41 | * 42 | * Call this function to lock the mutex before performing a state change 43 | * Blocking, thread will block until lock request fails 44 | * 45 | * @param IoT_Mutex_t - pointer to the mutex to be locked 46 | * @return IoT_Error_t - error code indicating result of operation 47 | */ 48 | IoT_Error_t aws_iot_thread_mutex_lock(IoT_Mutex_t *pMutex) { 49 | int rc = pthread_mutex_lock(&(pMutex->lock)); 50 | if(0 != rc) { 51 | return MUTEX_LOCK_ERROR; 52 | } 53 | 54 | return SUCCESS; 55 | } 56 | 57 | /** 58 | * @brief Try to lock the provided mutex 59 | * 60 | * Call this function to attempt to lock the mutex before performing a state change 61 | * Non-Blocking, immediately returns with failure if lock attempt fails 62 | * 63 | * @param IoT_Mutex_t - pointer to the mutex to be locked 64 | * @return IoT_Error_t - error code indicating result of operation 65 | */ 66 | IoT_Error_t aws_iot_thread_mutex_trylock(IoT_Mutex_t *pMutex) { 67 | int rc = pthread_mutex_trylock(&(pMutex->lock)); 68 | if(0 != rc) { 69 | return MUTEX_LOCK_ERROR; 70 | } 71 | 72 | return SUCCESS; 73 | } 74 | 75 | /** 76 | * @brief Unlock the provided mutex 77 | * 78 | * Call this function to unlock the mutex before performing a state change 79 | * 80 | * @param IoT_Mutex_t - pointer to the mutex to be unlocked 81 | * @return IoT_Error_t - error code indicating result of operation 82 | */ 83 | IoT_Error_t aws_iot_thread_mutex_unlock(IoT_Mutex_t *pMutex) { 84 | if(0 != pthread_mutex_unlock(&(pMutex->lock))) { 85 | return MUTEX_UNLOCK_ERROR; 86 | } 87 | 88 | return SUCCESS; 89 | } 90 | 91 | /** 92 | * @brief Destroy the provided mutex 93 | * 94 | * Call this function to destroy the mutex 95 | * 96 | * @param IoT_Mutex_t - pointer to the mutex to be destroyed 97 | * @return IoT_Error_t - error code indicating result of operation 98 | */ 99 | IoT_Error_t aws_iot_thread_mutex_destroy(IoT_Mutex_t *pMutex) { 100 | if(0 != pthread_mutex_destroy(&(pMutex->lock))) { 101 | return MUTEX_DESTROY_ERROR; 102 | } 103 | 104 | return SUCCESS; 105 | } 106 | 107 | #ifdef __cplusplus 108 | } 109 | #endif 110 | 111 | #endif /* _ENABLE_THREAD_SUPPORT_ */ 112 | 113 | -------------------------------------------------------------------------------- /samples/README.md: -------------------------------------------------------------------------------- 1 | ## Overview 2 | This folder contains several samples that demonstrate various SDK functions. The Readme file also includes a walk-through of the subscribe publish sample to explain how the SDK is used. The samples are currently provided with Makefiles for building them on linux. For each sample: 3 | 4 | * Explore the makefile. The makefile for each sample provides a reference on how to set up makefiles for client applications 5 | * Explore the example. It connects to AWS IoT platform using MQTT and demonstrates few actions that can be performed by the SDK 6 | * Download certificate authority CA file from [Symantec](https://www.symantec.com/content/en/us/enterprise/verisign/roots/VeriSign-Class%203-Public-Primary-Certification-Authority-G5.pem) and place in location referenced in the example (certs/) 7 | * Ensure you have [created a thing](https://docs.aws.amazon.com/iot/latest/developerguide/create-thing.html) through your AWS IoT Console with name matching the definition AWS_IOT_MY_THING_NAME in the `aws_iot_config.h` file 8 | * Place device identity cert and private key in locations referenced in the example (certs/) 9 | * Ensure the names of the cert files are the same as in the `aws_iot_config.h` file 10 | * Ensure the certificate has an attached policy which allows the proper permissions for AWS IoT 11 | * Build the example using make (`make`) 12 | * Run sample application (./subscribe_publish_sample or ./shadow_sample). The sample will print status messages to stdout 13 | * All samples are written in C unless otherwise mentioned. The following sample applications are included: 14 | * `subscribe_publish_sample` - a simple pub/sub MQTT example 15 | * `subscribe_publish_cpp_sample` - a simple pub/sub MQTT example written in C++ 16 | * `subscribe_publish_library_sample` - a simple pub/sub MQTT example which builds the SDK as a separate library 17 | * `shadow_sample` - a simple device shadow example using a connected window example 18 | * `shadow_sample_console_echo` - a sample to work with the AWS IoT Console interactive guide 19 | 20 | ## Subscribe Publish Sample 21 | This is a simple pub/sub MQTT example. It connects a single MQTT client to the server and subscribes to a test topic. Then it proceeds to publish messages on this topic and yields after each publish to ensure that the message was received. 22 | 23 | * The sample first creates an instance of the AWS_IoT_Client 24 | * The next step is to initialize the client. The aws_iot_mqtt_init API is called for this purpose. The API takes the client instance and an IoT_Client_Init_Params variable to set the initial values for the client. The Init params include values like host URL, port, certificates, disconnect handler etc. 25 | * If the call to the init API was successful, we can proceed to call connect. The API is called aws_iot_mqtt_connect. It takes the client instance and IoT_Client_Connect_Params variable as arguments. The IoT_Client_Connect_Params is optional after the first call to connect as the client retains the original values that were provided to support reconnect. The Connect params include values like Client Id, MQTT Version etc. 26 | * If the connect API call was successful, we can proceed to subscribe and publish on this connect. The connect API call will return an error code, specific to the type of error that occurred, in case the call fails. 27 | * It is important to remember here that there is no dynamic memory allocation in the SDK. Any values that are passed as a pointer to the APIs should not be freed unless they are not required any further. For example, if the variable that stores the certificate path is freed after the init call is made, the connect call will fail. Similarly, if it is freed after the connect API returns success, any future connect calls (including reconnects) will fail. 28 | * The next step for this sample is to subscribe to the test topic. The API to be called for subscribe is aws_iot_mqtt_subscribe. It takes as arguments, the IoT Client instance, topic name, the length of the topic name, QoS, the subscribe callback handler and an optional pointer to some data to be returned to the subscribe handler 29 | * The next step it to call the publish API to send a message on the test topic. The sample sends two different messages, one QoS0 and one QoS1. The 30 | * The publish API takes the client instance, topic name to publish to, topic name length and a variable of type IoT_Publish_Message_Params. The IoT_Publish_Message_Params contains the payload, length of the payload and QoS. 31 | * If the publish API calls are successful, the sample proceeds to call the yield API. The yield API takes the client instance and a timeout value in milliseconds as arguments. 32 | * The yield API is called to let the SDK process any incoming messages. It also periodically sends out the PING request to prevent disconnect and, if enabled, it also performs auto-reconnect and resubscribe. 33 | * The yield API should be called periodically to process the PING request as well as read any messages in the receive buffer. It should be called once at least every TTL/2 time periods to ensure disconnect does not happen. There can only be one yield in progress at a time. Therefore, in multi-threaded scenarios one thread can be a dedicated yield thread while other threads handle other operations. 34 | * The sample sends out messages equal to the value set in publish count unless infinite publishing flag is set 35 | 36 | For further information on each API please read the API documentation. 37 | 38 | ## Subscribe Publish Cpp Sample 39 | This is the same sample as above but it is built using a C++ compiler. It demonstrates how the SDK can be used in a C++ program. 40 | 41 | ## Subscribe Publish Library Sample 42 | This is also the same code as the Subscribe Publish sample. In this case, the SDK is built as a separate library and then used in the sample program. 43 | 44 | ## Download Agent Sample 45 | This is the sample that uses the file download agent to download a file over MQTT. The API of the download agent is defined in /include/aws_iot_download_agent.h. -------------------------------------------------------------------------------- /samples/linux/download_agent_sample/Makefile: -------------------------------------------------------------------------------- 1 | #This target is to ensure accidental execution of Makefile as a bash script will not execute commands like rm in unexpected directories and exit gracefully. 2 | .prevent_execution: 3 | exit 0 4 | 5 | CC = gcc 6 | 7 | #remove @ for no make command prints 8 | DEBUG = @ 9 | 10 | APP_DIR = . 11 | APP_INCLUDE_DIRS += -I $(APP_DIR) 12 | APP_NAME = download_agent_sample 13 | APP_SRC_FILES = $(APP_NAME).c 14 | 15 | #IoT client directory 16 | IOT_CLIENT_DIR = ../../.. 17 | 18 | PLATFORM_DIR = $(IOT_CLIENT_DIR)/platform/linux/mbedtls 19 | PLATFORM_COMMON_DIR = $(IOT_CLIENT_DIR)/platform/linux/common 20 | 21 | IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/include 22 | IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/external_libs/jsmn 23 | IOT_INCLUDE_DIRS += -I $(PLATFORM_COMMON_DIR) 24 | IOT_INCLUDE_DIRS += -I $(PLATFORM_DIR) 25 | 26 | IOT_SRC_FILES += $(shell find $(IOT_CLIENT_DIR)/src/ -name '*.c') 27 | IOT_SRC_FILES += $(shell find $(IOT_CLIENT_DIR)/external_libs/jsmn -name '*.c') 28 | IOT_SRC_FILES += $(shell find $(PLATFORM_DIR)/ -name '*.c') 29 | IOT_SRC_FILES += $(shell find $(PLATFORM_COMMON_DIR)/ -name '*.c') 30 | 31 | #TLS - mbedtls 32 | MBEDTLS_DIR = $(IOT_CLIENT_DIR)/external_libs/mbedTLS 33 | TLS_LIB_DIR = $(MBEDTLS_DIR)/library 34 | CRYPTO_LIB_DIR = $(MBEDTLS_DIR)/crypto/library 35 | TLS_INCLUDE_DIR = -I $(MBEDTLS_DIR)/include 36 | 37 | #CBOR - tinycbor 38 | TINYCBOR_DIR = $(IOT_CLIENT_DIR)/external_libs/tinycbor 39 | CBOR_LIB_DIR = $(TINYCBOR_DIR)/lib 40 | CBOR_INCLUDE_DIR = -I $(TINYCBOR_DIR)/src 41 | 42 | EXTERNAL_LIBS += -L$(TLS_LIB_DIR) 43 | LD_FLAG += -Wl,-rpath,$(TLS_LIB_DIR) 44 | LD_FLAG += -ldl $(TLS_LIB_DIR)/libmbedtls.a $(CRYPTO_LIB_DIR)/libmbedcrypto.a $(TLS_LIB_DIR)/libmbedx509.a $(CBOR_LIB_DIR)/libtinycbor.a -lpthread 45 | 46 | #Aggregate all include and src directories 47 | INCLUDE_ALL_DIRS += $(IOT_INCLUDE_DIRS) 48 | INCLUDE_ALL_DIRS += $(TLS_INCLUDE_DIR) 49 | INCLUDE_ALL_DIRS += $(CBOR_INCLUDE_DIR) 50 | INCLUDE_ALL_DIRS += $(APP_INCLUDE_DIRS) 51 | 52 | SRC_FILES += $(APP_SRC_FILES) 53 | SRC_FILES += $(IOT_SRC_FILES) 54 | 55 | # Logging level control 56 | LOG_FLAGS += -DENABLE_IOT_DEBUG 57 | LOG_FLAGS += -DENABLE_IOT_INFO 58 | LOG_FLAGS += -DENABLE_IOT_WARN 59 | LOG_FLAGS += -DENABLE_IOT_ERROR 60 | 61 | COMPILER_FLAGS += $(LOG_FLAGS) 62 | #If the processor is big endian uncomment the compiler flag 63 | #COMPILER_FLAGS += -DREVERSED 64 | 65 | MBED_TLS_MAKE_CMD = $(MAKE) -C $(MBEDTLS_DIR) 66 | TINYCBOR_MAKE_CMD = $(MAKE) -C $(TINYCBOR_DIR) 67 | 68 | PRE_MAKE_CMD = $(MBED_TLS_MAKE_CMD) && $(TINYCBOR_MAKE_CMD) 69 | MAKE_CMD = $(CC) $(SRC_FILES) $(COMPILER_FLAGS) -DENABLE_TINYCBOR -o $(APP_NAME) $(LD_FLAG) $(EXTERNAL_LIBS) $(INCLUDE_ALL_DIRS) 70 | 71 | all: 72 | $(PRE_MAKE_CMD) 73 | $(DEBUG)$(MAKE_CMD) 74 | $(POST_MAKE_CMD) 75 | 76 | clean: 77 | rm -f $(APP_DIR)/$(APP_NAME) 78 | $(MBED_TLS_MAKE_CMD) clean 79 | $(TINYCBOR_MAKE_CMD) clean 80 | -------------------------------------------------------------------------------- /samples/linux/download_agent_sample/aws_iot_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file aws_iot_config.h 18 | * @brief AWS IoT specific configuration file 19 | */ 20 | 21 | #ifndef SRC_DLA_IOT_DLA_CONFIG_H_ 22 | #define SRC_DLA_IOT_DLA_CONFIG_H_ 23 | 24 | // Get from console 25 | // ================================================= 26 | #define AWS_IOT_MQTT_HOST "" ///< Customer specific MQTT HOST. The same will be used for Thing Shadow 27 | #define AWS_IOT_MQTT_PORT 443 ///< default port for MQTT/S 28 | #define AWS_IOT_MQTT_CLIENT_ID "c-sdk-client-id" ///< MQTT client ID should be unique for every device 29 | #define AWS_IOT_MY_THING_NAME "AWS-IoT-C-SDK" ///< Thing Name of the Shadow this device is associated with 30 | #define AWS_IOT_ROOT_CA_FILENAME "rootCA.crt" ///< Root CA file name 31 | #define AWS_IOT_CERTIFICATE_FILENAME "cert.pem" ///< device signed certificate file name 32 | #define AWS_IOT_PRIVATE_KEY_FILENAME "privkey.pem" ///< Device private key filename 33 | // ================================================= 34 | 35 | // MQTT PubSub 36 | #define AWS_IOT_MQTT_TX_BUF_LEN 512 ///< Any time a message is sent out through the MQTT layer. The message is copied into this buffer anytime a publish is done. This will also be used in the case of Thing Shadow 37 | #define AWS_IOT_MQTT_RX_BUF_LEN 4096 ///< Any message that comes into the device should be less than this buffer size. If a received message is bigger than this buffer size the message will be dropped. 38 | #define AWS_IOT_MQTT_NUM_SUBSCRIBE_HANDLERS 10 ///< Maximum number of topic filters the MQTT client can handle at any given time. This should be increased appropriately when using Thing Shadow 39 | 40 | // Thing Shadow specific configs 41 | #define SHADOW_MAX_SIZE_OF_RX_BUFFER (AWS_IOT_MQTT_RX_BUF_LEN+1) ///< Maximum size of the SHADOW buffer to store the received Shadow message, including terminating NULL byte. 42 | #define MAX_SIZE_OF_UNIQUE_CLIENT_ID_BYTES 80 ///< Maximum size of the Unique Client Id. For More info on the Client Id refer \ref response "Acknowledgments" 43 | #define MAX_SIZE_CLIENT_ID_WITH_SEQUENCE MAX_SIZE_OF_UNIQUE_CLIENT_ID_BYTES + 10 ///< This is size of the extra sequence number that will be appended to the Unique client Id 44 | #define MAX_SIZE_CLIENT_TOKEN_CLIENT_SEQUENCE MAX_SIZE_CLIENT_ID_WITH_SEQUENCE + 20 ///< This is size of the the total clientToken key and value pair in the JSON 45 | #define MAX_ACKS_TO_COMEIN_AT_ANY_GIVEN_TIME 10 ///< At Any given time we will wait for this many responses. This will correlate to the rate at which the shadow actions are requested 46 | #define MAX_THINGNAME_HANDLED_AT_ANY_GIVEN_TIME 10 ///< We could perform shadow action on any thing Name and this is maximum Thing Names we can act on at any given time 47 | #define MAX_JSON_TOKEN_EXPECTED 120 ///< These are the max tokens that is expected to be in the Shadow JSON document. Include the metadata that gets published 48 | #define MAX_SHADOW_TOPIC_LENGTH_WITHOUT_THINGNAME 60 ///< All shadow actions have to be published or subscribed to a topic which is of the format $aws/things/{thingName}/shadow/update/accepted. This refers to the size of the topic without the Thing Name 49 | #define MAX_SIZE_OF_THING_NAME 20 ///< The Thing Name should not be bigger than this value. Modify this if the Thing Name needs to be bigger 50 | #define MAX_SHADOW_TOPIC_LENGTH_BYTES MAX_SHADOW_TOPIC_LENGTH_WITHOUT_THINGNAME + MAX_SIZE_OF_THING_NAME ///< This size includes the length of topic with Thing Name 51 | 52 | // Job specific configs 53 | #define MAX_SIZE_OF_JOB_ID 64 54 | #define MAX_JOB_JSON_TOKEN_EXPECTED 120 55 | #define MAX_SIZE_OF_JOB_REQUEST AWS_IOT_MQTT_TX_BUF_LEN 56 | 57 | #define MAX_JOB_TOPIC_LENGTH_WITHOUT_JOB_ID_OR_THING_NAME 40 58 | #define MAX_JOB_TOPIC_LENGTH_BYTES MAX_JOB_TOPIC_LENGTH_WITHOUT_JOB_ID_OR_THING_NAME + MAX_SIZE_OF_THING_NAME + MAX_SIZE_OF_JOB_ID + 2 59 | 60 | // Download Agent specific configs 61 | #define MAX_SIZE_OF_STREAM_NAME 64 62 | #define MAX_SIZE_OF_FILE_NAME 64 63 | #define MAX_SIZE_OF_FILE_BLOCK_LOG2 11UL 64 | #define MAX_SIZE_OF_CMD 128 65 | #define AWS_IOT_DOWNLOAD_AGENT_REQUEST_WAIT_INTERVAL 5000 ///< Time interval after being idle for download. 66 | 67 | #define DOWNLOAD_AGENT_WRITE_FLASH_SUPPORTED true ///< Enable write flash function for Download Agent 68 | 69 | // Auto Reconnect specific config 70 | #define AWS_IOT_MQTT_MIN_RECONNECT_WAIT_INTERVAL 1000 ///< Minimum time before the First reconnect attempt is made as part of the exponential back-off algorithm 71 | #define AWS_IOT_MQTT_MAX_RECONNECT_WAIT_INTERVAL 128000 ///< Maximum time interval after which exponential back-off will stop attempting to reconnect. 72 | 73 | #define DISABLE_METRICS false ///< Disable the collection of metrics by setting this to true 74 | 75 | #endif /* SRC_DLA_IOT_DLA_CONFIG_H_ */ 76 | -------------------------------------------------------------------------------- /samples/linux/execute_cmd_jobs_sample/Makefile: -------------------------------------------------------------------------------- 1 | #This target is to ensure accidental execution of Makefile as a bash script will not execute commands like rm in unexpected directories and exit gracefully. 2 | .prevent_execution: 3 | exit 0 4 | 5 | ifeq ($(origin CC),default) 6 | CC = gcc 7 | endif 8 | 9 | #remove @ for no make command prints 10 | DEBUG = @ 11 | 12 | #Use MbedTLS as default tls adapter. 13 | TLS_ADAPTER ?= mbedtls 14 | VALID_TLS_ADAPTER := mbedtls openssl 15 | ifneq ($(filter $(TLS_ADAPTER),$(VALID_TLS_ADAPTER)),) 16 | $(info TLS_ADAPTER=$(TLS_ADAPTER)) 17 | else 18 | $(error invalid TLS_ADAPTER value) 19 | endif 20 | 21 | APP_DIR = . 22 | APP_INCLUDE_DIRS += -I $(APP_DIR) 23 | APP_NAME = execute_cmd_job_sample 24 | APP_SRC_FILES = $(APP_NAME).c 25 | 26 | #IoT client directory 27 | IOT_CLIENT_DIR = ../../.. 28 | 29 | ifeq ($(TLS_ADAPTER),mbedtls) 30 | PLATFORM_DIR = $(IOT_CLIENT_DIR)/platform/linux/mbedtls 31 | endif 32 | 33 | ifeq ($(TLS_ADAPTER),openssl) 34 | PLATFORM_DIR = $(IOT_CLIENT_DIR)/platform/linux/openssl 35 | endif 36 | 37 | PLATFORM_COMMON_DIR = $(IOT_CLIENT_DIR)/platform/linux/common 38 | 39 | IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/include 40 | IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/sdk_config 41 | IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/external_libs/jsmn 42 | IOT_INCLUDE_DIRS += -I $(PLATFORM_COMMON_DIR) 43 | IOT_INCLUDE_DIRS += -I $(PLATFORM_DIR) 44 | 45 | IOT_SRC_FILES += $(shell find $(IOT_CLIENT_DIR)/src/ -name '*.c') 46 | IOT_SRC_FILES += $(shell find $(IOT_CLIENT_DIR)/external_libs/jsmn -name '*.c') 47 | IOT_SRC_FILES += $(shell find $(PLATFORM_DIR)/ -name '*.c') 48 | IOT_SRC_FILES += $(shell find $(PLATFORM_COMMON_DIR)/ -name '*.c') 49 | 50 | ifeq ($(TLS_ADAPTER),mbedtls) 51 | #TLS - mbedtls 52 | MBEDTLS_DIR = $(IOT_CLIENT_DIR)/external_libs/mbedTLS 53 | TLS_LIB_DIR = $(MBEDTLS_DIR)/library 54 | CRYPTO_LIB_DIR = $(MBEDTLS_DIR)/crypto/library 55 | TLS_INCLUDE_DIR = -I $(MBEDTLS_DIR)/include 56 | EXTERNAL_LIBS += -L$(TLS_LIB_DIR) 57 | LD_FLAG += -Wl,-rpath,$(TLS_LIB_DIR) 58 | LD_FLAG += -ldl $(TLS_LIB_DIR)/libmbedtls.a $(CRYPTO_LIB_DIR)/libmbedcrypto.a $(TLS_LIB_DIR)/libmbedx509.a -lpthread 59 | TLS_MAKE_CMD = $(MAKE) -C $(MBEDTLS_DIR) 60 | PRE_MAKE_CMD = $(TLS_MAKE_CMD) lib 61 | endif 62 | 63 | ifeq ($(TLS_ADAPTER),openssl) 64 | #TLS - openssl 65 | LD_FLAG += -lcrypto -lssl 66 | TLS_MAKE_CMD = @: 67 | PRE_MAKE_CMD = @: 68 | POST_MAKE_CMD = @: 69 | endif 70 | 71 | #Aggregate all include and src directories 72 | INCLUDE_ALL_DIRS += $(IOT_INCLUDE_DIRS) 73 | INCLUDE_ALL_DIRS += $(TLS_INCLUDE_DIR) 74 | INCLUDE_ALL_DIRS += $(APP_INCLUDE_DIRS) 75 | 76 | SRC_FILES += $(APP_SRC_FILES) 77 | SRC_FILES += $(IOT_SRC_FILES) 78 | 79 | # Logging level control 80 | LOG_FLAGS += -DENABLE_IOT_DEBUG 81 | LOG_FLAGS += -DENABLE_IOT_INFO 82 | LOG_FLAGS += -DENABLE_IOT_WARN 83 | LOG_FLAGS += -DENABLE_IOT_ERROR 84 | 85 | COMPILER_FLAGS += $(LOG_FLAGS) 86 | #If the processor is big endian uncomment the compiler flag 87 | #COMPILER_FLAGS += -DREVERSED 88 | 89 | MAKE_CMD = $(CC) $(SRC_FILES) $(COMPILER_FLAGS) -o $(APP_NAME) $(LD_FLAG) $(EXTERNAL_LIBS) $(INCLUDE_ALL_DIRS) 90 | 91 | all: 92 | $(PRE_MAKE_CMD) 93 | $(DEBUG)$(MAKE_CMD) 94 | $(POST_MAKE_CMD) 95 | 96 | clean: 97 | rm -f $(APP_DIR)/$(APP_NAME) 98 | $(TLS_MAKE_CMD) clean 99 | -------------------------------------------------------------------------------- /samples/linux/execute_cmd_jobs_sample/aws_iot_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file aws_iot_config.h 18 | * @brief AWS IoT specific configuration file 19 | */ 20 | 21 | #ifndef SRC_EXECUTE_CMD_JOBS_IOT_CONFIG_H_ 22 | #define SRC_EXECUTE_CMD_JOBS_IOT_CONFIG_H_ 23 | 24 | // Get from console 25 | // ================================================= 26 | #define AWS_IOT_MQTT_HOST "" ///< Customer specific MQTT HOST. The same will be used for Thing Shadow 27 | #define AWS_IOT_MQTT_PORT 443 ///< default port for MQTT/S 28 | #define AWS_IOT_MQTT_CLIENT_ID "c-sdk-client-id" ///< MQTT client ID should be unique for every device 29 | #define AWS_IOT_MY_THING_NAME "AWS-IoT-C-SDK" ///< Thing Name of the Shadow this device is associated with 30 | #define AWS_IOT_ROOT_CA_FILENAME "rootCA.crt" ///< Root CA file name 31 | #define AWS_IOT_CERTIFICATE_FILENAME "cert.pem" ///< device signed certificate file name 32 | #define AWS_IOT_PRIVATE_KEY_FILENAME "privkey.pem" ///< Device private key filename 33 | // ================================================= 34 | 35 | // MQTT PubSub 36 | #define AWS_IOT_MQTT_TX_BUF_LEN 512 ///< Any time a message is sent out through the MQTT layer. The message is copied into this buffer anytime a publish is done. This will also be used in the case of Thing Shadow 37 | #define AWS_IOT_MQTT_RX_BUF_LEN 4096 ///< Any message that comes into the device should be less than this buffer size. If a received message is bigger than this buffer size the message will be dropped. 38 | #define AWS_IOT_MQTT_NUM_SUBSCRIBE_HANDLERS 5 ///< Maximum number of topic filters the MQTT client can handle at any given time. This should be increased appropriately when using Thing Shadow 39 | 40 | // Shadow and Job common configs 41 | #define MAX_SIZE_OF_UNIQUE_CLIENT_ID_BYTES 80 ///< Maximum size of the Unique Client Id. For More info on the Client Id refer \ref response "Acknowledgments" 42 | #define MAX_SIZE_CLIENT_ID_WITH_SEQUENCE MAX_SIZE_OF_UNIQUE_CLIENT_ID_BYTES + 10 ///< This is size of the extra sequence number that will be appended to the Unique client Id 43 | #define MAX_SIZE_CLIENT_TOKEN_CLIENT_SEQUENCE MAX_SIZE_CLIENT_ID_WITH_SEQUENCE + 20 ///< This is size of the the total clientToken key and value pair in the JSON 44 | #define MAX_SIZE_OF_THING_NAME 30 ///< The Thing Name should not be bigger than this value. Modify this if the Thing Name needs to be bigger 45 | 46 | // Thing Shadow specific configs 47 | #define SHADOW_MAX_SIZE_OF_RX_BUFFER 512 ///< Maximum size of the SHADOW buffer to store the received Shadow message 48 | #define MAX_ACKS_TO_COMEIN_AT_ANY_GIVEN_TIME 10 ///< At Any given time we will wait for this many responses. This will correlate to the rate at which the shadow actions are requested 49 | #define MAX_THINGNAME_HANDLED_AT_ANY_GIVEN_TIME 10 ///< We could perform shadow action on any thing Name and this is maximum Thing Names we can act on at any given time 50 | #define MAX_JSON_TOKEN_EXPECTED 120 ///< These are the max tokens that is expected to be in the Shadow JSON document. Include the metadata that gets published 51 | #define MAX_SHADOW_TOPIC_LENGTH_WITHOUT_THINGNAME 60 ///< All shadow actions have to be published or subscribed to a topic which is of the format $aws/things/{thingName}/shadow/update/accepted. This refers to the size of the topic without the Thing Name 52 | #define MAX_SHADOW_TOPIC_LENGTH_BYTES MAX_SHADOW_TOPIC_LENGTH_WITHOUT_THINGNAME + MAX_SIZE_OF_THING_NAME ///< This size includes the length of topic with Thing Name 53 | 54 | // Job specific configs 55 | #define MAX_SIZE_OF_JOB_ID 64 56 | #define MAX_JOB_JSON_TOKEN_EXPECTED 120 57 | #define MAX_SIZE_OF_JOB_REQUEST AWS_IOT_MQTT_TX_BUF_LEN 58 | 59 | #define MAX_JOB_TOPIC_LENGTH_WITHOUT_JOB_ID_OR_THING_NAME 40 60 | #define MAX_JOB_TOPIC_LENGTH_BYTES MAX_JOB_TOPIC_LENGTH_WITHOUT_JOB_ID_OR_THING_NAME + MAX_SIZE_OF_THING_NAME + MAX_SIZE_OF_JOB_ID + 2 61 | 62 | // Execute commands specific configs 63 | #define MAX_SIZE_OF_CMD AWS_IOT_MQTT_RX_BUF_LEN 64 | 65 | // Auto Reconnect specific config 66 | #define AWS_IOT_MQTT_MIN_RECONNECT_WAIT_INTERVAL 1000 ///< Minimum time before the First reconnect attempt is made as part of the exponential back-off algorithm 67 | #define AWS_IOT_MQTT_MAX_RECONNECT_WAIT_INTERVAL 128000 ///< Maximum time interval after which exponential back-off will stop attempting to reconnect. 68 | 69 | #define DISABLE_METRICS false ///< Disable the collection of metrics by setting this to true 70 | 71 | #endif /* SRC_EXECUTE_CMD_JOBS_IOT_CONFIG_H_ */ 72 | -------------------------------------------------------------------------------- /samples/linux/execute_cmd_jobs_sample/images/check_the_job_execution_status_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws-samples/aws-iot-mqtt-download-agent/6a4bfb687e87131c9cec57e2763b9b0ac4a5deb8/samples/linux/execute_cmd_jobs_sample/images/check_the_job_execution_status_01.png -------------------------------------------------------------------------------- /samples/linux/execute_cmd_jobs_sample/images/create_a_job_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws-samples/aws-iot-mqtt-download-agent/6a4bfb687e87131c9cec57e2763b9b0ac4a5deb8/samples/linux/execute_cmd_jobs_sample/images/create_a_job_01.png -------------------------------------------------------------------------------- /samples/linux/execute_cmd_jobs_sample/images/create_a_job_02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws-samples/aws-iot-mqtt-download-agent/6a4bfb687e87131c9cec57e2763b9b0ac4a5deb8/samples/linux/execute_cmd_jobs_sample/images/create_a_job_02.png -------------------------------------------------------------------------------- /samples/linux/execute_cmd_jobs_sample/images/create_a_job_03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws-samples/aws-iot-mqtt-download-agent/6a4bfb687e87131c9cec57e2763b9b0ac4a5deb8/samples/linux/execute_cmd_jobs_sample/images/create_a_job_03.png -------------------------------------------------------------------------------- /samples/linux/execute_cmd_jobs_sample/images/create_a_job_04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws-samples/aws-iot-mqtt-download-agent/6a4bfb687e87131c9cec57e2763b9b0ac4a5deb8/samples/linux/execute_cmd_jobs_sample/images/create_a_job_04.png -------------------------------------------------------------------------------- /samples/linux/execute_cmd_jobs_sample/images/create_a_job_05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws-samples/aws-iot-mqtt-download-agent/6a4bfb687e87131c9cec57e2763b9b0ac4a5deb8/samples/linux/execute_cmd_jobs_sample/images/create_a_job_05.png -------------------------------------------------------------------------------- /samples/linux/execute_cmd_jobs_sample/images/upload_a_file_to_aws_s3_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws-samples/aws-iot-mqtt-download-agent/6a4bfb687e87131c9cec57e2763b9b0ac4a5deb8/samples/linux/execute_cmd_jobs_sample/images/upload_a_file_to_aws_s3_01.png -------------------------------------------------------------------------------- /samples/linux/execute_cmd_jobs_sample/images/upload_a_file_to_aws_s3_02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws-samples/aws-iot-mqtt-download-agent/6a4bfb687e87131c9cec57e2763b9b0ac4a5deb8/samples/linux/execute_cmd_jobs_sample/images/upload_a_file_to_aws_s3_02.png -------------------------------------------------------------------------------- /samples/linux/execute_cmd_jobs_sample/images/upload_a_file_to_aws_s3_03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws-samples/aws-iot-mqtt-download-agent/6a4bfb687e87131c9cec57e2763b9b0ac4a5deb8/samples/linux/execute_cmd_jobs_sample/images/upload_a_file_to_aws_s3_03.png -------------------------------------------------------------------------------- /samples/linux/execute_cmd_jobs_sample/images/upload_a_file_to_aws_s3_04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws-samples/aws-iot-mqtt-download-agent/6a4bfb687e87131c9cec57e2763b9b0ac4a5deb8/samples/linux/execute_cmd_jobs_sample/images/upload_a_file_to_aws_s3_04.png -------------------------------------------------------------------------------- /samples/linux/execute_cmd_jobs_sample/images/upload_a_file_to_aws_s3_05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws-samples/aws-iot-mqtt-download-agent/6a4bfb687e87131c9cec57e2763b9b0ac4a5deb8/samples/linux/execute_cmd_jobs_sample/images/upload_a_file_to_aws_s3_05.png -------------------------------------------------------------------------------- /samples/linux/execute_cmd_jobs_sample/images/upload_a_file_to_aws_s3_06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws-samples/aws-iot-mqtt-download-agent/6a4bfb687e87131c9cec57e2763b9b0ac4a5deb8/samples/linux/execute_cmd_jobs_sample/images/upload_a_file_to_aws_s3_06.png -------------------------------------------------------------------------------- /samples/linux/jobs_sample/Makefile: -------------------------------------------------------------------------------- 1 | #This target is to ensure accidental execution of Makefile as a bash script will not execute commands like rm in unexpected directories and exit gracefully. 2 | .prevent_execution: 3 | exit 0 4 | 5 | CC = gcc 6 | 7 | #remove @ for no make command prints 8 | DEBUG = @ 9 | 10 | APP_DIR = . 11 | APP_INCLUDE_DIRS += -I $(APP_DIR) 12 | APP_NAME = jobs_sample 13 | APP_SRC_FILES = $(APP_NAME).c 14 | 15 | #IoT client directory 16 | IOT_CLIENT_DIR = ../../.. 17 | 18 | PLATFORM_DIR = $(IOT_CLIENT_DIR)/platform/linux/mbedtls 19 | PLATFORM_COMMON_DIR = $(IOT_CLIENT_DIR)/platform/linux/common 20 | 21 | IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/include 22 | IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/sdk_config 23 | IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/external_libs/jsmn 24 | IOT_INCLUDE_DIRS += -I $(PLATFORM_COMMON_DIR) 25 | IOT_INCLUDE_DIRS += -I $(PLATFORM_DIR) 26 | 27 | IOT_SRC_FILES += $(shell find $(IOT_CLIENT_DIR)/src/ -name '*.c') 28 | IOT_SRC_FILES += $(shell find $(IOT_CLIENT_DIR)/external_libs/jsmn -name '*.c') 29 | IOT_SRC_FILES += $(shell find $(PLATFORM_DIR)/ -name '*.c') 30 | IOT_SRC_FILES += $(shell find $(PLATFORM_COMMON_DIR)/ -name '*.c') 31 | 32 | #TLS - mbedtls 33 | MBEDTLS_DIR = $(IOT_CLIENT_DIR)/external_libs/mbedTLS 34 | TLS_LIB_DIR = $(MBEDTLS_DIR)/library 35 | CRYPTO_LIB_DIR = $(MBEDTLS_DIR)/crypto/library 36 | TLS_INCLUDE_DIR = -I $(MBEDTLS_DIR)/include 37 | EXTERNAL_LIBS += -L$(TLS_LIB_DIR) 38 | LD_FLAG += -Wl,-rpath,$(TLS_LIB_DIR) 39 | LD_FLAG += -ldl $(TLS_LIB_DIR)/libmbedtls.a $(CRYPTO_LIB_DIR)/libmbedcrypto.a $(TLS_LIB_DIR)/libmbedx509.a -lpthread 40 | 41 | #Aggregate all include and src directories 42 | INCLUDE_ALL_DIRS += $(IOT_INCLUDE_DIRS) 43 | INCLUDE_ALL_DIRS += $(TLS_INCLUDE_DIR) 44 | INCLUDE_ALL_DIRS += $(APP_INCLUDE_DIRS) 45 | 46 | SRC_FILES += $(APP_SRC_FILES) 47 | SRC_FILES += $(IOT_SRC_FILES) 48 | 49 | # Logging level control 50 | LOG_FLAGS += -DENABLE_IOT_DEBUG 51 | LOG_FLAGS += -DENABLE_IOT_INFO 52 | LOG_FLAGS += -DENABLE_IOT_WARN 53 | LOG_FLAGS += -DENABLE_IOT_ERROR 54 | 55 | COMPILER_FLAGS += $(LOG_FLAGS) 56 | #If the processor is big endian uncomment the compiler flag 57 | #COMPILER_FLAGS += -DREVERSED 58 | 59 | MBED_TLS_MAKE_CMD = $(MAKE) -C $(MBEDTLS_DIR) 60 | 61 | PRE_MAKE_CMD = $(MBED_TLS_MAKE_CMD) 62 | MAKE_CMD = $(CC) $(SRC_FILES) $(COMPILER_FLAGS) -o $(APP_NAME) $(LD_FLAG) $(EXTERNAL_LIBS) $(INCLUDE_ALL_DIRS) 63 | 64 | all: 65 | $(PRE_MAKE_CMD) 66 | $(DEBUG)$(MAKE_CMD) 67 | $(POST_MAKE_CMD) 68 | 69 | clean: 70 | rm -f $(APP_DIR)/$(APP_NAME) 71 | $(MBED_TLS_MAKE_CMD) clean 72 | -------------------------------------------------------------------------------- /samples/linux/jobs_sample/aws_iot_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file aws_iot_config.h 18 | * @brief AWS IoT specific configuration file 19 | */ 20 | 21 | #ifndef SRC_JOBS_IOT_JOB_CONFIG_H_ 22 | #define SRC_JOBS_IOT_JOB_CONFIG_H_ 23 | 24 | // Get from console 25 | // ================================================= 26 | #define AWS_IOT_MQTT_HOST "" ///< Customer specific MQTT HOST. The same will be used for Thing Shadow 27 | #define AWS_IOT_MQTT_PORT 443 ///< default port for MQTT/S 28 | #define AWS_IOT_MQTT_CLIENT_ID "c-sdk-client-id" ///< MQTT client ID should be unique for every device 29 | #define AWS_IOT_MY_THING_NAME "AWS-IoT-C-SDK" ///< Thing Name of the Shadow this device is associated with 30 | #define AWS_IOT_ROOT_CA_FILENAME "rootCA.crt" ///< Root CA file name 31 | #define AWS_IOT_CERTIFICATE_FILENAME "cert.pem" ///< device signed certificate file name 32 | #define AWS_IOT_PRIVATE_KEY_FILENAME "privkey.pem" ///< Device private key filename 33 | 34 | // MQTT PubSub 35 | #ifndef DISABLE_IOT_JOBS 36 | #define AWS_IOT_MQTT_RX_BUF_LEN 512 ///< Any message that comes into the device should be less than this buffer size. If a received message is bigger than this buffer size the message will be dropped. 37 | #else 38 | #define AWS_IOT_MQTT_RX_BUF_LEN 2048 39 | #endif 40 | #define AWS_IOT_MQTT_TX_BUF_LEN 512 ///< Any time a message is sent out through the MQTT layer. The message is copied into this buffer anytime a publish is done. This will also be used in the case of Thing Shadow 41 | #define AWS_IOT_MQTT_NUM_SUBSCRIBE_HANDLERS 5 ///< Maximum number of topic filters the MQTT client can handle at any given time. This should be increased appropriately when using Thing Shadow 42 | 43 | // Shadow and Job common configs 44 | #define MAX_SIZE_OF_UNIQUE_CLIENT_ID_BYTES 80 ///< Maximum size of the Unique Client Id. For More info on the Client Id refer \ref response "Acknowledgments" 45 | #define MAX_SIZE_CLIENT_ID_WITH_SEQUENCE MAX_SIZE_OF_UNIQUE_CLIENT_ID_BYTES + 10 ///< This is size of the extra sequence number that will be appended to the Unique client Id 46 | #define MAX_SIZE_CLIENT_TOKEN_CLIENT_SEQUENCE MAX_SIZE_CLIENT_ID_WITH_SEQUENCE + 20 ///< This is size of the the total clientToken key and value pair in the JSON 47 | #define MAX_SIZE_OF_THING_NAME 30 ///< The Thing Name should not be bigger than this value. Modify this if the Thing Name needs to be bigger 48 | 49 | // Thing Shadow specific configs 50 | #define SHADOW_MAX_SIZE_OF_RX_BUFFER 512 ///< Maximum size of the SHADOW buffer to store the received Shadow message 51 | #define MAX_ACKS_TO_COMEIN_AT_ANY_GIVEN_TIME 10 ///< At Any given time we will wait for this many responses. This will correlate to the rate at which the shadow actions are requested 52 | #define MAX_THINGNAME_HANDLED_AT_ANY_GIVEN_TIME 10 ///< We could perform shadow action on any thing Name and this is maximum Thing Names we can act on at any given time 53 | #define MAX_JSON_TOKEN_EXPECTED 120 ///< These are the max tokens that is expected to be in the Shadow JSON document. Include the metadata that gets published 54 | #define MAX_SHADOW_TOPIC_LENGTH_WITHOUT_THINGNAME 60 ///< All shadow actions have to be published or subscribed to a topic which is of the format $aws/things/{thingName}/shadow/update/accepted. This refers to the size of the topic without the Thing Name 55 | #define MAX_SHADOW_TOPIC_LENGTH_BYTES MAX_SHADOW_TOPIC_LENGTH_WITHOUT_THINGNAME + MAX_SIZE_OF_THING_NAME ///< This size includes the length of topic with Thing Name 56 | 57 | // Job specific configs 58 | #ifndef DISABLE_IOT_JOBS 59 | #define MAX_SIZE_OF_JOB_ID 64 60 | #define MAX_JOB_JSON_TOKEN_EXPECTED 120 61 | #define MAX_SIZE_OF_JOB_REQUEST AWS_IOT_MQTT_TX_BUF_LEN 62 | 63 | #define MAX_JOB_TOPIC_LENGTH_WITHOUT_JOB_ID_OR_THING_NAME 40 64 | #define MAX_JOB_TOPIC_LENGTH_BYTES MAX_JOB_TOPIC_LENGTH_WITHOUT_JOB_ID_OR_THING_NAME + MAX_SIZE_OF_THING_NAME + MAX_SIZE_OF_JOB_ID + 2 65 | #endif 66 | 67 | // Auto Reconnect specific config 68 | #define AWS_IOT_MQTT_MIN_RECONNECT_WAIT_INTERVAL 1000 ///< Minimum time before the First reconnect attempt is made as part of the exponential back-off algorithm 69 | #define AWS_IOT_MQTT_MAX_RECONNECT_WAIT_INTERVAL 128000 ///< Maximum time interval after which exponential back-off will stop attempting to reconnect. 70 | 71 | #define DISABLE_METRICS false ///< Disable the collection of metrics by setting this to true 72 | 73 | #endif /* SRC_JOBS_IOT_JOB_CONFIG_H_ */ 74 | -------------------------------------------------------------------------------- /samples/linux/shadow_sample/Makefile: -------------------------------------------------------------------------------- 1 | #This target is to ensure accidental execution of Makefile as a bash script will not execute commands like rm in unexpected directories and exit gracefully. 2 | .prevent_execution: 3 | exit 0 4 | 5 | CC = gcc 6 | 7 | #remove @ for no make command prints 8 | DEBUG = @ 9 | 10 | APP_DIR = . 11 | APP_INCLUDE_DIRS += -I $(APP_DIR) 12 | APP_NAME = shadow_sample 13 | APP_SRC_FILES = $(APP_NAME).c 14 | 15 | #IoT client directory 16 | IOT_CLIENT_DIR = ../../.. 17 | 18 | PLATFORM_DIR = $(IOT_CLIENT_DIR)/platform/linux/mbedtls 19 | PLATFORM_COMMON_DIR = $(IOT_CLIENT_DIR)/platform/linux/common 20 | 21 | IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/include 22 | IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/external_libs/jsmn 23 | IOT_INCLUDE_DIRS += -I $(PLATFORM_COMMON_DIR) 24 | IOT_INCLUDE_DIRS += -I $(PLATFORM_DIR) 25 | 26 | IOT_SRC_FILES += $(shell find $(IOT_CLIENT_DIR)/src/ -name '*.c') 27 | IOT_SRC_FILES += $(shell find $(IOT_CLIENT_DIR)/external_libs/jsmn -name '*.c') 28 | IOT_SRC_FILES += $(shell find $(PLATFORM_DIR)/ -name '*.c') 29 | IOT_SRC_FILES += $(shell find $(PLATFORM_COMMON_DIR)/ -name '*.c') 30 | 31 | #TLS - mbedtls 32 | MBEDTLS_DIR = $(IOT_CLIENT_DIR)/external_libs/mbedTLS 33 | TLS_LIB_DIR = $(MBEDTLS_DIR)/library 34 | CRYPTO_LIB_DIR = $(MBEDTLS_DIR)/crypto/library 35 | TLS_INCLUDE_DIR = -I $(MBEDTLS_DIR)/include 36 | EXTERNAL_LIBS += -L$(TLS_LIB_DIR) 37 | LD_FLAG += -Wl,-rpath,$(TLS_LIB_DIR) 38 | LD_FLAG += -ldl $(TLS_LIB_DIR)/libmbedtls.a $(CRYPTO_LIB_DIR)/libmbedcrypto.a $(TLS_LIB_DIR)/libmbedx509.a 39 | 40 | 41 | #Aggregate all include and src directories 42 | INCLUDE_ALL_DIRS += $(IOT_INCLUDE_DIRS) 43 | INCLUDE_ALL_DIRS += $(TLS_INCLUDE_DIR) 44 | INCLUDE_ALL_DIRS += $(APP_INCLUDE_DIRS) 45 | 46 | SRC_FILES += $(APP_SRC_FILES) 47 | SRC_FILES += $(IOT_SRC_FILES) 48 | 49 | # Logging level control 50 | LOG_FLAGS += -DENABLE_IOT_DEBUG 51 | LOG_FLAGS += -DENABLE_IOT_INFO 52 | LOG_FLAGS += -DENABLE_IOT_WARN 53 | LOG_FLAGS += -DENABLE_IOT_ERROR 54 | 55 | COMPILER_FLAGS += -g 56 | COMPILER_FLAGS += $(LOG_FLAGS) 57 | #If the processor is big endian uncomment the compiler flag 58 | #COMPILER_FLAGS += -DREVERSED 59 | 60 | MBED_TLS_MAKE_CMD = $(MAKE) -C $(MBEDTLS_DIR) 61 | 62 | PRE_MAKE_CMD = $(MBED_TLS_MAKE_CMD) 63 | MAKE_CMD = $(CC) $(SRC_FILES) $(COMPILER_FLAGS) -o $(APP_NAME) $(LD_FLAG) $(EXTERNAL_LIBS) $(INCLUDE_ALL_DIRS) 64 | 65 | all: 66 | $(PRE_MAKE_CMD) 67 | $(DEBUG)$(MAKE_CMD) 68 | $(POST_MAKE_CMD) 69 | 70 | clean: 71 | rm -f $(APP_DIR)/$(APP_NAME) 72 | $(MBED_TLS_MAKE_CMD) clean 73 | -------------------------------------------------------------------------------- /samples/linux/shadow_sample/aws_iot_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file aws_iot_config.h 18 | * @brief AWS IoT specific configuration file 19 | */ 20 | 21 | #ifndef SRC_SHADOW_IOT_SHADOW_CONFIG_H_ 22 | #define SRC_SHADOW_IOT_SHADOW_CONFIG_H_ 23 | 24 | // Get from console 25 | // ================================================= 26 | #define AWS_IOT_MQTT_HOST "" ///< Customer specific MQTT HOST. The same will be used for Thing Shadow 27 | #define AWS_IOT_MQTT_PORT 443 ///< default port for MQTT/S 28 | #define AWS_IOT_MQTT_CLIENT_ID "c-sdk-client-id" ///< MQTT client ID should be unique for every device 29 | #define AWS_IOT_MY_THING_NAME "AWS-IoT-C-SDK" ///< Thing Name of the Shadow this device is associated with 30 | #define AWS_IOT_ROOT_CA_FILENAME "rootCA.crt" ///< Root CA file name 31 | #define AWS_IOT_CERTIFICATE_FILENAME "cert.pem" ///< device signed certificate file name 32 | #define AWS_IOT_PRIVATE_KEY_FILENAME "privkey.pem" ///< Device private key filename 33 | // ================================================= 34 | 35 | // MQTT PubSub 36 | #define AWS_IOT_MQTT_TX_BUF_LEN 512 ///< Any time a message is sent out through the MQTT layer. The message is copied into this buffer anytime a publish is done. This will also be used in the case of Thing Shadow 37 | #define AWS_IOT_MQTT_RX_BUF_LEN 512 ///< Any message that comes into the device should be less than this buffer size. If a received message is bigger than this buffer size the message will be dropped. 38 | #define AWS_IOT_MQTT_NUM_SUBSCRIBE_HANDLERS 5 ///< Maximum number of topic filters the MQTT client can handle at any given time. This should be increased appropriately when using Thing Shadow 39 | 40 | // Thing Shadow specific configs 41 | #define SHADOW_MAX_SIZE_OF_RX_BUFFER (AWS_IOT_MQTT_RX_BUF_LEN+1) ///< Maximum size of the SHADOW buffer to store the received Shadow message, including terminating NULL byte. 42 | #define MAX_SIZE_OF_UNIQUE_CLIENT_ID_BYTES 80 ///< Maximum size of the Unique Client Id. For More info on the Client Id refer \ref response "Acknowledgments" 43 | #define MAX_SIZE_CLIENT_ID_WITH_SEQUENCE MAX_SIZE_OF_UNIQUE_CLIENT_ID_BYTES + 10 ///< This is size of the extra sequence number that will be appended to the Unique client Id 44 | #define MAX_SIZE_CLIENT_TOKEN_CLIENT_SEQUENCE MAX_SIZE_CLIENT_ID_WITH_SEQUENCE + 20 ///< This is size of the the total clientToken key and value pair in the JSON 45 | #define MAX_ACKS_TO_COMEIN_AT_ANY_GIVEN_TIME 10 ///< At Any given time we will wait for this many responses. This will correlate to the rate at which the shadow actions are requested 46 | #define MAX_THINGNAME_HANDLED_AT_ANY_GIVEN_TIME 10 ///< We could perform shadow action on any thing Name and this is maximum Thing Names we can act on at any given time 47 | #define MAX_JSON_TOKEN_EXPECTED 120 ///< These are the max tokens that is expected to be in the Shadow JSON document. Include the metadata that gets published 48 | #define MAX_SHADOW_TOPIC_LENGTH_WITHOUT_THINGNAME 60 ///< All shadow actions have to be published or subscribed to a topic which is of the format $aws/things/{thingName}/shadow/update/accepted. This refers to the size of the topic without the Thing Name 49 | #define MAX_SIZE_OF_THING_NAME 20 ///< The Thing Name should not be bigger than this value. Modify this if the Thing Name needs to be bigger 50 | #define MAX_SHADOW_TOPIC_LENGTH_BYTES MAX_SHADOW_TOPIC_LENGTH_WITHOUT_THINGNAME + MAX_SIZE_OF_THING_NAME ///< This size includes the length of topic with Thing Name 51 | 52 | // Auto Reconnect specific config 53 | #define AWS_IOT_MQTT_MIN_RECONNECT_WAIT_INTERVAL 1000 ///< Minimum time before the First reconnect attempt is made as part of the exponential back-off algorithm 54 | #define AWS_IOT_MQTT_MAX_RECONNECT_WAIT_INTERVAL 128000 ///< Maximum time interval after which exponential back-off will stop attempting to reconnect. 55 | 56 | #define DISABLE_METRICS false ///< Disable the collection of metrics by setting this to true 57 | 58 | #endif /* SRC_SHADOW_IOT_SHADOW_CONFIG_H_ */ 59 | -------------------------------------------------------------------------------- /samples/linux/shadow_sample_console_echo/Makefile: -------------------------------------------------------------------------------- 1 | #This target is to ensure accidental execution of Makefile as a bash script will not execute commands like rm in unexpected directories and exit gracefully. 2 | .prevent_execution: 3 | exit 0 4 | 5 | CC = gcc 6 | 7 | #remove @ for no make command prints 8 | DEBUG = @ 9 | 10 | APP_DIR = . 11 | APP_INCLUDE_DIRS += -I $(APP_DIR) 12 | APP_NAME = shadow_console_echo 13 | APP_SRC_FILES = $(APP_NAME).c 14 | 15 | #IoT client directory 16 | IOT_CLIENT_DIR = ../../.. 17 | 18 | PLATFORM_DIR = $(IOT_CLIENT_DIR)/platform/linux/mbedtls 19 | PLATFORM_COMMON_DIR = $(IOT_CLIENT_DIR)/platform/linux/common 20 | 21 | IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/include 22 | IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/external_libs/jsmn 23 | IOT_INCLUDE_DIRS += -I $(PLATFORM_COMMON_DIR) 24 | IOT_INCLUDE_DIRS += -I $(PLATFORM_DIR) 25 | 26 | IOT_SRC_FILES += $(shell find $(IOT_CLIENT_DIR)/src/ -name '*.c') 27 | IOT_SRC_FILES += $(shell find $(IOT_CLIENT_DIR)/external_libs/jsmn -name '*.c') 28 | IOT_SRC_FILES += $(shell find $(PLATFORM_DIR)/ -name '*.c') 29 | IOT_SRC_FILES += $(shell find $(PLATFORM_COMMON_DIR)/ -name '*.c') 30 | 31 | #TLS - mbedtls 32 | MBEDTLS_DIR = $(IOT_CLIENT_DIR)/external_libs/mbedTLS 33 | TLS_LIB_DIR = $(MBEDTLS_DIR)/library 34 | CRYPTO_LIB_DIR = $(MBEDTLS_DIR)/crypto/library 35 | TLS_INCLUDE_DIR = -I $(MBEDTLS_DIR)/include 36 | EXTERNAL_LIBS += -L$(TLS_LIB_DIR) 37 | LD_FLAG += -Wl,-rpath,$(TLS_LIB_DIR) 38 | LD_FLAG += -ldl $(TLS_LIB_DIR)/libmbedtls.a $(CRYPTO_LIB_DIR)/libmbedcrypto.a $(TLS_LIB_DIR)/libmbedx509.a 39 | 40 | 41 | #Aggregate all include and src directories 42 | INCLUDE_ALL_DIRS += $(IOT_INCLUDE_DIRS) 43 | INCLUDE_ALL_DIRS += $(MQTT_INCLUDE_DIR) 44 | INCLUDE_ALL_DIRS += $(TLS_INCLUDE_DIR) 45 | INCLUDE_ALL_DIRS += $(APP_INCLUDE_DIRS) 46 | 47 | SRC_FILES += $(MQTT_SRC_FILES) 48 | SRC_FILES += $(APP_SRC_FILES) 49 | SRC_FILES += $(IOT_SRC_FILES) 50 | 51 | # Logging level control 52 | LOG_FLAGS += -DENABLE_IOT_DEBUG 53 | LOG_FLAGS += -DENABLE_IOT_INFO 54 | LOG_FLAGS += -DENABLE_IOT_WARN 55 | LOG_FLAGS += -DENABLE_IOT_ERROR 56 | 57 | COMPILER_FLAGS += -g 58 | COMPILER_FLAGS += $(LOG_FLAGS) 59 | 60 | #If the processor is big endian uncomment the compiler flag 61 | #COMPILER_FLAGS += -DREVERSED 62 | 63 | MBED_TLS_MAKE_CMD = $(MAKE) -C $(MBEDTLS_DIR) 64 | 65 | PRE_MAKE_CMD = $(MBED_TLS_MAKE_CMD) 66 | MAKE_CMD = $(CC) $(SRC_FILES) $(COMPILER_FLAGS) -o $(APP_NAME) $(LD_FLAG) $(EXTERNAL_LIBS) $(INCLUDE_ALL_DIRS) 67 | 68 | all: 69 | $(PRE_MAKE_CMD) 70 | $(DEBUG)$(MAKE_CMD) 71 | $(POST_MAKE_CMD) 72 | 73 | clean: 74 | rm -f $(APP_DIR)/$(APP_NAME) 75 | $(MBED_TLS_MAKE_CMD) clean 76 | -------------------------------------------------------------------------------- /samples/linux/shadow_sample_console_echo/aws_iot_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file aws_iot_config.h 18 | * @brief AWS IoT specific configuration file 19 | */ 20 | 21 | #ifndef SRC_SHADOW_IOT_SHADOW_CONFIG_H_ 22 | #define SRC_SHADOW_IOT_SHADOW_CONFIG_H_ 23 | 24 | // Get from console 25 | // ================================================= 26 | #define AWS_IOT_MQTT_HOST "" ///< Customer specific MQTT HOST. The same will be used for Thing Shadow 27 | #define AWS_IOT_MQTT_PORT 443 ///< default port for MQTT/S 28 | #define AWS_IOT_MQTT_CLIENT_ID "c-sdk-client-id" ///< MQTT client ID should be unique for every device 29 | #define AWS_IOT_MY_THING_NAME "AWS-IoT-C-SDK" ///< Thing Name of the Shadow this device is associated with 30 | #define AWS_IOT_ROOT_CA_FILENAME "rootCA.crt" ///< Root CA file name 31 | #define AWS_IOT_CERTIFICATE_FILENAME "cert.pem" ///< device signed certificate file name 32 | #define AWS_IOT_PRIVATE_KEY_FILENAME "privkey.pem" ///< Device private key filename 33 | // ================================================= 34 | 35 | // MQTT PubSub 36 | #define AWS_IOT_MQTT_TX_BUF_LEN 512 ///< Any time a message is sent out through the MQTT layer. The message is copied into this buffer anytime a publish is done. This will also be used in the case of Thing Shadow 37 | #define AWS_IOT_MQTT_RX_BUF_LEN 512 ///< Any message that comes into the device should be less than this buffer size. If a received message is bigger than this buffer size the message will be dropped. 38 | #define AWS_IOT_MQTT_NUM_SUBSCRIBE_HANDLERS 5 ///< Maximum number of topic filters the MQTT client can handle at any given time. This should be increased appropriately when using Thing Shadow 39 | 40 | // Thing Shadow specific configs 41 | #define SHADOW_MAX_SIZE_OF_RX_BUFFER (AWS_IOT_MQTT_RX_BUF_LEN+1) ///< Maximum size of the SHADOW buffer to store the received Shadow message, including terminating NULL byte. 42 | #define MAX_SIZE_OF_UNIQUE_CLIENT_ID_BYTES 80 ///< Maximum size of the Unique Client Id. For More info on the Client Id refer \ref response "Acknowledgments" 43 | #define MAX_SIZE_CLIENT_ID_WITH_SEQUENCE MAX_SIZE_OF_UNIQUE_CLIENT_ID_BYTES + 10 ///< This is size of the extra sequence number that will be appended to the Unique client Id 44 | #define MAX_SIZE_CLIENT_TOKEN_CLIENT_SEQUENCE MAX_SIZE_CLIENT_ID_WITH_SEQUENCE + 20 ///< This is size of the the total clientToken key and value pair in the JSON 45 | #define MAX_ACKS_TO_COMEIN_AT_ANY_GIVEN_TIME 10 ///< At Any given time we will wait for this many responses. This will correlate to the rate at which the shadow actions are requested 46 | #define MAX_THINGNAME_HANDLED_AT_ANY_GIVEN_TIME 10 ///< We could perform shadow action on any thing Name and this is maximum Thing Names we can act on at any given time 47 | #define MAX_JSON_TOKEN_EXPECTED 120 ///< These are the max tokens that is expected to be in the Shadow JSON document. Include the metadata that gets published 48 | #define MAX_SHADOW_TOPIC_LENGTH_WITHOUT_THINGNAME 60 ///< All shadow actions have to be published or subscribed to a topic which is of the format $aws/things/{thingName}/shadow/update/accepted. This refers to the size of the topic without the Thing Name 49 | #define MAX_SIZE_OF_THING_NAME 20 ///< The Thing Name should not be bigger than this value. Modify this if the Thing Name needs to be bigger 50 | #define MAX_SHADOW_TOPIC_LENGTH_BYTES MAX_SHADOW_TOPIC_LENGTH_WITHOUT_THINGNAME + MAX_SIZE_OF_THING_NAME ///< This size includes the length of topic with Thing Name 51 | 52 | // Auto Reconnect specific config 53 | #define AWS_IOT_MQTT_MIN_RECONNECT_WAIT_INTERVAL 1000 ///< Minimum time before the First reconnect attempt is made as part of the exponential back-off algorithm 54 | #define AWS_IOT_MQTT_MAX_RECONNECT_WAIT_INTERVAL 128000 ///< Maximum time interval after which exponential back-off will stop attempting to reconnect. 55 | 56 | #define DISABLE_METRICS false ///< Disable the collection of metrics by setting this to true 57 | 58 | #endif /* SRC_SHADOW_IOT_SHADOW_CONFIG_H_ */ 59 | -------------------------------------------------------------------------------- /samples/linux/subscribe_publish_library_sample/Makefile: -------------------------------------------------------------------------------- 1 | #This target is to ensure accidental execution of Makefile as a bash script will not execute commands like rm in unexpected directories and exit gracefully. 2 | .prevent_execution: 3 | exit 0 4 | 5 | CC = gcc 6 | 7 | #remove @ for no make command prints 8 | DEBUG = @ 9 | 10 | APP_DIR = . 11 | APP_INCLUDE_DIRS += -I $(APP_DIR) 12 | APP_NAME = subscribe_publish_library_sample 13 | APP_SRC_FILES = $(APP_NAME).c 14 | 15 | #IoT client directory 16 | IOT_CLIENT_DIR = ../../.. 17 | 18 | PLATFORM_DIR = $(IOT_CLIENT_DIR)/platform/linux/mbedtls 19 | PLATFORM_COMMON_DIR = $(IOT_CLIENT_DIR)/platform/linux/common 20 | 21 | IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/include 22 | IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/external_libs/jsmn 23 | IOT_INCLUDE_DIRS += -I $(PLATFORM_COMMON_DIR) 24 | IOT_INCLUDE_DIRS += -I $(PLATFORM_DIR) 25 | 26 | IOT_SRC_FILES += $(shell find $(IOT_CLIENT_DIR)/src/ -name '*.c') 27 | IOT_SRC_FILES += $(shell find $(IOT_CLIENT_DIR)/external_libs/jsmn -name '*.c') 28 | IOT_SRC_FILES += $(shell find $(PLATFORM_DIR)/ -name '*.c') 29 | IOT_SRC_FILES += $(shell find $(PLATFORM_COMMON_DIR)/ -name '*.c') 30 | 31 | #TLS - mbedtls 32 | MBEDTLS_DIR = $(IOT_CLIENT_DIR)/external_libs/mbedTLS 33 | TLS_LIB_DIR = $(MBEDTLS_DIR)/library 34 | CRYPTO_LIB_DIR = $(MBEDTLS_DIR)/crypto/library 35 | TLS_INCLUDE_DIR = -I $(MBEDTLS_DIR)/include 36 | EXTERNAL_LIBS += -L$(TLS_LIB_DIR) 37 | LD_FLAG += -Wl,-rpath,$(TLS_LIB_DIR) 38 | LD_FLAG += -ldl $(TLS_LIB_DIR)/libmbedtls.a $(CRYPTO_LIB_DIR)/libmbedcrypto.a $(TLS_LIB_DIR)/libmbedx509.a -lpthread 39 | 40 | #Aggregate all include and src directories 41 | INCLUDE_ALL_DIRS += $(IOT_INCLUDE_DIRS) 42 | INCLUDE_ALL_DIRS += $(TLS_INCLUDE_DIR) 43 | INCLUDE_ALL_DIRS += $(APP_INCLUDE_DIRS) 44 | 45 | SRC_FILES += $(IOT_SRC_FILES) 46 | 47 | # Logging level control 48 | LOG_FLAGS += -DENABLE_IOT_DEBUG 49 | LOG_FLAGS += -DENABLE_IOT_INFO 50 | LOG_FLAGS += -DENABLE_IOT_WARN 51 | LOG_FLAGS += -DENABLE_IOT_ERROR 52 | 53 | COMPILER_FLAGS += $(LOG_FLAGS) 54 | #If the processor is big endian uncomment the compiler flag 55 | #COMPILER_FLAGS += -DREVERSED 56 | 57 | MBED_TLS_MAKE_CMD = $(MAKE) -C $(MBEDTLS_DIR) 58 | 59 | PRE_MAKE_CMD = $(MBED_TLS_MAKE_CMD) 60 | MAKE_CMD = $(CC) $(APP_NAME).c $(COMPILER_FLAGS) -o $(APP_NAME) -L. -lAwsIotSdk $(LD_FLAG) $(INCLUDE_ALL_DIRS) 61 | 62 | all: libAwsIotSdk.a 63 | $(PRE_MAKE_CMD) 64 | $(DEBUG)$(MAKE_CMD) 65 | $(POST_MAKE_CMD) 66 | 67 | libAwsIotSdk.a: $(SRC_FILES:.c=.o) 68 | ar rcs $@ $^ 69 | 70 | %.o : %.c 71 | $(CC) -c $< -o $@ $(COMPILER_FLAGS) $(EXTERNAL_LIBS) $(INCLUDE_ALL_DIRS) 72 | 73 | clean: 74 | rm -f $(APP_DIR)/$(APP_NAME) 75 | rm -f $(APP_DIR)/libAwsIotSdk.a 76 | $(MBED_TLS_MAKE_CMD) clean 77 | -------------------------------------------------------------------------------- /samples/linux/subscribe_publish_library_sample/aws_iot_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file aws_iot_config.h 18 | * @brief AWS IoT specific configuration file 19 | */ 20 | 21 | #ifndef SRC_SHADOW_IOT_SHADOW_CONFIG_H_ 22 | #define SRC_SHADOW_IOT_SHADOW_CONFIG_H_ 23 | 24 | // Get from console 25 | // ================================================= 26 | #define AWS_IOT_MQTT_HOST "" ///< Customer specific MQTT HOST. The same will be used for Thing Shadow 27 | #define AWS_IOT_MQTT_PORT 443 ///< default port for MQTT/S 28 | #define AWS_IOT_MQTT_CLIENT_ID "c-sdk-client-id" ///< MQTT client ID should be unique for every device 29 | #define AWS_IOT_MY_THING_NAME "AWS-IoT-C-SDK" ///< Thing Name of the Shadow this device is associated with 30 | #define AWS_IOT_ROOT_CA_FILENAME "rootCA.crt" ///< Root CA file name 31 | #define AWS_IOT_CERTIFICATE_FILENAME "cert.pem" ///< device signed certificate file name 32 | #define AWS_IOT_PRIVATE_KEY_FILENAME "privkey.pem" ///< Device private key filename 33 | // ================================================= 34 | 35 | // MQTT PubSub 36 | #define AWS_IOT_MQTT_TX_BUF_LEN 512 ///< Any time a message is sent out through the MQTT layer. The message is copied into this buffer anytime a publish is done. This will also be used in the case of Thing Shadow 37 | #define AWS_IOT_MQTT_RX_BUF_LEN 512 ///< Any message that comes into the device should be less than this buffer size. If a received message is bigger than this buffer size the message will be dropped. 38 | #define AWS_IOT_MQTT_NUM_SUBSCRIBE_HANDLERS 5 ///< Maximum number of topic filters the MQTT client can handle at any given time. This should be increased appropriately when using Thing Shadow 39 | 40 | // Thing Shadow specific configs 41 | #define SHADOW_MAX_SIZE_OF_RX_BUFFER (AWS_IOT_MQTT_RX_BUF_LEN+1) ///< Maximum size of the SHADOW buffer to store the received Shadow message, including terminating NULL byte. 42 | #define MAX_SIZE_OF_UNIQUE_CLIENT_ID_BYTES 80 ///< Maximum size of the Unique Client Id. For More info on the Client Id refer \ref response "Acknowledgments" 43 | #define MAX_SIZE_CLIENT_ID_WITH_SEQUENCE MAX_SIZE_OF_UNIQUE_CLIENT_ID_BYTES + 10 ///< This is size of the extra sequence number that will be appended to the Unique client Id 44 | #define MAX_SIZE_CLIENT_TOKEN_CLIENT_SEQUENCE MAX_SIZE_CLIENT_ID_WITH_SEQUENCE + 20 ///< This is size of the the total clientToken key and value pair in the JSON 45 | #define MAX_ACKS_TO_COMEIN_AT_ANY_GIVEN_TIME 10 ///< At Any given time we will wait for this many responses. This will correlate to the rate at which the shadow actions are requested 46 | #define MAX_THINGNAME_HANDLED_AT_ANY_GIVEN_TIME 10 ///< We could perform shadow action on any thing Name and this is maximum Thing Names we can act on at any given time 47 | #define MAX_JSON_TOKEN_EXPECTED 120 ///< These are the max tokens that is expected to be in the Shadow JSON document. Include the metadata that gets published 48 | #define MAX_SHADOW_TOPIC_LENGTH_WITHOUT_THINGNAME 60 ///< All shadow actions have to be published or subscribed to a topic which is of the format $aws/things/{thingName}/shadow/update/accepted. This refers to the size of the topic without the Thing Name 49 | #define MAX_SIZE_OF_THING_NAME 20 ///< The Thing Name should not be bigger than this value. Modify this if the Thing Name needs to be bigger 50 | #define MAX_SHADOW_TOPIC_LENGTH_BYTES MAX_SHADOW_TOPIC_LENGTH_WITHOUT_THINGNAME + MAX_SIZE_OF_THING_NAME ///< This size includes the length of topic with Thing Name 51 | 52 | // Auto Reconnect specific config 53 | #define AWS_IOT_MQTT_MIN_RECONNECT_WAIT_INTERVAL 1000 ///< Minimum time before the First reconnect attempt is made as part of the exponential back-off algorithm 54 | #define AWS_IOT_MQTT_MAX_RECONNECT_WAIT_INTERVAL 128000 ///< Maximum time interval after which exponential back-off will stop attempting to reconnect. 55 | 56 | #define DISABLE_METRICS false ///< Disable the collection of metrics by setting this to true 57 | 58 | #endif /* SRC_SHADOW_IOT_SHADOW_CONFIG_H_ */ 59 | -------------------------------------------------------------------------------- /samples/linux/subscribe_publish_sample/Makefile: -------------------------------------------------------------------------------- 1 | #This target is to ensure accidental execution of Makefile as a bash script will not execute commands like rm in unexpected directories and exit gracefully. 2 | .prevent_execution: 3 | exit 0 4 | 5 | CC = gcc 6 | 7 | #remove @ for no make command prints 8 | DEBUG = @ 9 | 10 | APP_DIR = . 11 | APP_INCLUDE_DIRS += -I $(APP_DIR) 12 | APP_NAME = subscribe_publish_sample 13 | APP_SRC_FILES = $(APP_NAME).c 14 | 15 | #IoT client directory 16 | IOT_CLIENT_DIR = ../../.. 17 | 18 | PLATFORM_DIR = $(IOT_CLIENT_DIR)/platform/linux/mbedtls 19 | PLATFORM_COMMON_DIR = $(IOT_CLIENT_DIR)/platform/linux/common 20 | 21 | IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/include 22 | IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/external_libs/jsmn 23 | IOT_INCLUDE_DIRS += -I $(PLATFORM_COMMON_DIR) 24 | IOT_INCLUDE_DIRS += -I $(PLATFORM_DIR) 25 | 26 | IOT_SRC_FILES += $(shell find $(IOT_CLIENT_DIR)/src/ -name '*.c') 27 | IOT_SRC_FILES += $(shell find $(IOT_CLIENT_DIR)/external_libs/jsmn -name '*.c') 28 | IOT_SRC_FILES += $(shell find $(PLATFORM_DIR)/ -name '*.c') 29 | IOT_SRC_FILES += $(shell find $(PLATFORM_COMMON_DIR)/ -name '*.c') 30 | 31 | #TLS - mbedtls 32 | MBEDTLS_DIR = $(IOT_CLIENT_DIR)/external_libs/mbedTLS 33 | TLS_LIB_DIR = $(MBEDTLS_DIR)/library 34 | CRYPTO_LIB_DIR = $(MBEDTLS_DIR)/crypto/library 35 | TLS_INCLUDE_DIR = -I $(MBEDTLS_DIR)/include 36 | EXTERNAL_LIBS += -L$(TLS_LIB_DIR) 37 | LD_FLAG += -Wl,-rpath,$(TLS_LIB_DIR) 38 | LD_FLAG += -ldl $(TLS_LIB_DIR)/libmbedtls.a $(CRYPTO_LIB_DIR)/libmbedcrypto.a $(TLS_LIB_DIR)/libmbedx509.a -lpthread 39 | 40 | #Aggregate all include and src directories 41 | INCLUDE_ALL_DIRS += $(IOT_INCLUDE_DIRS) 42 | INCLUDE_ALL_DIRS += $(TLS_INCLUDE_DIR) 43 | INCLUDE_ALL_DIRS += $(APP_INCLUDE_DIRS) 44 | 45 | SRC_FILES += $(APP_SRC_FILES) 46 | SRC_FILES += $(IOT_SRC_FILES) 47 | 48 | # Logging level control 49 | LOG_FLAGS += -DENABLE_IOT_DEBUG 50 | LOG_FLAGS += -DENABLE_IOT_INFO 51 | LOG_FLAGS += -DENABLE_IOT_WARN 52 | LOG_FLAGS += -DENABLE_IOT_ERROR 53 | 54 | COMPILER_FLAGS += $(LOG_FLAGS) 55 | #If the processor is big endian uncomment the compiler flag 56 | #COMPILER_FLAGS += -DREVERSED 57 | 58 | MBED_TLS_MAKE_CMD = $(MAKE) -C $(MBEDTLS_DIR) 59 | 60 | PRE_MAKE_CMD = $(MBED_TLS_MAKE_CMD) 61 | MAKE_CMD = $(CC) $(SRC_FILES) $(COMPILER_FLAGS) -o $(APP_NAME) $(LD_FLAG) $(EXTERNAL_LIBS) $(INCLUDE_ALL_DIRS) 62 | 63 | all: 64 | $(PRE_MAKE_CMD) 65 | $(DEBUG)$(MAKE_CMD) 66 | $(POST_MAKE_CMD) 67 | 68 | clean: 69 | rm -f $(APP_DIR)/$(APP_NAME) 70 | $(MBED_TLS_MAKE_CMD) clean 71 | -------------------------------------------------------------------------------- /samples/linux/subscribe_publish_sample/aws_iot_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file aws_iot_config.h 18 | * @brief AWS IoT specific configuration file 19 | */ 20 | 21 | #ifndef SRC_SHADOW_IOT_SHADOW_CONFIG_H_ 22 | #define SRC_SHADOW_IOT_SHADOW_CONFIG_H_ 23 | 24 | // Get from console 25 | // ================================================= 26 | #define AWS_IOT_MQTT_HOST "" ///< Customer specific MQTT HOST. The same will be used for Thing Shadow 27 | #define AWS_IOT_MQTT_PORT 443 ///< default port for MQTT/S 28 | #define AWS_IOT_MQTT_CLIENT_ID "c-sdk-client-id" ///< MQTT client ID should be unique for every device 29 | #define AWS_IOT_MY_THING_NAME "AWS-IoT-C-SDK" ///< Thing Name of the Shadow this device is associated with 30 | #define AWS_IOT_ROOT_CA_FILENAME "rootCA.crt" ///< Root CA file name 31 | #define AWS_IOT_CERTIFICATE_FILENAME "cert.pem" ///< device signed certificate file name 32 | #define AWS_IOT_PRIVATE_KEY_FILENAME "privkey.pem" ///< Device private key filename 33 | // ================================================= 34 | 35 | // MQTT PubSub 36 | #define AWS_IOT_MQTT_TX_BUF_LEN 512 ///< Any time a message is sent out through the MQTT layer. The message is copied into this buffer anytime a publish is done. This will also be used in the case of Thing Shadow 37 | #define AWS_IOT_MQTT_RX_BUF_LEN 512 ///< Any message that comes into the device should be less than this buffer size. If a received message is bigger than this buffer size the message will be dropped. 38 | #define AWS_IOT_MQTT_NUM_SUBSCRIBE_HANDLERS 5 ///< Maximum number of topic filters the MQTT client can handle at any given time. This should be increased appropriately when using Thing Shadow 39 | 40 | // Thing Shadow specific configs 41 | #define SHADOW_MAX_SIZE_OF_RX_BUFFER (AWS_IOT_MQTT_RX_BUF_LEN+1) ///< Maximum size of the SHADOW buffer to store the received Shadow message, including terminating NULL byte. 42 | #define MAX_SIZE_OF_UNIQUE_CLIENT_ID_BYTES 80 ///< Maximum size of the Unique Client Id. For More info on the Client Id refer \ref response "Acknowledgments" 43 | #define MAX_SIZE_CLIENT_ID_WITH_SEQUENCE MAX_SIZE_OF_UNIQUE_CLIENT_ID_BYTES + 10 ///< This is size of the extra sequence number that will be appended to the Unique client Id 44 | #define MAX_SIZE_CLIENT_TOKEN_CLIENT_SEQUENCE MAX_SIZE_CLIENT_ID_WITH_SEQUENCE + 20 ///< This is size of the the total clientToken key and value pair in the JSON 45 | #define MAX_ACKS_TO_COMEIN_AT_ANY_GIVEN_TIME 10 ///< At Any given time we will wait for this many responses. This will correlate to the rate at which the shadow actions are requested 46 | #define MAX_THINGNAME_HANDLED_AT_ANY_GIVEN_TIME 10 ///< We could perform shadow action on any thing Name and this is maximum Thing Names we can act on at any given time 47 | #define MAX_JSON_TOKEN_EXPECTED 120 ///< These are the max tokens that is expected to be in the Shadow JSON document. Include the metadata that gets published 48 | #define MAX_SHADOW_TOPIC_LENGTH_WITHOUT_THINGNAME 60 ///< All shadow actions have to be published or subscribed to a topic which is of the format $aws/things/{thingName}/shadow/update/accepted. This refers to the size of the topic without the Thing Name 49 | #define MAX_SIZE_OF_THING_NAME 20 ///< The Thing Name should not be bigger than this value. Modify this if the Thing Name needs to be bigger 50 | #define MAX_SHADOW_TOPIC_LENGTH_BYTES MAX_SHADOW_TOPIC_LENGTH_WITHOUT_THINGNAME + MAX_SIZE_OF_THING_NAME ///< This size includes the length of topic with Thing Name 51 | 52 | // Auto Reconnect specific config 53 | #define AWS_IOT_MQTT_MIN_RECONNECT_WAIT_INTERVAL 1000 ///< Minimum time before the First reconnect attempt is made as part of the exponential back-off algorithm 54 | #define AWS_IOT_MQTT_MAX_RECONNECT_WAIT_INTERVAL 128000 ///< Maximum time interval after which exponential back-off will stop attempting to reconnect. 55 | 56 | #define DISABLE_METRICS false ///< Disable the collection of metrics by setting this to true 57 | 58 | #endif /* SRC_SHADOW_IOT_SHADOW_CONFIG_H_ */ 59 | -------------------------------------------------------------------------------- /src/aws_iot_jobs_topics.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | #include "aws_iot_jobs_topics.h" 21 | #include 22 | #include 23 | #include 24 | 25 | #define BASE_THINGS_TOPIC "$aws/things/" 26 | 27 | #define NOTIFY_OPERATION "notify" 28 | #define NOTIFY_NEXT_OPERATION "notify-next" 29 | #define GET_OPERATION "get" 30 | #define START_NEXT_OPERATION "start-next" 31 | #define WILDCARD_OPERATION "+" 32 | #define UPDATE_OPERATION "update" 33 | #define ACCEPTED_REPLY "accepted" 34 | #define REJECTED_REPLY "rejected" 35 | #define WILDCARD_REPLY "+" 36 | 37 | static const char *_get_operation_for_base_topic(AwsIotJobExecutionTopicType topicType) { 38 | switch (topicType) { 39 | case JOB_UPDATE_TOPIC: 40 | return UPDATE_OPERATION; 41 | case JOB_NOTIFY_TOPIC: 42 | return NOTIFY_OPERATION; 43 | case JOB_NOTIFY_NEXT_TOPIC: 44 | return NOTIFY_NEXT_OPERATION; 45 | case JOB_GET_PENDING_TOPIC: 46 | case JOB_DESCRIBE_TOPIC: 47 | return GET_OPERATION; 48 | case JOB_START_NEXT_TOPIC: 49 | return START_NEXT_OPERATION; 50 | case JOB_WILDCARD_TOPIC: 51 | return WILDCARD_OPERATION; 52 | case JOB_UNRECOGNIZED_TOPIC: 53 | default: 54 | return NULL; 55 | } 56 | } 57 | 58 | static bool _base_topic_requires_job_id(AwsIotJobExecutionTopicType topicType) { 59 | switch (topicType) { 60 | case JOB_UPDATE_TOPIC: 61 | case JOB_DESCRIBE_TOPIC: 62 | return true; 63 | case JOB_NOTIFY_TOPIC: 64 | case JOB_NOTIFY_NEXT_TOPIC: 65 | case JOB_START_NEXT_TOPIC: 66 | case JOB_GET_PENDING_TOPIC: 67 | case JOB_WILDCARD_TOPIC: 68 | case JOB_UNRECOGNIZED_TOPIC: 69 | default: 70 | return false; 71 | } 72 | } 73 | 74 | static const char *_get_suffix_for_topic_type(AwsIotJobExecutionTopicReplyType replyType) { 75 | switch (replyType) { 76 | case JOB_REQUEST_TYPE: 77 | return ""; 78 | break; 79 | case JOB_ACCEPTED_REPLY_TYPE: 80 | return "/" ACCEPTED_REPLY; 81 | break; 82 | case JOB_REJECTED_REPLY_TYPE: 83 | return "/" REJECTED_REPLY; 84 | break; 85 | case JOB_WILDCARD_REPLY_TYPE: 86 | return "/" WILDCARD_REPLY; 87 | break; 88 | case JOB_UNRECOGNIZED_TOPIC_TYPE: 89 | default: 90 | return NULL; 91 | } 92 | } 93 | 94 | int aws_iot_jobs_get_api_topic(char *buffer, size_t bufferSize, 95 | AwsIotJobExecutionTopicType topicType, AwsIotJobExecutionTopicReplyType replyType, 96 | const char* thingName, const char* jobId) 97 | { 98 | if (thingName == NULL) { 99 | return -1; 100 | } 101 | 102 | if ((topicType == JOB_NOTIFY_TOPIC || topicType == JOB_NOTIFY_NEXT_TOPIC) && replyType != JOB_REQUEST_TYPE) { 103 | return -1; 104 | } 105 | 106 | bool requireJobId = _base_topic_requires_job_id(topicType); 107 | if (jobId == NULL && requireJobId) { 108 | return -1; 109 | } 110 | 111 | const char *operation = _get_operation_for_base_topic(topicType); 112 | if (operation == NULL) { 113 | return -1; 114 | } 115 | 116 | const char *suffix = _get_suffix_for_topic_type(replyType); 117 | 118 | if (requireJobId || (topicType == JOB_WILDCARD_TOPIC && jobId != NULL)) { 119 | return snprintf(buffer, bufferSize, BASE_THINGS_TOPIC "%s/jobs/%s/%s%s", thingName, jobId, operation, suffix); 120 | } else if (topicType == JOB_WILDCARD_TOPIC) { 121 | return snprintf(buffer, bufferSize, BASE_THINGS_TOPIC "%s/jobs/#", thingName); 122 | } else { 123 | return snprintf(buffer, bufferSize, BASE_THINGS_TOPIC "%s/jobs/%s%s", thingName, operation, suffix); 124 | } 125 | } 126 | 127 | #ifdef __cplusplus 128 | } 129 | #endif 130 | -------------------------------------------------------------------------------- /src/aws_iot_jobs_types.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | #include 21 | #include "aws_iot_jobs_types.h" 22 | 23 | const char *JOB_EXECUTION_QUEUED_STR = "QUEUED"; 24 | const char *JOB_EXECUTION_IN_PROGRESS_STR = "IN_PROGRESS"; 25 | const char *JOB_EXECUTION_FAILED_STR = "FAILED"; 26 | const char *JOB_EXECUTION_SUCCEEDED_STR = "SUCCEEDED"; 27 | const char *JOB_EXECUTION_CANCELED_STR = "CANCELED"; 28 | const char *JOB_EXECUTION_REJECTED_STR = "REJECTED"; 29 | 30 | JobExecutionStatus aws_iot_jobs_map_string_to_job_status(const char *str) { 31 | if (str == NULL || str[0] == '\0') { 32 | return JOB_EXECUTION_STATUS_NOT_SET; 33 | } else if (strcmp(str, JOB_EXECUTION_QUEUED_STR) == 0) { 34 | return JOB_EXECUTION_QUEUED; 35 | } else if(strcmp(str, JOB_EXECUTION_IN_PROGRESS_STR) == 0) { 36 | return JOB_EXECUTION_IN_PROGRESS; 37 | } else if(strcmp(str, JOB_EXECUTION_FAILED_STR) == 0) { 38 | return JOB_EXECUTION_FAILED; 39 | } else if(strcmp(str, JOB_EXECUTION_SUCCEEDED_STR) == 0) { 40 | return JOB_EXECUTION_SUCCEEDED; 41 | } else if(strcmp(str, JOB_EXECUTION_CANCELED_STR) == 0) { 42 | return JOB_EXECUTION_CANCELED; 43 | } else if(strcmp(str, JOB_EXECUTION_REJECTED_STR) == 0) { 44 | return JOB_EXECUTION_REJECTED; 45 | } else { 46 | return JOB_EXECUTION_UNKNOWN_STATUS; 47 | } 48 | } 49 | 50 | const char *aws_iot_jobs_map_status_to_string(JobExecutionStatus status) { 51 | switch(status) { 52 | case JOB_EXECUTION_QUEUED: 53 | return JOB_EXECUTION_QUEUED_STR; 54 | case JOB_EXECUTION_IN_PROGRESS: 55 | return JOB_EXECUTION_IN_PROGRESS_STR; 56 | case JOB_EXECUTION_FAILED: 57 | return JOB_EXECUTION_FAILED_STR; 58 | case JOB_EXECUTION_SUCCEEDED: 59 | return JOB_EXECUTION_SUCCEEDED_STR; 60 | case JOB_EXECUTION_CANCELED: 61 | return JOB_EXECUTION_CANCELED_STR; 62 | case JOB_EXECUTION_REJECTED: 63 | return JOB_EXECUTION_REJECTED_STR; 64 | case JOB_EXECUTION_STATUS_NOT_SET: 65 | case JOB_EXECUTION_UNKNOWN_STATUS: 66 | default: 67 | return NULL; 68 | } 69 | } 70 | 71 | #ifdef __cplusplus 72 | } 73 | #endif 74 | -------------------------------------------------------------------------------- /src/aws_iot_shadow_actions.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file aws_iot_shadow_actions.c 18 | * @brief Shadow client Action API definitions 19 | */ 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | #include "aws_iot_shadow_actions.h" 26 | 27 | #include "aws_iot_log.h" 28 | #include "aws_iot_shadow_json.h" 29 | #include "aws_iot_shadow_records.h" 30 | #include "aws_iot_config.h" 31 | 32 | IoT_Error_t aws_iot_shadow_internal_action(const char *pThingName, ShadowActions_t action, 33 | const char *pJsonDocumentToBeSent, size_t jsonSize, fpActionCallback_t callback, 34 | void *pCallbackContext, uint32_t timeout_seconds, bool isSticky) { 35 | IoT_Error_t ret_val = SUCCESS; 36 | bool isClientTokenPresent = false; 37 | bool isAckWaitListFree = false; 38 | uint8_t indexAckWaitList; 39 | char extractedClientToken[MAX_SIZE_CLIENT_ID_WITH_SEQUENCE]; 40 | 41 | FUNC_ENTRY; 42 | 43 | if(NULL == pThingName || NULL == pJsonDocumentToBeSent) { 44 | FUNC_EXIT_RC(NULL_VALUE_ERROR); 45 | } 46 | 47 | isClientTokenPresent = extractClientToken(pJsonDocumentToBeSent, jsonSize, extractedClientToken, MAX_SIZE_CLIENT_ID_WITH_SEQUENCE ); 48 | 49 | if(isClientTokenPresent && (NULL != callback)) { 50 | if(getNextFreeIndexOfAckWaitList(&indexAckWaitList)) { 51 | isAckWaitListFree = true; 52 | } 53 | 54 | if(isAckWaitListFree) { 55 | if(!isSubscriptionPresent(pThingName, action)) { 56 | ret_val = subscribeToShadowActionAcks(pThingName, action, isSticky); 57 | } else { 58 | incrementSubscriptionCnt(pThingName, action, isSticky); 59 | } 60 | } 61 | else { 62 | ret_val = FAILURE; 63 | } 64 | } 65 | 66 | if(SUCCESS == ret_val) { 67 | ret_val = publishToShadowAction(pThingName, action, pJsonDocumentToBeSent); 68 | } 69 | 70 | if(isClientTokenPresent && (NULL != callback) && (SUCCESS == ret_val) && isAckWaitListFree) { 71 | addToAckWaitList(indexAckWaitList, pThingName, action, extractedClientToken, callback, pCallbackContext, 72 | timeout_seconds); 73 | } 74 | 75 | FUNC_EXIT_RC(ret_val); 76 | } 77 | 78 | #ifdef __cplusplus 79 | } 80 | #endif 81 | -------------------------------------------------------------------------------- /tests/README.md: -------------------------------------------------------------------------------- 1 | # Tests 2 | This folder contains tests to verify SDK functionality. These have been tested to work with Linux but haven't been ported to any specific platform. For additional information about porting the Device SDK for embedded C onto additional platforms please refer to the [PortingGuide](https://github.com/aws/aws-iot-device-sdk-embedded-c/blob/master/PortingGuide.md/). 3 | A description for each folder is given below 4 | 5 | ## integration 6 | This folder contains integration tests that run directly against the server. For further information on how to run these tests check out the [Integration Test README](https://github.com/aws/aws-iot-device-sdk-embedded-c/blob/master/tests/integration/README.md/). 7 | 8 | ## unit 9 | This folder contains unit tests that test SDK functionality against a Mock TLS layer. They are built using the CppUTest testing framework. For further information on how to run these tests check out the [Unit Test README](https://github.com/aws/aws-iot-device-sdk-embedded-c/blob/master/tests/unit/README.md/). -------------------------------------------------------------------------------- /tests/integration/Makefile: -------------------------------------------------------------------------------- 1 | #This target is to ensure accidental execution of Makefile as a bash script will not execute commands like rm in unexpected directories and exit gracefully. 2 | .prevent_execution: 3 | exit 0 4 | 5 | ifeq ($(origin CC),default) 6 | CC = gcc 7 | endif 8 | RM = rm 9 | 10 | DEBUG = 11 | 12 | #IoT client directory 13 | IOT_CLIENT_DIR = ../.. 14 | 15 | #Use MbedTLS as default tls adapter. 16 | TLS_ADAPTER ?= mbedtls 17 | VALID_TLS_ADAPTER := mbedtls openssl 18 | ifneq ($(filter $(TLS_ADAPTER),$(VALID_TLS_ADAPTER)),) 19 | $(info TLS_ADAPTER=$(TLS_ADAPTER)) 20 | else 21 | $(error invalid TLS_ADAPTER value) 22 | endif 23 | 24 | APP_DIR = $(IOT_CLIENT_DIR)/tests/integration 25 | APP_NAME = integration_tests_$(TLS_ADAPTER) 26 | MT_APP_NAME = integration_tests_$(TLS_ADAPTER)_mt 27 | APP_SRC_FILES = $(shell find $(APP_DIR)/src/ -name '*.c') 28 | MT_APP_SRC_FILES = $(shell find $(APP_DIR)/multithreadingTest/ -name '*.c') 29 | APP_INCLUDE_DIRS = -I $(APP_DIR)/include 30 | 31 | PLATFORM_DIR = $(IOT_CLIENT_DIR)/platform/linux 32 | 33 | STATIC_LIBS = 34 | 35 | ifeq ($(TLS_ADAPTER),mbedtls) 36 | #MbedTLS directory 37 | TEMP_MBEDTLS_SRC_DIR = $(IOT_CLIENT_DIR)/external_libs/mbedTLS 38 | TLS_LIB_DIR = $(TEMP_MBEDTLS_SRC_DIR)/library 39 | CRYPTO_LIB_DIR = $(TEMP_MBEDTLS_SRC_DIR)/crypto/library 40 | TLS_INCLUDE_DIR = -I $(TEMP_MBEDTLS_SRC_DIR)/include 41 | EXTERNAL_LIBS += -L$(TLS_LIB_DIR) 42 | STATIC_LIBS += $(TLS_LIB_DIR)/libmbedtls.a $(CRYPTO_LIB_DIR)/libmbedcrypto.a $(TLS_LIB_DIR)/libmbedx509.a 43 | COMPILER_FLAGS += -DENABLE_TLS_ADAPTER_MBEDTLS 44 | LD_FLAG += -Wl,-rpath,$(TLS_LIB_DIR) 45 | PRE_MAKE_CMDS += $(MAKE) -C $(TEMP_MBEDTLS_SRC_DIR); 46 | CLEAN_CMD += $(MAKE) -C $(TEMP_MBEDTLS_SRC_DIR) clean; 47 | endif 48 | 49 | ifeq ($(TLS_ADAPTER),openssl) 50 | COMPILER_FLAGS += -DENABLE_TLS_ADAPTER_OPENSSL 51 | LD_FLAG += -lcrypto -lssl 52 | endif 53 | 54 | #CBOR - tinycbor 55 | TINYCBOR_DIR = $(IOT_CLIENT_DIR)/external_libs/tinycbor 56 | CBOR_LIB_DIR = $(TINYCBOR_DIR)/lib 57 | CBOR_INCLUDE_DIR = -I $(TINYCBOR_DIR)/src 58 | STATIC_LIBS += $(CBOR_LIB_DIR)/libtinycbor.a 59 | PRE_MAKE_CMDS += $(MAKE) -C $(TINYCBOR_DIR); 60 | CLEAN_CMD += $(MAKE) -C $(TINYCBOR_DIR) clean; 61 | LD_FLAG += -ldl $(STATIC_LIBS) -lpthread 62 | 63 | # Logging level control 64 | #LOG_FLAGS += -DENABLE_IOT_DEBUG 65 | #LOG_FLAGS += -DENABLE_IOT_TRACE 66 | #LOG_FLAGS += -DENABLE_IOT_INFO 67 | LOG_FLAGS += -DENABLE_IOT_WARN 68 | LOG_FLAGS += -DENABLE_IOT_ERROR 69 | COMPILER_FLAGS += $(LOG_FLAGS) 70 | 71 | #IoT client directory 72 | PLATFORM_COMMON_DIR = $(PLATFORM_DIR)/common 73 | PLATFORM_THREAD_DIR = $(PLATFORM_DIR)/pthread 74 | ifeq ($(TLS_ADAPTER),mbedtls) 75 | PLATFORM_NETWORK_DIR = $(IOT_CLIENT_DIR)/platform/linux/mbedtls 76 | endif 77 | ifeq ($(TLS_ADAPTER),openssl) 78 | PLATFORM_NETWORK_DIR = $(IOT_CLIENT_DIR)/platform/linux/openssl 79 | endif 80 | 81 | IOT_INCLUDE_DIRS = -I $(PLATFORM_COMMON_DIR) 82 | IOT_INCLUDE_DIRS += -I $(PLATFORM_THREAD_DIR) 83 | IOT_INCLUDE_DIRS += -I $(PLATFORM_NETWORK_DIR) 84 | IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/include 85 | IOT_INCLUDE_DIRS += -I $(IOT_CLIENT_DIR)/external_libs/jsmn 86 | ifeq ($(TLS_ADAPTER),mbedtls) 87 | IOT_INCLUDE_DIRS += -I $(TEMP_MBEDTLS_SRC_DIR)/include/mbedtls 88 | endif 89 | 90 | IOT_SRC_FILES += $(shell find $(IOT_CLIENT_DIR)/src/ -name '*.c') 91 | IOT_SRC_FILES += $(shell find $(IOT_CLIENT_DIR)/external_libs/jsmn/ -name '*.c') 92 | IOT_SRC_FILES += $(shell find $(PLATFORM_NETWORK_DIR)/ -name '*.c') 93 | IOT_SRC_FILES += $(shell find $(PLATFORM_COMMON_DIR)/ -name '*.c') 94 | IOT_SRC_FILES += $(shell find $(PLATFORM_THREAD_DIR)/ -name '*.c') 95 | 96 | #Aggregate all include and src directories 97 | INCLUDE_ALL_DIRS += $(IOT_INCLUDE_DIRS) 98 | INCLUDE_ALL_DIRS += $(APP_INCLUDE_DIRS) 99 | INCLUDE_ALL_DIRS += $(TLS_INCLUDE_DIR) 100 | INCLUDE_ALL_DIRS += $(CBOR_INCLUDE_DIR) 101 | 102 | SRC_FILES += $(APP_SRC_FILES) 103 | SRC_FILES += $(IOT_SRC_FILES) 104 | 105 | MT_SRC_FILES += $(MT_APP_SRC_FILES) 106 | MT_SRC_FILES += $(IOT_SRC_FILES) 107 | 108 | COMPILER_FLAGS += -g 109 | COMPILER_FLAGS += $(LOG_FLAGS) 110 | 111 | MAKE_CMD = $(CC) $(SRC_FILES) $(COMPILER_FLAGS) -g3 -D_ENABLE_THREAD_SUPPORT_ -DDOWNLOAD_AGENT_WRITE_FLASH_SUPPORTED -DENABLE_TINYCBOR -o $(APP_DIR)/$(APP_NAME) $(EXTERNAL_LIBS) $(LD_FLAG) $(INCLUDE_ALL_DIRS); 112 | MAKE_MT_CMD = $(CC) $(MT_SRC_FILES) $(COMPILER_FLAGS) -g3 -D_ENABLE_THREAD_SUPPORT_ -o $(APP_DIR)/$(MT_APP_NAME) $(EXTERNAL_LIBS) $(LD_FLAG) $(INCLUDE_ALL_DIRS); 113 | 114 | ifeq ($(CODE_SIZE_ENABLE),Y) 115 | POST_MAKE_CMDS += $(CC) -c $(SRC_FILES) $(INCLUDE_ALL_DIRS) -fstack-usage; 116 | POST_MAKE_CMDS += (size --format=Berkeley *.o > $(APP_NAME)_size_info.txt); 117 | POST_MAKE_CMDS += (cat *.su >> $(APP_NAME)_stack_usage.txt); 118 | POST_MAKE_CMDS += ($(RM) *.o); 119 | POST_MAKE_CMDS += ($(RM) *.su); 120 | CLEAN_CMD += ($(RM) -f $(APP_NAME)_size_info.txt); 121 | CLEAN_CMD += ($(RM) -f $(APP_NAME)_stack_usage.txt); 122 | endif 123 | 124 | all: 125 | $(PRE_MAKE_CMDS) 126 | $(DEBUG)$(MAKE_CMD) 127 | $(DEBUG)$(MAKE_MT_CMD) 128 | ./$(APP_NAME) 129 | ./$(MT_APP_NAME) 130 | $(POST_MAKE_CMDS) 131 | 132 | app: 133 | $(PRE_MAKE_CMDS) 134 | $(DEBUG)$(MAKE_CMD) 135 | $(DEBUG)$(MAKE_MT_CMD) 136 | 137 | tests: 138 | ./$(APP_NAME) 139 | ./$(MT_APP_NAME) 140 | $(POST_MAKE_CMDS) 141 | 142 | clean: 143 | $(RM) -f $(APP_DIR)/$(APP_NAME) 144 | $(RM) -f $(APP_DIR)/$(MT_APP_NAME) 145 | $(CLEAN_CMD) 146 | 147 | ALL_TARGETS_CLEAN += test-integration-assert-clean 148 | -------------------------------------------------------------------------------- /tests/integration/include/aws_iot_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | #ifndef SRC_SHADOW_IOT_SHADOW_CONFIG_H_ 17 | #define SRC_SHADOW_IOT_SHADOW_CONFIG_H_ 18 | 19 | // Get from console 20 | // ================================================= 21 | #define AWS_IOT_MQTT_HOST "" ///< Customer specific MQTT HOST. The same will be used for Thing Shadow 22 | #define AWS_IOT_MQTT_PORT 443 ///< default port for MQTT/S 23 | #define AWS_IOT_MQTT_CLIENT_ID "c-sdk-client-id" ///< MQTT client ID should be unique for every device 24 | #define AWS_IOT_MY_THING_NAME "AWS-IoT-C-SDK" ///< Thing Name of the Shadow this device is associated with 25 | #define AWS_IOT_ROOT_CA_FILENAME "rootCA.crt" ///< Root CA file name 26 | #define AWS_IOT_CERTIFICATE_FILENAME "cert.pem" ///< device signed certificate file name 27 | #define AWS_IOT_PRIVATE_KEY_FILENAME "privkey.pem" ///< Device private key filename 28 | 29 | // MQTT PubSub 30 | #ifndef DISABLE_IOT_JOBS 31 | #define AWS_IOT_MQTT_RX_BUF_LEN 4096 ///< Any message that comes into the device should be less than this buffer size. If a received message is bigger than this buffer size the message will be dropped. 32 | #else 33 | #define AWS_IOT_MQTT_RX_BUF_LEN 2048 34 | #endif 35 | #define AWS_IOT_MQTT_TX_BUF_LEN 512 ///< Any time a message is sent out through the MQTT layer. The message is copied into this buffer anytime a publish is done. This will also be used in the case of Thing Shadow 36 | #define AWS_IOT_MQTT_NUM_SUBSCRIBE_HANDLERS 10 ///< Maximum number of topic filters the MQTT client can handle at any given time. This should be increased appropriately when using Thing Shadow 37 | 38 | // Shadow and Job common configs 39 | #define MAX_SIZE_OF_UNIQUE_CLIENT_ID_BYTES 80 ///< Maximum size of the Unique Client Id. For More info on the Client Id refer \ref response "Acknowledgments" 40 | #define MAX_SIZE_CLIENT_ID_WITH_SEQUENCE MAX_SIZE_OF_UNIQUE_CLIENT_ID_BYTES + 10 ///< This is size of the extra sequence number that will be appended to the Unique client Id 41 | #define MAX_SIZE_CLIENT_TOKEN_CLIENT_SEQUENCE MAX_SIZE_CLIENT_ID_WITH_SEQUENCE + 20 ///< This is size of the the total clientToken key and value pair in the JSON 42 | #define MAX_SIZE_OF_THING_NAME 30 ///< The Thing Name should not be bigger than this value. Modify this if the Thing Name needs to be bigger 43 | 44 | // Thing Shadow specific configs 45 | #define SHADOW_MAX_SIZE_OF_RX_BUFFER 512 ///< Maximum size of the SHADOW buffer to store the received Shadow message 46 | #define MAX_ACKS_TO_COMEIN_AT_ANY_GIVEN_TIME 10 ///< At Any given time we will wait for this many responses. This will correlate to the rate at which the shadow actions are requested 47 | #define MAX_THINGNAME_HANDLED_AT_ANY_GIVEN_TIME 10 ///< We could perform shadow action on any thing Name and this is maximum Thing Names we can act on at any given time 48 | #define MAX_JSON_TOKEN_EXPECTED 120 ///< These are the max tokens that is expected to be in the Shadow JSON document. Include the metadata that gets published 49 | #define MAX_SHADOW_TOPIC_LENGTH_WITHOUT_THINGNAME 60 ///< All shadow actions have to be published or subscribed to a topic which is of the format $aws/things/{thingName}/shadow/update/accepted. This refers to the size of the topic without the Thing Name 50 | #define MAX_SHADOW_TOPIC_LENGTH_BYTES MAX_SHADOW_TOPIC_LENGTH_WITHOUT_THINGNAME + MAX_SIZE_OF_THING_NAME ///< This size includes the length of topic with Thing Name 51 | 52 | // Job specific configs 53 | #ifndef DISABLE_IOT_JOBS 54 | #define MAX_SIZE_OF_JOB_ID 64 55 | #define MAX_JOB_JSON_TOKEN_EXPECTED 120 56 | #define MAX_SIZE_OF_JOB_REQUEST AWS_IOT_MQTT_TX_BUF_LEN 57 | 58 | #define MAX_JOB_TOPIC_LENGTH_WITHOUT_JOB_ID_OR_THING_NAME 40 59 | #define MAX_JOB_TOPIC_LENGTH_BYTES MAX_JOB_TOPIC_LENGTH_WITHOUT_JOB_ID_OR_THING_NAME + MAX_SIZE_OF_THING_NAME + MAX_SIZE_OF_JOB_ID + 2 60 | #endif 61 | 62 | // Download Agent specific configs 63 | #define MAX_SIZE_OF_STREAM_NAME 64 64 | #define MAX_SIZE_OF_FILE_BLOCK_LOG2 11UL 65 | #define AWS_IOT_DOWNLOAD_AGENT_REQUEST_WAIT_INTERVAL 5000 ///< Time interval after being idle for download. 66 | 67 | //#define DOWNLOAD_AGENT_WRITE_FLASH_SUPPORTED true ///< Enable write flash function for Download Agent 68 | 69 | // Auto Reconnect specific config 70 | #define AWS_IOT_MQTT_MIN_RECONNECT_WAIT_INTERVAL 1000 ///< Minimum time before the First reconnect attempt is made as part of the exponential back-off algorithm 71 | #define AWS_IOT_MQTT_MAX_RECONNECT_WAIT_INTERVAL 128000 ///< Maximum time interval after which exponential back-off will stop attempting to reconnect. 72 | 73 | #define DISABLE_METRICS false ///< Disable the collection of metrics by setting this to true 74 | 75 | #endif /* SRC_SHADOW_IOT_SHADOW_CONFIG_H_ */ 76 | -------------------------------------------------------------------------------- /tests/integration/include/aws_iot_integ_tests_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | #ifndef TESTS_INTEGRATION_INTEG_TESTS_CONFIG_H_ 17 | #define TESTS_INTEGRATION_INTEG_TESTS_CONFIG_H_ 18 | 19 | /* Number of messages to publish in each publish thread */ 20 | #define PUBLISH_COUNT 100 21 | 22 | /* Maximum number of threads to create for the multi-threading test */ 23 | #define MAX_PUB_THREAD_COUNT 3 24 | 25 | /* Minimum percentage of messages that must be received back by the yield thread. 26 | * This is here ONLY because sometimes the yield thread doesn't get scheduled before the publish 27 | * thread when it is created. In every other case, 100% messages should be received. */ 28 | #define RX_RECEIVE_PERCENTAGE 99.0f 29 | 30 | /* Max number of initial connect retries */ 31 | #define CONNECT_MAX_ATTEMPT_COUNT 3 32 | 33 | /* Max timeout of file downloading thru download agent */ 34 | #define TIMEOUT_DOWNLOAD_FILE_SEC 100 35 | 36 | /* Interval that each thread sleeps for */ 37 | #define THREAD_SLEEP_INTERVAL_USEC 500000 38 | 39 | /* Test topic to publish on */ 40 | #define INTEGRATION_TEST_TOPIC "Tests/Integration/EmbeddedC" 41 | 42 | /* Client ID to be used for single client tests */ 43 | #define INTEGRATION_TEST_CLIENT_ID "EMB_C_SDK_INTEG_TESTER" 44 | 45 | /* Client IDs to be used for multiple client tests */ 46 | #define INTEGRATION_TEST_CLIENT_ID_PUB "EMB_C_SDK_INTEG_TESTER_PUB" 47 | #define INTEGRATION_TEST_CLIENT_ID_SUB "EMB_C_SDK_INTEG_TESTER_SUB" 48 | 49 | #endif /* TESTS_INTEGRATION_INTEG_TESTS_CONFIG_H_ */ 50 | -------------------------------------------------------------------------------- /tests/integration/include/aws_iot_test_integration_common.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"). 6 | * You may not use this file except in compliance with the License. 7 | * A copy of the License is located at 8 | * 9 | * http://aws.amazon.com/apache2.0 10 | * 11 | * or in the "license" file accompanying this file. This file is distributed 12 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 13 | * express or implied. See the License for the specific language governing 14 | * permissions and limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file aws_iot_test_integration_common.h 19 | * @brief Integration Test common header 20 | */ 21 | 22 | #ifndef TESTS_INTEGRATION_H_ 23 | #define TESTS_INTEGRATION_H_ 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include "aws_iot_mqtt_client_interface.h" 35 | #include "aws_iot_log.h" 36 | #include "aws_iot_integ_tests_config.h" 37 | #include "aws_iot_config.h" 38 | 39 | int aws_iot_mqtt_tests_basic_connectivity(); 40 | int aws_iot_mqtt_tests_multiple_clients(); 41 | int aws_iot_mqtt_tests_auto_reconnect(); 42 | int aws_iot_download_agent_basic_test(); 43 | 44 | #ifndef DISABLE_IOT_JOBS 45 | #ifndef DISABLE_IOT_JOBS_INTERFACE 46 | int aws_iot_jobs_basic_test(); 47 | #endif 48 | #endif 49 | 50 | #endif /* TESTS_INTEGRATION_COMMON_H_ */ 51 | -------------------------------------------------------------------------------- /tests/unit/README.md: -------------------------------------------------------------------------------- 1 | ## Unit Tests 2 | This folder contains unit tests to verify Embedded C SDK functionality. These have been tested to work with Linux using CppUTest as the testing framework. 3 | CppUTest is not provided along with this code. It needs to be separately downloaded. These tests have been verified to work with CppUTest v3.6, which can be found [here](https://github.com/cpputest/cpputest/tree/v3.6). 4 | Each test contains a comment describing what is being tested. The Tests can be run using the Makefile provided in the root folder for the SDK. There are a total of 187 tests. 5 | 6 | To run these tests, follow the below steps: 7 | 8 | * Copy the code for CppUTest v3.6 from github to external_libs/CppUTest 9 | * Navigate to SDK Root folder 10 | * run `make run-unit-tests` 11 | 12 | This will run all unit tests and generate coverage report in the build_output folder. The report can be viewed by opening /build_output/generated-coverage/index.html in a browser. -------------------------------------------------------------------------------- /tests/unit/include/aws_iot_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file aws_iot_config.h 18 | * @brief IoT Client Unit Testing - IoT Config 19 | */ 20 | 21 | #ifndef IOT_TESTS_UNIT_CONFIG_H_ 22 | #define IOT_TESTS_UNIT_CONFIG_H_ 23 | 24 | // Get from console 25 | // ================================================= 26 | #define AWS_IOT_MQTT_HOST "localhost" 27 | #define AWS_IOT_MQTT_PORT 443 28 | #define AWS_IOT_MQTT_CLIENT_ID "C-SDK_UnitTestClient" 29 | #define AWS_IOT_MY_THING_NAME "C-SDK_UnitTestThing" 30 | #define AWS_IOT_ROOT_CA_FILENAME "rootCA.crt" 31 | #define AWS_IOT_CERTIFICATE_FILENAME "cert.crt" 32 | #define AWS_IOT_PRIVATE_KEY_FILENAME "privkey.pem" 33 | // ================================================= 34 | 35 | 36 | // MQTT PubSub 37 | #ifndef DISABLE_IOT_JOBS 38 | #define AWS_IOT_MQTT_RX_BUF_LEN 512 ///< Any message that comes into the device should be less than this buffer size. If a received message is bigger than this buffer size the message will be dropped. 39 | #else 40 | #define AWS_IOT_MQTT_RX_BUF_LEN 2048 41 | #endif 42 | #define AWS_IOT_MQTT_TX_BUF_LEN 512 ///< Any time a message is sent out through the MQTT layer. The message is copied into this buffer anytime a publish is done. This will also be used in the case of Thing Shadow 43 | #define AWS_IOT_MQTT_NUM_SUBSCRIBE_HANDLERS 5 ///< Maximum number of topic filters the MQTT client can handle at any given time. This should be increased appropriately when using Thing Shadow 44 | 45 | // Shadow and Job common configs 46 | #define MAX_SIZE_OF_UNIQUE_CLIENT_ID_BYTES 80 ///< Maximum size of the Unique Client Id. For More info on the Client Id refer \ref response "Acknowledgments" 47 | #define MAX_SIZE_CLIENT_ID_WITH_SEQUENCE MAX_SIZE_OF_UNIQUE_CLIENT_ID_BYTES + 10 ///< This is size of the extra sequence number that will be appended to the Unique client Id 48 | #define MAX_SIZE_CLIENT_TOKEN_CLIENT_SEQUENCE MAX_SIZE_CLIENT_ID_WITH_SEQUENCE + 20 ///< This is size of the the total clientToken key and value pair in the JSON 49 | #define MAX_SIZE_OF_THING_NAME 30 ///< The Thing Name should not be bigger than this value. Modify this if the Thing Name needs to be bigger 50 | 51 | // Thing Shadow specific configs 52 | #define SHADOW_MAX_SIZE_OF_RX_BUFFER 512 ///< Maximum size of the SHADOW buffer to store the received Shadow message 53 | #define MAX_ACKS_TO_COMEIN_AT_ANY_GIVEN_TIME 10 ///< At Any given time we will wait for this many responses. This will correlate to the rate at which the shadow actions are requested 54 | #define MAX_THINGNAME_HANDLED_AT_ANY_GIVEN_TIME 10 ///< We could perform shadow action on any thing Name and this is maximum Thing Names we can act on at any given time 55 | #define MAX_JSON_TOKEN_EXPECTED 120 ///< These are the max tokens that is expected to be in the Shadow JSON document. Include the metadata that gets published 56 | #define MAX_SHADOW_TOPIC_LENGTH_WITHOUT_THINGNAME 60 ///< All shadow actions have to be published or subscribed to a topic which is of the format $aws/things/{thingName}/shadow/update/accepted. This refers to the size of the topic without the Thing Name 57 | #define MAX_SHADOW_TOPIC_LENGTH_BYTES MAX_SHADOW_TOPIC_LENGTH_WITHOUT_THINGNAME + MAX_SIZE_OF_THING_NAME ///< This size includes the length of topic with Thing Name 58 | 59 | // Job specific configs 60 | #ifndef DISABLE_IOT_JOBS 61 | #define MAX_SIZE_OF_JOB_ID 64 62 | #define MAX_JOB_JSON_TOKEN_EXPECTED 120 63 | #define MAX_SIZE_OF_JOB_REQUEST AWS_IOT_MQTT_TX_BUF_LEN 64 | 65 | #define MAX_JOB_TOPIC_LENGTH_WITHOUT_JOB_ID_OR_THING_NAME 40 66 | #define MAX_JOB_TOPIC_LENGTH_BYTES MAX_JOB_TOPIC_LENGTH_WITHOUT_JOB_ID_OR_THING_NAME + MAX_SIZE_OF_THING_NAME + MAX_SIZE_OF_JOB_ID + 2 67 | #endif 68 | 69 | // Auto Reconnect specific config 70 | #define AWS_IOT_MQTT_MIN_RECONNECT_WAIT_INTERVAL 1000 ///< Minimum time before the First reconnect attempt is made as part of the exponential back-off algorithm 71 | #define AWS_IOT_MQTT_MAX_RECONNECT_WAIT_INTERVAL 128000 ///< Maximum time interval after which exponential back-off will stop attempting to reconnect. 72 | 73 | #endif /* IOT_TESTS_UNIT_CONFIG_H_ */ 74 | -------------------------------------------------------------------------------- /tests/unit/include/aws_iot_tests_unit_helper_functions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file aws_iot_tests_unit_helper_functions.h 18 | * @brief IoT Client Unit Testing - Helper Functions 19 | */ 20 | 21 | #ifndef IOT_TESTS_UNIT_HELPER_FUNCTIONS_H_ 22 | #define IOT_TESTS_UNIT_HELPER_FUNCTIONS_H_ 23 | 24 | #include 25 | #include "aws_iot_mqtt_client_interface.h" 26 | #include "aws_iot_jobs_topics.h" 27 | 28 | typedef struct { 29 | unsigned char PacketType; 30 | unsigned int RemainingLength; 31 | unsigned int ProtocolLength; 32 | unsigned char ProtocolName[4]; 33 | unsigned int ProtocolLevel; 34 | unsigned char ConnectFlag; 35 | unsigned int KeepAlive; 36 | } ConnectBufferProofread; 37 | 38 | void ResetInvalidParameters(void); 39 | 40 | void InitMQTTParamsSetup(IoT_Client_Init_Params *params, char *pHost, uint16_t port, bool enableAutoReconnect, 41 | iot_disconnect_handler disconnectHandler); 42 | 43 | void ConnectMQTTParamsSetup(IoT_Client_Connect_Params *params, char *pClientID, uint16_t clientIDLen); 44 | 45 | void ConnectMQTTParamsSetup_Detailed(IoT_Client_Connect_Params *params, char *pClientID, uint16_t clientIDLen, 46 | QoS qos, bool isCleanSession, bool isWillMsgPresent, char *pWillTopicName, 47 | uint16_t willTopicNameLen, char *pWillMessage, uint16_t willMsgLen, 48 | char *pUsername, uint16_t userNameLen, char *pPassword, 49 | uint16_t passwordLen); 50 | 51 | void printBuffer(unsigned char *buffer, size_t len); 52 | 53 | void setTLSRxBufferForConnack(IoT_Client_Connect_Params *params, unsigned char sessionPresent, 54 | unsigned char connackResponseCode); 55 | 56 | void setTLSRxBufferForPuback(void); 57 | 58 | void setTLSRxBufferForSuback(char *topicName, size_t topicNameLen, QoS qos, IoT_Publish_Message_Params params); 59 | 60 | void setTLSRxBufferForDoubleSuback(char *topicName, size_t topicNameLen, QoS qos, IoT_Publish_Message_Params params); 61 | 62 | void setTLSRxBufferForSubFail(void); 63 | 64 | void setTLSRxBufferWithMsgOnSubscribedTopic(char *topicName, size_t topicNameLen, QoS qos, 65 | IoT_Publish_Message_Params params, char *pMsg); 66 | 67 | void setTLSRxBufferForUnsuback(void); 68 | 69 | void setTLSRxBufferForPingresp(void); 70 | 71 | void setTLSRxBufferForError(IoT_Error_t error); 72 | 73 | void setTLSTxBufferForError(IoT_Error_t error); 74 | 75 | void setTLSRxBufferForConnackAndSuback(IoT_Client_Connect_Params *conParams, unsigned char sessionPresent, 76 | char *topicName, size_t topicNameLen, QoS qos); 77 | 78 | unsigned char isLastTLSTxMessagePuback(void); 79 | 80 | unsigned char isLastTLSTxMessagePingreq(void); 81 | 82 | unsigned char isLastTLSTxMessageDisconnect(void); 83 | 84 | void setTLSRxBufferDelay(int seconds, int microseconds); 85 | 86 | void ResetTLSBuffer(void); 87 | 88 | unsigned char generateMultipleSubTopics(char *des, int boundary); 89 | 90 | void encodeRemainingLength(unsigned char *buf, size_t *st, size_t length); 91 | 92 | unsigned char *connectTxBufferHeaderParser(ConnectBufferProofread *params, unsigned char *buf); 93 | 94 | bool isConnectTxBufFlagCorrect(IoT_Client_Connect_Params *settings, ConnectBufferProofread *readRes); 95 | 96 | bool isConnectTxBufPayloadCorrect(IoT_Client_Connect_Params *settings, unsigned char *payloadBuf); 97 | 98 | void printPrfrdParams(ConnectBufferProofread *params); 99 | 100 | const char *getJobTopicTypeName(AwsIotJobExecutionTopicType topicType); 101 | 102 | const char *getJobReplyTypeName(AwsIotJobExecutionTopicReplyType replyType); 103 | 104 | #endif /* IOT_TESTS_UNIT_HELPER_FUNCTIONS_H_ */ 105 | -------------------------------------------------------------------------------- /tests/unit/include/aws_iot_tests_unit_shadow_helper.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file aws_iot_tests_unit_shadow_helper.h 18 | * @brief IoT Client Unit Testing - Shadow Helper functions 19 | */ 20 | 21 | #ifndef IOT_TESTS_UNIT_SHADOW_HELPER_FUNCTIONS_H_ 22 | #define IOT_TESTS_UNIT_SHADOW_HELPER_FUNCTIONS_H_ 23 | 24 | #define AWS_THINGS_TOPIC "$aws/things/" 25 | #define SHADOW_TOPIC "/shadow/" 26 | #define ACCEPTED_TOPIC "/accepted" 27 | #define REJECTED_TOPIC "/rejected" 28 | #define UPDATE_TOPIC "update" 29 | #define GET_TOPIC "get" 30 | #define DELETE_TOPIC "delete" 31 | 32 | 33 | #define GET_ACCEPTED_TOPIC AWS_THINGS_TOPIC AWS_IOT_MY_THING_NAME SHADOW_TOPIC GET_TOPIC ACCEPTED_TOPIC 34 | #define GET_REJECTED_TOPIC AWS_THINGS_TOPIC AWS_IOT_MY_THING_NAME SHADOW_TOPIC GET_TOPIC REJECTED_TOPIC 35 | #define GET_PUB_TOPIC AWS_THINGS_TOPIC AWS_IOT_MY_THING_NAME SHADOW_TOPIC GET_TOPIC 36 | 37 | #define DELETE_ACCEPTED_TOPIC AWS_THINGS_TOPIC AWS_IOT_MY_THING_NAME SHADOW_TOPIC DELETE_TOPIC ACCEPTED_TOPIC 38 | #define DELETE_REJECTED_TOPIC AWS_THINGS_TOPIC AWS_IOT_MY_THING_NAME SHADOW_TOPIC DELETE_TOPIC REJECTED_TOPIC 39 | 40 | #define UPDATE_ACCEPTED_TOPIC AWS_THINGS_TOPIC AWS_IOT_MY_THING_NAME SHADOW_TOPIC UPDATE_TOPIC ACCEPTED_TOPIC 41 | #define UPDATE_REJECTED_TOPIC AWS_THINGS_TOPIC AWS_IOT_MY_THING_NAME SHADOW_TOPIC UPDATE_TOPIC REJECTED_TOPIC 42 | 43 | #endif /* IOT_TESTS_UNIT_SHADOW_HELPER_FUNCTIONS_H_ */ 44 | -------------------------------------------------------------------------------- /tests/unit/src/aws_iot_tests_unit_common_tests.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file aws_iot_tests_unit_common_tests.cpp 18 | * @brief IoT Client Unit Testing - Common Tests 19 | */ 20 | 21 | #include 22 | #include 23 | 24 | TEST_GROUP_C(CommonTests){ 25 | TEST_GROUP_C_SETUP_WRAPPER(CommonTests) 26 | TEST_GROUP_C_TEARDOWN_WRAPPER(CommonTests) 27 | }; 28 | 29 | TEST_GROUP_C_WRAPPER(CommonTests, NullClientGetState) 30 | TEST_GROUP_C_WRAPPER(CommonTests, NullClientSetAutoreconnect) 31 | 32 | TEST_GROUP_C_WRAPPER(CommonTests, UnexpectedAckFiltering) 33 | TEST_GROUP_C_WRAPPER(CommonTests, BigMQTTRxMessageIgnore) 34 | TEST_GROUP_C_WRAPPER(CommonTests, BigMQTTRxMessageReadNextMessage) 35 | -------------------------------------------------------------------------------- /tests/unit/src/aws_iot_tests_unit_connect.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file aws_iot_tests_unit_connect.cpp 18 | * @brief IoT Client Unit Testing - Connect API Tests 19 | */ 20 | 21 | #include 22 | #include 23 | 24 | TEST_GROUP_C(ConnectTests){ 25 | TEST_GROUP_C_SETUP_WRAPPER(ConnectTests) 26 | TEST_GROUP_C_TEARDOWN_WRAPPER(ConnectTests) 27 | }; 28 | 29 | /* B:1 - Init with Null/empty client instance */ 30 | TEST_GROUP_C_WRAPPER(ConnectTests, NullClientInit) 31 | /* B:2 - Connect with Null/empty client instance */ 32 | TEST_GROUP_C_WRAPPER(ConnectTests, NullClientConnect) 33 | /* B:3 - Connect with Null/Empty endpoint */ 34 | TEST_GROUP_C_WRAPPER(ConnectTests, NullHost) 35 | /* B:4 - Connect with Null/Empty port */ 36 | TEST_GROUP_C_WRAPPER(ConnectTests, NullPort) 37 | /* B:5 - Connect with Null/Empty root CA path */ 38 | TEST_GROUP_C_WRAPPER(ConnectTests, NullRootCAPath) 39 | /* B:6 - Connect with Null/Empty Client certificate path */ 40 | TEST_GROUP_C_WRAPPER(ConnectTests, NullClientCertificate) 41 | /* B:7 - Connect with Null/Empty private key Path */ 42 | TEST_GROUP_C_WRAPPER(ConnectTests, NullPrivateKeyPath) 43 | /* B:8 - Connect with Null/Empty client ID */ 44 | TEST_GROUP_C_WRAPPER(ConnectTests, NullClientID) 45 | /* B:9 - Connect with invalid Endpoint */ 46 | TEST_GROUP_C_WRAPPER(ConnectTests, InvalidEndpoint) 47 | /* B:10 - Connect with invalid correct endpoint but invalid port */ 48 | TEST_GROUP_C_WRAPPER(ConnectTests, InvalidPort) 49 | /* B:11 - Connect with invalid Root CA path */ 50 | TEST_GROUP_C_WRAPPER(ConnectTests, InvalidRootCAPath) 51 | /* B:12 - Connect with invalid Client certificate path */ 52 | TEST_GROUP_C_WRAPPER(ConnectTests, InvalidClientCertPath) 53 | /* B:13 - Connect with invalid private key path */ 54 | TEST_GROUP_C_WRAPPER(ConnectTests, InvalidPrivateKeyPath) 55 | /* B:14 - Connect, no response timeout */ 56 | TEST_GROUP_C_WRAPPER(ConnectTests, NoResponseTimeout) 57 | /* B:15 - Connect, connack malformed, too large */ 58 | TEST_GROUP_C_WRAPPER(ConnectTests, ConnackTooLarge) 59 | /* B:16 - Connect, connack malformed, fixed header corrupted */ 60 | TEST_GROUP_C_WRAPPER(ConnectTests, FixedHeaderCorrupted) 61 | /* B:17 - Connect, connack malformed, invalid remaining length */ 62 | TEST_GROUP_C_WRAPPER(ConnectTests, InvalidRemainingLength) 63 | /* B:18 - Connect, connack returned error, unacceptable protocol version */ 64 | TEST_GROUP_C_WRAPPER(ConnectTests, UnacceptableProtocolVersion) 65 | /* B:19 - Connect, connack returned error, identifier rejected */ 66 | TEST_GROUP_C_WRAPPER(ConnectTests, IndentifierRejected) 67 | /* B:20 - Connect, connack returned error, Server unavailable */ 68 | TEST_GROUP_C_WRAPPER(ConnectTests, ServerUnavailable) 69 | /* B:21 - Connect, connack returned error, bad user name or password */ 70 | TEST_GROUP_C_WRAPPER(ConnectTests, BadUserNameOrPassword) 71 | /* B:22 - Connect, connack returned error, not authorized */ 72 | TEST_GROUP_C_WRAPPER(ConnectTests, NotAuthorized) 73 | /* B:23 - Connect, connack return after half command timeout delay, success */ 74 | TEST_GROUP_C_WRAPPER(ConnectTests, SuccessAfterDelayedConnack) 75 | /* B:24 - Connect, connack returned success */ 76 | TEST_GROUP_C_WRAPPER(ConnectTests, ConnectSuccess) 77 | /* B:25 - Connect, flag settings and parameters are recorded in buffer */ 78 | TEST_GROUP_C_WRAPPER(ConnectTests, FlagSettingsAndParamsAreRecordedIntoBuf) 79 | /* B:26 - Connect attempt, Disconnect, Manually reconnect */ 80 | TEST_GROUP_C_WRAPPER(ConnectTests, ConnectDisconnectConnect) 81 | /* B:27 - Connect attempt, Clean session, Subscribe */ 82 | TEST_GROUP_C_WRAPPER(ConnectTests, cleanSessionInitSubscribers) 83 | /* B:28 - Connect attempt, power cycle with clean session false */ 84 | TEST_GROUP_C_WRAPPER(ConnectTests, PowerCycleWithCleanSessionFalse) 85 | /* B:29 - Reconnect attempt succeeds, but resubscribes fail */ 86 | TEST_GROUP_C_WRAPPER(ConnectTests, ReconnectAndResubscribe) 87 | -------------------------------------------------------------------------------- /tests/unit/src/aws_iot_tests_unit_disconnect.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file aws_iot_tests_unit_disconnect.cpp 18 | * @brief IoT Client Unit Testing - Disconnect API Tests 19 | */ 20 | 21 | #include 22 | #include 23 | 24 | TEST_GROUP_C(DisconnectTests){ 25 | TEST_GROUP_C_SETUP_WRAPPER(DisconnectTests) 26 | TEST_GROUP_C_TEARDOWN_WRAPPER(DisconnectTests) 27 | }; 28 | 29 | /* F:1 - Disconnect with Null/empty client instance */ 30 | TEST_GROUP_C_WRAPPER(DisconnectTests, NullClientDisconnect) 31 | /* F:2 - Set Disconnect Handler with Null/empty Client */ 32 | TEST_GROUP_C_WRAPPER(DisconnectTests, NullClientSetDisconnectHandler) 33 | /* F:3 - Call Set Disconnect handler with Null handler */ 34 | TEST_GROUP_C_WRAPPER(DisconnectTests, SetDisconnectHandlerNullHandler) 35 | /* F:4 - Disconnect attempt, not connected */ 36 | TEST_GROUP_C_WRAPPER(DisconnectTests, disconnectNotConnected) 37 | /* F:5 - Disconnect success */ 38 | TEST_GROUP_C_WRAPPER(DisconnectTests, disconnectNoAckSuccess) 39 | /* F:6 - Disconnect, Handler invoked on disconnect */ 40 | TEST_GROUP_C_WRAPPER(DisconnectTests, HandlerInvokedOnDisconnect) 41 | /* F:7 - Disconnect, with set handler and invoked on disconnect */ 42 | TEST_GROUP_C_WRAPPER(DisconnectTests, SetHandlerAndInvokedOnDisconnect) 43 | -------------------------------------------------------------------------------- /tests/unit/src/aws_iot_tests_unit_download_cbor.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file aws_iot_tests_unit_download_cbor.cpp 18 | * @brief IoT Download CBOR API - Common Tests 19 | */ 20 | 21 | #include 22 | #include 23 | 24 | TEST_GROUP_C(DownloadCbor){ 25 | TEST_GROUP_C_SETUP_WRAPPER(DownloadCbor) 26 | TEST_GROUP_C_TEARDOWN_WRAPPER(DownloadCbor) 27 | }; 28 | 29 | TEST_GROUP_C_WRAPPER(DownloadCbor, CborDownloadAgentApi) 30 | TEST_GROUP_C_WRAPPER(DownloadCbor, CborDownloadAgentServerFiles) 31 | -------------------------------------------------------------------------------- /tests/unit/src/aws_iot_tests_unit_jobs.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | #include 17 | #include 18 | 19 | 20 | TEST_GROUP_C(JobsTypesTests) { 21 | TEST_GROUP_C_SETUP_WRAPPER(JobsTypesTests) 22 | TEST_GROUP_C_TEARDOWN_WRAPPER(JobsTypesTests) 23 | }; 24 | 25 | TEST_GROUP_C_WRAPPER(JobsTypesTests, StringToStatus) 26 | TEST_GROUP_C_WRAPPER(JobsTypesTests, StatusToString) 27 | 28 | TEST_GROUP_C(JobsJsonTests) { 29 | TEST_GROUP_C_SETUP_WRAPPER(JobsJsonTests) 30 | TEST_GROUP_C_TEARDOWN_WRAPPER(JobsJsonTests) 31 | }; 32 | 33 | TEST_GROUP_C_WRAPPER(JobsJsonTests, SerializeUpdateRequest) 34 | TEST_GROUP_C_WRAPPER(JobsJsonTests, SerializeUpdateRequestWithNullBuffer) 35 | TEST_GROUP_C_WRAPPER(JobsJsonTests, SerializeUpdateRequestWithTooSmallBuffer) 36 | TEST_GROUP_C_WRAPPER(JobsJsonTests, SerializeDescribeJobExecutionRequest) 37 | TEST_GROUP_C_WRAPPER(JobsJsonTests, SerializeDescribeJobExecutionRequestWithNullBuffer) 38 | TEST_GROUP_C_WRAPPER(JobsJsonTests, SerializeDescribeJobExecutionRequestWithTooSmallBuffer) 39 | TEST_GROUP_C_WRAPPER(JobsJsonTests, SerializeStartNextRequest) 40 | TEST_GROUP_C_WRAPPER(JobsJsonTests, SerializeStartNextRequestWithNullBuffer) 41 | TEST_GROUP_C_WRAPPER(JobsJsonTests, SerializeStartNextRequestWithTooSmallBuffer) 42 | 43 | TEST_GROUP_C(JobsTopicsTests) { 44 | TEST_GROUP_C_SETUP_WRAPPER(JobsTopicsTests) 45 | TEST_GROUP_C_TEARDOWN_WRAPPER(JobsTopicsTests) 46 | }; 47 | 48 | TEST_GROUP_C_WRAPPER(JobsTopicsTests, GenerateValidTopics) 49 | TEST_GROUP_C_WRAPPER(JobsTopicsTests, GenerateWithMissingJobId) 50 | TEST_GROUP_C_WRAPPER(JobsTopicsTests, GenerateWithInvalidTopicOrReplyType) 51 | TEST_GROUP_C_WRAPPER(JobsTopicsTests, GenerateWithInvalidCombinations) 52 | 53 | TEST_GROUP_C(JobsInterfaceTest) { 54 | TEST_GROUP_C_SETUP_WRAPPER(JobsInterfaceTest) 55 | TEST_GROUP_C_TEARDOWN_WRAPPER(JobsInterfaceTest) 56 | }; 57 | 58 | TEST_GROUP_C_WRAPPER(JobsInterfaceTest, TestSubscribeAndUnsubscribe) 59 | TEST_GROUP_C_WRAPPER(JobsInterfaceTest, TestSendQuery) 60 | TEST_GROUP_C_WRAPPER(JobsInterfaceTest, TestSendUpdate) 61 | -------------------------------------------------------------------------------- /tests/unit/src/aws_iot_tests_unit_jobs_types.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | TEST_GROUP_C_SETUP(JobsTypesTests) { 30 | } 31 | 32 | TEST_GROUP_C_TEARDOWN(JobsTypesTests) { 33 | } 34 | 35 | TEST_C(JobsTypesTests, StringToStatus) { 36 | char emptyString = '\0'; 37 | 38 | IOT_DEBUG("\n-->Running Jobs Types Tests - string to status \n"); 39 | 40 | CHECK_EQUAL_C_INT((int)JOB_EXECUTION_STATUS_NOT_SET, (int)aws_iot_jobs_map_string_to_job_status(NULL)); 41 | CHECK_EQUAL_C_INT((int)JOB_EXECUTION_STATUS_NOT_SET, (int)aws_iot_jobs_map_string_to_job_status(&emptyString)); 42 | CHECK_EQUAL_C_INT((int)JOB_EXECUTION_QUEUED, (int)aws_iot_jobs_map_string_to_job_status("QUEUED")); 43 | CHECK_EQUAL_C_INT((int)JOB_EXECUTION_IN_PROGRESS, (int)aws_iot_jobs_map_string_to_job_status("IN_PROGRESS")); 44 | CHECK_EQUAL_C_INT((int)JOB_EXECUTION_FAILED, (int)aws_iot_jobs_map_string_to_job_status("FAILED")); 45 | CHECK_EQUAL_C_INT((int)JOB_EXECUTION_SUCCEEDED, (int)aws_iot_jobs_map_string_to_job_status("SUCCEEDED")); 46 | CHECK_EQUAL_C_INT((int)JOB_EXECUTION_CANCELED, (int)aws_iot_jobs_map_string_to_job_status("CANCELED")); 47 | CHECK_EQUAL_C_INT((int)JOB_EXECUTION_REJECTED, (int)aws_iot_jobs_map_string_to_job_status("REJECTED")); 48 | CHECK_EQUAL_C_INT((int)JOB_EXECUTION_UNKNOWN_STATUS, (int)aws_iot_jobs_map_string_to_job_status("invalidStatus")); 49 | 50 | IOT_DEBUG("-->Success - string to status \n"); 51 | } 52 | 53 | TEST_C(JobsTypesTests, StatusToString) { 54 | IOT_DEBUG("\n-->Running Jobs Types Tests - status to string \n"); 55 | 56 | CHECK_EQUAL_C_STRING("QUEUED", aws_iot_jobs_map_status_to_string(JOB_EXECUTION_QUEUED)); 57 | CHECK_EQUAL_C_STRING("IN_PROGRESS", aws_iot_jobs_map_status_to_string(JOB_EXECUTION_IN_PROGRESS)); 58 | CHECK_EQUAL_C_STRING("FAILED", aws_iot_jobs_map_status_to_string(JOB_EXECUTION_FAILED)); 59 | CHECK_EQUAL_C_STRING("SUCCEEDED", aws_iot_jobs_map_status_to_string(JOB_EXECUTION_SUCCEEDED)); 60 | CHECK_EQUAL_C_STRING("CANCELED", aws_iot_jobs_map_status_to_string(JOB_EXECUTION_CANCELED)); 61 | CHECK_EQUAL_C_STRING("REJECTED", aws_iot_jobs_map_status_to_string(JOB_EXECUTION_REJECTED)); 62 | CHECK_EQUAL_C_STRING(NULL, aws_iot_jobs_map_status_to_string(JOB_EXECUTION_STATUS_NOT_SET)); 63 | CHECK_EQUAL_C_STRING(NULL, aws_iot_jobs_map_status_to_string(JOB_EXECUTION_UNKNOWN_STATUS)); 64 | 65 | IOT_DEBUG("-->Success - status to string \n"); 66 | } 67 | 68 | #ifdef __cplusplus 69 | } 70 | #endif 71 | -------------------------------------------------------------------------------- /tests/unit/src/aws_iot_tests_unit_json_utils.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file aws_iot_tests_unit_json_utils.cpp 18 | * @brief IoT Client Unit Testing - JSON Utility Tests 19 | */ 20 | 21 | #include 22 | #include 23 | 24 | TEST_GROUP_C(JsonUtils) { 25 | TEST_GROUP_C_SETUP_WRAPPER(JsonUtils) 26 | TEST_GROUP_C_TEARDOWN_WRAPPER(JsonUtils) 27 | }; 28 | 29 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseStringBasic) 30 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseStringLongerStringIsValid) 31 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseStringWithBufferTooSmall) 32 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseStringEmptyStringIsValid) 33 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseStringErrorOnInteger) 34 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseStringErrorOnBoolean) 35 | 36 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseBooleanTrue) 37 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseBooleanFalse) 38 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseBooleanErrorOnString) 39 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseBooleanErrorOnInvalidJson) 40 | 41 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseDoubleBasic) 42 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseDoubleNumberWithNoDecimal) 43 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseDoubleSmallDouble) 44 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseDoubleErrorOnString) 45 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseDoubleErrorOnBoolean) 46 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseDoubleErrorOnJsonObject) 47 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseDoubleNegativeNumber) 48 | 49 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseFloatBasic) 50 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseFloatNumberWithNoDecimal) 51 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseFloatSmallFloat) 52 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseFloatErrorOnString) 53 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseFloatErrorOnBoolean) 54 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseFloatErrorOnJsonObject) 55 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseFloatNegativeNumber) 56 | 57 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseIntegerBasic) 58 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseIntegerLargeInteger) 59 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseIntegerNegativeInteger) 60 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseIntegerErrorOnBoolean) 61 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseIntegerErrorOnString) 62 | 63 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseInteger16bitBasic) 64 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseInteger16bitLargeInteger) 65 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseInteger16bitNegativeInteger) 66 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseInteger16bitErrorOnBoolean) 67 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseInteger16bitErrorOnString) 68 | 69 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseInteger8bitBasic) 70 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseInteger8bitLargeInteger) 71 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseInteger8bitNegativeInteger) 72 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseInteger8bitErrorOnBoolean) 73 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseInteger8bitErrorOnString) 74 | 75 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseUnsignedIntegerBasic) 76 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseUnsignedIntegerLargeInteger) 77 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseUnsignedIntegerErrorOnNegativeInteger) 78 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseUnsignedIntegerErrorOnBoolean) 79 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseUnsignedIntegerErrorOnString) 80 | 81 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseUnsignedInteger16bitBasic) 82 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseUnsignedInteger16bitLargeInteger) 83 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseUnsignedInteger16bitErrorOnNegativeInteger) 84 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseUnsignedInteger16bitErrorOnBoolean) 85 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseUnsignedInteger16bitErrorOnString) 86 | 87 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseUnsignedInteger8bitBasic) 88 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseUnsignedInteger8bitLargeInteger) 89 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseUnsignedInteger8bitErrorOnNegativeInteger) 90 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseUnsignedInteger8bitErrorOnBoolean) 91 | TEST_GROUP_C_WRAPPER(JsonUtils, ParseUnsignedInteger8bitErrorOnString) 92 | -------------------------------------------------------------------------------- /tests/unit/src/aws_iot_tests_unit_publish.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file aws_iot_tests_unit_publish.cpp 18 | * @brief IoT Client Unit Testing - Publish API Tests 19 | */ 20 | 21 | #include 22 | #include 23 | 24 | TEST_GROUP_C(PublishTests) { 25 | TEST_GROUP_C_SETUP_WRAPPER(PublishTests) 26 | TEST_GROUP_C_TEARDOWN_WRAPPER(PublishTests) 27 | }; 28 | 29 | /* E:1 - Publish with Null/empty client instance */ 30 | TEST_GROUP_C_WRAPPER(PublishTests, PublishNullClient) 31 | /* E:2 - Publish with Null/empty Topic Name */ 32 | TEST_GROUP_C_WRAPPER(PublishTests, PublishNullTopic) 33 | /* E:3 - Publish with Null/empty payload */ 34 | TEST_GROUP_C_WRAPPER(PublishTests, PublishNullParams) 35 | /* E:4 - Publish with network disconnected */ 36 | TEST_GROUP_C_WRAPPER(PublishTests, PublishNetworkDisconnected) 37 | /* E:5 - Publish with QoS2 */ 38 | /* Not required here, enum value doesn't exist for QoS2 */ 39 | /* E:6 - Publish with QoS1 send success, Puback not received */ 40 | TEST_GROUP_C_WRAPPER(PublishTests, publishQoS1FailureToReceivePuback) 41 | /* E:7 - Publish with QoS1 send success, Delayed Puback received after command timeout */ 42 | TEST_GROUP_C_WRAPPER(PublishTests, publishQoS1FailureDelayedPuback) 43 | /* E:8 - Publish with send success, Delayed Puback received before command timeout */ 44 | TEST_GROUP_C_WRAPPER(PublishTests, publishQoS1Success10msDelayedPuback) 45 | /* E:9 - Publish QoS0 success */ 46 | TEST_GROUP_C_WRAPPER(PublishTests, publishQoS0NoPubackSuccess) 47 | /* E:10 - Publish with QoS1 send success, Puback received */ 48 | TEST_GROUP_C_WRAPPER(PublishTests, publishQoS1Success) 49 | -------------------------------------------------------------------------------- /tests/unit/src/aws_iot_tests_unit_runner.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file aws_iot_tests_unit_runner.cpp 18 | * @brief IoT Client Unit Testing - Runner 19 | */ 20 | 21 | #include 22 | 23 | int main(int ac, char **argv) { 24 | return CommandLineTestRunner::RunAllTests(ac, argv); 25 | } 26 | -------------------------------------------------------------------------------- /tests/unit/src/aws_iot_tests_unit_shadow_action.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file aws_iot_tests_unit_shadow_action.cpp 18 | * @brief IoT Client Unit Testing - Shadow Action Tests 19 | */ 20 | 21 | #include 22 | #include 23 | 24 | TEST_GROUP_C(ShadowActionTests) { 25 | TEST_GROUP_C_SETUP_WRAPPER(ShadowActionTests) 26 | TEST_GROUP_C_TEARDOWN_WRAPPER(ShadowActionTests) 27 | }; 28 | 29 | TEST_GROUP_C_WRAPPER(ShadowActionTests, GetTheFullJSONDocument) 30 | TEST_GROUP_C_WRAPPER(ShadowActionTests, DeleteTheJSONDocument) 31 | TEST_GROUP_C_WRAPPER(ShadowActionTests, UpdateTheJSONDocument) 32 | TEST_GROUP_C_WRAPPER(ShadowActionTests, GetTheFullJSONDocumentTimeout) 33 | TEST_GROUP_C_WRAPPER(ShadowActionTests, SubscribeToAcceptedRejectedOnGet) 34 | TEST_GROUP_C_WRAPPER(ShadowActionTests, UnSubscribeToAcceptedRejectedOnGetResponse) 35 | TEST_GROUP_C_WRAPPER(ShadowActionTests, UnSubscribeToAcceptedRejectedOnGetTimeout) 36 | TEST_GROUP_C_WRAPPER(ShadowActionTests, UnSubscribeToAcceptedRejectedOnGetTimeoutWithSticky) 37 | TEST_GROUP_C_WRAPPER(ShadowActionTests, WrongTokenInGetResponse) 38 | TEST_GROUP_C_WRAPPER(ShadowActionTests, NoTokenInGetResponse) 39 | TEST_GROUP_C_WRAPPER(ShadowActionTests, InvalidInboundJSONInGetResponse) 40 | TEST_GROUP_C_WRAPPER(ShadowActionTests, AcceptedSubFailsGetRequest) 41 | TEST_GROUP_C_WRAPPER(ShadowActionTests, RejectedSubFailsGetRequest) 42 | TEST_GROUP_C_WRAPPER(ShadowActionTests, PublishFailsGetRequest) 43 | TEST_GROUP_C_WRAPPER(ShadowActionTests, GetVersionFromAckStatus) 44 | TEST_GROUP_C_WRAPPER(ShadowActionTests, StickyNonStickyNeverConflict) 45 | TEST_GROUP_C_WRAPPER(ShadowActionTests, ACKWaitingMoreThanAllowed) 46 | TEST_GROUP_C_WRAPPER(ShadowActionTests, InboundDataTooBigForBuffer) 47 | TEST_GROUP_C_WRAPPER(ShadowActionTests, NoClientTokenForShadowAction) 48 | TEST_GROUP_C_WRAPPER(ShadowActionTests, NoCallbackForShadowAction) 49 | TEST_GROUP_C_WRAPPER(ShadowActionTests, GetAndDeleteRequest) 50 | TEST_GROUP_C_WRAPPER(ShadowActionTests, ExtractClientToken) 51 | TEST_GROUP_C_WRAPPER(ShadowActionTests, IsReceivedJsonValid) 52 | -------------------------------------------------------------------------------- /tests/unit/src/aws_iot_tests_unit_shadow_delta.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file aws_iot_tests_unit_shadow_delta.cpp 18 | * @brief IoT Client Unit Testing - Shadow Delta Tests 19 | */ 20 | 21 | #include 22 | #include 23 | 24 | TEST_GROUP_C(ShadowDeltaTest){ 25 | TEST_GROUP_C_SETUP_WRAPPER(ShadowDeltaTest) 26 | TEST_GROUP_C_TEARDOWN_WRAPPER(ShadowDeltaTest) 27 | }; 28 | 29 | TEST_GROUP_C_WRAPPER(ShadowDeltaTest, registerDeltaSuccess) 30 | TEST_GROUP_C_WRAPPER(ShadowDeltaTest, registerDeltaInt) 31 | TEST_GROUP_C_WRAPPER(ShadowDeltaTest, registerDeltaIntNoCallback) 32 | TEST_GROUP_C_WRAPPER(ShadowDeltaTest, DeltaNestedObject) 33 | TEST_GROUP_C_WRAPPER(ShadowDeltaTest, DeltaVersionIgnoreOldVersion) 34 | -------------------------------------------------------------------------------- /tests/unit/src/aws_iot_tests_unit_shadow_json_builder.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file aws_iot_tests_unit_shadow_json_builder.cpp 18 | * @brief IoT Client Unit Testing - Shadow JSON Builder Tests 19 | */ 20 | 21 | #include 22 | #include 23 | 24 | TEST_GROUP_C(ShadowJsonBuilderTests){ 25 | TEST_GROUP_C_SETUP_WRAPPER(ShadowJsonBuilderTests) 26 | TEST_GROUP_C_TEARDOWN_WRAPPER(ShadowJsonBuilderTests) 27 | }; 28 | 29 | TEST_GROUP_C_WRAPPER(ShadowJsonBuilderTests, UpdateTheJSONDocumentBuilder) 30 | TEST_GROUP_C_WRAPPER(ShadowJsonBuilderTests, PassingNullValue) 31 | TEST_GROUP_C_WRAPPER(ShadowJsonBuilderTests, SmallBuffer) 32 | -------------------------------------------------------------------------------- /tests/unit/src/aws_iot_tests_unit_shadow_null_fields.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file aws_iot_tests_unit_shadow_null_fields.cpp 18 | * @brief IoT Client Unit Testing - Shadow APIs NULL field Tests 19 | */ 20 | 21 | #include 22 | #include 23 | 24 | TEST_GROUP_C(ShadowNullFields){ 25 | TEST_GROUP_C_SETUP_WRAPPER(ShadowNullFields) 26 | TEST_GROUP_C_TEARDOWN_WRAPPER(ShadowNullFields) 27 | }; 28 | 29 | TEST_GROUP_C_WRAPPER(ShadowNullFields, NullClientInit) 30 | TEST_GROUP_C_WRAPPER(ShadowNullFields, NullClientConnect) 31 | TEST_GROUP_C_WRAPPER(ShadowNullFields, NullHost) 32 | TEST_GROUP_C_WRAPPER(ShadowNullFields, NullPort) 33 | TEST_GROUP_C_WRAPPER(ShadowNullFields, NullClientID) 34 | TEST_GROUP_C_WRAPPER(ShadowNullFields, NullUpdateDocument) 35 | TEST_GROUP_C_WRAPPER(ShadowNullFields, NullClientYield) 36 | TEST_GROUP_C_WRAPPER(ShadowNullFields, NullClientDisconnect) 37 | TEST_GROUP_C_WRAPPER(ShadowNullFields, NullClientShadowGet) 38 | TEST_GROUP_C_WRAPPER(ShadowNullFields, NullClientShadowUpdate) 39 | TEST_GROUP_C_WRAPPER(ShadowNullFields, NullClientShadowDelete) 40 | TEST_GROUP_C_WRAPPER(ShadowNullFields, NullClientSetAutoreconnect) 41 | -------------------------------------------------------------------------------- /tests/unit/src/aws_iot_tests_unit_subscribe.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file aws_iot_tests_unit_subscribe.cpp 18 | * @brief IoT Client Unit Testing - Subscribe API Tests 19 | */ 20 | 21 | #include 22 | #include 23 | 24 | TEST_GROUP_C(SubscribeTests){ 25 | TEST_GROUP_C_SETUP_WRAPPER(SubscribeTests) 26 | TEST_GROUP_C_TEARDOWN_WRAPPER(SubscribeTests) 27 | }; 28 | 29 | /* C:1 - Subscribe with Null/empty Client Instance */ 30 | TEST_GROUP_C_WRAPPER(SubscribeTests, SubscribeNullClient) 31 | /* C:2 - Subscribe with Null/empty Topic Name */ 32 | TEST_GROUP_C_WRAPPER(SubscribeTests, SubscribeNullTopic) 33 | /* C:3 - Subscribe with Null client callback */ 34 | TEST_GROUP_C_WRAPPER(SubscribeTests, SubscribeNullSubscribeHandler) 35 | /* C:4 - Subscribe with Null client callback data */ 36 | TEST_GROUP_C_WRAPPER(SubscribeTests, SubscribeNullSubscribeHandlerData) 37 | /* C:5 - Subscribe with no connection */ 38 | TEST_GROUP_C_WRAPPER(SubscribeTests, SubscribeNoConnection) 39 | /* C:6 - Subscribe QoS2, error */ 40 | /* Not required, QoS enum doesn't have value for QoS2 */ 41 | 42 | /* C:7 - Subscribe attempt, QoS0, no response timeout */ 43 | TEST_GROUP_C_WRAPPER(SubscribeTests, subscribeQoS0FailureOnNoSuback) 44 | /* C:8 - Subscribe attempt, QoS1, no response timeout */ 45 | TEST_GROUP_C_WRAPPER(SubscribeTests, subscribeQoS1FailureOnNoSuback) 46 | 47 | /* C:9 - Subscribe QoS0 success, suback received */ 48 | TEST_GROUP_C_WRAPPER(SubscribeTests, subscribeQoS0Success) 49 | /* C:10 - Subscribe QoS1 success, suback received */ 50 | TEST_GROUP_C_WRAPPER(SubscribeTests, subscribeQoS1Success) 51 | 52 | /* C:11 - Subscribe, QoS0, delayed suback, success */ 53 | TEST_GROUP_C_WRAPPER(SubscribeTests, subscribeQoS0WithDelayedSubackSuccess) 54 | /* C:12 - Subscribe, QoS1, delayed suback, success */ 55 | TEST_GROUP_C_WRAPPER(SubscribeTests, subscribeQoS1WithDelayedSubackSuccess) 56 | 57 | /* C:13 - Subscribe QoS0 success, no puback sent on message */ 58 | TEST_GROUP_C_WRAPPER(SubscribeTests, subscribeQoS0MsgReceivedAndNoPubackSent) 59 | /* C:14 - Subscribe QoS1 success, puback sent on message */ 60 | TEST_GROUP_C_WRAPPER(SubscribeTests, subscribeQoS1MsgReceivedAndSendPuback) 61 | 62 | /* C:15 - Subscribe, malformed response */ 63 | TEST_GROUP_C_WRAPPER(SubscribeTests, subscribeMalformedResponse) 64 | 65 | /* C:16 - Subscribe, multiple topics, messages on each topic */ 66 | TEST_GROUP_C_WRAPPER(SubscribeTests, SubscribeToMultipleTopicsSuccess) 67 | /* C:17 - Subscribe, max topics, messages on each topic */ 68 | TEST_GROUP_C_WRAPPER(SubscribeTests, SubscribeToMaxAllowedTopicsSuccess) 69 | /* C:18 - Subscribe, max topics, another subscribe */ 70 | TEST_GROUP_C_WRAPPER(SubscribeTests, SubscribeToMaxPlusOneAllowedTopicsFailure) 71 | 72 | /* C:19 - Subscribe, '#' not last character in topic name, Failure */ 73 | TEST_GROUP_C_WRAPPER(SubscribeTests, subscribeTopicWithHashkeyAllSubTopicSuccess) 74 | /* C:20 - Subscribe with '#', subscribed to all subtopics */ 75 | TEST_GROUP_C_WRAPPER(SubscribeTests, subscribeTopicHashkeyMustBeTheLastFail) 76 | /* C:21 - Subscribe with '+' as wildcard success */ 77 | TEST_GROUP_C_WRAPPER(SubscribeTests, subscribeTopicWithPluskeySuccess) 78 | /* C:22 - Subscribe with '+' as last character in topic name, Success */ 79 | TEST_GROUP_C_WRAPPER(SubscribeTests, subscribeTopicPluskeyComesLastSuccess) 80 | -------------------------------------------------------------------------------- /tests/unit/src/aws_iot_tests_unit_unsubscribe.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file aws_iot_tests_unit_unsubscribe.cpp 18 | * @brief IoT Client Unit Testing - Unsubscribe API Tests 19 | */ 20 | 21 | #include 22 | #include 23 | 24 | TEST_GROUP_C(UnsubscribeTests){ 25 | TEST_GROUP_C_SETUP_WRAPPER(UnsubscribeTests) 26 | TEST_GROUP_C_TEARDOWN_WRAPPER(UnsubscribeTests) 27 | }; 28 | 29 | /* D:1 - Unsubscribe with Null/empty client instance */ 30 | TEST_GROUP_C_WRAPPER(UnsubscribeTests, UnsubscribeNullClient) 31 | /* D:2 - Unsubscribe with Null/empty topic name */ 32 | TEST_GROUP_C_WRAPPER(UnsubscribeTests, UnsubscribeNullTopic) 33 | /* D:3 - Unsubscribe, Not subscribed to topic */ 34 | TEST_GROUP_C_WRAPPER(UnsubscribeTests, UnsubscribeNotSubscribed) 35 | 36 | /* D:4 - Unsubscribe, QoS0, No response, timeout */ 37 | TEST_GROUP_C_WRAPPER(UnsubscribeTests, unsubscribeQoS0FailureOnNoUnsuback) 38 | /* D:5 - Unsubscribe, QoS1, No response, timeout */ 39 | TEST_GROUP_C_WRAPPER(UnsubscribeTests, unsubscribeQoS1FailureOnNoUnsuback) 40 | 41 | /* D:6 - Unsubscribe, QoS0, success */ 42 | TEST_GROUP_C_WRAPPER(UnsubscribeTests, unsubscribeQoS0WithUnsubackSuccess) 43 | /* D:7 - Unsubscribe, QoS0, half command timeout delayed unsuback, success */ 44 | TEST_GROUP_C_WRAPPER(UnsubscribeTests, unsubscribeQoS0WithDelayedUnsubackSuccess) 45 | /* D:8 - Unsubscribe, QoS1, success */ 46 | TEST_GROUP_C_WRAPPER(UnsubscribeTests, unsubscribeQoS1WithUnsubackSuccess) 47 | /* D:9 - Unsubscribe, QoS1, half command timeout delayed unsuback, success */ 48 | TEST_GROUP_C_WRAPPER(UnsubscribeTests, unsubscribeQoS1WithDelayedUnsubackSuccess) 49 | 50 | /* D:10 - Unsubscribe, success, message on topic ignored */ 51 | TEST_GROUP_C_WRAPPER(UnsubscribeTests, MsgAfterUnsubscribe) 52 | /* D:11 - Unsubscribe after max topics reached */ 53 | TEST_GROUP_C_WRAPPER(UnsubscribeTests, MaxTopicsSubscription) 54 | /* D:12 - Repeated Subscribe and Unsubscribe */ 55 | TEST_GROUP_C_WRAPPER(UnsubscribeTests, RepeatedSubUnSub) 56 | -------------------------------------------------------------------------------- /tests/unit/src/aws_iot_tests_unit_yield.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file aws_iot_tests_unit_yield.cpp 18 | * @brief IoT Client Unit Testing - Yield API Tests 19 | */ 20 | 21 | #include 22 | #include 23 | 24 | TEST_GROUP_C(YieldTests){ 25 | TEST_GROUP_C_SETUP_WRAPPER(YieldTests) 26 | TEST_GROUP_C_TEARDOWN_WRAPPER(YieldTests) 27 | }; 28 | 29 | /* G:1 - Yield with Null/empty Client Instance */ 30 | TEST_GROUP_C_WRAPPER(YieldTests, NullClientYield) 31 | /* G:2 - Yield with zero yield timeout */ 32 | TEST_GROUP_C_WRAPPER(YieldTests, ZeroTimeoutYield) 33 | /* G:3 - Yield, network disconnected, never connected */ 34 | TEST_GROUP_C_WRAPPER(YieldTests, YieldNetworkDisconnectedNeverConnected) 35 | /* G:4 - Yield, network disconnected, disconnected manually */ 36 | TEST_GROUP_C_WRAPPER(YieldTests, YieldNetworkDisconnectedDisconnectedManually) 37 | /* G:5 - Yield, network connected, yield called while in subscribe application callback */ 38 | TEST_GROUP_C_WRAPPER(YieldTests, YieldInSubscribeCallback) 39 | /* G:6 - Yield, network disconnected, ping timeout, auto-reconnect disabled */ 40 | TEST_GROUP_C_WRAPPER(YieldTests, disconnectNoAutoReconnect) 41 | 42 | /* G:7 - Yield, network connected, no incoming messages */ 43 | TEST_GROUP_C_WRAPPER(YieldTests, YieldSuccessNoMessages) 44 | /* G:8 - Yield, network connected, ping request/response */ 45 | TEST_GROUP_C_WRAPPER(YieldTests, PingRequestPingResponse) 46 | 47 | /* G:9 - Yield, disconnected, Auto-reconnect timed-out */ 48 | TEST_GROUP_C_WRAPPER(YieldTests, disconnectAutoReconnectTimeout) 49 | /* G:10 - Yield, disconnected, Auto-reconnect successful */ 50 | TEST_GROUP_C_WRAPPER(YieldTests, disconnectAutoReconnectSuccess) 51 | /* G:11 - Yield, disconnected, Manual reconnect */ 52 | TEST_GROUP_C_WRAPPER(YieldTests, disconnectManualAutoReconnect) 53 | /* G:12 - Yield, resubscribe to all topics on reconnect */ 54 | TEST_GROUP_C_WRAPPER(YieldTests, resubscribeSuccessfulReconnect) 55 | -------------------------------------------------------------------------------- /tests/unit/test_files/getStreamResponse_0.cbor: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws-samples/aws-iot-mqtt-download-agent/6a4bfb687e87131c9cec57e2763b9b0ac4a5deb8/tests/unit/test_files/getStreamResponse_0.cbor -------------------------------------------------------------------------------- /tests/unit/test_files/getStreamResponse_1.cbor: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws-samples/aws-iot-mqtt-download-agent/6a4bfb687e87131c9cec57e2763b9b0ac4a5deb8/tests/unit/test_files/getStreamResponse_1.cbor -------------------------------------------------------------------------------- /tests/unit/test_files/getStreamResponse_2.cbor: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws-samples/aws-iot-mqtt-download-agent/6a4bfb687e87131c9cec57e2763b9b0ac4a5deb8/tests/unit/test_files/getStreamResponse_2.cbor -------------------------------------------------------------------------------- /tests/unit/test_files/getStreamResponse_3.cbor: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws-samples/aws-iot-mqtt-download-agent/6a4bfb687e87131c9cec57e2763b9b0ac4a5deb8/tests/unit/test_files/getStreamResponse_3.cbor -------------------------------------------------------------------------------- /tests/unit/test_files/getStreamResponse_4.cbor: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws-samples/aws-iot-mqtt-download-agent/6a4bfb687e87131c9cec57e2763b9b0ac4a5deb8/tests/unit/test_files/getStreamResponse_4.cbor -------------------------------------------------------------------------------- /tests/unit/test_files/getStreamResponse_5.cbor: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws-samples/aws-iot-mqtt-download-agent/6a4bfb687e87131c9cec57e2763b9b0ac4a5deb8/tests/unit/test_files/getStreamResponse_5.cbor -------------------------------------------------------------------------------- /tests/unit/test_files/getStreamResponse_6.cbor: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws-samples/aws-iot-mqtt-download-agent/6a4bfb687e87131c9cec57e2763b9b0ac4a5deb8/tests/unit/test_files/getStreamResponse_6.cbor -------------------------------------------------------------------------------- /tests/unit/test_files/getStreamResponse_7.cbor: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws-samples/aws-iot-mqtt-download-agent/6a4bfb687e87131c9cec57e2763b9b0ac4a5deb8/tests/unit/test_files/getStreamResponse_7.cbor -------------------------------------------------------------------------------- /tests/unit/tls_mock/aws_iot_tests_unit_mock_tls_params.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file aws_iot_tests_unit_mock_tls_params.c 18 | * @brief IoT Client Unit Testing Mock TLS Params 19 | */ 20 | 21 | #include "aws_iot_tests_unit_mock_tls_params.h" 22 | 23 | unsigned char RxBuf[TLSMaxBufferSize]; 24 | unsigned char TxBuf[TLSMaxBufferSize]; 25 | char LastSubscribeMessage[TLSMaxBufferSize]; 26 | size_t lastSubscribeMsgLen; 27 | char SecondLastSubscribeMessage[TLSMaxBufferSize]; 28 | size_t secondLastSubscribeMsgLen; 29 | 30 | char LastUnsubscribeMessage[TLSMaxBufferSize]; 31 | size_t lastUnsubscribeMsgLen; 32 | 33 | char LastPublishMessageTopic[TLSMaxBufferSize]; 34 | size_t lastPublishMessageTopicLen; 35 | char LastPublishMessagePayload[TLSMaxBufferSize]; 36 | size_t lastPublishMessagePayloadLen; 37 | 38 | TlsBuffer RxBuffer = {.pBuffer = RxBuf,.len = 512, .NoMsgFlag=1, .expiry_time = {0, 0}, .BufMaxSize = TLSMaxBufferSize, .mockedError = SUCCESS}; 39 | TlsBuffer TxBuffer = {.pBuffer = TxBuf,.len = 512, .NoMsgFlag=1, .expiry_time = {0, 0}, .BufMaxSize = TLSMaxBufferSize, .mockedError = SUCCESS}; 40 | 41 | size_t RxIndex = 0; 42 | 43 | char *invalidEndpointFilter; 44 | char *invalidRootCAPathFilter; 45 | char *invalidCertPathFilter; 46 | char *invalidPrivKeyPathFilter; 47 | uint16_t invalidPortFilter; 48 | -------------------------------------------------------------------------------- /tests/unit/tls_mock/aws_iot_tests_unit_mock_tls_params.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"). 5 | * You may not use this file except in compliance with the License. 6 | * A copy of the License is located at 7 | * 8 | * http://aws.amazon.com/apache2.0 9 | * 10 | * or in the "license" file accompanying this file. This file is distributed 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 | * express or implied. See the License for the specific language governing 13 | * permissions and limitations under the License. 14 | */ 15 | 16 | /** 17 | * @file aws_iot_tests_unit_mock_tls_params.h 18 | * @brief IoT Client Unit Testing Mock TLS Params 19 | */ 20 | 21 | #ifndef UNITTESTS_MOCKS_TLS_PARAMS_H_ 22 | #define UNITTESTS_MOCKS_TLS_PARAMS_H_ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #define TLSMaxBufferSize 2560 31 | #define NO_MSG_LENGTH_MENTIONED -1 32 | 33 | typedef struct { 34 | unsigned char *pBuffer; 35 | size_t len; 36 | bool NoMsgFlag; 37 | struct timeval expiry_time; 38 | size_t BufMaxSize; 39 | IoT_Error_t mockedError; 40 | } TlsBuffer; 41 | 42 | 43 | extern TlsBuffer RxBuffer; 44 | extern TlsBuffer TxBuffer; 45 | 46 | extern size_t RxIndex; 47 | extern unsigned char RxBuf[TLSMaxBufferSize]; 48 | extern unsigned char TxBuf[TLSMaxBufferSize]; 49 | extern char LastSubscribeMessage[TLSMaxBufferSize]; 50 | extern size_t lastSubscribeMsgLen; 51 | extern char SecondLastSubscribeMessage[TLSMaxBufferSize]; 52 | extern size_t secondLastSubscribeMsgLen; 53 | 54 | extern char LastUnsubscribeMessage[TLSMaxBufferSize]; 55 | extern size_t lastUnsubscribeMsgLen; 56 | 57 | extern char LastPublishMessageTopic[TLSMaxBufferSize]; 58 | extern size_t lastPublishMessageTopicLen; 59 | extern char LastPublishMessagePayload[TLSMaxBufferSize]; 60 | extern size_t lastPublishMessagePayloadLen; 61 | 62 | extern char hostAddress[512]; 63 | extern uint16_t port; 64 | extern uint32_t handshakeTimeout_ms; 65 | 66 | extern char *invalidEndpointFilter; 67 | extern char *invalidRootCAPathFilter; 68 | extern char *invalidCertPathFilter; 69 | extern char *invalidPrivKeyPathFilter; 70 | extern uint16_t invalidPortFilter; 71 | 72 | #endif /* UNITTESTS_MOCKS_TLS_PARAMS_H_ */ 73 | -------------------------------------------------------------------------------- /tests/unit/tls_mock/network_platform.h: -------------------------------------------------------------------------------- 1 | // 2 | // Created by chaurah on 3/22/16. 3 | // 4 | 5 | #ifndef IOTSDKC_NETWORK_MBEDTLS_PLATFORM_H_H 6 | 7 | /** 8 | * @brief TLS Connection Parameters 9 | * 10 | * Defines a type containing TLS specific parameters to be passed down to the 11 | * TLS networking layer to create a TLS secured socket. 12 | */ 13 | typedef struct _TLSDataParams { 14 | uint32_t flags; 15 | }TLSDataParams; 16 | 17 | #define IOTSDKC_NETWORK_MBEDTLS_PLATFORM_H_H 18 | 19 | #endif //IOTSDKC_NETWORK_MBEDTLS_PLATFORM_H_H 20 | --------------------------------------------------------------------------------