mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-12-23 11:09:28 -05:00
Update transport interface for compatibility (#844)
Update transport interface for compatibility * Update the network transport that using socket wrapper to depend on socket wrapper only. * AT command timeout should not be changed for cellular socket buffer access mode. * mbedTLS config include using MBEDTLS_CONFIG_FILE macro. * Remove strnlen usage in using_mbedtls_pkcs11.
This commit is contained in:
parent
2e772110e3
commit
0fc242b7db
9 changed files with 125 additions and 119 deletions
|
|
@ -89,9 +89,6 @@ extern uint8_t CellularSocketPdnContextId;
|
|||
#define CELLULAR_SOCKET_OPEN_TIMEOUT_TICKS ( portMAX_DELAY )
|
||||
#define CELLULAR_SOCKET_CLOSE_TIMEOUT_TICKS ( pdMS_TO_TICKS( 10000U ) )
|
||||
|
||||
/* Cellular socket AT command timeout. */
|
||||
#define CELLULAR_SOCKET_RECV_TIMEOUT_MS ( 1000UL )
|
||||
|
||||
/* Time conversion constants. */
|
||||
#define _MILLISECONDS_PER_SECOND ( 1000 ) /**< @brief Milliseconds per second. */
|
||||
#define _MILLISECONDS_PER_TICK ( _MILLISECONDS_PER_SECOND / configTICK_RATE_HZ ) /**< Milliseconds per FreeRTOS tick. */
|
||||
|
|
@ -447,7 +444,6 @@ static BaseType_t prvSetupSocketRecvTimeout( cellularSocketWrapper_t * pCellular
|
|||
static BaseType_t prvSetupSocketSendTimeout( cellularSocketWrapper_t * pCellularSocketContext,
|
||||
TickType_t sendTimeout )
|
||||
{
|
||||
CellularError_t socketStatus = CELLULAR_SUCCESS;
|
||||
BaseType_t retSetSockOpt = SOCKETS_ERROR_NONE;
|
||||
uint32_t sendTimeoutMs = 0;
|
||||
CellularSocketHandle_t cellularSocketHandle = NULL;
|
||||
|
|
@ -478,18 +474,6 @@ static BaseType_t prvSetupSocketSendTimeout( cellularSocketWrapper_t * pCellular
|
|||
pCellularSocketContext->sendTimeout = sendTimeout;
|
||||
sendTimeoutMs = TICKS_TO_MS( sendTimeout );
|
||||
}
|
||||
|
||||
socketStatus = Cellular_SocketSetSockOpt( CellularHandle,
|
||||
cellularSocketHandle,
|
||||
CELLULAR_SOCKET_OPTION_LEVEL_TRANSPORT,
|
||||
CELLULAR_SOCKET_OPTION_SEND_TIMEOUT,
|
||||
( const uint8_t * ) &sendTimeoutMs,
|
||||
sizeof( uint32_t ) );
|
||||
|
||||
if( socketStatus != CELLULAR_SUCCESS )
|
||||
{
|
||||
retSetSockOpt = SOCKETS_EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
return retSetSockOpt;
|
||||
|
|
@ -599,7 +583,6 @@ BaseType_t Sockets_Connect( Socket_t * pTcpSocket,
|
|||
CellularSocketAddress_t serverAddress = { 0 };
|
||||
EventBits_t waitEventBits = 0;
|
||||
BaseType_t retConnect = SOCKETS_ERROR_NONE;
|
||||
const uint32_t defaultReceiveTimeoutMs = CELLULAR_SOCKET_RECV_TIMEOUT_MS;
|
||||
|
||||
/* Create a new TCP socket. */
|
||||
cellularSocketStatus = Cellular_CreateSocket( CellularHandle,
|
||||
|
|
@ -660,23 +643,6 @@ BaseType_t Sockets_Connect( Socket_t * pTcpSocket,
|
|||
retConnect = prvCellularSocketRegisterCallback( cellularSocketHandle, pCellularSocketContext );
|
||||
}
|
||||
|
||||
/* Setup cellular socket recv AT command default timeout. */
|
||||
if( retConnect == SOCKETS_ERROR_NONE )
|
||||
{
|
||||
cellularSocketStatus = Cellular_SocketSetSockOpt( CellularHandle,
|
||||
cellularSocketHandle,
|
||||
CELLULAR_SOCKET_OPTION_LEVEL_TRANSPORT,
|
||||
CELLULAR_SOCKET_OPTION_RECV_TIMEOUT,
|
||||
( const uint8_t * ) &defaultReceiveTimeoutMs,
|
||||
sizeof( uint32_t ) );
|
||||
|
||||
if( cellularSocketStatus != CELLULAR_SUCCESS )
|
||||
{
|
||||
IotLogError( "Failed to setup cellular AT command receive timeout %d.", cellularSocketStatus );
|
||||
retConnect = SOCKETS_SOCKET_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
/* Setup cellular socket send/recv timeout. */
|
||||
if( retConnect == SOCKETS_ERROR_NONE )
|
||||
{
|
||||
|
|
@ -923,7 +889,7 @@ int32_t Sockets_Send( Socket_t xSocket,
|
|||
}
|
||||
}
|
||||
|
||||
IotLogDebug( "Sockets_Send expect %d write %d", len, sentLength );
|
||||
IotLogDebug( "Sockets_Send expect %d write %d", xDataLength, sentLength );
|
||||
}
|
||||
|
||||
return retSendLength;
|
||||
|
|
|
|||
|
|
@ -53,6 +53,9 @@
|
|||
#define LIBRARY_LOG_LEVEL LOG_INFO
|
||||
#endif
|
||||
|
||||
extern void vLoggingPrintf( const char * pcFormatString,
|
||||
... );
|
||||
|
||||
#include "logging_stack.h"
|
||||
|
||||
/************ End of logging configuration ****************/
|
||||
|
|
|
|||
|
|
@ -75,6 +75,8 @@ extern void vLoggingPrintf( const char * pcFormatString,
|
|||
|
||||
/************ End of logging configuration ****************/
|
||||
|
||||
#define SOCKETS_INVALID_SOCKET ( ( Socket_t ) ~0U )
|
||||
|
||||
/**
|
||||
* @brief Establish a connection to server.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -36,10 +36,6 @@
|
|||
/* FreeRTOS includes. */
|
||||
#include "FreeRTOS.h"
|
||||
|
||||
/* FreeRTOS+TCP includes. */
|
||||
#include "FreeRTOS_IP.h"
|
||||
#include "FreeRTOS_Sockets.h"
|
||||
|
||||
/* TLS transport header. */
|
||||
#include "using_mbedtls.h"
|
||||
|
||||
|
|
@ -700,9 +696,9 @@ TlsTransportStatus_t TLS_FreeRTOS_Connect( NetworkContext_t * pNetworkContext,
|
|||
{
|
||||
sslContextFree( &( pTlsTransportParams->sslContext ) );
|
||||
|
||||
if( pTlsTransportParams->tcpSocket != FREERTOS_INVALID_SOCKET )
|
||||
if( pTlsTransportParams->tcpSocket != SOCKETS_INVALID_SOCKET )
|
||||
{
|
||||
( void ) FreeRTOS_closesocket( pTlsTransportParams->tcpSocket );
|
||||
( void ) Sockets_Disconnect( pTlsTransportParams->tcpSocket );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,10 +39,6 @@
|
|||
/* FreeRTOS includes. */
|
||||
#include "FreeRTOS.h"
|
||||
|
||||
/* FreeRTOS+TCP includes. */
|
||||
#include "FreeRTOS_IP.h"
|
||||
#include "FreeRTOS_Sockets.h"
|
||||
|
||||
/* TLS transport header. */
|
||||
#include "using_mbedtls_pkcs11.h"
|
||||
|
||||
|
|
@ -530,12 +526,25 @@ static CK_RV readCertificateIntoContext( SSLContext_t * pSslContext,
|
|||
CK_RV xResult = CKR_OK;
|
||||
CK_ATTRIBUTE xTemplate = { 0 };
|
||||
CK_OBJECT_HANDLE xCertObj = 0;
|
||||
size_t labelLength;
|
||||
char * pcNullTerminator = NULL;
|
||||
|
||||
/* Check for NULL character within pkcs11configMAX_LABEL_LENGTH. */
|
||||
pcNullTerminator = memchr( pcLabelName, '\0', pkcs11configMAX_LABEL_LENGTH );
|
||||
if( NULL != pcNullTerminator )
|
||||
{
|
||||
labelLength = ( size_t )( pcNullTerminator - pcLabelName );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* If NULL character not found set length to pkcs11configMAX_LABEL_LENGTH. */
|
||||
labelLength = pkcs11configMAX_LABEL_LENGTH;
|
||||
}
|
||||
|
||||
/* Get the handle of the certificate. */
|
||||
xResult = xFindObjectWithLabelAndClass( pSslContext->xP11Session,
|
||||
pcLabelName,
|
||||
strnlen( pcLabelName,
|
||||
pkcs11configMAX_LABEL_LENGTH ),
|
||||
labelLength,
|
||||
xClass,
|
||||
&xCertObj );
|
||||
|
||||
|
|
@ -648,11 +657,25 @@ static CK_RV initializeClientKeys( SSLContext_t * pxCtx,
|
|||
|
||||
if( CKR_OK == xResult )
|
||||
{
|
||||
size_t labelLength;
|
||||
char * pcNullTerminator = NULL;
|
||||
|
||||
/* Check for NULL character within pkcs11configMAX_LABEL_LENGTH. */
|
||||
pcNullTerminator = memchr( pcLabelName, '\0', pkcs11configMAX_LABEL_LENGTH );
|
||||
if( NULL != pcNullTerminator )
|
||||
{
|
||||
labelLength = ( size_t )( pcNullTerminator - pcLabelName );
|
||||
}
|
||||
else
|
||||
{
|
||||
/* If NULL character not found set length to pkcs11configMAX_LABEL_LENGTH. */
|
||||
labelLength = pkcs11configMAX_LABEL_LENGTH;
|
||||
}
|
||||
|
||||
/* Get the handle of the device private key. */
|
||||
xResult = xFindObjectWithLabelAndClass( pxCtx->xP11Session,
|
||||
pcLabelName,
|
||||
strnlen( pcLabelName,
|
||||
pkcs11configMAX_LABEL_LENGTH ),
|
||||
labelLength,
|
||||
CKO_PRIVATE_KEY,
|
||||
&pxCtx->xP11PrivateKey );
|
||||
}
|
||||
|
|
@ -901,9 +924,10 @@ TlsTransportStatus_t TLS_FreeRTOS_Connect( NetworkContext_t * pNetworkContext,
|
|||
if( returnStatus != TLS_TRANSPORT_SUCCESS )
|
||||
{
|
||||
if( ( pNetworkContext != NULL ) &&
|
||||
( pTlsTransportParams->tcpSocket != FREERTOS_INVALID_SOCKET ) )
|
||||
( pTlsTransportParams != NULL ) &&
|
||||
( pTlsTransportParams->tcpSocket != SOCKETS_INVALID_SOCKET ) )
|
||||
{
|
||||
( void ) FreeRTOS_closesocket( pTlsTransportParams->tcpSocket );
|
||||
( void ) Sockets_Disconnect( pTlsTransportParams->tcpSocket );
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ extern void vLoggingPrintf( const char * pcFormatString,
|
|||
/************ End of logging configuration ****************/
|
||||
|
||||
/* FreeRTOS+TCP include. */
|
||||
#include "FreeRTOS_Sockets.h"
|
||||
#include "sockets_wrapper.h"
|
||||
|
||||
/* Transport interface include. */
|
||||
#include "transport_interface.h"
|
||||
|
|
|
|||
|
|
@ -31,13 +31,16 @@
|
|||
|
||||
/* FreeRTOS includes. */
|
||||
#include "FreeRTOS.h"
|
||||
#include "FreeRTOS_Sockets.h"
|
||||
|
||||
/* Sockets wrapper includes. */
|
||||
#include "sockets_wrapper.h"
|
||||
|
||||
/* mbed TLS includes. */
|
||||
#include "mbedtls_config.h"
|
||||
#if !defined( MBEDTLS_CONFIG_FILE )
|
||||
#include "config.h"
|
||||
#else
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
#include "threading_alt.h"
|
||||
#include "mbedtls/entropy.h"
|
||||
#include "mbedtls/ssl.h"
|
||||
|
|
|
|||
|
|
@ -34,7 +34,11 @@
|
|||
#include "FreeRTOS_Sockets.h"
|
||||
|
||||
/* mbed TLS includes. */
|
||||
#include "mbedtls_config.h"
|
||||
#if !defined( MBEDTLS_CONFIG_FILE )
|
||||
#include "config.h"
|
||||
#else
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
#include "threading_alt.h"
|
||||
#include "mbedtls/entropy.h"
|
||||
#include "mbedtls/ssl.h"
|
||||
|
|
|
|||
|
|
@ -34,7 +34,11 @@
|
|||
#include "FreeRTOS_Sockets.h"
|
||||
|
||||
/* mbed TLS includes. */
|
||||
#include "mbedtls_config.h"
|
||||
#if !defined( MBEDTLS_CONFIG_FILE )
|
||||
#include "config.h"
|
||||
#else
|
||||
#include MBEDTLS_CONFIG_FILE
|
||||
#endif
|
||||
#include "threading_alt.h"
|
||||
#include "mbedtls/entropy.h"
|
||||
#include "mbedtls/ssl.h"
|
||||
|
|
@ -180,6 +184,7 @@ int mbedtls_platform_mutex_unlock( mbedtls_threading_mutex_t * pMutex )
|
|||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
#ifdef _WIN32
|
||||
/**
|
||||
* @brief Function to generate a random number.
|
||||
*
|
||||
|
|
@ -224,9 +229,11 @@ int mbedtls_platform_entropy_poll( void * data,
|
|||
|
||||
return status;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
#ifdef _WIN32
|
||||
/**
|
||||
* @brief Function to generate a random number based on a hardware poll.
|
||||
*
|
||||
|
|
@ -248,5 +255,6 @@ int mbedtls_hardware_poll( void * data,
|
|||
{
|
||||
return mbedtls_platform_entropy_poll( data, output, len, olen );
|
||||
}
|
||||
#endif
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue