winsim-ota-demos: Move checks out of demo_config.h

Move checks for undefined democonfig settings from demo_config.h to
each demo task file.
pull/842/head
Paul Bartell 3 years ago committed by Paul Bartell
parent 2ffe3de4b5
commit 5d68fdb5cc

@ -323,6 +323,132 @@
/* HTTP buffers used for http request and response. */
#define HTTP_USER_BUFFER_LENGTH ( otaconfigFILE_BLOCK_SIZE + HTTP_HEADER_SIZE_MAX )
/* 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.
*/
#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
#define democonfigMQTT_LIB "core-mqtt@1.0.0"
#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 ) )
/*---------------------------------------------------------*/
/**
@ -1573,7 +1699,6 @@ static BaseType_t connectToS3Server(NetworkContext_t* pxNetworkContext,
memcpy( acServerHost, pcAddress, xServerHostLength );
acServerHost[ xServerHostLength ] = '\0';
}
}
if( xHTTPStatus == HTTPSuccess )

@ -323,141 +323,4 @@ extern void vLoggingPrintf( const char * pcFormatString,
*/
#define democonfigDEMO_STACKSIZE configMINIMAL_STACK_SIZE
/**********************************************************************************
* 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.
*/
#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
#define democonfigMQTT_LIB "core-mqtt@1.0.0"
#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 */

@ -291,6 +291,133 @@
*/
#define OTA_SUSPEND_TIMEOUT_MS ( 10000U )
/* 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.
*/
#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
#define democonfigMQTT_LIB "core-mqtt@1.0.0"
#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 ) )
/*---------------------------------------------------------*/
/**
@ -326,7 +453,6 @@ struct NetworkContext
TlsTransportParams_t * pParams;
};
/*---------------------------------------------------------*/
/**
@ -976,7 +1102,6 @@ static void prvMQTTSubscribeCompleteCallback( MQTTAgentCommandContext_t* pxComma
static void prvMQTTUnsubscribeCompleteCallback( MQTTAgentCommandContext_t * pxCommandContext,
MQTTAgentReturnInfo_t * pxReturnInfo )
{
/* Store the result in the application defined context so the task that
* initiated the publish can check the operation's status. */
pxCommandContext->xReturnStatus = pxReturnInfo->returnCode;

@ -273,141 +273,4 @@ extern void vLoggingPrintf( const char * pcFormatString,
*/
#define democonfigDEMO_STACKSIZE configMINIMAL_STACK_SIZE
/**********************************************************************************
* 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.
*/
#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
#define democonfigMQTT_LIB "core-mqtt@1.0.0"
#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 */

Loading…
Cancel
Save