in source/ota.c [2558:2630]
static IngestResult_t decodeAndStoreDataBlock( OtaFileContext_t * pFileContext,
const uint8_t * pRawMsg,
uint32_t messageSize,
uint8_t ** pPayload,
uint32_t * pBlockSize,
uint32_t * pBlockIndex )
{
IngestResult_t eIngestResult = IngestResultUninitialized;
int32_t lFileId = 0;
int32_t sBlockSize = 0;
int32_t sBlockIndex = 0;
size_t payloadSize = 0;
/* If we are expecting a data block, allocate space for it. */
if( ( pFileContext->pRxBlockBitmap != NULL ) && ( pFileContext->blocksRemaining > 0U ) )
{
( void ) otaAgent.pOtaInterface->os.timer.start( OtaRequestTimer,
"OtaRequestTimer",
otaconfigFILE_REQUEST_WAIT_MS,
otaTimerCallback );
if( otaAgent.fileContext.decodeMemMaxSize != 0U )
{
*pPayload = otaAgent.fileContext.pDecodeMem;
payloadSize = otaAgent.fileContext.decodeMemMaxSize;
}
else
{
*pPayload = otaAgent.pOtaInterface->os.mem.malloc( 1UL << otaconfigLOG2_FILE_BLOCK_SIZE );
if( *pPayload != NULL )
{
payloadSize = ( 1UL << otaconfigLOG2_FILE_BLOCK_SIZE );
}
}
}
else
{
eIngestResult = IngestResultUnexpectedBlock;
}
/* Decode the file block if space is allocated. */
if( payloadSize > 0u )
{
/* Decode the file block received. */
if( OtaErrNone != otaDataInterface.decodeFileBlock(
pRawMsg,
messageSize,
&lFileId,
&sBlockIndex,
&sBlockSize,
pPayload,
&payloadSize ) )
{
eIngestResult = IngestResultBadData;
}
else
{
*pBlockIndex = ( uint32_t ) sBlockIndex;
*pBlockSize = ( uint32_t ) sBlockSize;
}
}
else
{
/* If the block is expected, but we could not allocate space. */
if( eIngestResult == IngestResultUninitialized )
{
eIngestResult = IngestResultNoDecodeMemory;
}
}
return eIngestResult;
}