Verified Commit c1e2a4a1 authored by Vincent Coubard's avatar Vincent Coubard
Browse files

Convert iot socket to CDI APIs


Signed-off-by: Vincent Coubard's avatarVincent Coubard <vincent.coubard@arm.com>
parent d391136c
/*
* FreeRTOS V202107.00
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (c) 2022, Arm Limited and Contributors. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
......@@ -26,6 +27,7 @@
#ifndef IOT_SECURE_SOCKETS_CONFIG_H
#define IOT_SECURE_SOCKETS_CONFIG_H
#include "RTOS_config.h"
/**
* @brief Byte order of the target MCU.
......
/*
* FreeRTOS Secure Sockets V1.3.0
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (c) 2022, Arm Limited and Contributors. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
......@@ -50,10 +51,11 @@
*/
#include <stdint.h>
#include <stddef.h>
#include "cmsis_os2.h"
#include "RTOS_config.h"
#include "iot_secure_sockets_config.h"
#include "iot_secure_sockets_config_defaults.h"
#include "iot_secure_sockets_wrapper_metrics.h"
#include "iot_lib_init.h"
/**
* @ingroup SecureSockets_datatypes_handles
......@@ -464,13 +466,13 @@ int32_t SOCKETS_Close( Socket_t xSocket );
* - Berkeley Socket Options
* - @ref SOCKETS_SO_RCVTIMEO
* - Sets the receive timeout
* - pvOptionValue (TickType_t) is the number of milliseconds that the
* - pvOptionValue (uint32_t) is the number of milliseconds that the
* receive function should wait before timing out.
* - Setting pvOptionValue = 0 causes receive to wait forever.
* - See PORT_SPECIFIC_LINK for device limitations.
* - @ref SOCKETS_SO_SNDTIMEO
* - Sets the send timeout
* - pvOptionValue (TickType_t) is the number of milliseconds that the
* - pvOptionValue (uint32_t) is the number of milliseconds that the
* send function should wait before timing out.
* - Setting pvOptionValue = 0 causes send to wait forever.
* - See PORT_SPECIFIC_LINK for device limitations.
......
/*
* FreeRTOS Transport Secure Sockets V1.0.0
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (c) 2022, Arm Limited and Contributors. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
......@@ -34,6 +35,8 @@
/* TCP/IP abstraction includes. */
#include "transport_secure_sockets.h"
#include "cmsis_os2.h"
/*-----------------------------------------------------------*/
/**
......@@ -349,42 +352,39 @@ static int32_t transportTimeoutSetup( Socket_t tcpSocket,
uint32_t sendTimeoutMs,
uint32_t recvTimeoutMs )
{
TickType_t receiveTimeout = 0, sendTimeout = 0;
uint32_t receiveTimeout = 0, sendTimeout = 0;
int32_t secureSocketStatus = ( int32_t ) SOCKETS_ERROR_NONE;
configASSERT( tcpSocket != SOCKETS_INVALID_SOCKET );
/* Secure Sockets uses TickType_t therefore replace the timeout value with portMAX_DELAY if it is exceeded. */
/* Secure Sockets uses uint32_t therefore replace the timeout value with osWaitForever if it is exceeded. */
receiveTimeout = pdMS_TO_TICKS( recvTimeoutMs );
if( receiveTimeout > portMAX_DELAY )
if( receiveTimeout > osWaitForever )
{
receiveTimeout = portMAX_DELAY;
receiveTimeout = osWaitForever;
}
secureSocketStatus = SOCKETS_SetSockOpt( tcpSocket,
0,
SOCKETS_SO_RCVTIMEO,
&receiveTimeout,
sizeof( TickType_t ) );
sizeof( uint32_t ) );
if( secureSocketStatus == SOCKETS_ERROR_NONE )
{
/* Secure Sockets uses TickType_t therefore replace timeout vale with portMAX_DELAY if it exceeds. */
if( pdMS_TO_TICKS( sendTimeoutMs ) > portMAX_DELAY )
{
sendTimeout = portMAX_DELAY;
}
else
/* Secure Sockets uses uint32_t therefore replace timeout vale with osWaitForever if it exceeds. */
sendTimeout = pdMS_TO_TICKS( sendTimeoutMs );
if( sendTimeout > osWaitForever )
{
sendTimeout = pdMS_TO_TICKS( sendTimeoutMs );
sendTimeout = osWaitForever;
}
secureSocketStatus = SOCKETS_SetSockOpt( tcpSocket,
0,
SOCKETS_SO_SNDTIMEO,
&sendTimeout,
sizeof( TickType_t ) );
sizeof( uint32_t ) );
if( secureSocketStatus != ( int32_t ) SOCKETS_ERROR_NONE )
{
......
/*
* FreeRTOS Transport Secure Sockets V1.0.0
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (c) 2022, Arm Limited and Contributors. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
......@@ -31,6 +32,9 @@
#ifndef TRANSPORT_SECURE_SOCKETS_H
#define TRANSPORT_SECURE_SOCKETS_H
#include "cmsis_os2.h"
#include "RTOS_config.h"
/* bool is defined in only C99+. */
#if defined( __cplusplus ) || ( defined( __STDC_VERSION__ ) && ( __STDC_VERSION__ >= 199901L ) )
#include <stdbool.h>
......@@ -45,10 +49,6 @@
#include "transport_interface.h"
#include "iot_secure_sockets.h"
/* Kernel include. */
#include "FreeRTOS.h"
#include "task.h"
/* Include header that defines log levels. */
#include "logging_levels.h"
......
/*
* FreeRTOS TLS V1.3.1
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (c) 2022, Arm Limited and Contributors. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
......@@ -26,9 +27,7 @@
#ifndef __AWS__TLS__H__
#define __AWS__TLS__H__
#ifndef INC_FREERTOS_H
#error "include FreeRTOS.h must appear in source files before include iot_tls.h"
#endif
#include "RTOS_config.h"
/**
* @defgroup TlsErrors TLS Error Codes
......
/*
* FreeRTOS TLS V1.3.1
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Copyright (c) 2022, Arm Limited and Contributors. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
......@@ -24,13 +25,12 @@
*/
/* FreeRTOS includes. */
#include "FreeRTOS.h"
#include "cmsis_os2.h"
#include "FreeRTOSIPConfig.h"
#include "iot_tls.h"
#include "iot_crypto.h"
#include "core_pkcs11_config.h"
#include "core_pkcs11.h"
#include "task.h"
#include "aws_clientcredential_keys.h"
#include "iot_default_root_certificates.h"
#include "core_pki_utils.h"
......@@ -57,6 +57,8 @@
#include <time.h>
#include <stdio.h>
#define ERRNO_NOSPACE 28
/**
* @brief Represents string to be logged when mbedTLS returned error
* does not contain a high-level code.
......@@ -1044,7 +1046,7 @@ BaseType_t TLS_Send( void * pvContext,
/* Sent data, so update the tally and keep looping. */
xWritten += ( size_t ) xResult;
}
else if( ( 0 == xResult ) || ( -pdFREERTOS_ERRNO_ENOSPC == xResult ) )
else if( ( 0 == xResult ) || ( -ERRNO_NOSPACE == xResult ) )
{
/* No data sent. The secure sockets
* API supports non-blocking send, so stop the loop but don't
......
......@@ -3,8 +3,9 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define LWIP_SO_SNDTIMEO 1
#define LWIP_SO_RCVTIMEO 1
#define LWIP_SO_SNDTIMEO 1
#define LWIP_SO_RCVTIMEO 1
#define LWIP_SO_SNDRCVTIMEO_NONSTANDARD 1
#define MEM_ALIGNMENT 4U
#define MEM_SIZE (20 * 1024)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment