From 5d68fdb5cc0570d0a75b37c1451d6869bb19dc15 Mon Sep 17 00:00:00 2001 From: Paul Bartell Date: Tue, 16 Aug 2022 14:46:32 -0700 Subject: [PATCH] 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. --- .../DemoTasks/OtaOverHttpDemoExample.c | 789 ++++++++++-------- .../Ota_Over_Http_Demo/demo_config.h | 167 +--- .../DemoTasks/OtaOverMqttDemoExample.c | 517 +++++++----- .../Ota_Over_Mqtt_Demo/demo_config.h | 149 +--- 4 files changed, 799 insertions(+), 823 deletions(-) diff --git a/FreeRTOS-Plus/Demo/AWS/Ota_Windows_Simulator/Ota_Over_Http_Demo/DemoTasks/OtaOverHttpDemoExample.c b/FreeRTOS-Plus/Demo/AWS/Ota_Windows_Simulator/Ota_Over_Http_Demo/DemoTasks/OtaOverHttpDemoExample.c index 3f6bb25ea9..000e3dfea6 100644 --- a/FreeRTOS-Plus/Demo/AWS/Ota_Windows_Simulator/Ota_Over_Http_Demo/DemoTasks/OtaOverHttpDemoExample.c +++ b/FreeRTOS-Plus/Demo/AWS/Ota_Windows_Simulator/Ota_Over_Http_Demo/DemoTasks/OtaOverHttpDemoExample.c @@ -32,8 +32,8 @@ * and coreHTTP library. It creates an OTA agent task which manages the OTA firmware update * for the device. The example also provides implementations to subscribe, publish, * from an MQTT broker and receive data from s3 service using presigned url. The implementation - * uses coreMQTT agent which manages thread safety of the MQTT operations and allows OTA agent to - * share the same MQTT broker connection with other tasks. OTA agent invokes the callback + * uses coreMQTT agent which manages thread safety of the MQTT operations and allows OTA agent to + * share the same MQTT broker connection with other tasks. OTA agent invokes the callback * implementations to publish job related control information as well as request and receive chunks * of pre-signed firmware image from the S3 service. * @@ -97,38 +97,38 @@ /** * @brief The maximum size of the file paths used in the demo. */ -#define otaexampleMAX_FILE_PATH_SIZE ( 260 ) +#define otaexampleMAX_FILE_PATH_SIZE ( 260 ) /** * @brief The maximum size of the stream name required for downloading update file * from streaming service. */ -#define otaexampleMAX_STREAM_NAME_SIZE ( 128 ) +#define otaexampleMAX_STREAM_NAME_SIZE ( 128 ) /** * @brief The delay used in the OTA demo task to periodically output the OTA * statistics like number of packets received, dropped, processed and queued per connection. */ -#define otaexampleTASK_DELAY_MS ( 1000U ) +#define otaexampleTASK_DELAY_MS ( 1000U ) /** * @brief The maximum time for which OTA demo waits for an MQTT operation to be complete. * This involves receiving an acknowledgment for broker for SUBSCRIBE, UNSUBSCRIBE and non * QOS0 publishes. */ -#define otaexampleMQTT_TIMEOUT_MS ( 5000U ) +#define otaexampleMQTT_TIMEOUT_MS ( 5000U ) - /** - * @brief HTTP response codes used in this demo. - */ -#define HTTP_RESPONSE_PARTIAL_CONTENT ( 206 ) -#define HTTP_RESPONSE_BAD_REQUEST ( 400 ) -#define HTTP_RESPONSE_FORBIDDEN ( 403 ) -#define HTTP_RESPONSE_NOT_FOUND ( 404 ) +/** + * @brief HTTP response codes used in this demo. + */ +#define HTTP_RESPONSE_PARTIAL_CONTENT ( 206 ) +#define HTTP_RESPONSE_BAD_REQUEST ( 400 ) +#define HTTP_RESPONSE_FORBIDDEN ( 403 ) +#define HTTP_RESPONSE_NOT_FOUND ( 404 ) - /** - * @brief Transport timeout in milliseconds for transport send and receive. - */ +/** + * @brief Transport timeout in milliseconds for transport send and receive. + */ #define otaexampleHTTPS_TRANSPORT_SEND_RECV_TIMEOUT_MS ( 2000U ) /** @@ -139,19 +139,19 @@ * filter is used to match incoming packet received and route them to OTA. * Thing name is not needed for this matching. */ -#define OTA_TOPIC_PREFIX "$aws/things/+/" +#define OTA_TOPIC_PREFIX "$aws/things/+/" /** * @brief Wildcard topic filter for job notification. * The filter is used to match the constructed job notify topic filter from OTA agent and register * appropriate callback for it. */ -#define OTA_JOB_NOTIFY_TOPIC_FILTER OTA_TOPIC_PREFIX "jobs/notify-next" +#define OTA_JOB_NOTIFY_TOPIC_FILTER OTA_TOPIC_PREFIX "jobs/notify-next" /** * @brief Length of job notification topic filter. */ -#define OTA_JOB_NOTIFY_TOPIC_FILTER_LENGTH ( ( uint16_t ) ( sizeof( OTA_JOB_NOTIFY_TOPIC_FILTER ) - 1 ) ) +#define OTA_JOB_NOTIFY_TOPIC_FILTER_LENGTH ( ( uint16_t ) ( sizeof( OTA_JOB_NOTIFY_TOPIC_FILTER ) - 1 ) ) /** * @brief Wildcard topic filter for matching job response messages. @@ -159,12 +159,12 @@ * topic filter is a reserved topic which is not subscribed with MQTT broker. * */ -#define OTA_JOB_ACCEPTED_RESPONSE_TOPIC_FILTER OTA_TOPIC_PREFIX "jobs/$next/get/accepted" +#define OTA_JOB_ACCEPTED_RESPONSE_TOPIC_FILTER OTA_TOPIC_PREFIX "jobs/$next/get/accepted" /** * @brief Length of job accepted response topic filter. */ -#define OTA_JOB_ACCEPTED_RESPONSE_TOPIC_FILTER_LENGTH ( ( uint16_t ) ( sizeof( OTA_JOB_ACCEPTED_RESPONSE_TOPIC_FILTER ) - 1 ) ) +#define OTA_JOB_ACCEPTED_RESPONSE_TOPIC_FILTER_LENGTH ( ( uint16_t ) ( sizeof( OTA_JOB_ACCEPTED_RESPONSE_TOPIC_FILTER ) - 1 ) ) /** @@ -185,65 +185,65 @@ */ #define OTA_TOPIC_CLIENT_IDENTIFIER_START_IDX ( 12U ) - /** - * @brief Default topic filter for OTA. - * This is used to route all the packets for OTA reserved topics which OTA agent has not subscribed for. - */ -#define OTA_DEFAULT_TOPIC_FILTER OTA_TOPIC_PREFIX "jobs/#" +/** + * @brief Default topic filter for OTA. + * This is used to route all the packets for OTA reserved topics which OTA agent has not subscribed for. + */ +#define OTA_DEFAULT_TOPIC_FILTER OTA_TOPIC_PREFIX "jobs/#" - /** - * @brief Length of default topic filter. - */ -#define OTA_DEFAULT_TOPIC_FILTER_LENGTH ( ( uint16_t ) ( sizeof( OTA_DEFAULT_TOPIC_FILTER ) - 1 ) ) +/** + * @brief Length of default topic filter. + */ +#define OTA_DEFAULT_TOPIC_FILTER_LENGTH ( ( uint16_t ) ( sizeof( OTA_DEFAULT_TOPIC_FILTER ) - 1 ) ) /** * @brief Used to clear bits in a task's notification value. */ #define otaexampleMAX_UINT32 ( 0xffffffff ) - /** - * @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. - */ -#define MQTT_AGENT_NETWORK_BUFFER_SIZE ( 10240 ) +/** + * @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. + */ +#define MQTT_AGENT_NETWORK_BUFFER_SIZE ( 10240 ) - /** - * @brief The length of the queue used to hold commands for the agent. - */ -#define MQTT_AGENT_COMMAND_QUEUE_LENGTH ( 10 ) +/** + * @brief The length of the queue used to hold commands for the agent. + */ +#define MQTT_AGENT_COMMAND_QUEUE_LENGTH ( 10 ) /** * @brief The maximum amount of time in milliseconds to wait for the commands * to be posted to the MQTT agent should the MQTT agent's command queue be full. * Tasks wait in the Blocked state, so don't use any CPU time. */ -#define MQTT_AGENT_SEND_BLOCK_TIME_MS ( 200U ) +#define MQTT_AGENT_SEND_BLOCK_TIME_MS ( 200U ) - /** - * @brief This demo uses task notifications to signal tasks from MQTT callback - * functions. mqttexampleMS_TO_WAIT_FOR_NOTIFICATION defines the time, in ticks, - * to wait for such a callback. - */ -#define MQTT_AGENT_MS_TO_WAIT_FOR_NOTIFICATION ( 5000U ) +/** + * @brief This demo uses task notifications to signal tasks from MQTT callback + * functions. mqttexampleMS_TO_WAIT_FOR_NOTIFICATION defines the time, in ticks, + * to wait for such a callback. + */ +#define MQTT_AGENT_MS_TO_WAIT_FOR_NOTIFICATION ( 5000U ) /** * @brief The maximum number of retries for network operation with server. */ -#define RETRY_MAX_ATTEMPTS ( 5U ) +#define RETRY_MAX_ATTEMPTS ( 5U ) /** * @brief The maximum back-off delay (in milliseconds) for retrying failed operation * with server. */ -#define RETRY_MAX_BACKOFF_DELAY_MS ( 5000U ) +#define RETRY_MAX_BACKOFF_DELAY_MS ( 5000U ) /** * @brief The base back-off delay (in milliseconds) to use for network operation retry * attempts. */ -#define RETRY_BACKOFF_BASE_MS ( 500U ) +#define RETRY_BACKOFF_BASE_MS ( 500U ) /** * @brief The maximum time interval in seconds which is allowed to elapse @@ -261,33 +261,33 @@ */ #define otaexampleTRANSPORT_SEND_RECV_TIMEOUT_MS ( 750 ) - /** - * @brief Timeout for receiving CONNACK after sending an MQTT CONNECT packet. - * Defined in milliseconds. - */ -#define otaexampleCONNACK_RECV_TIMEOUT_MS ( 1000U ) +/** + * @brief Timeout for receiving CONNACK after sending an MQTT CONNECT packet. + * Defined in milliseconds. + */ +#define otaexampleCONNACK_RECV_TIMEOUT_MS ( 1000U ) /** * @brief Stack size required for MQTT agent task. * MQTT agent task takes care of TLS connection and reconnection, keeping task stack size * to high enough required for TLS connection. */ -#define MQTT_AGENT_TASK_STACK_SIZE ( 6000U ) +#define MQTT_AGENT_TASK_STACK_SIZE ( 6000U ) /** * @brief Priority required for OTA statistics task. */ -#define MQTT_AGENT_TASK_PRIORITY ( tskIDLE_PRIORITY ) +#define MQTT_AGENT_TASK_PRIORITY ( tskIDLE_PRIORITY ) /** * @brief Stack size required for OTA agent task. */ -#define OTA_AGENT_TASK_STACK_SIZE ( 10000U ) +#define OTA_AGENT_TASK_STACK_SIZE ( 10000U ) /** * @brief Priority required for OTA agent task. */ -#define OTA_AGENT_TASK_PRIORITY ( tskIDLE_PRIORITY ) +#define OTA_AGENT_TASK_PRIORITY ( tskIDLE_PRIORITY ) /** * @brief Used to convert times to/from ticks and milliseconds. @@ -295,33 +295,159 @@ #define otaexampleMILLISECONDS_PER_SECOND ( 1000U ) #define otaexampleMILLISECONDS_PER_TICK ( otaexampleMILLISECONDS_PER_SECOND / configTICK_RATE_HZ ) - /** - * @brief The timeout for waiting for the agent to get suspended after closing the - * connection. - * - * Timeout value should be large enough for OTA agent to finish any pending MQTT operations - * and suspend itself. - * - */ -#define OTA_SUSPEND_TIMEOUT_MS ( 10000U ) +/** + * @brief The timeout for waiting for the agent to get suspended after closing the + * connection. + * + * Timeout value should be large enough for OTA agent to finish any pending MQTT operations + * and suspend itself. + * + */ +#define OTA_SUSPEND_TIMEOUT_MS ( 10000U ) /** * @brief Maximum size of the url. */ -#define OTA_MAX_URL_SIZE ( 2048U ) +#define OTA_MAX_URL_SIZE ( 2048U ) /** * @brief Maximum size of the auth scheme. */ -#define OTA_MAX_AUTH_SCHEME_SIZE ( 48U ) +#define OTA_MAX_AUTH_SCHEME_SIZE ( 48U ) /** * @brief The maximum size of the HTTP header. */ -#define HTTP_HEADER_SIZE_MAX ( 1024U ) +#define HTTP_HEADER_SIZE_MAX ( 1024U ) /* HTTP buffers used for http request and response. */ -#define HTTP_USER_BUFFER_LENGTH ( otaconfigFILE_BLOCK_SIZE + HTTP_HEADER_SIZE_MAX ) +#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 ) ) /*---------------------------------------------------------*/ @@ -397,7 +523,7 @@ static NetworkContext_t xNetworkContextHttp; * @note S3_PRESIGNED_GET_URL_LENGTH is set as the array length here as the * length of the host name string cannot exceed this value. */ -static char acServerHost[256]; +static char acServerHost[ 256 ]; /** * @brief The length of the host address found in the pre-signed URL. @@ -412,7 +538,7 @@ static size_t xServerHostLength; * response after the HTTP request is sent out. However, the user can also * decide to use separate buffers for storing the HTTP request and response. */ -static uint8_t aucHttpUserBuffer[HTTP_USER_BUFFER_LENGTH]; +static uint8_t aucHttpUserBuffer[ HTTP_USER_BUFFER_LENGTH ]; /** * @brief The parameters for the network context using a TLS channel. @@ -468,12 +594,12 @@ static uint8_t bitmap[ OTA_MAX_BLOCK_BITMAP_SIZE ]; /** * @brief Certificate File path buffer. */ -static uint8_t updateUrl[OTA_MAX_URL_SIZE]; +static uint8_t updateUrl[ OTA_MAX_URL_SIZE ]; /** * @brief Auth scheme buffer. */ -static uint8_t authScheme[OTA_MAX_URL_SIZE]; +static uint8_t authScheme[ OTA_MAX_URL_SIZE ]; /** @@ -501,7 +627,7 @@ static TransportInterface_t xTransportInterfaceHttp; /** * @brief The location of the path within the pre-signed URL. */ -static const char* pcPath; +static const char * pcPath; /*---------------------------------------------------------*/ @@ -513,7 +639,7 @@ static const char* pcPath; * * @param[in] pParam Can be used to pass down functionality to the agent task */ -static void prvMQTTAgentTask(void* pParam); +static void prvMQTTAgentTask( void * pParam ); /** * @brief Function used by OTA agent to publish control messages to the MQTT broker. @@ -621,14 +747,14 @@ static void prvOTAAgentTask( void * pvParam ); * It reports OTA update statistics (which includes number of blocks received, processed and dropped), * at regular intervals. */ -static void vOtaDemoTask( void* pvParam ); +static void vOtaDemoTask( void * pvParam ); /** * @brief The function which implements the flow for OTA demo. * * @return pdPASS if success or pdFAIL. */ -static BaseType_t prvRunOTADemo(void); +static BaseType_t prvRunOTADemo( void ); /** * @brief Callback registered with the OTA library that notifies the OTA agent @@ -670,7 +796,7 @@ static void prvMqttDefaultCallback( void * pvIncomingPublishCallbackContext, * @brief Attempt to connect to the MQTT broker. * */ -static void prvConnectToMQTTBroker(void); +static void prvConnectToMQTTBroker( void ); /** * @brief Retry logic to establish a connection to the MQTT broker. @@ -681,14 +807,14 @@ static void prvConnectToMQTTBroker(void); * @param[in] pNetworkContext Network context to connect on. * @return int pdFALSE if connection failed after retries. */ -static BaseType_t prvSocketConnect(NetworkContext_t* pNetworkContext); +static BaseType_t prvSocketConnect( NetworkContext_t * pNetworkContext ); /** * @brief Disconnects from the MQTT broker. * Initiates an MQTT disconnect and then teardown underlying TCP connection. * */ -static void prvDisconnectFromMQTTBroker(void); +static void prvDisconnectFromMQTTBroker( void ); /** * @brief Initializes an MQTT context, including transport interface and @@ -696,7 +822,7 @@ static void prvDisconnectFromMQTTBroker(void); * * @return `MQTTSuccess` if the initialization succeeds, else `MQTTBadParameter`. */ -static MQTTStatus_t prvMqttInit(void); +static MQTTStatus_t prvMqttInit( void ); /** * @brief Sends an MQTT Connect packet over the already connected TCP socket. @@ -716,22 +842,22 @@ static MQTTStatus_t prvMQTTConnect( bool xCleanSession ); * @param[in] topicFilterLength length of the topic filter. * */ -static void prvRegisterOTACallback(const char* pTopicFilter, - uint16_t topicFilterLength); +static void prvRegisterOTACallback( const char * pTopicFilter, + uint16_t topicFilterLength ); /** * @brief Suspend OTA demo. * * @return pPASS or pdFAIL. */ -static BaseType_t prvSuspendOTA(void); +static BaseType_t prvSuspendOTA( void ); /** * @brief Resume OTA demo. * * @return pPASS or pdFAIL. */ -static BaseType_t prvResumeOTA(void); +static BaseType_t prvResumeOTA( void ); /** * @brief Set OTA interfaces. @@ -740,7 +866,7 @@ static BaseType_t prvResumeOTA(void); * * @return None. */ -static void setOtaInterfaces(OtaInterfaces_t* pOtaInterfaces); +static void setOtaInterfaces( OtaInterfaces_t * pOtaInterfaces ); /** * @brief Structure containing all application allocated buffers used by the OTA agent. @@ -756,10 +882,10 @@ static OtaAppBuffer_t otaBuffer = .decodeMemorySize = ( 1U << otaconfigLOG2_FILE_BLOCK_SIZE ), .pFileBitmap = bitmap, .fileBitmapSize = OTA_MAX_BLOCK_BITMAP_SIZE, - .pUrl = updateUrl, - .urlSize = OTA_MAX_URL_SIZE, - .pAuthScheme = authScheme, - .authSchemeSize = OTA_MAX_AUTH_SCHEME_SIZE + .pUrl = updateUrl, + .urlSize = OTA_MAX_URL_SIZE, + .pAuthScheme = authScheme, + .authSchemeSize = OTA_MAX_AUTH_SCHEME_SIZE }; /** @@ -1002,9 +1128,9 @@ static void prvMqttDataCallback( void * pvIncomingPublishCallbackContext, pxData = prvOTAEventBufferGet(); - if(pxData != NULL ) + if( pxData != NULL ) { - memcpy(pxData->data, pxPublishInfo->pPayload, pxPublishInfo->payloadLength ); + memcpy( pxData->data, pxPublishInfo->pPayload, pxPublishInfo->payloadLength ); pxData->dataLength = pxPublishInfo->payloadLength; eventMsg.eventId = OtaAgentEventReceivedFileBlock; eventMsg.pEventData = pxData; @@ -1031,45 +1157,45 @@ static void prvCommandCallback( MQTTAgentCommandContext_t * pxCommandContext, } } -static void prvMQTTSubscribeCompleteCallback( MQTTAgentCommandContext_t* pxCommandContext, - MQTTAgentReturnInfo_t* pxReturnInfo ) +static void prvMQTTSubscribeCompleteCallback( MQTTAgentCommandContext_t * pxCommandContext, + MQTTAgentReturnInfo_t * pxReturnInfo ) { - MQTTAgentSubscribeArgs_t* pSubsribeArgs; + MQTTAgentSubscribeArgs_t * pSubsribeArgs; - if (pxReturnInfo->returnCode == MQTTSuccess) + if( pxReturnInfo->returnCode == MQTTSuccess ) { - pSubsribeArgs = (MQTTAgentSubscribeArgs_t*)(pxCommandContext->pArgs); - prvRegisterOTACallback(pSubsribeArgs->pSubscribeInfo->pTopicFilter, pSubsribeArgs->pSubscribeInfo->topicFilterLength); + pSubsribeArgs = ( MQTTAgentSubscribeArgs_t * ) ( pxCommandContext->pArgs ); + prvRegisterOTACallback( pSubsribeArgs->pSubscribeInfo->pTopicFilter, pSubsribeArgs->pSubscribeInfo->topicFilterLength ); } /* 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; - if (pxCommandContext->xTaskToNotify != NULL) + if( pxCommandContext->xTaskToNotify != NULL ) { /* Send the context's ulNotificationValue as the notification value so * the receiving task can check the value it set in the context matches * the value it receives in the notification. */ - xTaskNotify(pxCommandContext->xTaskToNotify, (uint32_t)(pxReturnInfo->returnCode), eSetValueWithOverwrite); + xTaskNotify( pxCommandContext->xTaskToNotify, ( uint32_t ) ( pxReturnInfo->returnCode ), eSetValueWithOverwrite ); } } /*-----------------------------------------------------------*/ -static void prvMQTTUnsubscribeCompleteCallback( MQTTAgentCommandContext_t* pxCommandContext, - MQTTAgentReturnInfo_t* pxReturnInfo ) +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; - if (pxCommandContext->xTaskToNotify != NULL) + if( pxCommandContext->xTaskToNotify != NULL ) { /* Send the context's ulNotificationValue as the notification value so * the receiving task can check the value it set in the context matches * the value it receives in the notification. */ - xTaskNotify(pxCommandContext->xTaskToNotify, (uint32_t)(pxReturnInfo->returnCode), eSetValueWithOverwrite); + xTaskNotify( pxCommandContext->xTaskToNotify, ( uint32_t ) ( pxReturnInfo->returnCode ), eSetValueWithOverwrite ); } } @@ -1141,15 +1267,15 @@ static void prvSubscriptionCommandCallback( void * pxCommandContext, for( xIndex = 0; xIndex < pxSubscribeArgs->numSubscriptions; xIndex++ ) { /* This demo doesn't attempt to resubscribe in the event that a SUBACK failed. */ - if( pxReturnInfo->pSubackCodes[xIndex] == MQTTSubAckFailure ) + if( pxReturnInfo->pSubackCodes[ xIndex ] == MQTTSubAckFailure ) { LogError( ( "Failed to resubscribe to topic %.*s.", - pxSubscribeArgs->pSubscribeInfo[xIndex].topicFilterLength, - pxSubscribeArgs->pSubscribeInfo[xIndex].pTopicFilter ) ); + pxSubscribeArgs->pSubscribeInfo[ xIndex ].topicFilterLength, + pxSubscribeArgs->pSubscribeInfo[ xIndex ].pTopicFilter ) ); /* Remove subscription callback for unsubscribe. */ removeSubscription( xGlobalSubscriptionList, - pxSubscribeArgs->pSubscribeInfo[xIndex].pTopicFilter, - pxSubscribeArgs->pSubscribeInfo[xIndex].topicFilterLength ); + pxSubscribeArgs->pSubscribeInfo[ xIndex ].pTopicFilter, + pxSubscribeArgs->pSubscribeInfo[ xIndex ].topicFilterLength ); } } @@ -1357,12 +1483,12 @@ static BaseType_t prvSocketConnect( NetworkContext_t * pxNetworkContext ) /*-----------------------------------------------------------*/ -static BaseType_t prvSocketDisconnect(NetworkContext_t* pxNetworkContext) +static BaseType_t prvSocketDisconnect( NetworkContext_t * pxNetworkContext ) { BaseType_t xDisconnected = pdFAIL; - LogInfo(("Disconnecting TLS connection.\n")); - TLS_FreeRTOS_Disconnect(pxNetworkContext); + LogInfo( ( "Disconnecting TLS connection.\n" ) ); + TLS_FreeRTOS_Disconnect( pxNetworkContext ); xDisconnected = pdPASS; return xDisconnected; @@ -1386,7 +1512,7 @@ static MQTTStatus_t prvMQTTInit( void ) LogDebug( ( "Creating command queue." ) ); xCommandQueue.queue = xQueueCreateStatic( MQTT_AGENT_COMMAND_QUEUE_LENGTH, - sizeof(MQTTAgentCommand_t* ), + sizeof( MQTTAgentCommand_t * ), staticQueueStorageArea, &staticQueueStructure ); configASSERT( xCommandQueue.queue ); @@ -1539,8 +1665,8 @@ static void prvDisconnectFromMQTTBroker( void ) prvSocketDisconnect( &xNetworkContextMqtt ); } -static BaseType_t connectToS3Server(NetworkContext_t* pxNetworkContext, - const char* pcUrl) +static BaseType_t connectToS3Server( NetworkContext_t * pxNetworkContext, + const char * pcUrl ) { TlsTransportStatus_t xNetworkStatus; NetworkCredentials_t xNetworkCredentials = { 0 }; @@ -1548,57 +1674,56 @@ static BaseType_t connectToS3Server(NetworkContext_t* pxNetworkContext, HTTPStatus_t xHTTPStatus = HTTPSuccess; /* The location of the host address within the pre-signed URL. */ - const char* pcAddress = NULL; + const char * pcAddress = NULL; - configASSERT(pxNetworkContext != NULL); + configASSERT( pxNetworkContext != NULL ); /* Retrieve the address location and length from S3_PRESIGNED_GET_URL. */ - if (pcUrl != NULL) + if( pcUrl != NULL ) { /* Retrieve the address location and length from S3_PRESIGNED_GET_URL. */ - xHTTPStatus = getUrlAddress(pcUrl, - strlen(pcUrl), - &pcAddress, - &xServerHostLength); + xHTTPStatus = getUrlAddress( pcUrl, + strlen( pcUrl ), + &pcAddress, + &xServerHostLength ); - if (xHTTPStatus != HTTPSuccess) + if( xHTTPStatus != HTTPSuccess ) { - LogError(("URL %s parsing failed. Error code: %d", - pcUrl, - xHTTPStatus)); + LogError( ( "URL %s parsing failed. Error code: %d", + pcUrl, + xHTTPStatus ) ); } else { /* serverHost should consist only of the host address. */ - memcpy(acServerHost, pcAddress, xServerHostLength); - acServerHost[xServerHostLength] = '\0'; + memcpy( acServerHost, pcAddress, xServerHostLength ); + acServerHost[ xServerHostLength ] = '\0'; } - } - if (xHTTPStatus == HTTPSuccess) + if( xHTTPStatus == HTTPSuccess ) { xNetworkCredentials.disableSni = democonfigDISABLE_SNI; /* Set the credentials for establishing a TLS connection. */ - xNetworkCredentials.pRootCa = (const unsigned char*)democonfigHTTPS_ROOT_CA_PEM; - xNetworkCredentials.rootCaSize = sizeof(democonfigHTTPS_ROOT_CA_PEM); + xNetworkCredentials.pRootCa = ( const unsigned char * ) democonfigHTTPS_ROOT_CA_PEM; + xNetworkCredentials.rootCaSize = sizeof( democonfigHTTPS_ROOT_CA_PEM ); /* Establish a TLS session with the HTTP server. This example connects * to the server host located in democonfigPRESIGNED_GET_URL and * democonfigHTTPS_PORT in demo_config.h. */ - LogInfo(("Establishing a TLS session with %s:%d.", - acServerHost, - democonfigHTTPS_PORT)); + LogInfo( ( "Establishing a TLS session with %s:%d.", + acServerHost, + democonfigHTTPS_PORT ) ); /* Attempt to create a server-authenticated TLS connection. */ - xNetworkStatus = TLS_FreeRTOS_Connect(pxNetworkContext, - acServerHost, - democonfigHTTPS_PORT, - &xNetworkCredentials, - otaexampleTRANSPORT_SEND_RECV_TIMEOUT_MS, - otaexampleTRANSPORT_SEND_RECV_TIMEOUT_MS); - - if (xNetworkStatus == TLS_TRANSPORT_SUCCESS) + xNetworkStatus = TLS_FreeRTOS_Connect( pxNetworkContext, + acServerHost, + democonfigHTTPS_PORT, + &xNetworkCredentials, + otaexampleTRANSPORT_SEND_RECV_TIMEOUT_MS, + otaexampleTRANSPORT_SEND_RECV_TIMEOUT_MS ); + + if( xNetworkStatus == TLS_TRANSPORT_SUCCESS ) { xStatus = pdPASS; } @@ -1609,64 +1734,64 @@ static BaseType_t connectToS3Server(NetworkContext_t* pxNetworkContext, /*-----------------------------------------------------------*/ -static OtaHttpStatus_t handleHttpResponse(const HTTPResponse_t* pResponse) +static OtaHttpStatus_t handleHttpResponse( const HTTPResponse_t * pResponse ) { /* Return error code. */ OtaHttpStatus_t ret = OtaHttpRequestFailed; - OtaEventData_t* pData; + OtaEventData_t * pData; OtaEventMsg_t eventMsg = { 0 }; - switch (pResponse->statusCode) + switch( pResponse->statusCode ) { - case HTTP_RESPONSE_PARTIAL_CONTENT: - /* Get buffer to send event & data. */ - pData = prvOTAEventBufferGet(); + case HTTP_RESPONSE_PARTIAL_CONTENT: + /* Get buffer to send event & data. */ + pData = prvOTAEventBufferGet(); - if (pData != NULL) - { - /* Get the data from response buffer. */ - memcpy(pData->data, pResponse->pBody, pResponse->bodyLen); - pData->dataLength = pResponse->bodyLen; + if( pData != NULL ) + { + /* Get the data from response buffer. */ + memcpy( pData->data, pResponse->pBody, pResponse->bodyLen ); + pData->dataLength = pResponse->bodyLen; - /* Send job document received event. */ - eventMsg.eventId = OtaAgentEventReceivedFileBlock; - eventMsg.pEventData = pData; - OTA_SignalEvent(&eventMsg); + /* Send job document received event. */ + eventMsg.eventId = OtaAgentEventReceivedFileBlock; + eventMsg.pEventData = pData; + OTA_SignalEvent( &eventMsg ); - ret = OtaHttpSuccess; - } - else - { - LogError(("Error: No OTA data buffers available.")); + ret = OtaHttpSuccess; + } + else + { + LogError( ( "Error: No OTA data buffers available." ) ); - ret = OtaHttpRequestFailed; - } + ret = OtaHttpRequestFailed; + } - break; + break; - case HTTP_RESPONSE_BAD_REQUEST: - case HTTP_RESPONSE_FORBIDDEN: - case HTTP_RESPONSE_NOT_FOUND: - /* Request the job document to get new url. */ - eventMsg.eventId = OtaAgentEventRequestJobDocument; - eventMsg.pEventData = NULL; - OTA_SignalEvent(&eventMsg); + case HTTP_RESPONSE_BAD_REQUEST: + case HTTP_RESPONSE_FORBIDDEN: + case HTTP_RESPONSE_NOT_FOUND: + /* Request the job document to get new url. */ + eventMsg.eventId = OtaAgentEventRequestJobDocument; + eventMsg.pEventData = NULL; + OTA_SignalEvent( &eventMsg ); - ret = OtaHttpSuccess; - break; + ret = OtaHttpSuccess; + break; - default: - LogError(("Unhandled http response code: =%d.", - pResponse->statusCode)); + default: + LogError( ( "Unhandled http response code: =%d.", + pResponse->statusCode ) ); - ret = OtaHttpRequestFailed; + ret = OtaHttpRequestFailed; } return ret; } -static OtaHttpStatus_t httpInit(char* pUrl) +static OtaHttpStatus_t httpInit( char * pUrl ) { /* OTA lib return error code. */ OtaHttpStatus_t ret = OtaHttpSuccess; @@ -1685,7 +1810,7 @@ static OtaHttpStatus_t httpInit(char* pUrl) size_t xPathLen = 0; /* Establish HTTPs connection */ - LogInfo(("Performing TLS handshake on top of the TCP connection.")); + LogInfo( ( "Performing TLS handshake on top of the TCP connection." ) ); xNetworkContextHttp.pParams = &xTlsTransportParamsHttps; @@ -1694,12 +1819,12 @@ static OtaHttpStatus_t httpInit(char* pUrl) * attempts are reached or maximum timeout value is reached. The function * returns EXIT_FAILURE if the TCP connection cannot be established to * broker after configured number of attempts. */ - xReturnStatus = connectToS3Server(&xNetworkContextHttp, pUrl); + xReturnStatus = connectToS3Server( &xNetworkContextHttp, pUrl ); - if (xReturnStatus == pdPASS ) + if( xReturnStatus == pdPASS ) { /* Define the transport interface. */ - (void)memset(&xTransportInterfaceHttp, 0, sizeof(xTransportInterfaceHttp)); + ( void ) memset( &xTransportInterfaceHttp, 0, sizeof( xTransportInterfaceHttp ) ); /* Define the transport interface. */ xTransportInterfaceHttp.pNetworkContext = &xNetworkContextHttp; xTransportInterfaceHttp.send = TLS_FreeRTOS_send; @@ -1708,19 +1833,19 @@ static OtaHttpStatus_t httpInit(char* pUrl) /* Retrieve the path location from url. This * function returns the length of the path without the query into * pathLen, which is left unused in this demo. */ - httpStatus = getUrlPath(pUrl, - strlen(pUrl), - &pcPath, - &xPathLen); + httpStatus = getUrlPath( pUrl, + strlen( pUrl ), + &pcPath, + &xPathLen ); - ret = (httpStatus == HTTPSuccess) ? OtaHttpSuccess : OtaHttpInitFailed; + ret = ( httpStatus == HTTPSuccess ) ? OtaHttpSuccess : OtaHttpInitFailed; } else { /* Log an error to indicate connection failure after all * reconnect attempts are over. */ - LogError(("Failed to connect to HTTP server %s.", - acServerHost)); + LogError( ( "Failed to connect to HTTP server %s.", + acServerHost ) ); ret = OtaHttpInitFailed; } @@ -1728,8 +1853,8 @@ static OtaHttpStatus_t httpInit(char* pUrl) return ret; } -static OtaHttpStatus_t httpRequest(uint32_t rangeStart, - uint32_t rangeEnd) +static OtaHttpStatus_t httpRequest( uint32_t rangeStart, + uint32_t rangeEnd ) { /* OTA lib return error code. */ OtaHttpStatus_t ret = OtaHttpSuccess; @@ -1749,17 +1874,17 @@ static OtaHttpStatus_t httpRequest(uint32_t rangeStart, bool reconnectRequired = false; /* Initialize all HTTP Client library API structs to 0. */ - (void)memset(&requestInfo, 0, sizeof(requestInfo)); - (void)memset(&response, 0, sizeof(response)); - (void)memset(&requestHeaders, 0, sizeof(requestHeaders)); + ( void ) memset( &requestInfo, 0, sizeof( requestInfo ) ); + ( void ) memset( &response, 0, sizeof( response ) ); + ( void ) memset( &requestHeaders, 0, sizeof( requestHeaders ) ); /* Initialize the request object. */ requestInfo.pHost = acServerHost; requestInfo.hostLen = xServerHostLength; requestInfo.pMethod = HTTP_METHOD_GET; - requestInfo.methodLen = sizeof(HTTP_METHOD_GET) - 1; + requestInfo.methodLen = sizeof( HTTP_METHOD_GET ) - 1; requestInfo.pPath = pcPath; - requestInfo.pathLen = strlen(pcPath); + requestInfo.pathLen = strlen( pcPath ); /* Set "Connection" HTTP header to "keep-alive" so that multiple requests * can be sent over the same established TCP connection. */ @@ -1769,12 +1894,12 @@ static OtaHttpStatus_t httpRequest(uint32_t rangeStart, requestHeaders.pBuffer = aucHttpUserBuffer; requestHeaders.bufferLen = HTTP_USER_BUFFER_LENGTH; - httpStatus = HTTPClient_InitializeRequestHeaders(&requestHeaders, - &requestInfo); + httpStatus = HTTPClient_InitializeRequestHeaders( &requestHeaders, + &requestInfo ); - HTTPClient_AddRangeHeader(&requestHeaders, rangeStart, rangeEnd); + HTTPClient_AddRangeHeader( &requestHeaders, rangeStart, rangeEnd ); - if (httpStatus == HTTPSuccess) + if( httpStatus == HTTPSuccess ) { /* Initialize the response object. The same buffer used for storing * request headers is reused here. */ @@ -1782,29 +1907,29 @@ static OtaHttpStatus_t httpRequest(uint32_t rangeStart, response.bufferLen = HTTP_USER_BUFFER_LENGTH; /* Send the request and receive the response. */ - httpStatus = HTTPClient_Send(&xTransportInterfaceHttp, - &requestHeaders, - NULL, - 0, - &response, - 0); + httpStatus = HTTPClient_Send( &xTransportInterfaceHttp, + &requestHeaders, + NULL, + 0, + &response, + 0 ); } else { - LogError(("Failed to initialize HTTP request headers: Error=%s.", - HTTPClient_strerror(httpStatus))); + LogError( ( "Failed to initialize HTTP request headers: Error=%s.", + HTTPClient_strerror( httpStatus ) ) ); } - if (httpStatus != HTTPSuccess) + if( httpStatus != HTTPSuccess ) { - if ((httpStatus == HTTPNoResponse) || (httpStatus == HTTPNetworkError)) + if( ( httpStatus == HTTPNoResponse ) || ( httpStatus == HTTPNetworkError ) ) { reconnectRequired = true; } else { - LogError(("HTTPClient_Send failed: Error=%s.", - HTTPClient_strerror(httpStatus))); + LogError( ( "HTTPClient_Send failed: Error=%s.", + HTTPClient_strerror( httpStatus ) ) ); ret = OtaHttpRequestFailed; } @@ -1812,22 +1937,22 @@ static OtaHttpStatus_t httpRequest(uint32_t rangeStart, else { /* Check if reconnection required. */ - if (response.respFlags & HTTP_RESPONSE_CONNECTION_CLOSE_FLAG) + if( response.respFlags & HTTP_RESPONSE_CONNECTION_CLOSE_FLAG ) { reconnectRequired = true; } /* Handle the http response received. */ - ret = handleHttpResponse(&response); + ret = handleHttpResponse( &response ); } - if (reconnectRequired == true) + if( reconnectRequired == true ) { /* End TLS session, then close TCP connection. */ - TLS_FreeRTOS_Disconnect(&xNetworkContextHttp); + TLS_FreeRTOS_Disconnect( &xNetworkContextHttp ); /* Try establishing connection to S3 server again. */ - if (connectToS3Server(&xNetworkContextHttp, NULL) == EXIT_SUCCESS) + if( connectToS3Server( &xNetworkContextHttp, NULL ) == EXIT_SUCCESS ) { ret = HTTPSuccess; } @@ -1835,8 +1960,8 @@ static OtaHttpStatus_t httpRequest(uint32_t rangeStart, { /* Log an error to indicate connection failure after all * reconnect attempts are over. */ - LogError(("Failed to connect to HTTP server %s.", - acServerHost)); + LogError( ( "Failed to connect to HTTP server %s.", + acServerHost ) ); ret = OtaHttpRequestFailed; } @@ -1847,7 +1972,7 @@ static OtaHttpStatus_t httpRequest(uint32_t rangeStart, /*-----------------------------------------------------------*/ -static OtaHttpStatus_t httpDeinit(void) +static OtaHttpStatus_t httpDeinit( void ) { OtaHttpStatus_t ret = OtaHttpSuccess; @@ -1856,9 +1981,9 @@ static OtaHttpStatus_t httpDeinit(void) return ret; } -static OtaMqttStatus_t prvMQTTSubscribe(const char* pTopicFilter, - uint16_t topicFilterLength, - uint8_t ucQoS) +static OtaMqttStatus_t prvMQTTSubscribe( const char * pTopicFilter, + uint16_t topicFilterLength, + uint8_t ucQoS ) { MQTTStatus_t mqttStatus; uint32_t ulNotifiedValue; @@ -1869,8 +1994,8 @@ static OtaMqttStatus_t prvMQTTSubscribe(const char* pTopicFilter, MQTTAgentCommandContext_t xApplicationDefinedContext = { 0 }; OtaMqttStatus_t otaRet = OtaMqttSuccess; - configASSERT(pTopicFilter != NULL); - configASSERT(topicFilterLength > 0); + configASSERT( pTopicFilter != NULL ); + configASSERT( topicFilterLength > 0 ); xSubscribeInfo.pTopicFilter = pTopicFilter; xSubscribeInfo.topicFilterLength = topicFilterLength; @@ -1884,21 +2009,21 @@ static OtaMqttStatus_t prvMQTTSubscribe(const char* pTopicFilter, xCommandParams.blockTimeMs = otaexampleMQTT_TIMEOUT_MS; xCommandParams.cmdCompleteCallback = prvMQTTSubscribeCompleteCallback; - xCommandParams.pCmdCompleteCallbackContext = (void*)&xApplicationDefinedContext; + xCommandParams.pCmdCompleteCallbackContext = ( void * ) &xApplicationDefinedContext; - xTaskNotifyStateClear(NULL); + xTaskNotifyStateClear( NULL ); - mqttStatus = MQTTAgent_Subscribe(&xGlobalMqttAgentContext, - &xSubscribeArgs, - &xCommandParams); + mqttStatus = MQTTAgent_Subscribe( &xGlobalMqttAgentContext, + &xSubscribeArgs, + &xCommandParams ); /* Wait for command to complete so MQTTSubscribeInfo_t remains in scope for the * duration of the command. */ - if (mqttStatus == MQTTSuccess) + if( mqttStatus == MQTTSuccess ) { - result = xTaskNotifyWait(0, otaexampleMAX_UINT32, &ulNotifiedValue, pdMS_TO_TICKS(otaexampleMQTT_TIMEOUT_MS)); + result = xTaskNotifyWait( 0, otaexampleMAX_UINT32, &ulNotifiedValue, pdMS_TO_TICKS( otaexampleMQTT_TIMEOUT_MS ) ); - if (result == pdTRUE) + if( result == pdTRUE ) { mqttStatus = xApplicationDefinedContext.xReturnStatus; } @@ -1908,18 +2033,18 @@ static OtaMqttStatus_t prvMQTTSubscribe(const char* pTopicFilter, } } - if (mqttStatus != MQTTSuccess) + if( mqttStatus != MQTTSuccess ) { - LogError(("Failed to SUBSCRIBE to topic with error = %u.", - mqttStatus)); + LogError( ( "Failed to SUBSCRIBE to topic with error = %u.", + mqttStatus ) ); otaRet = OtaMqttSubscribeFailed; } else { - LogInfo(("Subscribed to topic %.*s.\n\n", - topicFilterLength, - pTopicFilter)); + LogInfo( ( "Subscribed to topic %.*s.\n\n", + topicFilterLength, + pTopicFilter ) ); otaRet = OtaMqttSuccess; } @@ -1927,11 +2052,11 @@ static OtaMqttStatus_t prvMQTTSubscribe(const char* pTopicFilter, return otaRet; } -static OtaMqttStatus_t prvMQTTPublish(const char* const pacTopic, - uint16_t topicLen, - const char* pMsg, - uint32_t msgSize, - uint8_t qos) +static OtaMqttStatus_t prvMQTTPublish( const char * const pacTopic, + uint16_t topicLen, + const char * pMsg, + uint32_t msgSize, + uint8_t qos ) { OtaMqttStatus_t otaRet = OtaMqttSuccess; BaseType_t result; @@ -1947,23 +2072,23 @@ static OtaMqttStatus_t prvMQTTPublish(const char* const pacTopic, publishInfo.payloadLength = msgSize; xCommandContext.xTaskToNotify = xTaskGetCurrentTaskHandle(); - xTaskNotifyStateClear(NULL); + xTaskNotifyStateClear( NULL ); xCommandParams.blockTimeMs = otaexampleMQTT_TIMEOUT_MS; xCommandParams.cmdCompleteCallback = prvCommandCallback; - xCommandParams.pCmdCompleteCallbackContext = (void*)&xCommandContext; + xCommandParams.pCmdCompleteCallbackContext = ( void * ) &xCommandContext; - mqttStatus = MQTTAgent_Publish(&xGlobalMqttAgentContext, - &publishInfo, - &xCommandParams); + mqttStatus = MQTTAgent_Publish( &xGlobalMqttAgentContext, + &publishInfo, + &xCommandParams ); /* Wait for command to complete so MQTTSubscribeInfo_t remains in scope for the * duration of the command. */ - if (mqttStatus == MQTTSuccess) + if( mqttStatus == MQTTSuccess ) { - result = xTaskNotifyWait(0, otaexampleMAX_UINT32, NULL, pdMS_TO_TICKS(otaexampleMQTT_TIMEOUT_MS)); + result = xTaskNotifyWait( 0, otaexampleMAX_UINT32, NULL, pdMS_TO_TICKS( otaexampleMQTT_TIMEOUT_MS ) ); - if (result != pdTRUE) + if( result != pdTRUE ) { mqttStatus = MQTTSendFailed; } @@ -1973,16 +2098,16 @@ static OtaMqttStatus_t prvMQTTPublish(const char* const pacTopic, } } - if (mqttStatus != MQTTSuccess) + if( mqttStatus != MQTTSuccess ) { - LogError(("Failed to send PUBLISH packet to broker with error = %u.", mqttStatus)); + LogError( ( "Failed to send PUBLISH packet to broker with error = %u.", mqttStatus ) ); otaRet = OtaMqttPublishFailed; } else { - LogInfo(("Sent PUBLISH packet to broker %.*s to broker.\n\n", - topicLen, - pacTopic)); + LogInfo( ( "Sent PUBLISH packet to broker %.*s to broker.\n\n", + topicLen, + pacTopic ) ); otaRet = OtaMqttSuccess; } @@ -1990,9 +2115,9 @@ static OtaMqttStatus_t prvMQTTPublish(const char* const pacTopic, return otaRet; } -static OtaMqttStatus_t prvMQTTUnsubscribe(const char* pTopicFilter, - uint16_t topicFilterLength, - uint8_t ucQoS) +static OtaMqttStatus_t prvMQTTUnsubscribe( const char * pTopicFilter, + uint16_t topicFilterLength, + uint8_t ucQoS ) { MQTTStatus_t mqttStatus; uint32_t ulNotifiedValue; @@ -2003,8 +2128,8 @@ static OtaMqttStatus_t prvMQTTUnsubscribe(const char* pTopicFilter, MQTTAgentCommandContext_t xApplicationDefinedContext = { 0 }; OtaMqttStatus_t otaRet = OtaMqttSuccess; - configASSERT(pTopicFilter != NULL); - configASSERT(topicFilterLength > 0); + configASSERT( pTopicFilter != NULL ); + configASSERT( topicFilterLength > 0 ); xSubscribeInfo.pTopicFilter = pTopicFilter; xSubscribeInfo.topicFilterLength = topicFilterLength; @@ -2017,23 +2142,23 @@ static OtaMqttStatus_t prvMQTTUnsubscribe(const char* pTopicFilter, xCommandParams.blockTimeMs = otaexampleMQTT_TIMEOUT_MS; xCommandParams.cmdCompleteCallback = prvMQTTUnsubscribeCompleteCallback; - xCommandParams.pCmdCompleteCallbackContext = (void*)&xApplicationDefinedContext; + xCommandParams.pCmdCompleteCallbackContext = ( void * ) &xApplicationDefinedContext; - LogInfo((" Unsubscribing to topic filter: %s", pTopicFilter)); - xTaskNotifyStateClear(NULL); + LogInfo( ( " Unsubscribing to topic filter: %s", pTopicFilter ) ); + xTaskNotifyStateClear( NULL ); - mqttStatus = MQTTAgent_Unsubscribe(&xGlobalMqttAgentContext, - &xSubscribeArgs, - &xCommandParams); + mqttStatus = MQTTAgent_Unsubscribe( &xGlobalMqttAgentContext, + &xSubscribeArgs, + &xCommandParams ); /* Wait for command to complete so MQTTSubscribeInfo_t remains in scope for the * duration of the command. */ - if (mqttStatus == MQTTSuccess) + if( mqttStatus == MQTTSuccess ) { - result = xTaskNotifyWait(0, otaexampleMAX_UINT32, &ulNotifiedValue, pdMS_TO_TICKS(otaexampleMQTT_TIMEOUT_MS)); + result = xTaskNotifyWait( 0, otaexampleMAX_UINT32, &ulNotifiedValue, pdMS_TO_TICKS( otaexampleMQTT_TIMEOUT_MS ) ); - if (result == pdTRUE) + if( result == pdTRUE ) { mqttStatus = xApplicationDefinedContext.xReturnStatus; } @@ -2043,20 +2168,20 @@ static OtaMqttStatus_t prvMQTTUnsubscribe(const char* pTopicFilter, } } - if (mqttStatus != MQTTSuccess) + if( mqttStatus != MQTTSuccess ) { - LogError(("Failed to UNSUBSCRIBE from topic %.*s with error = %u.", - topicFilterLength, - pTopicFilter, - mqttStatus)); + LogError( ( "Failed to UNSUBSCRIBE from topic %.*s with error = %u.", + topicFilterLength, + pTopicFilter, + mqttStatus ) ); otaRet = OtaMqttUnsubscribeFailed; } else { - LogInfo(("UNSUBSCRIBED from topic %.*s.\n\n", - topicFilterLength, - pTopicFilter)); + LogInfo( ( "UNSUBSCRIBED from topic %.*s.\n\n", + topicFilterLength, + pTopicFilter ) ); otaRet = OtaMqttSuccess; } @@ -2068,9 +2193,9 @@ static OtaMqttStatus_t prvMQTTUnsubscribe(const char* pTopicFilter, /*-----------------------------------------------------------*/ -static void setOtaInterfaces(OtaInterfaces_t* pOtaInterfaces) +static void setOtaInterfaces( OtaInterfaces_t * pOtaInterfaces ) { - configASSERT(pOtaInterfaces != NULL); + configASSERT( pOtaInterfaces != NULL ); /* Initialize OTA library OS Interface. */ pOtaInterfaces->os.event.init = OtaInitEvent_FreeRTOS; @@ -2106,21 +2231,21 @@ static void setOtaInterfaces(OtaInterfaces_t* pOtaInterfaces) /*-----------------------------------------------------------*/ -static void prvOTAAgentTask(void* pParam) +static void prvOTAAgentTask( void * pParam ) { /* Calling OTA agent task. */ - OTA_EventProcessingTask(pParam); - LogInfo(("OTA Agent stopped.")); + OTA_EventProcessingTask( pParam ); + LogInfo( ( "OTA Agent stopped." ) ); - vTaskDelete(NULL); + vTaskDelete( NULL ); } -static void prvMQTTAgentTask(void* pParam) +static void prvMQTTAgentTask( void * pParam ) { BaseType_t xResult = pdFAIL; MQTTStatus_t xMQTTStatus = MQTTSuccess; - (void)pParam; + ( void ) pParam; do { @@ -2129,36 +2254,36 @@ static void prvMQTTAgentTask(void* pParam) * which could be a disconnect. If an error occurs the MQTT context on * which the error happened is returned so there can be an attempt to * clean up and reconnect however the application writer prefers. */ - xMQTTStatus = MQTTAgent_CommandLoop(&xGlobalMqttAgentContext); + xMQTTStatus = MQTTAgent_CommandLoop( &xGlobalMqttAgentContext ); /* Clear Agent queue so that no any pending MQTT operations are processed. */ - MQTTAgent_CancelAll(&xGlobalMqttAgentContext); + MQTTAgent_CancelAll( &xGlobalMqttAgentContext ); /* Success is returned for application initiated disconnect or termination. The socket will also be disconnected by the caller. */ - if (xMQTTStatus != MQTTSuccess) + if( xMQTTStatus != MQTTSuccess ) { xResult = prvSuspendOTA(); - configASSERT(xResult == pdPASS); + configASSERT( xResult == pdPASS ); - LogInfo(("Suspended OTA agent.")); + LogInfo( ( "Suspended OTA agent." ) ); /* End TLS session, then close TCP connection. */ - prvSocketDisconnect(&xNetworkContextMqtt); + prvSocketDisconnect( &xNetworkContextMqtt ); /* Connect to MQTT broker. */ prvConnectToMQTTBroker(); xResult = prvResumeOTA(); - configASSERT(xResult == pdPASS); + configASSERT( xResult == pdPASS ); - LogInfo(("Resumed OTA agent.")); + LogInfo( ( "Resumed OTA agent." ) ); } - } while (xMQTTStatus != MQTTSuccess); + } while( xMQTTStatus != MQTTSuccess ); - vTaskDelete(NULL); + vTaskDelete( NULL ); } -static BaseType_t prvSuspendOTA(void) +static BaseType_t prvSuspendOTA( void ) { /* OTA library return status. */ OtaErr_t otaRet = OtaErrNone; @@ -2167,33 +2292,33 @@ static BaseType_t prvSuspendOTA(void) otaRet = OTA_Suspend(); - if (otaRet == OtaErrNone) + if( otaRet == OtaErrNone ) { suspendTimeout = OTA_SUSPEND_TIMEOUT_MS; - while ((OTA_GetState() != OtaAgentStateSuspended) && (suspendTimeout > 0)) + while( ( OTA_GetState() != OtaAgentStateSuspended ) && ( suspendTimeout > 0 ) ) { /* Wait for OTA Library state to suspend */ - vTaskDelay(pdMS_TO_TICKS(otaexampleTASK_DELAY_MS)); + vTaskDelay( pdMS_TO_TICKS( otaexampleTASK_DELAY_MS ) ); suspendTimeout -= otaexampleTASK_DELAY_MS; } - if (OTA_GetState() != OtaAgentStateSuspended) + if( OTA_GetState() != OtaAgentStateSuspended ) { - LogError(("Failed to suspend OTA.")); + LogError( ( "Failed to suspend OTA." ) ); status = pdFAIL; } } else { - LogError(("Error while trying to suspend OTA agent %d", otaRet)); + LogError( ( "Error while trying to suspend OTA agent %d", otaRet ) ); status = pdFAIL; } return status; } -static BaseType_t prvResumeOTA(void) +static BaseType_t prvResumeOTA( void ) { /* OTA library return status. */ OtaErr_t otaRet = OtaErrNone; @@ -2202,26 +2327,26 @@ static BaseType_t prvResumeOTA(void) otaRet = OTA_Resume(); - if (otaRet == OtaErrNone) + if( otaRet == OtaErrNone ) { suspendTimeout = OTA_SUSPEND_TIMEOUT_MS; - while ((OTA_GetState() == OtaAgentStateSuspended) && (suspendTimeout > 0)) + while( ( OTA_GetState() == OtaAgentStateSuspended ) && ( suspendTimeout > 0 ) ) { /* Wait for OTA Library state to suspend */ - vTaskDelay(pdMS_TO_TICKS(otaexampleTASK_DELAY_MS)); + vTaskDelay( pdMS_TO_TICKS( otaexampleTASK_DELAY_MS ) ); suspendTimeout -= otaexampleTASK_DELAY_MS; } - if (OTA_GetState() == OtaAgentStateSuspended) + if( OTA_GetState() == OtaAgentStateSuspended ) { - LogError(("Failed to resume OTA.")); + LogError( ( "Failed to resume OTA." ) ); status = pdFAIL; } } else { - LogError(("Error while trying to resume OTA agent %d", otaRet)); + LogError( ( "Error while trying to resume OTA agent %d", otaRet ) ); status = pdFAIL; } @@ -2317,7 +2442,7 @@ static BaseType_t prvRunOTADemo( void ) otaStatistics.otaPacketsDropped ) ); } - vTaskDelay( pdMS_TO_TICKS(otaexampleTASK_DELAY_MS) ); + vTaskDelay( pdMS_TO_TICKS( otaexampleTASK_DELAY_MS ) ); } } @@ -2343,9 +2468,9 @@ static BaseType_t prvRunOTADemo( void ) * the OTA agent. If not, it is simply ignored. * */ -void vOtaDemoTask(void* pParam) +void vOtaDemoTask( void * pParam ) { - (void)pParam; + ( void ) pParam; /* Return error status. */ BaseType_t xReturnStatus = pdPASS; @@ -2369,7 +2494,7 @@ void vOtaDemoTask(void* pParam) /****************************** Init MQTT ******************************/ - if(xReturnStatus == pdPASS ) + if( xReturnStatus == pdPASS ) { /* Create the TCP connection to the broker, then the MQTT connection to the * same. */ @@ -2378,7 +2503,7 @@ void vOtaDemoTask(void* pParam) /****************************** Create MQTT Agent Task. ******************************/ - if(xReturnStatus == pdPASS ) + if( xReturnStatus == pdPASS ) { if( xTaskCreate( prvMQTTAgentTask, "MQTT Agent Task", @@ -2394,7 +2519,7 @@ void vOtaDemoTask(void* pParam) /****************************** Start OTA Demo. ******************************/ - if(xReturnStatus == pdPASS) + if( xReturnStatus == pdPASS ) { /* Start OTA demo. The function returns only if OTA completes successfully and a * shutdown of OTA is triggered for a manual restart of the device.*/ @@ -2421,18 +2546,18 @@ void vOtaDemoTask(void* pParam) /* * @brief Create the task that demonstrates the Ota demo. */ -void vStartOtaDemo(void) +void vStartOtaDemo( void ) { - /* + /* * vOtaDemoTask() connects to the MQTT broker, creates the - * MQTT Agent task and calls the Ota demo loop prvRunOTADemo() - * which creates the OTA Agent task. + * MQTT Agent task and calls the Ota demo loop prvRunOTADemo() + * which creates the OTA Agent task. */ - xTaskCreate(vOtaDemoTask, /* Function that implements the task. */ - "OTA Demo Task", /* Text name for the task - only used for debugging. */ - democonfigDEMO_STACKSIZE, /* Size of stack (in words, not bytes) to allocate for the task. */ - NULL, /* Optional - task parameter - not used in this case. */ - tskIDLE_PRIORITY + 1, /* Task priority, must be between 0 and configMAX_PRIORITIES - 1. */ - NULL); /* Optional - used to pass out a handle to the created task. */ + xTaskCreate( vOtaDemoTask, /* Function that implements the task. */ + "OTA Demo Task", /* Text name for the task - only used for debugging. */ + democonfigDEMO_STACKSIZE, /* Size of stack (in words, not bytes) to allocate for the task. */ + NULL, /* Optional - task parameter - not used in this case. */ + tskIDLE_PRIORITY + 1, /* Task priority, must be between 0 and configMAX_PRIORITIES - 1. */ + NULL ); /* Optional - used to pass out a handle to the created task. */ } diff --git a/FreeRTOS-Plus/Demo/AWS/Ota_Windows_Simulator/Ota_Over_Http_Demo/demo_config.h b/FreeRTOS-Plus/Demo/AWS/Ota_Windows_Simulator/Ota_Over_Http_Demo/demo_config.h index 13aca0b54d..a77963c0f2 100644 --- a/FreeRTOS-Plus/Demo/AWS/Ota_Windows_Simulator/Ota_Over_Http_Demo/demo_config.h +++ b/FreeRTOS-Plus/Demo/AWS/Ota_Windows_Simulator/Ota_Over_Http_Demo/demo_config.h @@ -54,7 +54,7 @@ * The function prints to the console before the network is connected; * then a UDP port after the network has connected. */ extern void vLoggingPrintf( const char * pcFormatString, - ... ); + ... ); /* Map the SdkLog macro to the logging function to enable logging * on Windows simulator. */ @@ -72,9 +72,9 @@ extern void vLoggingPrintf( const char * pcFormatString, * download image should be higher than the current version, otherwise the new image is * rejected in self test phase. */ -#define APP_VERSION_MAJOR 0 -#define APP_VERSION_MINOR 9 -#define APP_VERSION_BUILD 2 +#define APP_VERSION_MAJOR 0 +#define APP_VERSION_MINOR 9 +#define APP_VERSION_BUILD 2 /** * @brief The MQTT client identifier used in this example. Each client identifier @@ -88,7 +88,7 @@ extern void vLoggingPrintf( const char * pcFormatString, * * #define democonfigCLIENT_IDENTIFIER "...insert here..." */ -#define democonfigCLIENT_IDENTIFIER "...insert here..." +#define democonfigCLIENT_IDENTIFIER "...insert here..." /** * @brief Endpoint of the MQTT broker to connect to. @@ -105,7 +105,7 @@ extern void vLoggingPrintf( const char * pcFormatString, * * #define democonfigMQTT_BROKER_ENDPOINT "...insert here..." */ -#define democonfigMQTT_BROKER_ENDPOINT "...insert here..." +#define democonfigMQTT_BROKER_ENDPOINT "...insert here..." /** * @brief The port to use for the demo. @@ -225,15 +225,15 @@ extern void vLoggingPrintf( const char * pcFormatString, "-----END CERTIFICATE-----\n" #endif /* ifndef democonfigHTTPS_ROOT_CA_PEM */ - /** - * @brief AWS IoT Core server port number for HTTPS connections. - * - * For this demo, an X.509 certificate is used to verify the client. - * - * @note Port 443 requires use of the ALPN TLS extension with the ALPN protocol - * name being x-amzn-http-ca. When using port 8443, ALPN is not required. - */ -#define democonfigHTTPS_PORT 443 +/** + * @brief AWS IoT Core server port number for HTTPS connections. + * + * For this demo, an X.509 certificate is used to verify the client. + * + * @note Port 443 requires use of the ALPN TLS extension with the ALPN protocol + * name being x-amzn-http-ca. When using port 8443, ALPN is not required. + */ +#define democonfigHTTPS_PORT 443 /** * @brief An option to disable Server Name Indication. @@ -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 */ diff --git a/FreeRTOS-Plus/Demo/AWS/Ota_Windows_Simulator/Ota_Over_Mqtt_Demo/DemoTasks/OtaOverMqttDemoExample.c b/FreeRTOS-Plus/Demo/AWS/Ota_Windows_Simulator/Ota_Over_Mqtt_Demo/DemoTasks/OtaOverMqttDemoExample.c index cf9a0ff8f4..2b0cdc654d 100644 --- a/FreeRTOS-Plus/Demo/AWS/Ota_Windows_Simulator/Ota_Over_Mqtt_Demo/DemoTasks/OtaOverMqttDemoExample.c +++ b/FreeRTOS-Plus/Demo/AWS/Ota_Windows_Simulator/Ota_Over_Mqtt_Demo/DemoTasks/OtaOverMqttDemoExample.c @@ -93,26 +93,26 @@ /** * @brief The maximum size of the file paths used in the demo. */ -#define otaexampleMAX_FILE_PATH_SIZE ( 260 ) +#define otaexampleMAX_FILE_PATH_SIZE ( 260 ) /** * @brief The maximum size of the stream name required for downloading update file * from streaming service. */ -#define otaexampleMAX_STREAM_NAME_SIZE ( 128 ) +#define otaexampleMAX_STREAM_NAME_SIZE ( 128 ) /** * @brief The delay used in the OTA demo task to periodically output the OTA * statistics like number of packets received, dropped, processed and queued per connection. */ -#define otaexampleTASK_DELAY_MS ( 1000U ) +#define otaexampleTASK_DELAY_MS ( 1000U ) /** * @brief The maximum time for which OTA demo waits for an MQTT operation to be complete. * This involves receiving an acknowledgment for broker for SUBSCRIBE, UNSUBSCRIBE and non * QOS0 publishes. */ -#define otaexampleMQTT_TIMEOUT_MS ( 5000U ) +#define otaexampleMQTT_TIMEOUT_MS ( 5000U ) /** * @brief The common prefix for all OTA topics. @@ -168,36 +168,36 @@ */ #define OTA_TOPIC_CLIENT_IDENTIFIER_START_IDX ( 12U ) - /** - * @brief Default topic filter for OTA. - * This is used to route all the packets for OTA reserved topics which OTA agent has not subscribed for. - */ -#define OTA_DEFAULT_TOPIC_FILTER OTA_TOPIC_PREFIX "jobs/#" +/** + * @brief Default topic filter for OTA. + * This is used to route all the packets for OTA reserved topics which OTA agent has not subscribed for. + */ +#define OTA_DEFAULT_TOPIC_FILTER OTA_TOPIC_PREFIX "jobs/#" - /** - * @brief Length of default topic filter. - */ -#define OTA_DEFAULT_TOPIC_FILTER_LENGTH ( ( uint16_t ) ( sizeof( OTA_DEFAULT_TOPIC_FILTER ) - 1 ) ) +/** + * @brief Length of default topic filter. + */ +#define OTA_DEFAULT_TOPIC_FILTER_LENGTH ( ( uint16_t ) ( sizeof( OTA_DEFAULT_TOPIC_FILTER ) - 1 ) ) /** * @brief Used to clear bits in a task's notification value. */ #define otaexampleMAX_UINT32 ( 0xffffffff ) - /** - * @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. - */ +/** + * @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 ( 10240 ) + #define MQTT_AGENT_NETWORK_BUFFER_SIZE ( 10240 ) #endif - /** - * @brief The length of the queue used to hold commands for the agent. - */ +/** + * @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 ( 10 ) #endif /** @@ -205,31 +205,31 @@ * to be posted to the MQTT agent should the MQTT agent's command queue be full. * Tasks wait in the Blocked state, so don't use any CPU time. */ -#define MQTT_AGENT_SEND_BLOCK_TIME_MS ( 200U ) +#define MQTT_AGENT_SEND_BLOCK_TIME_MS ( 200U ) - /** - * @brief This demo uses task notifications to signal tasks from MQTT callback - * functions. mqttexampleMS_TO_WAIT_FOR_NOTIFICATION defines the time, in ticks, - * to wait for such a callback. - */ -#define MQTT_AGENT_MS_TO_WAIT_FOR_NOTIFICATION ( 5000U ) +/** + * @brief This demo uses task notifications to signal tasks from MQTT callback + * functions. mqttexampleMS_TO_WAIT_FOR_NOTIFICATION defines the time, in ticks, + * to wait for such a callback. + */ +#define MQTT_AGENT_MS_TO_WAIT_FOR_NOTIFICATION ( 5000U ) /** * @brief The maximum number of retries for network operation with server. */ -#define RETRY_MAX_ATTEMPTS ( 5U ) +#define RETRY_MAX_ATTEMPTS ( 5U ) /** * @brief The maximum back-off delay (in milliseconds) for retrying failed operation * with server. */ -#define RETRY_MAX_BACKOFF_DELAY_MS ( 5000U ) +#define RETRY_MAX_BACKOFF_DELAY_MS ( 5000U ) /** * @brief The base back-off delay (in milliseconds) to use for network operation retry * attempts. */ -#define RETRY_BACKOFF_BASE_MS ( 500U ) +#define RETRY_BACKOFF_BASE_MS ( 500U ) /** * @brief The maximum time interval in seconds which is allowed to elapse @@ -247,33 +247,33 @@ */ #define otaexampleTRANSPORT_SEND_RECV_TIMEOUT_MS ( 750 ) - /** - * @brief Timeout for receiving CONNACK after sending an MQTT CONNECT packet. - * Defined in milliseconds. - */ -#define otaexampleCONNACK_RECV_TIMEOUT_MS ( 1000U ) +/** + * @brief Timeout for receiving CONNACK after sending an MQTT CONNECT packet. + * Defined in milliseconds. + */ +#define otaexampleCONNACK_RECV_TIMEOUT_MS ( 1000U ) /** * @brief Stack size required for MQTT agent task. * MQTT agent task takes care of TLS connection and reconnection, keeping task stack size * to high enough required for TLS connection. */ -#define MQTT_AGENT_TASK_STACK_SIZE ( 6000U ) +#define MQTT_AGENT_TASK_STACK_SIZE ( 6000U ) /** * @brief Priority required for OTA statistics task. */ -#define MQTT_AGENT_TASK_PRIORITY ( tskIDLE_PRIORITY ) +#define MQTT_AGENT_TASK_PRIORITY ( tskIDLE_PRIORITY ) /** * @brief Stack size required for OTA agent task. */ -#define OTA_AGENT_TASK_STACK_SIZE ( 5000U ) +#define OTA_AGENT_TASK_STACK_SIZE ( 5000U ) /** * @brief Priority required for OTA agent task. */ -#define OTA_AGENT_TASK_PRIORITY ( tskIDLE_PRIORITY ) +#define OTA_AGENT_TASK_PRIORITY ( tskIDLE_PRIORITY ) /** * @brief Used to convert times to/from ticks and milliseconds. @@ -281,15 +281,142 @@ #define otaexampleMILLISECONDS_PER_SECOND ( 1000U ) #define otaexampleMILLISECONDS_PER_TICK ( otaexampleMILLISECONDS_PER_SECOND / configTICK_RATE_HZ ) - /** - * @brief The timeout for waiting for the agent to get suspended after closing the - * connection. - * - * Timeout value should be large enough for OTA agent to finish any pending MQTT operations - * and suspend itself. - * - */ -#define OTA_SUSPEND_TIMEOUT_MS ( 10000U ) +/** + * @brief The timeout for waiting for the agent to get suspended after closing the + * connection. + * + * Timeout value should be large enough for OTA agent to finish any pending MQTT operations + * and suspend itself. + * + */ +#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; }; - /*---------------------------------------------------------*/ /** @@ -429,7 +555,7 @@ static MQTTAgentContext_t xGlobalMqttAgentContext; * * @param[in] pParam Can be used to pass down functionality to the agent task */ -static void prvMQTTAgentTask(void* pParam); +static void prvMQTTAgentTask( void * pParam ); /** * @brief Function used by OTA agent to publish control messages to the MQTT broker. @@ -536,17 +662,17 @@ static void prvOTAAgentTask( void * pvParam ); * The demo task initializes the OTA agent an loops until OTA agent is shutdown. * It reports OTA update statistics (which includes number of blocks received, processed and dropped), * at regular intervals. - * + * * @param[in] pvParam Any parameters to be passed to OTA Demo task. */ -static void vOtaDemoTask( void* pvParam ); +static void vOtaDemoTask( void * pvParam ); /** * @brief The function which implements the flow for OTA demo. * * @return pdPASS if success or pdFAIL. */ -static BaseType_t prvRunOTADemo(void); +static BaseType_t prvRunOTADemo( void ); /** * @brief Callback registered with the OTA library that notifies the OTA agent @@ -588,7 +714,7 @@ static void prvMqttDefaultCallback( void * pvIncomingPublishCallbackContext, * @brief Attempt to connect to the MQTT broker. * */ -static void prvConnectToMQTTBroker(void); +static void prvConnectToMQTTBroker( void ); /** * @brief Retry logic to establish a connection to the MQTT broker. @@ -599,14 +725,14 @@ static void prvConnectToMQTTBroker(void); * @param[in] pNetworkContext Network context to connect on. * @return int pdFALSE if connection failed after retries. */ -static BaseType_t prvSocketConnect(NetworkContext_t* pNetworkContext); +static BaseType_t prvSocketConnect( NetworkContext_t * pNetworkContext ); /** * @brief Disconnects from the MQTT broker. * Initiates an MQTT disconnect and then teardown underlying TCP connection. * */ -static void prvDisconnectFromMQTTBroker(void); +static void prvDisconnectFromMQTTBroker( void ); /** * @brief Initializes an MQTT context, including transport interface and @@ -614,7 +740,7 @@ static void prvDisconnectFromMQTTBroker(void); * * @return `MQTTSuccess` if the initialization succeeds, else `MQTTBadParameter`. */ -static MQTTStatus_t prvMqttInit(void); +static MQTTStatus_t prvMqttInit( void ); /** * @brief Sends an MQTT Connect packet over the already connected TCP socket. @@ -634,22 +760,22 @@ static MQTTStatus_t prvMQTTConnect( bool xCleanSession ); * @param[in] topicFilterLength length of the topic filter. * */ -static void prvRegisterOTACallback(const char* pTopicFilter, - uint16_t topicFilterLength); +static void prvRegisterOTACallback( const char * pTopicFilter, + uint16_t topicFilterLength ); /** * @brief Suspend OTA demo. * * @return pPASS or pdFAIL. */ -static BaseType_t prvSuspendOTA(void); +static BaseType_t prvSuspendOTA( void ); /** * @brief Resume OTA demo. * * @return pPASS or pdFAIL. */ -static BaseType_t prvResumeOTA(void); +static BaseType_t prvResumeOTA( void ); /** * @brief Set OTA interfaces. @@ -658,7 +784,7 @@ static BaseType_t prvResumeOTA(void); * * @return None. */ -static void setOtaInterfaces(OtaInterfaces_t* pOtaInterfaces); +static void setOtaInterfaces( OtaInterfaces_t * pOtaInterfaces ); /** * @brief Structure containing all application allocated buffers used by the OTA agent. @@ -918,9 +1044,9 @@ static void prvMqttDataCallback( void * pvIncomingPublishCallbackContext, pxData = prvOTAEventBufferGet(); - if(pxData != NULL ) + if( pxData != NULL ) { - memcpy(pxData->data, pxPublishInfo->pPayload, pxPublishInfo->payloadLength ); + memcpy( pxData->data, pxPublishInfo->pPayload, pxPublishInfo->payloadLength ); pxData->dataLength = pxPublishInfo->payloadLength; eventMsg.eventId = OtaAgentEventReceivedFileBlock; eventMsg.pEventData = pxData; @@ -947,46 +1073,45 @@ static void prvCommandCallback( MQTTAgentCommandContext_t * pxCommandContext, } } -static void prvMQTTSubscribeCompleteCallback( MQTTAgentCommandContext_t* pxCommandContext, - MQTTAgentReturnInfo_t* pxReturnInfo ) +static void prvMQTTSubscribeCompleteCallback( MQTTAgentCommandContext_t * pxCommandContext, + MQTTAgentReturnInfo_t * pxReturnInfo ) { - MQTTAgentSubscribeArgs_t* pSubsribeArgs; + MQTTAgentSubscribeArgs_t * pSubsribeArgs; - if (pxReturnInfo->returnCode == MQTTSuccess) + if( pxReturnInfo->returnCode == MQTTSuccess ) { - pSubsribeArgs = (MQTTAgentSubscribeArgs_t*)(pxCommandContext->pArgs); - prvRegisterOTACallback(pSubsribeArgs->pSubscribeInfo->pTopicFilter, pSubsribeArgs->pSubscribeInfo->topicFilterLength); + pSubsribeArgs = ( MQTTAgentSubscribeArgs_t * ) ( pxCommandContext->pArgs ); + prvRegisterOTACallback( pSubsribeArgs->pSubscribeInfo->pTopicFilter, pSubsribeArgs->pSubscribeInfo->topicFilterLength ); } /* 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; - if (pxCommandContext->xTaskToNotify != NULL) + if( pxCommandContext->xTaskToNotify != NULL ) { /* Send the context's ulNotificationValue as the notification value so * the receiving task can check the value it set in the context matches * the value it receives in the notification. */ - xTaskNotify(pxCommandContext->xTaskToNotify, (uint32_t)(pxReturnInfo->returnCode), eSetValueWithOverwrite); + xTaskNotify( pxCommandContext->xTaskToNotify, ( uint32_t ) ( pxReturnInfo->returnCode ), eSetValueWithOverwrite ); } } /*-----------------------------------------------------------*/ -static void prvMQTTUnsubscribeCompleteCallback( MQTTAgentCommandContext_t* pxCommandContext, - MQTTAgentReturnInfo_t* pxReturnInfo ) +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; - if (pxCommandContext->xTaskToNotify != NULL) + if( pxCommandContext->xTaskToNotify != NULL ) { /* Send the context's ulNotificationValue as the notification value so * the receiving task can check the value it set in the context matches * the value it receives in the notification. */ - xTaskNotify(pxCommandContext->xTaskToNotify, (uint32_t)(pxReturnInfo->returnCode), eSetValueWithOverwrite); + xTaskNotify( pxCommandContext->xTaskToNotify, ( uint32_t ) ( pxReturnInfo->returnCode ), eSetValueWithOverwrite ); } } @@ -1058,15 +1183,15 @@ static void prvSubscriptionCommandCallback( void * pxCommandContext, for( xIndex = 0; xIndex < pxSubscribeArgs->numSubscriptions; xIndex++ ) { /* This demo doesn't attempt to resubscribe in the event that a SUBACK failed. */ - if( pxReturnInfo->pSubackCodes[xIndex] == MQTTSubAckFailure ) + if( pxReturnInfo->pSubackCodes[ xIndex ] == MQTTSubAckFailure ) { LogError( ( "Failed to resubscribe to topic %.*s.", - pxSubscribeArgs->pSubscribeInfo[xIndex].topicFilterLength, - pxSubscribeArgs->pSubscribeInfo[xIndex].pTopicFilter ) ); + pxSubscribeArgs->pSubscribeInfo[ xIndex ].topicFilterLength, + pxSubscribeArgs->pSubscribeInfo[ xIndex ].pTopicFilter ) ); /* Remove subscription callback for unsubscribe. */ removeSubscription( xGlobalSubscriptionList, - pxSubscribeArgs->pSubscribeInfo[xIndex].pTopicFilter, - pxSubscribeArgs->pSubscribeInfo[xIndex].topicFilterLength ); + pxSubscribeArgs->pSubscribeInfo[ xIndex ].pTopicFilter, + pxSubscribeArgs->pSubscribeInfo[ xIndex ].topicFilterLength ); } } @@ -1274,12 +1399,12 @@ static BaseType_t prvSocketConnect( NetworkContext_t * pxNetworkContext ) /*-----------------------------------------------------------*/ -static BaseType_t prvSocketDisconnect(NetworkContext_t* pxNetworkContext) +static BaseType_t prvSocketDisconnect( NetworkContext_t * pxNetworkContext ) { BaseType_t xDisconnected = pdFAIL; - LogInfo(("Disconnecting TLS connection.\n")); - TLS_FreeRTOS_Disconnect(pxNetworkContext); + LogInfo( ( "Disconnecting TLS connection.\n" ) ); + TLS_FreeRTOS_Disconnect( pxNetworkContext ); xDisconnected = pdPASS; return xDisconnected; @@ -1303,7 +1428,7 @@ static MQTTStatus_t prvMQTTInit( void ) LogDebug( ( "Creating command queue." ) ); xCommandQueue.queue = xQueueCreateStatic( MQTT_AGENT_COMMAND_QUEUE_LENGTH, - sizeof( MQTTAgentCommand_t* ), + sizeof( MQTTAgentCommand_t * ), staticQueueStorageArea, &staticQueueStructure ); configASSERT( xCommandQueue.queue ); @@ -1456,9 +1581,9 @@ static void prvDisconnectFromMQTTBroker( void ) prvSocketDisconnect( &xNetworkContextMqtt ); } -static OtaMqttStatus_t prvMQTTSubscribe(const char* pTopicFilter, - uint16_t topicFilterLength, - uint8_t ucQoS) +static OtaMqttStatus_t prvMQTTSubscribe( const char * pTopicFilter, + uint16_t topicFilterLength, + uint8_t ucQoS ) { MQTTStatus_t mqttStatus; uint32_t ulNotifiedValue; @@ -1469,8 +1594,8 @@ static OtaMqttStatus_t prvMQTTSubscribe(const char* pTopicFilter, MQTTAgentCommandContext_t xApplicationDefinedContext = { 0 }; OtaMqttStatus_t otaRet = OtaMqttSuccess; - configASSERT(pTopicFilter != NULL); - configASSERT(topicFilterLength > 0); + configASSERT( pTopicFilter != NULL ); + configASSERT( topicFilterLength > 0 ); xSubscribeInfo.pTopicFilter = pTopicFilter; xSubscribeInfo.topicFilterLength = topicFilterLength; @@ -1484,21 +1609,21 @@ static OtaMqttStatus_t prvMQTTSubscribe(const char* pTopicFilter, xCommandParams.blockTimeMs = otaexampleMQTT_TIMEOUT_MS; xCommandParams.cmdCompleteCallback = prvMQTTSubscribeCompleteCallback; - xCommandParams.pCmdCompleteCallbackContext = (void*)&xApplicationDefinedContext; + xCommandParams.pCmdCompleteCallbackContext = ( void * ) &xApplicationDefinedContext; - xTaskNotifyStateClear(NULL); + xTaskNotifyStateClear( NULL ); - mqttStatus = MQTTAgent_Subscribe(&xGlobalMqttAgentContext, - &xSubscribeArgs, - &xCommandParams); + mqttStatus = MQTTAgent_Subscribe( &xGlobalMqttAgentContext, + &xSubscribeArgs, + &xCommandParams ); /* Wait for command to complete so MQTTSubscribeInfo_t remains in scope for the * duration of the command. */ - if (mqttStatus == MQTTSuccess) + if( mqttStatus == MQTTSuccess ) { - result = xTaskNotifyWait(0, otaexampleMAX_UINT32, &ulNotifiedValue, pdMS_TO_TICKS(otaexampleMQTT_TIMEOUT_MS)); + result = xTaskNotifyWait( 0, otaexampleMAX_UINT32, &ulNotifiedValue, pdMS_TO_TICKS( otaexampleMQTT_TIMEOUT_MS ) ); - if (result == pdTRUE) + if( result == pdTRUE ) { mqttStatus = xApplicationDefinedContext.xReturnStatus; } @@ -1508,18 +1633,18 @@ static OtaMqttStatus_t prvMQTTSubscribe(const char* pTopicFilter, } } - if (mqttStatus != MQTTSuccess) + if( mqttStatus != MQTTSuccess ) { - LogError(("Failed to SUBSCRIBE to topic with error = %u.", - mqttStatus)); + LogError( ( "Failed to SUBSCRIBE to topic with error = %u.", + mqttStatus ) ); otaRet = OtaMqttSubscribeFailed; } else { - LogInfo(("Subscribed to topic %.*s.\n\n", - topicFilterLength, - pTopicFilter)); + LogInfo( ( "Subscribed to topic %.*s.\n\n", + topicFilterLength, + pTopicFilter ) ); otaRet = OtaMqttSuccess; } @@ -1527,11 +1652,11 @@ static OtaMqttStatus_t prvMQTTSubscribe(const char* pTopicFilter, return otaRet; } -static OtaMqttStatus_t prvMQTTPublish(const char* const pacTopic, - uint16_t topicLen, - const char* pMsg, - uint32_t msgSize, - uint8_t qos) +static OtaMqttStatus_t prvMQTTPublish( const char * const pacTopic, + uint16_t topicLen, + const char * pMsg, + uint32_t msgSize, + uint8_t qos ) { OtaMqttStatus_t otaRet = OtaMqttSuccess; BaseType_t result; @@ -1547,23 +1672,23 @@ static OtaMqttStatus_t prvMQTTPublish(const char* const pacTopic, publishInfo.payloadLength = msgSize; xCommandContext.xTaskToNotify = xTaskGetCurrentTaskHandle(); - xTaskNotifyStateClear(NULL); + xTaskNotifyStateClear( NULL ); xCommandParams.blockTimeMs = otaexampleMQTT_TIMEOUT_MS; xCommandParams.cmdCompleteCallback = prvCommandCallback; - xCommandParams.pCmdCompleteCallbackContext = (void*)&xCommandContext; + xCommandParams.pCmdCompleteCallbackContext = ( void * ) &xCommandContext; - mqttStatus = MQTTAgent_Publish(&xGlobalMqttAgentContext, - &publishInfo, - &xCommandParams); + mqttStatus = MQTTAgent_Publish( &xGlobalMqttAgentContext, + &publishInfo, + &xCommandParams ); /* Wait for command to complete so MQTTSubscribeInfo_t remains in scope for the * duration of the command. */ - if (mqttStatus == MQTTSuccess) + if( mqttStatus == MQTTSuccess ) { - result = xTaskNotifyWait(0, otaexampleMAX_UINT32, NULL, pdMS_TO_TICKS(otaexampleMQTT_TIMEOUT_MS)); + result = xTaskNotifyWait( 0, otaexampleMAX_UINT32, NULL, pdMS_TO_TICKS( otaexampleMQTT_TIMEOUT_MS ) ); - if (result != pdTRUE) + if( result != pdTRUE ) { mqttStatus = MQTTSendFailed; } @@ -1573,16 +1698,16 @@ static OtaMqttStatus_t prvMQTTPublish(const char* const pacTopic, } } - if (mqttStatus != MQTTSuccess) + if( mqttStatus != MQTTSuccess ) { - LogError(("Failed to send PUBLISH packet to broker with error = %u.", mqttStatus)); + LogError( ( "Failed to send PUBLISH packet to broker with error = %u.", mqttStatus ) ); otaRet = OtaMqttPublishFailed; } else { - LogInfo(("Sent PUBLISH packet to broker %.*s to broker.\n\n", - topicLen, - pacTopic)); + LogInfo( ( "Sent PUBLISH packet to broker %.*s to broker.\n\n", + topicLen, + pacTopic ) ); otaRet = OtaMqttSuccess; } @@ -1590,9 +1715,9 @@ static OtaMqttStatus_t prvMQTTPublish(const char* const pacTopic, return otaRet; } -static OtaMqttStatus_t prvMQTTUnsubscribe(const char* pTopicFilter, - uint16_t topicFilterLength, - uint8_t ucQoS) +static OtaMqttStatus_t prvMQTTUnsubscribe( const char * pTopicFilter, + uint16_t topicFilterLength, + uint8_t ucQoS ) { MQTTStatus_t mqttStatus; uint32_t ulNotifiedValue; @@ -1603,8 +1728,8 @@ static OtaMqttStatus_t prvMQTTUnsubscribe(const char* pTopicFilter, MQTTAgentCommandContext_t xApplicationDefinedContext = { 0 }; OtaMqttStatus_t otaRet = OtaMqttSuccess; - configASSERT(pTopicFilter != NULL); - configASSERT(topicFilterLength > 0); + configASSERT( pTopicFilter != NULL ); + configASSERT( topicFilterLength > 0 ); xSubscribeInfo.pTopicFilter = pTopicFilter; xSubscribeInfo.topicFilterLength = topicFilterLength; @@ -1617,23 +1742,23 @@ static OtaMqttStatus_t prvMQTTUnsubscribe(const char* pTopicFilter, xCommandParams.blockTimeMs = otaexampleMQTT_TIMEOUT_MS; xCommandParams.cmdCompleteCallback = prvMQTTUnsubscribeCompleteCallback; - xCommandParams.pCmdCompleteCallbackContext = (void*)&xApplicationDefinedContext; + xCommandParams.pCmdCompleteCallbackContext = ( void * ) &xApplicationDefinedContext; - LogInfo((" Unsubscribing to topic filter: %s", pTopicFilter)); - xTaskNotifyStateClear(NULL); + LogInfo( ( " Unsubscribing to topic filter: %s", pTopicFilter ) ); + xTaskNotifyStateClear( NULL ); - mqttStatus = MQTTAgent_Unsubscribe(&xGlobalMqttAgentContext, - &xSubscribeArgs, - &xCommandParams); + mqttStatus = MQTTAgent_Unsubscribe( &xGlobalMqttAgentContext, + &xSubscribeArgs, + &xCommandParams ); /* Wait for command to complete so MQTTSubscribeInfo_t remains in scope for the * duration of the command. */ - if (mqttStatus == MQTTSuccess) + if( mqttStatus == MQTTSuccess ) { - result = xTaskNotifyWait(0, otaexampleMAX_UINT32, &ulNotifiedValue, pdMS_TO_TICKS(otaexampleMQTT_TIMEOUT_MS)); + result = xTaskNotifyWait( 0, otaexampleMAX_UINT32, &ulNotifiedValue, pdMS_TO_TICKS( otaexampleMQTT_TIMEOUT_MS ) ); - if (result == pdTRUE) + if( result == pdTRUE ) { mqttStatus = xApplicationDefinedContext.xReturnStatus; } @@ -1643,20 +1768,20 @@ static OtaMqttStatus_t prvMQTTUnsubscribe(const char* pTopicFilter, } } - if (mqttStatus != MQTTSuccess) + if( mqttStatus != MQTTSuccess ) { - LogError(("Failed to UNSUBSCRIBE from topic %.*s with error = %u.", - topicFilterLength, - pTopicFilter, - mqttStatus)); + LogError( ( "Failed to UNSUBSCRIBE from topic %.*s with error = %u.", + topicFilterLength, + pTopicFilter, + mqttStatus ) ); otaRet = OtaMqttUnsubscribeFailed; } else { - LogInfo(("UNSUBSCRIBED from topic %.*s.\n\n", - topicFilterLength, - pTopicFilter)); + LogInfo( ( "UNSUBSCRIBED from topic %.*s.\n\n", + topicFilterLength, + pTopicFilter ) ); otaRet = OtaMqttSuccess; } @@ -1666,9 +1791,9 @@ static OtaMqttStatus_t prvMQTTUnsubscribe(const char* pTopicFilter, /*-----------------------------------------------------------*/ -static void setOtaInterfaces(OtaInterfaces_t* pOtaInterfaces) +static void setOtaInterfaces( OtaInterfaces_t * pOtaInterfaces ) { - configASSERT(pOtaInterfaces != NULL); + configASSERT( pOtaInterfaces != NULL ); /* Initialize OTA library OS Interface. */ pOtaInterfaces->os.event.init = OtaInitEvent_FreeRTOS; @@ -1699,21 +1824,21 @@ static void setOtaInterfaces(OtaInterfaces_t* pOtaInterfaces) /*-----------------------------------------------------------*/ -static void prvOTAAgentTask(void* pParam) +static void prvOTAAgentTask( void * pParam ) { /* Calling OTA agent task. */ - OTA_EventProcessingTask(pParam); - LogInfo(("OTA Agent stopped.")); + OTA_EventProcessingTask( pParam ); + LogInfo( ( "OTA Agent stopped." ) ); - vTaskDelete(NULL); + vTaskDelete( NULL ); } -static void prvMQTTAgentTask(void* pParam) +static void prvMQTTAgentTask( void * pParam ) { BaseType_t xResult = pdFAIL; MQTTStatus_t xMQTTStatus = MQTTSuccess; - (void)pParam; + ( void ) pParam; do { @@ -1722,36 +1847,36 @@ static void prvMQTTAgentTask(void* pParam) * which could be a disconnect. If an error occurs the MQTT context on * which the error happened is returned so there can be an attempt to * clean up and reconnect however the application writer prefers. */ - xMQTTStatus = MQTTAgent_CommandLoop(&xGlobalMqttAgentContext); + xMQTTStatus = MQTTAgent_CommandLoop( &xGlobalMqttAgentContext ); /* Clear Agent queue so that no any pending MQTT operations are processed. */ - MQTTAgent_CancelAll(&xGlobalMqttAgentContext); + MQTTAgent_CancelAll( &xGlobalMqttAgentContext ); /* Success is returned for application initiated disconnect or termination. The socket will also be disconnected by the caller. */ - if (xMQTTStatus != MQTTSuccess) + if( xMQTTStatus != MQTTSuccess ) { xResult = prvSuspendOTA(); - configASSERT(xResult == pdPASS); + configASSERT( xResult == pdPASS ); - LogInfo(("Suspended OTA agent.")); + LogInfo( ( "Suspended OTA agent." ) ); /* End TLS session, then close TCP connection. */ - prvSocketDisconnect(&xNetworkContextMqtt); + prvSocketDisconnect( &xNetworkContextMqtt ); /* Connect to MQTT broker. */ prvConnectToMQTTBroker(); xResult = prvResumeOTA(); - configASSERT(xResult == pdPASS); + configASSERT( xResult == pdPASS ); - LogInfo(("Resumed OTA agent.")); + LogInfo( ( "Resumed OTA agent." ) ); } - } while (xMQTTStatus != MQTTSuccess); + } while( xMQTTStatus != MQTTSuccess ); - vTaskDelete(NULL); + vTaskDelete( NULL ); } -static BaseType_t prvSuspendOTA(void) +static BaseType_t prvSuspendOTA( void ) { /* OTA library return status. */ OtaErr_t otaRet = OtaErrNone; @@ -1760,33 +1885,33 @@ static BaseType_t prvSuspendOTA(void) otaRet = OTA_Suspend(); - if (otaRet == OtaErrNone) + if( otaRet == OtaErrNone ) { suspendTimeout = OTA_SUSPEND_TIMEOUT_MS; - while ((OTA_GetState() != OtaAgentStateSuspended) && (suspendTimeout > 0)) + while( ( OTA_GetState() != OtaAgentStateSuspended ) && ( suspendTimeout > 0 ) ) { /* Wait for OTA Library state to suspend */ - vTaskDelay(pdMS_TO_TICKS(otaexampleTASK_DELAY_MS)); + vTaskDelay( pdMS_TO_TICKS( otaexampleTASK_DELAY_MS ) ); suspendTimeout -= otaexampleTASK_DELAY_MS; } - if (OTA_GetState() != OtaAgentStateSuspended) + if( OTA_GetState() != OtaAgentStateSuspended ) { - LogError(("Failed to suspend OTA.")); + LogError( ( "Failed to suspend OTA." ) ); status = pdFAIL; } } else { - LogError(("Error while trying to suspend OTA agent %d", otaRet)); + LogError( ( "Error while trying to suspend OTA agent %d", otaRet ) ); status = pdFAIL; } return status; } -static BaseType_t prvResumeOTA(void) +static BaseType_t prvResumeOTA( void ) { /* OTA library return status. */ OtaErr_t otaRet = OtaErrNone; @@ -1795,26 +1920,26 @@ static BaseType_t prvResumeOTA(void) otaRet = OTA_Resume(); - if (otaRet == OtaErrNone) + if( otaRet == OtaErrNone ) { suspendTimeout = OTA_SUSPEND_TIMEOUT_MS; - while ((OTA_GetState() == OtaAgentStateSuspended) && (suspendTimeout > 0)) + while( ( OTA_GetState() == OtaAgentStateSuspended ) && ( suspendTimeout > 0 ) ) { /* Wait for OTA Library state to suspend */ - vTaskDelay(pdMS_TO_TICKS(otaexampleTASK_DELAY_MS)); + vTaskDelay( pdMS_TO_TICKS( otaexampleTASK_DELAY_MS ) ); suspendTimeout -= otaexampleTASK_DELAY_MS; } - if (OTA_GetState() == OtaAgentStateSuspended) + if( OTA_GetState() == OtaAgentStateSuspended ) { - LogError(("Failed to resume OTA.")); + LogError( ( "Failed to resume OTA." ) ); status = pdFAIL; } } else { - LogError(("Error while trying to resume OTA agent %d", otaRet)); + LogError( ( "Error while trying to resume OTA agent %d", otaRet ) ); status = pdFAIL; } @@ -1910,7 +2035,7 @@ static BaseType_t prvRunOTADemo( void ) otaStatistics.otaPacketsDropped ) ); } - vTaskDelay( pdMS_TO_TICKS(otaexampleTASK_DELAY_MS) ); + vTaskDelay( pdMS_TO_TICKS( otaexampleTASK_DELAY_MS ) ); } } @@ -1936,7 +2061,7 @@ static BaseType_t prvRunOTADemo( void ) * the OTA agent. If not, it is simply ignored. * */ -static void vOtaDemoTask( void* pvParam ) +static void vOtaDemoTask( void * pvParam ) { /* Return error status. */ BaseType_t xReturnStatus = pdPASS; @@ -1944,7 +2069,7 @@ static void vOtaDemoTask( void* pvParam ) /* Flag for MQTT init status. */ bool mqttInitialized = false; - ( void )pvParam; + ( void ) pvParam; LogInfo( ( "OTA over MQTT demo, Application version %u.%u.%u", appFirmwareVersion.u.x.major, @@ -1962,7 +2087,7 @@ static void vOtaDemoTask( void* pvParam ) /****************************** Init MQTT ******************************/ - if(xReturnStatus == pdPASS ) + if( xReturnStatus == pdPASS ) { /* Create the TCP connection to the broker, then the MQTT connection to the * same. */ @@ -1971,7 +2096,7 @@ static void vOtaDemoTask( void* pvParam ) /****************************** Create MQTT Agent Task. ******************************/ - if(xReturnStatus == pdPASS ) + if( xReturnStatus == pdPASS ) { if( xTaskCreate( prvMQTTAgentTask, "MQTT Agent Task", @@ -1987,7 +2112,7 @@ static void vOtaDemoTask( void* pvParam ) /****************************** Start OTA Demo. ******************************/ - if(xReturnStatus == pdPASS) + if( xReturnStatus == pdPASS ) { /* Start OTA demo. The function returns only if OTA completes successfully and a * shutdown of OTA is triggered for a manual restart of the device.*/ @@ -2014,18 +2139,18 @@ static void vOtaDemoTask( void* pvParam ) /* * @brief Create the task that demonstrates the Ota demo. */ -void vStartOtaDemo(void) +void vStartOtaDemo( void ) { - /* + /* * vOtaDemoTask() connects to the MQTT broker, creates the - * MQTT Agent task and calls the Ota demo loop prvRunOTADemo() - * which creates the OTA Agent task. + * MQTT Agent task and calls the Ota demo loop prvRunOTADemo() + * which creates the OTA Agent task. */ - xTaskCreate(vOtaDemoTask, /* Function that implements the task. */ - "OTA Demo Task", /* Text name for the task - only used for debugging. */ - democonfigDEMO_STACKSIZE, /* Size of stack (in words, not bytes) to allocate for the task. */ - NULL, /* Optional - task parameter - not used in this case. */ - tskIDLE_PRIORITY + 1, /* Task priority, must be between 0 and configMAX_PRIORITIES - 1. */ - NULL); /* Optional - used to pass out a handle to the created task. */ + xTaskCreate( vOtaDemoTask, /* Function that implements the task. */ + "OTA Demo Task", /* Text name for the task - only used for debugging. */ + democonfigDEMO_STACKSIZE, /* Size of stack (in words, not bytes) to allocate for the task. */ + NULL, /* Optional - task parameter - not used in this case. */ + tskIDLE_PRIORITY + 1, /* Task priority, must be between 0 and configMAX_PRIORITIES - 1. */ + NULL ); /* Optional - used to pass out a handle to the created task. */ } diff --git a/FreeRTOS-Plus/Demo/AWS/Ota_Windows_Simulator/Ota_Over_Mqtt_Demo/demo_config.h b/FreeRTOS-Plus/Demo/AWS/Ota_Windows_Simulator/Ota_Over_Mqtt_Demo/demo_config.h index 85bc09a3a9..11ed7cfe26 100644 --- a/FreeRTOS-Plus/Demo/AWS/Ota_Windows_Simulator/Ota_Over_Mqtt_Demo/demo_config.h +++ b/FreeRTOS-Plus/Demo/AWS/Ota_Windows_Simulator/Ota_Over_Mqtt_Demo/demo_config.h @@ -54,7 +54,7 @@ * The function prints to the console before the network is connected; * then a UDP port after the network has connected. */ extern void vLoggingPrintf( const char * pcFormatString, - ... ); + ... ); /* Map the SdkLog macro to the logging function to enable logging * on Windows simulator. */ @@ -72,9 +72,9 @@ extern void vLoggingPrintf( const char * pcFormatString, * download image should be higher than the current version, otherwise the new image is * rejected in self test phase. */ -#define APP_VERSION_MAJOR 0 -#define APP_VERSION_MINOR 9 -#define APP_VERSION_BUILD 2 +#define APP_VERSION_MAJOR 0 +#define APP_VERSION_MINOR 9 +#define APP_VERSION_BUILD 2 /** * @brief The MQTT client identifier used in this example. Each client identifier @@ -88,7 +88,7 @@ extern void vLoggingPrintf( const char * pcFormatString, * * #define democonfigCLIENT_IDENTIFIER "...insert here..." */ -#define democonfigCLIENT_IDENTIFIER "...insert here..." +#define democonfigCLIENT_IDENTIFIER "...insert here..." /** * @brief Endpoint of the MQTT broker to connect to. @@ -105,7 +105,7 @@ extern void vLoggingPrintf( const char * pcFormatString, * * #define democonfigMQTT_BROKER_ENDPOINT "...insert here..." */ -#define democonfigMQTT_BROKER_ENDPOINT "...insert here..." +#define democonfigMQTT_BROKER_ENDPOINT "...insert here..." /** * @brief The port to use for the demo. @@ -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 */