Skip to content
This repository has been archived by the owner on Oct 25, 2023. It is now read-only.

Commit

Permalink
Fix GreenGrass Discovery demo failure in Nuvoton Ethernet board (aws#…
Browse files Browse the repository at this point in the history
…2242) (aws#2249)

* Fix mapping of configPRINTF to vLoggingPrintf to fix message mangling

* Fix incorrect mapping of FreeRTOS_debug_printf

* Fix incorrect mapping of FreeRTOS_debug_printf for aws_tests

* Enable ipconfigINCLUDE_FULL_INET_ADDR for Nuvoton Ethernet GreenGrass demo

* Add logs GGD_SecureConnect_Connect for improving debuggability

* Hygiene improvements

* Add error log for SOCKETS_GetHostByName failure

* Increase logging message length in aws_demo config to avoid truncated message causing CI failure in
  • Loading branch information
aggarw13 authored and VanNamDinh committed Jul 12, 2020
1 parent 3d6aca5 commit e6014f0
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ BaseType_t GGD_SecureConnect_Connect( const GGD_HostAddressData_t * pxHostAddres
size_t xURLLength;
BaseType_t xIsIPAddress;
BaseType_t xStatus;
int32_t returnCode;

configASSERT( pxHostAddressData != NULL );
configASSERT( pxSocket != NULL );
Expand Down Expand Up @@ -105,6 +106,13 @@ BaseType_t GGD_SecureConnect_Connect( const GGD_HostAddressData_t * pxHostAddres
xServerAddress.usPort = SOCKETS_htons( pxHostAddressData->usPort );
xServerAddress.ulAddress =
SOCKETS_GetHostByName( pxHostAddressData->pcHostAddress );

if( xServerAddress.ulAddress == 0u )
{
ggdconfigPRINT( "ERROR! Failed to resolve host address: ServerHost=%.*s",
xURLLength, pxHostAddressData->pcHostAddress );
}

xServerAddress.ucSocketDomain = SOCKETS_AF_INET;

/* Set send timeout for the socket. */
Expand All @@ -130,38 +138,50 @@ BaseType_t GGD_SecureConnect_Connect( const GGD_HostAddressData_t * pxHostAddres

if( pxHostAddressData->pcCertificate != NULL )
{
if( SOCKETS_SetSockOpt( *pxSocket,
0,
SOCKETS_SO_TRUSTED_SERVER_CERTIFICATE,
pxHostAddressData->pcCertificate,
( size_t ) pxHostAddressData->ulCertificateSize )
!= SOCKETS_ERROR_NONE )
/* Override TLS trust store with server certificate. */
returnCode = SOCKETS_SetSockOpt( *pxSocket,
0,
SOCKETS_SO_TRUSTED_SERVER_CERTIFICATE,
pxHostAddressData->pcCertificate,
( size_t ) pxHostAddressData->ulCertificateSize );

if( returnCode != SOCKETS_ERROR_NONE )
{
ggdconfigPRINT( "ERROR! Failure in SOCKET_SetSockOpt call for overriding TLS trust store: "
"ReturnCode=%d\r\n", returnCode );
xStatus = pdFAIL;
}
}

if( xIsIPAddress == pdFALSE )
{
if( SOCKETS_SetSockOpt( *pxSocket,
0,
SOCKETS_SO_SERVER_NAME_INDICATION,
pxHostAddressData->pcHostAddress,
( size_t ) 1 + xURLLength )
!= SOCKETS_ERROR_NONE )
/* Enable use of SNI in TLS. */
returnCode = SOCKETS_SetSockOpt( *pxSocket,
0,
SOCKETS_SO_SERVER_NAME_INDICATION,
pxHostAddressData->pcHostAddress,
( size_t ) 1 + xURLLength );

if( returnCode != SOCKETS_ERROR_NONE )
{
ggdconfigPRINT( "ERROR! Failure in SOCKET_SetSockOpt call for enabling TLS SNI: "
"ServerHost=%.*s, ReturnCode=%d\r\n",
xURLLength, pxHostAddressData->pcHostAddress, returnCode );
xStatus = pdFAIL;
}
}

/* Establish the TCP connection. */
if( pdPASS == xStatus )
{
if( ( SOCKETS_Connect( *pxSocket,
&xServerAddress,
( uint32_t ) sizeof( xServerAddress ) )
!= SOCKETS_ERROR_NONE ) )
returnCode = SOCKETS_Connect( *pxSocket,
&xServerAddress,
( uint32_t ) sizeof( xServerAddress ) );

if( returnCode != SOCKETS_ERROR_NONE )
{
ggdconfigPRINT( "ERROR! SOCKETS_Connect call failed: ServerAddress=%lu, Port=%u, ReturnCode=%d\r\n",
xServerAddress.ulAddress, xServerAddress.usPort, returnCode );
GGD_SecureConnect_Disconnect( pxSocket );
xStatus = pdFAIL;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ void vLoggingPrintf( const char * pcFormat,
... );

/* Map the FreeRTOS printf() to the logging task printf. */
#define configPRINTF( x ) printf x //vLoggingPrintf x
#define configPRINTF( x ) vLoggingPrintf x

/* Non-format version thread-safe print */
#define configPRINT( X ) vLoggingPrint( X )
Expand All @@ -152,7 +152,7 @@ void vLoggingPrintf( const char * pcFormat,

/* Sets the length of the buffers into which logging messages are written - so
* also defines the maximum length of each log message. */
#define configLOGGING_MAX_MESSAGE_LENGTH 80
#define configLOGGING_MAX_MESSAGE_LENGTH 128

/* Set to 1 to prepend each log message with a message number, the task name,
* and a time stamp. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ extern void vLoggingPrintf( const char * pcFormatString,
* out the debugging messages. */
#define ipconfigHAS_DEBUG_PRINTF 0
#if ( ipconfigHAS_DEBUG_PRINTF == 1 )
#define FreeRTOS_debug_printf( X ) vLoggingPrintf( X )
#define FreeRTOS_debug_printf( X ) configPRINTF( X )
#endif

/* Set to 1 to print out non debugging messages, for example the output of the
Expand Down Expand Up @@ -200,7 +200,7 @@ extern uint32_t numaker_ulRand(void);
* ipconfigINCLUDE_FULL_INET_ADDR is set to 1 then both FreeRTOS_inet_addr() and
* FreeRTOS_indet_addr_quick() are available. If ipconfigINCLUDE_FULL_INET_ADDR is
* not set to 1 then only FreeRTOS_indet_addr_quick() is available. */
#define ipconfigINCLUDE_FULL_INET_ADDR 0
#define ipconfigINCLUDE_FULL_INET_ADDR 1

/* ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS defines the total number of network buffer that
* are available to the IP stack. The total number of network buffers is limited
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ extern void vLoggingPrintf( const char * pcFormatString,
/* Set to 1 to print out debug messages. If ipconfigHAS_DEBUG_PRINTF is set to
* 1 then FreeRTOS_debug_printf should be defined to the function used to print
* out the debugging messages. */
#define ipconfigHAS_DEBUG_PRINTF 0 //1
#define ipconfigHAS_DEBUG_PRINTF 0
#if ( ipconfigHAS_DEBUG_PRINTF == 1 )
#define FreeRTOS_debug_printf( X ) vLoggingPrintf( X )//configPRINTF( X )
#define FreeRTOS_debug_printf( X ) configPRINTF( X )
#endif

/* Set to 1 to print out non debugging messages, for example the output of the
Expand Down Expand Up @@ -118,7 +118,7 @@ extern void vLoggingPrintf( const char * pcFormatString,
* number generation is performed via this macro to allow applications to use their
* own random number generation method. For example, it might be possible to
* generate a random number by sampling noise on an analogue input. */
extern uint32_t numaker_ulRand(void);
extern uint32_t numaker_ulRand( void );
#define ipconfigRAND32() numaker_ulRand()

/* If ipconfigUSE_NETWORK_EVENT_HOOK is set to 1 then FreeRTOS+TCP will call the
Expand Down Expand Up @@ -206,7 +206,7 @@ extern uint32_t numaker_ulRand(void);
* are available to the IP stack. The total number of network buffers is limited
* to ensure the total amount of RAM that can be consumed by the IP stack is capped
* to a pre-determinable value. */
#define ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS 5//16
#define ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS 5

/* A FreeRTOS queue is used to send events from application tasks to the IP
* stack. ipconfigEVENT_QUEUE_LENGTH sets the maximum number of events that can
Expand Down

0 comments on commit e6014f0

Please sign in to comment.