Skip to content

Commit

Permalink
Merge branch 'dev/v202210.01-lts-rx-1.1.1' into 'main'
Browse files Browse the repository at this point in the history
Fix mbedtls_bio for case 0

See merge request products/common/rtos/amazon-freertos/lts/iot-reference-rx!138
  • Loading branch information
KazukiMochizuki926 committed Nov 30, 2023
2 parents 7dc2a56 + 1624c13 commit bff68b7
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,30 @@
*/

/**
* @file mbedtls_bio_freertos_plus_tcp.c
* @brief Implements mbed TLS platform send/receive functions for freertos plus tcp.
* @file mbedtls_bio_tcp_sockets_wrapper.c
* @brief Implements mbed TLS platform send/receive functions for the TCP sockets wrapper.
*/

/* FreeRTOS includes. */
#include "FreeRTOS.h"

/* TCP Sockets Wrapper include.*/
#include "tcp_sockets_wrapper.h"

/* MbedTLS Bio TCP sockets wrapper include. */
#include "mbedtls_bio_tcp_sockets_wrapper.h"

/* mbed TLS includes. */
/* MbedTLS includes. */
#if !defined( MBEDTLS_CONFIG_FILE )
#include "config.h"
#include "mbedtls/mbedtls_config.h"
#else
#include MBEDTLS_CONFIG_FILE
#endif
#include "threading_alt.h"
#include "mbedtls/entropy.h"
#include "mbedtls/ssl.h"

/*-----------------------------------------------------------*/
/* TCP Sockets Wrapper include.*/
#include "tcp_sockets_wrapper.h"

/* MbedTLS Bio TCP sockets wrapper include. */
#include "mbedtls_bio_tcp_sockets_wrapper.h"

/* Cellular include. */
#include "r_cellular_if.h"
/**
* @brief Sends data over FreeRTOS+TCP sockets.
* @brief Sends data over TCP socket.
*
* @param[in] ctx The network context containing the socket handle.
* @param[in] buf Buffer containing the bytes to send.
Expand All @@ -60,19 +57,30 @@
* @return Number of bytes sent on success; else a negative value.
*/
int xMbedTLSBioTCPSocketsWrapperSend( void * ctx,
const unsigned char * buf,
size_t len )
const unsigned char * buf,
size_t len )
{
int32_t xReturnStatus;

configASSERT( ctx != NULL );
configASSERT( buf != NULL );

return TCP_Sockets_Send( ( Socket_t ) ctx, buf, len );
}
xReturnStatus = TCP_Sockets_Send( ( Socket_t ) ctx, buf, len );

/*-----------------------------------------------------------*/
switch( xReturnStatus )
{
case 0:
xReturnStatus = MBEDTLS_ERR_SSL_WANT_WRITE;
break;
default:
break;
}

return ( int ) xReturnStatus;
}

/**
* @brief Receives data from FreeRTOS+TCP socket.
* @brief Receives data from TCP socket.
*
* @param[in] ctx The network context containing the socket handle.
* @param[out] buf Buffer to receive bytes into.
Expand All @@ -81,25 +89,28 @@ int xMbedTLSBioTCPSocketsWrapperSend( void * ctx,
* @return Number of bytes received if successful; Negative value on error.
*/
int xMbedTLSBioTCPSocketsWrapperRecv( void * ctx,
unsigned char * buf,
size_t len )
unsigned char * buf,
size_t len )
{
int recvStatus = 0;
int returnStatus = -1;
int32_t xReturnStatus;

configASSERT( ctx != NULL );
configASSERT( buf != NULL );

xReturnStatus = TCP_Sockets_Recv( ( Socket_t ) ctx, buf, len );


configASSERT( ctx != NULL );
configASSERT( buf != NULL );

recvStatus = TCP_Sockets_Recv( ( Socket_t ) ctx, buf, len );
switch( xReturnStatus )
{
/* A timeout occurred before any data could be received. */
case 0:
xReturnStatus = MBEDTLS_ERR_SSL_WANT_READ;
break;

if( recvStatus < 0 )
{
returnStatus = MBEDTLS_ERR_SSL_INTERNAL_ERROR;
}
else
{
returnStatus = recvStatus;
}
default:
break;
}

return returnStatus;
return ( int ) xReturnStatus;
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ The hook function *1 is called by occuring an error of a TCP_Sockets API *2 (dis

* Notes on bootloader to application transition.
When transitioning from the bootloader sample program to the application, the settings of the bootloader's peripheral functions are taken over by the application.
For more information, check chapter 6.4 of the following document.
[RX Family Firmware Update module Using Firmware Integration Technology Application Notes](https://www.renesas.com/search?keywords=R01AN6850)
For more information, check chapter 7 of the following document.
[RX Family Firmware Update module Using Firmware Integration Technology Application Notes Rev.2.01 - Sample Code](https://www.renesas.com/search?keywords=R01AN6850)


### About bootloader macros
Expand Down

0 comments on commit bff68b7

Please sign in to comment.