mirror of
https://github.com/FreeRTOS/FreeRTOS.git
synced 2026-10-02 16:24:45 +08:00
Sync OTA from latest AFR master branch (#320)
This commit is contained in:
+2
-2
@@ -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 );
|
||||
|
||||
|
||||
+7
-5
@@ -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 );
|
||||
|
||||
+3
-2
@@ -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 );
|
||||
|
||||
|
||||
+1
@@ -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;
|
||||
|
||||
/**
|
||||
|
||||
+2
-2
@@ -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;
|
||||
|
||||
+1
-1
@@ -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__ */
|
||||
|
||||
+20
-8
@@ -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 );
|
||||
|
||||
|
||||
+15
-2
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user