Skip to content

Commit 5f0bf94

Browse files
Fix MISRA warnings for platform code used by MQTT demos (FreeRTOS#337)
In addition to fixing MISRA warnings, code is updated to have complexity <= 8. Also, this adds changes from PR FreeRTOS#313, which allows the support of simultaneous connections in the mbedTLS transport wrapper. Co-authored-by: Muneeb Ahmed <[email protected]>
1 parent 02aafc3 commit 5f0bf94

File tree

13 files changed

+1187
-878
lines changed

13 files changed

+1187
-878
lines changed

FreeRTOS-Plus/Demo/coreMQTT_Windows_Simulator/MQTT_Mutual_Auth/DemoTasks/MutualAuthMQTTExample.c

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -190,22 +190,12 @@
190190
*/
191191
#define AWS_IOT_MQTT_ALPN "\x0ex-amzn-mqtt-ca"
192192

193-
/**
194-
* @brief Length of ALPN protocol name.
195-
*/
196-
#define AWS_IOT_MQTT_ALPN_LENGTH ( ( uint16_t ) ( sizeof( AWS_IOT_MQTT_ALPN ) - 1 ) )
197-
198193
/**
199194
* @brief This is the ALPN (Application-Layer Protocol Negotiation) string
200195
* required by AWS IoT for password-based authentication using TCP port 443.
201196
*/
202197
#define AWS_IOT_CUSTOM_AUTH_ALPN "\x04mqtt"
203198

204-
/**
205-
* @brief Length of password ALPN.
206-
*/
207-
#define AWS_IOT_CUSTOM_AUTH_ALPN_LENGTH ( ( uint16_t ) ( sizeof( AWS_IOT_CUSTOM_AUTH_ALPN ) - 1 ) )
208-
209199
/**
210200
* Provide default values for undefined configuration settings.
211201
*/
@@ -567,6 +557,11 @@ static TlsTransportStatus_t prvConnectToServerWithBackoffRetries( NetworkCredent
567557
RetryUtilsStatus_t xRetryUtilsStatus = RetryUtilsSuccess;
568558
RetryUtilsParams_t xReconnectParams;
569559

560+
/* ALPN protocols must be a NULL-terminated list of strings. Therefore,
561+
* the first entry will contain the actual ALPN protocol string while the
562+
* second entry must remain NULL. */
563+
char * pcAlpnProtocols[] = { NULL, NULL };
564+
570565
/* Set the credentials for establishing a TLS connection. */
571566
pxNetworkCredentials->pRootCa = ( const unsigned char * ) democonfigROOT_CA_PEM;
572567
pxNetworkCredentials->rootCaSize = sizeof( democonfigROOT_CA_PEM );
@@ -580,11 +575,12 @@ static TlsTransportStatus_t prvConnectToServerWithBackoffRetries( NetworkCredent
580575
pxNetworkCredentials->disableSni = pdFALSE;
581576
/* The ALPN string changes depending on whether username/password authentication is used. */
582577
#ifdef democonfigCLIENT_USERNAME
583-
pxNetworkCredentials->pAlpnProtos = AWS_IOT_CUSTOM_AUTH_ALPN;
578+
pcAlpnProtocols[ 0 ] = AWS_IOT_CUSTOM_AUTH_ALPN;
584579
#else
585-
pxNetworkCredentials->pAlpnProtos = AWS_IOT_MQTT_ALPN;
580+
pcAlpnProtocols[ 0 ] = AWS_IOT_MQTT_ALPN;
586581
#endif
587-
#else
582+
pxNetworkCredentials->pAlpnProtos = pcAlpnProtocols;
583+
#else /* ifdef democonfigUSE_AWS_IOT_CORE_BROKER */
588584

589585
/* When using a local Mosquitto server setup, SNI needs to be disabled for
590586
* an MQTT broker that only has an IP address but no hostname. However,
@@ -686,7 +682,7 @@ static void prvCreateMQTTConnectionWithBroker( MQTTContext_t * pxMQTTContext,
686682
/* Password for authentication is not used. */
687683
xConnectInfo.pPassword = NULL;
688684
xConnectInfo.passwordLength = 0U;
689-
#endif /* ifdef democonfigCLIENT_USERNAME */
685+
#endif
690686
#else /* ifdef democonfigUSE_AWS_IOT_CORE_BROKER */
691687
#ifdef democonfigCLIENT_USERNAME
692688
xConnectInfo.pUserName = democonfigCLIENT_USERNAME;

0 commit comments

Comments
 (0)