Skip to content

Commit

Permalink
Merge branch 'master' into ota/fix_late_callback_event_handling
Browse files Browse the repository at this point in the history
  • Loading branch information
pvyawaha committed May 21, 2020
2 parents ec0eaa3 + a446766 commit f01a4ef
Show file tree
Hide file tree
Showing 8 changed files with 396 additions and 379 deletions.
3 changes: 2 additions & 1 deletion demos/demo_runner/iot_demo_freertos.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ static void _onNetworkStateChangeCallback( uint32_t network,
pNetworkInterface );
}
}
else if( ( state == eNetworkStateDisabled ) && ( demoConnectedNetwork == network ) )
else if( ( ( state == eNetworkStateDisabled ) || ( state == eNetworkStateUnknown ) ) &&
( demoConnectedNetwork == network ) )
{
if( pDemoContext->networkDisconnectedCallback != NULL )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ CK_RV xDestroyProvidedObjects( CK_SESSION_HANDLE xSession,
pxLabel = ppxPkcsLabels[ uiIndex ];

xResult = xFindObjectWithLabelAndClass( xSession,
( const char * ) pxLabel,
( char * ) pxLabel,
xClass[ uiIndex ],
&xObjectHandle );

Expand All @@ -762,7 +762,7 @@ CK_RV xDestroyProvidedObjects( CK_SESSION_HANDLE xSession,
if( xResult == CKR_OK )
{
xResult = xFindObjectWithLabelAndClass( xSession,
( const char * ) pxLabel,
( char * ) pxLabel,
xClass[ uiIndex ],
&xObjectHandle );
}
Expand Down
693 changes: 347 additions & 346 deletions libraries/abstractions/pkcs11/mbedtls/iot_pkcs11_mbedtls.c

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion libraries/abstractions/pkcs11/test/iot_test_pkcs11.c
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ void prvFindObjectTest( void )

/* Try to find an object that has never been created. */
xResult = xFindObjectWithLabelAndClass( xGlobalSession,
( const char * ) "This label doesn't exist",
( char * ) "This label doesn't exist",
CKO_PUBLIC_KEY,
&xTestObjectHandle );
TEST_ASSERT_EQUAL_MESSAGE( CKR_OK, xResult, "Incorrect error code finding object that doesn't exist" );
Expand Down
6 changes: 3 additions & 3 deletions libraries/freertos_plus/standard/pkcs11/include/iot_pkcs11.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ typedef struct PKCS11_CertificateTemplate
CK_ATTRIBUTE xValue; /**< @brief CKA_VALUE, the DER byte array of the certificate contents. */
CK_ATTRIBUTE xLabel; /**< @brief CKA_LABEL. */
CK_ATTRIBUTE xTokenObject; /**< @brief CKA_TOKEN. */
} PKCS11_CertificateTemplate_t, * PKCS11_CertificateTemplatePtr_t;
} PKCS11_CertificateTemplate_t;

/*------------------------ PKCS #11 wrapper functions -------------------------*/

Expand Down Expand Up @@ -299,7 +299,7 @@ CK_RV xInitializePkcs11Token( void );
*/
/* @[declare_pkcs11_iot_xfindobjectwithlabelandclass] */
CK_RV xFindObjectWithLabelAndClass( CK_SESSION_HANDLE xSession,
const char * pcLabelName,
char * pcLabelName,
CK_OBJECT_CLASS xClass,
CK_OBJECT_HANDLE_PTR pxHandle );
/* @[declare_pkcs11_iot_xfindobjectwithlabelandclass] */
Expand All @@ -324,7 +324,7 @@ CK_RV xFindObjectWithLabelAndClass( CK_SESSION_HANDLE xSession,
*
*/
/* @[declare_pkcs11_iot_vappendsha256algorithmidentifiersequence] */
CK_RV vAppendSHA256AlgorithmIdentifierSequence( uint8_t * puc32ByteHashedMessage,
CK_RV vAppendSHA256AlgorithmIdentifierSequence( const uint8_t * puc32ByteHashedMessage,
uint8_t * puc51ByteHashOidBuffer );
/* @[declare_pkcs11_iot_vappendsha256algorithmidentifiersequence] */

Expand Down
24 changes: 12 additions & 12 deletions libraries/freertos_plus/standard/pkcs11/src/iot_pkcs11.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
*
* \return CKR_OK or PKCS #11 error code. (PKCS #11 error codes are positive).
*/
CK_RV prvOpenSession( CK_SESSION_HANDLE * pxSession,
CK_SLOT_ID xSlotId )
static CK_RV prvOpenSession( CK_SESSION_HANDLE * pxSession,
CK_SLOT_ID xSlotId )
{
CK_RV xResult;
CK_FUNCTION_LIST_PTR pxFunctionList;
Expand Down Expand Up @@ -196,12 +196,12 @@ CK_RV xInitializePkcs11Token( void )
xTokenFlags = pxTokenInfo->flags;
}

if( ( CKR_OK == xResult ) && !( CKF_TOKEN_INITIALIZED & xTokenFlags ) )
if( ( CKR_OK == xResult ) && ( ( CKF_TOKEN_INITIALIZED & xTokenFlags ) != CKF_TOKEN_INITIALIZED ) )
{
/* Initialize the token if it is not already. */
xResult = pxFunctionList->C_InitToken( pxSlotId[ 0 ],
( CK_UTF8CHAR_PTR ) configPKCS11_DEFAULT_USER_PIN,
sizeof( configPKCS11_DEFAULT_USER_PIN ) - 1,
sizeof( configPKCS11_DEFAULT_USER_PIN ) - 1UL,
( CK_UTF8CHAR_PTR ) "FreeRTOS" );
}
}
Expand Down Expand Up @@ -270,15 +270,15 @@ CK_RV xInitializePkcs11Session( CK_SESSION_HANDLE * pxSession )
xResult = pxFunctionList->C_Login( *pxSession,
CKU_USER,
( CK_UTF8CHAR_PTR ) configPKCS11_DEFAULT_USER_PIN,
sizeof( configPKCS11_DEFAULT_USER_PIN ) - 1 );
sizeof( configPKCS11_DEFAULT_USER_PIN ) - 1UL );
}

