diff options
author | Paul Bartell <pbartell@amazon.com> | 2022-07-28 14:26:18 -0700 |
---|---|---|
committer | Paul Bartell <paul.bartell@gmail.com> | 2022-08-17 15:43:21 -0700 |
commit | 2ffe3de4b5a2d57cd246925f33194a09250310dc (patch) | |
tree | 4ff7aa69cea59884dc6f98248ca54f3852bb9dc5 | |
parent | a8a2234b2b0b5003493fbce385ec60228aaeb427 (diff) | |
download | freertos-git-2ffe3de4b5a2d57cd246925f33194a09250310dc.tar.gz |
mqtt-multitask-demo: Move demo_config.h checks
-rw-r--r-- | FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Multitask/DemoTasks/mqtt-agent-task.c | 139 | ||||
-rw-r--r-- | FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Multitask/demo_config.h | 120 |
2 files changed, 137 insertions, 122 deletions
diff --git a/FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Multitask/DemoTasks/mqtt-agent-task.c b/FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Multitask/DemoTasks/mqtt-agent-task.c index eac6a4a53..a056cadda 100644 --- a/FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Multitask/DemoTasks/mqtt-agent-task.c +++ b/FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Multitask/DemoTasks/mqtt-agent-task.c @@ -53,6 +53,7 @@ /* Standard includes. */ #include <string.h> #include <stdio.h> +#include <stdint.h> #include <assert.h> /* Kernel includes. */ @@ -102,20 +103,84 @@ #error Please define democonfigSIMPLE_SUB_PUB_TASK_STACK_SIZE in demo_config.h to set the stack size (in words, not bytes) for the tasks created by vStartSimpleSubscribePublishTask(). #endif + /* Compile time error for some undefined configs, and provide default values + * for others. */ +#ifndef democonfigMQTT_BROKER_ENDPOINT +#error "Please define democonfigMQTT_BROKER_ENDPOINT in demo_config.h." +#endif + +#ifndef democonfigCLIENT_IDENTIFIER + + /** + * @brief The MQTT client identifier used in this example. Each client identifier + * must be unique so edit as required to ensure no two clients connecting to the + * same broker use the same client identifier. Using a #define is for convenience + * of demonstration only - production devices should use something unique to the + * device that can be read from software - such as a production serial number. + */ +#error "Please define democonfigCLIENT_IDENTIFIER in demo_config.h to something unique for this device." +#endif + + +#if defined( democonfigUSE_TLS ) && ( democonfigUSE_TLS == 1 ) +#ifndef democonfigROOT_CA_PEM +#error "Please define Root CA certificate of the MQTT broker(democonfigROOT_CA_PEM) in demo_config.h." +#endif + + /* If no username is defined, then a client certificate/key is required. */ +#ifndef democonfigCLIENT_USERNAME + +/* + *!!! Please note democonfigCLIENT_PRIVATE_KEY_PEM in used for + *!!! convenience of demonstration only. Production devices should + *!!! store keys securely, such as within a secure element. + */ + +#ifndef democonfigCLIENT_CERTIFICATE_PEM +#error "Please define client certificate(democonfigCLIENT_CERTIFICATE_PEM) in demo_config.h." +#endif +#ifndef democonfigCLIENT_PRIVATE_KEY_PEM +#error "Please define client private key(democonfigCLIENT_PRIVATE_KEY_PEM) in demo_config.h." +#endif +#else + +/* If a username is defined, a client password also would need to be defined for + * client authentication. */ +#ifndef democonfigCLIENT_PASSWORD +#error "Please define client password(democonfigCLIENT_PASSWORD) in demo_config.h for client authentication based on username/password." +#endif + + /* AWS IoT MQTT broker port needs to be 443 for client authentication based on + * username/password. */ +#if defined( democonfigUSE_AWS_IOT_CORE_BROKER ) && democonfigMQTT_BROKER_PORT != 443 +#error "Broker port(democonfigMQTT_BROKER_PORT) should be defined as 443 in demo_config.h for client authentication based on username/password in AWS IoT Core." +#endif +#endif /* ifndef democonfigCLIENT_USERNAME */ + +#ifndef democonfigMQTT_BROKER_PORT +#define democonfigMQTT_BROKER_PORT ( 8883 ) +#endif +#else /* if defined( democonfigUSE_TLS ) && ( democonfigUSE_TLS == 1 ) */ +#ifndef democonfigMQTT_BROKER_PORT +#define democonfigMQTT_BROKER_PORT ( 1883 ) +#endif +#endif /* if defined( democonfigUSE_TLS ) && ( democonfigUSE_TLS == 1 ) */ + + /** * @brief Dimensions the buffer used to serialize and deserialize MQTT packets. * @note Specified in bytes. Must be large enough to hold the maximum * anticipated MQTT payload. */ #ifndef MQTT_AGENT_NETWORK_BUFFER_SIZE - #define MQTT_AGENT_NETWORK_BUFFER_SIZE ( 5000 ) + #define MQTT_AGENT_NETWORK_BUFFER_SIZE ( 5000U ) #endif /** * @brief The length of the queue used to hold commands for the agent. */ #ifndef MQTT_AGENT_COMMAND_QUEUE_LENGTH - #define MQTT_AGENT_COMMAND_QUEUE_LENGTH ( 10 ) + #define MQTT_AGENT_COMMAND_QUEUE_LENGTH ( 10U ) #endif @@ -168,6 +233,76 @@ #define mqttexampleMILLISECONDS_PER_SECOND ( 1000U ) #define mqttexampleMILLISECONDS_PER_TICK ( mqttexampleMILLISECONDS_PER_SECOND / configTICK_RATE_HZ ) +/** + * @brief ALPN (Application-Layer Protocol Negotiation) protocol name for AWS IoT MQTT. + * + * This will be used if democonfigMQTT_BROKER_PORT is configured as 443 for the AWS IoT MQTT broker. + * Please see more details about the ALPN protocol for AWS IoT MQTT endpoint + * in the link below. + * https://aws.amazon.com/blogs/iot/mqtt-with-tls-client-authentication-on-port-443-why-it-is-useful-and-how-it-works/ + */ +#define AWS_IOT_MQTT_ALPN "\x0ex-amzn-mqtt-ca" + +/** + * @brief This is the ALPN (Application-Layer Protocol Negotiation) string + * required by AWS IoT for password-based authentication using TCP port 443. + */ +#define AWS_IOT_CUSTOM_AUTH_ALPN "\x04mqtt" + + /** + * @brief The MQTT metrics string expected by AWS IoT. + */ +#define AWS_IOT_METRICS_STRING \ + "?SDK=" democonfigOS_NAME "&Version=" democonfigOS_VERSION \ + "&Platform=" democonfigHARDWARE_PLATFORM_NAME "&MQTTLib=" democonfigMQTT_LIB + + /** + * @brief The length of the MQTT metrics string expected by AWS IoT. + */ +#define AWS_IOT_METRICS_STRING_LENGTH ( ( uint16_t ) ( sizeof( AWS_IOT_METRICS_STRING ) - 1 ) ) + +#ifdef democonfigCLIENT_USERNAME + + /** + * @brief Append the username with the metrics string if #democonfigCLIENT_USERNAME is defined. + * + * This is to support both metrics reporting and username/password based client + * authentication by AWS IoT. + */ +#define CLIENT_USERNAME_WITH_METRICS democonfigCLIENT_USERNAME AWS_IOT_METRICS_STRING +#endif + + +/** + * Provide default values for undefined configuration settings. + */ +#ifndef democonfigOS_NAME +#define democonfigOS_NAME "FreeRTOS" +#endif + +#ifndef democonfigOS_VERSION +#define democonfigOS_VERSION tskKERNEL_VERSION_NUMBER +#endif + +#ifndef democonfigHARDWARE_PLATFORM_NAME +#define democonfigHARDWARE_PLATFORM_NAME "WinSim" +#endif + +#ifndef democonfigMQTT_LIB +#include "core_mqtt.h" /* Include coreMQTT header for MQTT_LIBRARY_VERSION macro. */ +#define democonfigMQTT_LIB "core-mqtt@"MQTT_LIBRARY_VERSION +#endif + +/** + * @brief Length of client identifier. + */ +#define democonfigCLIENT_IDENTIFIER_LENGTH ( ( uint16_t ) ( sizeof( democonfigCLIENT_IDENTIFIER ) - 1 ) ) + +/** + * @brief Length of MQTT server host name. + */ +#define democonfigBROKER_ENDPOINT_LENGTH ( ( uint16_t ) ( sizeof( democonfigMQTT_BROKER_ENDPOINT ) - 1 ) ) + /*-----------------------------------------------------------*/ /** diff --git a/FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Multitask/demo_config.h b/FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Multitask/demo_config.h index 60dc5fb86..c5ad6298d 100644 --- a/FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Multitask/demo_config.h +++ b/FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Multitask/demo_config.h @@ -273,92 +273,6 @@ extern void vLoggingPrintf( const char * pcFormatString, */ #define MQTT_AGENT_COMMAND_QUEUE_LENGTH 10 - - -/********************************************************************************** -* Error checks and derived values only below here - do not edit below here. -----* -**********************************************************************************/ - - -/* Compile time error for some undefined configs, and provide default values - * for others. */ -#ifndef democonfigMQTT_BROKER_ENDPOINT - #error "Please define democonfigMQTT_BROKER_ENDPOINT in demo_config.h." -#endif - -#ifndef democonfigCLIENT_IDENTIFIER - -/** - * @brief The MQTT client identifier used in this example. Each client identifier - * must be unique so edit as required to ensure no two clients connecting to the - * same broker use the same client identifier. Using a #define is for convenience - * of demonstration only - production devices should use something unique to the - * device that can be read from software - such as a production serial number. - */ - #error "Please define democonfigCLIENT_IDENTIFIER in demo_config.h to something unique for this device." -#endif - - -#if defined( democonfigUSE_TLS ) && ( democonfigUSE_TLS == 1 ) - #ifndef democonfigROOT_CA_PEM - #error "Please define Root CA certificate of the MQTT broker(democonfigROOT_CA_PEM) in demo_config.h." - #endif - -/* If no username is defined, then a client certificate/key is required. */ - #ifndef democonfigCLIENT_USERNAME - -/* - *!!! Please note democonfigCLIENT_PRIVATE_KEY_PEM in used for - *!!! convenience of demonstration only. Production devices should - *!!! store keys securely, such as within a secure element. - */ - - #ifndef democonfigCLIENT_CERTIFICATE_PEM - #error "Please define client certificate(democonfigCLIENT_CERTIFICATE_PEM) in demo_config.h." - #endif - #ifndef democonfigCLIENT_PRIVATE_KEY_PEM - #error "Please define client private key(democonfigCLIENT_PRIVATE_KEY_PEM) in demo_config.h." - #endif - #else - -/* If a username is defined, a client password also would need to be defined for - * client authentication. */ - #ifndef democonfigCLIENT_PASSWORD - #error "Please define client password(democonfigCLIENT_PASSWORD) in demo_config.h for client authentication based on username/password." - #endif - -/* AWS IoT MQTT broker port needs to be 443 for client authentication based on - * username/password. */ - #if defined( democonfigUSE_AWS_IOT_CORE_BROKER ) && democonfigMQTT_BROKER_PORT != 443 - #error "Broker port(democonfigMQTT_BROKER_PORT) should be defined as 443 in demo_config.h for client authentication based on username/password in AWS IoT Core." - #endif - #endif /* ifndef democonfigCLIENT_USERNAME */ - - #ifndef democonfigMQTT_BROKER_PORT - #define democonfigMQTT_BROKER_PORT ( 8883 ) - #endif -#else /* if defined( democonfigUSE_TLS ) && ( democonfigUSE_TLS == 1 ) */ - #ifndef democonfigMQTT_BROKER_PORT - #define democonfigMQTT_BROKER_PORT ( 1883 ) - #endif -#endif /* if defined( democonfigUSE_TLS ) && ( democonfigUSE_TLS == 1 ) */ - -/** - * @brief ALPN (Application-Layer Protocol Negotiation) protocol name for AWS IoT MQTT. - * - * This will be used if democonfigMQTT_BROKER_PORT is configured as 443 for the AWS IoT MQTT broker. - * Please see more details about the ALPN protocol for AWS IoT MQTT endpoint - * in the link below. - * https://aws.amazon.com/blogs/iot/mqtt-with-tls-client-authentication-on-port-443-why-it-is-useful-and-how-it-works/ - */ -#define AWS_IOT_MQTT_ALPN "\x0ex-amzn-mqtt-ca" - -/** - * @brief This is the ALPN (Application-Layer Protocol Negotiation) string - * required by AWS IoT for password-based authentication using TCP port 443. - */ -#define AWS_IOT_CUSTOM_AUTH_ALPN "\x04mqtt" - /** * Provide default values for undefined configuration settings. */ @@ -379,38 +293,4 @@ extern void vLoggingPrintf( const char * pcFormatString, #define democonfigMQTT_LIB "core-mqtt@"MQTT_LIBRARY_VERSION #endif -/** - * @brief The MQTT metrics string expected by AWS IoT. - */ -#define AWS_IOT_METRICS_STRING \ - "?SDK=" democonfigOS_NAME "&Version=" democonfigOS_VERSION \ - "&Platform=" democonfigHARDWARE_PLATFORM_NAME "&MQTTLib=" democonfigMQTT_LIB - -/** - * @brief The length of the MQTT metrics string expected by AWS IoT. - */ -#define AWS_IOT_METRICS_STRING_LENGTH ( ( uint16_t ) ( sizeof( AWS_IOT_METRICS_STRING ) - 1 ) ) - -#ifdef democonfigCLIENT_USERNAME - -/** - * @brief Append the username with the metrics string if #democonfigCLIENT_USERNAME is defined. - * - * This is to support both metrics reporting and username/password based client - * authentication by AWS IoT. - */ - #define CLIENT_USERNAME_WITH_METRICS democonfigCLIENT_USERNAME AWS_IOT_METRICS_STRING -#endif - -/** - * @brief Length of client identifier. - */ -#define democonfigCLIENT_IDENTIFIER_LENGTH ( ( uint16_t ) ( sizeof( democonfigCLIENT_IDENTIFIER ) - 1 ) ) - -/** - * @brief Length of MQTT server host name. - */ -#define democonfigBROKER_ENDPOINT_LENGTH ( ( uint16_t ) ( sizeof( democonfigMQTT_BROKER_ENDPOINT ) - 1 ) ) - - #endif /* DEMO_CONFIG_H */ |