From 07e2bc2769cba6b2bb0cbbfbe9cdc48d419ecbaa Mon Sep 17 00:00:00 2001 From: Soren Ptak Date: Tue, 31 Oct 2023 11:22:03 -0700 Subject: [PATCH] Use ubuntu 20.04 for formatting so that this repo can use the same formatting as all other FreeRTOS Repos --- .github/workflows/ci.yml | 2 +- Bsp/common/bsp_serial.c | 180 ++++++++++-------- Bsp/common/bsp_serial.h | 4 +- .../transport_tls_iot_socket.c | 17 +- .../src/ota_provision.c | 17 +- .../src/ota_provision.h | 18 +- Middleware/ARM/mbedtls-lib/src/tls_helper.h | 25 +-- .../dev_mode_key_provisioning.c | 2 + .../mqtt-agent-wrapper/mqtt_agent_task.c | 1 + 9 files changed, 147 insertions(+), 119 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e4c0de6f..ad72bda3 100755 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,7 +27,7 @@ jobs: uses: FreeRTOS/CI-CD-Github-Actions/spellings@main formatting: - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v3 - name: Check formatting diff --git a/Bsp/common/bsp_serial.c b/Bsp/common/bsp_serial.c index e9bbd012..990a5a9b 100644 --- a/Bsp/common/bsp_serial.c +++ b/Bsp/common/bsp_serial.c @@ -11,114 +11,134 @@ extern ARM_DRIVER_USART Driver_USART0; -void bsp_serial_init(void) +void bsp_serial_init( void ) { - Driver_USART0.Initialize(NULL); - Driver_USART0.Control(ARM_USART_MODE_ASYNCHRONOUS, DEFAULT_UART_BAUDRATE); + Driver_USART0.Initialize( NULL ); + Driver_USART0.Control( ARM_USART_MODE_ASYNCHRONOUS, DEFAULT_UART_BAUDRATE ); } -void bsp_serial_print(char *str) +void bsp_serial_print( char * str ) { - (void)Driver_USART0.Send(str, strlen(str)); + ( void ) Driver_USART0.Send( str, strlen( str ) ); } -#if defined(__ARMCOMPILER_VERSION) +#if defined( __ARMCOMPILER_VERSION ) /* Retarget armclang, which requires all IO system calls to be overridden together. */ -#include + #include -#define STDIN_FILENO 0 -#define STDOUT_FILENO 1 -#define STDERR_FILENO 2 + #define STDIN_FILENO 0 + #define STDOUT_FILENO 1 + #define STDERR_FILENO 2 -FILEHANDLE _sys_open(const char *name, int openmode) -{ - if (name == NULL) { - return -1; - } - - // By default, the Arm Compiler uses the special file path ":tt" for stdin, - // stdout and stderr and distinguishes between them using openmode. For details, - // see https://github.com/ARM-software/abi-aa/blob/2022Q1/semihosting/semihosting.rst#sys-open-0x01 - if (strcmp(name, ":tt") == 0) { - if (openmode & OPEN_W) { - return STDOUT_FILENO; - } - if (openmode & OPEN_A) { - return STDERR_FILENO; + FILEHANDLE _sys_open( const char * name, + int openmode ) + { + if( name == NULL ) + { + return -1; } - return STDIN_FILENO; - } - - return -1; -} -int _sys_close(FILEHANDLE fh) -{ - /* Not implemented */ - (void)fh; - return -1; -} - -int _sys_write(FILEHANDLE fd, const unsigned char *str, unsigned int len, int mode) -{ - /* From : `mode' exists for historical reasons and must be ignored. */ - (void)mode; + /* By default, the Arm Compiler uses the special file path ":tt" for stdin, */ + /* stdout and stderr and distinguishes between them using openmode. For details, */ + /* see https://github.com/ARM-software/abi-aa/blob/2022Q1/semihosting/semihosting.rst#sys-open-0x01 */ + if( strcmp( name, ":tt" ) == 0 ) + { + if( openmode & OPEN_W ) + { + return STDOUT_FILENO; + } + + if( openmode & OPEN_A ) + { + return STDERR_FILENO; + } + + return STDIN_FILENO; + } - if (fd != STDOUT_FILENO && fd != STDERR_FILENO) { return -1; } - if (Driver_USART0.Send(str, len) != ARM_DRIVER_OK) { + int _sys_close( FILEHANDLE fh ) + { + /* Not implemented */ + ( void ) fh; return -1; } - return 0; -} + int _sys_write( FILEHANDLE fd, + const unsigned char * str, + unsigned int len, + int mode ) + { + /* From : `mode' exists for historical reasons and must be ignored. */ + ( void ) mode; + + if( ( fd != STDOUT_FILENO ) && ( fd != STDERR_FILENO ) ) + { + return -1; + } -int _sys_read(FILEHANDLE fd, unsigned char *str, unsigned int len, int mode) -{ - // From : `mode' exists for historical reasons and must be ignored. - (void)mode; + if( Driver_USART0.Send( str, len ) != ARM_DRIVER_OK ) + { + return -1; + } - /* Not implemented */ - (void)str; - (void)len; - return -1; -} + return 0; + } -int _sys_istty(FILEHANDLE fh) -{ - /* Not implemented */ - (void)fh; - return 0; -} + int _sys_read( FILEHANDLE fd, + unsigned char * str, + unsigned int len, + int mode ) + { + /* From : `mode' exists for historical reasons and must be ignored. */ + ( void ) mode; + + /* Not implemented */ + ( void ) str; + ( void ) len; + return -1; + } -long _sys_flen(FILEHANDLE fh) -{ - /* Not implemented */ - (void)fh; - return -1; -} + int _sys_istty( FILEHANDLE fh ) + { + /* Not implemented */ + ( void ) fh; + return 0; + } -int _sys_seek(FILEHANDLE fh, long offset) -{ - /* Not implemented */ - (void)fh; - (void)offset; - return -1; -} + long _sys_flen( FILEHANDLE fh ) + { + /* Not implemented */ + ( void ) fh; + return -1; + } + + int _sys_seek( FILEHANDLE fh, + long offset ) + { + /* Not implemented */ + ( void ) fh; + ( void ) offset; + return -1; + } #else /* !defined(__ARMCOMPILER_VERSION) */ /* Redirects gcc printf to UART0 */ -int _write(int fd, char *str, int len) -{ - if (Driver_USART0.Send(str, len) == ARM_DRIVER_OK) { - return len; + int _write( int fd, + char * str, + int len ) + { + if( Driver_USART0.Send( str, len ) == ARM_DRIVER_OK ) + { + return len; + } + + return 0; } - return 0; -} -#endif +#endif /* if defined( __ARMCOMPILER_VERSION ) */ diff --git a/Bsp/common/bsp_serial.h b/Bsp/common/bsp_serial.h index 1714c9e7..f01b3ef2 100644 --- a/Bsp/common/bsp_serial.h +++ b/Bsp/common/bsp_serial.h @@ -12,11 +12,11 @@ /** * \brief Initializes default UART device */ -void bsp_serial_init(void); +void bsp_serial_init( void ); /** * \brief Prints a string through the default UART device */ -void bsp_serial_print(char *str); +void bsp_serial_print( char * str ); #endif /* __SERIAL_H__ */ diff --git a/Middleware/ARM/IoT_VSocket-lib/transport_tls_iot_socket.c b/Middleware/ARM/IoT_VSocket-lib/transport_tls_iot_socket.c index 90fcc915..98b34f1f 100644 --- a/Middleware/ARM/IoT_VSocket-lib/transport_tls_iot_socket.c +++ b/Middleware/ARM/IoT_VSocket-lib/transport_tls_iot_socket.c @@ -23,11 +23,11 @@ static int Recv_Cb( void * pvCallerContext, - unsigned char * pucReceiveBuffer, - size_t xReceiveLength ); + unsigned char * pucReceiveBuffer, + size_t xReceiveLength ); static int Send_Cb( void * pvCallerContext, - const unsigned char * pucData, - size_t xDataLength ); + const unsigned char * pucData, + size_t xDataLength ); TransportStatus_t Transport_Connect( NetworkContext_t * pNetworkContext, @@ -199,8 +199,8 @@ int32_t Transport_Send( NetworkContext_t * pNetworkContext, * @return The number of bytes actually read or appropriate error code. */ static int Recv_Cb( void * pvCallerContext, - unsigned char * pucReceiveBuffer, - size_t xReceiveLength ) + unsigned char * pucReceiveBuffer, + size_t xReceiveLength ) { int rc; NetworkContext_t * pNetworkContext = ( NetworkContext_t * ) ( pvCallerContext ); @@ -236,8 +236,8 @@ static int Recv_Cb( void * pvCallerContext, * @return The number of bytes actually sent. */ static int Send_Cb( void * pvCallerContext, - const unsigned char * pucData, - size_t xDataLength ) + const unsigned char * pucData, + size_t xDataLength ) { NetworkContext_t * pNetworkContext = ( NetworkContext_t * ) ( pvCallerContext ); int rc; @@ -265,6 +265,7 @@ TransportStatus_t Transport_Disconnect( NetworkContext_t * pNetworkContext ) else { int32_t socketStatus; + do { socketStatus = iotSocketClose( pNetworkContext->socket ); diff --git a/Middleware/ARM/freertos-ota-pal-psa-lib/src/ota_provision.c b/Middleware/ARM/freertos-ota-pal-psa-lib/src/ota_provision.c index c9bfe5e0..08d5a8d1 100644 --- a/Middleware/ARM/freertos-ota-pal-psa-lib/src/ota_provision.c +++ b/Middleware/ARM/freertos-ota-pal-psa-lib/src/ota_provision.c @@ -29,9 +29,9 @@ extern int convert_pem_to_der( const unsigned char * pucInput, unsigned char * pucOutput, size_t * pxOlen ); -int ota_privision_code_signing_key(psa_key_handle_t * key_handle) +int ota_privision_code_signing_key( psa_key_handle_t * key_handle ) { - uint8_t public_key_der[512]; + uint8_t public_key_der[ 512 ]; size_t xLength = 512; int result; psa_key_handle_t key_handle_tmp = 0; @@ -39,9 +39,10 @@ int ota_privision_code_signing_key(psa_key_handle_t * key_handle) psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; result = convert_pem_to_der( ( const unsigned char * ) cOTARSAPublicKey, - sizeof( cOTARSAPublicKey ), - public_key_der, - &xLength ); + sizeof( cOTARSAPublicKey ), + public_key_der, + &xLength ); + if( result != 0 ) { return result; @@ -50,11 +51,13 @@ int ota_privision_code_signing_key(psa_key_handle_t * key_handle) psa_set_key_usage_flags( &attributes, PSA_KEY_USAGE_VERIFY_HASH ); psa_set_key_algorithm( &attributes, PSA_ALG_RSA_PSS_ANY_SALT( PSA_ALG_SHA_256 ) ); psa_set_key_type( &attributes, PSA_KEY_TYPE_RSA_PUBLIC_KEY ); - psa_set_key_bits(&attributes, 3072); - status = psa_import_key(&attributes, ( const uint8_t *)public_key_der, xLength, &key_handle_tmp ); + psa_set_key_bits( &attributes, 3072 ); + status = psa_import_key( &attributes, ( const uint8_t * ) public_key_der, xLength, &key_handle_tmp ); + if( status == PSA_SUCCESS ) { *key_handle = key_handle_tmp; } + return status; } diff --git a/Middleware/ARM/freertos-ota-pal-psa-lib/src/ota_provision.h b/Middleware/ARM/freertos-ota-pal-psa-lib/src/ota_provision.h index c40d0ca4..d5d01bdc 100644 --- a/Middleware/ARM/freertos-ota-pal-psa-lib/src/ota_provision.h +++ b/Middleware/ARM/freertos-ota-pal-psa-lib/src/ota_provision.h @@ -4,15 +4,15 @@ */ #ifndef _OTA_PROVISION_ -#define _OTA_PROVISION_ -#include "psa/crypto.h" -#ifdef __cplusplus -extern "C" { -#endif + #define _OTA_PROVISION_ + #include "psa/crypto.h" + #ifdef __cplusplus + extern "C" { + #endif -int ota_privision_code_signing_key(psa_key_handle_t * key_handle); + int ota_privision_code_signing_key( psa_key_handle_t * key_handle ); -#ifdef __cplusplus + #ifdef __cplusplus } -#endif -#endif + #endif +#endif /* ifndef _OTA_PROVISION_ */ diff --git a/Middleware/ARM/mbedtls-lib/src/tls_helper.h b/Middleware/ARM/mbedtls-lib/src/tls_helper.h index c4c88099..f5361e4d 100644 --- a/Middleware/ARM/mbedtls-lib/src/tls_helper.h +++ b/Middleware/ARM/mbedtls-lib/src/tls_helper.h @@ -63,8 +63,8 @@ typedef struct TLSContext * @return The number of bytes actually read. */ typedef int ( * NetworkRecv_t )( void * pvCallerContext, - unsigned char * pucReceiveBuffer, - size_t xReceiveLength ); + unsigned char * pucReceiveBuffer, + size_t xReceiveLength ); /** * @brief Defines callback type for sending bytes to the network. @@ -76,8 +76,8 @@ typedef int ( * NetworkRecv_t )( void * pvCallerContext, * @return The number of bytes actually sent. */ typedef int ( * NetworkSend_t )( void * pvCallerContext, - const unsigned char * pucData, - size_t xDataLength ); + const unsigned char * pucData, + size_t xDataLength ); /** * @brief Defines parameter structure for initializing the TLS interface. @@ -103,9 +103,9 @@ typedef struct TLSHelperParams const char * pcServerCertificate; uint32_t ulServerCertificateLength; - const char * pClientCertLabel; /**< @brief String representing the PKCS #11 label for the client certificate. */ - const char * pPrivateKeyLabel; /**< @brief String representing the PKCS #11 label for the private key. */ - const char * pcLoginPIN; /**< @brief A login Password used to retrive the credentials */ + const char * pClientCertLabel; /**< @brief String representing the PKCS #11 label for the client certificate. */ + const char * pPrivateKeyLabel; /**< @brief String representing the PKCS #11 label for the private key. */ + const char * pcLoginPIN; /**< @brief A login Password used to retrive the credentials */ } TLSHelperParams_t; /** @@ -116,7 +116,8 @@ typedef struct TLSHelperParams * * @return Zero on success. Error return codes have the high bit set. */ -BaseType_t TLS_Init( TLSHelperParams_t * pxParams, TLSContext_t * pxContext ); +BaseType_t TLS_Init( TLSHelperParams_t * pxParams, + TLSContext_t * pxContext ); /** * @brief Perform TLS handshake with the given TLS context. @@ -136,12 +137,12 @@ void TLS_Cleanup( TLSContext_t * pxContext ); int32_t TLS_Recv( TLSContext_t * pxContext, - unsigned char * pucReadBuffer, - size_t xReadLength ); + unsigned char * pucReadBuffer, + size_t xReadLength ); int32_t TLS_Send( TLSContext_t * pxContext, - const unsigned char * pucMsg, - size_t xMsgLength ); + const unsigned char * pucMsg, + size_t xMsgLength ); #endif /* ifndef TLS_HELPER_H */ diff --git a/Projects/aws-iot-example/dev_mode_key_provisioning.c b/Projects/aws-iot-example/dev_mode_key_provisioning.c index dcde9abe..5ffad940 100644 --- a/Projects/aws-iot-example/dev_mode_key_provisioning.c +++ b/Projects/aws-iot-example/dev_mode_key_provisioning.c @@ -1074,6 +1074,7 @@ CK_RV xProvisionDevice( CK_SESSION_HANDLE xSession, xResult = C_GetFunctionList( &pxFunctionList ); #if ( pkcs11configIMPORT_PRIVATE_KEYS_SUPPORTED == 1 ) + /* Attempt to clean-up old crypto objects, but only if private key import is * supported by this application, and only if the caller has provided new * objects to use instead. */ @@ -1107,6 +1108,7 @@ CK_RV xProvisionDevice( CK_SESSION_HANDLE xSession, } #if ( pkcs11configIMPORT_PRIVATE_KEYS_SUPPORTED == 1 ) + /* If this application supports importing private keys, and if a private * key has been provided by the caller, attempt to import it. */ if( ( xResult == CKR_OK ) && ( NULL != pxParams->pucClientPrivateKey ) ) diff --git a/Projects/aws-iot-example/mqtt-agent-wrapper/mqtt_agent_task.c b/Projects/aws-iot-example/mqtt-agent-wrapper/mqtt_agent_task.c index b239dc9f..c77db1b7 100644 --- a/Projects/aws-iot-example/mqtt-agent-wrapper/mqtt_agent_task.c +++ b/Projects/aws-iot-example/mqtt-agent-wrapper/mqtt_agent_task.c @@ -287,6 +287,7 @@ static BaseType_t prvSocketConnect( NetworkContext_t * pxNetworkContext ) ServerInfo_t xServerInfo = { 0 }; #ifdef democonfigUSE_AWS_IOT_CORE_BROKER + /* ALPN protocols must be a NULL-terminated list of strings. Therefore, * the first entry will contain the actual ALPN protocol string while the * second entry must remain NULL. */