return xResult;
}
/*-----------------------------------------------------------*/

CK_RV xFindObjectWithLabelAndClass( CK_SESSION_HANDLE xSession,
const char * pcLabelName,
char * pcLabelName,
CK_OBJECT_CLASS xClass,
CK_OBJECT_HANDLE_PTR pxHandle )
{
Expand All @@ -294,7 +294,7 @@ CK_RV xFindObjectWithLabelAndClass( CK_SESSION_HANDLE xSession,
else
{
xTemplate[ 0 ].type = CKA_LABEL;
xTemplate[ 0 ].pValue = ( char * ) pcLabelName;
xTemplate[ 0 ].pValue = ( CK_VOID_PTR ) pcLabelName;
xTemplate[ 0 ].ulValueLen = strlen( pcLabelName );

xTemplate[ 1 ].type = CKA_CLASS;
Expand Down Expand Up @@ -325,7 +325,7 @@ CK_RV xFindObjectWithLabelAndClass( CK_SESSION_HANDLE xSession,
xResult = pxFunctionList->C_FindObjectsFinal( xSession );
}

if( ( NULL != pxHandle ) && ( ulCount == 0 ) )
if( ( NULL != pxHandle ) && ( ulCount == 0UL ) )
{
*pxHandle = CK_INVALID_HANDLE;
}
Expand All @@ -335,11 +335,11 @@ CK_RV xFindObjectWithLabelAndClass( CK_SESSION_HANDLE xSession,

/*-----------------------------------------------------------*/

CK_RV vAppendSHA256AlgorithmIdentifierSequence( uint8_t * puc32ByteHashedMessage,
CK_RV vAppendSHA256AlgorithmIdentifierSequence( const uint8_t * puc32ByteHashedMessage,
uint8_t * puc51ByteHashOidBuffer )
{
CK_RV xResult = CKR_OK;
uint8_t pucOidSequence[] = pkcs11STUFF_APPENDED_TO_RSA_SIG;
const uint8_t pucOidSequence[] = pkcs11STUFF_APPENDED_TO_RSA_SIG;

if( ( puc32ByteHashedMessage == NULL ) || ( puc51ByteHashOidBuffer == NULL ) )
{
Expand All @@ -348,8 +348,8 @@ CK_RV vAppendSHA256AlgorithmIdentifierSequence( uint8_t * puc32ByteHashedMessage

if( xResult == CKR_OK )
{
memcpy( puc51ByteHashOidBuffer, pucOidSequence, sizeof( pucOidSequence ) );
memcpy( &puc51ByteHashOidBuffer[ sizeof( pucOidSequence ) ], puc32ByteHashedMessage, 32 );
( void ) memcpy( puc51ByteHashOidBuffer, pucOidSequence, sizeof( pucOidSequence ) );
( void ) memcpy( &puc51ByteHashOidBuffer[ sizeof( pucOidSequence ) ], puc32ByteHashedMessage, 32 );
}

return xResult;
Expand Down
2 changes: 1 addition & 1 deletion libraries/freertos_plus/standard/tls/src/iot_tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ static int prvPrivateKeySigningCallback( void * pvContext,
* @return Zero on success.
*/
static int prvReadCertificateIntoContext( TLSContext_t * pxTlsContext,
const char * pcLabelName,
char * pcLabelName,
CK_OBJECT_CLASS xClass,
mbedtls_x509_crt * pxCertificateContext )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ uint32_t app_timer_create(app_timer_id_t const * p_timer_id,
app_timer_info_t * pinfo = (app_timer_info_t*)(*p_timer_id);
uint32_t err_code = NRF_SUCCESS;
unsigned long timer_mode;
TimerHandle_t timer_handle;

if ((timeout_handler == NULL) || (p_timer_id == NULL))
{
Expand All @@ -133,26 +134,40 @@ uint32_t app_timer_create(app_timer_id_t const * p_timer_id,
return NRF_ERROR_INVALID_STATE;
}

if (pinfo->osHandle == NULL)
/* If a FreeRTOS timer already exists, delete and recreate the timer. */
if (pinfo->osHandle != NULL)
{
/* New timer is created */
memset(pinfo, 0, sizeof(app_timer_info_t));
timer_handle = ( TimerHandle_t ) ( pinfo->osHandle );
/* Return error if the timer is active */
if( xTimerIsTimerActive( timer_handle ) )
{
return NRF_ERROR_INVALID_STATE;
}

if (mode == APP_TIMER_MODE_SINGLE_SHOT)
timer_mode = pdFALSE;
else
timer_mode = pdTRUE;
if( xTimerDelete( timer_handle, portMAX_DELAY ) != pdTRUE )
{
return NRF_ERROR_INVALID_STATE;
}
}

pinfo->func = timeout_handler;
pinfo->osHandle = xTimerCreate(" ", 1000, timer_mode, pinfo, app_timer_callback);
/* New timer is created */
memset(pinfo, 0, sizeof(app_timer_info_t));

if (pinfo->osHandle == NULL)
err_code = NRF_ERROR_NULL;
if (mode == APP_TIMER_MODE_SINGLE_SHOT)
{
timer_mode = pdFALSE;
}
else
{
/* Timer cannot be reinitialized using FreeRTOS API */
return NRF_ERROR_INVALID_STATE;
timer_mode = pdTRUE;
}

pinfo->func = timeout_handler;
pinfo->osHandle = xTimerCreate(" ", 1000, timer_mode, pinfo, app_timer_callback);

if (pinfo->osHandle == NULL)
{
err_code = NRF_ERROR_NULL;
}

return err_code;
Expand Down

0 comments on commit f01a4ef

Please sign in to comment.