mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-10-26 23:36:32 -04:00
Remove using_mbedtls folder and move its content to the parent folder (#717)
Move the contents of FreeRTOS/FreeRTOS-Plus/Source/Application-Protocols/network_transport/using_mbedtls/ to its parent folder i.e. FreeRTOS/FreeRTOS-Plus/Source/Application-Protocols/network_transport/. This removes one unnecessary folder in the hierarchy.
This commit is contained in:
parent
575acb8a1a
commit
426ad44c05
48 changed files with 179 additions and 157 deletions
|
|
@ -0,0 +1,199 @@
|
|||
/*
|
||||
* FreeRTOS V202111.00
|
||||
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. 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
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* https://www.FreeRTOS.org
|
||||
* https://github.com/FreeRTOS
|
||||
*
|
||||
*/
|
||||
|
||||
/* Standard includes. */
|
||||
#include <string.h>
|
||||
|
||||
/* FreeRTOS includes. */
|
||||
#include "FreeRTOS.h"
|
||||
#if ( configUSE_PREEMPTION == 0 )
|
||||
#include "task.h"
|
||||
#endif
|
||||
|
||||
/* FreeRTOS+TCP includes. */
|
||||
#include "FreeRTOS_IP.h"
|
||||
#include "FreeRTOS_Sockets.h"
|
||||
|
||||
/* FreeRTOS Socket wrapper include. */
|
||||
#include "sockets_wrapper.h"
|
||||
|
||||
/* Transport interface include. */
|
||||
#include "using_plaintext.h"
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* @brief Each compilation unit that consumes the NetworkContext must define it.
|
||||
* It should contain a single pointer as seen below whenever the header file
|
||||
* of this transport implementation is included to your project.
|
||||
*
|
||||
* @note When using multiple transports in the same compilation unit,
|
||||
* define this pointer as void *.
|
||||
*/
|
||||
struct NetworkContext
|
||||
{
|
||||
PlaintextTransportParams_t * pParams;
|
||||
};
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
PlaintextTransportStatus_t Plaintext_FreeRTOS_Connect( NetworkContext_t * pNetworkContext,
|
||||
const char * pHostName,
|
||||
uint16_t port,
|
||||
uint32_t receiveTimeoutMs,
|
||||
uint32_t sendTimeoutMs )
|
||||
{
|
||||
PlaintextTransportParams_t * pPlaintextTransportParams = NULL;
|
||||
PlaintextTransportStatus_t plaintextStatus = PLAINTEXT_TRANSPORT_SUCCESS;
|
||||
BaseType_t socketStatus = 0;
|
||||
|
||||
if( ( pNetworkContext == NULL ) || ( pNetworkContext->pParams == NULL ) || ( pHostName == NULL ) )
|
||||
{
|
||||
LogError( ( "Invalid input parameter(s): Arguments cannot be NULL. pNetworkContext=%p, "
|
||||
"pHostName=%p.",
|
||||
pNetworkContext,
|
||||
pHostName ) );
|
||||
plaintextStatus = PLAINTEXT_TRANSPORT_INVALID_PARAMETER;
|
||||
}
|
||||
else
|
||||
{
|
||||
pPlaintextTransportParams = pNetworkContext->pParams;
|
||||
/* Establish a TCP connection with the server. */
|
||||
socketStatus = Sockets_Connect( &( pPlaintextTransportParams->tcpSocket ),
|
||||
pHostName,
|
||||
port,
|
||||
receiveTimeoutMs,
|
||||
sendTimeoutMs );
|
||||
|
||||
/* A non zero status is an error. */
|
||||
if( socketStatus != 0 )
|
||||
{
|
||||
LogError( ( "Failed to connect to %s with error %d.",
|
||||
pHostName,
|
||||
socketStatus ) );
|
||||
plaintextStatus = PLAINTEXT_TRANSPORT_CONNECT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
return plaintextStatus;
|
||||
}
|
||||
|
||||
PlaintextTransportStatus_t Plaintext_FreeRTOS_Disconnect( const NetworkContext_t * pNetworkContext )
|
||||
{
|
||||
PlaintextTransportParams_t * pPlaintextTransportParams = NULL;
|
||||
PlaintextTransportStatus_t plaintextStatus = PLAINTEXT_TRANSPORT_SUCCESS;
|
||||
|
||||
if( ( pNetworkContext == NULL ) || ( pNetworkContext->pParams == NULL ) )
|
||||
{
|
||||
LogError( ( "pNetworkContext cannot be NULL." ) );
|
||||
plaintextStatus = PLAINTEXT_TRANSPORT_INVALID_PARAMETER;
|
||||
}
|
||||
else if( pNetworkContext->pParams->tcpSocket == FREERTOS_INVALID_SOCKET )
|
||||
{
|
||||
LogError( ( "pPlaintextTransportParams->tcpSocket cannot be an invalid socket." ) );
|
||||
plaintextStatus = PLAINTEXT_TRANSPORT_INVALID_PARAMETER;
|
||||
}
|
||||
else
|
||||
{
|
||||
pPlaintextTransportParams = pNetworkContext->pParams;
|
||||
/* Call socket disconnect function to close connection. */
|
||||
Sockets_Disconnect( pPlaintextTransportParams->tcpSocket );
|
||||
}
|
||||
|
||||
return plaintextStatus;
|
||||
}
|
||||
|
||||
int32_t Plaintext_FreeRTOS_recv( NetworkContext_t * pNetworkContext,
|
||||
void * pBuffer,
|
||||
size_t bytesToRecv )
|
||||
{
|
||||
PlaintextTransportParams_t * pPlaintextTransportParams = NULL;
|
||||
int32_t socketStatus = 1;
|
||||
|
||||
configASSERT( ( pNetworkContext != NULL ) && ( pNetworkContext->pParams != NULL ) );
|
||||
|
||||
pPlaintextTransportParams = pNetworkContext->pParams;
|
||||
|
||||
/* The TCP socket may have a receive block time. If bytesToRecv is greater
|
||||
* than 1 then a frame is likely already part way through reception and
|
||||
* blocking to wait for the desired number of bytes to be available is the
|
||||
* most efficient thing to do. If bytesToRecv is 1 then this may be a
|
||||
* speculative call to read to find the start of a new frame, in which case
|
||||
* blocking is not desirable as it could block an entire protocol agent
|
||||
* task for the duration of the read block time and therefore negatively
|
||||
* impact performance. So if bytesToRecv is 1 then don't call recv unless
|
||||
* it is known that bytes are already available. */
|
||||
if( bytesToRecv == 1 )
|
||||
{
|
||||
socketStatus = ( int32_t ) FreeRTOS_recvcount( pPlaintextTransportParams->tcpSocket );
|
||||
}
|
||||
|
||||
if( socketStatus > 0 )
|
||||
{
|
||||
socketStatus = FreeRTOS_recv( pPlaintextTransportParams->tcpSocket,
|
||||
pBuffer,
|
||||
bytesToRecv,
|
||||
0 );
|
||||
}
|
||||
|
||||
return socketStatus;
|
||||
}
|
||||
|
||||
int32_t Plaintext_FreeRTOS_send( NetworkContext_t * pNetworkContext,
|
||||
const void * pBuffer,
|
||||
size_t bytesToSend )
|
||||
{
|
||||
PlaintextTransportParams_t * pPlaintextTransportParams = NULL;
|
||||
int32_t socketStatus = 0;
|
||||
|
||||
configASSERT( ( pNetworkContext != NULL ) && ( pNetworkContext->pParams != NULL ) );
|
||||
|
||||
pPlaintextTransportParams = pNetworkContext->pParams;
|
||||
socketStatus = FreeRTOS_send( pPlaintextTransportParams->tcpSocket,
|
||||
pBuffer,
|
||||
bytesToSend,
|
||||
0 );
|
||||
|
||||
if( socketStatus == -pdFREERTOS_ERRNO_ENOSPC )
|
||||
{
|
||||
/* The TCP buffers could not accept any more bytes so zero bytes were sent.
|
||||
* This is not necessarily an error that should cause a disconnect
|
||||
* unless it persists. */
|
||||
socketStatus = 0;
|
||||
}
|
||||
|
||||
#if ( configUSE_PREEMPTION == 0 )
|
||||
{
|
||||
/* FreeRTOS_send adds the packet to be sent to the IP task's queue for later processing.
|
||||
* The packet is sent later by the IP task. When FreeRTOS is used in collaborative
|
||||
* mode (i.e. configUSE_PREEMPTION is 0), call taskYIELD to give IP task a chance to run
|
||||
* so that the packet is actually sent before this function returns. */
|
||||
taskYIELD();
|
||||
}
|
||||
#endif
|
||||
|
||||
return socketStatus;
|
||||
}
|
||||
|
|
@ -0,0 +1,152 @@
|
|||
/*
|
||||
* FreeRTOS V202111.00
|
||||
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. 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
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* https://www.FreeRTOS.org
|
||||
* https://github.com/FreeRTOS
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef USING_PLAINTEXT_H
|
||||
#define USING_PLAINTEXT_H
|
||||
|
||||
/**************************************************/
|
||||
/******* DO NOT CHANGE the following order ********/
|
||||
/**************************************************/
|
||||
|
||||
/* Logging related header files are required to be included in the following order:
|
||||
* 1. Include the header file "logging_levels.h".
|
||||
* 2. Define LIBRARY_LOG_NAME and LIBRARY_LOG_LEVEL.
|
||||
* 3. Include the header file "logging_stack.h".
|
||||
*/
|
||||
|
||||
/* Include header that defines log levels. */
|
||||
#include "logging_levels.h"
|
||||
|
||||
/* Logging configuration for the Sockets. */
|
||||
#ifndef LIBRARY_LOG_NAME
|
||||
#define LIBRARY_LOG_NAME "PlaintextTransport"
|
||||
#endif
|
||||
#ifndef LIBRARY_LOG_LEVEL
|
||||
#define LIBRARY_LOG_LEVEL LOG_ERROR
|
||||
#endif
|
||||
|
||||
/* Prototype for the function used to print to console on Windows simulator
|
||||
* of FreeRTOS.
|
||||
* The function prints to the console before the network is connected;
|
||||
* then a UDP port after the network has connected. */
|
||||
extern void vLoggingPrintf( const char * pcFormatString,
|
||||
... );
|
||||
|
||||
/* Map the SdkLog macro to the logging function to enable logging
|
||||
* on Windows simulator. */
|
||||
#ifndef SdkLog
|
||||
#define SdkLog( message ) vLoggingPrintf message
|
||||
#endif
|
||||
|
||||
#include "logging_stack.h"
|
||||
|
||||
/************ End of logging configuration ****************/
|
||||
|
||||
/* FreeRTOS+TCP include. */
|
||||
#include "FreeRTOS_Sockets.h"
|
||||
|
||||
/* Transport interface include. */
|
||||
#include "transport_interface.h"
|
||||
|
||||
/**
|
||||
* @brief Parameters for the network context that uses FreeRTOS+TCP sockets.
|
||||
*/
|
||||
typedef struct PlaintextTransportParams
|
||||
{
|
||||
Socket_t tcpSocket;
|
||||
} PlaintextTransportParams_t;
|
||||
|
||||
/**
|
||||
* @brief Plain text transport Connect / Disconnect return status.
|
||||
*/
|
||||
typedef enum PlaintextTransportStatus
|
||||
{
|
||||
PLAINTEXT_TRANSPORT_SUCCESS = 1, /**< Function successfully completed. */
|
||||
PLAINTEXT_TRANSPORT_INVALID_PARAMETER = 2, /**< At least one parameter was invalid. */
|
||||
PLAINTEXT_TRANSPORT_CONNECT_FAILURE = 3 /**< Initial connection to the server failed. */
|
||||
} PlaintextTransportStatus_t;
|
||||
|
||||
/**
|
||||
* @brief Create a TCP connection with FreeRTOS sockets.
|
||||
*
|
||||
* @param[out] pNetworkContext Pointer to a network context to contain the
|
||||
* initialized socket handle.
|
||||
* @param[in] pHostName The hostname of the remote endpoint.
|
||||
* @param[in] port The destination port.
|
||||
* @param[in] receiveTimeoutMs Receive socket timeout.
|
||||
*
|
||||
* @return #PLAINTEXT_TRANSPORT_SUCCESS, #PLAINTEXT_TRANSPORT_INVALID_PARAMETER,
|
||||
* or #PLAINTEXT_TRANSPORT_CONNECT_FAILURE.
|
||||
*/
|
||||
PlaintextTransportStatus_t Plaintext_FreeRTOS_Connect( NetworkContext_t * pNetworkContext,
|
||||
const char * pHostName,
|
||||
uint16_t port,
|
||||
uint32_t receiveTimeoutMs,
|
||||
uint32_t sendTimeoutMs );
|
||||
|
||||
/**
|
||||
* @brief Gracefully disconnect an established TCP connection.
|
||||
*
|
||||
* @param[in] pNetworkContext Network context containing the TCP socket handle.
|
||||
*
|
||||
* @return #PLAINTEXT_TRANSPORT_SUCCESS, or #PLAINTEXT_TRANSPORT_INVALID_PARAMETER.
|
||||
*/
|
||||
PlaintextTransportStatus_t Plaintext_FreeRTOS_Disconnect( const NetworkContext_t * pNetworkContext );
|
||||
|
||||
/**
|
||||
* @brief Receives data from an established TCP connection.
|
||||
*
|
||||
* @note When the number of bytes requested is 1, the TCP socket's Rx stream
|
||||
* is checked for available bytes to read. If there are none, this function
|
||||
* immediately returns 0 without blocking.
|
||||
*
|
||||
* @param[in] pNetworkContext The network context containing the TCP socket
|
||||
* handle.
|
||||
* @param[out] pBuffer Buffer to receive bytes into.
|
||||
* @param[in] bytesToRecv Number of bytes to receive from the network.
|
||||
*
|
||||
* @return Number of bytes received if successful; 0 if the socket times out;
|
||||
* Negative value on error.
|
||||
*/
|
||||
int32_t Plaintext_FreeRTOS_recv( NetworkContext_t * pNetworkContext,
|
||||
void * pBuffer,
|
||||
size_t bytesToRecv );
|
||||
|
||||
/**
|
||||
* @brief Sends data over an established TCP connection.
|
||||
*
|
||||
* @param[in] pNetworkContext The network context containing the TCP socket
|
||||
* handle.
|
||||
* @param[in] pBuffer Buffer containing the bytes to send.
|
||||
* @param[in] bytesToSend Number of bytes to send from the buffer.
|
||||
*
|
||||
* @return Number of bytes sent on success; else a negative value.
|
||||
*/
|
||||
int32_t Plaintext_FreeRTOS_send( NetworkContext_t * pNetworkContext,
|
||||
const void * pBuffer,
|
||||
size_t bytesToSend );
|
||||
|
||||
#endif /* ifndef USING_PLAINTEXT_H */
|
||||
Loading…
Add table
Add a link
Reference in a new issue