diff options
author | Tiangang Song <ts.whu@outlook.com> | 2020-10-05 15:00:12 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-05 15:00:12 -0700 |
commit | c2a9775726006dae2ebe2fb9c40cbd8c1c005d5b (patch) | |
tree | 21bb2d56cea8d07b0bdc995fbda511b48c5c381d | |
parent | 0e002d3263e95c0e6d7715f155d22c2a467cd0b7 (diff) | |
download | freertos-git-c2a9775726006dae2ebe2fb9c40cbd8c1c005d5b.tar.gz |
Sync OTA from latest AFR master branch (#320)
8 files changed, 51 insertions, 22 deletions
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta1/c_sdk/aws/ota/include/aws_iot_ota_agent.h b/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta1/c_sdk/aws/ota/include/aws_iot_ota_agent.h index 69040c1ac..ea5a9970f 100755 --- a/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta1/c_sdk/aws/ota/include/aws_iot_ota_agent.h +++ b/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta1/c_sdk/aws/ota/include/aws_iot_ota_agent.h @@ -405,7 +405,7 @@ typedef struct OTA_FileContext { int32_t lFileHandle; /*!< Device internal file pointer or handle. * File type is handle after file is open for write. */ - #if WIN32 + #ifdef WIN32 FILE * pxFile; /*!< File type is stdio FILE structure after file is open for write. */ #endif uint8_t * pucFile; /*!< File type is RAM/Flash image pointer after file is open for write. */ @@ -620,7 +620,7 @@ OTA_State_t OTA_AgentInit_internal( void * pvConnectionContext, * returned to the caller. * * @return One of the OTA agent states from the OTA_State_t enum. - * A normal shutdown will return eOTA_AgentState_NotReady. Otherwise, refer to the OTA_State_t enum for details. + * A normal shutdown will return eOTA_AgentState_Stopped. Otherwise, refer to the OTA_State_t enum for details. */ OTA_State_t OTA_AgentShutdown( TickType_t xTicksToWait ); diff --git a/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta1/c_sdk/aws/ota/src/aws_iot_ota_agent.c b/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta1/c_sdk/aws/ota/src/aws_iot_ota_agent.c index 29a79c329..35d704a48 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta1/c_sdk/aws/ota/src/aws_iot_ota_agent.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta1/c_sdk/aws/ota/src/aws_iot_ota_agent.c @@ -23,9 +23,6 @@ * http://www.FreeRTOS.org */ -/* The config header is always included first. */ -#include "iot_config.h" - /* Standard library includes. */ #include <stddef.h> #include <string.h> @@ -1307,7 +1304,6 @@ static OTA_Err_t prvResumeHandler( OTA_EventData_t * pxEventData ) static OTA_Err_t prvJobNotificationHandler( OTA_EventData_t * pxEventData ) { ( void ) pxEventData; - OTA_Err_t xErr = kOTA_Err_Uninitialized; OTA_EventMsg_t xEventMsg = { 0 }; /* We receieved job notification so stop the data request timer. */ @@ -2654,7 +2650,13 @@ static void prvAgentShutdownCleanup( void ) xOTA_Agent.xRequestTimer = NULL; } - /* Cleanup related to selected protocol. */ + /* Control plane cleanup related to selected protocol. */ + if( xOTA_ControlInterface.prvCleanup != NULL ) + { + ( void ) xOTA_ControlInterface.prvCleanup( &xOTA_Agent ); + } + + /* Data plane cleanup related to selected protocol. */ if( xOTA_DataInterface.prvCleanup != NULL ) { ( void ) xOTA_DataInterface.prvCleanup( &xOTA_Agent ); diff --git a/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta1/c_sdk/aws/ota/src/aws_iot_ota_interface.c b/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta1/c_sdk/aws/ota/src/aws_iot_ota_interface.c index 2f9b81ead..0ec5b6761 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta1/c_sdk/aws/ota/src/aws_iot_ota_interface.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta1/c_sdk/aws/ota/src/aws_iot_ota_interface.c @@ -74,6 +74,7 @@ void prvSetControlInterface( OTA_ControlInterface_t * pxControlInterface ) #if ( configENABLED_CONTROL_PROTOCOL == OTA_CONTROL_OVER_MQTT ) pxControlInterface->prvRequestJob = prvRequestJob_Mqtt; pxControlInterface->prvUpdateJobStatus = prvUpdateJobStatus_Mqtt; + pxControlInterface->prvCleanup = prvCleanupControl_Mqtt; #else #error "Enable MQTT control as control operations are only supported over MQTT." #endif @@ -97,7 +98,7 @@ OTA_Err_t prvSetDataInterface( OTA_DataInterface_t * pxDataInterface, pxDataInterface->prvInitFileTransfer = prvInitFileTransfer_Mqtt; pxDataInterface->prvRequestFileBlock = prvRequestFileBlock_Mqtt; pxDataInterface->prvDecodeFileBlock = prvDecodeFileBlock_Mqtt; - pxDataInterface->prvCleanup = prvCleanup_Mqtt; + pxDataInterface->prvCleanup = prvCleanupData_Mqtt; OTA_LOG_L1( "[%s] Data interface is set to MQTT.\r\n", OTA_METHOD_NAME ); @@ -112,7 +113,7 @@ OTA_Err_t prvSetDataInterface( OTA_DataInterface_t * pxDataInterface, pxDataInterface->prvInitFileTransfer = _AwsIotOTA_InitFileTransfer_HTTP; pxDataInterface->prvRequestFileBlock = _AwsIotOTA_RequestDataBlock_HTTP; pxDataInterface->prvDecodeFileBlock = _AwsIotOTA_DecodeFileBlock_HTTP; - pxDataInterface->prvCleanup = _AwsIotOTA_Cleanup_HTTP; + pxDataInterface->prvCleanup = _AwsIotOTA_CleanupData_HTTP; OTA_LOG_L1( "[%s] Data interface is set to HTTP.\r\n", OTA_METHOD_NAME ); diff --git a/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta1/c_sdk/aws/ota/src/aws_iot_ota_interface.h b/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta1/c_sdk/aws/ota/src/aws_iot_ota_interface.h index 0ab5abb5a..ca5aaa0c5 100755 --- a/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta1/c_sdk/aws/ota/src/aws_iot_ota_interface.h +++ b/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta1/c_sdk/aws/ota/src/aws_iot_ota_interface.h @@ -54,6 +54,7 @@ typedef struct OTA_JobStatus_t eStatus, int32_t lReason, int32_t lSubReason ); + OTA_Err_t ( * prvCleanup )( OTA_AgentContext_t * pAgentCtx ); } OTA_ControlInterface_t; /** diff --git a/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta1/c_sdk/aws/ota/src/http/aws_iot_ota_http.c b/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta1/c_sdk/aws/ota/src/http/aws_iot_ota_http.c index d1a6b6b54..c775fe17b 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta1/c_sdk/aws/ota/src/http/aws_iot_ota_http.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta1/c_sdk/aws/ota/src/http/aws_iot_ota_http.c @@ -1170,9 +1170,9 @@ OTA_Err_t _AwsIotOTA_DecodeFileBlock_HTTP( uint8_t * pMessageBuffer, } -OTA_Err_t _AwsIotOTA_Cleanup_HTTP( OTA_AgentContext_t * pAgentCtx ) +OTA_Err_t _AwsIotOTA_CleanupData_HTTP( OTA_AgentContext_t * pAgentCtx ) { - IotLogDebug( "Invoking _AwsIotOTA_Cleanup_HTTP" ); + IotLogDebug( "Invoking _AwsIotOTA_CleanupData_HTTP" ); /* Unused parameters. */ ( void ) pAgentCtx; diff --git a/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta1/c_sdk/aws/ota/src/http/aws_iot_ota_http.h b/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta1/c_sdk/aws/ota/src/http/aws_iot_ota_http.h index e7e775a78..abb6280e6 100755 --- a/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta1/c_sdk/aws/ota/src/http/aws_iot_ota_http.h +++ b/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta1/c_sdk/aws/ota/src/http/aws_iot_ota_http.h @@ -43,6 +43,6 @@ OTA_Err_t _AwsIotOTA_DecodeFileBlock_HTTP( uint8_t * pMessageBuffer, uint8_t ** pPayload, size_t * pPayloadSize ); -OTA_Err_t _AwsIotOTA_Cleanup_HTTP( OTA_AgentContext_t * pxAgentCtx ); +OTA_Err_t _AwsIotOTA_CleanupData_HTTP( OTA_AgentContext_t * pxAgentCtx ); #endif /* ifndef __AWS_OTA_HTTP__H__ */ diff --git a/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta1/c_sdk/aws/ota/src/mqtt/aws_iot_ota_mqtt.c b/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta1/c_sdk/aws/ota/src/mqtt/aws_iot_ota_mqtt.c index 21ab6b010..b8da7fd42 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta1/c_sdk/aws/ota/src/mqtt/aws_iot_ota_mqtt.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta1/c_sdk/aws/ota/src/mqtt/aws_iot_ota_mqtt.c @@ -224,12 +224,14 @@ static bool prvUnSubscribeFromDataStream( const OTA_AgentContext_t * pxAgentCtx IotMqttSubscription_t xUnSub; + xUnSub.qos = IOT_MQTT_QOS_0; + bool bResult = false; char pcOTA_RxStreamTopic[ OTA_MAX_TOPIC_LEN ]; - xUnSub.qos = IOT_MQTT_QOS_0; + const OTA_FileContext_t * pFileContext = &( pxAgentCtx->pxOTA_Files[ pxAgentCtx->ulFileIndex ] ); - if( pxAgentCtx != NULL ) + if( ( pFileContext != NULL ) && ( pFileContext->pucStreamName != NULL ) ) { /* Try to build the dynamic data stream topic and un-subscribe from it. */ @@ -237,7 +239,7 @@ static bool prvUnSubscribeFromDataStream( const OTA_AgentContext_t * pxAgentCtx sizeof( pcOTA_RxStreamTopic ), pcOTA_StreamData_TopicTemplate, pxAgentCtx->pcThingName, - ( const char * ) pxAgentCtx->pxOTA_Files[ 0 ].pucStreamName ); + ( const char * ) pFileContext->pucStreamName ); if( ( xUnSub.topicFilterLength > 0U ) && ( xUnSub.topicFilterLength < sizeof( pcOTA_RxStreamTopic ) ) ) { @@ -759,6 +761,7 @@ OTA_Err_t prvInitFileTransfer_Mqtt( OTA_AgentContext_t * pxAgentCtx ) OTA_Err_t xResult = kOTA_Err_PublishFailed; char pcOTA_RxStreamTopic[ OTA_MAX_TOPIC_LEN ]; IotMqttSubscription_t xOTAUpdateDataSubscription; + const OTA_FileContext_t * pFileContext = &( pxAgentCtx->pxOTA_Files[ pxAgentCtx->ulFileIndex ] ); memset( &xOTAUpdateDataSubscription, 0, sizeof( xOTAUpdateDataSubscription ) ); xOTAUpdateDataSubscription.qos = IOT_MQTT_QOS_0; @@ -769,7 +772,7 @@ OTA_Err_t prvInitFileTransfer_Mqtt( OTA_AgentContext_t * pxAgentCtx ) sizeof( pcOTA_RxStreamTopic ), pcOTA_StreamData_TopicTemplate, pxAgentCtx->pcThingName, - ( const char * ) pxAgentCtx->pxOTA_Files->pucStreamName ); + ( const char * ) pFileContext->pucStreamName ); if( ( xOTAUpdateDataSubscription.topicFilterLength > 0U ) && ( xOTAUpdateDataSubscription.topicFilterLength < sizeof( pcOTA_RxStreamTopic ) ) ) { @@ -935,16 +938,25 @@ OTA_Err_t prvDecodeFileBlock_Mqtt( uint8_t * pucMessageBuffer, } /* - * Perform any cleanup operations required like unsubscribing from - * job topics. + * Perform any cleanup operations required for control plane. */ -OTA_Err_t prvCleanup_Mqtt( OTA_AgentContext_t * pxAgentCtx ) +OTA_Err_t prvCleanupControl_Mqtt( OTA_AgentContext_t * pxAgentCtx ) { - DEFINE_OTA_METHOD_NAME( "prvCleanup_Mqtt" ); + DEFINE_OTA_METHOD_NAME( "prvCleanupControl_Mqtt" ); /* Unsubscribe from job notification topics. */ prvUnSubscribeFromJobNotificationTopic( pxAgentCtx ); + return kOTA_Err_None; +} + +/* + * Perform any cleanup operations required for data plane. + */ +OTA_Err_t prvCleanupData_Mqtt( OTA_AgentContext_t * pxAgentCtx ) +{ + DEFINE_OTA_METHOD_NAME( "prvCleanupData_Mqtt" ); + /* Unsubscribe from data stream topics. */ prvUnSubscribeFromDataStream( pxAgentCtx ); diff --git a/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta1/c_sdk/aws/ota/src/mqtt/aws_iot_ota_mqtt.h b/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta1/c_sdk/aws/ota/src/mqtt/aws_iot_ota_mqtt.h index 91cd09a63..a07800865 100755 --- a/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta1/c_sdk/aws/ota/src/mqtt/aws_iot_ota_mqtt.h +++ b/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta1/c_sdk/aws/ota/src/mqtt/aws_iot_ota_mqtt.h @@ -96,7 +96,7 @@ OTA_Err_t prvDecodeFileBlock_Mqtt( uint8_t * pucMessageBuffer, size_t * pxPayloadSize ); /** - * @brief Cleanup related to OTA over MQTT. + * @brief Cleanup related to OTA control plane over MQTT. * * This function perfroms cleanup by unsubscribing from any topics that were * subscribed for performing OTA over MQTT. @@ -106,7 +106,20 @@ OTA_Err_t prvDecodeFileBlock_Mqtt( uint8_t * pucMessageBuffer, * @return The OTA error code. See OTA Agent error codes information in aws_iot_ota_agent.h. */ -OTA_Err_t prvCleanup_Mqtt( OTA_AgentContext_t * pxAgentCtx ); +OTA_Err_t prvCleanupControl_Mqtt( OTA_AgentContext_t * pxAgentCtx ); + +/** + * @brief Cleanup related to OTA data plane over MQTT. + * + * This function perfroms cleanup by unsubscribing from any topics that were + * subscribed for performing OTA over MQTT. + * + * @param[in] pxAgentCtx The OTA agent context. + * + * @return The OTA error code. See OTA Agent error codes information in aws_iot_ota_agent.h. + */ + +OTA_Err_t prvCleanupData_Mqtt( OTA_AgentContext_t * pxAgentCtx ); /** * @brief Update job status over MQTT. |