diff --git a/Jenkinsfile b/Jenkinsfile index 99ae34d..eb0d536 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -14,7 +14,7 @@ pipeline { { bat 'git clone %GIT_REPO% .' bat 'git checkout origin/dev/1.2.0' - bat 'git submodule update --init' + bat 'git submodule update --init' } } } @@ -97,7 +97,7 @@ pipeline { for /d %%D in ("STSELib\\doc\\resources\\*") do ( if /i not "%%~nxD"=="__html" if /i not "%%~nxD"=="Pictures" rmdir /s /q "%%D" ) - + REM Remove all files except those in __html and Pictures for %%F in ("STSELib\\doc\\resources\\*") do ( if /i not "%%~nxF"=="__html" if /i not "%%~nxF"=="Pictures" del /q "%%F" @@ -108,7 +108,7 @@ pipeline { REM Remove the resources@tmp folder if exist "STSELib\\doc\\resources@tmp" rmdir /s /q "STSELib\\doc\\resources@tmp" ''' - // Create the documentation release package + // Create the documentation release package bat """ powershell -Command "Compress-Archive -Path 'STSELib\\doc\\*' -DestinationPath 'STSELib_nightly_${BUILD_ID}_${DATE}_documentation.zip' -Force" """ diff --git a/api/stse_aes.c b/api/stse_aes.c index b709a8a..3aa32e8 100644 --- a/api/stse_aes.c +++ b/api/stse_aes.c @@ -84,9 +84,10 @@ stse_ReturnCode_t stse_aes_ccm_encrypt( slot_number, authentication_tag_length, pNonce, - associated_data_length, pAssociated_data, + authentication_tag_length == 0 ? 0 : associated_data_length, + authentication_tag_length == 0 ? NULL : pAssociated_data, message_length, - pPlaintext_message, + message_length == 0 ? NULL : pPlaintext_message, pEncrypted_message, pEncrypted_authentication_tag, counter_presence, pCounter); @@ -207,8 +208,8 @@ stse_ReturnCode_t stse_aes_ccm_decrypt( slot_number, authentication_tag_length, pNonce, - associated_data_length, - pAssociated_data, + authentication_tag_length == 0 ? 0 : associated_data_length, + authentication_tag_length == 0 ? NULL : pAssociated_data, message_length, pEncrypted_message, pEncrypted_authentication_tag, @@ -243,7 +244,7 @@ stse_ReturnCode_t stse_aes_gcm_encrypt( IV_length, pIV, associated_data_length, - pAssociated_data, + associated_data_length == 0 ? NULL : pAssociated_data, message_length, pPlaintext_message, pEncrypted_message, @@ -448,7 +449,7 @@ stse_ReturnCode_t stse_aes_gcm_decrypt( IV_length, pIV, associated_data_length, - pAssociated_data, + associated_data_length == 0 ? NULL : pAssociated_data, message_length, pEncrypted_message, pAuthentication_tag, diff --git a/api/stse_aes.h b/api/stse_aes.h index e16ee9b..fb79068 100644 --- a/api/stse_aes.h +++ b/api/stse_aes.h @@ -183,7 +183,7 @@ stse_ReturnCode_t stse_aes_ccm_encrypt_finish( * \param[in] pNonce Buffer containing the nonce * \param[in] associated_data_length Length of the associated data * \param[in] pAssociated_data Buffer containing associated data - * \param[in] message_length Length of the message to encrypt + * \param[in] message_length Length of the original message (before encryption) * \param[in] pEncrypted_message Buffer containing the message to decrypt * \param[in] pEncrypted_authentication_tag Buffer containing the encrypted authentication tag * \param[out] pVerification_result Verification result flag diff --git a/api/stse_device_management.c b/api/stse_device_management.c index 673e559..f54e1c6 100644 --- a/api/stse_device_management.c +++ b/api/stse_device_management.c @@ -30,6 +30,7 @@ stse_ReturnCode_t stse_init(stse_Handle_t *pSTSE, void *pArg) { #ifdef STSE_CONF_STSAFE_A_SUPPORT PLAT_UI8 mask_id[STSAFEA_MASK_ID_SIZE]; PLAT_UI16 mask_number; + PLAT_UI8 st_number[STSAFEA_ST_NUMBER_SIZE]; #endif /* STSE_CONF_STSAFE_A_SUPPORT */ /* - Check STSAFE handler initialization */ @@ -102,7 +103,7 @@ stse_ReturnCode_t stse_init(stse_Handle_t *pSTSE, void *pArg) { if (pSTSE->device_type != STSAFE_L010) { #endif /* STSE_CONF_STSAFE_L_SUPPORT */ #ifndef STSE_CONF_USE_STATIC_PERSONALIZATION_INFORMATIONS - ret = stsafea_query_mask_id(pSTSE, mask_id); + ret = stsafea_query_mask_id_st_number(pSTSE, mask_id, st_number); if (ret != STSE_OK) { return ret; } diff --git a/api/stse_device_management.h b/api/stse_device_management.h index e0b7b6a..4fa70a7 100644 --- a/api/stse_device_management.h +++ b/api/stse_device_management.h @@ -76,8 +76,8 @@ stse_ReturnCode_t stse_device_reset(stse_Handle_t *pSTSE); /** * \brief Put target device in hibernate mode * \details This function call hibernate service to put the device in hibernate - * \param[in] pSTSE Pointer to STSE Handler - * \param[in] wake_up_mode Event to wake up from, + * \param[in] pSTSE Pointer to STSE Handler + * \param[in] wake_up_mode Event to wake up from (only significant with STSAFE-A devices), * listed in enum \ref stse_hibernate_wake_up_mode_t * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ @@ -103,7 +103,7 @@ stse_ReturnCode_t stse_device_power_off(stse_Handle_t *pSTSE); /** * \brief Send echo command * \details This function call send service to send an echo command - * \param[in] pSTSE Pointer to STSE Handler + * \param[in] pSTSE Pointer to STSE Handler * \param[in] pIn Pointer to data buffer to be sent * \param[out] pOut Pointer to received data buffer * \param[in] size Size in bytes of pIn buffer @@ -126,7 +126,7 @@ stse_ReturnCode_t stse_device_lock(stse_Handle_t *pSTSE, PLAT_UI8 *pPassword, PL /** * \brief Unlock target device * \details This function unlock the target device using the password in argument - * \param[in] pSTSE Pointer to STSE Handler + * \param[in] pSTSE Pointer to STSE Handler * \param[in] pPassword Pointer to the password buffer * \param[in] password_length Length of the password buffer in bytes * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise @@ -138,7 +138,7 @@ stse_ReturnCode_t stse_device_unlock(stse_Handle_t *pSTSE, PLAT_UI8 *pPassword, * \brief Return the record count of command access conditions * \details This function query the access conditions * of the target device command set and return the number of records - * \param[in] pSTSE Pointer to STSE Handler + * \param[in] pSTSE Pointer to STSE Handler * \param[out] record_count Command authorization records count * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise * \details Please refer to stse_device_get_command_AC() @@ -149,7 +149,7 @@ stse_ReturnCode_t stse_device_get_command_count(stse_Handle_t *pSTSE, PLAT_UI8 * * \brief Return the command access conditions and change right * \details This function query the access conditions * of the target device command set - * \param[in] pSTSE Pointer to STSE Handler + * \param[in] pSTSE Pointer to STSE Handler * \param[in] record_count Command authorization records count * \param[out] pChange_rights Pointer to change rights structure of the commands AC and host encrytpion flag * \param[out] pRecord_table Command authorization records table diff --git a/api/stse_symmetric_keys_management.c b/api/stse_symmetric_keys_management.c index 82db536..1b00293 100644 --- a/api/stse_symmetric_keys_management.c +++ b/api/stse_symmetric_keys_management.c @@ -464,7 +464,7 @@ static stse_ReturnCode_t stse_KEK_wrap( ret = stse_platform_nist_kw_encrypt( pPayload, payload_length, working_kek, STSAFEA_KEK_KEY_SIZE, - pEnvelope, NULL); + pEnvelope, &envelope_length); memset(working_kek, 0, STSAFEA_KEK_KEY_SIZE); diff --git a/core/stse_frame.c b/core/stse_frame.c index eac1f53..85d3c0f 100644 --- a/core/stse_frame.c +++ b/core/stse_frame.c @@ -143,7 +143,7 @@ void stse_frame_pop_element(stse_frame_t *pFrame) { /* Select first Frame Element*/ pCurrent_element = pFrame->first_element; /* Parse Frame until previous to last element */ - while (pCurrent_element->next != pFrame->last_element) { + while (pCurrent_element->next != pFrame->last_element && pCurrent_element->next->next != NULL) { pCurrent_element = pCurrent_element->next; } /* Remove references/link to the last element */ diff --git a/services/stsafea/stsafea_aes.c b/services/stsafea/stsafea_aes.c index 9592a54..e083f1b 100644 --- a/services/stsafea/stsafea_aes.c +++ b/services/stsafea/stsafea_aes.c @@ -171,7 +171,7 @@ stse_ReturnCode_t stsafea_aes_ccm_encrypt( } stse_frame_element_allocate_push(&CmdFrame, eMessage_length, STSAFEA_GENERIC_LENGTH_SIZE, (PLAT_UI8 *)&message_length); stse_frame_element_allocate(ePlaintext_message, message_length, pPlaintext_message); - if (associated_data_length != 0) { + if (message_length != 0) { stse_frame_push_element(&CmdFrame, &ePlaintext_message); } @@ -227,7 +227,13 @@ stse_ReturnCode_t stsafea_aes_ccm_encrypt_start( return (STSE_SERVICE_HANDLER_NOT_INITIALISED); } - if ((pNonce == NULL) || (pAssociated_data_chunk == NULL && associated_data_chunk_length != 0) || (pAssociated_data_chunk != NULL && associated_data_chunk_length == 0) || (pPlaintext_message_chunk == NULL && message_chunk_length != 0) || (pPlaintext_message_chunk != NULL && message_chunk_length == 0) || (pEncrypted_message_chunk == NULL && message_chunk_length != 0) || (pEncrypted_message_chunk != NULL && message_chunk_length == 0)) { + if ((pNonce == NULL) || + (pAssociated_data_chunk == NULL && associated_data_chunk_length != 0) || + (pAssociated_data_chunk != NULL && associated_data_chunk_length == 0) || + (pPlaintext_message_chunk == NULL && message_chunk_length != 0) || + (pPlaintext_message_chunk != NULL && message_chunk_length == 0) || + (pEncrypted_message_chunk == NULL && message_chunk_length != 0) || + (pEncrypted_message_chunk != NULL && message_chunk_length == 0)) { return (STSE_SERVICE_INVALID_PARAMETER); } @@ -334,7 +340,16 @@ stse_ReturnCode_t stsafea_aes_ccm_decrypt( return (STSE_SERVICE_HANDLER_NOT_INITIALISED); } - if ((pNonce == NULL) || (pAssociated_data == NULL && associated_data_length != 0) || (pAssociated_data != NULL && associated_data_length == 0) || (pEncrypted_message == NULL && message_length != 0) || (pEncrypted_message != NULL && message_length == 0) || (pPlaintext_message == NULL && message_length != 0) || (pPlaintext_message != NULL && message_length == 0) || (pEncrypted_authentication_tag == NULL && authentication_tag_length != 0) || (pEncrypted_authentication_tag != NULL && authentication_tag_length == 0) || (pVerification_result == NULL)) { + if ((pNonce == NULL) || + (pAssociated_data == NULL && associated_data_length != 0) || + (pAssociated_data != NULL && associated_data_length == 0) || + (pEncrypted_message == NULL && message_length != 0) || + (pEncrypted_message != NULL && message_length == 0) || + (pPlaintext_message == NULL && message_length != 0) || + (pPlaintext_message != NULL && message_length == 0) || + (pEncrypted_authentication_tag == NULL && authentication_tag_length != 0) || + (pEncrypted_authentication_tag != NULL && authentication_tag_length == 0) || + (pVerification_result == NULL)) { return (STSE_SERVICE_INVALID_PARAMETER); } @@ -385,7 +400,13 @@ stse_ReturnCode_t stsafea_aes_ccm_decrypt_start( return (STSE_SERVICE_HANDLER_NOT_INITIALISED); } - if ((pNonce == NULL) || (pAssociated_data_chunk == NULL && associated_data_chunk_length != 0) || (pAssociated_data_chunk != NULL && associated_data_chunk_length == 0) || (pEncrypted_message_chunk == NULL && message_chunk_length != 0) || (pEncrypted_message_chunk != NULL && message_chunk_length == 0) || (pPlaintext_message_chunk == NULL && message_chunk_length != 0) || (pPlaintext_message_chunk != NULL && message_chunk_length == 0)) { + if ((pNonce == NULL) || + (pAssociated_data_chunk == NULL && associated_data_chunk_length != 0) || + (pAssociated_data_chunk != NULL && associated_data_chunk_length == 0) || + (pEncrypted_message_chunk == NULL && message_chunk_length != 0) || + (pEncrypted_message_chunk != NULL && message_chunk_length == 0) || + (pPlaintext_message_chunk == NULL && message_chunk_length != 0) || + (pPlaintext_message_chunk != NULL && message_chunk_length == 0)) { return (STSE_SERVICE_INVALID_PARAMETER); } @@ -476,7 +497,14 @@ stse_ReturnCode_t stsafea_aes_gcm_encrypt( return (STSE_SERVICE_HANDLER_NOT_INITIALISED); } - if ((pIV == NULL || IV_length == 0) || (pAssociated_data == NULL && pPlaintext_message == NULL) || (pAssociated_data == NULL && associated_data_length != 0) || (pAssociated_data != NULL && associated_data_length == 0) || (pPlaintext_message == NULL && message_length != 0) || (pPlaintext_message != NULL && message_length == 0) || (pEncrypted_message == NULL && pPlaintext_message != NULL) || (pAuthentication_tag == NULL)) { + if ((pIV == NULL || IV_length == 0) || + (pAssociated_data == NULL && pPlaintext_message == NULL) || + (pAssociated_data == NULL && associated_data_length != 0) || + (pAssociated_data != NULL && associated_data_length == 0) || + (pPlaintext_message == NULL && message_length != 0) || + (pPlaintext_message != NULL && message_length == 0) || + (pEncrypted_message == NULL && pPlaintext_message != NULL) || + (pAuthentication_tag == NULL)) { return (STSE_SERVICE_INVALID_PARAMETER); } diff --git a/services/stsafea/stsafea_frame_transfer.c b/services/stsafea/stsafea_frame_transfer.c index 5ce2922..a7e34a3 100644 --- a/services/stsafea/stsafea_frame_transfer.c +++ b/services/stsafea/stsafea_frame_transfer.c @@ -86,7 +86,7 @@ stse_ReturnCode_t stsafea_frame_transmit(stse_Handle_t *pSTSE, stse_frame_t *pFr if (ret == STSE_OK) { pCurrent_element = pFrame->first_element; - while (pCurrent_element != pFrame->last_element) { + while (pCurrent_element != pFrame->last_element && pCurrent_element != NULL) { ret = pSTSE->io.BusSendContinue( pSTSE->io.busID, pSTSE->io.Devaddr, @@ -325,7 +325,7 @@ stse_ReturnCode_t stsafea_frame_receive(stse_Handle_t *pSTSE, stse_frame_t *pFra /* - Perform frame element reception and populate local RSP Frame */ pCurrent_element = pFrame->first_element->next; - while (pCurrent_element != pFrame->last_element) { + while (pCurrent_element != pFrame->last_element && pCurrent_element != NULL) { if (received_length < pCurrent_element->length) { pCurrent_element->length = received_length; } diff --git a/services/stsafea/stsafea_put_query.c b/services/stsafea/stsafea_put_query.c index d636ab2..4023d82 100644 --- a/services/stsafea/stsafea_put_query.c +++ b/services/stsafea/stsafea_put_query.c @@ -25,6 +25,7 @@ #ifdef STSE_CONF_STSAFE_A_SUPPORT #define STSAFEA_SUB_TAG_MASK_ID 0x01 +#define STSAFEA_SUB_TAG_ST_NUMBER 0x02 stse_ReturnCode_t stsafea_put_life_cyle_state( stse_Handle_t *pSTSE, @@ -149,14 +150,15 @@ stse_ReturnCode_t stsafea_query_i2c_parameters( stsafea_cmd_timings[pSTSE->device_type][cmd_header]); } -stse_ReturnCode_t stsafea_query_mask_id( +stse_ReturnCode_t stsafea_query_mask_id_st_number( stse_Handle_t *pSTSE, - PLAT_UI8 mask_id[STSAFEA_MASK_ID_SIZE]) { + PLAT_UI8 mask_id[STSAFEA_MASK_ID_SIZE], + PLAT_UI8 st_number[STSAFEA_ST_NUMBER_SIZE]) { PLAT_UI8 cmd_header = STSAFEA_CMD_QUERY; PLAT_UI8 tag = STSAFEA_SUBJECT_TAG_PRODUCT_DATA; PLAT_UI8 rsp_header; - PLAT_UI8 sub_tag; - PLAT_UI8 sub_tag_size; + PLAT_UI8 sub_tag_mask_id, sub_tag_mask_id_size; + PLAT_UI8 sub_tag_st_number, sub_tag_st_number_size; stse_ReturnCode_t ret; if (pSTSE == NULL) { @@ -171,9 +173,12 @@ stse_ReturnCode_t stsafea_query_mask_id( /*- Create Rsp frame and populate elements*/ stse_frame_allocate(RspFrame); stse_frame_element_allocate_push(&RspFrame, eRsp_header, 1, &rsp_header); - stse_frame_element_allocate_push(&RspFrame, e_sub_tag, 1, &sub_tag); - stse_frame_element_allocate_push(&RspFrame, e_sub_tag_size, 1, &sub_tag_size); + stse_frame_element_allocate_push(&RspFrame, e_sub_tag_mask_id, 1, &sub_tag_mask_id); + stse_frame_element_allocate_push(&RspFrame, e_sub_tag_mask_id_size, 1, &sub_tag_mask_id_size); stse_frame_element_allocate_push(&RspFrame, e_mask_id, STSAFEA_MASK_ID_SIZE, mask_id); + stse_frame_element_allocate_push(&RspFrame, e_sub_tag_st_number, 1, &sub_tag_st_number); + stse_frame_element_allocate_push(&RspFrame, e_sub_tag_st_number_size, 1, &sub_tag_st_number_size); + stse_frame_element_allocate_push(&RspFrame, e_st_number, STSAFEA_ST_NUMBER_SIZE, st_number); /*- Perform Transfer*/ ret = stsafea_frame_raw_transfer(pSTSE, @@ -181,7 +186,8 @@ stse_ReturnCode_t stsafea_query_mask_id( &RspFrame, stsafea_cmd_timings[pSTSE->device_type][cmd_header]); - if (sub_tag != STSAFEA_SUB_TAG_MASK_ID) { + if ((sub_tag_mask_id != STSAFEA_SUB_TAG_MASK_ID) || (sub_tag_mask_id_size != STSAFEA_MASK_ID_SIZE) || + (sub_tag_st_number != STSAFEA_SUB_TAG_ST_NUMBER) || (sub_tag_st_number_size != STSAFEA_ST_NUMBER_SIZE)) { return (STSE_SERVICE_INCOMPATIBLE_DEVICE_TYPE); } diff --git a/services/stsafea/stsafea_put_query.h b/services/stsafea/stsafea_put_query.h index ec16ea3..aeb0741 100644 --- a/services/stsafea/stsafea_put_query.h +++ b/services/stsafea/stsafea_put_query.h @@ -74,7 +74,8 @@ #define STSAFEA_SUBJECT_TAG_GENERIC_PUBLIC_KEY_SLOT 0x4C /*!< Generic public key slot subject-tag */ #define STSAFEA_SUBJECT_TAG_GENERIC_PUBLIC_KEY_CONFIGURATION_FLAGS 0x4D /*!< Generic public key configuration flags subject-tag */ -#define STSAFEA_MASK_ID_SIZE 3 /*!< Mask identification size */ +#define STSAFEA_MASK_ID_SIZE 3 /*!< Mask identification size */ +#define STSAFEA_ST_NUMBER_SIZE 9 /*!< ST number size */ /*! * \enum stsafea_life_cycle_state_t @@ -105,7 +106,7 @@ typedef struct /** * \brief STSAFEA put life cycle service * \details This service format and send/receive the put life cycle command/response - * \param[in] pSTSE Pointer to STSE Handler + * \param[in] pSTSE Pointer to STSE Handle * \param[in] life_cycle_state Life cycle state * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ @@ -116,7 +117,7 @@ stse_ReturnCode_t stsafea_put_life_cyle_state( /** * \brief STSAFEA put life cycle service * \details This service format and send/receive the put life cycle command/response - * \param[in] pSTSE Pointer to STSE Handler + * \param[in] pSTSE Pointer to STSE Handle * \param[out] pLife_cycle_state Life cycle state * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ @@ -127,7 +128,7 @@ stse_ReturnCode_t stsafea_query_life_cycle_state( /** * \brief STSAFEA put I2C parameters service * \details This service format and send/receive the put I2C parameters command/response - * \param[in] pSTSE Pointer to STSE Handler + * \param[in] pSTSE Pointer to STSE Handle * \param[in] pI2c_parameters I2C parameters * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ @@ -138,7 +139,7 @@ stse_ReturnCode_t stsafea_put_i2c_parameters( /** * \brief STSAFEA query I2C parameters service * \details This service format and send/receive the query I2C parameters command/response - * \param[in] pSTSE Pointer to STSE Handler + * \param[in] pSTSE Pointer to STSE Handle * \param[out] pI2c_parameters I2C parameters * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ @@ -147,15 +148,17 @@ stse_ReturnCode_t stsafea_query_i2c_parameters( stsafea_i2c_parameters_t *pI2c_parameters); /** - * \brief STSAFEA query mask identification service - * \details This service format and send/receive the mask identification command/response - * \param[in] pSTSE Pointer to STSE Handler + * \brief STSAFEA query mask identification & ST number service + * \details This service format and send/receive the mask identification & ST number command/response + * \param[in] pSTSE Pointer to STSE Handle * \param[out] mask_id Mask identification (3 bytes) + * \param[out] st_number ST number (7 bytes) * \return \ref STSE_OK on success ; \ref stse_ReturnCode_t error code otherwise */ -stse_ReturnCode_t stsafea_query_mask_id( +stse_ReturnCode_t stsafea_query_mask_id_st_number( stse_Handle_t *pSTSE, - PLAT_UI8 mask_id[STSAFEA_MASK_ID_SIZE]); + PLAT_UI8 mask_id[STSAFEA_MASK_ID_SIZE], + PLAT_UI8 st_number[STSAFEA_ST_NUMBER_SIZE]); /** \}*/ diff --git a/services/stsafel/stsafel_frame_transfer.c b/services/stsafel/stsafel_frame_transfer.c index c3b32dc..f20efcd 100644 --- a/services/stsafel/stsafel_frame_transfer.c +++ b/services/stsafel/stsafel_frame_transfer.c @@ -83,7 +83,7 @@ stse_ReturnCode_t stsafel_frame_transmit(stse_Handle_t *pSTSE, stse_frame_t *pFr if (ret == STSE_OK) { pCurrent_element = pFrame->first_element; - while (pCurrent_element != pFrame->last_element) { + while (pCurrent_element != pFrame->last_element && pCurrent_element != NULL) { ret = pSTSE->io.BusSendContinue( pSTSE->io.busID, pSTSE->io.Devaddr, @@ -283,7 +283,7 @@ stse_ReturnCode_t stsafel_i2c_frame_receive(stse_Handle_t *pSTSE, stse_frame_t * /* - Perform frame element reception and populate local RSP Frame */ pCurrent_element = pFrame->first_element->next; - while (pCurrent_element != pFrame->last_element) { + while (pCurrent_element != pFrame->last_element && pCurrent_element != NULL) { if (received_length < pCurrent_element->length) { pCurrent_element->length = received_length; } @@ -422,7 +422,7 @@ stse_ReturnCode_t stsafel_st1wire_frame_receive(stse_Handle_t *pSTSE, stse_frame /* - Perform frame element reception and populate local RSP Frame */ pCurrent_element = pFrame->first_element->next; - while (pCurrent_element != pFrame->last_element) { + while (pCurrent_element != pFrame->last_element && pCurrent_element != NULL) { if (received_length < pCurrent_element->length) { pCurrent_element->length = received_length; }