From 2c89170b7e343b60e517467a14d4a03c2941d9af Mon Sep 17 00:00:00 2001 From: diogosilva1 Date: Wed, 2 Aug 2023 14:57:20 +0000 Subject: [PATCH 1/7] Add SSL config and File Storage methods --- source/cellular_common_api.c | 14 +++++ source/include/cellular_api.h | 72 ++++++++++++++++++++++ source/include/cellular_types.h | 6 +- source/include/common/cellular_common.h | 11 ++++ test/unit-test/cellular_common_api_utest.c | 72 ++++++++++++++++++++++ 5 files changed, 173 insertions(+), 2 deletions(-) diff --git a/source/cellular_common_api.c b/source/cellular_common_api.c index 43a67bf0..4fd25ac6 100644 --- a/source/cellular_common_api.c +++ b/source/cellular_common_api.c @@ -112,6 +112,20 @@ static CellularError_t _socketSetSockOptLevelTransport( CellularSocketOption_t o cellularStatus = CELLULAR_INTERNAL_FAILURE; } } + else if( option == CELLULAR_SOCKET_OPTION_SSL_CONTEXT_ID ) + { + if( ( socketHandle->socketState == SOCKETSTATE_ALLOCATED ) && ( optionValueLength == sizeof( uint8_t ) ) ) + { + socketHandle->sslConfig.sslContextId = *pOptionValue; + socketHandle->sslConfig.useSsl = 1; + } + else + { + LogError( ( "Cellular_SocketSetSockOpt: Cannot change the sslContextID in this state %d or length %d is invalid.", + socketHandle->socketState, optionValueLength ) ); + cellularStatus = CELLULAR_INTERNAL_FAILURE; + } + } else if( option == CELLULAR_SOCKET_OPTION_SET_LOCAL_PORT ) { if( ( socketHandle->socketState == SOCKETSTATE_ALLOCATED ) && ( optionValueLength == sizeof( uint16_t ) ) ) diff --git a/source/include/cellular_api.h b/source/include/cellular_api.h index ddd3c17c..6a6e6cee 100644 --- a/source/include/cellular_api.h +++ b/source/include/cellular_api.h @@ -639,6 +639,78 @@ CellularError_t Cellular_SocketRegisterClosedCallback( CellularHandle_t cellular CellularSocketClosedCallback_t closedCallback, void * pCallbackContext ); +/** + * @brief Configure parameters of an SSL Context. + * + * @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init. + * @param[in] sslContextId The SSL context ID. + * @param[in] sslConfigurationParameter The SSL parameter to be configured. + * @param[in] inputArg The value to be passed to the SSL parameter. + * + * @return CELLULAR_SUCCESS if the operation is successful, otherwise an error + * code indicating the cause of the error. + */ +CellularError_t Cellular_ConfigureSSLContext(CellularHandle_t cellularHandle, + uint8_t sslContextId, + const char* sslConfigurationParameter, + const char* inputArg); + +/** + * @brief Delete a File in the Storage. + * + * @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init. + * @param[in] filename Name of the file to be deleted. + * + * @return CELLULAR_SUCCESS if the operation is successful, otherwise an error + * code indicating the cause of the error. + */ +CellularError_t Cellular_DeleteFileFromStorage(CellularHandle_t cellularHandle, + const char* filename); + +/** + * @brief Lists the information of a single file. + * + * @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init. + * @param[in] filename Name of the file to be listed. + * + * @return CELLULAR_SUCCESS if the operation is successful, otherwise an error + * code indicating the cause of the error. + */ +CellularError_t Cellular_VerifyFileFromStorage(CellularHandle_t cellularHandle, + const char* filename); + +/** + * @brief Upload a File into the Storage. + * + * @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init. + * @param[in] filename Name of the file to be uploaded. + * @param[in] fileContent Content of the file to be uploaded. + * @param[in] fileSize Size of the file to be uploaded. + * @param[out] pSentDataLength Out parameter to provide the length of the actual + * data sent. Note that it may be less than the dataLength in case complete data + * could not be sent. + * + * @return CELLULAR_SUCCESS if the operation is successful, otherwise an error + * code indicating the cause of the error. + */ +CellularError_t Cellular_UploadFileToStorage(CellularHandle_t cellularHandle, + const char* filename, + const char* fileContent, + uint32_t fileSize, + uint32_t* pSentDataLength); + +/** + * @brief Gets the space information of the specified storage. + * + * @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init. + * @param[in] storage_pattern Storage pattern to be listed. + * + * @return CELLULAR_SUCCESS if the operation is successful, otherwise an error + * code indicating the cause of the error. + */ +CellularError_t Cellular_GetSpaceInformationOfTheStorage(CellularHandle_t cellularHandle, + const char* storage_pattern); + /* *INDENT-OFF* */ #ifdef __cplusplus } diff --git a/source/include/cellular_types.h b/source/include/cellular_types.h index 53eeba61..462c3bea 100644 --- a/source/include/cellular_types.h +++ b/source/include/cellular_types.h @@ -313,8 +313,9 @@ typedef enum CellularIPAddressType */ typedef enum CellularSocketOptionLevel { - CELLULAR_SOCKET_OPTION_LEVEL_IP, /**< IP layer options. */ - CELLULAR_SOCKET_OPTION_LEVEL_TRANSPORT /**< Transport (TCP/UDP) layer options. */ + CELLULAR_SOCKET_OPTION_LEVEL_IP, /**< IP layer options. */ + CELLULAR_SOCKET_OPTION_LEVEL_TRANSPORT, /**< Transport (TCP/UDP) layer options. */ + CELLULAR_SOCKET_OPTION_LEVEL_SECURE /**< Secured socket connection. */ } CellularSocketOptionLevel_t; /** @@ -327,6 +328,7 @@ typedef enum CellularSocketOption CELLULAR_SOCKET_OPTION_SEND_TIMEOUT, /**< Set send timeout (in milliseconds). */ CELLULAR_SOCKET_OPTION_RECV_TIMEOUT, /**< Set receive timeout (in milliseconds). */ CELLULAR_SOCKET_OPTION_PDN_CONTEXT_ID, /**< Set PDN Context ID to use for the socket. */ + CELLULAR_SOCKET_OPTION_SSL_CONTEXT_ID, /**< Set SSL Context ID to use for the socket. */ CELLULAR_SOCKET_OPTION_SET_LOCAL_PORT /**< Set local port. */ } CellularSocketOption_t; diff --git a/source/include/common/cellular_common.h b/source/include/common/cellular_common.h index aecc5c5e..acb37dce 100644 --- a/source/include/common/cellular_common.h +++ b/source/include/common/cellular_common.h @@ -115,6 +115,16 @@ typedef enum CellularSocketState SOCKETSTATE_DISCONNECTED /**< Socket is disconnected by remote peer or due to network error. */ } CellularSocketState_t; +/** + * @ingroup cellular_common_datatypes_paramstructs + * @brief the ssl mapping structure. + */ +typedef struct CellularSocketSslConfig +{ + uint8_t useSsl; + uint8_t sslContextId; +} CellularSocketSslConfig_t; + /** * @ingroup cellular_common_datatypes_paramstructs * @brief Parameters involved in sending/receiving data through sockets. @@ -123,6 +133,7 @@ typedef struct CellularSocketContext { uint8_t contextId; /**< PDN context ID on which this socket exists. */ uint32_t socketId; /**< Socket ID of this socket. */ + CellularSocketSslConfig_t sslConfig; /**< SSL context ID on which this socket exists. */ CellularSocketState_t socketState; /**< State of the socket, Allocated, Free etc. */ CellularSocketType_t socketType; /**< Type of socket, DGRAM or STREAM. */ CellularSocketDomain_t socketDomain; /**< Socket domain, IPV4 or V6. */ diff --git a/test/unit-test/cellular_common_api_utest.c b/test/unit-test/cellular_common_api_utest.c index 787afa06..8bfdc143 100644 --- a/test/unit-test/cellular_common_api_utest.c +++ b/test/unit-test/cellular_common_api_utest.c @@ -841,6 +841,78 @@ void test_Cellular_CommonSocketSetSockOpt_Option_PdnContextId_WrongSize_Failure_ TEST_ASSERT_EQUAL( CELLULAR_INTERNAL_FAILURE, cellularStatus ); } +/** + * @brief Test that option ssl context id happy path case for Cellular_CommonSocketSetSockOpt. + */ +void test_Cellular_CommonSocketSetSockOpt_Option_SslContextId_Happy_Path( void ) +{ + CellularError_t cellularStatus = CELLULAR_SUCCESS; + CellularContext_t context; + + memset( &context, 0, sizeof( CellularContext_t ) ); + struct CellularSocketContext socketHandle; + uint32_t optionValue = 0; + + socketHandle.socketState = SOCKETSTATE_ALLOCATED; + + _Cellular_CheckLibraryStatus_IgnoreAndReturn( CELLULAR_SUCCESS ); + + cellularStatus = Cellular_CommonSocketSetSockOpt( &context, &socketHandle, + CELLULAR_SOCKET_OPTION_LEVEL_SECURE, + CELLULAR_SOCKET_OPTION_SSL_CONTEXT_ID, + ( const uint8_t * ) &optionValue, sizeof( uint8_t ) ); + + TEST_ASSERT_EQUAL( CELLULAR_SUCCESS, cellularStatus ); +} + +/** + * @brief Test that option ssl context id failure path case for Cellular_CommonSocketSetSockOpt. + */ +void test_Cellular_CommonSocketSetSockOpt_Option_SslContextId_Failure_Path( void ) +{ + CellularError_t cellularStatus = CELLULAR_SUCCESS; + CellularContext_t context; + + memset( &context, 0, sizeof( CellularContext_t ) ); + struct CellularSocketContext socketHandle; + uint32_t optionValue = 0; + + socketHandle.socketState = SOCKETSTATE_CONNECTING; + + _Cellular_CheckLibraryStatus_IgnoreAndReturn( CELLULAR_SUCCESS ); + + cellularStatus = Cellular_CommonSocketSetSockOpt( &context, &socketHandle, + CELLULAR_SOCKET_OPTION_LEVEL_SECURE, + CELLULAR_SOCKET_OPTION_SSL_CONTEXT_ID, + ( const uint8_t * ) &optionValue, sizeof( uint8_t ) ); + + TEST_ASSERT_EQUAL( CELLULAR_INTERNAL_FAILURE, cellularStatus ); +} + +/** + * @brief Test that option ssl context id failure path case with wrong size for Cellular_CommonSocketSetSockOpt. + */ +void test_Cellular_CommonSocketSetSockOpt_Option_SslContextId_WrongSize_Failure_Path( void ) +{ + CellularError_t cellularStatus = CELLULAR_SUCCESS; + CellularContext_t context; + + memset( &context, 0, sizeof( CellularContext_t ) ); + struct CellularSocketContext socketHandle; + uint32_t optionValue = 0; + + socketHandle.socketState = SOCKETSTATE_ALLOCATED; + + _Cellular_CheckLibraryStatus_IgnoreAndReturn( CELLULAR_SUCCESS ); + + cellularStatus = Cellular_CommonSocketSetSockOpt( &context, &socketHandle, + CELLULAR_SOCKET_OPTION_LEVEL_SECURE, + CELLULAR_SOCKET_OPTION_SSL_CONTEXT_ID, + ( const uint8_t * ) &optionValue, sizeof( uint32_t ) ); + + TEST_ASSERT_EQUAL( CELLULAR_INTERNAL_FAILURE, cellularStatus ); +} + /** * @brief Test that option pdn context id failure path case for Cellular_CommonSocketSetSockOpt. */ From f50fe222d674ff0a72ce0579d504fe777266305a Mon Sep 17 00:00:00 2001 From: diogosilva1 Date: Fri, 4 Aug 2023 15:14:41 +0000 Subject: [PATCH 2/7] Add option for useSsl field --- source/cellular_common_api.c | 14 ++++- source/include/cellular_types.h | 1 + test/unit-test/cellular_common_api_utest.c | 72 ++++++++++++++++++++++ 3 files changed, 86 insertions(+), 1 deletion(-) diff --git a/source/cellular_common_api.c b/source/cellular_common_api.c index 4fd25ac6..378d9ebb 100644 --- a/source/cellular_common_api.c +++ b/source/cellular_common_api.c @@ -117,7 +117,6 @@ static CellularError_t _socketSetSockOptLevelTransport( CellularSocketOption_t o if( ( socketHandle->socketState == SOCKETSTATE_ALLOCATED ) && ( optionValueLength == sizeof( uint8_t ) ) ) { socketHandle->sslConfig.sslContextId = *pOptionValue; - socketHandle->sslConfig.useSsl = 1; } else { @@ -126,6 +125,19 @@ static CellularError_t _socketSetSockOptLevelTransport( CellularSocketOption_t o cellularStatus = CELLULAR_INTERNAL_FAILURE; } } + else if( option == CELLULAR_SOCKET_OPTION_SSL_USAGE ) + { + if( ( socketHandle->socketState == SOCKETSTATE_ALLOCATED ) && ( optionValueLength == sizeof( uint8_t ) ) ) + { + socketHandle->sslConfig.useSsl = *pOptionValue; + } + else + { + LogError( ( "Cellular_SocketSetSockOpt: Cannot change the useSsl in this state %d or length %d is invalid.", + socketHandle->socketState, optionValueLength ) ); + cellularStatus = CELLULAR_INTERNAL_FAILURE; + } + } else if( option == CELLULAR_SOCKET_OPTION_SET_LOCAL_PORT ) { if( ( socketHandle->socketState == SOCKETSTATE_ALLOCATED ) && ( optionValueLength == sizeof( uint16_t ) ) ) diff --git a/source/include/cellular_types.h b/source/include/cellular_types.h index 462c3bea..a458b1f1 100644 --- a/source/include/cellular_types.h +++ b/source/include/cellular_types.h @@ -329,6 +329,7 @@ typedef enum CellularSocketOption CELLULAR_SOCKET_OPTION_RECV_TIMEOUT, /**< Set receive timeout (in milliseconds). */ CELLULAR_SOCKET_OPTION_PDN_CONTEXT_ID, /**< Set PDN Context ID to use for the socket. */ CELLULAR_SOCKET_OPTION_SSL_CONTEXT_ID, /**< Set SSL Context ID to use for the socket. */ + CELLULAR_SOCKET_OPTION_SSL_USAGE, /**< Set SSL or non SSL to use for the socket. */ CELLULAR_SOCKET_OPTION_SET_LOCAL_PORT /**< Set local port. */ } CellularSocketOption_t; diff --git a/test/unit-test/cellular_common_api_utest.c b/test/unit-test/cellular_common_api_utest.c index 8bfdc143..4361a916 100644 --- a/test/unit-test/cellular_common_api_utest.c +++ b/test/unit-test/cellular_common_api_utest.c @@ -913,6 +913,78 @@ void test_Cellular_CommonSocketSetSockOpt_Option_SslContextId_WrongSize_Failure_ TEST_ASSERT_EQUAL( CELLULAR_INTERNAL_FAILURE, cellularStatus ); } +/** + * @brief Test that option ssl context id happy path case for Cellular_CommonSocketSetSockOpt. + */ +void test_Cellular_CommonSocketSetSockOpt_Option_UseSsl_Happy_Path( void ) +{ + CellularError_t cellularStatus = CELLULAR_SUCCESS; + CellularContext_t context; + + memset( &context, 0, sizeof( CellularContext_t ) ); + struct CellularSocketContext socketHandle; + uint32_t optionValue = 0; + + socketHandle.socketState = SOCKETSTATE_ALLOCATED; + + _Cellular_CheckLibraryStatus_IgnoreAndReturn( CELLULAR_SUCCESS ); + + cellularStatus = Cellular_CommonSocketSetSockOpt( &context, &socketHandle, + CELLULAR_SOCKET_OPTION_LEVEL_SECURE, + CELLULAR_SOCKET_OPTION_SSL_USAGE, + ( const uint8_t * ) &optionValue, sizeof( uint8_t ) ); + + TEST_ASSERT_EQUAL( CELLULAR_SUCCESS, cellularStatus ); +} + +/** + * @brief Test that option ssl context id failure path case for Cellular_CommonSocketSetSockOpt. + */ +void test_Cellular_CommonSocketSetSockOpt_Option_UseSsl_Failure_Path( void ) +{ + CellularError_t cellularStatus = CELLULAR_SUCCESS; + CellularContext_t context; + + memset( &context, 0, sizeof( CellularContext_t ) ); + struct CellularSocketContext socketHandle; + uint32_t optionValue = 0; + + socketHandle.socketState = SOCKETSTATE_CONNECTING; + + _Cellular_CheckLibraryStatus_IgnoreAndReturn( CELLULAR_SUCCESS ); + + cellularStatus = Cellular_CommonSocketSetSockOpt( &context, &socketHandle, + CELLULAR_SOCKET_OPTION_LEVEL_SECURE, + CELLULAR_SOCKET_OPTION_SSL_USAGE, + ( const uint8_t * ) &optionValue, sizeof( uint8_t ) ); + + TEST_ASSERT_EQUAL( CELLULAR_INTERNAL_FAILURE, cellularStatus ); +} + +/** + * @brief Test that option ssl context id failure path case with wrong size for Cellular_CommonSocketSetSockOpt. + */ +void test_Cellular_CommonSocketSetSockOpt_Option_UseSsl_WrongSize_Failure_Path( void ) +{ + CellularError_t cellularStatus = CELLULAR_SUCCESS; + CellularContext_t context; + + memset( &context, 0, sizeof( CellularContext_t ) ); + struct CellularSocketContext socketHandle; + uint32_t optionValue = 0; + + socketHandle.socketState = SOCKETSTATE_ALLOCATED; + + _Cellular_CheckLibraryStatus_IgnoreAndReturn( CELLULAR_SUCCESS ); + + cellularStatus = Cellular_CommonSocketSetSockOpt( &context, &socketHandle, + CELLULAR_SOCKET_OPTION_LEVEL_SECURE, + CELLULAR_SOCKET_OPTION_SSL_USAGE, + ( const uint8_t * ) &optionValue, sizeof( uint32_t ) ); + + TEST_ASSERT_EQUAL( CELLULAR_INTERNAL_FAILURE, cellularStatus ); +} + /** * @brief Test that option pdn context id failure path case for Cellular_CommonSocketSetSockOpt. */ From 63bc0f8ab3d5f8817574f12f829ef2859ca957dc Mon Sep 17 00:00:00 2001 From: diogosilva1 Date: Mon, 28 Aug 2023 16:18:00 +0000 Subject: [PATCH 3/7] Remove unused function --- source/include/cellular_api.h | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/source/include/cellular_api.h b/source/include/cellular_api.h index 6a6e6cee..236460f8 100644 --- a/source/include/cellular_api.h +++ b/source/include/cellular_api.h @@ -698,18 +698,7 @@ CellularError_t Cellular_UploadFileToStorage(CellularHandle_t cellularHandle, const char* fileContent, uint32_t fileSize, uint32_t* pSentDataLength); - -/** - * @brief Gets the space information of the specified storage. - * - * @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init. - * @param[in] storage_pattern Storage pattern to be listed. - * - * @return CELLULAR_SUCCESS if the operation is successful, otherwise an error - * code indicating the cause of the error. - */ -CellularError_t Cellular_GetSpaceInformationOfTheStorage(CellularHandle_t cellularHandle, - const char* storage_pattern); + /* *INDENT-OFF* */ #ifdef __cplusplus From f36d3e71bc1f2e5af7c77b026792847be6974e36 Mon Sep 17 00:00:00 2001 From: diogosilva1 Date: Tue, 29 Aug 2023 17:26:33 +0000 Subject: [PATCH 4/7] Address peer review comments --- source/include/cellular_api.h | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/source/include/cellular_api.h b/source/include/cellular_api.h index 236460f8..1326bcd7 100644 --- a/source/include/cellular_api.h +++ b/source/include/cellular_api.h @@ -655,30 +655,6 @@ CellularError_t Cellular_ConfigureSSLContext(CellularHandle_t cellularHandle, const char* sslConfigurationParameter, const char* inputArg); -/** - * @brief Delete a File in the Storage. - * - * @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init. - * @param[in] filename Name of the file to be deleted. - * - * @return CELLULAR_SUCCESS if the operation is successful, otherwise an error - * code indicating the cause of the error. - */ -CellularError_t Cellular_DeleteFileFromStorage(CellularHandle_t cellularHandle, - const char* filename); - -/** - * @brief Lists the information of a single file. - * - * @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init. - * @param[in] filename Name of the file to be listed. - * - * @return CELLULAR_SUCCESS if the operation is successful, otherwise an error - * code indicating the cause of the error. - */ -CellularError_t Cellular_VerifyFileFromStorage(CellularHandle_t cellularHandle, - const char* filename); - /** * @brief Upload a File into the Storage. * From c3a6916892b82fd942a81b1143316e5b49eb25c8 Mon Sep 17 00:00:00 2001 From: diogosilva1 Date: Tue, 29 Aug 2023 17:40:26 +0000 Subject: [PATCH 5/7] Address formatting rules --- source/include/cellular_api.h | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/source/include/cellular_api.h b/source/include/cellular_api.h index 1326bcd7..82e3e5f6 100644 --- a/source/include/cellular_api.h +++ b/source/include/cellular_api.h @@ -650,10 +650,10 @@ CellularError_t Cellular_SocketRegisterClosedCallback( CellularHandle_t cellular * @return CELLULAR_SUCCESS if the operation is successful, otherwise an error * code indicating the cause of the error. */ -CellularError_t Cellular_ConfigureSSLContext(CellularHandle_t cellularHandle, - uint8_t sslContextId, - const char* sslConfigurationParameter, - const char* inputArg); +CellularError_t Cellular_ConfigureSSLContext( CellularHandle_t cellularHandle, + uint8_t sslContextId, + const char* sslConfigurationParameter, + const char* inputArg ); /** * @brief Upload a File into the Storage. @@ -669,12 +669,11 @@ CellularError_t Cellular_ConfigureSSLContext(CellularHandle_t cellularHandle, * @return CELLULAR_SUCCESS if the operation is successful, otherwise an error * code indicating the cause of the error. */ -CellularError_t Cellular_UploadFileToStorage(CellularHandle_t cellularHandle, - const char* filename, - const char* fileContent, - uint32_t fileSize, - uint32_t* pSentDataLength); - +CellularError_t Cellular_UploadFileToStorage( CellularHandle_t cellularHandle, + const char* filename, + const char* fileContent, + uint32_t fileSize, + uint32_t* pSentDataLength ); /* *INDENT-OFF* */ #ifdef __cplusplus From 12450e4ea4cfb6ebae263a401382e3c5af316ff7 Mon Sep 17 00:00:00 2001 From: Ching-Hsin Lee Date: Thu, 21 Sep 2023 18:38:13 +0800 Subject: [PATCH 6/7] Move the file upload and configure ssl API to port --- source/cellular_common_api.c | 37 +----- source/include/cellular_api.h | 36 ------ source/include/cellular_types.h | 6 +- source/include/common/cellular_common.h | 11 -- test/unit-test/cellular_common_api_utest.c | 144 --------------------- 5 files changed, 9 insertions(+), 225 deletions(-) diff --git a/source/cellular_common_api.c b/source/cellular_common_api.c index 378d9ebb..2b131bc4 100644 --- a/source/cellular_common_api.c +++ b/source/cellular_common_api.c @@ -112,32 +112,6 @@ static CellularError_t _socketSetSockOptLevelTransport( CellularSocketOption_t o cellularStatus = CELLULAR_INTERNAL_FAILURE; } } - else if( option == CELLULAR_SOCKET_OPTION_SSL_CONTEXT_ID ) - { - if( ( socketHandle->socketState == SOCKETSTATE_ALLOCATED ) && ( optionValueLength == sizeof( uint8_t ) ) ) - { - socketHandle->sslConfig.sslContextId = *pOptionValue; - } - else - { - LogError( ( "Cellular_SocketSetSockOpt: Cannot change the sslContextID in this state %d or length %d is invalid.", - socketHandle->socketState, optionValueLength ) ); - cellularStatus = CELLULAR_INTERNAL_FAILURE; - } - } - else if( option == CELLULAR_SOCKET_OPTION_SSL_USAGE ) - { - if( ( socketHandle->socketState == SOCKETSTATE_ALLOCATED ) && ( optionValueLength == sizeof( uint8_t ) ) ) - { - socketHandle->sslConfig.useSsl = *pOptionValue; - } - else - { - LogError( ( "Cellular_SocketSetSockOpt: Cannot change the useSsl in this state %d or length %d is invalid.", - socketHandle->socketState, optionValueLength ) ); - cellularStatus = CELLULAR_INTERNAL_FAILURE; - } - } else if( option == CELLULAR_SOCKET_OPTION_SET_LOCAL_PORT ) { if( ( socketHandle->socketState == SOCKETSTATE_ALLOCATED ) && ( optionValueLength == sizeof( uint16_t ) ) ) @@ -464,14 +438,15 @@ CellularError_t Cellular_CommonSocketSetSockOpt( CellularHandle_t cellularHandle } else { - if( optionLevel == CELLULAR_SOCKET_OPTION_LEVEL_IP ) + if( optionLevel == CELLULAR_SOCKET_OPTION_LEVEL_TRANSPORT ) { - LogError( ( "Cellular_SocketSetSockOpt: Option not supported" ) ); - cellularStatus = CELLULAR_UNSUPPORTED; + cellularStatus = _socketSetSockOptLevelTransport( option, socketHandle, pOptionValue, optionValueLength ); } - else /* optionLevel CELLULAR_SOCKET_OPTION_LEVEL_TRANSPORT. */ + else { - cellularStatus = _socketSetSockOptLevelTransport( option, socketHandle, pOptionValue, optionValueLength ); + /* Other socket option levels are not supported in common layer. Modem ports + * can use their own implementation for these options. */ + cellularStatus = CELLULAR_UNSUPPORTED; } } diff --git a/source/include/cellular_api.h b/source/include/cellular_api.h index 82e3e5f6..ddd3c17c 100644 --- a/source/include/cellular_api.h +++ b/source/include/cellular_api.h @@ -639,42 +639,6 @@ CellularError_t Cellular_SocketRegisterClosedCallback( CellularHandle_t cellular CellularSocketClosedCallback_t closedCallback, void * pCallbackContext ); -/** - * @brief Configure parameters of an SSL Context. - * - * @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init. - * @param[in] sslContextId The SSL context ID. - * @param[in] sslConfigurationParameter The SSL parameter to be configured. - * @param[in] inputArg The value to be passed to the SSL parameter. - * - * @return CELLULAR_SUCCESS if the operation is successful, otherwise an error - * code indicating the cause of the error. - */ -CellularError_t Cellular_ConfigureSSLContext( CellularHandle_t cellularHandle, - uint8_t sslContextId, - const char* sslConfigurationParameter, - const char* inputArg ); - -/** - * @brief Upload a File into the Storage. - * - * @param[in] cellularHandle The opaque cellular context pointer created by Cellular_Init. - * @param[in] filename Name of the file to be uploaded. - * @param[in] fileContent Content of the file to be uploaded. - * @param[in] fileSize Size of the file to be uploaded. - * @param[out] pSentDataLength Out parameter to provide the length of the actual - * data sent. Note that it may be less than the dataLength in case complete data - * could not be sent. - * - * @return CELLULAR_SUCCESS if the operation is successful, otherwise an error - * code indicating the cause of the error. - */ -CellularError_t Cellular_UploadFileToStorage( CellularHandle_t cellularHandle, - const char* filename, - const char* fileContent, - uint32_t fileSize, - uint32_t* pSentDataLength ); - /* *INDENT-OFF* */ #ifdef __cplusplus } diff --git a/source/include/cellular_types.h b/source/include/cellular_types.h index 44d58968..a26691a9 100644 --- a/source/include/cellular_types.h +++ b/source/include/cellular_types.h @@ -315,7 +315,7 @@ typedef enum CellularSocketOptionLevel { CELLULAR_SOCKET_OPTION_LEVEL_IP, /**< IP layer options. */ CELLULAR_SOCKET_OPTION_LEVEL_TRANSPORT, /**< Transport (TCP/UDP) layer options. */ - CELLULAR_SOCKET_OPTION_LEVEL_SECURE /**< Secured socket connection. */ + CELLULAR_SOCKET_OPTION_LEVEL_SECURE /**< Secure sockets layer options. */ } CellularSocketOptionLevel_t; /** @@ -328,8 +328,8 @@ typedef enum CellularSocketOption CELLULAR_SOCKET_OPTION_SEND_TIMEOUT, /**< Set send timeout (in milliseconds). */ CELLULAR_SOCKET_OPTION_RECV_TIMEOUT, /**< Set receive timeout (in milliseconds). */ CELLULAR_SOCKET_OPTION_PDN_CONTEXT_ID, /**< Set PDN Context ID to use for the socket. */ - CELLULAR_SOCKET_OPTION_SSL_CONTEXT_ID, /**< Set SSL Context ID to use for the socket. */ - CELLULAR_SOCKET_OPTION_SSL_USAGE, /**< Set SSL or non SSL to use for the socket. */ + CELLULAR_SOCKET_OPTION_SSL_CONTEXT_ID, /**< Set secure sockets layer context ID to use for the socket. */ + CELLULAR_SOCKET_OPTION_SSL_USAGE, /**< Set secure sockets layer usage for the socket. */ CELLULAR_SOCKET_OPTION_SET_LOCAL_PORT /**< Set local port. */ } CellularSocketOption_t; diff --git a/source/include/common/cellular_common.h b/source/include/common/cellular_common.h index 2611ef74..3bd8ac49 100644 --- a/source/include/common/cellular_common.h +++ b/source/include/common/cellular_common.h @@ -115,16 +115,6 @@ typedef enum CellularSocketState SOCKETSTATE_DISCONNECTED /**< Socket is disconnected by remote peer or due to network error. */ } CellularSocketState_t; -/** - * @ingroup cellular_common_datatypes_paramstructs - * @brief the ssl mapping structure. - */ -typedef struct CellularSocketSslConfig -{ - uint8_t useSsl; - uint8_t sslContextId; -} CellularSocketSslConfig_t; - /** * @ingroup cellular_common_datatypes_paramstructs * @brief Parameters involved in sending/receiving data through sockets. @@ -133,7 +123,6 @@ typedef struct CellularSocketContext { uint8_t contextId; /**< PDN context ID on which this socket exists. */ uint32_t socketId; /**< Socket ID of this socket. */ - CellularSocketSslConfig_t sslConfig; /**< SSL context ID on which this socket exists. */ CellularSocketState_t socketState; /**< State of the socket, Allocated, Free etc. */ CellularSocketType_t socketType; /**< Type of socket, DGRAM or STREAM. */ CellularSocketDomain_t socketDomain; /**< Socket domain, IPV4 or V6. */ diff --git a/test/unit-test/cellular_common_api_utest.c b/test/unit-test/cellular_common_api_utest.c index 4361a916..787afa06 100644 --- a/test/unit-test/cellular_common_api_utest.c +++ b/test/unit-test/cellular_common_api_utest.c @@ -841,150 +841,6 @@ void test_Cellular_CommonSocketSetSockOpt_Option_PdnContextId_WrongSize_Failure_ TEST_ASSERT_EQUAL( CELLULAR_INTERNAL_FAILURE, cellularStatus ); } -/** - * @brief Test that option ssl context id happy path case for Cellular_CommonSocketSetSockOpt. - */ -void test_Cellular_CommonSocketSetSockOpt_Option_SslContextId_Happy_Path( void ) -{ - CellularError_t cellularStatus = CELLULAR_SUCCESS; - CellularContext_t context; - - memset( &context, 0, sizeof( CellularContext_t ) ); - struct CellularSocketContext socketHandle; - uint32_t optionValue = 0; - - socketHandle.socketState = SOCKETSTATE_ALLOCATED; - - _Cellular_CheckLibraryStatus_IgnoreAndReturn( CELLULAR_SUCCESS ); - - cellularStatus = Cellular_CommonSocketSetSockOpt( &context, &socketHandle, - CELLULAR_SOCKET_OPTION_LEVEL_SECURE, - CELLULAR_SOCKET_OPTION_SSL_CONTEXT_ID, - ( const uint8_t * ) &optionValue, sizeof( uint8_t ) ); - - TEST_ASSERT_EQUAL( CELLULAR_SUCCESS, cellularStatus ); -} - -/** - * @brief Test that option ssl context id failure path case for Cellular_CommonSocketSetSockOpt. - */ -void test_Cellular_CommonSocketSetSockOpt_Option_SslContextId_Failure_Path( void ) -{ - CellularError_t cellularStatus = CELLULAR_SUCCESS; - CellularContext_t context; - - memset( &context, 0, sizeof( CellularContext_t ) ); - struct CellularSocketContext socketHandle; - uint32_t optionValue = 0; - - socketHandle.socketState = SOCKETSTATE_CONNECTING; - - _Cellular_CheckLibraryStatus_IgnoreAndReturn( CELLULAR_SUCCESS ); - - cellularStatus = Cellular_CommonSocketSetSockOpt( &context, &socketHandle, - CELLULAR_SOCKET_OPTION_LEVEL_SECURE, - CELLULAR_SOCKET_OPTION_SSL_CONTEXT_ID, - ( const uint8_t * ) &optionValue, sizeof( uint8_t ) ); - - TEST_ASSERT_EQUAL( CELLULAR_INTERNAL_FAILURE, cellularStatus ); -} - -/** - * @brief Test that option ssl context id failure path case with wrong size for Cellular_CommonSocketSetSockOpt. - */ -void test_Cellular_CommonSocketSetSockOpt_Option_SslContextId_WrongSize_Failure_Path( void ) -{ - CellularError_t cellularStatus = CELLULAR_SUCCESS; - CellularContext_t context; - - memset( &context, 0, sizeof( CellularContext_t ) ); - struct CellularSocketContext socketHandle; - uint32_t optionValue = 0; - - socketHandle.socketState = SOCKETSTATE_ALLOCATED; - - _Cellular_CheckLibraryStatus_IgnoreAndReturn( CELLULAR_SUCCESS ); - - cellularStatus = Cellular_CommonSocketSetSockOpt( &context, &socketHandle, - CELLULAR_SOCKET_OPTION_LEVEL_SECURE, - CELLULAR_SOCKET_OPTION_SSL_CONTEXT_ID, - ( const uint8_t * ) &optionValue, sizeof( uint32_t ) ); - - TEST_ASSERT_EQUAL( CELLULAR_INTERNAL_FAILURE, cellularStatus ); -} - -/** - * @brief Test that option ssl context id happy path case for Cellular_CommonSocketSetSockOpt. - */ -void test_Cellular_CommonSocketSetSockOpt_Option_UseSsl_Happy_Path( void ) -{ - CellularError_t cellularStatus = CELLULAR_SUCCESS; - CellularContext_t context; - - memset( &context, 0, sizeof( CellularContext_t ) ); - struct CellularSocketContext socketHandle; - uint32_t optionValue = 0; - - socketHandle.socketState = SOCKETSTATE_ALLOCATED; - - _Cellular_CheckLibraryStatus_IgnoreAndReturn( CELLULAR_SUCCESS ); - - cellularStatus = Cellular_CommonSocketSetSockOpt( &context, &socketHandle, - CELLULAR_SOCKET_OPTION_LEVEL_SECURE, - CELLULAR_SOCKET_OPTION_SSL_USAGE, - ( const uint8_t * ) &optionValue, sizeof( uint8_t ) ); - - TEST_ASSERT_EQUAL( CELLULAR_SUCCESS, cellularStatus ); -} - -/** - * @brief Test that option ssl context id failure path case for Cellular_CommonSocketSetSockOpt. - */ -void test_Cellular_CommonSocketSetSockOpt_Option_UseSsl_Failure_Path( void ) -{ - CellularError_t cellularStatus = CELLULAR_SUCCESS; - CellularContext_t context; - - memset( &context, 0, sizeof( CellularContext_t ) ); - struct CellularSocketContext socketHandle; - uint32_t optionValue = 0; - - socketHandle.socketState = SOCKETSTATE_CONNECTING; - - _Cellular_CheckLibraryStatus_IgnoreAndReturn( CELLULAR_SUCCESS ); - - cellularStatus = Cellular_CommonSocketSetSockOpt( &context, &socketHandle, - CELLULAR_SOCKET_OPTION_LEVEL_SECURE, - CELLULAR_SOCKET_OPTION_SSL_USAGE, - ( const uint8_t * ) &optionValue, sizeof( uint8_t ) ); - - TEST_ASSERT_EQUAL( CELLULAR_INTERNAL_FAILURE, cellularStatus ); -} - -/** - * @brief Test that option ssl context id failure path case with wrong size for Cellular_CommonSocketSetSockOpt. - */ -void test_Cellular_CommonSocketSetSockOpt_Option_UseSsl_WrongSize_Failure_Path( void ) -{ - CellularError_t cellularStatus = CELLULAR_SUCCESS; - CellularContext_t context; - - memset( &context, 0, sizeof( CellularContext_t ) ); - struct CellularSocketContext socketHandle; - uint32_t optionValue = 0; - - socketHandle.socketState = SOCKETSTATE_ALLOCATED; - - _Cellular_CheckLibraryStatus_IgnoreAndReturn( CELLULAR_SUCCESS ); - - cellularStatus = Cellular_CommonSocketSetSockOpt( &context, &socketHandle, - CELLULAR_SOCKET_OPTION_LEVEL_SECURE, - CELLULAR_SOCKET_OPTION_SSL_USAGE, - ( const uint8_t * ) &optionValue, sizeof( uint32_t ) ); - - TEST_ASSERT_EQUAL( CELLULAR_INTERNAL_FAILURE, cellularStatus ); -} - /** * @brief Test that option pdn context id failure path case for Cellular_CommonSocketSetSockOpt. */ From b340fe92f8abc8edd4f639102396b5e70b34d3da Mon Sep 17 00:00:00 2001 From: Ching-Hsin Lee Date: Thu, 21 Sep 2023 22:51:41 +0800 Subject: [PATCH 7/7] Update for format --- source/include/cellular_types.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/include/cellular_types.h b/source/include/cellular_types.h index a26691a9..89dbca7a 100644 --- a/source/include/cellular_types.h +++ b/source/include/cellular_types.h @@ -315,7 +315,7 @@ typedef enum CellularSocketOptionLevel { CELLULAR_SOCKET_OPTION_LEVEL_IP, /**< IP layer options. */ CELLULAR_SOCKET_OPTION_LEVEL_TRANSPORT, /**< Transport (TCP/UDP) layer options. */ - CELLULAR_SOCKET_OPTION_LEVEL_SECURE /**< Secure sockets layer options. */ + CELLULAR_SOCKET_OPTION_LEVEL_SECURE /**< Secure sockets layer options. */ } CellularSocketOptionLevel_t; /**