xNetworkInfo.u.setup.pNetworkCredentialInfo = NULL;\r
\r
/* Use FreeRTOS+TCP network. */\r
- xNetworkInfo.pNetworkInterface = IOT_NETWORK_INTERFACE_AFR;\r
+ xNetworkInfo.pNetworkInterface = IOT_NETWORK_INTERFACE_FREERTOS;\r
\r
/* Setup the callback which is called when the MQTT connection is disconnected. */\r
xNetworkInfo.disconnectCallback.pCallbackContext = ( void * ) xTaskGetCurrentTaskHandle();\r
<ClCompile Include="..\..\..\Source\FreeRTOS-IoT-Libraries\abstractions\platform\freertos\iot_clock_freertos.c" />\r
<ClCompile Include="..\..\..\Source\FreeRTOS-IoT-Libraries\abstractions\platform\freertos\iot_network_freertos.c" />\r
<ClCompile Include="..\..\..\Source\FreeRTOS-IoT-Libraries\abstractions\platform\freertos\iot_threads_freertos.c" />\r
- <ClCompile Include="..\..\..\Source\FreeRTOS-IoT-Libraries\abstractions\secure_sockets\freertos_plus_tcp\iot_secure_sockets.c" />\r
<ClCompile Include="..\..\..\Source\FreeRTOS-IoT-Libraries\c_sdk\standard\common\logging\iot_logging.c" />\r
<ClCompile Include="..\..\..\Source\FreeRTOS-IoT-Libraries\c_sdk\standard\common\taskpool\iot_taskpool.c" />\r
<ClCompile Include="..\..\..\Source\FreeRTOS-IoT-Libraries\c_sdk\standard\mqtt\src\iot_mqtt_api.c" />\r
<ClInclude Include="..\..\..\Source\FreeRTOS-IoT-Libraries\abstractions\platform\include\platform\iot_network.h" />\r
<ClInclude Include="..\..\..\Source\FreeRTOS-IoT-Libraries\abstractions\platform\include\platform\iot_threads.h" />\r
<ClInclude Include="..\..\..\Source\FreeRTOS-IoT-Libraries\abstractions\platform\include\types\iot_platform_types.h" />\r
- <ClInclude Include="..\..\..\Source\FreeRTOS-IoT-Libraries\abstractions\secure_sockets\include\iot_secure_sockets.h" />\r
- <ClInclude Include="..\..\..\Source\FreeRTOS-IoT-Libraries\abstractions\secure_sockets\include\iot_secure_sockets_config_defaults.h" />\r
- <ClInclude Include="..\..\..\Source\FreeRTOS-IoT-Libraries\abstractions\secure_sockets\include\iot_secure_sockets_wrapper_metrics.h" />\r
<ClInclude Include="..\..\..\Source\FreeRTOS-IoT-Libraries\c_sdk\standard\common\include\iot_taskpool.h" />\r
<ClInclude Include="..\..\..\Source\FreeRTOS-IoT-Libraries\c_sdk\standard\common\include\private\iot_error.h" />\r
- <ClInclude Include="..\..\..\Source\FreeRTOS-IoT-Libraries\c_sdk\standard\common\include\private\iot_lib_init.h" />\r
<ClInclude Include="..\..\..\Source\FreeRTOS-IoT-Libraries\c_sdk\standard\common\include\private\iot_logging.h" />\r
<ClInclude Include="..\..\..\Source\FreeRTOS-IoT-Libraries\c_sdk\standard\common\include\private\iot_static_memory.h" />\r
<ClInclude Include="..\..\..\Source\FreeRTOS-IoT-Libraries\c_sdk\standard\common\include\private\iot_taskpool_internal.h" />\r
<Filter Include="FreeRTOS+\FreeRTOS IoT Libraries\standard\common\logging">\r
<UniqueIdentifier>{1943ad1a-a367-4ef5-ab65-1313801e6327}</UniqueIdentifier>\r
</Filter>\r
- <Filter Include="FreeRTOS+\FreeRTOS IoT Libraries\abstractions\secure_sockets">\r
- <UniqueIdentifier>{9a82e058-c6c5-4da5-817e-a28c5137749b}</UniqueIdentifier>\r
- </Filter>\r
- <Filter Include="FreeRTOS+\FreeRTOS IoT Libraries\abstractions\secure_sockets\include">\r
- <UniqueIdentifier>{cf6813fa-76cf-4e4d-86f7-18f1ae92ad44}</UniqueIdentifier>\r
- </Filter>\r
- <Filter Include="FreeRTOS+\FreeRTOS IoT Libraries\abstractions\secure_sockets\freertos_plus_tcp">\r
- <UniqueIdentifier>{79ebfd9f-45cb-4a3b-8c73-73f9d9fe7984}</UniqueIdentifier>\r
- </Filter>\r
</ItemGroup>\r
<ItemGroup>\r
<ClCompile Include="..\..\..\..\FreeRTOS\Source\portable\MSVC-MingW\port.c">\r
<ClCompile Include="..\..\..\Source\FreeRTOS-IoT-Libraries\abstractions\platform\freertos\iot_threads_freertos.c">\r
<Filter>FreeRTOS+\FreeRTOS IoT Libraries\abstractions\platform\freertos</Filter>\r
</ClCompile>\r
- <ClCompile Include="..\..\..\Source\FreeRTOS-IoT-Libraries\abstractions\secure_sockets\freertos_plus_tcp\iot_secure_sockets.c">\r
- <Filter>FreeRTOS+\FreeRTOS IoT Libraries\abstractions\secure_sockets\freertos_plus_tcp</Filter>\r
- </ClCompile>\r
<ClCompile Include="DemoTasks\SimpleMQTTExamples.c">\r
<Filter>DemoTasks</Filter>\r
</ClCompile>\r
<ClInclude Include="..\..\..\Source\FreeRTOS-IoT-Libraries\abstractions\platform\include\platform\iot_threads.h">\r
<Filter>FreeRTOS+\FreeRTOS IoT Libraries\abstractions\platform\include\platform</Filter>\r
</ClInclude>\r
- <ClInclude Include="..\..\..\Source\FreeRTOS-IoT-Libraries\abstractions\secure_sockets\include\iot_secure_sockets.h">\r
- <Filter>FreeRTOS+\FreeRTOS IoT Libraries\abstractions\secure_sockets\include</Filter>\r
- </ClInclude>\r
- <ClInclude Include="..\..\..\Source\FreeRTOS-IoT-Libraries\abstractions\secure_sockets\include\iot_secure_sockets_config_defaults.h">\r
- <Filter>FreeRTOS+\FreeRTOS IoT Libraries\abstractions\secure_sockets\include</Filter>\r
- </ClInclude>\r
- <ClInclude Include="..\..\..\Source\FreeRTOS-IoT-Libraries\abstractions\secure_sockets\include\iot_secure_sockets_wrapper_metrics.h">\r
- <Filter>FreeRTOS+\FreeRTOS IoT Libraries\abstractions\secure_sockets\include</Filter>\r
- </ClInclude>\r
- <ClInclude Include="..\..\..\Source\FreeRTOS-IoT-Libraries\c_sdk\standard\common\include\private\iot_lib_init.h">\r
- <Filter>FreeRTOS+\FreeRTOS IoT Libraries\standard\common\include\private</Filter>\r
- </ClInclude>\r
</ItemGroup>\r
</Project>
\ No newline at end of file
\r
/**\r
* @file iot_network_freertos.h\r
- * @brief Declares the network stack functions specified in aws_iot_network.h for\r
- * Amazon FreeRTOS Secure Sockets.\r
+ * @brief Declares the network stack functions specified in iot_network.h for\r
+ * FreeRTOS+TCP.\r
*/\r
\r
-#ifndef _IOT_NETWORK_AFR_H_\r
-#define _IOT_NETWORK_AFR_H_\r
+#ifndef _IOT_NETWORK_FREERTOS_H_\r
+#define _IOT_NETWORK_FREERTOS_H_\r
\r
/* Standard includes. */\r
#include <stdbool.h>\r
/* Platform network include. */\r
#include "platform/iot_network.h"\r
\r
-/* Amazon FreeRTOS Secure Sockets include. */\r
-#include "iot_secure_sockets.h"\r
-\r
/**\r
- * @brief Represents a network connection that uses Amazon FreeRTOS Secure Sockets.\r
+ * @brief Represents a network connection that uses FreeRTOS+TCP sockets.\r
*\r
* This is an incomplete type. In application code, only pointers to this type\r
* should be used.\r
*/\r
-typedef struct _networkConnection IotNetworkConnectionAfr_t;\r
+typedef struct _networkConnection IotNetworkConnectionFreeRTOS_t;\r
\r
/**\r
- * @brief Provides a default value for an #IotNetworkConnectionAfr_t.\r
+ * @brief Provides a default value for an #IotNetworkConnectionFreeRTOS_t.\r
*\r
- * All instances of #IotNetworkConnectionAfr_t should be initialized with\r
+ * All instances of #IotNetworkConnectionFreeRTOS_t should be initialized with\r
* this constant.\r
*\r
- * @warning Failing to initialize an #IotNetworkConnectionAfr_t with this\r
+ * @warning Failing to initialize an #IotNetworkConnectionFreeRTOS_t with this\r
* initializer may result in undefined behavior!\r
* @note This initializer may change at any time in future versions, but its\r
* name will remain the same.\r
*/\r
-#define IOT_NETWORK_CONNECTION_AFR_INITIALIZER { 0 }\r
+#define IOT_NETWORK_CONNECTION_FREERTOS_INITIALIZER { 0 }\r
\r
/**\r
* @brief Generic initializer for an #IotNetworkServerInfo_t.\r
* @note This initializer may change at any time in future versions, but its\r
* name will remain the same.\r
*/\r
-#define IOT_NETWORK_SERVER_INFO_AFR_INITIALIZER { 0 }\r
+#define IOT_NETWORK_SERVER_INFO_FREERTOS_INITIALIZER { 0 }\r
\r
/**\r
* @brief Generic initializer for an #IotNetworkCredentials_t.\r
* @note This initializer may change at any time in future versions, but its\r
* name will remain the same.\r
*/\r
-#define IOT_NETWORK_CREDENTIALS_AFR_INITIALIZER { 0 }\r
+#define IOT_NETWORK_CREDENTIALS_FREERTOS_INITIALIZER { 0 }\r
\r
/**\r
* @brief Provides a pointer to an #IotNetworkInterface_t that uses the functions\r
* declared in this file.\r
*/\r
-#define IOT_NETWORK_INTERFACE_AFR ( &( IotNetworkAfr ) )\r
+#define IOT_NETWORK_INTERFACE_FREERTOS ( &( IotNetworkFreeRTOS ) )\r
\r
/**\r
- * @brief An implementation of #IotNetworkInterface_t::create for Amazon FreeRTOS\r
- * Secure Sockets.\r
+ * @brief An implementation of #IotNetworkInterface_t::create for FreeRTOS+TCP\r
+ * sockets.\r
*/\r
-IotNetworkError_t IotNetworkAfr_Create( void * pConnectionInfo,\r
- void * pCredentialInfo,\r
- void ** const pConnection );\r
+IotNetworkError_t IotNetworkFreeRTOS_Create( void * pConnectionInfo,\r
+ void * pCredentialInfo,\r
+ void ** const pConnection );\r
\r
/**\r
* @brief An implementation of #IotNetworkInterface_t::setReceiveCallback for\r
- * Amazon FreeRTOS Secure Sockets.\r
+ * FreeRTOS+TCP sockets.\r
*/\r
-IotNetworkError_t IotNetworkAfr_SetReceiveCallback( void * pConnection,\r
- IotNetworkReceiveCallback_t receiveCallback,\r
- void * pContext );\r
+IotNetworkError_t IotNetworkFreeRTOS_SetReceiveCallback( void * pConnection,\r
+ IotNetworkReceiveCallback_t receiveCallback,\r
+ void * pContext );\r
\r
/**\r
- * @brief An implementation of #IotNetworkInterface_t::send for Amazon FreeRTOS\r
- * Secure Sockets.\r
+ * @brief An implementation of #IotNetworkInterface_t::send for FreeRTOS+TCP\r
+ * sockets.\r
*/\r
-size_t IotNetworkAfr_Send( void * pConnection,\r
- const uint8_t * pMessage,\r
- size_t messageLength );\r
+size_t IotNetworkFreeRTOS_Send( void * pConnection,\r
+ const uint8_t * pMessage,\r
+ size_t messageLength );\r
\r
/**\r
- * @brief An implementation of #IotNetworkInterface_t::receive for Amazon FreeRTOS\r
- * Secure Sockets.\r
+ * @brief An implementation of #IotNetworkInterface_t::receive for FreeRTOS+TCP\r
+ * sockets.\r
*/\r
-size_t IotNetworkAfr_Receive( void * pConnection,\r
- uint8_t * pBuffer,\r
- size_t bytesRequested );\r
+size_t IotNetworkFreeRTOS_Receive( void * pConnection,\r
+ uint8_t * pBuffer,\r
+ size_t bytesRequested );\r
\r
/**\r
- * @brief An implementation of #IotNetworkInterface_t::close for Amazon FreeRTOS\r
- * Secure Sockets.\r
+ * @brief An implementation of #IotNetworkInterface_t::close for FreeRTOS+TCP\r
+ * sockets.\r
*/\r
-IotNetworkError_t IotNetworkAfr_Close( void * pConnection );\r
+IotNetworkError_t IotNetworkFreeRTOS_Close( void * pConnection );\r
\r
/**\r
- * @brief An implementation of #IotNetworkInterface_t::destroy for Amazon FreeRTOS\r
- * Secure Sockets.\r
+ * @brief An implementation of #IotNetworkInterface_t::destroy for FreeRTOS+TCP\r
+ * sockets.\r
*/\r
-IotNetworkError_t IotNetworkAfr_Destroy( void * pConnection );\r
+IotNetworkError_t IotNetworkFreeRTOS_Destroy( void * pConnection );\r
\r
/**\r
* @cond DOXYGEN_IGNORE\r
*\r
* Declaration of a network interface struct using the functions in this file.\r
*/\r
-extern const IotNetworkInterface_t IotNetworkAfr;\r
+extern const IotNetworkInterface_t IotNetworkFreeRTOS;\r
/** @endcond */\r
\r
-#endif /* ifndef _IOT_NETWORK_AFR_H_ */\r
+#endif /* ifndef _IOT_NETWORK_FREERTOS_H_ */\r
/**\r
* @file iot_network_freertos.c\r
* @brief Implementation of the network-related functions from iot_network_freertos.h\r
- * for Amazon FreeRTOS secure sockets.\r
+ * for FreeRTOS+TCP sockets.\r
*/\r
\r
/* The config header is always included first. */\r
#include <string.h>\r
\r
/* FreeRTOS includes. */\r
+#include "FreeRTOS.h"\r
#include "semphr.h"\r
#include "event_groups.h"\r
\r
-/* Error handling include. */\r
-#include "private/iot_error.h"\r
+/* FreeRTOS+TCP includes. */\r
+#include "FreeRTOS_IP.h"\r
+#include "FreeRTOS_Sockets.h"\r
\r
-/* Amazon FreeRTOS network include. */\r
+/* FreeRTOS-IoT-Libraries includes. */\r
+#include "private/iot_error.h"\r
#include "platform/iot_network_freertos.h"\r
\r
/* Configure logs for the functions in this file. */\r
/* Provide a default value for the number of milliseconds for a socket poll.\r
* This is a temporary workaround to deal with the lack of poll(). */\r
#ifndef IOT_NETWORK_SOCKET_POLL_MS\r
- #define IOT_NETWORK_SOCKET_POLL_MS ( 1000 )\r
+ #define IOT_NETWORK_SOCKET_POLL_MS ( 1000 )\r
#endif\r
\r
/**\r
* @brief The event group bit to set when a connection's socket is shut down.\r
*/\r
-#define _FLAG_SHUTDOWN ( 1 )\r
+#define _SHUTDOWN_BITMASK ( 1UL << 0UL )\r
\r
/**\r
* @brief The event group bit to set when a connection's receive task exits.\r
*/\r
-#define _FLAG_RECEIVE_TASK_EXITED ( 2 )\r
+#define _RECEIVE_TASK_EXITED_BITMASK ( 1UL << 1UL )\r
\r
/**\r
* @brief The event group bit to set when the connection is destroyed from the\r
* receive task.\r
*/\r
-#define _FLAG_CONNECTION_DESTROYED ( 4 )\r
+#define _CONNECTION_DESTROYED_BITMASK ( 1UL << 2UL )\r
\r
+/**\r
+ * @brief Maximum length of a DNS name.\r
+ *\r
+ * Per https://tools.ietf.org/html/rfc1035, 253 is the maximum string length\r
+ * of a DNS name.\r
+ */\r
+#define _MAX_DNS_NAME_LENGTH ( 253 )\r
/*-----------------------------------------------------------*/\r
\r
typedef struct _networkConnection\r
{\r
- Socket_t socket; /**< @brief Amazon FreeRTOS Secure Sockets handle. */\r
- StaticSemaphore_t socketMutex; /**< @brief Prevents concurrent threads from sending on a socket. */\r
- StaticEventGroup_t connectionFlags; /**< @brief Synchronizes with the receive task. */\r
- TaskHandle_t receiveTask; /**< @brief Handle of the receive task, if any. */\r
- IotNetworkReceiveCallback_t receiveCallback; /**< @brief Network receive callback, if any. */\r
- void * pReceiveContext; /**< @brief The context for the receive callback. */\r
- bool bufferedByteValid; /**< @brief Used to determine if the buffered byte is valid. */\r
- uint8_t bufferedByte; /**< @brief A single byte buffered from a receive, since AFR Secure Sockets does not have poll(). */\r
+ Socket_t socket; /**< @brief FreeRTOS+TCP sockets handle. */\r
+ SemaphoreHandle_t socketMutex; /**< @brief Prevents concurrent threads from sending on a socket. */\r
+ StaticSemaphore_t socketMutexStorage; /**< @brief Storage space for socketMutex. */\r
+ EventGroupHandle_t connectionEventGroup; /**< @brief Synchronizes with the receive task. */\r
+ StaticEventGroup_t connectionEventGroupStorage; /**< @brief Storage space for connectionEventGroup. */\r
+ TaskHandle_t receiveTask; /**< @brief Handle of the receive task, if any. */\r
+ IotNetworkReceiveCallback_t receiveCallback; /**< @brief Network receive callback, if any. */\r
+ void * pReceiveContext; /**< @brief The context for the receive callback. */\r
+ bool bufferedByteValid; /**< @brief Used to determine if the buffered byte is valid. */\r
+ uint8_t bufferedByte; /**< @brief A single byte buffered from a receive, since FreeRTOS+TCP sockets does not have poll(). */\r
} _networkConnection_t;\r
-\r
/*-----------------------------------------------------------*/\r
\r
/**\r
* @brief An #IotNetworkInterface_t that uses the functions in this file.\r
*/\r
-const IotNetworkInterface_t IotNetworkAfr =\r
+const IotNetworkInterface_t IotNetworkFreeRTOS =\r
{\r
- .create = IotNetworkAfr_Create,\r
- .setReceiveCallback = IotNetworkAfr_SetReceiveCallback,\r
- .send = IotNetworkAfr_Send,\r
- .receive = IotNetworkAfr_Receive,\r
- .close = IotNetworkAfr_Close,\r
- .destroy = IotNetworkAfr_Destroy\r
+ .create = IotNetworkFreeRTOS_Create,\r
+ .setReceiveCallback = IotNetworkFreeRTOS_SetReceiveCallback,\r
+ .send = IotNetworkFreeRTOS_Send,\r
+ .receive = IotNetworkFreeRTOS_Receive,\r
+ .close = IotNetworkFreeRTOS_Close,\r
+ .destroy = IotNetworkFreeRTOS_Destroy\r
};\r
-\r
/*-----------------------------------------------------------*/\r
\r
/**\r
*/\r
static void _destroyConnection( _networkConnection_t * pNetworkConnection )\r
{\r
- /* Call Secure Sockets close function to free resources. */\r
- int32_t socketStatus = SOCKETS_Close( pNetworkConnection->socket );\r
-\r
- if( socketStatus != SOCKETS_ERROR_NONE )\r
- {\r
- IotLogWarn( "Failed to destroy connection." );\r
- }\r
+ /* Call FreeRTOS+TCP close function to free resources. */\r
+ ( void ) FreeRTOS_closesocket( pNetworkConnection->socket );\r
\r
/* Free the network connection. */\r
vPortFree( pNetworkConnection );\r
}\r
-\r
/*-----------------------------------------------------------*/\r
\r
/**\r
{\r
bool destroyConnection = false;\r
int32_t socketStatus = 0;\r
- EventBits_t connectionFlags = 0;\r
+ EventBits_t connectionEventGroupBits = 0;\r
\r
/* Cast network connection to the correct type. */\r
_networkConnection_t * pNetworkConnection = pArgument;\r
* MULTIPLE CALLS OF RECEIVE. */\r
do\r
{\r
- socketStatus = SOCKETS_Recv( pNetworkConnection->socket,\r
- &( pNetworkConnection->bufferedByte ),\r
- 1,\r
- 0 );\r
+ socketStatus = FreeRTOS_recv( pNetworkConnection->socket,\r
+ &( pNetworkConnection->bufferedByte ),\r
+ 1,\r
+ 0 );\r
\r
- connectionFlags = xEventGroupGetBits( ( EventGroupHandle_t ) &( pNetworkConnection->connectionFlags ) );\r
+ connectionEventGroupBits = xEventGroupGetBits( pNetworkConnection->connectionEventGroup );\r
\r
- if( ( connectionFlags & _FLAG_SHUTDOWN ) == _FLAG_SHUTDOWN )\r
+ if( ( connectionEventGroupBits & _SHUTDOWN_BITMASK ) == _SHUTDOWN_BITMASK )\r
{\r
- socketStatus = SOCKETS_ECLOSED;\r
+ socketStatus = FREERTOS_ECLOSED;\r
}\r
\r
/* Check for timeout. Some ports return 0, some return EWOULDBLOCK. */\r
- } while( ( socketStatus == 0 ) || ( socketStatus == SOCKETS_EWOULDBLOCK ) );\r
+ } while( ( socketStatus == 0 ) || ( socketStatus == FREERTOS_EWOULDBLOCK ) );\r
\r
if( socketStatus <= 0 )\r
{\r
/* Check if the connection was destroyed by the receive callback. This\r
* does not need to be thread-safe because the destroy connection function\r
* may only be called once (per its API doc). */\r
- connectionFlags = xEventGroupGetBits( ( EventGroupHandle_t ) &( pNetworkConnection->connectionFlags ) );\r
+ connectionEventGroupBits = xEventGroupGetBits( pNetworkConnection->connectionEventGroup );\r
\r
- if( ( connectionFlags & _FLAG_CONNECTION_DESTROYED ) == _FLAG_CONNECTION_DESTROYED )\r
+ if( ( connectionEventGroupBits & _CONNECTION_DESTROYED_BITMASK ) == _CONNECTION_DESTROYED_BITMASK )\r
{\r
destroyConnection = true;\r
break;\r
}\r
else\r
{\r
- /* Set the flag to indicate that the receive task has exited. */\r
- ( void ) xEventGroupSetBits( ( EventGroupHandle_t ) &( pNetworkConnection->connectionFlags ),\r
- _FLAG_RECEIVE_TASK_EXITED );\r
+ /* Set the bit to indicate that the receive task has exited. */\r
+ ( void ) xEventGroupSetBits( pNetworkConnection->connectionEventGroup,\r
+ _RECEIVE_TASK_EXITED_BITMASK );\r
}\r
\r
vTaskDelete( NULL );\r
}\r
-\r
-/*-----------------------------------------------------------*/\r
-\r
-/**\r
- * @brief Set up a secured TLS connection.\r
- *\r
- * @param[in] pAfrCredentials Credentials for the secured connection.\r
- * @param[in] tcpSocket An initialized socket to secure.\r
- * @param[in] pHostName Remote server name for SNI.\r
- * @param[in] hostnameLength The length of `pHostName`.\r
- *\r
- * @return #IOT_NETWORK_SUCCESS or #IOT_NETWORK_SYSTEM_ERROR.\r
- */\r
-static IotNetworkError_t _tlsSetup( const IotNetworkCredentials_t * pAfrCredentials,\r
- Socket_t tcpSocket,\r
- const char * pHostName,\r
- size_t hostnameLength )\r
-{\r
- IOT_FUNCTION_ENTRY( IotNetworkError_t, IOT_NETWORK_SUCCESS );\r
- int32_t socketStatus = SOCKETS_ERROR_NONE;\r
-\r
- /* ALPN options for AWS IoT. */\r
- const char * ppcALPNProtos[] = { socketsAWS_IOT_ALPN_MQTT };\r
-\r
- /* Set secured option. */\r
- socketStatus = SOCKETS_SetSockOpt( tcpSocket,\r
- 0,\r
- SOCKETS_SO_REQUIRE_TLS,\r
- NULL,\r
- 0 );\r
-\r
- if( socketStatus != SOCKETS_ERROR_NONE )\r
- {\r
- IotLogError( "Failed to set secured option for new connection." );\r
- IOT_SET_AND_GOTO_CLEANUP( IOT_NETWORK_SYSTEM_ERROR );\r
- }\r
-\r
- /* Set ALPN option. */\r
- if( pAfrCredentials->pAlpnProtos != NULL )\r
- {\r
- socketStatus = SOCKETS_SetSockOpt( tcpSocket,\r
- 0,\r
- SOCKETS_SO_ALPN_PROTOCOLS,\r
- ppcALPNProtos,\r
- sizeof( ppcALPNProtos ) / sizeof( ppcALPNProtos[ 0 ] ) );\r
-\r
- if( socketStatus != SOCKETS_ERROR_NONE )\r
- {\r
- IotLogError( "Failed to set ALPN option for new connection." );\r
- IOT_SET_AND_GOTO_CLEANUP( IOT_NETWORK_SYSTEM_ERROR );\r
- }\r
- }\r
-\r
- /* Set SNI option. */\r
- if( pAfrCredentials->disableSni == false )\r
- {\r
- socketStatus = SOCKETS_SetSockOpt( tcpSocket,\r
- 0,\r
- SOCKETS_SO_SERVER_NAME_INDICATION,\r
- pHostName,\r
- hostnameLength + 1 );\r
-\r
- if( socketStatus != SOCKETS_ERROR_NONE )\r
- {\r
- IotLogError( "Failed to set SNI option for new connection." );\r
- IOT_SET_AND_GOTO_CLEANUP( IOT_NETWORK_SYSTEM_ERROR );\r
- }\r
- }\r
-\r
- /* Set custom server certificate. */\r
- if( pAfrCredentials->pRootCa != NULL )\r
- {\r
- socketStatus = SOCKETS_SetSockOpt( tcpSocket,\r
- 0,\r
- SOCKETS_SO_TRUSTED_SERVER_CERTIFICATE,\r
- pAfrCredentials->pRootCa,\r
- pAfrCredentials->rootCaSize );\r
-\r
- if( socketStatus != SOCKETS_ERROR_NONE )\r
- {\r
- IotLogError( "Failed to set server certificate option for new connection." );\r
- IOT_SET_AND_GOTO_CLEANUP( IOT_NETWORK_SYSTEM_ERROR );\r
- }\r
- }\r
-\r
- IOT_FUNCTION_EXIT_NO_CLEANUP();\r
-}\r
-\r
/*-----------------------------------------------------------*/\r
\r
-IotNetworkError_t IotNetworkAfr_Create( void * pConnectionInfo,\r
- void * pCredentialInfo,\r
- void ** pConnection )\r
+IotNetworkError_t IotNetworkFreeRTOS_Create( void * pConnectionInfo,\r
+ void * pCredentialInfo,\r
+ void ** pConnection )\r
{\r
IOT_FUNCTION_ENTRY( IotNetworkError_t, IOT_NETWORK_SUCCESS );\r
- Socket_t tcpSocket = SOCKETS_INVALID_SOCKET;\r
- int32_t socketStatus = SOCKETS_ERROR_NONE;\r
- SocketsSockaddr_t serverAddress = { 0 };\r
- EventGroupHandle_t pConnectionFlags = NULL;\r
- SemaphoreHandle_t pConnectionMutex = NULL;\r
+ Socket_t tcpSocket = FREERTOS_INVALID_SOCKET;\r
+ int32_t socketStatus = 0;\r
+ struct freertos_sockaddr serverAddress = { 0 };\r
const TickType_t receiveTimeout = pdMS_TO_TICKS( IOT_NETWORK_SOCKET_POLL_MS );\r
_networkConnection_t * pNewNetworkConnection = NULL;\r
\r
+ /* TLS is not supported yet and therefore pCredentialInfo must be NULL. */\r
+ configASSERT( pCredentialInfo == NULL );\r
+\r
/* Cast function parameters to correct types. */\r
const IotNetworkServerInfo_t * pServerInfo = pConnectionInfo;\r
- const IotNetworkCredentials_t * pAfrCredentials = pCredentialInfo;\r
_networkConnection_t ** pNetworkConnection = ( _networkConnection_t ** ) pConnection;\r
\r
- /* Check host name length against the maximum length allowed by Secure\r
- * Sockets. */\r
+ /* Check host name length against the maximum length allowed. */\r
const size_t hostnameLength = strlen( pServerInfo->pHostName );\r
\r
- if( hostnameLength > ( size_t ) securesocketsMAX_DNS_NAME_LENGTH )\r
+ if( hostnameLength > ( size_t ) _MAX_DNS_NAME_LENGTH )\r
{\r
IotLogError( "Host name length exceeds %d, which is the maximum allowed.",\r
- securesocketsMAX_DNS_NAME_LENGTH );\r
+ _MAX_DNS_NAME_LENGTH );\r
IOT_SET_AND_GOTO_CLEANUP( IOT_NETWORK_BAD_PARAMETER );\r
}\r
\r
( void ) memset( pNewNetworkConnection, 0x00, sizeof( _networkConnection_t ) );\r
\r
/* Create a new TCP socket. */\r
- tcpSocket = SOCKETS_Socket( SOCKETS_AF_INET,\r
- SOCKETS_SOCK_STREAM,\r
- SOCKETS_IPPROTO_TCP );\r
+ tcpSocket = FreeRTOS_socket( FREERTOS_AF_INET,\r
+ FREERTOS_SOCK_STREAM,\r
+ FREERTOS_IPPROTO_TCP );\r
\r
- if( tcpSocket == SOCKETS_INVALID_SOCKET )\r
+ if( tcpSocket == FREERTOS_INVALID_SOCKET )\r
{\r
IotLogError( "Failed to create new socket." );\r
IOT_SET_AND_GOTO_CLEANUP( IOT_NETWORK_SYSTEM_ERROR );\r
}\r
\r
- /* Set up connection encryption if credentials are provided. */\r
- if( pAfrCredentials != NULL )\r
- {\r
- status = _tlsSetup( pAfrCredentials, tcpSocket, pServerInfo->pHostName, hostnameLength );\r
-\r
- if( status != IOT_NETWORK_SUCCESS )\r
- {\r
- IOT_GOTO_CLEANUP();\r
- }\r
- }\r
-\r
/* Establish connection. */\r
- serverAddress.ucSocketDomain = SOCKETS_AF_INET;\r
- serverAddress.usPort = SOCKETS_htons( pServerInfo->port );\r
- serverAddress.ulAddress = SOCKETS_GetHostByName( pServerInfo->pHostName );\r
+ serverAddress.sin_family = FREERTOS_AF_INET;\r
+ serverAddress.sin_port = FreeRTOS_htons( pServerInfo->port );\r
+ serverAddress.sin_addr = FreeRTOS_gethostbyname( pServerInfo->pHostName );\r
+ serverAddress.sin_len = ( uint8_t ) sizeof( serverAddress );\r
\r
/* Check for errors from DNS lookup. */\r
- if( serverAddress.ulAddress == 0 )\r
+ if( serverAddress.sin_addr == 0 )\r
{\r
IotLogError( "Failed to resolve %s.", pServerInfo->pHostName );\r
IOT_SET_AND_GOTO_CLEANUP( IOT_NETWORK_SYSTEM_ERROR );\r
}\r
\r
- socketStatus = SOCKETS_Connect( tcpSocket,\r
- &serverAddress,\r
- sizeof( SocketsSockaddr_t ) );\r
+ socketStatus = FreeRTOS_connect( tcpSocket,\r
+ &serverAddress,\r
+ sizeof( serverAddress ) );\r
\r
- if( socketStatus != SOCKETS_ERROR_NONE )\r
+ if( socketStatus != 0 )\r
{\r
IotLogError( "Failed to establish new connection." );\r
IOT_SET_AND_GOTO_CLEANUP( IOT_NETWORK_SYSTEM_ERROR );\r
}\r
\r
/* Set a long timeout for receive. */\r
- socketStatus = SOCKETS_SetSockOpt( tcpSocket,\r
- 0,\r
- SOCKETS_SO_RCVTIMEO,\r
- &receiveTimeout,\r
- sizeof( TickType_t ) );\r
+ socketStatus = FreeRTOS_setsockopt( tcpSocket,\r
+ 0,\r
+ FREERTOS_SO_RCVTIMEO,\r
+ &receiveTimeout,\r
+ sizeof( TickType_t ) );\r
\r
- if( socketStatus != SOCKETS_ERROR_NONE )\r
+ if( socketStatus != 0 )\r
{\r
IotLogError( "Failed to set socket receive timeout." );\r
IOT_SET_AND_GOTO_CLEANUP( IOT_NETWORK_SYSTEM_ERROR );\r
/* Clean up on failure. */\r
if( status != IOT_NETWORK_SUCCESS )\r
{\r
- if( tcpSocket != SOCKETS_INVALID_SOCKET )\r
+ if( tcpSocket != FREERTOS_INVALID_SOCKET )\r
{\r
- SOCKETS_Close( tcpSocket );\r
+ FreeRTOS_closesocket( tcpSocket );\r
}\r
\r
/* Clear the connection information. */\r
/* Set the socket. */\r
pNewNetworkConnection->socket = tcpSocket;\r
\r
- /* Create the connection event flags and mutex. */\r
- pConnectionFlags = xEventGroupCreateStatic( &( pNewNetworkConnection->connectionFlags ) );\r
- pConnectionMutex = xSemaphoreCreateMutexStatic( &( pNewNetworkConnection->socketMutex ) );\r
-\r
- /* Static event flags and mutex creation should never fail. The handles\r
- * should point inside the connection object. */\r
- configASSERT( pConnectionFlags == ( EventGroupHandle_t ) &( pNewNetworkConnection->connectionFlags ) );\r
- configASSERT( pConnectionMutex == ( SemaphoreHandle_t ) &( pNewNetworkConnection->socketMutex ) );\r
+ /* Create the connection event group and socket mutex. */\r
+ pNewNetworkConnection->connectionEventGroup = xEventGroupCreateStatic( &( pNewNetworkConnection->connectionEventGroupStorage ) );\r
+ pNewNetworkConnection->socketMutex = xSemaphoreCreateMutexStatic( &( pNewNetworkConnection->socketMutexStorage ) );\r
\r
/* Set the output parameter. */\r
*pNetworkConnection = pNewNetworkConnection;\r
\r
IOT_FUNCTION_CLEANUP_END();\r
}\r
-\r
/*-----------------------------------------------------------*/\r
\r
-IotNetworkError_t IotNetworkAfr_SetReceiveCallback( void * pConnection,\r
- IotNetworkReceiveCallback_t receiveCallback,\r
- void * pContext )\r
+IotNetworkError_t IotNetworkFreeRTOS_SetReceiveCallback( void * pConnection,\r
+ IotNetworkReceiveCallback_t receiveCallback,\r
+ void * pContext )\r
{\r
IotNetworkError_t status = IOT_NETWORK_SUCCESS;\r
\r
pNetworkConnection->receiveCallback = receiveCallback;\r
pNetworkConnection->pReceiveContext = pContext;\r
\r
- /* No flags should be set. */\r
- configASSERT( xEventGroupGetBits( ( EventGroupHandle_t ) &( pNetworkConnection->connectionFlags ) ) == 0 );\r
+ /* No bit should be set in the connection event group. */\r
+ configASSERT( xEventGroupGetBits( pNetworkConnection->connectionEventGroup ) == 0 );\r
\r
/* Create task that waits for incoming data. */\r
if( xTaskCreate( _networkReceiveTask,\r
\r
return status;\r
}\r
-\r
/*-----------------------------------------------------------*/\r
\r
-size_t IotNetworkAfr_Send( void * pConnection,\r
- const uint8_t * pMessage,\r
- size_t messageLength )\r
+size_t IotNetworkFreeRTOS_Send( void * pConnection,\r
+ const uint8_t * pMessage,\r
+ size_t messageLength )\r
{\r
size_t bytesSent = 0;\r
- int32_t socketStatus = SOCKETS_ERROR_NONE;\r
+ int32_t socketStatus = 0;\r
\r
/* Cast network connection to the correct type. */\r
_networkConnection_t * pNetworkConnection = ( _networkConnection_t * ) pConnection;\r
\r
/* Only one thread at a time may send on the connection. Lock the socket\r
* mutex to prevent other threads from sending. */\r
- if( xSemaphoreTake( ( QueueHandle_t ) &( pNetworkConnection->socketMutex ),\r
- portMAX_DELAY ) == pdTRUE )\r
+ if( xSemaphoreTake( pNetworkConnection->socketMutex, portMAX_DELAY ) == pdTRUE )\r
{\r
- socketStatus = SOCKETS_Send( pNetworkConnection->socket,\r
- pMessage,\r
- messageLength,\r
- 0 );\r
+ socketStatus = FreeRTOS_send( pNetworkConnection->socket,\r
+ pMessage,\r
+ messageLength,\r
+ 0 );\r
\r
if( socketStatus > 0 )\r
{\r
bytesSent = ( size_t ) socketStatus;\r
}\r
\r
- xSemaphoreGive( ( QueueHandle_t ) &( pNetworkConnection->socketMutex ) );\r
+ xSemaphoreGive( pNetworkConnection->socketMutex );\r
}\r
\r
return bytesSent;\r
}\r
-\r
/*-----------------------------------------------------------*/\r
\r
-size_t IotNetworkAfr_Receive( void * pConnection,\r
- uint8_t * pBuffer,\r
- size_t bytesRequested )\r
+size_t IotNetworkFreeRTOS_Receive( void * pConnection,\r
+ uint8_t * pBuffer,\r
+ size_t bytesRequested )\r
{\r
int32_t socketStatus = 0;\r
size_t bytesReceived = 0, bytesRemaining = bytesRequested;\r
/* Block and wait for incoming data. */\r
while( bytesRemaining > 0 )\r
{\r
- socketStatus = SOCKETS_Recv( pNetworkConnection->socket,\r
- pBuffer + bytesReceived,\r
- bytesRemaining,\r
- 0 );\r
+ socketStatus = FreeRTOS_recv( pNetworkConnection->socket,\r
+ pBuffer + bytesReceived,\r
+ bytesRemaining,\r
+ 0 );\r
\r
- if( socketStatus == SOCKETS_EWOULDBLOCK )\r
+ if( socketStatus == FREERTOS_EWOULDBLOCK )\r
{\r
/* The return value EWOULDBLOCK means no data was received within\r
* the socket timeout. Ignore it and try again. */\r
\r
return bytesReceived;\r
}\r
-\r
/*-----------------------------------------------------------*/\r
\r
-IotNetworkError_t IotNetworkAfr_Close( void * pConnection )\r
+IotNetworkError_t IotNetworkFreeRTOS_Close( void * pConnection )\r
{\r
- int32_t socketStatus = SOCKETS_ERROR_NONE;\r
+ int32_t socketStatus = 0;\r
\r
/* Cast network connection to the correct type. */\r
_networkConnection_t * pNetworkConnection = ( _networkConnection_t * ) pConnection;\r
\r
- /* Call Secure Sockets shutdown function to close connection. */\r
- socketStatus = SOCKETS_Shutdown( pNetworkConnection->socket,\r
- SOCKETS_SHUT_RDWR );\r
+ /* Call socket shutdown function to close connection. */\r
+ socketStatus = FreeRTOS_shutdown( pNetworkConnection->socket,\r
+ FREERTOS_SHUT_RDWR );\r
\r
- if( socketStatus != SOCKETS_ERROR_NONE )\r
+ if( socketStatus != 0 )\r
{\r
IotLogWarn( "Failed to close connection." );\r
}\r
\r
- /* Set the shutdown flag. */\r
- ( void ) xEventGroupSetBits( ( EventGroupHandle_t ) &( pNetworkConnection->connectionFlags ),\r
- _FLAG_SHUTDOWN );\r
+ /* Set the shutdown bit in the connection event group. */\r
+ ( void ) xEventGroupSetBits( pNetworkConnection->connectionEventGroup,\r
+ _SHUTDOWN_BITMASK );\r
\r
return IOT_NETWORK_SUCCESS;\r
}\r
-\r
/*-----------------------------------------------------------*/\r
\r
-IotNetworkError_t IotNetworkAfr_Destroy( void * pConnection )\r
+IotNetworkError_t IotNetworkFreeRTOS_Destroy( void * pConnection )\r
{\r
/* Cast network connection to the correct type. */\r
_networkConnection_t * pNetworkConnection = ( _networkConnection_t * ) pConnection;\r
/* Check if this function is being called from the receive task. */\r
if( xTaskGetCurrentTaskHandle() == pNetworkConnection->receiveTask )\r
{\r
- /* Set the flag specifying that the connection is destroyed. */\r
- ( void ) xEventGroupSetBits( ( EventGroupHandle_t ) &( pNetworkConnection->connectionFlags ),\r
- _FLAG_CONNECTION_DESTROYED );\r
+ /* Set the bit specifying that the connection is destroyed. */\r
+ ( void ) xEventGroupSetBits( pNetworkConnection->connectionEventGroup,\r
+ _CONNECTION_DESTROYED_BITMASK );\r
}\r
else\r
{\r
/* If a receive task was created, wait for it to exit. */\r
if( pNetworkConnection->receiveTask != NULL )\r
{\r
- ( void ) xEventGroupWaitBits( ( EventGroupHandle_t ) &( pNetworkConnection->connectionFlags ),\r
- _FLAG_RECEIVE_TASK_EXITED,\r
+ ( void ) xEventGroupWaitBits( pNetworkConnection->connectionEventGroup,\r
+ _RECEIVE_TASK_EXITED_BITMASK,\r
pdTRUE,\r
pdTRUE,\r
portMAX_DELAY );\r
\r
return IOT_NETWORK_SUCCESS;\r
}\r
-\r
/*-----------------------------------------------------------*/\r
+++ /dev/null
-/*\r
- * Amazon FreeRTOS Secure Sockets V1.1.5\r
- * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.\r
- *\r
- * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
- * this software and associated documentation files (the "Software"), to deal in\r
- * the Software without restriction, including without limitation the rights to\r
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
- * the Software, and to permit persons to whom the Software is furnished to do so,\r
- * subject to the following conditions:\r
- *\r
- * The above copyright notice and this permission notice shall be included in all\r
- * copies or substantial portions of the Software.\r
- *\r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
- * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
- *\r
- * http://aws.amazon.com/freertos\r
- * http://www.FreeRTOS.org\r
- */\r
-\r
-/* Define _SECURE_SOCKETS_WRAPPER_NOT_REDEFINE to prevent secure sockets functions\r
- * from redefining in iot_secure_sockets_wrapper_metrics.h */\r
-#define _SECURE_SOCKETS_WRAPPER_NOT_REDEFINE\r
-\r
-/* FreeRTOS includes. */\r
-#include "FreeRTOS.h"\r
-#include "FreeRTOSIPConfig.h"\r
-#include "list.h"\r
-#include "semphr.h"\r
-#include "FreeRTOS_IP.h"\r
-#include "FreeRTOS_Sockets.h"\r
-#include "iot_secure_sockets.h"\r
-#include "task.h"\r
-\r
-#undef _SECURE_SOCKETS_WRAPPER_NOT_REDEFINE\r
-\r
-/* Internal context structure. */\r
-typedef struct SSOCKETContext\r
-{\r
- Socket_t xSocket;\r
- char * pcDestination;\r
- BaseType_t xSendFlags;\r
- BaseType_t xRecvFlags;\r
- BaseType_t xConnectAttempted;\r
-} SSOCKETContext_t, * SSOCKETContextPtr_t;\r
-\r
-/*\r
- * Helper routines.\r
- */\r
-\r
-/*\r
- * @brief Network send callback.\r
- */\r
-static BaseType_t prvNetworkSend( void * pvContext,\r
- const unsigned char * pucData,\r
- size_t xDataLength )\r
-{\r
- SSOCKETContextPtr_t pxContext = ( SSOCKETContextPtr_t ) pvContext; /*lint !e9087 cast used for portability. */\r
-\r
- return FreeRTOS_send( pxContext->xSocket, pucData, xDataLength, pxContext->xSendFlags );\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-/*\r
- * @brief Network receive callback.\r
- */\r
-static BaseType_t prvNetworkRecv( void * pvContext,\r
- unsigned char * pucReceiveBuffer,\r
- size_t xReceiveLength )\r
-{\r
- SSOCKETContextPtr_t pxContext = ( SSOCKETContextPtr_t ) pvContext; /*lint !e9087 cast used for portability. */\r
-\r
- return FreeRTOS_recv( pxContext->xSocket, pucReceiveBuffer, xReceiveLength, pxContext->xRecvFlags );\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-/*\r
- * Interface routines.\r
- */\r
-\r
-int32_t SOCKETS_Close( Socket_t xSocket )\r
-{\r
- SSOCKETContextPtr_t pxContext = ( SSOCKETContextPtr_t ) xSocket; /*lint !e9087 cast used for portability. */\r
- int32_t lReturn;\r
-\r
- if( ( xSocket != SOCKETS_INVALID_SOCKET ) && ( NULL != pxContext ) )\r
- {\r
- /* Clean-up destination string. */\r
- if( NULL != pxContext->pcDestination )\r
- {\r
- vPortFree( pxContext->pcDestination );\r
- }\r
-\r
- /* Close the underlying socket handle. */\r
- ( void ) FreeRTOS_closesocket( pxContext->xSocket );\r
-\r
- /* Free the context. */\r
- vPortFree( pxContext );\r
- lReturn = SOCKETS_ERROR_NONE;\r
- }\r
- else\r
- {\r
- lReturn = SOCKETS_EINVAL;\r
- }\r
-\r
- return lReturn;\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-int32_t SOCKETS_Connect( Socket_t xSocket,\r
- SocketsSockaddr_t * pxAddress,\r
- Socklen_t xAddressLength )\r
-{\r
- int32_t lStatus = SOCKETS_ERROR_NONE;\r
- SSOCKETContextPtr_t pxContext = ( SSOCKETContextPtr_t ) xSocket; /*lint !e9087 cast used for portability. */\r
- struct freertos_sockaddr xTempAddress = { 0 };\r
-\r
- if( ( pxContext != SOCKETS_INVALID_SOCKET ) && ( pxAddress != NULL ) )\r
- {\r
- /* A connection was attempted. If this function fails, then the socket is invalid and the user\r
- * must call SOCKETS_Close(), on this socket, and SOCKETS_Socket() to get a new socket. */\r
- pxContext->xConnectAttempted = pdTRUE;\r
-\r
- /* Connect the wrapped socket. */\r
- xTempAddress.sin_addr = pxAddress->ulAddress;\r
- xTempAddress.sin_family = pxAddress->ucSocketDomain;\r
- xTempAddress.sin_len = ( uint8_t ) sizeof( xTempAddress );\r
- xTempAddress.sin_port = pxAddress->usPort;\r
- lStatus = FreeRTOS_connect( pxContext->xSocket, &xTempAddress, xAddressLength );\r
- }\r
- else\r
- {\r
- lStatus = SOCKETS_SOCKET_ERROR;\r
- }\r
-\r
- return lStatus;\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-uint32_t SOCKETS_GetHostByName( const char * pcHostName )\r
-{\r
- return FreeRTOS_gethostbyname( pcHostName );\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-int32_t SOCKETS_Recv( Socket_t xSocket,\r
- void * pvBuffer,\r
- size_t xBufferLength,\r
- uint32_t ulFlags )\r
-{\r
- int32_t lStatus = SOCKETS_SOCKET_ERROR;\r
- SSOCKETContextPtr_t pxContext = ( SSOCKETContextPtr_t ) xSocket; /*lint !e9087 cast used for portability. */\r
-\r
- if( ( xSocket != SOCKETS_INVALID_SOCKET ) &&\r
- ( pvBuffer != NULL ) )\r
- {\r
- pxContext->xRecvFlags = ( BaseType_t ) ulFlags;\r
-\r
- /* Receive unencrypted. */\r
- lStatus = prvNetworkRecv( pxContext, pvBuffer, xBufferLength );\r
- }\r
- else\r
- {\r
- lStatus = SOCKETS_EINVAL;\r
- }\r
-\r
- return lStatus;\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-int32_t SOCKETS_Send( Socket_t xSocket,\r
- const void * pvBuffer,\r
- size_t xDataLength,\r
- uint32_t ulFlags )\r
-{\r
- int32_t lStatus = SOCKETS_SOCKET_ERROR;\r
- SSOCKETContextPtr_t pxContext = ( SSOCKETContextPtr_t ) xSocket; /*lint !e9087 cast used for portability. */\r
-\r
- if( ( xSocket != SOCKETS_INVALID_SOCKET ) &&\r
- ( pvBuffer != NULL ) )\r
- {\r
- pxContext->xSendFlags = ( BaseType_t ) ulFlags;\r
-\r
- /* Send unencrypted. */\r
- lStatus = prvNetworkSend( pxContext, pvBuffer, xDataLength );\r
- }\r
- else\r
- {\r
- lStatus = SOCKETS_EINVAL;\r
- }\r
-\r
- return lStatus;\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-int32_t SOCKETS_SetSockOpt( Socket_t xSocket,\r
- int32_t lLevel,\r
- int32_t lOptionName,\r
- const void * pvOptionValue,\r
- size_t xOptionLength )\r
-{\r
- int32_t lStatus = SOCKETS_ERROR_NONE;\r
- TickType_t xTimeout;\r
- SSOCKETContextPtr_t pxContext = ( SSOCKETContextPtr_t ) xSocket; /*lint !e9087 cast used for portability. */\r
-\r
- if( ( xSocket != SOCKETS_INVALID_SOCKET ) && ( xSocket != NULL ) )\r
- {\r
- switch( lOptionName )\r
- {\r
- case SOCKETS_SO_NONBLOCK:\r
- xTimeout = 0;\r
-\r
- /* Non-blocking connect is not supported. Socket may be set to nonblocking\r
- * only after a connection is made. */\r
- if( pdTRUE == pxContext->xConnectAttempted )\r
- {\r
- lStatus = FreeRTOS_setsockopt( pxContext->xSocket,\r
- lLevel,\r
- SOCKETS_SO_RCVTIMEO,\r
- &xTimeout,\r
- sizeof( xTimeout ) );\r
-\r
- if( lStatus == SOCKETS_ERROR_NONE )\r
- {\r
- lStatus = FreeRTOS_setsockopt( pxContext->xSocket,\r
- lLevel,\r
- SOCKETS_SO_SNDTIMEO,\r
- &xTimeout,\r
- sizeof( xTimeout ) );\r
- }\r
- }\r
- else\r
- {\r
- lStatus = SOCKETS_EISCONN;\r
- }\r
-\r
- break;\r
-\r
- case SOCKETS_SO_RCVTIMEO:\r
- case SOCKETS_SO_SNDTIMEO:\r
- /* Comply with Berkeley standard - a 0 timeout is wait forever. */\r
- xTimeout = *( ( const TickType_t * ) pvOptionValue ); /*lint !e9087 pvOptionValue passed should be of TickType_t */\r
-\r
- if( xTimeout == 0U )\r
- {\r
- xTimeout = portMAX_DELAY;\r
- }\r
-\r
- lStatus = FreeRTOS_setsockopt( pxContext->xSocket,\r
- lLevel,\r
- lOptionName,\r
- &xTimeout,\r
- xOptionLength );\r
- break;\r
-\r
- default:\r
- lStatus = FreeRTOS_setsockopt( pxContext->xSocket,\r
- lLevel,\r
- lOptionName,\r
- pvOptionValue,\r
- xOptionLength );\r
- break;\r
- }\r
- }\r
- else\r
- {\r
- lStatus = SOCKETS_EINVAL;\r
- }\r
-\r
- return lStatus;\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-int32_t SOCKETS_Shutdown( Socket_t xSocket,\r
- uint32_t ulHow )\r
-{\r
- int32_t lReturn;\r
- SSOCKETContextPtr_t pxContext = ( SSOCKETContextPtr_t ) xSocket; /*lint !e9087 cast used for portability. */\r
-\r
- if( ( xSocket != SOCKETS_INVALID_SOCKET ) && ( xSocket != NULL ) )\r
- {\r
- lReturn = FreeRTOS_shutdown( pxContext->xSocket, ( BaseType_t ) ulHow );\r
- }\r
- else\r
- {\r
- lReturn = SOCKETS_EINVAL;\r
- }\r
-\r
- return lReturn;\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-Socket_t SOCKETS_Socket( int32_t lDomain,\r
- int32_t lType,\r
- int32_t lProtocol )\r
-{\r
- SSOCKETContextPtr_t pxContext = NULL;\r
- Socket_t xSocket;\r
-\r
- /* Ensure that only supported values are supplied. */\r
- configASSERT( lDomain == SOCKETS_AF_INET );\r
- configASSERT( lType == SOCKETS_SOCK_STREAM );\r
- configASSERT( lProtocol == SOCKETS_IPPROTO_TCP );\r
-\r
- /* Create the wrapped socket. */\r
- xSocket = FreeRTOS_socket( lDomain, lType, lProtocol );\r
-\r
- if( xSocket != FREERTOS_INVALID_SOCKET )\r
- {\r
- /* Allocate the internal context structure. */\r
- if( NULL == ( pxContext = pvPortMalloc( sizeof( SSOCKETContext_t ) ) ) )\r
- {\r
- /* Need to close socket. */\r
- ( void ) FreeRTOS_closesocket( xSocket );\r
- pxContext = SOCKETS_INVALID_SOCKET;\r
- }\r
- else\r
- {\r
- memset( pxContext, 0, sizeof( SSOCKETContext_t ) );\r
- pxContext->xSocket = xSocket;\r
- }\r
- }\r
- else\r
- {\r
- pxContext = SOCKETS_INVALID_SOCKET;\r
- }\r
-\r
- return pxContext;\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-BaseType_t SOCKETS_Init( void )\r
-{\r
- /* Empty initialization for this port. */\r
- return pdPASS;\r
-}\r
-/*-----------------------------------------------------------*/\r
+++ /dev/null
-/*\r
- * Amazon FreeRTOS Secure Sockets V1.1.5\r
- * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.\r
- *\r
- * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
- * this software and associated documentation files (the "Software"), to deal in\r
- * the Software without restriction, including without limitation the rights to\r
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
- * the Software, and to permit persons to whom the Software is furnished to do so,\r
- * subject to the following conditions:\r
- *\r
- * The above copyright notice and this permission notice shall be included in all\r
- * copies or substantial portions of the Software.\r
- *\r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
- * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
- *\r
- * http://aws.amazon.com/freertos\r
- * http://www.FreeRTOS.org\r
- */\r
-\r
-/**\r
- * @file iot_secure_sockets.h\r
- * @brief Secure Sockets Interface.\r
- *\r
- * Secure sockets is a portable layer for establishing a TCP/IP\r
- * connection, with the option of using TLS.\r
- *\r
- * Secure sockets is based on the Berkeley sockets API.\r
- * A few difference general differences between Berkeley and SOCKETS are:\r
- * - SOCKETS has additional socket options to enable TLS, server name\r
- * indication, and per-socket root of trust server certificates. See\r
- * SOCKETS_SetSockOpt() for more information.\r
- * - SOCKETS API return an error code, rather than returning -1 and setting\r
- * a global errno value.\r
- *\r
- */\r
-\r
-#ifndef _AWS_SECURE_SOCKETS_H_\r
-#define _AWS_SECURE_SOCKETS_H_\r
-\r
-/*\r
- #ifdef __cplusplus\r
- * extern "C" {\r
- #endif\r
- */\r
-#include <stdint.h>\r
-#include <stddef.h>\r
-#include "iot_secure_sockets_config.h"\r
-#include "iot_secure_sockets_config_defaults.h"\r
-#include "iot_secure_sockets_wrapper_metrics.h"\r
-#include "iot_lib_init.h"\r
-\r
-/**\r
- * @ingroup SecureSockets_datatypes_handles\r
- * @brief The socket handle data type.\r
- *\r
- * For detail of socket, refer to [Network Sockets]\r
- * (https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/socket.html)\r
- *\r
- * Data contained by the Socket_t type is port specific.\r
- */\r
-typedef void * Socket_t;\r
-\r
-/**\r
- * @brief The "size_t" of secure sockets.\r
- *\r
- * This type is used for compatibility with the expected Berkeley sockets\r
- * naming.\r
- */\r
-#define Socklen_t uint32_t\r
-\r
-/**\r
- * @anchor SocketsErrors\r
- * @name SocketsErrors\r
- * @brief Error codes returned by the SOCKETS API.\r
- *\r
- * Note that SOCKETS API may also propagate port-specific\r
- * error codes when they are more descriptive. See your\r
- * port's error codes for more details.\r
- * PORT_SPECIFIC_LINK\r
- */\r
-/**@{ */\r
-\r
-#define SOCKETS_ERROR_NONE ( 0 ) /*!< No error. */\r
-#define SOCKETS_SOCKET_ERROR ( -1 ) /*!< Catch-all sockets error code. */\r
-#define SOCKETS_EWOULDBLOCK ( -11 ) /*!< A resource is temporarily unavailable. */\r
-#define SOCKETS_ENOMEM ( -12 ) /*!< Memory allocation failed. */\r
-#define SOCKETS_EINVAL ( -22 ) /*!< Invalid argument. */\r
-#define SOCKETS_ENOPROTOOPT ( -109 ) /*!< A bad option was specified . */\r
-#define SOCKETS_ENOTCONN ( -126 ) /*!< The supplied socket is not connected. */\r
-#define SOCKETS_EISCONN ( -127 ) /*!< The supplied socket is already connected. */\r
-#define SOCKETS_ECLOSED ( -128 ) /*!< The supplied socket has already been closed. */\r
-#define SOCKETS_TLS_INIT_ERROR ( -1001 ) /*!< TLS initialization failed. */\r
-#define SOCKETS_TLS_HANDSHAKE_ERROR ( -1002 ) /*!< TLS handshake failed. */\r
-#define SOCKETS_TLS_SERVER_UNVERIFIED ( -1003 ) /*!< A connection was made but the server could not be verified. It is recommended that the socket be closed. */\r
-#define SOCKETS_TLS_RECV_ERROR ( -1004 ) /*!< TLS receive operation failed. */\r
-#define SOCKETS_TLS_SEND_ERROR ( -1005 ) /*!< TLS send operation failed. */\r
-#define SOCKETS_PERIPHERAL_RESET ( -1006 ) /*!< Communications peripheral has been reset. */\r
-/**@} */\r
-\r
-/**\r
- * @brief Assigned to an Socket_t variable when the socket is not valid.\r
- */\r
-#define SOCKETS_INVALID_SOCKET ( ( Socket_t ) ~0U )\r
-\r
-/**\r
- * @anchor SocketDomains\r
- * @name SocketDomains\r
- *\r
- * @brief Options for the lDomain parameter of SOCKETS_Socket()\r
- * function.\r
- *\r
- * These select the protocol family to be used for communication.\r
- */\r
-/**@{ */\r
-#define SOCKETS_AF_INET ( 2 ) /*!< IPv4 Internet Protocols. */\r
-#define SOCKETS_PF_INET SOCKETS_AF_INET /*!< IPv4 Internet Protocol. */\r
-#define SOCKETS_AF_INET6 ( 10 ) /*!< IPv6 Internet Protocols. This option is currently not supported. */\r
-/**@} */\r
-\r
-/**\r
- * @anchor SocketTypes\r
- * @name SocketTypes\r
- *\r
- * @brief Options for the lType parameter of SOCKETS_Socket()\r
- * function.\r
- *\r
- * These specify the communication semantics.\r
- */\r
-/**@{ */\r
-#define SOCKETS_SOCK_DGRAM ( 2 ) /*!< Datagram. */\r
-#define SOCKETS_SOCK_STREAM ( 1 ) /*!< Byte-stream. */\r
-/**@} */\r
-\r
-/**\r
- * @anchor Protocols\r
- * @name Protocols\r
- *\r
- * @brief Options for the lProtocol parameter of SOCKETS_Socket() function.\r
- *\r
- */\r
-/**@{ */\r
-#define SOCKETS_IPPROTO_UDP ( 17 ) /*!< UDP. This option is currently not supported. */\r
-#define SOCKETS_IPPROTO_TCP ( 6 ) /*!< TCP. */\r
-/**@} */\r
-\r
-/**\r
- * @anchor SetSockOptOptions\r
- * @name SetSockOptOptions\r
- *\r
- * @brief Options for lOptionName in SOCKETS_SetSockOpt().\r
- *\r
- */\r
-/**@{ */\r
-#define SOCKETS_SO_RCVTIMEO ( 0 ) /**< Set the receive timeout. */\r
-#define SOCKETS_SO_SNDTIMEO ( 1 ) /**< Set the send timeout. */\r
-#define SOCKETS_SO_SNDBUF ( 4 ) /**< Set the size of the send buffer (TCP only). */\r
-#define SOCKETS_SO_RCVBUF ( 5 ) /**< Set the size of the receive buffer (TCP only). */\r
-#define SOCKETS_SO_SERVER_NAME_INDICATION ( 6 ) /**< Toggle client use of TLS SNI. */\r
-#define SOCKETS_SO_TRUSTED_SERVER_CERTIFICATE ( 7 ) /**< Override default TLS server certificate trust. Must be PEM encoded and length must include null terminator. */\r
-#define SOCKETS_SO_REQUIRE_TLS ( 8 ) /**< Toggle client enforcement of TLS. */\r
-#define SOCKETS_SO_NONBLOCK ( 9 ) /**< Socket is nonblocking. */\r
-#define SOCKETS_SO_ALPN_PROTOCOLS ( 10 ) /**< Application protocol list to be included in TLS ClientHello. */\r
-#define SOCKETS_SO_WAKEUP_CALLBACK ( 17 ) /**< Set the callback to be called whenever there is data available on the socket for reading. */\r
-\r
-/**@} */\r
-\r
-/**\r
- * @anchor ShutdownFlags <br>\r
- * @name ShutdownFlags\r
- *\r
- * @brief Options for the ulHow parameter in SOCKETS_Shutdown().\r
- */\r
-/**@{ */\r
-#define SOCKETS_SHUT_RD ( 0 ) /**< No further receives. */\r
-#define SOCKETS_SHUT_WR ( 1 ) /**< No further sends. */\r
-#define SOCKETS_SHUT_RDWR ( 2 ) /**< No further send or receive. */\r
-/**@} */\r
-\r
-/**\r
- * @brief Maximum length of an ASCII DNS name.\r
- */\r
-#define securesocketsMAX_DNS_NAME_LENGTH ( 253 )\r
-\r
-/**\r
- * @ingroup SecureSockets_datatypes_paramstructs\r
- * @brief Socket address.\r
- *\r
- * \sa PORT_SPECIFIC_LINK\r
- */\r
-typedef struct SocketsSockaddr\r
-{\r
- uint8_t ucLength; /**< Length of SocketsSockaddr structure. */\r
- uint8_t ucSocketDomain; /**< Only SOCKETS_AF_INET is supported. */\r
- uint16_t usPort; /**< Port number. Convention is to call this sin_port. */\r
- uint32_t ulAddress; /**< IP Address. Convention is to call this sin_addr. */\r
-} SocketsSockaddr_t;\r
-\r
-/**\r
- * @brief Well-known port numbers.\r
- */\r
-#define securesocketsDEFAULT_TLS_DESTINATION_PORT 443\r
-\r
-/**\r
- * @brief Secure Sockets library initialization function.\r
- *\r
- * This function does general initialization and setup. It must be called once\r
- * and only once before calling any other function.\r
- *\r
- * @return\r
- * * `pdPASS` if everything succeeds\r
- * * `pdFAIL` otherwise.\r
- */\r
-lib_initDECLARE_LIB_INIT( SOCKETS_Init );\r
-\r
-/**\r
- * @brief Creates a TCP socket.\r
- *\r
- * See the [FreeRTOS+TCP networking tutorial]\r
- * (https://freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_Networking_Tutorial.html)\r
- * for more information on TCP sockets.\r
- *\r
- * See the [Berkeley Sockets API]\r
- * (https://en.wikipedia.org/wiki/Berkeley_sockets#Socket_API_functions)\r
- * in wikipedia\r
- *\r
- * @sa SOCKETS_Close()\r
- *\r
- * @param[in] lDomain Must be set to SOCKETS_AF_INET. See @ref SocketDomains.\r
- * @param[in] lType Set to SOCKETS_SOCK_STREAM to create a TCP socket.\r
- * No other value is valid. See @ref SocketTypes.\r
- * @param[in] lProtocol Set to SOCKETS_IPPROTO_TCP to create a TCP socket.\r
- * No other value is valid. See @ref Protocols.\r
- *\r
- * @return\r
- * * If a socket is created successfully, then the socket handle is\r
- * returned\r
- * * @ref SOCKETS_INVALID_SOCKET is returned if an error occurred.\r
- */\r
-\r
-/*\r
- * This call allocates memory and claims a socket resource.\r
- */\r
-/* @[declare_secure_sockets_socket] */\r
-Socket_t SOCKETS_Socket( int32_t lDomain,\r
- int32_t lType,\r
- int32_t lProtocol );\r
-/* @[declare_secure_sockets_socket] */\r
-\r
-\r
-/**\r
- * @brief Connects the socket to the specified IP address and port.\r
- *\r
- * The socket must first have been successfully created by a call to SOCKETS_Socket().\r
- *\r
- * \note To create a secure socket, SOCKETS_SetSockOpt() should be called with the\r
- * SOCKETS_SO_REQUIRE_TLS option \a before SOCKETS_Connect() is called.\r
- *\r
- * If this function returns an error the socket is considered invalid.\r
- *\r
- * \warning SOCKETS_Connect() is not safe to be called on the same socket\r
- * from multiple threads simultaneously with SOCKETS_Connect(),\r
- * SOCKETS_SetSockOpt(), SOCKETS_Shutdown(), SOCKETS_Close().\r
- *\r
- * See the [Berkeley Sockets API]\r
- * (https://en.wikipedia.org/wiki/Berkeley_sockets#Socket_API_functions)\r
- * in wikipedia\r
- *\r
- * @param[in] xSocket The handle of the socket to be connected.\r
- * @param[in] pxAddress A pointer to a SocketsSockaddr_t structure that contains the\r
- * the address to connect the socket to.\r
- * @param[in] xAddressLength Should be set to sizeof( @ref SocketsSockaddr_t ).\r
- *\r
- * @return\r
- * * @ref SOCKETS_ERROR_NONE if a connection is established.\r
- * * If an error occurred, a negative value is returned. @ref SocketsErrors\r
- */\r
-/* @[declare_secure_sockets_connect] */\r
-int32_t SOCKETS_Connect( Socket_t xSocket,\r
- SocketsSockaddr_t * pxAddress,\r
- Socklen_t xAddressLength );\r
-/* @[declare_secure_sockets_connect] */\r
-\r
-/**\r
- * @brief Receive data from a TCP socket.\r
- *\r
- * The socket must have already been created using a call to SOCKETS_Socket()\r
- * and connected to a remote socket using SOCKETS_Connect().\r
- *\r
- * See the [Berkeley Sockets API]\r
- * (https://en.wikipedia.org/wiki/Berkeley_sockets#Socket_API_functions)\r
- * in wikipedia\r
- *\r
- * @param[in] xSocket The handle of the socket from which data is being received.\r
- * @param[out] pvBuffer The buffer into which the received data will be placed.\r
- * @param[in] xBufferLength The maximum number of bytes which can be received.\r
- * pvBuffer must be at least xBufferLength bytes long.\r
- * @param[in] ulFlags Not currently used. Should be set to 0.\r
- *\r
- * @return\r
- * * If the receive was successful then the number of bytes received (placed in the\r
- * buffer pointed to by pvBuffer) is returned.\r
- * * If a timeout occurred before data could be received then 0 is returned (timeout\r
- * is set using @ref SOCKETS_SO_RCVTIMEO).\r
- * * If an error occurred, a negative value is returned. @ref SocketsErrors\r
- */\r
-/* @[declare_secure_sockets_recv] */\r
-int32_t SOCKETS_Recv( Socket_t xSocket,\r
- void * pvBuffer,\r
- size_t xBufferLength,\r
- uint32_t ulFlags );\r
-/* @[declare_secure_sockets_recv] */\r
-\r
-/**\r
- * @brief Transmit data to the remote socket.\r
- *\r
- * The socket must have already been created using a call to SOCKETS_Socket() and\r
- * connected to a remote socket using SOCKETS_Connect().\r
- *\r
- * See the [Berkeley Sockets API]\r
- * (https://en.wikipedia.org/wiki/Berkeley_sockets#Socket_API_functions)\r
- * in wikipedia\r
- *\r
- * @param[in] xSocket The handle of the sending socket.\r
- * @param[in] pvBuffer The buffer containing the data to be sent.\r
- * @param[in] xDataLength The length of the data to be sent.\r
- * @param[in] ulFlags Not currently used. Should be set to 0.\r
- *\r
- * @return\r
- * * On success, the number of bytes actually sent is returned.\r
- * * If an error occurred, a negative value is returned. @ref SocketsErrors\r
- */\r
-/* @[declare_secure_sockets_send] */\r
-int32_t SOCKETS_Send( Socket_t xSocket,\r
- const void * pvBuffer,\r
- size_t xDataLength,\r
- uint32_t ulFlags );\r
-/* @[declare_secure_sockets_send] */\r
-\r
-/**\r
- * @brief Closes all or part of a full-duplex connection on the socket.\r
- *\r
- * Disable reads and writes on a connected TCP socket. A connected TCP socket must be gracefully\r
- * shut down before it can be closed.\r
- *\r
- * See the [Berkeley Sockets API]\r
- * (https://en.wikipedia.org/wiki/Berkeley_sockets#Socket_API_functions)\r
- * in wikipedia\r
- *\r
- * \warning SOCKETS_Shutdown() is not safe to be called on the same socket\r
- * from multiple threads simultaneously with SOCKETS_Connect(),\r
- * SOCKETS_SetSockOpt(), SOCKETS_Shutdown(), SOCKETS_Close().\r
- *\r
- * @param[in] xSocket The handle of the socket to shutdown.\r
- * @param[in] ulHow SOCKETS_SHUT_RD, SOCKETS_SHUT_WR or SOCKETS_SHUT_RDWR.\r
- * @ref ShutdownFlags\r
- *\r
- * @return\r
- * * If the operation was successful, 0 is returned.\r
- * * If an error occurred, a negative value is returned. @ref SocketsErrors\r
- */\r
-/* @[declare_secure_sockets_shutdown] */\r
-int32_t SOCKETS_Shutdown( Socket_t xSocket,\r
- uint32_t ulHow );\r
-/* @[declare_secure_sockets_shutdown] */\r
-\r
-/**\r
- * @brief Closes the socket and frees the related resources.\r
- *\r
- * A socket should be shutdown gracefully before it is closed, and cannot be used after it has been closed.\r
- *\r
- * See the [Berkeley Sockets API]\r
- * (https://en.wikipedia.org/wiki/Berkeley_sockets#Socket_API_functions)\r
- * in wikipedia\r
- *\r
- * \warning SOCKETS_Close() is not safe to be called on the same socket\r
- * from multiple threads simultaneously with SOCKETS_Connect(),\r
- * SOCKETS_SetSockOpt(), SOCKETS_Shutdown(), SOCKETS_Close().\r
- *\r
- * @param[in] xSocket The handle of the socket to close.\r
- *\r
- * @return\r
- * * On success, 0 is returned.\r
- * * If an error occurred, a negative value is returned. @ref SocketsErrors\r
- */\r
-/* @[declare_secure_sockets_close] */\r
-int32_t SOCKETS_Close( Socket_t xSocket );\r
-/* @[declare_secure_sockets_close] */\r
-\r
-/**\r
- * @brief AWS IoT ALPN protocol name for MQTT over TLS on server port 443.\r
- */\r
-#define socketsAWS_IOT_ALPN_MQTT "x-amzn-mqtt-ca"\r
-\r
-/**\r
- * @brief Manipulates the options for the socket.\r
- *\r
- * See the [Berkeley Sockets API]\r
- * (https://en.wikipedia.org/wiki/Berkeley_sockets#Socket_API_functions)\r
- * in wikipedia\r
- *\r
- * @param[in] xSocket The handle of the socket to set the option for.\r
- * @param[in] lLevel Not currently used. Should be set to 0.\r
- * @param[in] lOptionName See @ref SetSockOptOptions.\r
- * @param[in] pvOptionValue A buffer containing the value of the option to set.\r
- * @param[in] xOptionLength The length of the buffer pointed to by pvOptionValue.\r
- *\r
- * \warning SOCKETS_Close() is not safe to be called on the same socket\r
- * from multiple threads simultaneously with SOCKETS_Connect(),\r
- * SOCKETS_SetSockOpt(), SOCKETS_Shutdown(), SOCKETS_Close().\r
- *\r
- * @note Socket option support and possible values vary by port. Please see\r
- * PORT_SPECIFIC_LINK to check the valid options and limitations of your device.\r
- *\r
- * - Berkeley Socket Options\r
- * - @ref SOCKETS_SO_RCVTIMEO\r
- * - Sets the receive timeout\r
- * - pvOptionValue (TickType_t) is the number of milliseconds that the\r
- * receive function should wait before timing out.\r
- * - Setting pvOptionValue = 0 causes receive to wait forever.\r
- * - See PORT_SPECIFIC_LINK for device limitations.\r
- * - @ref SOCKETS_SO_SNDTIMEO\r
- * - Sets the send timeout\r
- * - pvOptionValue (TickType_t) is the number of milliseconds that the\r
- * send function should wait before timing out.\r
- * - Setting pvOptionValue = 0 causes send to wait forever.\r
- * - See PORT_SPECIFIC_LINK for device limitations.\r
- * - Non-Standard Options\r
- * - @ref SOCKETS_SO_NONBLOCK\r
- * - Makes a socket non-blocking.\r
- * - Non-blocking connect is not supported - socket option should be\r
- * called after connect.\r
- * - pvOptionValue is ignored for this option.\r
- * - @ref SOCKETS_SO_WAKEUP_CALLBACK\r
- * - Set the callback to be called whenever there is data available on\r
- * the socket for reading\r
- * - This option provides an asynchronous way to handle received data\r
- * - pvOptionValue is a pointer to the callback function\r
- * - See PORT_SPECIFIC_LINK for device limitations.\r
- * - Security Sockets Options\r
- * - @ref SOCKETS_SO_REQUIRE_TLS\r
- * - Use TLS for all connect, send, and receive on this socket.\r
- * - This socket options MUST be set for TLS to be used, even\r
- * if other secure socket options are set.\r
- * - This socket option should be set before SOCKETS_Connect() is\r
- * called.\r
- * - pvOptionValue is ignored for this option.\r
- * - @ref SOCKETS_SO_TRUSTED_SERVER_CERTIFICATE\r
- * - Set the root of trust server certificate for the socket.\r
- * - This socket option only takes effect if @ref SOCKETS_SO_REQUIRE_TLS\r
- * is also set. If @ref SOCKETS_SO_REQUIRE_TLS is not set,\r
- * this option will be ignored.\r
- * - pvOptionValue is a pointer to the formatted server certificate.\r
- * TODO: Link to description of how to format certificates with \n\r
- * - xOptionLength (BaseType_t) is the length of the certificate\r
- * in bytes.\r
- * - @ref SOCKETS_SO_SERVER_NAME_INDICATION\r
- * - Use Server Name Indication (SNI)\r
- * - This socket option only takes effect if @ref SOCKETS_SO_REQUIRE_TLS\r
- * is also set. If @ref SOCKETS_SO_REQUIRE_TLS is not set,\r
- * this option will be ignored.\r
- * - pvOptionValue is a pointer to a string containing the hostname\r
- * - xOptionLength is the length of the hostname string in bytes.\r
- * - @ref SOCKETS_SO_ALPN_PROTOCOLS\r
- * - Negotiate an application protocol along with TLS.\r
- * - The ALPN list is expressed as an array of NULL-terminated ANSI\r
- * strings.\r
- * - xOptionLength is the number of items in the array.\r
- *\r
- * @return\r
- * * On success, 0 is returned.\r
- * * If an error occurred, a negative value is returned. @ref SocketsErrors\r
- */\r
-/* @[declare_secure_sockets_setsockopt] */\r
-int32_t SOCKETS_SetSockOpt( Socket_t xSocket,\r
- int32_t lLevel,\r
- int32_t lOptionName,\r
- const void * pvOptionValue,\r
- size_t xOptionLength );\r
-/* @[declare_secure_sockets_setsockopt] */\r
-\r
-/**\r
- * @brief Resolve a host name using Domain Name Service.\r
- *\r
- * See the [Berkeley Sockets API]\r
- * (https://en.wikipedia.org/wiki/Berkeley_sockets#Socket_API_functions)\r
- * in wikipedia\r
- *\r
- * @param[in] pcHostName The host name to resolve.\r
- * @return\r
- * * The IPv4 address of the specified host.\r
- * * If an error has occurred, 0 is returned.\r
- */\r
-/* @[declare_secure_sockets_gethostbyname] */\r
-uint32_t SOCKETS_GetHostByName( const char * pcHostName );\r
-/* @[declare_secure_sockets_gethostbyname] */\r
-\r
-\r
-\r
-/**\r
- * @brief Convert an unsigned thirty-two-bit value from host endianness to network\r
- * endianness.\r
- *\r
- * @param[in] usIn The unsigned thirty-two-bit value to convert.\r
- */\r
-#if defined( socketsconfigBYTE_ORDER ) && ( socketsconfigBYTE_ORDER == pdLITTLE_ENDIAN )\r
- #define SOCKETS_htonl( ulIn ) ( ( uint32_t ) ( ( ( ulIn & 0xFF ) << 24 ) | ( ( ulIn & 0xFF00 ) << 8 ) | ( ( ulIn & 0xFF0000 ) >> 8 ) | ( ( ulIn & 0xFF000000 ) >> 24 ) ) )\r
-#else\r
- #define SOCKETS_htonl( usIn ) ( ( uint32_t ) ( usIn ) )\r
-#endif\r
-\r
-/**\r
- * @brief Convert an unsigned thirty-two-bit value from network endianness to host\r
- * endianness.\r
- *\r
- * @param[in] usIn The unsigned thirty-two-bit value to convert.\r
- */\r
-#define SOCKETS_ntohl( usIn ) SOCKETS_htonl( usIn )\r
-\r
-\r
-/**\r
- * @brief Convert an unsigned sixteen-bit value from host endianness to network\r
- * endianness.\r
- *\r
- * @param[in] usIn The unsigned sixteen-bit value to convert.\r
- */\r
-\r
-#if defined( socketsconfigBYTE_ORDER ) && ( socketsconfigBYTE_ORDER == pdLITTLE_ENDIAN )\r
- #define SOCKETS_htons( usIn ) ( ( uint16_t ) ( ( ( usIn ) << 8U ) | ( ( usIn ) >> 8U ) ) )\r
-#else\r
- #define SOCKETS_htons( usIn ) ( ( uint16_t ) ( usIn ) )\r
-#endif\r
-\r
-\r
-/**\r
- * @brief Convert an unsigned sixteen-bit value from network endianness to host\r
- * endianness.\r
- *\r
- * @param[in] usIn The unsigned sixteen-bit value to convert.\r
- */\r
-#define SOCKETS_ntohs( usIn ) SOCKETS_htons( usIn )\r
-\r
-/**\r
- * @brief Convert an IP address expressed as four separate numeric octets into a an IP address expressed as a 32-bit number in network byte order\r
- * (for example 192, 168, 0, 100)\r
- *\r
- * @param[in] ucOctet0 0th IP Octet\r
- * @param[in] ucOctet1 1st IP Octet\r
- * @param[in] ucOctet2 2nd IP Octet\r
- * @param[in] ucOctet3 3rd IP Octet\r
- */\r
-#if defined( socketsconfigBYTE_ORDER ) && ( socketsconfigBYTE_ORDER == pdLITTLE_ENDIAN )\r
-\r
- #define SOCKETS_inet_addr_quick( ucOctet0, ucOctet1, ucOctet2, ucOctet3 ) \\r
- ( ( ( ( uint32_t ) ( ucOctet3 ) ) << 24UL ) | \\r
- ( ( ( uint32_t ) ( ucOctet2 ) ) << 16UL ) | \\r
- ( ( ( uint32_t ) ( ucOctet1 ) ) << 8UL ) | \\r
- ( ( uint32_t ) ( ucOctet0 ) ) )\r
-\r
-/**\r
- * @brief Convert an IP address expressed as a 32-bit number in network byte order to a string in decimal dot notation.\r
- * (for example "192.168.0.100")\r
- *\r
- * @param[in] ulIPAddress An IP address expressed as a 32-bit value in network byte order.\r
- * @param[in] pucBuffer A pointer to a buffer into which the IP address will be written in decimal dot notation.\r
- */\r
- #define SOCKETS_inet_ntoa( ulIPAddress, pucBuffer ) \\r
- sprintf( ( char * ) ( pucBuffer ), "%u.%u.%u.%u", \\r
- ( ( unsigned ) ( ( ulIPAddress ) & 0xffUL ) ), \\r
- ( ( unsigned ) ( ( ( ulIPAddress ) >> 8 ) & 0xffUL ) ), \\r
- ( ( unsigned ) ( ( ( ulIPAddress ) >> 16 ) & 0xffUL ) ), \\r
- ( ( unsigned ) ( ( ulIPAddress ) >> 24 ) ) )\r
-\r
-#else /* socketsconfigBYTE_ORDER. */\r
-\r
- #define SOCKETS_inet_addr_quick( ucOctet0, ucOctet1, ucOctet2, ucOctet3 ) \\r
- ( ( ( ( uint32_t ) ( ucOctet0 ) ) << 24UL ) | \\r
- ( ( ( uint32_t ) ( ucOctet1 ) ) << 16UL ) | \\r
- ( ( ( uint32_t ) ( ucOctet2 ) ) << 8UL ) | \\r
- ( ( uint32_t ) ( ucOctet3 ) ) )\r
-\r
-/**\r
- * @brief Convert an IP address expressed as a 32-bit number in network byte order to a string in decimal dot notation.\r
- * (for example "192.168.0.100")\r
- *\r
- * @param[in] ulIPAddress An IP address expressed as a 32-bit value in network byte order.\r
- * @param[in] pucBuffer A pointer to a buffer into which the IP address will be written in decimal dot notation.\r
- */\r
- #define SOCKETS_inet_ntoa( ulIPAddress, pucBuffer ) \\r
- sprintf( ( char * ) ( pucBuffer ), "%u.%u.%u.%u", \\r
- ( ( unsigned ) ( ( ulIPAddress ) >> 24 ) ), \\r
- ( ( unsigned ) ( ( ( ulIPAddress ) >> 16 ) & 0xffUL ) ), \\r
- ( ( unsigned ) ( ( ( ulIPAddress ) >> 8 ) & 0xffUL ) ), \\r
- ( ( unsigned ) ( ( ulIPAddress ) & 0xffUL ) ) )\r
-\r
-#endif /* socketsconfigBYTE_ORDER. */\r
-\r
-/*\r
- #ifdef __cplusplus\r
- * }\r
- #endif\r
- */\r
-\r
-#endif /* _AWS_SECURE_SOCKETS_H_ */\r
+++ /dev/null
-/*\r
- * Amazon FreeRTOS Secure Sockets V1.1.5\r
- * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.\r
- *\r
- * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
- * this software and associated documentation files (the "Software"), to deal in\r
- * the Software without restriction, including without limitation the rights to\r
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
- * the Software, and to permit persons to whom the Software is furnished to do so,\r
- * subject to the following conditions:\r
- *\r
- * The above copyright notice and this permission notice shall be included in all\r
- * copies or substantial portions of the Software.\r
- *\r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
- * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
- *\r
- * http://aws.amazon.com/freertos\r
- * http://www.FreeRTOS.org\r
- */\r
-\r
-/**\r
- * @file iot_secure_sockets_config_defaults.h\r
- * @brief Ensures that the required sockets configuration options are supplied\r
- * and the optional ones are set to sane values if the user does not supply.\r
- */\r
-\r
-#ifndef AWS_INC_SECURE_SOCKETS_CONFIG_DEFAULTS_H_\r
-#define AWS_INC_SECURE_SOCKETS_CONFIG_DEFAULTS_H_\r
-\r
-/**\r
- * @brief Byte order of the target MCU must be defined.\r
- *\r
- * Valid values are pdLITTLE_ENDIAN and pdBIG_ENDIAN.\r
- */\r
-#ifndef socketsconfigBYTE_ORDER\r
- #error "socketsconfigBYTE_ORDER must be defined."\r
-#endif\r
-\r
-/**\r
- * @brief Default socket send timeout.\r
- *\r
- * The user can change the send timeout for a socket using the SOCKETS_SetSockOpt API\r
- * with the SOCKETS_SO_SNDTIMEO option.\r
- */\r
-#ifndef socketsconfigDEFAULT_SEND_TIMEOUT\r
- #define socketsconfigDEFAULT_SEND_TIMEOUT ( 10000 )\r
-#endif\r
-\r
-/**\r
- * @brief Default socket receive timeout.\r
- *\r
- * The user can change the receive timeout for a socket using the SOCKETS_SetSockOpt API\r
- * with the SOCKETS_SO_RCVTIMEO option.\r
- */\r
-#ifndef socketsconfigDEFAULT_RECV_TIMEOUT\r
- #define socketsconfigDEFAULT_RECV_TIMEOUT ( 10000 )\r
-#endif\r
-\r
-/**\r
- * @brief By default, metrics of secure socket is disabled.\r
- *\r
- */\r
-#ifndef AWS_IOT_SECURE_SOCKETS_METRICS_ENABLED\r
- #define AWS_IOT_SECURE_SOCKETS_METRICS_ENABLED ( 0 )\r
-#endif\r
-\r
-#endif /* AWS_INC_SECURE_SOCKETS_CONFIG_DEFAULTS_H_ */\r
+++ /dev/null
-/*\r
- * Amazon FreeRTOS Secure Sockets V1.1.5\r
- * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.\r
- *\r
- * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
- * this software and associated documentation files (the "Software"), to deal in\r
- * the Software without restriction, including without limitation the rights to\r
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
- * the Software, and to permit persons to whom the Software is furnished to do so,\r
- * subject to the following conditions:\r
- *\r
- * The above copyright notice and this permission notice shall be included in all\r
- * copies or substantial portions of the Software.\r
- *\r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
- * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
- *\r
- * http://aws.amazon.com/freertos\r
- * http://www.FreeRTOS.org\r
- */\r
-\r
-#ifndef _AWS_SECURE_SOCKETS_WRAPPER_METRICS_\r
-#define _AWS_SECURE_SOCKETS_WRAPPER_METRICS_\r
-\r
-/* This file redefines Secure Sockets functions to be called through a wrapper macro,\r
- * but only if metrics is enabled explicitly. */\r
-#if AWS_IOT_SECURE_SOCKETS_METRICS_ENABLED == 1\r
-\r
-/* This macro is included in aws_secure_socket.c and aws_secure_socket_wrapper_metrics.c.\r
- * It will prevent the redefine in those source files. */\r
- #ifndef _SECURE_SOCKETS_WRAPPER_NOT_REDEFINE\r
- #define SOCKETS_Init Sockets_MetricsInit\r
- #define SOCKETS_Connect Sockets_MetricsConnect\r
- #define SOCKETS_Shutdown Sockets_MetricsShutdown\r
- #endif\r
-\r
-#endif\r
-\r
-#endif /* ifndef _AWS_SECURE_SOCKETS_WRAPPER_METRICS_ */\r
+++ /dev/null
-/*\r
- * Amazon FreeRTOS Common V1.0.0\r
- * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.\r
- *\r
- * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
- * this software and associated documentation files (the "Software"), to deal in\r
- * the Software without restriction, including without limitation the rights to\r
- * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
- * the Software, and to permit persons to whom the Software is furnished to do so,\r
- * subject to the following conditions:\r
- *\r
- * The above copyright notice and this permission notice shall be included in all\r
- * copies or substantial portions of the Software.\r
- *\r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
- * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
- * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
- * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
- *\r
- * http://aws.amazon.com/freertos\r
- * http://www.FreeRTOS.org\r
- */\r
-\r
-#ifndef _AWS_LIB_INIT_H_\r
-#define _AWS_LIB_INIT_H_\r
-\r
-#include "FreeRTOS.h"\r
-\r
-#define lib_initDECLARE_LIB_INIT( f ) extern BaseType_t f( void )\r
-\r
-#endif /* _AWS_LIB_INIT_H_ */\r