mirror of
https://github.com/FreeRTOS/FreeRTOS.git
synced 2025-06-18 22:33:36 +08:00
Support multiple transports in the same compilation unit (#434)
By removing the definition of the NetworkContext struct in the header file, we allow the application to define it. This allows an application writer to use multiple transports in the same compilation unit. That way, multiple .c files do not have to be created for each transport.
This commit is contained in:

committed by
GitHub

parent
a9fd30af94
commit
73b0d1b259
@ -116,6 +116,12 @@ typedef enum
|
|||||||
ReportStatusAccepted,
|
ReportStatusAccepted,
|
||||||
ReportStatusRejected
|
ReportStatusRejected
|
||||||
} ReportStatus_t;
|
} ReportStatus_t;
|
||||||
|
|
||||||
|
/* Each compilation unit must define the NetworkContext struct. */
|
||||||
|
struct NetworkContext
|
||||||
|
{
|
||||||
|
TlsTransportParams_t * pParams;
|
||||||
|
};
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -128,6 +134,11 @@ static MQTTContext_t xMqttContext;
|
|||||||
*/
|
*/
|
||||||
static NetworkContext_t xNetworkContext;
|
static NetworkContext_t xNetworkContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The parameters for the network context using mbedTLS operation.
|
||||||
|
*/
|
||||||
|
static TlsTransportParams_t xTlsTransportParams;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Static buffer used to hold MQTT messages being sent and received.
|
* @brief Static buffer used to hold MQTT messages being sent and received.
|
||||||
*/
|
*/
|
||||||
@ -626,6 +637,9 @@ void prvDefenderDemoTask( void * pvParameters )
|
|||||||
/* Remove compiler warnings about unused parameters. */
|
/* Remove compiler warnings about unused parameters. */
|
||||||
( void ) pvParameters;
|
( void ) pvParameters;
|
||||||
|
|
||||||
|
/* Set the pParams member of the network context with desired transport. */
|
||||||
|
xNetworkContext.pParams = &xTlsTransportParams;
|
||||||
|
|
||||||
/* Start with report not received. */
|
/* Start with report not received. */
|
||||||
xReportStatus = ReportStatusNotReceived;
|
xReportStatus = ReportStatusNotReceived;
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* FreeRTOS Kernel V10.3.0
|
* FreeRTOS V202011.00
|
||||||
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
@ -19,10 +19,9 @@
|
|||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*
|
*
|
||||||
* http://www.FreeRTOS.org
|
* https://www.FreeRTOS.org
|
||||||
* http://aws.amazon.com/freertos
|
* https://github.com/FreeRTOS
|
||||||
*
|
*
|
||||||
* 1 tab == 4 spaces!
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/***
|
/***
|
||||||
|
@ -22,7 +22,6 @@
|
|||||||
* https://www.FreeRTOS.org
|
* https://www.FreeRTOS.org
|
||||||
* https://github.com/FreeRTOS
|
* https://github.com/FreeRTOS
|
||||||
*
|
*
|
||||||
* 1 tab == 4 spaces!
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -162,6 +161,14 @@
|
|||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* Each compilation unit must define the NetworkContext struct. */
|
||||||
|
struct NetworkContext
|
||||||
|
{
|
||||||
|
TlsTransportParams_t * pParams;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The MQTT context used for MQTT operation.
|
* @brief The MQTT context used for MQTT operation.
|
||||||
*/
|
*/
|
||||||
@ -172,6 +179,11 @@ static MQTTContext_t xMqttContext;
|
|||||||
*/
|
*/
|
||||||
static NetworkContext_t xNetworkContext;
|
static NetworkContext_t xNetworkContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The parameters for the network context using mbedTLS operation.
|
||||||
|
*/
|
||||||
|
static TlsTransportParams_t xTlsTransportParams;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Static buffer used to hold MQTT messages being sent and received.
|
* @brief Static buffer used to hold MQTT messages being sent and received.
|
||||||
*/
|
*/
|
||||||
@ -590,6 +602,9 @@ void prvShadowDemoTask( void * pvParameters )
|
|||||||
/* Remove compiler warnings about unused parameters. */
|
/* Remove compiler warnings about unused parameters. */
|
||||||
( void ) pvParameters;
|
( void ) pvParameters;
|
||||||
|
|
||||||
|
/* Set the pParams member of the network context with desired transport. */
|
||||||
|
xNetworkContext.pParams = &xTlsTransportParams;
|
||||||
|
|
||||||
/****************************** Connect. ******************************/
|
/****************************** Connect. ******************************/
|
||||||
|
|
||||||
demoStatus = xEstablishMqttSession( &xMqttContext,
|
demoStatus = xEstablishMqttSession( &xMqttContext,
|
||||||
|
@ -223,6 +223,14 @@ typedef enum JobActionType
|
|||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* Each compilation unit must define the NetworkContext struct. */
|
||||||
|
struct NetworkContext
|
||||||
|
{
|
||||||
|
TlsTransportParams_t * pParams;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The MQTT context used for MQTT operation.
|
* @brief The MQTT context used for MQTT operation.
|
||||||
*/
|
*/
|
||||||
@ -233,6 +241,11 @@ static MQTTContext_t xMqttContext;
|
|||||||
*/
|
*/
|
||||||
static NetworkContext_t xNetworkContext;
|
static NetworkContext_t xNetworkContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The parameters for the network context using mbedTLS operation.
|
||||||
|
*/
|
||||||
|
static TlsTransportParams_t xTlsTransportParams;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Static buffer used to hold MQTT messages being sent and received.
|
* @brief Static buffer used to hold MQTT messages being sent and received.
|
||||||
*/
|
*/
|
||||||
@ -726,6 +739,9 @@ void prvJobsDemoTask( void * pvParameters )
|
|||||||
/* Remove compiler warnings about unused parameters. */
|
/* Remove compiler warnings about unused parameters. */
|
||||||
( void ) pvParameters;
|
( void ) pvParameters;
|
||||||
|
|
||||||
|
/* Set the pParams member of the network context with desired transport. */
|
||||||
|
xNetworkContext.pParams = &xTlsTransportParams;
|
||||||
|
|
||||||
/* Establish an MQTT connection with AWS IoT over a mutually authenticated TLS session. */
|
/* Establish an MQTT connection with AWS IoT over a mutually authenticated TLS session. */
|
||||||
xDemoStatus = xEstablishMqttSession( &xMqttContext,
|
xDemoStatus = xEstablishMqttSession( &xMqttContext,
|
||||||
&xNetworkContext,
|
&xNetworkContext,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* FreeRTOS Kernel V10.3.0
|
* FreeRTOS V202011.00
|
||||||
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
@ -19,10 +19,9 @@
|
|||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*
|
*
|
||||||
* http://www.FreeRTOS.org
|
* https://www.FreeRTOS.org
|
||||||
* http://aws.amazon.com/freertos
|
* https://github.com/FreeRTOS
|
||||||
*
|
*
|
||||||
* 1 tab == 4 spaces!
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/***
|
/***
|
||||||
|
@ -202,6 +202,14 @@ typedef struct PublishPackets
|
|||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* Each compilation unit must define the NetworkContext struct. */
|
||||||
|
struct NetworkContext
|
||||||
|
{
|
||||||
|
TlsTransportParams_t * pParams;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Global entry time into the application to use as a reference timestamp
|
* @brief Global entry time into the application to use as a reference timestamp
|
||||||
* in the #prvGetTimeMs function. #prvGetTimeMs will always return the difference
|
* in the #prvGetTimeMs function. #prvGetTimeMs will always return the difference
|
||||||
@ -583,9 +591,8 @@ BaseType_t xEstablishMqttSession( MQTTContext_t * pxMqttContext,
|
|||||||
configASSERT( pxMqttContext != NULL );
|
configASSERT( pxMqttContext != NULL );
|
||||||
configASSERT( pxNetworkContext != NULL );
|
configASSERT( pxNetworkContext != NULL );
|
||||||
|
|
||||||
/* Initialize the mqtt context and network context. */
|
/* Initialize the mqtt context. */
|
||||||
( void ) memset( pxMqttContext, 0U, sizeof( MQTTContext_t ) );
|
( void ) memset( pxMqttContext, 0U, sizeof( MQTTContext_t ) );
|
||||||
( void ) memset( pxNetworkContext, 0U, sizeof( NetworkContext_t ) );
|
|
||||||
|
|
||||||
if( prvConnectToServerWithBackoffRetries( pxNetworkContext ) != TLS_TRANSPORT_SUCCESS )
|
if( prvConnectToServerWithBackoffRetries( pxNetworkContext ) != TLS_TRANSPORT_SUCCESS )
|
||||||
{
|
{
|
||||||
|
@ -56,6 +56,15 @@
|
|||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* Each compilation unit must define the NetworkContext struct.
|
||||||
|
* void * is used as this utility can be used by both plaintext and TLS demos. */
|
||||||
|
struct NetworkContext
|
||||||
|
{
|
||||||
|
void * pParams;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
extern UBaseType_t uxRand();
|
extern UBaseType_t uxRand();
|
||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* FreeRTOS Kernel V10.3.0
|
* FreeRTOS V202011.00
|
||||||
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
@ -19,8 +19,8 @@
|
|||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*
|
*
|
||||||
* http://www.FreeRTOS.org
|
* https://www.FreeRTOS.org
|
||||||
* http://aws.amazon.com/freertos
|
* https://github.com/FreeRTOS
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -122,6 +122,12 @@
|
|||||||
*/
|
*/
|
||||||
#define IOT_CORE_ALPN_PROTOCOL_NAME "\x0ex-amzn-http-ca"
|
#define IOT_CORE_ALPN_PROTOCOL_NAME "\x0ex-amzn-http-ca"
|
||||||
|
|
||||||
|
/* Each compilation unit must define the NetworkContext struct. */
|
||||||
|
struct NetworkContext
|
||||||
|
{
|
||||||
|
TlsTransportParams_t * pParams;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief A buffer used in the demo for storing HTTP request headers and
|
* @brief A buffer used in the demo for storing HTTP request headers and
|
||||||
* HTTP response headers and body.
|
* HTTP response headers and body.
|
||||||
@ -207,6 +213,7 @@ static void prvHTTPDemoTask( void * pvParameters )
|
|||||||
TransportInterface_t xTransportInterface;
|
TransportInterface_t xTransportInterface;
|
||||||
/* The network context for the transport layer interface. */
|
/* The network context for the transport layer interface. */
|
||||||
NetworkContext_t xNetworkContext = { 0 };
|
NetworkContext_t xNetworkContext = { 0 };
|
||||||
|
TlsTransportParams_t xTlsTransportParams = { 0 };
|
||||||
BaseType_t xIsConnectionEstablished = pdFALSE;
|
BaseType_t xIsConnectionEstablished = pdFALSE;
|
||||||
|
|
||||||
/* The user of this demo must check the logs for any failure codes. */
|
/* The user of this demo must check the logs for any failure codes. */
|
||||||
@ -215,6 +222,9 @@ static void prvHTTPDemoTask( void * pvParameters )
|
|||||||
/* Remove compiler warnings about unused parameters. */
|
/* Remove compiler warnings about unused parameters. */
|
||||||
( void ) pvParameters;
|
( void ) pvParameters;
|
||||||
|
|
||||||
|
/* Set the pParams member of the network context with desired transport. */
|
||||||
|
xNetworkContext.pParams = &xTlsTransportParams;
|
||||||
|
|
||||||
/**************************** Connect. ******************************/
|
/**************************** Connect. ******************************/
|
||||||
|
|
||||||
/* Attempt to connect to the HTTP server. If connection fails, retry after a
|
/* Attempt to connect to the HTTP server. If connection fails, retry after a
|
||||||
|
@ -164,6 +164,12 @@
|
|||||||
*/
|
*/
|
||||||
#define httpexampleNUMBER_HTTP_PATHS ( 4 )
|
#define httpexampleNUMBER_HTTP_PATHS ( 4 )
|
||||||
|
|
||||||
|
/* Each compilation unit must define the NetworkContext struct. */
|
||||||
|
struct NetworkContext
|
||||||
|
{
|
||||||
|
PlaintextTransportParams_t * pParams;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief A pair containing a path string of the URI and its length.
|
* @brief A pair containing a path string of the URI and its length.
|
||||||
*/
|
*/
|
||||||
@ -269,6 +275,7 @@ static void prvHTTPDemoTask( void * pvParameters )
|
|||||||
TransportInterface_t xTransportInterface;
|
TransportInterface_t xTransportInterface;
|
||||||
/* The network context for the transport layer interface. */
|
/* The network context for the transport layer interface. */
|
||||||
NetworkContext_t xNetworkContext = { 0 };
|
NetworkContext_t xNetworkContext = { 0 };
|
||||||
|
PlaintextTransportParams_t xPlaintextTransportParams = { 0 };
|
||||||
/* An array of HTTP paths to request. */
|
/* An array of HTTP paths to request. */
|
||||||
const httpPathStrings_t xHttpMethodPaths[] =
|
const httpPathStrings_t xHttpMethodPaths[] =
|
||||||
{
|
{
|
||||||
@ -294,6 +301,9 @@ static void prvHTTPDemoTask( void * pvParameters )
|
|||||||
/* Remove compiler warnings about unused parameters. */
|
/* Remove compiler warnings about unused parameters. */
|
||||||
( void ) pvParameters;
|
( void ) pvParameters;
|
||||||
|
|
||||||
|
/* Set the pParams member of the network context with desired transport. */
|
||||||
|
xNetworkContext.pParams = &xPlaintextTransportParams;
|
||||||
|
|
||||||
/**************************** Connect. ******************************/
|
/**************************** Connect. ******************************/
|
||||||
|
|
||||||
/* Attempt to connect to the HTTP server. If connection fails, retry after a
|
/* Attempt to connect to the HTTP server. If connection fails, retry after a
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* FreeRTOS Kernel V10.3.0
|
* FreeRTOS V202011.00
|
||||||
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
@ -19,10 +19,9 @@
|
|||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*
|
*
|
||||||
* http://www.FreeRTOS.org
|
* https://www.FreeRTOS.org
|
||||||
* http://aws.amazon.com/freertos
|
* https://github.com/FreeRTOS
|
||||||
*
|
*
|
||||||
* 1 tab == 4 spaces!
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/***
|
/***
|
||||||
|
@ -185,6 +185,14 @@
|
|||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* Each compilation unit must define the NetworkContext struct. */
|
||||||
|
struct NetworkContext
|
||||||
|
{
|
||||||
|
TlsTransportParams_t * pParams;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The task used to demonstrate the MQTT API.
|
* @brief The task used to demonstrate the MQTT API.
|
||||||
*
|
*
|
||||||
@ -386,6 +394,7 @@ static void prvMQTTDemoTask( void * pvParameters )
|
|||||||
uint32_t ulPublishCount = 0U, ulTopicCount = 0U;
|
uint32_t ulPublishCount = 0U, ulTopicCount = 0U;
|
||||||
const uint32_t ulMaxPublishCount = 5UL;
|
const uint32_t ulMaxPublishCount = 5UL;
|
||||||
NetworkContext_t xNetworkContext = { 0 };
|
NetworkContext_t xNetworkContext = { 0 };
|
||||||
|
TlsTransportParams_t xTlsTransportParams = { 0 };
|
||||||
NetworkCredentials_t xNetworkCredentials = { 0 };
|
NetworkCredentials_t xNetworkCredentials = { 0 };
|
||||||
MQTTContext_t xMQTTContext = { 0 };
|
MQTTContext_t xMQTTContext = { 0 };
|
||||||
MQTTStatus_t xMQTTStatus;
|
MQTTStatus_t xMQTTStatus;
|
||||||
@ -394,6 +403,9 @@ static void prvMQTTDemoTask( void * pvParameters )
|
|||||||
/* Remove compiler warnings about unused parameters. */
|
/* Remove compiler warnings about unused parameters. */
|
||||||
( void ) pvParameters;
|
( void ) pvParameters;
|
||||||
|
|
||||||
|
/* Set the pParams member of the network context with desired transport. */
|
||||||
|
xNetworkContext.pParams = &xTlsTransportParams;
|
||||||
|
|
||||||
/* Set the entry time of the demo application. This entry time will be used
|
/* Set the entry time of the demo application. This entry time will be used
|
||||||
* to calculate relative time elapsed in the execution of the demo application,
|
* to calculate relative time elapsed in the execution of the demo application,
|
||||||
* by the timer utility function that is provided to the MQTT library.
|
* by the timer utility function that is provided to the MQTT library.
|
||||||
|
@ -207,6 +207,14 @@
|
|||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* Each compilation unit must define the NetworkContext struct. */
|
||||||
|
struct NetworkContext
|
||||||
|
{
|
||||||
|
PlaintextTransportParams_t * pParams;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The task used to demonstrate the MQTT API.
|
* @brief The task used to demonstrate the MQTT API.
|
||||||
*
|
*
|
||||||
@ -471,6 +479,7 @@ static void prvMQTTDemoTask( void * pvParameters )
|
|||||||
{
|
{
|
||||||
uint32_t ulTopicCount = 0U;
|
uint32_t ulTopicCount = 0U;
|
||||||
NetworkContext_t xNetworkContext = { 0 };
|
NetworkContext_t xNetworkContext = { 0 };
|
||||||
|
PlaintextTransportParams_t xPlaintextTransportParams = { 0 };
|
||||||
MQTTContext_t xMQTTContext;
|
MQTTContext_t xMQTTContext;
|
||||||
MQTTStatus_t xMQTTStatus;
|
MQTTStatus_t xMQTTStatus;
|
||||||
PlaintextTransportStatus_t xNetworkStatus;
|
PlaintextTransportStatus_t xNetworkStatus;
|
||||||
@ -479,6 +488,9 @@ static void prvMQTTDemoTask( void * pvParameters )
|
|||||||
/* Remove compiler warnings about unused parameters. */
|
/* Remove compiler warnings about unused parameters. */
|
||||||
( void ) pvParameters;
|
( void ) pvParameters;
|
||||||
|
|
||||||
|
/* Set the pParams member of the network context with desired transport. */
|
||||||
|
xNetworkContext.pParams = &xPlaintextTransportParams;
|
||||||
|
|
||||||
/* Serialize a PINGREQ packet to send upon invoking the keep-alive timer
|
/* Serialize a PINGREQ packet to send upon invoking the keep-alive timer
|
||||||
* callback. */
|
* callback. */
|
||||||
xMQTTStatus = MQTT_SerializePingreq( &xPingReqBuffer );
|
xMQTTStatus = MQTT_SerializePingreq( &xPingReqBuffer );
|
||||||
|
@ -375,6 +375,18 @@ typedef struct publishElement
|
|||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* Each compilation unit must define the NetworkContext struct. */
|
||||||
|
struct NetworkContext
|
||||||
|
{
|
||||||
|
#if defined( democonfigUSE_TLS ) && ( democonfigUSE_TLS == 1 )
|
||||||
|
TlsTransportParams_t * pParams;
|
||||||
|
#else
|
||||||
|
PlaintextTransportParams_t * pParams;
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initializes an MQTT context, including transport interface and
|
* @brief Initializes an MQTT context, including transport interface and
|
||||||
* network buffer.
|
* network buffer.
|
||||||
@ -686,6 +698,20 @@ static MQTTContext_t globalMqttContext;
|
|||||||
*/
|
*/
|
||||||
static NetworkContext_t xNetworkContext;
|
static NetworkContext_t xNetworkContext;
|
||||||
|
|
||||||
|
#if defined( democonfigUSE_TLS ) && ( democonfigUSE_TLS == 1 )
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The parameters for the network context using a TLS channel.
|
||||||
|
*/
|
||||||
|
static TlsTransportParams_t xTlsTransportParams;
|
||||||
|
#else
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The parameters for the network context using a non-encrypted channel.
|
||||||
|
*/
|
||||||
|
static PlaintextTransportParams_t xPlaintextTransportParams;
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief List of operations that are awaiting an ack from the broker.
|
* @brief List of operations that are awaiting an ack from the broker.
|
||||||
*/
|
*/
|
||||||
@ -981,6 +1007,8 @@ static BaseType_t prvSocketConnect( NetworkContext_t * pxNetworkContext )
|
|||||||
BackoffAlgorithmContext_t xReconnectParams;
|
BackoffAlgorithmContext_t xReconnectParams;
|
||||||
uint16_t usNextRetryBackOff = 0U;
|
uint16_t usNextRetryBackOff = 0U;
|
||||||
|
|
||||||
|
configASSERT( pxNetworkContext != NULL && pxNetworkContext->pParams != NULL );
|
||||||
|
|
||||||
#if defined( democonfigUSE_TLS ) && ( democonfigUSE_TLS == 1 )
|
#if defined( democonfigUSE_TLS ) && ( democonfigUSE_TLS == 1 )
|
||||||
TlsTransportStatus_t xNetworkStatus = TLS_TRANSPORT_CONNECT_FAILURE;
|
TlsTransportStatus_t xNetworkStatus = TLS_TRANSPORT_CONNECT_FAILURE;
|
||||||
NetworkCredentials_t xNetworkCredentials = { 0 };
|
NetworkCredentials_t xNetworkCredentials = { 0 };
|
||||||
@ -1079,7 +1107,7 @@ static BaseType_t prvSocketConnect( NetworkContext_t * pxNetworkContext )
|
|||||||
/* Set the socket wakeup callback. */
|
/* Set the socket wakeup callback. */
|
||||||
if( xConnected )
|
if( xConnected )
|
||||||
{
|
{
|
||||||
( void ) FreeRTOS_setsockopt( pxNetworkContext->tcpSocket,
|
( void ) FreeRTOS_setsockopt( pxNetworkContext->pParams->tcpSocket,
|
||||||
0, /* Level - Unused. */
|
0, /* Level - Unused. */
|
||||||
FREERTOS_SO_WAKEUP_CALLBACK,
|
FREERTOS_SO_WAKEUP_CALLBACK,
|
||||||
( void * ) prvMQTTClientSocketWakeupCallback,
|
( void * ) prvMQTTClientSocketWakeupCallback,
|
||||||
@ -1095,8 +1123,10 @@ static BaseType_t prvSocketDisconnect( NetworkContext_t * pxNetworkContext )
|
|||||||
{
|
{
|
||||||
BaseType_t xDisconnected = pdFAIL;
|
BaseType_t xDisconnected = pdFAIL;
|
||||||
|
|
||||||
|
configASSERT( pxNetworkContext != NULL && pxNetworkContext->pParams != NULL );
|
||||||
|
|
||||||
/* Set the wakeup callback to NULL since the socket will disconnect. */
|
/* Set the wakeup callback to NULL since the socket will disconnect. */
|
||||||
( void ) FreeRTOS_setsockopt( pxNetworkContext->tcpSocket,
|
( void ) FreeRTOS_setsockopt( pxNetworkContext->pParams->tcpSocket,
|
||||||
0, /* Level - Unused. */
|
0, /* Level - Unused. */
|
||||||
FREERTOS_SO_WAKEUP_CALLBACK,
|
FREERTOS_SO_WAKEUP_CALLBACK,
|
||||||
( void * ) NULL,
|
( void * ) NULL,
|
||||||
@ -2074,6 +2104,13 @@ static void prvMQTTDemoTask( void * pvParameters )
|
|||||||
|
|
||||||
( void ) pvParameters;
|
( void ) pvParameters;
|
||||||
|
|
||||||
|
/* Set the pParams member of the network context with desired transport. */
|
||||||
|
#if defined( democonfigUSE_TLS ) && ( democonfigUSE_TLS == 1 )
|
||||||
|
xNetworkContext.pParams = &xTlsTransportParams;
|
||||||
|
#else
|
||||||
|
xNetworkContext.pParams = &xPlaintextTransportParams;
|
||||||
|
#endif
|
||||||
|
|
||||||
ulGlobalEntryTimeMs = prvGetTimeMs();
|
ulGlobalEntryTimeMs = prvGetTimeMs();
|
||||||
|
|
||||||
/* Create command queue for processing MQTT commands. */
|
/* Create command queue for processing MQTT commands. */
|
||||||
|
@ -274,6 +274,14 @@
|
|||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* Each compilation unit must define the NetworkContext struct. */
|
||||||
|
struct NetworkContext
|
||||||
|
{
|
||||||
|
TlsTransportParams_t * pParams;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The task used to demonstrate the MQTT API.
|
* @brief The task used to demonstrate the MQTT API.
|
||||||
*
|
*
|
||||||
@ -475,6 +483,7 @@ static void prvMQTTDemoTask( void * pvParameters )
|
|||||||
uint32_t ulPublishCount = 0U, ulTopicCount = 0U;
|
uint32_t ulPublishCount = 0U, ulTopicCount = 0U;
|
||||||
const uint32_t ulMaxPublishCount = 5UL;
|
const uint32_t ulMaxPublishCount = 5UL;
|
||||||
NetworkContext_t xNetworkContext = { 0 };
|
NetworkContext_t xNetworkContext = { 0 };
|
||||||
|
TlsTransportParams_t xTlsTransportParams = { 0 };
|
||||||
NetworkCredentials_t xNetworkCredentials = { 0 };
|
NetworkCredentials_t xNetworkCredentials = { 0 };
|
||||||
MQTTContext_t xMQTTContext = { 0 };
|
MQTTContext_t xMQTTContext = { 0 };
|
||||||
MQTTStatus_t xMQTTStatus;
|
MQTTStatus_t xMQTTStatus;
|
||||||
@ -489,6 +498,9 @@ static void prvMQTTDemoTask( void * pvParameters )
|
|||||||
*/
|
*/
|
||||||
ulGlobalEntryTimeMs = prvGetTimeMs();
|
ulGlobalEntryTimeMs = prvGetTimeMs();
|
||||||
|
|
||||||
|
/* Set the pParams member of the network context with desired transport. */
|
||||||
|
xNetworkContext.pParams = &xTlsTransportParams;
|
||||||
|
|
||||||
for( ; ; )
|
for( ; ; )
|
||||||
{
|
{
|
||||||
/****************************** Connect. ******************************/
|
/****************************** Connect. ******************************/
|
||||||
|
@ -176,6 +176,14 @@
|
|||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* Each compilation unit must define the NetworkContext struct. */
|
||||||
|
struct NetworkContext
|
||||||
|
{
|
||||||
|
PlaintextTransportParams_t * pParams;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The task used to demonstrate the MQTT API.
|
* @brief The task used to demonstrate the MQTT API.
|
||||||
*
|
*
|
||||||
@ -359,6 +367,7 @@ static void prvMQTTDemoTask( void * pvParameters )
|
|||||||
uint32_t ulPublishCount = 0U, ulTopicCount = 0U;
|
uint32_t ulPublishCount = 0U, ulTopicCount = 0U;
|
||||||
const uint32_t ulMaxPublishCount = 5UL;
|
const uint32_t ulMaxPublishCount = 5UL;
|
||||||
NetworkContext_t xNetworkContext = { 0 };
|
NetworkContext_t xNetworkContext = { 0 };
|
||||||
|
PlaintextTransportParams_t xPlaintextTransportParams = { 0 };
|
||||||
MQTTContext_t xMQTTContext;
|
MQTTContext_t xMQTTContext;
|
||||||
MQTTStatus_t xMQTTStatus;
|
MQTTStatus_t xMQTTStatus;
|
||||||
PlaintextTransportStatus_t xNetworkStatus;
|
PlaintextTransportStatus_t xNetworkStatus;
|
||||||
@ -366,6 +375,9 @@ static void prvMQTTDemoTask( void * pvParameters )
|
|||||||
/* Remove compiler warnings about unused parameters. */
|
/* Remove compiler warnings about unused parameters. */
|
||||||
( void ) pvParameters;
|
( void ) pvParameters;
|
||||||
|
|
||||||
|
/* Set the pParams member of the network context with desired transport. */
|
||||||
|
xNetworkContext.pParams = &xPlaintextTransportParams;
|
||||||
|
|
||||||
ulGlobalEntryTimeMs = prvGetTimeMs();
|
ulGlobalEntryTimeMs = prvGetTimeMs();
|
||||||
|
|
||||||
for( ; ; )
|
for( ; ; )
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* FreeRTOS Kernel V10.3.0
|
* FreeRTOS V202011.00
|
||||||
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
@ -19,8 +19,9 @@
|
|||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*
|
*
|
||||||
* http://www.FreeRTOS.org
|
* https://www.FreeRTOS.org
|
||||||
* http://aws.amazon.com/freertos
|
* https://github.com/FreeRTOS
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -159,6 +160,14 @@
|
|||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* Each compilation unit must define the NetworkContext struct. */
|
||||||
|
struct NetworkContext
|
||||||
|
{
|
||||||
|
TlsTransportParams_t * pParams;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The task used to demonstrate the MQTT API.
|
* @brief The task used to demonstrate the MQTT API.
|
||||||
*
|
*
|
||||||
@ -324,6 +333,7 @@ static void prvMQTTDemoTask( void * pvParameters )
|
|||||||
uint32_t ulPublishCount = 0U;
|
uint32_t ulPublishCount = 0U;
|
||||||
const uint32_t ulMaxPublishCount = 5UL;
|
const uint32_t ulMaxPublishCount = 5UL;
|
||||||
NetworkContext_t xNetworkContext = { 0 };
|
NetworkContext_t xNetworkContext = { 0 };
|
||||||
|
TlsTransportParams_t xTlsTransportParams = { 0 };
|
||||||
NetworkCredentials_t xNetworkCredentials = { 0 };
|
NetworkCredentials_t xNetworkCredentials = { 0 };
|
||||||
MQTTContext_t xMQTTContext = { 0 };
|
MQTTContext_t xMQTTContext = { 0 };
|
||||||
MQTTStatus_t xMQTTStatus;
|
MQTTStatus_t xMQTTStatus;
|
||||||
@ -331,6 +341,9 @@ static void prvMQTTDemoTask( void * pvParameters )
|
|||||||
/* Remove compiler warnings about unused parameters. */
|
/* Remove compiler warnings about unused parameters. */
|
||||||
( void ) pvParameters;
|
( void ) pvParameters;
|
||||||
|
|
||||||
|
/* Set the pParams member of the network context with desired transport. */
|
||||||
|
xNetworkContext.pParams = &xTlsTransportParams;
|
||||||
|
|
||||||
/* Set the entry time of the demo application. This entry time will be used
|
/* Set the entry time of the demo application. This entry time will be used
|
||||||
* to calculate relative time elapsed in the execution of the demo application,
|
* to calculate relative time elapsed in the execution of the demo application,
|
||||||
* by the timer utility function that is provided to the MQTT library.
|
* by the timer utility function that is provided to the MQTT library.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* FreeRTOS Kernel V10.3.0
|
* FreeRTOS V202011.00
|
||||||
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
@ -19,10 +19,9 @@
|
|||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*
|
*
|
||||||
* http://www.FreeRTOS.org
|
* https://www.FreeRTOS.org
|
||||||
* http://aws.amazon.com/freertos
|
* https://github.com/FreeRTOS
|
||||||
*
|
*
|
||||||
* 1 tab == 4 spaces!
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/***
|
/***
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
|
* FreeRTOS V202011.00
|
||||||
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
@ -17,6 +18,10 @@
|
|||||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* https://www.FreeRTOS.org
|
||||||
|
* https://github.com/FreeRTOS
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
|
* FreeRTOS V202011.00
|
||||||
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
@ -17,6 +18,10 @@
|
|||||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* https://www.FreeRTOS.org
|
||||||
|
* https://github.com/FreeRTOS
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
|
* FreeRTOS V202011.00
|
||||||
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
@ -17,6 +18,10 @@
|
|||||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* https://www.FreeRTOS.org
|
||||||
|
* https://github.com/FreeRTOS
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -46,6 +51,14 @@
|
|||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* Each compilation unit must define the NetworkContext struct. */
|
||||||
|
struct NetworkContext
|
||||||
|
{
|
||||||
|
TlsTransportParams_t * pParams;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Represents string to be logged when mbedTLS returned error
|
* @brief Represents string to be logged when mbedTLS returned error
|
||||||
* does not contain a high-level code.
|
* does not contain a high-level code.
|
||||||
@ -282,17 +295,17 @@ static int32_t setClientCertificate( SSLContext_t * pSslContext,
|
|||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
static int32_t setPrivateKey( SSLContext_t * pSslContext,
|
static int32_t setPrivateKey( SSLContext_t * pSslContext,
|
||||||
const uint8_t * pPrivateKeyPath,
|
const uint8_t * pPrivateKey,
|
||||||
size_t privateKeySize )
|
size_t privateKeySize )
|
||||||
{
|
{
|
||||||
int32_t mbedtlsError = -1;
|
int32_t mbedtlsError = -1;
|
||||||
|
|
||||||
configASSERT( pSslContext != NULL );
|
configASSERT( pSslContext != NULL );
|
||||||
configASSERT( pPrivateKeyPath != NULL );
|
configASSERT( pPrivateKey != NULL );
|
||||||
|
|
||||||
/* Setup the client private key. */
|
/* Setup the client private key. */
|
||||||
mbedtlsError = mbedtls_pk_parse_key( &( pSslContext->privKey ),
|
mbedtlsError = mbedtls_pk_parse_key( &( pSslContext->privKey ),
|
||||||
pPrivateKeyPath,
|
pPrivateKey,
|
||||||
privateKeySize,
|
privateKeySize,
|
||||||
NULL,
|
NULL,
|
||||||
0 );
|
0 );
|
||||||
@ -424,18 +437,21 @@ static TlsTransportStatus_t tlsSetup( NetworkContext_t * pNetworkContext,
|
|||||||
const char * pHostName,
|
const char * pHostName,
|
||||||
const NetworkCredentials_t * pNetworkCredentials )
|
const NetworkCredentials_t * pNetworkCredentials )
|
||||||
{
|
{
|
||||||
|
TlsTransportParams_t * pTlsTransportParams = NULL;
|
||||||
TlsTransportStatus_t returnStatus = TLS_TRANSPORT_SUCCESS;
|
TlsTransportStatus_t returnStatus = TLS_TRANSPORT_SUCCESS;
|
||||||
int32_t mbedtlsError = 0;
|
int32_t mbedtlsError = 0;
|
||||||
|
|
||||||
configASSERT( pNetworkContext != NULL );
|
configASSERT( pNetworkContext != NULL );
|
||||||
|
configASSERT( pNetworkContext->pParams != NULL );
|
||||||
configASSERT( pHostName != NULL );
|
configASSERT( pHostName != NULL );
|
||||||
configASSERT( pNetworkCredentials != NULL );
|
configASSERT( pNetworkCredentials != NULL );
|
||||||
configASSERT( pNetworkCredentials->pRootCa != NULL );
|
configASSERT( pNetworkCredentials->pRootCa != NULL );
|
||||||
|
|
||||||
|
pTlsTransportParams = pNetworkContext->pParams;
|
||||||
/* Initialize the mbed TLS context structures. */
|
/* Initialize the mbed TLS context structures. */
|
||||||
sslContextInit( &( pNetworkContext->sslContext ) );
|
sslContextInit( &( pTlsTransportParams->sslContext ) );
|
||||||
|
|
||||||
mbedtlsError = mbedtls_ssl_config_defaults( &( pNetworkContext->sslContext.config ),
|
mbedtlsError = mbedtls_ssl_config_defaults( &( pTlsTransportParams->sslContext.config ),
|
||||||
MBEDTLS_SSL_IS_CLIENT,
|
MBEDTLS_SSL_IS_CLIENT,
|
||||||
MBEDTLS_SSL_TRANSPORT_STREAM,
|
MBEDTLS_SSL_TRANSPORT_STREAM,
|
||||||
MBEDTLS_SSL_PRESET_DEFAULT );
|
MBEDTLS_SSL_PRESET_DEFAULT );
|
||||||
@ -452,7 +468,7 @@ static TlsTransportStatus_t tlsSetup( NetworkContext_t * pNetworkContext,
|
|||||||
|
|
||||||
if( returnStatus == TLS_TRANSPORT_SUCCESS )
|
if( returnStatus == TLS_TRANSPORT_SUCCESS )
|
||||||
{
|
{
|
||||||
mbedtlsError = setCredentials( &( pNetworkContext->sslContext ),
|
mbedtlsError = setCredentials( &( pTlsTransportParams->sslContext ),
|
||||||
pNetworkCredentials );
|
pNetworkCredentials );
|
||||||
|
|
||||||
if( mbedtlsError != 0 )
|
if( mbedtlsError != 0 )
|
||||||
@ -462,7 +478,7 @@ static TlsTransportStatus_t tlsSetup( NetworkContext_t * pNetworkContext,
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Optionally set SNI and ALPN protocols. */
|
/* Optionally set SNI and ALPN protocols. */
|
||||||
setOptionalConfigurations( &( pNetworkContext->sslContext ),
|
setOptionalConfigurations( &( pTlsTransportParams->sslContext ),
|
||||||
pHostName,
|
pHostName,
|
||||||
pNetworkCredentials );
|
pNetworkCredentials );
|
||||||
}
|
}
|
||||||
@ -475,15 +491,18 @@ static TlsTransportStatus_t tlsSetup( NetworkContext_t * pNetworkContext,
|
|||||||
static TlsTransportStatus_t tlsHandshake( NetworkContext_t * pNetworkContext,
|
static TlsTransportStatus_t tlsHandshake( NetworkContext_t * pNetworkContext,
|
||||||
const NetworkCredentials_t * pNetworkCredentials )
|
const NetworkCredentials_t * pNetworkCredentials )
|
||||||
{
|
{
|
||||||
|
TlsTransportParams_t * pTlsTransportParams = NULL;
|
||||||
TlsTransportStatus_t returnStatus = TLS_TRANSPORT_SUCCESS;
|
TlsTransportStatus_t returnStatus = TLS_TRANSPORT_SUCCESS;
|
||||||
int32_t mbedtlsError = 0;
|
int32_t mbedtlsError = 0;
|
||||||
|
|
||||||
configASSERT( pNetworkContext != NULL );
|
configASSERT( pNetworkContext != NULL );
|
||||||
|
configASSERT( pNetworkContext->pParams != NULL );
|
||||||
configASSERT( pNetworkCredentials != NULL );
|
configASSERT( pNetworkCredentials != NULL );
|
||||||
|
|
||||||
|
pTlsTransportParams = pNetworkContext->pParams;
|
||||||
/* Initialize the mbed TLS secured connection context. */
|
/* Initialize the mbed TLS secured connection context. */
|
||||||
mbedtlsError = mbedtls_ssl_setup( &( pNetworkContext->sslContext.context ),
|
mbedtlsError = mbedtls_ssl_setup( &( pTlsTransportParams->sslContext.context ),
|
||||||
&( pNetworkContext->sslContext.config ) );
|
&( pTlsTransportParams->sslContext.config ) );
|
||||||
|
|
||||||
if( mbedtlsError != 0 )
|
if( mbedtlsError != 0 )
|
||||||
{
|
{
|
||||||
@ -502,8 +521,8 @@ static TlsTransportStatus_t tlsHandshake( NetworkContext_t * pNetworkContext,
|
|||||||
* #mbedtls_ssl_set_bio requires the second parameter as void *.
|
* #mbedtls_ssl_set_bio requires the second parameter as void *.
|
||||||
*/
|
*/
|
||||||
/* coverity[misra_c_2012_rule_11_2_violation] */
|
/* coverity[misra_c_2012_rule_11_2_violation] */
|
||||||
mbedtls_ssl_set_bio( &( pNetworkContext->sslContext.context ),
|
mbedtls_ssl_set_bio( &( pTlsTransportParams->sslContext.context ),
|
||||||
( void * ) pNetworkContext->tcpSocket,
|
( void * ) pTlsTransportParams->tcpSocket,
|
||||||
mbedtls_platform_send,
|
mbedtls_platform_send,
|
||||||
mbedtls_platform_recv,
|
mbedtls_platform_recv,
|
||||||
NULL );
|
NULL );
|
||||||
@ -514,7 +533,7 @@ static TlsTransportStatus_t tlsHandshake( NetworkContext_t * pNetworkContext,
|
|||||||
/* Perform the TLS handshake. */
|
/* Perform the TLS handshake. */
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
mbedtlsError = mbedtls_ssl_handshake( &( pNetworkContext->sslContext.context ) );
|
mbedtlsError = mbedtls_ssl_handshake( &( pTlsTransportParams->sslContext.context ) );
|
||||||
} while( ( mbedtlsError == MBEDTLS_ERR_SSL_WANT_READ ) ||
|
} while( ( mbedtlsError == MBEDTLS_ERR_SSL_WANT_READ ) ||
|
||||||
( mbedtlsError == MBEDTLS_ERR_SSL_WANT_WRITE ) );
|
( mbedtlsError == MBEDTLS_ERR_SSL_WANT_WRITE ) );
|
||||||
|
|
||||||
@ -602,10 +621,12 @@ TlsTransportStatus_t TLS_FreeRTOS_Connect( NetworkContext_t * pNetworkContext,
|
|||||||
uint32_t receiveTimeoutMs,
|
uint32_t receiveTimeoutMs,
|
||||||
uint32_t sendTimeoutMs )
|
uint32_t sendTimeoutMs )
|
||||||
{
|
{
|
||||||
|
TlsTransportParams_t * pTlsTransportParams = NULL;
|
||||||
TlsTransportStatus_t returnStatus = TLS_TRANSPORT_SUCCESS;
|
TlsTransportStatus_t returnStatus = TLS_TRANSPORT_SUCCESS;
|
||||||
BaseType_t socketStatus = 0;
|
BaseType_t socketStatus = 0;
|
||||||
|
|
||||||
if( ( pNetworkContext == NULL ) ||
|
if( ( pNetworkContext == NULL ) ||
|
||||||
|
( pNetworkContext->pParams == NULL ) ||
|
||||||
( pHostName == NULL ) ||
|
( pHostName == NULL ) ||
|
||||||
( pNetworkCredentials == NULL ) )
|
( pNetworkCredentials == NULL ) )
|
||||||
{
|
{
|
||||||
@ -629,7 +650,8 @@ TlsTransportStatus_t TLS_FreeRTOS_Connect( NetworkContext_t * pNetworkContext,
|
|||||||
/* Establish a TCP connection with the server. */
|
/* Establish a TCP connection with the server. */
|
||||||
if( returnStatus == TLS_TRANSPORT_SUCCESS )
|
if( returnStatus == TLS_TRANSPORT_SUCCESS )
|
||||||
{
|
{
|
||||||
socketStatus = Sockets_Connect( &( pNetworkContext->tcpSocket ),
|
pTlsTransportParams = pNetworkContext->pParams;
|
||||||
|
socketStatus = Sockets_Connect( &( pTlsTransportParams->tcpSocket ),
|
||||||
pHostName,
|
pHostName,
|
||||||
port,
|
port,
|
||||||
receiveTimeoutMs,
|
receiveTimeoutMs,
|
||||||
@ -647,8 +669,8 @@ TlsTransportStatus_t TLS_FreeRTOS_Connect( NetworkContext_t * pNetworkContext,
|
|||||||
/* Initialize mbedtls. */
|
/* Initialize mbedtls. */
|
||||||
if( returnStatus == TLS_TRANSPORT_SUCCESS )
|
if( returnStatus == TLS_TRANSPORT_SUCCESS )
|
||||||
{
|
{
|
||||||
returnStatus = initMbedtls( &( pNetworkContext->sslContext.entropyContext ),
|
returnStatus = initMbedtls( &( pTlsTransportParams->sslContext.entropyContext ),
|
||||||
&( pNetworkContext->sslContext.ctrDrgbContext ) );
|
&( pTlsTransportParams->sslContext.ctrDrgbContext ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize TLS contexts and set credentials. */
|
/* Initialize TLS contexts and set credentials. */
|
||||||
@ -666,13 +688,13 @@ TlsTransportStatus_t TLS_FreeRTOS_Connect( NetworkContext_t * pNetworkContext,
|
|||||||
/* Clean up on failure. */
|
/* Clean up on failure. */
|
||||||
if( returnStatus != TLS_TRANSPORT_SUCCESS )
|
if( returnStatus != TLS_TRANSPORT_SUCCESS )
|
||||||
{
|
{
|
||||||
if( pNetworkContext != NULL )
|
if( ( pNetworkContext != NULL ) && ( pNetworkContext->pParams != NULL ) )
|
||||||
{
|
{
|
||||||
sslContextFree( &( pNetworkContext->sslContext ) );
|
sslContextFree( &( pTlsTransportParams->sslContext ) );
|
||||||
|
|
||||||
if( pNetworkContext->tcpSocket != FREERTOS_INVALID_SOCKET )
|
if( pTlsTransportParams->tcpSocket != FREERTOS_INVALID_SOCKET )
|
||||||
{
|
{
|
||||||
( void ) FreeRTOS_closesocket( pNetworkContext->tcpSocket );
|
( void ) FreeRTOS_closesocket( pTlsTransportParams->tcpSocket );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -689,12 +711,14 @@ TlsTransportStatus_t TLS_FreeRTOS_Connect( NetworkContext_t * pNetworkContext,
|
|||||||
|
|
||||||
void TLS_FreeRTOS_Disconnect( NetworkContext_t * pNetworkContext )
|
void TLS_FreeRTOS_Disconnect( NetworkContext_t * pNetworkContext )
|
||||||
{
|
{
|
||||||
|
TlsTransportParams_t * pTlsTransportParams = NULL;
|
||||||
BaseType_t tlsStatus = 0;
|
BaseType_t tlsStatus = 0;
|
||||||
|
|
||||||
if( pNetworkContext != NULL )
|
if( ( pNetworkContext != NULL ) && ( pNetworkContext->pParams != NULL ) )
|
||||||
{
|
{
|
||||||
|
pTlsTransportParams = pNetworkContext->pParams;
|
||||||
/* Attempting to terminate TLS connection. */
|
/* Attempting to terminate TLS connection. */
|
||||||
tlsStatus = ( BaseType_t ) mbedtls_ssl_close_notify( &( pNetworkContext->sslContext.context ) );
|
tlsStatus = ( BaseType_t ) mbedtls_ssl_close_notify( &( pTlsTransportParams->sslContext.context ) );
|
||||||
|
|
||||||
/* Ignore the WANT_READ and WANT_WRITE return values. */
|
/* Ignore the WANT_READ and WANT_WRITE return values. */
|
||||||
if( ( tlsStatus != ( BaseType_t ) MBEDTLS_ERR_SSL_WANT_READ ) &&
|
if( ( tlsStatus != ( BaseType_t ) MBEDTLS_ERR_SSL_WANT_READ ) &&
|
||||||
@ -723,10 +747,10 @@ void TLS_FreeRTOS_Disconnect( NetworkContext_t * pNetworkContext )
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Call socket shutdown function to close connection. */
|
/* Call socket shutdown function to close connection. */
|
||||||
Sockets_Disconnect( pNetworkContext->tcpSocket );
|
Sockets_Disconnect( pTlsTransportParams->tcpSocket );
|
||||||
|
|
||||||
/* Free mbed TLS contexts. */
|
/* Free mbed TLS contexts. */
|
||||||
sslContextFree( &( pNetworkContext->sslContext ) );
|
sslContextFree( &( pTlsTransportParams->sslContext ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Clear the mutex functions for mbed TLS thread safety. */
|
/* Clear the mutex functions for mbed TLS thread safety. */
|
||||||
@ -738,9 +762,13 @@ int32_t TLS_FreeRTOS_recv( NetworkContext_t * pNetworkContext,
|
|||||||
void * pBuffer,
|
void * pBuffer,
|
||||||
size_t bytesToRecv )
|
size_t bytesToRecv )
|
||||||
{
|
{
|
||||||
|
TlsTransportParams_t * pTlsTransportParams = NULL;
|
||||||
int32_t tlsStatus = 0;
|
int32_t tlsStatus = 0;
|
||||||
|
|
||||||
tlsStatus = ( int32_t ) mbedtls_ssl_read( &( pNetworkContext->sslContext.context ),
|
configASSERT( ( pNetworkContext != NULL ) && ( pNetworkContext->pParams != NULL ) );
|
||||||
|
|
||||||
|
pTlsTransportParams = pNetworkContext->pParams;
|
||||||
|
tlsStatus = ( int32_t ) mbedtls_ssl_read( &( pTlsTransportParams->sslContext.context ),
|
||||||
pBuffer,
|
pBuffer,
|
||||||
bytesToRecv );
|
bytesToRecv );
|
||||||
|
|
||||||
@ -776,9 +804,13 @@ int32_t TLS_FreeRTOS_send( NetworkContext_t * pNetworkContext,
|
|||||||
const void * pBuffer,
|
const void * pBuffer,
|
||||||
size_t bytesToSend )
|
size_t bytesToSend )
|
||||||
{
|
{
|
||||||
|
TlsTransportParams_t * pTlsTransportParams = NULL;
|
||||||
int32_t tlsStatus = 0;
|
int32_t tlsStatus = 0;
|
||||||
|
|
||||||
tlsStatus = ( int32_t ) mbedtls_ssl_write( &( pNetworkContext->sslContext.context ),
|
configASSERT( ( pNetworkContext != NULL ) && ( pNetworkContext->pParams != NULL ) );
|
||||||
|
|
||||||
|
pTlsTransportParams = pNetworkContext->pParams;
|
||||||
|
tlsStatus = ( int32_t ) mbedtls_ssl_write( &( pTlsTransportParams->sslContext.context ),
|
||||||
pBuffer,
|
pBuffer,
|
||||||
bytesToSend );
|
bytesToSend );
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
|
* FreeRTOS V202011.00
|
||||||
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
@ -17,6 +18,10 @@
|
|||||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* https://www.FreeRTOS.org
|
||||||
|
* https://github.com/FreeRTOS
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -94,14 +99,14 @@ typedef struct SSLContext
|
|||||||
} SSLContext_t;
|
} SSLContext_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Definition of the network context for the transport interface
|
* @brief Parameters for the network context of the transport interface
|
||||||
* implementation that uses mbedTLS and FreeRTOS+TLS sockets.
|
* implementation that uses mbedTLS and FreeRTOS+TCP sockets.
|
||||||
*/
|
*/
|
||||||
struct NetworkContext
|
typedef struct TlsTransportParams
|
||||||
{
|
{
|
||||||
Socket_t tcpSocket;
|
Socket_t tcpSocket;
|
||||||
SSLContext_t sslContext;
|
SSLContext_t sslContext;
|
||||||
};
|
} TlsTransportParams_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Contains the credentials necessary for tls connection setup.
|
* @brief Contains the credentials necessary for tls connection setup.
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
|
* FreeRTOS V202011.00
|
||||||
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
@ -17,6 +18,10 @@
|
|||||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* https://www.FreeRTOS.org
|
||||||
|
* https://github.com/FreeRTOS
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -55,6 +60,14 @@
|
|||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* Each compilation unit must define the NetworkContext struct. */
|
||||||
|
struct NetworkContext
|
||||||
|
{
|
||||||
|
TlsTransportParams_t * pParams;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Represents string to be logged when mbedTLS returned error
|
* @brief Represents string to be logged when mbedTLS returned error
|
||||||
* does not contain a high-level code.
|
* does not contain a high-level code.
|
||||||
@ -221,19 +234,23 @@ static TlsTransportStatus_t tlsSetup( NetworkContext_t * pNetworkContext,
|
|||||||
const char * pHostName,
|
const char * pHostName,
|
||||||
const NetworkCredentials_t * pNetworkCredentials )
|
const NetworkCredentials_t * pNetworkCredentials )
|
||||||
{
|
{
|
||||||
|
TlsTransportParams_t * pTlsTransportParams = NULL;
|
||||||
TlsTransportStatus_t returnStatus = TLS_TRANSPORT_SUCCESS;
|
TlsTransportStatus_t returnStatus = TLS_TRANSPORT_SUCCESS;
|
||||||
int32_t mbedtlsError = 0;
|
int32_t mbedtlsError = 0;
|
||||||
CK_RV xResult = CKR_OK;
|
CK_RV xResult = CKR_OK;
|
||||||
|
|
||||||
configASSERT( pNetworkContext != NULL );
|
configASSERT( pNetworkContext != NULL );
|
||||||
|
configASSERT( pNetworkContext->pParams != NULL );
|
||||||
configASSERT( pHostName != NULL );
|
configASSERT( pHostName != NULL );
|
||||||
configASSERT( pNetworkCredentials != NULL );
|
configASSERT( pNetworkCredentials != NULL );
|
||||||
configASSERT( pNetworkCredentials->pRootCa != NULL );
|
configASSERT( pNetworkCredentials->pRootCa != NULL );
|
||||||
|
|
||||||
/* Initialize the mbed TLS context structures. */
|
pTlsTransportParams = pNetworkContext->pParams;
|
||||||
sslContextInit( &( pNetworkContext->sslContext ) );
|
|
||||||
|
|
||||||
mbedtlsError = mbedtls_ssl_config_defaults( &( pNetworkContext->sslContext.config ),
|
/* Initialize the mbed TLS context structures. */
|
||||||
|
sslContextInit( &( pTlsTransportParams->sslContext ) );
|
||||||
|
|
||||||
|
mbedtlsError = mbedtls_ssl_config_defaults( &( pTlsTransportParams->sslContext.config ),
|
||||||
MBEDTLS_SSL_IS_CLIENT,
|
MBEDTLS_SSL_IS_CLIENT,
|
||||||
MBEDTLS_SSL_TRANSPORT_STREAM,
|
MBEDTLS_SSL_TRANSPORT_STREAM,
|
||||||
MBEDTLS_SSL_PRESET_DEFAULT );
|
MBEDTLS_SSL_PRESET_DEFAULT );
|
||||||
@ -251,7 +268,7 @@ static TlsTransportStatus_t tlsSetup( NetworkContext_t * pNetworkContext,
|
|||||||
if( returnStatus == TLS_TRANSPORT_SUCCESS )
|
if( returnStatus == TLS_TRANSPORT_SUCCESS )
|
||||||
{
|
{
|
||||||
/* Set up the certificate security profile, starting from the default value. */
|
/* Set up the certificate security profile, starting from the default value. */
|
||||||
pNetworkContext->sslContext.certProfile = mbedtls_x509_crt_profile_default;
|
pTlsTransportParams->sslContext.certProfile = mbedtls_x509_crt_profile_default;
|
||||||
|
|
||||||
/* test.mosquitto.org only provides a 1024-bit RSA certificate, which is
|
/* test.mosquitto.org only provides a 1024-bit RSA certificate, which is
|
||||||
* not acceptable by the default mbed TLS certificate security profile.
|
* not acceptable by the default mbed TLS certificate security profile.
|
||||||
@ -259,20 +276,20 @@ static TlsTransportStatus_t tlsSetup( NetworkContext_t * pNetworkContext,
|
|||||||
* This block should be removed otherwise. */
|
* This block should be removed otherwise. */
|
||||||
if( strncmp( pHostName, "test.mosquitto.org", strlen( pHostName ) ) == 0 )
|
if( strncmp( pHostName, "test.mosquitto.org", strlen( pHostName ) ) == 0 )
|
||||||
{
|
{
|
||||||
pNetworkContext->sslContext.certProfile.rsa_min_bitlen = 1024;
|
pTlsTransportParams->sslContext.certProfile.rsa_min_bitlen = 1024;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set SSL authmode and the RNG context. */
|
/* Set SSL authmode and the RNG context. */
|
||||||
mbedtls_ssl_conf_authmode( &( pNetworkContext->sslContext.config ),
|
mbedtls_ssl_conf_authmode( &( pTlsTransportParams->sslContext.config ),
|
||||||
MBEDTLS_SSL_VERIFY_REQUIRED );
|
MBEDTLS_SSL_VERIFY_REQUIRED );
|
||||||
mbedtls_ssl_conf_rng( &( pNetworkContext->sslContext.config ),
|
mbedtls_ssl_conf_rng( &( pTlsTransportParams->sslContext.config ),
|
||||||
generateRandomBytes,
|
generateRandomBytes,
|
||||||
&pNetworkContext->sslContext );
|
&pTlsTransportParams->sslContext );
|
||||||
mbedtls_ssl_conf_cert_profile( &( pNetworkContext->sslContext.config ),
|
mbedtls_ssl_conf_cert_profile( &( pTlsTransportParams->sslContext.config ),
|
||||||
&( pNetworkContext->sslContext.certProfile ) );
|
&( pTlsTransportParams->sslContext.certProfile ) );
|
||||||
|
|
||||||
/* Parse the server root CA certificate into the SSL context. */
|
/* Parse the server root CA certificate into the SSL context. */
|
||||||
mbedtlsError = mbedtls_x509_crt_parse( &( pNetworkContext->sslContext.rootCa ),
|
mbedtlsError = mbedtls_x509_crt_parse( &( pTlsTransportParams->sslContext.rootCa ),
|
||||||
pNetworkCredentials->pRootCa,
|
pNetworkCredentials->pRootCa,
|
||||||
pNetworkCredentials->rootCaSize );
|
pNetworkCredentials->rootCaSize );
|
||||||
|
|
||||||
@ -286,8 +303,8 @@ static TlsTransportStatus_t tlsSetup( NetworkContext_t * pNetworkContext,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mbedtls_ssl_conf_ca_chain( &( pNetworkContext->sslContext.config ),
|
mbedtls_ssl_conf_ca_chain( &( pTlsTransportParams->sslContext.config ),
|
||||||
&( pNetworkContext->sslContext.rootCa ),
|
&( pTlsTransportParams->sslContext.rootCa ),
|
||||||
NULL );
|
NULL );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -295,7 +312,7 @@ static TlsTransportStatus_t tlsSetup( NetworkContext_t * pNetworkContext,
|
|||||||
if( returnStatus == TLS_TRANSPORT_SUCCESS )
|
if( returnStatus == TLS_TRANSPORT_SUCCESS )
|
||||||
{
|
{
|
||||||
/* Setup the client private key. */
|
/* Setup the client private key. */
|
||||||
xResult = initializeClientKeys( &( pNetworkContext->sslContext ) );
|
xResult = initializeClientKeys( &( pTlsTransportParams->sslContext ) );
|
||||||
|
|
||||||
if( xResult != CKR_OK )
|
if( xResult != CKR_OK )
|
||||||
{
|
{
|
||||||
@ -306,10 +323,10 @@ static TlsTransportStatus_t tlsSetup( NetworkContext_t * pNetworkContext,
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Setup the client certificate. */
|
/* Setup the client certificate. */
|
||||||
xResult = readCertificateIntoContext( &( pNetworkContext->sslContext ),
|
xResult = readCertificateIntoContext( &( pTlsTransportParams->sslContext ),
|
||||||
pkcs11configLABEL_DEVICE_CERTIFICATE_FOR_TLS,
|
pkcs11configLABEL_DEVICE_CERTIFICATE_FOR_TLS,
|
||||||
CKO_CERTIFICATE,
|
CKO_CERTIFICATE,
|
||||||
&( pNetworkContext->sslContext.clientCert ) );
|
&( pTlsTransportParams->sslContext.clientCert ) );
|
||||||
|
|
||||||
if( xResult != CKR_OK )
|
if( xResult != CKR_OK )
|
||||||
{
|
{
|
||||||
@ -319,9 +336,9 @@ static TlsTransportStatus_t tlsSetup( NetworkContext_t * pNetworkContext,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
( void ) mbedtls_ssl_conf_own_cert( &( pNetworkContext->sslContext.config ),
|
( void ) mbedtls_ssl_conf_own_cert( &( pTlsTransportParams->sslContext.config ),
|
||||||
&( pNetworkContext->sslContext.clientCert ),
|
&( pTlsTransportParams->sslContext.clientCert ),
|
||||||
&( pNetworkContext->sslContext.privKey ) );
|
&( pTlsTransportParams->sslContext.privKey ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -330,7 +347,7 @@ static TlsTransportStatus_t tlsSetup( NetworkContext_t * pNetworkContext,
|
|||||||
{
|
{
|
||||||
/* Include an application protocol list in the TLS ClientHello
|
/* Include an application protocol list in the TLS ClientHello
|
||||||
* message. */
|
* message. */
|
||||||
mbedtlsError = mbedtls_ssl_conf_alpn_protocols( &( pNetworkContext->sslContext.config ),
|
mbedtlsError = mbedtls_ssl_conf_alpn_protocols( &( pTlsTransportParams->sslContext.config ),
|
||||||
pNetworkCredentials->pAlpnProtos );
|
pNetworkCredentials->pAlpnProtos );
|
||||||
|
|
||||||
if( mbedtlsError != 0 )
|
if( mbedtlsError != 0 )
|
||||||
@ -346,8 +363,8 @@ static TlsTransportStatus_t tlsSetup( NetworkContext_t * pNetworkContext,
|
|||||||
if( returnStatus == TLS_TRANSPORT_SUCCESS )
|
if( returnStatus == TLS_TRANSPORT_SUCCESS )
|
||||||
{
|
{
|
||||||
/* Initialize the mbed TLS secured connection context. */
|
/* Initialize the mbed TLS secured connection context. */
|
||||||
mbedtlsError = mbedtls_ssl_setup( &( pNetworkContext->sslContext.context ),
|
mbedtlsError = mbedtls_ssl_setup( &( pTlsTransportParams->sslContext.context ),
|
||||||
&( pNetworkContext->sslContext.config ) );
|
&( pTlsTransportParams->sslContext.config ) );
|
||||||
|
|
||||||
if( mbedtlsError != 0 )
|
if( mbedtlsError != 0 )
|
||||||
{
|
{
|
||||||
@ -366,8 +383,8 @@ static TlsTransportStatus_t tlsSetup( NetworkContext_t * pNetworkContext,
|
|||||||
* #mbedtls_ssl_set_bio requires the second parameter as void *.
|
* #mbedtls_ssl_set_bio requires the second parameter as void *.
|
||||||
*/
|
*/
|
||||||
/* coverity[misra_c_2012_rule_11_2_violation] */
|
/* coverity[misra_c_2012_rule_11_2_violation] */
|
||||||
mbedtls_ssl_set_bio( &( pNetworkContext->sslContext.context ),
|
mbedtls_ssl_set_bio( &( pTlsTransportParams->sslContext.context ),
|
||||||
( void * ) pNetworkContext->tcpSocket,
|
( void * ) pTlsTransportParams->tcpSocket,
|
||||||
mbedtls_platform_send,
|
mbedtls_platform_send,
|
||||||
mbedtls_platform_recv,
|
mbedtls_platform_recv,
|
||||||
NULL );
|
NULL );
|
||||||
@ -379,7 +396,7 @@ static TlsTransportStatus_t tlsSetup( NetworkContext_t * pNetworkContext,
|
|||||||
/* Enable SNI if requested. */
|
/* Enable SNI if requested. */
|
||||||
if( pNetworkCredentials->disableSni == pdFALSE )
|
if( pNetworkCredentials->disableSni == pdFALSE )
|
||||||
{
|
{
|
||||||
mbedtlsError = mbedtls_ssl_set_hostname( &( pNetworkContext->sslContext.context ),
|
mbedtlsError = mbedtls_ssl_set_hostname( &( pTlsTransportParams->sslContext.context ),
|
||||||
pHostName );
|
pHostName );
|
||||||
|
|
||||||
if( mbedtlsError != 0 )
|
if( mbedtlsError != 0 )
|
||||||
@ -402,7 +419,7 @@ static TlsTransportStatus_t tlsSetup( NetworkContext_t * pNetworkContext,
|
|||||||
*
|
*
|
||||||
* Smaller values can be found in "mbedtls/include/ssl.h".
|
* Smaller values can be found in "mbedtls/include/ssl.h".
|
||||||
*/
|
*/
|
||||||
mbedtlsError = mbedtls_ssl_conf_max_frag_len( &( pNetworkContext->sslContext.config ), MBEDTLS_SSL_MAX_FRAG_LEN_4096 );
|
mbedtlsError = mbedtls_ssl_conf_max_frag_len( &( pTlsTransportParams->sslContext.config ), MBEDTLS_SSL_MAX_FRAG_LEN_4096 );
|
||||||
|
|
||||||
if( mbedtlsError != 0 )
|
if( mbedtlsError != 0 )
|
||||||
{
|
{
|
||||||
@ -419,7 +436,7 @@ static TlsTransportStatus_t tlsSetup( NetworkContext_t * pNetworkContext,
|
|||||||
/* Perform the TLS handshake. */
|
/* Perform the TLS handshake. */
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
mbedtlsError = mbedtls_ssl_handshake( &( pNetworkContext->sslContext.context ) );
|
mbedtlsError = mbedtls_ssl_handshake( &( pTlsTransportParams->sslContext.context ) );
|
||||||
} while( ( mbedtlsError == MBEDTLS_ERR_SSL_WANT_READ ) ||
|
} while( ( mbedtlsError == MBEDTLS_ERR_SSL_WANT_READ ) ||
|
||||||
( mbedtlsError == MBEDTLS_ERR_SSL_WANT_WRITE ) );
|
( mbedtlsError == MBEDTLS_ERR_SSL_WANT_WRITE ) );
|
||||||
|
|
||||||
@ -435,7 +452,7 @@ static TlsTransportStatus_t tlsSetup( NetworkContext_t * pNetworkContext,
|
|||||||
|
|
||||||
if( returnStatus != TLS_TRANSPORT_SUCCESS )
|
if( returnStatus != TLS_TRANSPORT_SUCCESS )
|
||||||
{
|
{
|
||||||
sslContextFree( &( pNetworkContext->sslContext ) );
|
sslContextFree( &( pTlsTransportParams->sslContext ) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -774,10 +791,12 @@ TlsTransportStatus_t TLS_FreeRTOS_Connect( NetworkContext_t * pNetworkContext,
|
|||||||
uint32_t receiveTimeoutMs,
|
uint32_t receiveTimeoutMs,
|
||||||
uint32_t sendTimeoutMs )
|
uint32_t sendTimeoutMs )
|
||||||
{
|
{
|
||||||
|
TlsTransportParams_t * pTlsTransportParams = NULL;
|
||||||
TlsTransportStatus_t returnStatus = TLS_TRANSPORT_SUCCESS;
|
TlsTransportStatus_t returnStatus = TLS_TRANSPORT_SUCCESS;
|
||||||
BaseType_t socketStatus = 0;
|
BaseType_t socketStatus = 0;
|
||||||
|
|
||||||
if( ( pNetworkContext == NULL ) ||
|
if( ( pNetworkContext == NULL ) ||
|
||||||
|
( pNetworkContext->pParams == NULL ) ||
|
||||||
( pHostName == NULL ) ||
|
( pHostName == NULL ) ||
|
||||||
( pNetworkCredentials == NULL ) )
|
( pNetworkCredentials == NULL ) )
|
||||||
{
|
{
|
||||||
@ -801,7 +820,8 @@ TlsTransportStatus_t TLS_FreeRTOS_Connect( NetworkContext_t * pNetworkContext,
|
|||||||
/* Establish a TCP connection with the server. */
|
/* Establish a TCP connection with the server. */
|
||||||
if( returnStatus == TLS_TRANSPORT_SUCCESS )
|
if( returnStatus == TLS_TRANSPORT_SUCCESS )
|
||||||
{
|
{
|
||||||
socketStatus = Sockets_Connect( &( pNetworkContext->tcpSocket ),
|
pTlsTransportParams = pNetworkContext->pParams;
|
||||||
|
socketStatus = Sockets_Connect( &( pTlsTransportParams->tcpSocket ),
|
||||||
pHostName,
|
pHostName,
|
||||||
port,
|
port,
|
||||||
receiveTimeoutMs,
|
receiveTimeoutMs,
|
||||||
@ -832,9 +852,9 @@ TlsTransportStatus_t TLS_FreeRTOS_Connect( NetworkContext_t * pNetworkContext,
|
|||||||
if( returnStatus != TLS_TRANSPORT_SUCCESS )
|
if( returnStatus != TLS_TRANSPORT_SUCCESS )
|
||||||
{
|
{
|
||||||
if( ( pNetworkContext != NULL ) &&
|
if( ( pNetworkContext != NULL ) &&
|
||||||
( pNetworkContext->tcpSocket != FREERTOS_INVALID_SOCKET ) )
|
( pTlsTransportParams->tcpSocket != FREERTOS_INVALID_SOCKET ) )
|
||||||
{
|
{
|
||||||
( void ) FreeRTOS_closesocket( pNetworkContext->tcpSocket );
|
( void ) FreeRTOS_closesocket( pTlsTransportParams->tcpSocket );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -851,12 +871,14 @@ TlsTransportStatus_t TLS_FreeRTOS_Connect( NetworkContext_t * pNetworkContext,
|
|||||||
|
|
||||||
void TLS_FreeRTOS_Disconnect( NetworkContext_t * pNetworkContext )
|
void TLS_FreeRTOS_Disconnect( NetworkContext_t * pNetworkContext )
|
||||||
{
|
{
|
||||||
|
TlsTransportParams_t * pTlsTransportParams = NULL;
|
||||||
BaseType_t tlsStatus = 0;
|
BaseType_t tlsStatus = 0;
|
||||||
|
|
||||||
if( pNetworkContext != NULL )
|
if( pNetworkContext != NULL && pNetworkContext->pParams != NULL )
|
||||||
{
|
{
|
||||||
|
pTlsTransportParams = pNetworkContext->pParams;
|
||||||
/* Attempting to terminate TLS connection. */
|
/* Attempting to terminate TLS connection. */
|
||||||
tlsStatus = ( BaseType_t ) mbedtls_ssl_close_notify( &( pNetworkContext->sslContext.context ) );
|
tlsStatus = ( BaseType_t ) mbedtls_ssl_close_notify( &( pTlsTransportParams->sslContext.context ) );
|
||||||
|
|
||||||
/* Ignore the WANT_READ and WANT_WRITE return values. */
|
/* Ignore the WANT_READ and WANT_WRITE return values. */
|
||||||
if( ( tlsStatus != ( BaseType_t ) MBEDTLS_ERR_SSL_WANT_READ ) &&
|
if( ( tlsStatus != ( BaseType_t ) MBEDTLS_ERR_SSL_WANT_READ ) &&
|
||||||
@ -885,10 +907,10 @@ void TLS_FreeRTOS_Disconnect( NetworkContext_t * pNetworkContext )
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Call socket shutdown function to close connection. */
|
/* Call socket shutdown function to close connection. */
|
||||||
Sockets_Disconnect( pNetworkContext->tcpSocket );
|
Sockets_Disconnect( pTlsTransportParams->tcpSocket );
|
||||||
|
|
||||||
/* Free mbed TLS contexts. */
|
/* Free mbed TLS contexts. */
|
||||||
sslContextFree( &( pNetworkContext->sslContext ) );
|
sslContextFree( &( pTlsTransportParams->sslContext ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Clear the mutex functions for mbed TLS thread safety. */
|
/* Clear the mutex functions for mbed TLS thread safety. */
|
||||||
@ -901,9 +923,13 @@ int32_t TLS_FreeRTOS_recv( NetworkContext_t * pNetworkContext,
|
|||||||
void * pBuffer,
|
void * pBuffer,
|
||||||
size_t bytesToRecv )
|
size_t bytesToRecv )
|
||||||
{
|
{
|
||||||
|
TlsTransportParams_t * pTlsTransportParams = NULL;
|
||||||
int32_t tlsStatus = 0;
|
int32_t tlsStatus = 0;
|
||||||
|
|
||||||
tlsStatus = ( int32_t ) mbedtls_ssl_read( &( pNetworkContext->sslContext.context ),
|
configASSERT( ( pNetworkContext != NULL ) && ( pNetworkContext->pParams != NULL ) );
|
||||||
|
|
||||||
|
pTlsTransportParams = pNetworkContext->pParams;
|
||||||
|
tlsStatus = ( int32_t ) mbedtls_ssl_read( &( pTlsTransportParams->sslContext.context ),
|
||||||
pBuffer,
|
pBuffer,
|
||||||
bytesToRecv );
|
bytesToRecv );
|
||||||
|
|
||||||
@ -940,9 +966,13 @@ int32_t TLS_FreeRTOS_send( NetworkContext_t * pNetworkContext,
|
|||||||
const void * pBuffer,
|
const void * pBuffer,
|
||||||
size_t bytesToSend )
|
size_t bytesToSend )
|
||||||
{
|
{
|
||||||
|
TlsTransportParams_t * pTlsTransportParams = NULL;
|
||||||
int32_t tlsStatus = 0;
|
int32_t tlsStatus = 0;
|
||||||
|
|
||||||
tlsStatus = ( int32_t ) mbedtls_ssl_write( &( pNetworkContext->sslContext.context ),
|
configASSERT( ( pNetworkContext != NULL ) && ( pNetworkContext->pParams != NULL ) );
|
||||||
|
|
||||||
|
pTlsTransportParams = pNetworkContext->pParams;
|
||||||
|
tlsStatus = ( int32_t ) mbedtls_ssl_write( &( pTlsTransportParams->sslContext.context ),
|
||||||
pBuffer,
|
pBuffer,
|
||||||
bytesToSend );
|
bytesToSend );
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
|
* FreeRTOS V202011.00
|
||||||
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
@ -17,6 +18,10 @@
|
|||||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* https://www.FreeRTOS.org
|
||||||
|
* https://github.com/FreeRTOS
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -110,11 +115,11 @@ typedef struct SSLContext
|
|||||||
* @brief Definition of the network context for the transport interface
|
* @brief Definition of the network context for the transport interface
|
||||||
* implementation that uses mbedTLS and FreeRTOS+TLS sockets.
|
* implementation that uses mbedTLS and FreeRTOS+TLS sockets.
|
||||||
*/
|
*/
|
||||||
struct NetworkContext
|
typedef struct TlsTransportParams
|
||||||
{
|
{
|
||||||
Socket_t tcpSocket;
|
Socket_t tcpSocket;
|
||||||
SSLContext_t sslContext;
|
SSLContext_t sslContext;
|
||||||
};
|
} TlsTransportParams_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Contains the credentials necessary for tls connection setup.
|
* @brief Contains the credentials necessary for tls connection setup.
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
|
* FreeRTOS V202011.00
|
||||||
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
@ -17,6 +18,10 @@
|
|||||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* https://www.FreeRTOS.org
|
||||||
|
* https://github.com/FreeRTOS
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Standard includes. */
|
/* Standard includes. */
|
||||||
@ -35,16 +40,27 @@
|
|||||||
/* Transport interface include. */
|
/* Transport interface include. */
|
||||||
#include "using_plaintext.h"
|
#include "using_plaintext.h"
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* Each compilation unit must define the NetworkContext struct. */
|
||||||
|
struct NetworkContext
|
||||||
|
{
|
||||||
|
PlaintextTransportParams_t * pParams;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
PlaintextTransportStatus_t Plaintext_FreeRTOS_Connect( NetworkContext_t * pNetworkContext,
|
PlaintextTransportStatus_t Plaintext_FreeRTOS_Connect( NetworkContext_t * pNetworkContext,
|
||||||
const char * pHostName,
|
const char * pHostName,
|
||||||
uint16_t port,
|
uint16_t port,
|
||||||
uint32_t receiveTimeoutMs,
|
uint32_t receiveTimeoutMs,
|
||||||
uint32_t sendTimeoutMs )
|
uint32_t sendTimeoutMs )
|
||||||
{
|
{
|
||||||
|
PlaintextTransportParams_t * pPlaintextTransportParams = NULL;
|
||||||
PlaintextTransportStatus_t plaintextStatus = PLAINTEXT_TRANSPORT_SUCCESS;
|
PlaintextTransportStatus_t plaintextStatus = PLAINTEXT_TRANSPORT_SUCCESS;
|
||||||
BaseType_t socketStatus = 0;
|
BaseType_t socketStatus = 0;
|
||||||
|
|
||||||
if( ( pNetworkContext == NULL ) || ( pHostName == NULL ) )
|
if( ( pNetworkContext == NULL ) || ( pNetworkContext->pParams == NULL ) || ( pHostName == NULL ) )
|
||||||
{
|
{
|
||||||
LogError( ( "Invalid input parameter(s): Arguments cannot be NULL. pNetworkContext=%p, "
|
LogError( ( "Invalid input parameter(s): Arguments cannot be NULL. pNetworkContext=%p, "
|
||||||
"pHostName=%p.",
|
"pHostName=%p.",
|
||||||
@ -54,8 +70,9 @@ PlaintextTransportStatus_t Plaintext_FreeRTOS_Connect( NetworkContext_t * pNetwo
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
pPlaintextTransportParams = pNetworkContext->pParams;
|
||||||
/* Establish a TCP connection with the server. */
|
/* Establish a TCP connection with the server. */
|
||||||
socketStatus = Sockets_Connect( &( pNetworkContext->tcpSocket ),
|
socketStatus = Sockets_Connect( &( pPlaintextTransportParams->tcpSocket ),
|
||||||
pHostName,
|
pHostName,
|
||||||
port,
|
port,
|
||||||
receiveTimeoutMs,
|
receiveTimeoutMs,
|
||||||
@ -76,22 +93,24 @@ PlaintextTransportStatus_t Plaintext_FreeRTOS_Connect( NetworkContext_t * pNetwo
|
|||||||
|
|
||||||
PlaintextTransportStatus_t Plaintext_FreeRTOS_Disconnect( const NetworkContext_t * pNetworkContext )
|
PlaintextTransportStatus_t Plaintext_FreeRTOS_Disconnect( const NetworkContext_t * pNetworkContext )
|
||||||
{
|
{
|
||||||
|
PlaintextTransportParams_t * pPlaintextTransportParams = NULL;
|
||||||
PlaintextTransportStatus_t plaintextStatus = PLAINTEXT_TRANSPORT_SUCCESS;
|
PlaintextTransportStatus_t plaintextStatus = PLAINTEXT_TRANSPORT_SUCCESS;
|
||||||
|
|
||||||
if( pNetworkContext == NULL )
|
if( ( pNetworkContext == NULL ) || ( pNetworkContext->pParams == NULL ) )
|
||||||
{
|
{
|
||||||
LogError( ( "pNetworkContext cannot be NULL." ) );
|
LogError( ( "pNetworkContext cannot be NULL." ) );
|
||||||
plaintextStatus = PLAINTEXT_TRANSPORT_INVALID_PARAMETER;
|
plaintextStatus = PLAINTEXT_TRANSPORT_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
else if( pNetworkContext->tcpSocket == FREERTOS_INVALID_SOCKET )
|
else if( pNetworkContext->pParams->tcpSocket == FREERTOS_INVALID_SOCKET )
|
||||||
{
|
{
|
||||||
LogError( ( "pNetworkContext->tcpSocket cannot be an invalid socket." ) );
|
LogError( ( "pPlaintextTransportParams->tcpSocket cannot be an invalid socket." ) );
|
||||||
plaintextStatus = PLAINTEXT_TRANSPORT_INVALID_PARAMETER;
|
plaintextStatus = PLAINTEXT_TRANSPORT_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
pPlaintextTransportParams = pNetworkContext->pParams;
|
||||||
/* Call socket disconnect function to close connection. */
|
/* Call socket disconnect function to close connection. */
|
||||||
Sockets_Disconnect( pNetworkContext->tcpSocket );
|
Sockets_Disconnect( pPlaintextTransportParams->tcpSocket );
|
||||||
}
|
}
|
||||||
|
|
||||||
return plaintextStatus;
|
return plaintextStatus;
|
||||||
@ -101,9 +120,16 @@ int32_t Plaintext_FreeRTOS_recv( NetworkContext_t * pNetworkContext,
|
|||||||
void * pBuffer,
|
void * pBuffer,
|
||||||
size_t bytesToRecv )
|
size_t bytesToRecv )
|
||||||
{
|
{
|
||||||
|
PlaintextTransportParams_t * pPlaintextTransportParams = NULL;
|
||||||
int32_t socketStatus = 0;
|
int32_t socketStatus = 0;
|
||||||
|
|
||||||
socketStatus = FreeRTOS_recv( pNetworkContext->tcpSocket, pBuffer, bytesToRecv, 0 );
|
configASSERT( ( pNetworkContext != NULL ) && ( pNetworkContext->pParams != NULL ) );
|
||||||
|
|
||||||
|
pPlaintextTransportParams = pNetworkContext->pParams;
|
||||||
|
socketStatus = FreeRTOS_recv( pPlaintextTransportParams->tcpSocket,
|
||||||
|
pBuffer,
|
||||||
|
bytesToRecv,
|
||||||
|
0 );
|
||||||
|
|
||||||
return socketStatus;
|
return socketStatus;
|
||||||
}
|
}
|
||||||
@ -112,9 +138,16 @@ int32_t Plaintext_FreeRTOS_send( NetworkContext_t * pNetworkContext,
|
|||||||
const void * pBuffer,
|
const void * pBuffer,
|
||||||
size_t bytesToSend )
|
size_t bytesToSend )
|
||||||
{
|
{
|
||||||
|
PlaintextTransportParams_t * pPlaintextTransportParams = NULL;
|
||||||
int32_t socketStatus = 0;
|
int32_t socketStatus = 0;
|
||||||
|
|
||||||
socketStatus = FreeRTOS_send( pNetworkContext->tcpSocket, pBuffer, bytesToSend, 0 );
|
configASSERT( ( pNetworkContext != NULL ) && ( pNetworkContext->pParams != NULL ) );
|
||||||
|
|
||||||
|
pPlaintextTransportParams = pNetworkContext->pParams;
|
||||||
|
socketStatus = FreeRTOS_send( pPlaintextTransportParams->tcpSocket,
|
||||||
|
pBuffer,
|
||||||
|
bytesToSend,
|
||||||
|
0 );
|
||||||
|
|
||||||
return socketStatus;
|
return socketStatus;
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
|
* FreeRTOS V202011.00
|
||||||
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
@ -17,6 +18,10 @@
|
|||||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* https://www.FreeRTOS.org
|
||||||
|
* https://github.com/FreeRTOS
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef USING_PLAINTEXT_H
|
#ifndef USING_PLAINTEXT_H
|
||||||
@ -67,12 +72,12 @@ extern void vLoggingPrintf( const char * pcFormatString,
|
|||||||
#include "transport_interface.h"
|
#include "transport_interface.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Network context definition for FreeRTOS sockets.
|
* @brief Parameters for the network context that uses FreeRTOS+TCP sockets.
|
||||||
*/
|
*/
|
||||||
struct NetworkContext
|
typedef struct PlaintextTransportParams
|
||||||
{
|
{
|
||||||
Socket_t tcpSocket;
|
Socket_t tcpSocket;
|
||||||
};
|
} PlaintextTransportParams_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Plain text transport Connect / Disconnect return status.
|
* @brief Plain text transport Connect / Disconnect return status.
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
|
* FreeRTOS V202011.00
|
||||||
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
@ -17,6 +18,10 @@
|
|||||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* https://www.FreeRTOS.org
|
||||||
|
* https://github.com/FreeRTOS
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user