--- /dev/null
+/*\r
+ * FreeRTOS Kernel V10.2.1\r
+ * Copyright (C) 2017 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://www.FreeRTOS.org\r
+ * http://aws.amazon.com/freertos\r
+ *\r
+ * 1 tab == 4 spaces!\r
+ */\r
+\r
+/* Standard inclues. */\r
+#include <string.h>\r
+\r
+/* Kernel includes. */\r
+#include "FreeRTOS.h"\r
+#include "task.h"\r
+\r
+/* MQTT include. */\r
+#include "iot_mqtt.h"\r
+\r
+/* Platform FreeRTOS network include. */\r
+#include "platform/iot_network_freertos.h"\r
+\r
+/**\r
+ * @brief The keep-alive interval used for this example.\r
+ *\r
+ * An MQTT ping request will be sent periodically at this interval.\r
+ */\r
+#define mqttexampleKEEP_ALIVE_SECONDS ( 60 )\r
+\r
+/**\r
+ * @brief The timeout for MQTT operations in this example.\r
+ */\r
+#define mqttexampleMQTT_TIMEOUT_MS ( 5000 )\r
+\r
+/**\r
+ * @brief The MQTT client identifier used in this example.\r
+ */\r
+#define mqttexampleCLIENT_IDENTIFIER "mqttexampleclient"\r
+\r
+/**\r
+ * @brief Details of the MQTT broker to connect to.\r
+ *\r
+ * @note This example does not use TLS and therefore won't work with AWS IoT.\r
+ */\r
+#define mqttexampleMQTT_BROKER_ENDPOINT "10.60.214.105"\r
+#define mqttexampleMQTT_BROKER_PORT 1883\r
+\r
+/**\r
+ * @brief The topic to subscribe and publish to in the example.\r
+ */\r
+#define mqttexampleTOPIC "example/topic"\r
+\r
+/**\r
+ * @brief The MQTT message published in this example.\r
+ */\r
+#define mqttexampleMESSAGE "Hello World!"\r
+\r
+/**\r
+ * @brief Paramters to control the retry behaviour in case a QoS1 publish\r
+ * message gets lost.\r
+ *\r
+ * Retry every minutes up to a maximum of 5 retries.\r
+ */\r
+#define mqttexamplePUBLISH_RETRY_MS ( 1000 )\r
+#define mqttexamplePUBLISH_RETRY_LIMIT ( 5 )\r
+\r
+/**\r
+ * @brief The bit which is set in the demo task's notification value from the\r
+ * disconnect callback to inform the demo task about the MQTT disconnect.\r
+ */\r
+#define mqttexampleDISCONNECTED_BIT ( 1UL << 0UL )\r
+\r
+/**\r
+ * @brief The bit which is set in the demo task's notification value from the\r
+ * publish callback to inform the demo task about the message received from the\r
+ * MQTT broker.\r
+ */\r
+#define mqttexampleMESSAGE_RECEIVED_BIT ( 1UL << 1UL )\r
+/*-----------------------------------------------------------*/\r
+\r
+/**\r
+ * @brief The MQTT connection handle used in this example.\r
+ */\r
+static IotMqttConnection_t xMQTTConnection = IOT_MQTT_CONNECTION_INITIALIZER;\r
+/*-----------------------------------------------------------*/\r
+\r
+/**\r
+ * @brief The task used to demonstrate the MQTT API.\r
+ *\r
+ * @param[in] pvParameters Parmaters as passed at the time of task creation. Not\r
+ * used in this example.\r
+ */\r
+static void prvMQTTDemoTask( void *pvParameters );\r
+\r
+/**\r
+ * @brief The callback invoked by the MQTT library when the MQTT connection gets\r
+ * disconnected.\r
+ * \r
+ * @param[in] pvCallbackContext Callback context as provided at the time of\r
+ * connect.\r
+ * @param[in] pxCallbackParams Contains the reason why the MQTT connection was\r
+ * disconnected.\r
+ */\r
+static void prvExample_DisconnectCallback( void * pvCallbackContext,\r
+ IotMqttCallbackParam_t * pxCallbackParams );\r
+\r
+/**\r
+ * @brief The callback invoked by the MQTT library when a message is received on\r
+ * a subscribed topic from the MQTT broker.\r
+ * \r
+ * @param[in] pvCallbackContext Callback context as provided at the time of\r
+ * subscribe.\r
+ * @param[in] pxCallbackParams Contain the details about the received message - \r
+ * topic on which the message was received, the received message.\r
+ */\r
+static void prvExample_PublishCallback( void * pvCallbackContext,\r
+ IotMqttCallbackParam_t * pxCallbackParams );\r
+\r
+/**\r
+ * @brief Connects to the MQTT broker as specified in mqttexampleMQTT_BROKER_ENDPOINT\r
+ * and mqttexampleMQTT_BROKER_PORT.\r
+ * \r
+ * @note This example does not use TLS and therefore will not work with MQTT.\r
+ */\r
+static void prvMQTTConnect( void );\r
+\r
+/**\r
+ * @brief Subscribes to the topic as specified in mqttexampleTOPIC.\r
+ */\r
+static void prvMQTTSubscribe( void );\r
+\r
+/**\r
+ * @brief Publishes a messages mqttexampleMESSAGE on mqttexampleTOPIC topic.\r
+ */\r
+static void prvMQTTPublish( void );\r
+\r
+/**\r
+ * @brief Unsubscribes from the mqttexampleTOPIC topic.\r
+ */\r
+static void prvMQTTUnsubscribe( void );\r
+\r
+/**\r
+ * @brief Disconnects from the MQTT broker gracefully by sending an MQTT\r
+ * DISCONNECT message.\r
+ */\r
+static void prvMQTTDisconnect( void );\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvExample_DisconnectCallback( void * pvCallbackContext,\r
+ IotMqttCallbackParam_t * pxCallbackParams )\r
+{\r
+TaskHandle_t xDemoTaskHandle = ( TaskHandle_t ) pvCallbackContext;\r
+\r
+ /* Ensure that we initiated the disconnect. */\r
+ configASSERT( pxCallbackParams->u.disconnectReason == IOT_MQTT_DISCONNECT_CALLED );\r
+\r
+ /* Inform the demo task about the disconnect. */\r
+ xTaskNotify( xDemoTaskHandle,\r
+ mqttexampleDISCONNECTED_BIT,\r
+ eSetBits /* Set the mqttexampleDISCONNECTED_BIT in the demo task's notification value. */\r
+ );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvExample_PublishCallback( void * pvCallbackContext,\r
+ IotMqttCallbackParam_t * pxCallbackParams )\r
+{\r
+TaskHandle_t xDemoTaskHandle = ( TaskHandle_t ) pvCallbackContext;\r
+\r
+ /* Ensure that the message is received on the expected topic. */\r
+ configASSERT( pxCallbackParams->u.message.info.topicNameLength == strlen( mqttexampleTOPIC ) );\r
+ configASSERT( strncmp( pxCallbackParams->u.message.info.pTopicName,\r
+ mqttexampleTOPIC,\r
+ strlen( mqttexampleTOPIC ) ) == 0 );\r
+\r
+ /* Ensure that the expected message is received. */\r
+ configASSERT( pxCallbackParams->u.message.info.payloadLength == strlen( mqttexampleMESSAGE ) );\r
+ configASSERT( strncmp( pxCallbackParams->u.message.info.pPayload,\r
+ mqttexampleMESSAGE,\r
+ strlen( mqttexampleMESSAGE ) ) == 0 );\r
+\r
+ /* Ensure that the message QoS is as expected. */\r
+ configASSERT( pxCallbackParams->u.message.info.qos == IOT_MQTT_QOS_1 );\r
+\r
+ /* Inform the demo task about the message received from the MQTT broker. */\r
+ xTaskNotify( xDemoTaskHandle,\r
+ mqttexampleMESSAGE_RECEIVED_BIT,\r
+ eSetBits /* Set the mqttexampleMESSAGE_RECEIVED_BIT in the demo task's notification value. */\r
+ );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+void vStartSimpleMQTTDemo( void )\r
+{\r
+ /* This example uses a single application task, which in turn is used to\r
+ * connect, subscribe, publish, unsubscribe and disconnect from the MQTT\r
+ * broker. */\r
+ xTaskCreate( prvMQTTDemoTask, /* Function that implements the task. */\r
+ "MQTTDemo", /* Text name for the task - only used for debugging. */\r
+ configMINIMAL_STACK_SIZE, /* Size of stack (in words, not bytes) to allocate for the task. */\r
+ NULL, /* Task parameter - not used in this case. */\r
+ tskIDLE_PRIORITY, /* Task priority, must be between 0 and configMAX_PRIORITIES - 1. */\r
+ NULL ); /* Used to pass out a handle to the created task - not used in this case. */\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvMQTTDemoTask( void *pvParameters )\r
+{\r
+IotMqttError_t xResult;\r
+uint32_t ulNotificationValue = 0;\r
+const TickType_t xNoDelay = ( TickType_t ) 0;\r
+\r
+ /* Remove compiler warnings about unused parameters. */\r
+ ( void ) pvParameters;\r
+\r
+ /* MQTT library must be initialized before it can be used. This is just one\r
+ * time initialization. */\r
+ xResult = IotMqtt_Init();\r
+ configASSERT( xResult == IOT_MQTT_SUCCESS );\r
+\r
+ for( ; ; )\r
+ {\r
+ /* Don't expect any notifications to be pending yet. */\r
+ configASSERT( ulTaskNotifyTake( pdTRUE, xNoDelay ) == 0 );\r
+\r
+ /* Establish a connection to the MQTT broker. This example connects to\r
+ * the MQTT broker as specified in mqttexampleMQTT_BROKER_ENDPOINT and\r
+ * mqttexampleMQTT_BROKER_PORT at the top of this file. Please change\r
+ * it to the MQTT broker you want to connect to. Note that this example\r
+ * does not use TLS and therefore will not work with AWS IoT. */\r
+ prvMQTTConnect();\r
+\r
+ /* Subscribe to the topic as specified in mqttexampleTOPIC at the top\r
+ * of this file. */\r
+ prvMQTTSubscribe();\r
+\r
+ /* Publish a message on the mqttexampleTOPIC topic as specified at the\r
+ * top of this file. */\r
+ prvMQTTPublish();\r
+\r
+ /* Since we are subscribed on the same topic, we will get the same\r
+ * message back from the MQTT broker. Wait for the message to be\r
+ * received which is informed to us by the publish callback\r
+ * (prvExample_PublishCallback) by setting the mqttexampleMESSAGE_RECEIVED_BIT\r
+ * in this task's notification value. */\r
+ xTaskNotifyWait( 0UL, /* Don't clear any bits on entry. */\r
+ 0UL, /* Don't clear any bits on exit. */\r
+ &( ulNotificationValue ), /* Obtain the notification value. */\r
+ pdMS_TO_TICKS( mqttexampleMQTT_TIMEOUT_MS ) );\r
+ configASSERT( ( ulNotificationValue & mqttexampleMESSAGE_RECEIVED_BIT ) == mqttexampleMESSAGE_RECEIVED_BIT );\r
+\r
+ /* Unsubscribe from the topic mqttexampleTOPIC. */\r
+ prvMQTTUnsubscribe();\r
+\r
+ /* Gracefully disconnect from the MQTT broker by sending an MQTT\r
+ * DISCONNECT message. */\r
+ prvMQTTDisconnect();\r
+\r
+ /* Wait for the disconnect operation to complete which is informed to us\r
+ * by the disconnect callback (prvExample_DisconnectCallback)by setting\r
+ * the mqttexampleDISCONNECTED_BIT in this task's notification value.\r
+ * Note that all bits are cleared in the task's notification value to\r
+ * ensure that it is ready for the next run. */\r
+ xTaskNotifyWait( 0UL, /* Don't clear any bits on entry. */\r
+ portMAX_DELAY, /* Clear all bits on exit - portMAX_DELAY is used as it is a portable way of having all bits set. */\r
+ &( ulNotificationValue ), /* Obtain the notification value. */\r
+ pdMS_TO_TICKS( mqttexampleMQTT_TIMEOUT_MS ) );\r
+ configASSERT( ( ulNotificationValue & mqttexampleDISCONNECTED_BIT ) == mqttexampleDISCONNECTED_BIT );\r
+ }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvMQTTConnect( void )\r
+{\r
+IotMqttError_t xResult;\r
+IotNetworkServerInfo_t xMQTTBrokerInfo;\r
+IotMqttNetworkInfo_t xNetworkInfo = IOT_MQTT_NETWORK_INFO_INITIALIZER;\r
+IotMqttConnectInfo_t xConnectInfo = IOT_MQTT_CONNECT_INFO_INITIALIZER;\r
+\r
+ /******************* Broker information setup. **********************/\r
+ xMQTTBrokerInfo.pHostName = mqttexampleMQTT_BROKER_ENDPOINT;\r
+ xMQTTBrokerInfo.port = mqttexampleMQTT_BROKER_PORT;\r
+\r
+ /******************* Network information setup. **********************/\r
+ /* No connection to the MQTT broker has been established yet and we want to\r
+ * establish a new connection. */\r
+ xNetworkInfo.createNetworkConnection = true;\r
+ xNetworkInfo.u.setup.pNetworkServerInfo = &( xMQTTBrokerInfo );\r
+\r
+ /* This example does not use TLS and therefore pNetworkCredentialInfo must\r
+ * be set to NULL. */\r
+ xNetworkInfo.u.setup.pNetworkCredentialInfo = NULL;\r
+\r
+ /* Use FreeRTOS+TCP network. */\r
+ xNetworkInfo.pNetworkInterface = IOT_NETWORK_INTERFACE_AFR;\r
+\r
+ /* Setup the callback which is called when the MQTT connection is disconnected. */\r
+ xNetworkInfo.disconnectCallback.pCallbackContext = ( void * ) xTaskGetCurrentTaskHandle();\r
+ xNetworkInfo.disconnectCallback.function = prvExample_DisconnectCallback;\r
+\r
+ /****************** MQTT Connection information setup. ********************/\r
+ /* This example does not use TLS and therefore won't work with AWS IoT. */\r
+ xConnectInfo.awsIotMqttMode = false;\r
+\r
+ /* Start with a clean session i.e. direct the MQTT broker to discard any\r
+ * previous session data. Also, establishing a connection with clean session\r
+ * will ensure that the broker does not store any data when this client\r
+ * gets disconnected. */\r
+ xConnectInfo.cleanSession = true;\r
+\r
+ /* Since we are starting with a clean session, there are no previous\r
+ * subscriptions to be restored. */\r
+ xConnectInfo.pPreviousSubscriptions = NULL;\r
+ xConnectInfo.previousSubscriptionCount = 0;\r
+\r
+ /* We do not want to publish Last Will and Testament (LWT) message if the\r
+ * client gets disconnected. */\r
+ xConnectInfo.pWillInfo = NULL;\r
+\r
+ /* Send an MQTT PING request every minute. */\r
+ xConnectInfo.keepAliveSeconds = mqttexampleKEEP_ALIVE_SECONDS;\r
+\r
+ /* The client identifier is used to uniquely identify this MQTT client to\r
+ * the MQTT broker. */\r
+ xConnectInfo.pClientIdentifier = mqttexampleCLIENT_IDENTIFIER;\r
+ xConnectInfo.clientIdentifierLength = ( uint16_t ) strlen( mqttexampleCLIENT_IDENTIFIER );\r
+\r
+ /* This example does not use any authentication and therefore username and\r
+ * password fields are not used. */\r
+ xConnectInfo.pUserName = NULL;\r
+ xConnectInfo.userNameLength = 0;\r
+ xConnectInfo.pPassword = NULL;\r
+ xConnectInfo.passwordLength = 0;\r
+\r
+ /* Establish the connection to the MQTT broker - It is a blocking call and\r
+ will return only when connection is complete. */\r
+ xResult = IotMqtt_Connect( &( xNetworkInfo ),\r
+ &( xConnectInfo ),\r
+ mqttexampleMQTT_TIMEOUT_MS,\r
+ &( xMQTTConnection ) );\r
+ configASSERT( xResult == IOT_MQTT_SUCCESS );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvMQTTSubscribe( void )\r
+{\r
+IotMqttError_t xResult;\r
+IotMqttSubscription_t xMQTTSubscription;\r
+\r
+ /* Subscribe to the mqttexampleTOPIC topic filter. */\r
+ xMQTTSubscription.qos = IOT_MQTT_QOS_1;\r
+ xMQTTSubscription.pTopicFilter = mqttexampleTOPIC;\r
+ xMQTTSubscription.topicFilterLength = ( uint16_t ) strlen( mqttexampleTOPIC );\r
+ xMQTTSubscription.callback.pCallbackContext = ( void * ) xTaskGetCurrentTaskHandle();\r
+ xMQTTSubscription.callback.function = prvExample_PublishCallback;\r
+\r
+ /* Use the synchronous API to subscribe - It is a blocking call and only\r
+ * returns when the subscribe operation is complete. */\r
+ xResult = IotMqtt_TimedSubscribe( xMQTTConnection,\r
+ &( xMQTTSubscription ),\r
+ 1, /* We are subscribing to one topic filter. */\r
+ 0, /* flags - currently ignored. */\r
+ mqttexampleMQTT_TIMEOUT_MS );\r
+ configASSERT( xResult == IOT_MQTT_SUCCESS );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvMQTTPublish( void )\r
+{\r
+IotMqttError_t xResult;\r
+IotMqttPublishInfo_t xMQTTPublishInfo;\r
+\r
+ /* Publish a message with QoS1 on the mqttexampleTOPIC topic. Since we are\r
+ * subscribed to the same topic, the MQTT broker will send the same message\r
+ * back to us. It is verified in the publish callback. */\r
+ xMQTTPublishInfo.qos = IOT_MQTT_QOS_1;\r
+ xMQTTPublishInfo.retain = false;\r
+ xMQTTPublishInfo.pTopicName = mqttexampleTOPIC;\r
+ xMQTTPublishInfo.topicNameLength = ( uint16_t ) strlen( mqttexampleTOPIC );\r
+ xMQTTPublishInfo.pPayload = mqttexampleMESSAGE;\r
+ xMQTTPublishInfo.payloadLength = strlen( mqttexampleMESSAGE );\r
+ xMQTTPublishInfo.retryMs = mqttexamplePUBLISH_RETRY_MS;\r
+ xMQTTPublishInfo.retryLimit = mqttexamplePUBLISH_RETRY_LIMIT;\r
+\r
+ /* Use the synchronous API to publish - It is a blocking call and only\r
+ * returns when the publish operation is complete. */\r
+ xResult = IotMqtt_TimedPublish( xMQTTConnection,\r
+ &( xMQTTPublishInfo ),\r
+ 0, /* flags - currently ignored. */\r
+ mqttexampleMQTT_TIMEOUT_MS );\r
+ configASSERT( xResult == IOT_MQTT_SUCCESS );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvMQTTUnsubscribe( void )\r
+{\r
+IotMqttError_t xResult;\r
+IotMqttSubscription_t xMQTTSubscription;\r
+\r
+ /* Unsubscribe from the mqttexampleTOPIC topic filter. */\r
+ xMQTTSubscription.pTopicFilter = mqttexampleTOPIC;\r
+ xMQTTSubscription.topicFilterLength = ( uint16_t ) strlen( mqttexampleTOPIC );\r
+ /* The following members of the IotMqttSubscription_t are ignored by the\r
+ * unsubscribe operation. Just initialize them to avoid "use of uninitialized\r
+ * variable" warnings. */\r
+ xMQTTSubscription.qos = IOT_MQTT_QOS_1;\r
+ xMQTTSubscription.callback.pCallbackContext = NULL;\r
+ xMQTTSubscription.callback.function = NULL;\r
+\r
+ /* Use the synchronous API to unsubscribe - It is a blocking call and only\r
+ * returns when the unsubscribe operation is complete. */\r
+ xResult = IotMqtt_TimedUnsubscribe( xMQTTConnection,\r
+ &( xMQTTSubscription ),\r
+ 1, /* We are unsubscribing from one topic filter. */\r
+ 0, /* flags - currently ignored. */\r
+ mqttexampleMQTT_TIMEOUT_MS );\r
+ configASSERT( xResult == IOT_MQTT_SUCCESS );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvMQTTDisconnect( void )\r
+{\r
+ /* Send a MQTT DISCONNECT packet to the MQTT broker to do a graceful\r
+ * disconnect. */\r
+ IotMqtt_Disconnect( xMQTTConnection,\r
+ 0 /* flags - 0 means a graceful disconnect by sending MQTT DISCONNECT. */\r
+ );\r
+}\r
+/*-----------------------------------------------------------*/\r
+++ /dev/null
-/*\r
- * FreeRTOS Kernel V10.2.1\r
- * Copyright (C) 2017 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://www.FreeRTOS.org\r
- * http://aws.amazon.com/freertos\r
- *\r
- * 1 tab == 4 spaces!\r
- */\r
-\r
-//_RB_ Add link to docs here.\r
-\r
-/* Kernel includes. */\r
-#include "FreeRTOS.h"\r
-#include "task.h"\r
-\r
-/* Standard includes. */\r
-#include <stdio.h>\r
-\r
-/* IoT SDK includes. */\r
-#include "iot_taskpool.h"\r
-\r
-/* The priority at which that tasks in the task pool (the worker tasks) get\r
-created. */\r
-#define tpTASK_POOL_WORKER_PRIORITY 1\r
-\r
-/* The number of jobs created in the example functions that create more than\r
-one job. */\r
-#define tpJOBS_TO_CREATE 5\r
-\r
-/*\r
- * Prototypes for the functions that demonstrate the task pool API.\r
- * See the implementation of the prvTaskPoolDemoTask() function within this file\r
- * for a description of the individual functions. A configASSERT() is hit if\r
- * any of the demos encounter any unexpected behaviour.\r
- */\r
-static void prvExample_BasicSingleJob( void );\r
-static void prvExample_DeferredJobAndCancellingJobs( void );\r
-static void prvExample_BasicRecyclableJob( void );\r
-static void prvExample_ReuseRecyclableJobFromLowPriorityTask( void );\r
-static void prvExample_ReuseRecyclableJobFromHighPriorityTask( void );\r
-\r
-/*\r
- * Prototypes of the callback functions used in the examples. The callback\r
- * simply sends a signal (in the form of a direct task notification) to the\r
- * prvTaskPoolDemoTask() task to let the task know that the callback execute.\r
- * The handle of the prvTaskPoolDemoTask() task is not accessed directly, but\r
- * instead passed into the task pool job as the job's context.\r
- */\r
-static void prvSimpleTaskNotifyCallback( IotTaskPool_t pTaskPool, IotTaskPoolJob_t pJob, void *pUserContext );\r
-\r
-/*\r
- * The task used to demonstrate the task pool API. This task just loops through\r
- * each demo in turn.\r
- */\r
-static void prvTaskPoolDemoTask( void *pvParameters );\r
-\r
-/*-----------------------------------------------------------*/\r
-\r
-/* Parameters used to create the system task pool - see TBD for more information\r
-as the task pool used in this example is a slimmed down version of the full\r
-library - the slimmed down version being intended specifically for FreeRTOS\r
-kernel use cases. */\r
-static const IotTaskPoolInfo_t xTaskPoolParameters = {\r
- /* Minimum number of threads in a task pool.\r
- Note the slimmed down version of the task\r
- pool used by this library does not autoscale\r
- the number of tasks in the pool so in this\r
- case this sets the number of tasks in the\r
- pool. */\r
- 2,\r
- /* Maximum number of threads in a task pool.\r
- Note the slimmed down version of the task\r
- pool used by this library does not autoscale\r
- the number of tasks in the pool so in this\r
- case this parameter is just ignored. */\r
- 2,\r
- /* Stack size for every task pool thread - in\r
- bytes, hence multiplying by the number of bytes\r
- in a word as configMINIMAL_STACK_SIZE is\r
- specified in words. */\r
- configMINIMAL_STACK_SIZE * sizeof( portSTACK_TYPE ),\r
- /* Priority for every task pool thread. */\r
- tpTASK_POOL_WORKER_PRIORITY,\r
- };\r
-\r
-/*-----------------------------------------------------------*/\r
-\r
-void vStartSimpleTaskPoolDemo( void )\r
-{\r
- /* This example uses a single application task, which in turn is used to\r
- create and send jobs to task pool tasks. */\r
- xTaskCreate( prvTaskPoolDemoTask, /* Function that implements the task. */\r
- "PoolDemo", /* Text name for the task - only used for debugging. */\r
- configMINIMAL_STACK_SIZE, /* Size of stack (in words, not bytes) to allocate for the task. */\r
- NULL, /* Task parameter - not used in this case. */\r
- tskIDLE_PRIORITY, /* Task priority, must be between 0 and configMAX_PRIORITIES - 1. */\r
- NULL ); /* Used to pass out a handle to the created tsak - not used in this case. */\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-static void prvTaskPoolDemoTask( void *pvParameters )\r
-{\r
-IotTaskPoolError_t xResult;\r
-uint32_t ulLoops = 0;\r
-\r
- /* Remove compiler warnings about unused parameters. */\r
- ( void ) pvParameters;\r
-\r
- /* The task pool must be created before it can be used. The system task\r
- pool is the task pool managed by the task pool library itself - the storage\r
- used by the task pool is provided by the library. */\r
- xResult = IotTaskPool_CreateSystemTaskPool( &xTaskPoolParameters );\r
- configASSERT( xResult == IOT_TASKPOOL_SUCCESS );\r
-\r
- /* Attempting to create the task pool again should then appear to succeed\r
- (in case it is initialised by more than one library), but have no effect. */\r
- xResult = IotTaskPool_CreateSystemTaskPool( &xTaskPoolParameters );\r
- configASSERT( xResult == IOT_TASKPOOL_SUCCESS );\r
-\r
- for( ;; )\r
- {\r
- /* Demonstrate the most basic use case where a non persistent job is\r
- created and scheduled to run immediately. The task pool worker tasks\r
- (in which the job callback function executes) have a priority above the\r
- priority of this task so the job's callback executes as soon as it is\r
- scheduled. */\r
- prvExample_BasicSingleJob();\r
-\r
- /* Demonstrate a job being scheduled to run at some time in the\r
- future, and how a job scheduled to run in the future can be cancelled if\r
- it has not yet started executing. */\r
- prvExample_DeferredJobAndCancellingJobs();\r
-\r
- /* Demonstrate the most basic use of a recyclable job. This is similar\r
- to prvExample_BasicSingleJob() but using a recyclable job. Creating a\r
- recyclable job will re-use a previously created and now spare job from\r
- the task pool's job cache if one is available, or otherwise dynamically\r
- create a new job if a spare job is not available in the cache but space\r
- remains in the cache. */\r
- prvExample_BasicRecyclableJob();\r
-\r
- /* Demonstrate multiple recyclable jobs being created, used, and then\r
- re-used. In this the task pool worker tasks (in which the job callback\r
- functions execute) have a priority above the priority of this task so\r
- the job's callback functions execute as soon as they are scheduled. */\r
- prvExample_ReuseRecyclableJobFromLowPriorityTask();\r
-\r
- /* Again demonstrate multiple recyclable jobs being used, but this time\r
- the priority of the task pool worker tasks (in which the job callback\r
- functions execute) are lower than the priority of this task so the job's\r
- callback functions don't execute until this task enteres the blocked\r
- state. */\r
- prvExample_ReuseRecyclableJobFromHighPriorityTask();\r
-\r
- ulLoops++;\r
- if( ( ulLoops % 10UL ) == 0 )\r
- {\r
- printf( "prvTaskPoolDemoTask() performed %u iterations without hitting an assert.\r\n", ulLoops );\r
- fflush( stdout );\r
- }\r
- }\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-static void prvSimpleTaskNotifyCallback( IotTaskPool_t pTaskPool, IotTaskPoolJob_t pJob, void *pUserContext )\r
-{\r
-/* The jobs context is the handle of the task to which a notification should\r
-be sent. */\r
-TaskHandle_t xTaskToNotify = ( TaskHandle_t ) pUserContext;\r
-\r
- /* Remove warnings about unused parameters. */\r
- ( void ) pTaskPool;\r
- ( void ) pJob;\r
-\r
- /* Notify the task that created this job. */\r
- xTaskNotifyGive( xTaskToNotify );\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-static void prvExample_BasicSingleJob( void )\r
-{\r
-IotTaskPoolJobStorage_t xJobStorage;\r
-IotTaskPoolJob_t xJob;\r
-IotTaskPoolError_t xResult;\r
-uint32_t ulReturn;\r
-const uint32_t ulNoFlags = 0UL;\r
-const TickType_t xNoDelay = ( TickType_t ) 0;\r
-size_t xFreeHeapBeforeCreatingJob = xPortGetFreeHeapSize();\r
-IotTaskPoolJobStatus_t xJobStatus;\r
-\r
- /* Don't expect any notifications to be pending yet. */\r
- configASSERT( ulTaskNotifyTake( pdTRUE, 0 ) == 0 );\r
-\r
- /* Create and schedule a job using the handle of this task as the job's\r
- context and the function that sends a notification to the task handle as\r
- the jobs callback function. This is not a recyclable job so the storage\r
- required to hold information about the job is provided by this task - in\r
- this case the storage is on the stack of this task so no memory is allocated\r
- dynamically but the stack frame must remain in scope for the lifetime of\r
- the job. */\r
- xResult = IotTaskPool_CreateJob( prvSimpleTaskNotifyCallback, /* Callback function. */\r
- ( void * ) xTaskGetCurrentTaskHandle(), /* Job context. */\r
- &xJobStorage,\r
- &xJob );\r
- configASSERT( xResult == IOT_TASKPOOL_SUCCESS );\r
-\r
- /* The job has been created but not scheduled so is now ready. */\r
- IotTaskPool_GetStatus( NULL, xJob, &xJobStatus );\r
- configASSERT( xJobStatus == IOT_TASKPOOL_STATUS_READY );\r
-\r
- /* This is not a persistent (recyclable) job and its storage is on the\r
- stack of this function, so the amount of heap space available should not\r
- have chanced since entering this function. */\r
- configASSERT( xFreeHeapBeforeCreatingJob == xPortGetFreeHeapSize() );\r
-\r
- /* In the full task pool implementation the first parameter is used to\r
- pass the handle of the task pool to schedule. The lean task pool\r
- implementation used in this demo only supports a single task pool, which\r
- is created internally within the library, so the first parameter is NULL. */\r
- xResult = IotTaskPool_Schedule( NULL, xJob, ulNoFlags );\r
- configASSERT( xResult == IOT_TASKPOOL_SUCCESS );\r
-\r
- /* Look for the notification coming from the job's callback function. The\r
- priority of the task pool worker task that executes the callback is higher\r
- than the priority of this task so a block time is not needed - the task pool\r
- worker task pre-empts this task and sends the notification (from the job's\r
- callback) as soon as the job is scheduled. */\r
- ulReturn = ulTaskNotifyTake( pdTRUE, xNoDelay );\r
- configASSERT( ulReturn );\r
-\r
- /* The job's callback has executed so the job has now completed. */\r
- IotTaskPool_GetStatus( NULL, xJob, &xJobStatus );\r
- configASSERT( xJobStatus == IOT_TASKPOOL_STATUS_COMPLETED );\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-static void prvExample_DeferredJobAndCancellingJobs( void )\r
-{\r
-IotTaskPoolJobStorage_t xJobStorage;\r
-IotTaskPoolJob_t xJob;\r
-IotTaskPoolError_t xResult;\r
-uint32_t ulReturn;\r
-const uint32_t ulShortDelay_ms = 100UL;\r
-const TickType_t xNoDelay = ( TickType_t ) 0, xAllowableMargin = ( TickType_t ) 5; /* Large margin for Windows port, which is not real time. */\r
-TickType_t xTimeBefore, xElapsedTime, xShortDelay_ticks;\r
-size_t xFreeHeapBeforeCreatingJob = xPortGetFreeHeapSize();\r
-IotTaskPoolJobStatus_t xJobStatus;\r
-\r
- /* Don't expect any notifications to be pending yet. */\r
- configASSERT( ulTaskNotifyTake( pdTRUE, 0 ) == 0 );\r
-\r
- /* Create a job using the handle of this task as the job's context and the\r
- function that sends a notification to the task handle as the jobs callback\r
- function. The job is created using storage allocated on the stack of this\r
- function - so no memory is allocated. */\r
- xResult = IotTaskPool_CreateJob( prvSimpleTaskNotifyCallback, /* Callback function. */\r
- ( void * ) xTaskGetCurrentTaskHandle(), /* Job context. */\r
- &xJobStorage,\r
- &xJob );\r
- configASSERT( xResult == IOT_TASKPOOL_SUCCESS );\r
-\r
- /* The job has been created but not scheduled so is now ready. */\r
- IotTaskPool_GetStatus( NULL, xJob, &xJobStatus );\r
- configASSERT( xJobStatus == IOT_TASKPOOL_STATUS_READY );\r
-\r
- /* This is not a persistent (recyclable) job and its storage is on the\r
- stack of this function, so the amount of heap space available should not\r
- have chanced since entering this function. */\r
- configASSERT( xFreeHeapBeforeCreatingJob == xPortGetFreeHeapSize() );\r
-\r
- /* Schedule the job to run its callback in xShortDelay_ms milliseconds time.\r
- In the full task pool implementation the first parameter is used to pass the\r
- handle of the task pool to schedule. The lean task pool implementation used\r
- in this demo only supports a single task pool, which is created internally\r
- within the library, so the first parameter is NULL. */\r
- xResult = IotTaskPool_ScheduleDeferred( NULL, xJob, ulShortDelay_ms );\r
- configASSERT( xResult == IOT_TASKPOOL_SUCCESS );\r
-\r
- /* The scheduled job should not have executed yet, so don't expect any\r
- notifications and expect the job's status to be 'deferred'. */\r
- ulReturn = ulTaskNotifyTake( pdTRUE, xNoDelay );\r
- configASSERT( ulReturn == 0 );\r
- IotTaskPool_GetStatus( NULL, xJob, &xJobStatus );\r
- configASSERT( xJobStatus == IOT_TASKPOOL_STATUS_DEFERRED );\r
-\r
- /* As the job has not yet been executed it can be stopped. */\r
- xResult = IotTaskPool_TryCancel( NULL, xJob, &xJobStatus );\r
- configASSERT( xResult == IOT_TASKPOOL_SUCCESS );\r
- IotTaskPool_GetStatus( NULL, xJob, &xJobStatus );\r
- configASSERT( xJobStatus == IOT_TASKPOOL_STATUS_CANCELED );\r
-\r
- /* Schedule the job again, and this time wait until its callback is\r
- executed (the callback function sends a notification to this task) to see\r
- that it executes at the right time. */\r
- xTimeBefore = xTaskGetTickCount();\r
- xResult = IotTaskPool_ScheduleDeferred( NULL, xJob, ulShortDelay_ms );\r
- configASSERT( xResult == IOT_TASKPOOL_SUCCESS );\r
-\r
- /* Wait twice the deferred execution time to ensure the callback is executed\r
- before the call below times out. */\r
- ulReturn = ulTaskNotifyTake( pdTRUE, pdMS_TO_TICKS( ulShortDelay_ms * 2UL ) );\r
- xElapsedTime = xTaskGetTickCount() - xTimeBefore;\r
-\r
- /* A single notification should not have been received... */\r
- configASSERT( ulReturn == 1 );\r
-\r
- /* ...and the time since scheduling the job should be greater than or\r
- equal to the deferred execution time - which is converted to ticks for\r
- comparison. */\r
- xShortDelay_ticks = pdMS_TO_TICKS( ulShortDelay_ms );\r
- configASSERT( ( xElapsedTime >= xShortDelay_ticks ) && ( xElapsedTime < ( xShortDelay_ticks + xAllowableMargin ) ) );\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-static void prvExample_BasicRecyclableJob( void )\r
-{\r
-IotTaskPoolJob_t xJob;\r
-IotTaskPoolError_t xResult;\r
-uint32_t ulReturn;\r
-const uint32_t ulNoFlags = 0UL;\r
-const TickType_t xNoDelay = ( TickType_t ) 0;\r
-size_t xFreeHeapBeforeCreatingJob = xPortGetFreeHeapSize();\r
-\r
- /* Don't expect any notifications to be pending yet. */\r
- configASSERT( ulTaskNotifyTake( pdTRUE, 0 ) == 0 );\r
-\r
- /* Create and schedule a job using the handle of this task as the job's\r
- context and the function that sends a notification to the task handle as\r
- the jobs callback function. The job is created as a recyclable job and in\r
- this case the memory used to hold the job status is allocated inside the\r
- create function. As the job is persistent it can be used multiple times,\r
- as demonstrated in other examples within this demo. In the full task pool\r
- implementation the first parameter is used to pass the handle of the task\r
- pool this recyclable job is to be associated with. In the lean\r
- implementation of the task pool used by this demo there is only one task\r
- pool (the system task pool created within the task pool library) so the\r
- first parameter is NULL. */\r
- xResult = IotTaskPool_CreateRecyclableJob( NULL,\r
- prvSimpleTaskNotifyCallback,\r
- (void * ) xTaskGetCurrentTaskHandle(),\r
- &xJob );\r
- configASSERT( xResult == IOT_TASKPOOL_SUCCESS );\r
-\r
- /* This recyclable job is persistent, and in this case created dynamically,\r
- so expect there to be less heap space then when entering the function. */\r
- configASSERT( xPortGetFreeHeapSize() < xFreeHeapBeforeCreatingJob );\r
-\r
- /* In the full task pool implementation the first parameter is used to\r
- pass the handle of the task pool to schedule. The lean task pool\r
- implementation used in this demo only supports a single task pool, which\r
- is created internally within the library, so the first parameter is NULL. */\r
- xResult = IotTaskPool_Schedule( NULL, xJob, ulNoFlags );\r
- configASSERT( xResult == IOT_TASKPOOL_SUCCESS );\r
-\r
- /* Look for the notification coming from the job's callback function. The\r
- priority of the task pool worker task that executes the callback is higher\r
- than the priority of this task so a block time is not needed - the task pool\r
- worker task pre-empts this task and sends the notification (from the job's\r
- callback) as soon as the job is scheduled. */\r
- ulReturn = ulTaskNotifyTake( pdTRUE, xNoDelay );\r
- configASSERT( ulReturn );\r
-\r
- /* Clean up recyclable job. In the full implementation of the task pool\r
- the first parameter is used to pass a handle to the task pool the job is\r
- associated with. In the lean implementation of the task pool used by this\r
- demo there is only one task pool (the system task pool created in the\r
- task pool library itself) so the first parameter is NULL. */\r
- IotTaskPool_DestroyRecyclableJob( NULL, xJob );\r
-\r
- /* Once the job has been deleted the memory used to hold the job is\r
- returned, so the available heap should be exactly as when entering this\r
- function. */\r
- configASSERT( xPortGetFreeHeapSize() == xFreeHeapBeforeCreatingJob );\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-static void prvExample_ReuseRecyclableJobFromLowPriorityTask( void )\r
-{\r
-IotTaskPoolError_t xResult;\r
-uint32_t x, xIndex, ulNotificationValue;\r
-const uint32_t ulNoFlags = 0UL;\r
-IotTaskPoolJob_t xJobs[ tpJOBS_TO_CREATE ];\r
-size_t xFreeHeapBeforeCreatingJob = xPortGetFreeHeapSize();\r
-IotTaskPoolJobStatus_t xJobStatus;\r
-\r
- /* Don't expect any notifications to be pending yet. */\r
- configASSERT( ulTaskNotifyTake( pdTRUE, 0 ) == 0 );\r
-\r
- /* Create tpJOBS_TO_CREATE jobs using the handle of this task as the job's\r
- context and the function that sends a notification to the task handle as\r
- the jobs callback function. The jobs are created as a recyclable job and\r
- in this case the memory to store the job information is allocated within\r
- the create function as at this time there are no recyclable jobs in the\r
- task pool jobs cache. As the jobs are persistent they can be used multiple\r
- times. In the full task pool implementation the first parameter is used to\r
- pass the handle of the task pool this recyclable job is to be associated\r
- with. In the lean implementation of the task pool used by this demo there\r
- is only one task pool (the system task pool created within the task pool\r
- library) so the first parameter is NULL. */\r
- for( x = 0; x < tpJOBS_TO_CREATE; x++ )\r
- {\r
- xResult = IotTaskPool_CreateRecyclableJob( NULL,\r
- prvSimpleTaskNotifyCallback,\r
- (void * ) xTaskGetCurrentTaskHandle(),\r
- &( xJobs[ x ] ) );\r
- configASSERT( xResult == IOT_TASKPOOL_SUCCESS );\r
-\r
- /* The job has been created but not scheduled so is now ready. */\r
- IotTaskPool_GetStatus( NULL, xJobs[ x ], &xJobStatus );\r
- configASSERT( xJobStatus == IOT_TASKPOOL_STATUS_READY );\r
- }\r
-\r
- /* Demonstrate that the jobs can be recycled by performing twice the number\r
- of iterations of scheduling jobs than there actually are created jobs. This\r
- works because the task pool task priorities are above the priority of this\r
- task, so the tasks that run the jobs pre-empt this task as soon as a job is\r
- ready. */\r
- for( x = 0; x < ( tpJOBS_TO_CREATE * 2UL ); x++ )\r
- {\r
- /* Make sure array index does not go out of bounds. */\r
- xIndex = x % tpJOBS_TO_CREATE;\r
-\r
- xResult = IotTaskPool_Schedule( NULL, xJobs[ xIndex ], ulNoFlags );\r
- configASSERT( xResult == IOT_TASKPOOL_SUCCESS );\r
-\r
- /* The priority of the task pool task(s) is higher than the priority\r
- of this task, so the job's callback function should have already\r
- executed, sending a notification to this task, and incrementing this\r
- task's notification value. */\r
- xTaskNotifyWait( 0UL, /* Don't clear any bits on entry. */\r
- 0UL, /* Don't clear any bits on exit. */\r
- &ulNotificationValue, /* Obtain the notification value. */\r
- 0UL ); /* No block time, return immediately. */\r
- configASSERT( ulNotificationValue == ( x + 1 ) );\r
-\r
- /* The job's callback has executed so the job is now completed. */\r
- IotTaskPool_GetStatus( NULL, xJobs[ xIndex ], &xJobStatus );\r
- configASSERT( xJobStatus == IOT_TASKPOOL_STATUS_COMPLETED );\r
-\r
- /* To leave the list of jobs empty we can stop re-creating jobs half\r
- way through iterations of this loop. */\r
- if( x < tpJOBS_TO_CREATE )\r
- {\r
- /* Recycle the job so it can be used again. In the full task pool\r
- implementation the first parameter is used to pass the handle of the\r
- task pool this job will be associated with. In this lean task pool\r
- implementation only the system task pool exists (the task pool created\r
- internally to the task pool library) so the first parameter is just\r
- passed as NULL. *//*_RB_ Why not recycle it automatically? */\r
- IotTaskPool_RecycleJob( NULL, xJobs[ xIndex ] );\r
- xResult = IotTaskPool_CreateRecyclableJob( NULL,\r
- prvSimpleTaskNotifyCallback,\r
- (void * ) xTaskGetCurrentTaskHandle(),\r
- &( xJobs[ xIndex ] ) );\r
- configASSERT( xResult == IOT_TASKPOOL_SUCCESS );\r
- }\r
- }\r
-\r
- /* Clear all the notification value bits again. */\r
- xTaskNotifyWait( portMAX_DELAY, /* Clear all bits on entry - portMAX_DELAY is used as it is a portable way of having all bits set. */\r
- 0UL, /* Don't clear any bits on exit. */\r
- NULL, /* Don't need the notification value this time. */\r
- 0UL ); /* No block time, return immediately. */\r
- configASSERT( ulTaskNotifyTake( pdTRUE, 0 ) == 0 );\r
-\r
- /* Clean up all the recyclable job. In the full implementation of the task\r
- pool the first parameter is used to pass a handle to the task pool the job\r
- is associated with. In the lean implementation of the task pool used by\r
- this demo there is only one task pool (the system task pool created in the\r
- task pool library itself) so the first parameter is NULL. */\r
- for( x = 0; x < tpJOBS_TO_CREATE; x++ )\r
- {\r
- xResult = IotTaskPool_DestroyRecyclableJob( NULL, xJobs[ x ] );\r
- configASSERT( xResult == IOT_TASKPOOL_SUCCESS );\r
- }\r
-\r
- /* Once the job has been deleted the memory used to hold the job is\r
- returned, so the available heap should be exactly as when entering this\r
- function. */\r
- configASSERT( xPortGetFreeHeapSize() == xFreeHeapBeforeCreatingJob );\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-static void prvExample_ReuseRecyclableJobFromHighPriorityTask( void )\r
-{\r
-IotTaskPoolError_t xResult;\r
-uint32_t x, ulNotificationValue;\r
-const uint32_t ulNoFlags = 0UL;\r
-IotTaskPoolJob_t xJobs[ tpJOBS_TO_CREATE ];\r
-IotTaskPoolJobStorage_t xJobStorage[ tpJOBS_TO_CREATE ];\r
-size_t xFreeHeapBeforeCreatingJob = xPortGetFreeHeapSize();\r
-TickType_t xShortDelay = pdMS_TO_TICKS( 150 );\r
-IotTaskPoolJobStatus_t xJobStatus;\r
-\r
- /* Don't expect any notifications to be pending yet. */\r
- configASSERT( ulTaskNotifyTake( pdTRUE, 0 ) == 0 );\r
-\r
- /* prvExample_ReuseRecyclableJobFromLowPriorityTask() executes in a task\r
- that has a lower [task] priority than the task pool's worker tasks.\r
- Therefore a talk pool worker preempts the task that calls\r
- prvExample_ReuseRecyclableJobFromHighPriorityTask() as soon as the job is\r
- scheduled. prvExample_ReuseRecyclableJobFromHighPriorityTask() reverses the\r
- priorities - prvExample_ReuseRecyclableJobFromHighPriorityTask() raises its\r
- priority to above the task pool's worker tasks, so the worker tasks do not\r
- execute until the calling task enters the blocked state. First raise the\r
- priority - passing NULL means raise the priority of the calling task. */\r
- vTaskPrioritySet( NULL, tpTASK_POOL_WORKER_PRIORITY + 1 );\r
-\r
- /* Create tpJOBS_TO_CREATE jobs using the handle of this task as the job's\r
- context and the function that sends a notification to the task handle as\r
- the jobs callback function. */\r
- for( x = 0; x < tpJOBS_TO_CREATE; x++ )\r
- {\r
- xResult = IotTaskPool_CreateJob( prvSimpleTaskNotifyCallback, /* Callback function. */\r
- ( void * ) xTaskGetCurrentTaskHandle(), /* Job context. */\r
- &( xJobStorage[ x ] ),\r
- &( xJobs[ x ] ) );\r
- configASSERT( xResult == IOT_TASKPOOL_SUCCESS );\r
-\r
- /* This is not a persistent (recyclable) job and its storage is on the\r
- stack of this function, so the amount of heap space available should not\r
- have chanced since entering this function. */\r
- configASSERT( xFreeHeapBeforeCreatingJob == xPortGetFreeHeapSize() );\r
- }\r
-\r
- for( x = 0; x < tpJOBS_TO_CREATE; x++ )\r
- {\r
- /* Schedule the next job. */\r
- xResult = IotTaskPool_Schedule( NULL, xJobs[ x ], ulNoFlags );\r
- configASSERT( xResult == IOT_TASKPOOL_SUCCESS );\r
-\r
- /* Although scheduled, the job's callback has not executed, so the job\r
- reports itself as scheduled. */\r
- IotTaskPool_GetStatus( NULL, xJobs[ x ], &xJobStatus );\r
- configASSERT( xJobStatus == IOT_TASKPOOL_STATUS_SCHEDULED );\r
-\r
- /* The priority of the task pool task(s) is lower than the priority\r
- of this task, so the job's callback function should not have executed\r
- yes, so don't expect the notification value for this task to have\r
- changed. */\r
- xTaskNotifyWait( 0UL, /* Don't clear any bits on entry. */\r
- 0UL, /* Don't clear any bits on exit. */\r
- &ulNotificationValue, /* Obtain the notification value. */\r
- 0UL ); /* No block time, return immediately. */\r
- configASSERT( ulNotificationValue == 0 );\r
- }\r
-\r
- /* At this point there are tpJOBS_TO_CREATE scheduled, but none have executed\r
- their callbacks because the priority of this task is higher than the\r
- priority of the task pool worker threads. When this task blocks to wait for\r
- a notification a worker thread will be able to executes - but as soon as its\r
- callback function sends a notification to this task this task will\r
- preempt it (because it has a higher priority) so this task only expects to\r
- receive one notification at a time. */\r
- for( x = 0; x < tpJOBS_TO_CREATE; x++ )\r
- {\r
- xTaskNotifyWait( 0UL, /* Don't clear any bits on entry. */\r
- 0UL, /* Don't clear any bits on exit. */\r
- &ulNotificationValue, /* Obtain the notification value. */\r
- xShortDelay ); /* Short delay to allow a task pool worker to execute. */\r
- configASSERT( ulNotificationValue == ( x + 1 ) );\r
- }\r
-\r
- /* All the scheduled jobs have now executed, so waiting for another\r
- notification should timeout without the notification value changing. */\r
- xTaskNotifyWait( 0UL, /* Don't clear any bits on entry. */\r
- 0UL, /* Don't clear any bits on exit. */\r
- &ulNotificationValue, /* Obtain the notification value. */\r
- xShortDelay ); /* Short delay to allow a task pool worker to execute. */\r
- configASSERT( ulNotificationValue == x );\r
-\r
- /* Reset the priority of this task and clear the notifications ready for the\r
- next example. */\r
- vTaskPrioritySet( NULL, tskIDLE_PRIORITY );\r
- xTaskNotifyWait( portMAX_DELAY, /* Clear all bits on entry - portMAX_DELAY is used as it is a portable way of having all bits set. */\r
- 0UL, /* Don't clear any bits on exit. */\r
- NULL, /* Don't need the notification value this time. */\r
- 0UL ); /* No block time, return immediately. */\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
</Midl>\r
<ClCompile>\r
<Optimization>Disabled</Optimization>\r
- <AdditionalIncludeDirectories>..\..\..\Source\FreeRTOS-Plus-IoT-SDK\c_sdk\standard\mqtt\include;..\..\..\Source\FreeRTOS-Plus-TCP\include;..\..\..\Source\FreeRTOS-Plus-TCP\portable\BufferManagement;..\..\..\Source\FreeRTOS-Plus-TCP\portable\Compiler\MSVC;.\DemoTasks\include;.\WinPCap;..\..\..\..\FreeRTOS\Source\include;..\..\..\..\FreeRTOS\Source\portable\MSVC-MingW;..\..\..\Source\FreeRTOS-Plus-IoT-SDK\c_sdk\standard\common\include;..\..\..\Source\FreeRTOS-Plus-IoT-SDK\abstractions\platform\include;..\..\..\Source\FreeRTOS-Plus-IoT-SDK\abstractions\platform\freertos\include;.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
+ <AdditionalIncludeDirectories>..\..\..\Source\FreeRTOS-Plus-IoT-SDK\c_sdk\standard\mqtt\include;..\..\..\Source\FreeRTOS-Plus-TCP\include;..\..\..\Source\FreeRTOS-Plus-TCP\portable\BufferManagement;..\..\..\Source\FreeRTOS-Plus-TCP\portable\Compiler\MSVC;.\DemoTasks\include;.\WinPCap;..\..\..\..\FreeRTOS\Source\include;..\..\..\..\FreeRTOS\Source\portable\MSVC-MingW;..\..\..\Source\FreeRTOS-Plus-IoT-SDK\c_sdk\standard\common\include\private;..\..\..\Source\FreeRTOS-Plus-IoT-SDK\c_sdk\standard\common\include;..\..\..\Source\FreeRTOS-Plus-IoT-SDK\abstractions\platform\include;..\..\..\Source\FreeRTOS-Plus-IoT-SDK\abstractions\platform\freertos\include;..\..\..\Source\FreeRTOS-Plus-IoT-SDK\abstractions\secure_sockets\include;.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_WIN32_WINNT=0x0500;WINVER=0x400;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
<MinimalRebuild>true</MinimalRebuild>\r
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>\r
</Bscmake>\r
</ItemDefinitionGroup>\r
<ItemGroup>\r
- <ClCompile Include="..\..\..\..\..\..\..\..\..\T\reviews\amazon-freertos-master\libraries\abstractions\platform\freertos\iot_clock_freertos.c" />\r
- <ClCompile Include="..\..\..\..\..\..\..\..\..\T\reviews\amazon-freertos-master\libraries\abstractions\platform\freertos\iot_threads_freertos.c" />\r
- <ClCompile Include="..\..\..\..\..\..\..\..\..\T\reviews\amazon-freertos-master\libraries\c_sdk\standard\mqtt\src\iot_mqtt_network.c" />\r
- <ClCompile Include="..\..\..\..\..\..\..\..\..\T\reviews\amazon-freertos-master\libraries\c_sdk\standard\mqtt\src\iot_mqtt_subscription.c" />\r
- <ClCompile Include="..\..\..\..\..\..\..\..\..\T\reviews\amazon-freertos-master\libraries\c_sdk\standard\mqtt\src\iot_mqtt_validate.c" />\r
<ClCompile Include="..\..\..\..\FreeRTOS\Source\event_groups.c" />\r
<ClCompile Include="..\..\..\..\FreeRTOS\Source\list.c" />\r
<ClCompile Include="..\..\..\..\FreeRTOS\Source\portable\MemMang\heap_4.c" />\r
<ClCompile Include="..\..\..\..\FreeRTOS\Source\queue.c" />\r
<ClCompile Include="..\..\..\..\FreeRTOS\Source\tasks.c" />\r
<ClCompile Include="..\..\..\..\FreeRTOS\Source\timers.c" />\r
+ <ClCompile Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\abstractions\platform\freertos\iot_clock_freertos.c" />\r
+ <ClCompile Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\abstractions\platform\freertos\iot_network_freertos.c" />\r
+ <ClCompile Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\abstractions\platform\freertos\iot_threads_freertos.c" />\r
+ <ClCompile Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\abstractions\secure_sockets\freertos_plus_tcp\iot_secure_sockets.c" />\r
<ClCompile Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\c_sdk\standard\common\logging\iot_logging.c" />\r
<ClCompile Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\c_sdk\standard\common\taskpool\iot_taskpool.c" />\r
<ClCompile Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\c_sdk\standard\mqtt\src\iot_mqtt_api.c" />\r
+ <ClCompile Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\c_sdk\standard\mqtt\src\iot_mqtt_network.c" />\r
<ClCompile Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\c_sdk\standard\mqtt\src\iot_mqtt_operation.c" />\r
<ClCompile Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\c_sdk\standard\mqtt\src\iot_mqtt_serialize.c" />\r
+ <ClCompile Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\c_sdk\standard\mqtt\src\iot_mqtt_subscription.c" />\r
+ <ClCompile Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\c_sdk\standard\mqtt\src\iot_mqtt_validate.c" />\r
<ClCompile Include="..\..\..\Source\FreeRTOS-Plus-TCP\FreeRTOS_ARP.c" />\r
<ClCompile Include="..\..\..\Source\FreeRTOS-Plus-TCP\FreeRTOS_DHCP.c" />\r
<ClCompile Include="..\..\..\Source\FreeRTOS-Plus-TCP\FreeRTOS_DNS.c" />\r
<ClCompile Include="..\..\..\Source\FreeRTOS-Plus-TCP\FreeRTOS_UDP_IP.c" />\r
<ClCompile Include="..\..\..\Source\FreeRTOS-Plus-TCP\portable\BufferManagement\BufferAllocation_2.c" />\r
<ClCompile Include="..\..\..\Source\FreeRTOS-Plus-TCP\portable\NetworkInterface\WinPCap\NetworkInterface.c" />\r
- <ClCompile Include="DemoTasks\SimpleTaskPoolExamples.c" />\r
+ <ClCompile Include="DemoTasks\SimpleMQTTExamples.c" />\r
<ClCompile Include="DemoTasks\SimpleUDPClientAndServer.c" />\r
<ClCompile Include="demo_logging.c" />\r
<ClCompile Include="main.c">\r
<ClInclude Include="..\..\..\..\FreeRTOS\Source\include\task.h" />\r
<ClInclude Include="..\..\..\..\FreeRTOS\Source\include\timers.h" />\r
<ClInclude Include="..\..\..\..\FreeRTOS\Source\portable\MSVC-MingW\portmacro.h" />\r
- <ClInclude Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\abstractions\platform\freertos\include\platform\iot_platform_types_afr.h" />\r
+ <ClInclude Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\abstractions\platform\freertos\include\platform\iot_platform_types_freertos.h" />\r
+ <ClInclude Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\abstractions\platform\include\platform\iot_clock.h" />\r
+ <ClInclude Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\abstractions\platform\include\platform\iot_metrics.h" />\r
+ <ClInclude Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\abstractions\platform\include\platform\iot_network.h" />\r
+ <ClInclude Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\abstractions\platform\include\platform\iot_threads.h" />\r
<ClInclude Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\abstractions\platform\include\types\iot_platform_types.h" />\r
+ <ClInclude Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\abstractions\secure_sockets\include\iot_secure_sockets.h" />\r
+ <ClInclude Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\abstractions\secure_sockets\include\iot_secure_sockets_config_defaults.h" />\r
+ <ClInclude Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\abstractions\secure_sockets\include\iot_secure_sockets_wrapper_metrics.h" />\r
<ClInclude Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\c_sdk\standard\common\include\iot_taskpool.h" />\r
<ClInclude Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\c_sdk\standard\common\include\private\iot_error.h" />\r
+ <ClInclude Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\c_sdk\standard\common\include\private\iot_lib_init.h" />\r
<ClInclude Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\c_sdk\standard\common\include\private\iot_logging.h" />\r
<ClInclude Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\c_sdk\standard\common\include\private\iot_static_memory.h" />\r
<ClInclude Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\c_sdk\standard\common\include\private\iot_taskpool_internal.h" />\r
<Filter Include="FreeRTOS+\FreeRTOS IoT Libraries\abstractions\platform\freertos\include\platform">\r
<UniqueIdentifier>{bdcbc1ec-99b8-4c72-9075-49035c115488}</UniqueIdentifier>\r
</Filter>\r
- <Filter Include="FreeRTOS+\FreeRTOS IoT Libraries\abstractions\platform\freertos\include\platform\types">\r
- <UniqueIdentifier>{35ce7745-52a2-4220-be31-50dfaa35c0ab}</UniqueIdentifier>\r
- </Filter>\r
<Filter Include="FreeRTOS+\FreeRTOS IoT Libraries\standard\mqtt">\r
<UniqueIdentifier>{2d17d5e6-ed70-4e42-9693-f7a63baf4948}</UniqueIdentifier>\r
</Filter>\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-Plus-IoT-SDK\c_sdk\standard\common\taskpool\iot_taskpool.c">\r
<Filter>FreeRTOS+\FreeRTOS IoT Libraries\standard\common\task_pool</Filter>\r
</ClCompile>\r
- <ClCompile Include="DemoTasks\SimpleTaskPoolExamples.c">\r
- <Filter>DemoTasks</Filter>\r
- </ClCompile>\r
<ClCompile Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\c_sdk\standard\mqtt\src\iot_mqtt_api.c">\r
<Filter>FreeRTOS+\FreeRTOS IoT Libraries\standard\mqtt\src</Filter>\r
</ClCompile>\r
<ClCompile Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\c_sdk\standard\mqtt\src\iot_mqtt_serialize.c">\r
<Filter>FreeRTOS+\FreeRTOS IoT Libraries\standard\mqtt\src</Filter>\r
</ClCompile>\r
- <ClCompile Include="..\..\..\..\..\..\..\..\..\T\reviews\amazon-freertos-master\libraries\c_sdk\standard\mqtt\src\iot_mqtt_network.c">\r
+ <ClCompile Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\c_sdk\standard\common\logging\iot_logging.c">\r
+ <Filter>FreeRTOS+\FreeRTOS IoT Libraries\standard\common\logging</Filter>\r
+ </ClCompile>\r
+ <ClCompile Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\c_sdk\standard\mqtt\src\iot_mqtt_network.c">\r
<Filter>FreeRTOS+\FreeRTOS IoT Libraries\standard\mqtt\src</Filter>\r
</ClCompile>\r
- <ClCompile Include="..\..\..\..\..\..\..\..\..\T\reviews\amazon-freertos-master\libraries\c_sdk\standard\mqtt\src\iot_mqtt_subscription.c">\r
+ <ClCompile Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\c_sdk\standard\mqtt\src\iot_mqtt_subscription.c">\r
<Filter>FreeRTOS+\FreeRTOS IoT Libraries\standard\mqtt\src</Filter>\r
</ClCompile>\r
- <ClCompile Include="..\..\..\..\..\..\..\..\..\T\reviews\amazon-freertos-master\libraries\c_sdk\standard\mqtt\src\iot_mqtt_validate.c">\r
+ <ClCompile Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\c_sdk\standard\mqtt\src\iot_mqtt_validate.c">\r
<Filter>FreeRTOS+\FreeRTOS IoT Libraries\standard\mqtt\src</Filter>\r
</ClCompile>\r
- <ClCompile Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\c_sdk\standard\common\logging\iot_logging.c">\r
- <Filter>FreeRTOS+\FreeRTOS IoT Libraries\standard\common\logging</Filter>\r
+ <ClCompile Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\abstractions\platform\freertos\iot_clock_freertos.c">\r
+ <Filter>FreeRTOS+\FreeRTOS IoT Libraries\abstractions\platform\freertos</Filter>\r
</ClCompile>\r
- <ClCompile Include="..\..\..\..\..\..\..\..\..\T\reviews\amazon-freertos-master\libraries\abstractions\platform\freertos\iot_threads_freertos.c">\r
+ <ClCompile Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\abstractions\platform\freertos\iot_threads_freertos.c">\r
<Filter>FreeRTOS+\FreeRTOS IoT Libraries\abstractions\platform\freertos</Filter>\r
</ClCompile>\r
- <ClCompile Include="..\..\..\..\..\..\..\..\..\T\reviews\amazon-freertos-master\libraries\abstractions\platform\freertos\iot_clock_freertos.c">\r
+ <ClCompile Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\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
+ <ClCompile Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\abstractions\platform\freertos\iot_network_freertos.c">\r
<Filter>FreeRTOS+\FreeRTOS IoT Libraries\abstractions\platform\freertos</Filter>\r
</ClCompile>\r
</ItemGroup>\r
</ClInclude>\r
<ClInclude Include="iot_config.h" />\r
<ClInclude Include="iot_config_common.h" />\r
- <ClInclude Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\abstractions\platform\freertos\include\platform\iot_platform_types_afr.h">\r
- <Filter>FreeRTOS+\FreeRTOS IoT Libraries\abstractions\platform\freertos\include\platform</Filter>\r
- </ClInclude>\r
<ClInclude Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\abstractions\platform\include\types\iot_platform_types.h">\r
<Filter>FreeRTOS+\FreeRTOS IoT Libraries\abstractions\platform\include\types</Filter>\r
</ClInclude>\r
<ClInclude Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\c_sdk\standard\mqtt\include\types\iot_mqtt_types.h">\r
<Filter>FreeRTOS+\FreeRTOS IoT Libraries\standard\mqtt\include\types</Filter>\r
</ClInclude>\r
+ <ClInclude Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\abstractions\platform\freertos\include\platform\iot_platform_types_freertos.h">\r
+ <Filter>FreeRTOS+\FreeRTOS IoT Libraries\abstractions\platform\freertos\include\platform</Filter>\r
+ </ClInclude>\r
+ <ClInclude Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\abstractions\platform\include\platform\iot_clock.h">\r
+ <Filter>FreeRTOS+\FreeRTOS IoT Libraries\abstractions\platform\include\platform</Filter>\r
+ </ClInclude>\r
+ <ClInclude Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\abstractions\platform\include\platform\iot_metrics.h">\r
+ <Filter>FreeRTOS+\FreeRTOS IoT Libraries\abstractions\platform\include\platform</Filter>\r
+ </ClInclude>\r
+ <ClInclude Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\abstractions\platform\include\platform\iot_network.h">\r
+ <Filter>FreeRTOS+\FreeRTOS IoT Libraries\abstractions\platform\include\platform</Filter>\r
+ </ClInclude>\r
+ <ClInclude Include="..\..\..\Source\FreeRTOS-Plus-IoT-SDK\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-Plus-IoT-SDK\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-Plus-IoT-SDK\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-Plus-IoT-SDK\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-Plus-IoT-SDK\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
--- /dev/null
+/*\r
+ * FreeRTOS Kernel V10.2.0\r
+ * Copyright (C) 2019 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://www.FreeRTOS.org\r
+ * http://aws.amazon.com/freertos\r
+ *\r
+ * 1 tab == 4 spaces!\r
+ */\r
+\r
+/**\r
+ * @file atomic.h\r
+ * @brief FreeRTOS atomic operation support.\r
+ *\r
+ * Two implementations of atomic are given in this header file:\r
+ * 1. Disabling interrupt globally.\r
+ * 2. ISA native atomic support.\r
+ * The former is available to all ports (compiler-architecture combination),\r
+ * while the latter is only available to ports compiling with GCC (version at\r
+ * least 4.7.0), which also have ISA atomic support.\r
+ *\r
+ * User can select which implementation to use by:\r
+ * setting/clearing configUSE_ATOMIC_INSTRUCTION in FreeRTOSConfig.h.\r
+ * Define AND set configUSE_ATOMIC_INSTRUCTION to 1 for ISA native atomic support.\r
+ * Undefine OR clear configUSE_ATOMIC_INSTRUCTION for disabling global interrupt\r
+ * implementation.\r
+ *\r
+ * @see GCC Built-in Functions for Memory Model Aware Atomic Operations\r
+ * https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html\r
+ */\r
+\r
+#ifndef ATOMIC_H\r
+#define ATOMIC_H\r
+\r
+#ifndef INC_FREERTOS_H\r
+ #error "include FreeRTOS.h must appear in source files before include atomic.h"\r
+#endif\r
+\r
+/* Standard includes. */\r
+#include <stdint.h>\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+#if defined ( configUSE_GCC_BUILTIN_ATOMICS ) && ( configUSE_GCC_BUILTIN_ATOMICS == 1 )\r
+\r
+ /* Needed for __atomic_compare_exchange() weak=false. */\r
+ #include <stdbool.h>\r
+\r
+ /* This branch is for GCC compiler and GCC compiler only. */\r
+ #ifndef portFORCE_INLINE\r
+ #define portFORCE_INLINE inline __attribute__((always_inline))\r
+ #endif\r
+\r
+#else\r
+\r
+ /* Port specific definitions -- entering/exiting critical section.\r
+ * Refer template -- ./lib/FreeRTOS/portable/Compiler/Arch/portmacro.h\r
+ *\r
+ * Every call to ATOMIC_EXIT_CRITICAL() must be closely paired with\r
+ * ATOMIC_ENTER_CRITICAL().\r
+ */\r
+ #if defined( portSET_INTERRUPT_MASK_FROM_ISR )\r
+\r
+ /* Nested interrupt scheme is supported in this port. */\r
+ #define ATOMIC_ENTER_CRITICAL() \\r
+ UBaseType_t uxCriticalSectionType = portSET_INTERRUPT_MASK_FROM_ISR()\r
+\r
+ #define ATOMIC_EXIT_CRITICAL() \\r
+ portCLEAR_INTERRUPT_MASK_FROM_ISR( uxCriticalSectionType )\r
+\r
+ #else\r
+\r
+ /* Nested interrupt scheme is NOT supported in this port. */\r
+ #define ATOMIC_ENTER_CRITICAL() portENTER_CRITICAL()\r
+ #define ATOMIC_EXIT_CRITICAL() portEXIT_CRITICAL()\r
+\r
+ #endif /* portSET_INTERRUPT_MASK_FROM_ISR() */\r
+\r
+ /* Port specific definition -- "always inline". \r
+ * Inline is compiler specific, and may not always get inlined depending on your optimization level. \r
+ * Also, inline is considerred as performance optimization for atomic. \r
+ * Thus, if portFORCE_INLINE is not provided by portmacro.h, instead of resulting error,\r
+ * simply define it. \r
+ */\r
+ #ifndef portFORCE_INLINE\r
+ #define portFORCE_INLINE \r
+ #endif\r
+\r
+#endif /* configUSE_GCC_BUILTIN_ATOMICS */\r
+\r
+#define ATOMIC_COMPARE_AND_SWAP_SUCCESS 0x1U /**< Compare and swap succeeded, swapped. */\r
+#define ATOMIC_COMPARE_AND_SWAP_FAILURE 0x0U /**< Compare and swap failed, did not swap. */\r
+\r
+/*----------------------------- Swap && CAS ------------------------------*/\r
+\r
+/**\r
+ * Atomic compare-and-swap\r
+ *\r
+ * @brief Performs an atomic compare-and-swap operation on the specified values.\r
+ *\r
+ * @param[in, out] pDestination Pointer to memory location from where value is\r
+ * to be loaded and checked.\r
+ * @param[in] ulExchange If condition meets, write this value to memory.\r
+ * @param[in] ulComparand Swap condition.\r
+ *\r
+ * @return Unsigned integer of value 1 or 0. 1 for swapped, 0 for not swapped.\r
+ *\r
+ * @note This function only swaps *pDestination with ulExchange, if previous\r
+ * *pDestination value equals ulComparand.\r
+ */\r
+static portFORCE_INLINE uint32_t Atomic_CompareAndSwap_u32(\r
+ uint32_t volatile * pDestination,\r
+ uint32_t ulExchange,\r
+ uint32_t ulComparand )\r
+{\r
+\r
+ uint32_t ulReturnValue = ATOMIC_COMPARE_AND_SWAP_FAILURE;\r
+\r
+#if defined ( configUSE_GCC_BUILTIN_ATOMICS ) && ( configUSE_GCC_BUILTIN_ATOMICS == 1 )\r
+\r
+ if ( __atomic_compare_exchange( pDestination,\r
+ &ulComparand,\r
+ &ulExchange,\r
+ false,\r
+ __ATOMIC_SEQ_CST,\r
+ __ATOMIC_SEQ_CST ) )\r
+ {\r
+ ulReturnValue = ATOMIC_COMPARE_AND_SWAP_SUCCESS;\r
+ }\r
+\r
+#else\r
+\r
+ ATOMIC_ENTER_CRITICAL();\r
+\r
+ if ( *pDestination == ulComparand )\r
+ {\r
+ *pDestination = ulExchange;\r
+ ulReturnValue = ATOMIC_COMPARE_AND_SWAP_SUCCESS;\r
+ }\r
+\r
+ ATOMIC_EXIT_CRITICAL();\r
+\r
+#endif\r
+\r
+ return ulReturnValue;\r
+\r
+}\r
+\r
+/**\r
+ * Atomic swap (pointers)\r
+ *\r
+ * @brief Atomically sets the address pointed to by *ppDestination to the value\r
+ * of *pExchange.\r
+ *\r
+ * @param[in, out] ppDestination Pointer to memory location from where a pointer\r
+ * value is to be loaded and written back to.\r
+ * @param[in] pExchange Pointer value to be written to *ppDestination.\r
+ *\r
+ * @return The initial value of *ppDestination.\r
+ */\r
+static portFORCE_INLINE void * Atomic_SwapPointers_p32(\r
+ void * volatile * ppDestination,\r
+ void * pExchange )\r
+{\r
+ void * pReturnValue;\r
+\r
+#if defined ( configUSE_GCC_BUILTIN_ATOMICS ) && ( configUSE_GCC_BUILTIN_ATOMICS == 1 )\r
+\r
+ __atomic_exchange( ppDestination, &pExchange, &pReturnValue, __ATOMIC_SEQ_CST );\r
+\r
+#else\r
+\r
+ ATOMIC_ENTER_CRITICAL();\r
+\r
+ pReturnValue = *ppDestination;\r
+\r
+ *ppDestination = pExchange;\r
+\r
+ ATOMIC_EXIT_CRITICAL();\r
+\r
+#endif\r
+\r
+ return pReturnValue;\r
+}\r
+\r
+/**\r
+ * Atomic compare-and-swap (pointers)\r
+ *\r
+ * @brief Performs an atomic compare-and-swap operation on the specified pointer\r
+ * values.\r
+ *\r
+ * @param[in, out] ppDestination Pointer to memory location from where a pointer\r
+ * value is to be loaded and checked.\r
+ * @param[in] pExchange If condition meets, write this value to memory.\r
+ * @param[in] pComparand Swap condition.\r
+ *\r
+ * @return Unsigned integer of value 1 or 0. 1 for swapped, 0 for not swapped.\r
+ *\r
+ * @note This function only swaps *ppDestination with pExchange, if previous\r
+ * *ppDestination value equals pComparand.\r
+ */\r
+static portFORCE_INLINE uint32_t Atomic_CompareAndSwapPointers_p32(\r
+ void * volatile * ppDestination,\r
+ void * pExchange, void * pComparand )\r
+{\r
+ uint32_t ulReturnValue = ATOMIC_COMPARE_AND_SWAP_FAILURE;\r
+\r
+#if defined ( configUSE_GCC_BUILTIN_ATOMICS ) && ( configUSE_GCC_BUILTIN_ATOMICS == 1 )\r
+ if ( __atomic_compare_exchange( ppDestination,\r
+ &pComparand,\r
+ &pExchange,\r
+ false,\r
+ __ATOMIC_SEQ_CST,\r
+ __ATOMIC_SEQ_CST ) )\r
+ {\r
+ ulReturnValue = ATOMIC_COMPARE_AND_SWAP_SUCCESS;\r
+ }\r
+\r
+#else\r
+\r
+ ATOMIC_ENTER_CRITICAL();\r
+\r
+ if ( *ppDestination == pComparand )\r
+ {\r
+ *ppDestination = pExchange;\r
+ ulReturnValue = ATOMIC_COMPARE_AND_SWAP_SUCCESS;\r
+ }\r
+\r
+ ATOMIC_EXIT_CRITICAL();\r
+\r
+#endif\r
+\r
+ return ulReturnValue;\r
+}\r
+\r
+\r
+/*----------------------------- Arithmetic ------------------------------*/\r
+\r
+/**\r
+ * Atomic add\r
+ *\r
+ * @brief Atomically adds count to the value of the specified pointer points to.\r
+ *\r
+ * @param[in,out] pAddend Pointer to memory location from where value is to be\r
+ * loaded and written back to.\r
+ * @param[in] ulCount Value to be added to *pAddend.\r
+ *\r
+ * @return previous *pAddend value.\r
+ */\r
+static portFORCE_INLINE uint32_t Atomic_Add_u32(\r
+ uint32_t volatile * pAddend,\r
+ uint32_t ulCount )\r
+{\r
+#if defined ( configUSE_GCC_BUILTIN_ATOMICS ) && ( configUSE_GCC_BUILTIN_ATOMICS == 1 )\r
+\r
+ return __atomic_fetch_add(pAddend, ulCount, __ATOMIC_SEQ_CST);\r
+\r
+#else\r
+\r
+ uint32_t ulCurrent;\r
+\r
+ ATOMIC_ENTER_CRITICAL();\r
+\r
+ ulCurrent = *pAddend;\r
+\r
+ *pAddend += ulCount;\r
+\r
+ ATOMIC_EXIT_CRITICAL();\r
+\r
+ return ulCurrent;\r
+\r
+#endif\r
+}\r
+\r
+/**\r
+ * Atomic subtract\r
+ *\r
+ * @brief Atomically subtracts count from the value of the specified pointer\r
+ * pointers to.\r
+ *\r
+ * @param[in,out] pAddend Pointer to memory location from where value is to be\r
+ * loaded and written back to.\r
+ * @param[in] ulCount Value to be subtract from *pAddend.\r
+ *\r
+ * @return previous *pAddend value.\r
+ */\r
+static portFORCE_INLINE uint32_t Atomic_Subtract_u32(\r
+ uint32_t volatile * pAddend,\r
+ uint32_t ulCount )\r
+{\r
+#if defined ( configUSE_GCC_BUILTIN_ATOMICS ) && ( configUSE_GCC_BUILTIN_ATOMICS == 1 )\r
+\r
+ return __atomic_fetch_sub(pAddend, ulCount, __ATOMIC_SEQ_CST);\r
+\r
+#else\r
+\r
+ uint32_t ulCurrent;\r
+\r
+ ATOMIC_ENTER_CRITICAL();\r
+\r
+ ulCurrent = *pAddend;\r
+\r
+ *pAddend -= ulCount;\r
+\r
+ ATOMIC_EXIT_CRITICAL();\r
+\r
+ return ulCurrent;\r
+\r
+#endif\r
+}\r
+\r
+/**\r
+ * Atomic increment\r
+ *\r
+ * @brief Atomically increments the value of the specified pointer points to.\r
+ *\r
+ * @param[in,out] pAddend Pointer to memory location from where value is to be\r
+ * loaded and written back to.\r
+ *\r
+ * @return *pAddend value before increment.\r
+ */\r
+static portFORCE_INLINE uint32_t Atomic_Increment_u32( uint32_t volatile * pAddend )\r
+{\r
+#if defined ( configUSE_GCC_BUILTIN_ATOMICS ) && ( configUSE_GCC_BUILTIN_ATOMICS == 1 )\r
+\r
+ return __atomic_fetch_add(pAddend, 1, __ATOMIC_SEQ_CST);\r
+\r
+#else\r
+\r
+ uint32_t ulCurrent;\r
+\r
+ ATOMIC_ENTER_CRITICAL();\r
+\r
+ ulCurrent = *pAddend;\r
+\r
+ *pAddend += 1;\r
+\r
+ ATOMIC_EXIT_CRITICAL();\r
+\r
+ return ulCurrent;\r
+\r
+#endif\r
+}\r
+\r
+/**\r
+ * Atomic decrement\r
+ *\r
+ * @brief Atomically decrements the value of the specified pointer points to\r
+ *\r
+ * @param[in,out] pAddend Pointer to memory location from where value is to be\r
+ * loaded and written back to.\r
+ *\r
+ * @return *pAddend value before decrement.\r
+ */\r
+static portFORCE_INLINE uint32_t Atomic_Decrement_u32( uint32_t volatile * pAddend )\r
+{\r
+#if defined ( configUSE_GCC_BUILTIN_ATOMICS ) && ( configUSE_GCC_BUILTIN_ATOMICS == 1 )\r
+\r
+ return __atomic_fetch_sub(pAddend, 1, __ATOMIC_SEQ_CST);\r
+\r
+#else\r
+\r
+ uint32_t ulCurrent;\r
+\r
+ ATOMIC_ENTER_CRITICAL();\r
+\r
+ ulCurrent = *pAddend;\r
+\r
+ *pAddend -= 1;\r
+\r
+ ATOMIC_EXIT_CRITICAL();\r
+\r
+ return ulCurrent;\r
+\r
+#endif\r
+}\r
+\r
+/*----------------------------- Bitwise Logical ------------------------------*/\r
+\r
+/**\r
+ * Atomic OR\r
+ *\r
+ * @brief Performs an atomic OR operation on the specified values.\r
+ *\r
+ * @param [in, out] pDestination Pointer to memory location from where value is\r
+ * to be loaded and written back to.\r
+ * @param [in] ulValue Value to be ORed with *pDestination.\r
+ *\r
+ * @return The original value of *pDestination.\r
+ */\r
+static portFORCE_INLINE uint32_t Atomic_OR_u32(\r
+ uint32_t volatile * pDestination,\r
+ uint32_t ulValue )\r
+{\r
+#if defined ( configUSE_GCC_BUILTIN_ATOMICS ) && ( configUSE_GCC_BUILTIN_ATOMICS == 1 )\r
+\r
+ return __atomic_fetch_or(pDestination, ulValue, __ATOMIC_SEQ_CST);\r
+\r
+#else\r
+\r
+ uint32_t ulCurrent;\r
+\r
+ ATOMIC_ENTER_CRITICAL();\r
+\r
+ ulCurrent = *pDestination;\r
+\r
+ *pDestination |= ulValue;\r
+\r
+ ATOMIC_EXIT_CRITICAL();\r
+\r
+ return ulCurrent;\r
+\r
+#endif\r
+}\r
+\r
+/**\r
+ * Atomic AND\r
+ *\r
+ * @brief Performs an atomic AND operation on the specified values.\r
+ *\r
+ * @param [in, out] pDestination Pointer to memory location from where value is\r
+ * to be loaded and written back to.\r
+ * @param [in] ulValue Value to be ANDed with *pDestination.\r
+ *\r
+ * @return The original value of *pDestination.\r
+ */\r
+static portFORCE_INLINE uint32_t Atomic_AND_u32(\r
+ uint32_t volatile * pDestination,\r
+ uint32_t ulValue )\r
+{\r
+#if defined ( configUSE_GCC_BUILTIN_ATOMICS ) && ( configUSE_GCC_BUILTIN_ATOMICS == 1 )\r
+\r
+ return __atomic_fetch_and(pDestination, ulValue, __ATOMIC_SEQ_CST);\r
+\r
+#else\r
+\r
+ uint32_t ulCurrent;\r
+\r
+ ATOMIC_ENTER_CRITICAL();\r
+\r
+ ulCurrent = *pDestination;\r
+\r
+ *pDestination &= ulValue;\r
+\r
+ ATOMIC_EXIT_CRITICAL();\r
+\r
+ return ulCurrent;\r
+\r
+#endif\r
+}\r
+\r
+/**\r
+ * Atomic NAND\r
+ *\r
+ * @brief Performs an atomic NAND operation on the specified values.\r
+ *\r
+ * @param [in, out] pDestination Pointer to memory location from where value is\r
+ * to be loaded and written back to.\r
+ * @param [in] ulValue Value to be NANDed with *pDestination.\r
+ *\r
+ * @return The original value of *pDestination.\r
+ */\r
+static portFORCE_INLINE uint32_t Atomic_NAND_u32(\r
+ uint32_t volatile * pDestination,\r
+ uint32_t ulValue )\r
+{\r
+#if defined ( configUSE_GCC_BUILTIN_ATOMICS ) && ( configUSE_GCC_BUILTIN_ATOMICS == 1 )\r
+\r
+ return __atomic_fetch_nand(pDestination, ulValue, __ATOMIC_SEQ_CST);\r
+\r
+#else\r
+\r
+ uint32_t ulCurrent;\r
+\r
+ ATOMIC_ENTER_CRITICAL();\r
+\r
+ ulCurrent = *pDestination;\r
+\r
+ *pDestination = ~(ulCurrent & ulValue);\r
+\r
+ ATOMIC_EXIT_CRITICAL();\r
+\r
+ return ulCurrent;\r
+\r
+#endif\r
+}\r
+\r
+/**\r
+ * Atomic XOR\r
+ *\r
+ * @brief Performs an atomic XOR operation on the specified values.\r
+ *\r
+ * @param [in, out] pDestination Pointer to memory location from where value is\r
+ * to be loaded and written back to.\r
+ * @param [in] ulValue Value to be XORed with *pDestination.\r
+ *\r
+ * @return The original value of *pDestination.\r
+ */\r
+static portFORCE_INLINE uint32_t Atomic_XOR_u32(\r
+ uint32_t volatile * pDestination,\r
+ uint32_t ulValue )\r
+{\r
+#if defined ( configUSE_GCC_BUILTIN_ATOMICS ) && ( configUSE_GCC_BUILTIN_ATOMICS == 1 )\r
+\r
+ return __atomic_fetch_xor(pDestination, ulValue, __ATOMIC_SEQ_CST);\r
+\r
+#else\r
+\r
+ uint32_t ulCurrent;\r
+\r
+ ATOMIC_ENTER_CRITICAL();\r
+\r
+ ulCurrent = *pDestination;\r
+\r
+ *pDestination ^= ulValue;\r
+\r
+ ATOMIC_EXIT_CRITICAL();\r
+\r
+ return ulCurrent;\r
+\r
+#endif\r
+}\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif /* ATOMIC_H */\r
--- /dev/null
+/*\r
+ * Amazon FreeRTOS V1.4.7\r
+ * Copyright (C) 2017 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 aws_secure_sockets_config.h\r
+ * @brief Secure sockets configuration options.\r
+ */\r
+\r
+#ifndef _AWS_SECURE_SOCKETS_CONFIG_H_\r
+#define _AWS_SECURE_SOCKETS_CONFIG_H_\r
+\r
+/**\r
+ * @brief Byte order of the target MCU.\r
+ *\r
+ * Valid values are pdLITTLE_ENDIAN and pdBIG_ENDIAN.\r
+ */\r
+#define socketsconfigBYTE_ORDER pdLITTLE_ENDIAN\r
+\r
+/**\r
+ * @brief Default socket send timeout.\r
+ */\r
+#define socketsconfigDEFAULT_SEND_TIMEOUT ( 10000 )\r
+\r
+/**\r
+ * @brief Default socket receive timeout.\r
+ */\r
+#define socketsconfigDEFAULT_RECV_TIMEOUT ( 10000 )\r
+\r
+/**\r
+ * @brief Enable metrics of secure socket.\r
+ */\r
+#define AWS_IOT_SECURE_SOCKETS_METRICS_ENABLED ( 0 )\r
+\r
+#endif /* _AWS_SECURE_SOCKETS_CONFIG_H_ */
\ No newline at end of file
--- /dev/null
+/*\r
+ * Amazon FreeRTOS Platform V1.0.0\r
+ * Copyright (C) 2019 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_network_freertos.h\r
+ * @brief Declares the network stack functions specified in aws_iot_network.h for\r
+ * Amazon FreeRTOS Secure Sockets.\r
+ */\r
+\r
+#ifndef _IOT_NETWORK_AFR_H_\r
+#define _IOT_NETWORK_AFR_H_\r
+\r
+/* Standard includes. */\r
+#include <stdbool.h>\r
+\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
+ *\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
+\r
+/**\r
+ * @brief Provides a default value for an #IotNetworkConnectionAfr_t.\r
+ *\r
+ * All instances of #IotNetworkConnectionAfr_t should be initialized with\r
+ * this constant.\r
+ *\r
+ * @warning Failing to initialize an #IotNetworkConnectionAfr_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
+\r
+/**\r
+ * @brief Generic initializer for an #IotNetworkServerInfo_t.\r
+ *\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
+\r
+/**\r
+ * @brief Generic initializer for an #IotNetworkCredentials_t.\r
+ *\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
+\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
+\r
+/**\r
+ * @brief An implementation of #IotNetworkInterface_t::create for Amazon FreeRTOS\r
+ * Secure Sockets.\r
+ */\r
+IotNetworkError_t IotNetworkAfr_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
+ */\r
+IotNetworkError_t IotNetworkAfr_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
+ */\r
+size_t IotNetworkAfr_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
+ */\r
+size_t IotNetworkAfr_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
+ */\r
+IotNetworkError_t IotNetworkAfr_Close( void * pConnection );\r
+\r
+/**\r
+ * @brief An implementation of #IotNetworkInterface_t::destroy for Amazon FreeRTOS\r
+ * Secure Sockets.\r
+ */\r
+IotNetworkError_t IotNetworkAfr_Destroy( void * pConnection );\r
+\r
+/**\r
+ * @cond DOXYGEN_IGNORE\r
+ * Doxygen should ignore this section.\r
+ *\r
+ * Declaration of a network interface struct using the functions in this file.\r
+ */\r
+extern const IotNetworkInterface_t IotNetworkAfr;\r
+/** @endcond */\r
+\r
+#endif /* ifndef _IOT_NETWORK_AFR_H_ */\r
--- /dev/null
+/*\r
+ * Amazon FreeRTOS Platform V1.0.0\r
+ * Copyright (C) 2019 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_network_freertos.c\r
+ * @brief Implementation of the network-related functions from iot_network_freertos.h\r
+ * for Amazon FreeRTOS secure sockets.\r
+ */\r
+\r
+/* The config header is always included first. */\r
+#include "iot_config.h"\r
+\r
+/* Standard includes. */\r
+#include <string.h>\r
+\r
+/* FreeRTOS includes. */\r
+#include "semphr.h"\r
+#include "event_groups.h"\r
+\r
+/* Error handling include. */\r
+#include "private/iot_error.h"\r
+\r
+/* Amazon FreeRTOS network include. */\r
+#include "platform/iot_network_freertos.h"\r
+\r
+/* Configure logs for the functions in this file. */\r
+#ifdef IOT_LOG_LEVEL_NETWORK\r
+ #define LIBRARY_LOG_LEVEL IOT_LOG_LEVEL_NETWORK\r
+#else\r
+ #ifdef IOT_LOG_LEVEL_GLOBAL\r
+ #define LIBRARY_LOG_LEVEL IOT_LOG_LEVEL_GLOBAL\r
+ #else\r
+ #define LIBRARY_LOG_LEVEL IOT_LOG_NONE\r
+ #endif\r
+#endif\r
+\r
+#define LIBRARY_LOG_NAME ( "NET" )\r
+#include "iot_logging_setup.h"\r
+\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
+#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
+\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
+\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
+\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
+} _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
+{\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
+};\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+/**\r
+ * @brief Destroys a network connection.\r
+ *\r
+ * @param[in] pNetworkConnection The connection to destroy.\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
+\r
+ /* Free the network connection. */\r
+ vPortFree( pNetworkConnection );\r
+}\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+/**\r
+ * @brief Task routine that waits on incoming network data.\r
+ *\r
+ * @param[in] pArgument The network connection.\r
+ */\r
+static void _networkReceiveTask( void * pArgument )\r
+{\r
+ bool destroyConnection = false;\r
+ int32_t socketStatus = 0;\r
+ EventBits_t connectionFlags = 0;\r
+\r
+ /* Cast network connection to the correct type. */\r
+ _networkConnection_t * pNetworkConnection = pArgument;\r
+\r
+ while( true )\r
+ {\r
+ /* No buffered byte should be in the connection. */\r
+ configASSERT( pNetworkConnection->bufferedByteValid == false );\r
+\r
+ /* Block and wait for 1 byte of data. This simulates the behavior of poll().\r
+ * THIS IS A TEMPORARY WORKAROUND AND DOES NOT PROVIDE THREAD-SAFETY AGAINST\r
+ * MULTIPLE CALLS OF RECEIVE. */\r
+ do\r
+ {\r
+ socketStatus = SOCKETS_Recv( pNetworkConnection->socket,\r
+ &( pNetworkConnection->bufferedByte ),\r
+ 1,\r
+ 0 );\r
+\r
+ connectionFlags = xEventGroupGetBits( ( EventGroupHandle_t ) &( pNetworkConnection->connectionFlags ) );\r
+\r
+ if( ( connectionFlags & _FLAG_SHUTDOWN ) == _FLAG_SHUTDOWN )\r
+ {\r
+ socketStatus = SOCKETS_ECLOSED;\r
+ }\r
+\r
+ /* Check for timeout. Some ports return 0, some return EWOULDBLOCK. */\r
+ } while( ( socketStatus == 0 ) || ( socketStatus == SOCKETS_EWOULDBLOCK ) );\r
+\r
+ if( socketStatus <= 0 )\r
+ {\r
+ break;\r
+ }\r
+\r
+ pNetworkConnection->bufferedByteValid = true;\r
+\r
+ /* Invoke the network callback. */\r
+ pNetworkConnection->receiveCallback( pNetworkConnection,\r
+ pNetworkConnection->pReceiveContext );\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
+\r
+ if( ( connectionFlags & _FLAG_CONNECTION_DESTROYED ) == _FLAG_CONNECTION_DESTROYED )\r
+ {\r
+ destroyConnection = true;\r
+ break;\r
+ }\r
+ }\r
+\r
+ IotLogDebug( "Network receive task terminating." );\r
+\r
+ /* If necessary, destroy the network connection before exiting. */\r
+ if( destroyConnection == true )\r
+ {\r
+ _destroyConnection( pNetworkConnection );\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
+ }\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
+{\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
+ const TickType_t receiveTimeout = pdMS_TO_TICKS( IOT_NETWORK_SOCKET_POLL_MS );\r
+ _networkConnection_t * pNewNetworkConnection = 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
+ const size_t hostnameLength = strlen( pServerInfo->pHostName );\r
+\r
+ if( hostnameLength > ( size_t ) securesocketsMAX_DNS_NAME_LENGTH )\r
+ {\r
+ IotLogError( "Host name length exceeds %d, which is the maximum allowed.",\r
+ securesocketsMAX_DNS_NAME_LENGTH );\r
+ IOT_SET_AND_GOTO_CLEANUP( IOT_NETWORK_BAD_PARAMETER );\r
+ }\r
+\r
+ pNewNetworkConnection = pvPortMalloc( sizeof( _networkConnection_t ) );\r
+\r
+ if( pNewNetworkConnection == NULL )\r
+ {\r
+ IotLogError( "Failed to allocate memory for new network connection." );\r
+ IOT_SET_AND_GOTO_CLEANUP( IOT_NETWORK_NO_MEMORY );\r
+ }\r
+\r
+ /* Clear the connection information. */\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
+\r
+ if( tcpSocket == SOCKETS_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
+\r
+ /* Check for errors from DNS lookup. */\r
+ if( serverAddress.ulAddress == 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
+\r
+ if( socketStatus != SOCKETS_ERROR_NONE )\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
+\r
+ if( socketStatus != SOCKETS_ERROR_NONE )\r
+ {\r
+ IotLogError( "Failed to set socket receive timeout." );\r
+ IOT_SET_AND_GOTO_CLEANUP( IOT_NETWORK_SYSTEM_ERROR );\r
+ }\r
+\r
+ IOT_FUNCTION_CLEANUP_BEGIN();\r
+\r
+ /* Clean up on failure. */\r
+ if( status != IOT_NETWORK_SUCCESS )\r
+ {\r
+ if( tcpSocket != SOCKETS_INVALID_SOCKET )\r
+ {\r
+ SOCKETS_Close( tcpSocket );\r
+ }\r
+\r
+ /* Clear the connection information. */\r
+ if( pNewNetworkConnection != NULL )\r
+ {\r
+ vPortFree( pNewNetworkConnection );\r
+ }\r
+ }\r
+ else\r
+ {\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
+\r
+ /* Set the output parameter. */\r
+ *pNetworkConnection = pNewNetworkConnection;\r
+ }\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
+{\r
+ IotNetworkError_t status = IOT_NETWORK_SUCCESS;\r
+\r
+ /* Cast network connection to the correct type. */\r
+ _networkConnection_t * pNetworkConnection = ( _networkConnection_t * ) pConnection;\r
+\r
+ /* Set the receive callback and context. */\r
+ pNetworkConnection->receiveCallback = receiveCallback;\r
+ pNetworkConnection->pReceiveContext = pContext;\r
+\r
+ /* No flags should be set. */\r
+ configASSERT( xEventGroupGetBits( ( EventGroupHandle_t ) &( pNetworkConnection->connectionFlags ) ) == 0 );\r
+\r
+ /* Create task that waits for incoming data. */\r
+ if( xTaskCreate( _networkReceiveTask,\r
+ "NetRecv",\r
+ IOT_NETWORK_RECEIVE_TASK_STACK_SIZE,\r
+ pNetworkConnection,\r
+ IOT_NETWORK_RECEIVE_TASK_PRIORITY,\r
+ &( pNetworkConnection->receiveTask ) ) != pdPASS )\r
+ {\r
+ IotLogError( "Failed to create network receive task." );\r
+\r
+ status = IOT_NETWORK_SYSTEM_ERROR;\r
+ }\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
+{\r
+ size_t bytesSent = 0;\r
+ int32_t socketStatus = SOCKETS_ERROR_NONE;\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
+ {\r
+ socketStatus = SOCKETS_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
+ }\r
+\r
+ return bytesSent;\r
+}\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+size_t IotNetworkAfr_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
+\r
+ /* Cast network connection to the correct type. */\r
+ _networkConnection_t * pNetworkConnection = ( _networkConnection_t * ) pConnection;\r
+\r
+ /* Write the buffered byte. THIS IS A TEMPORARY WORKAROUND AND ASSUMES THIS\r
+ * FUNCTION IS ALWAYS CALLED FROM THE RECEIVE CALLBACK. */\r
+ if( pNetworkConnection->bufferedByteValid == true )\r
+ {\r
+ *pBuffer = pNetworkConnection->bufferedByte;\r
+ bytesReceived = 1;\r
+ bytesRemaining--;\r
+ pNetworkConnection->bufferedByteValid = false;\r
+ }\r
+\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
+\r
+ if( socketStatus == SOCKETS_EWOULDBLOCK )\r
+ {\r
+ /* The return value EWOULDBLOCK means no data was received within\r
+ * the socket timeout. Ignore it and try again. */\r
+ continue;\r
+ }\r
+ else if( socketStatus <= 0 )\r
+ {\r
+ IotLogError( "Error %ld while receiving data.", ( long int ) socketStatus );\r
+ break;\r
+ }\r
+ else\r
+ {\r
+ bytesReceived += ( size_t ) socketStatus;\r
+ bytesRemaining -= ( size_t ) socketStatus;\r
+\r
+ configASSERT( bytesReceived + bytesRemaining == bytesRequested );\r
+ }\r
+ }\r
+\r
+ if( bytesReceived < bytesRequested )\r
+ {\r
+ IotLogWarn( "Receive requested %lu bytes, but %lu bytes received instead.",\r
+ ( unsigned long ) bytesRequested,\r
+ ( unsigned long ) bytesReceived );\r
+ }\r
+ else\r
+ {\r
+ IotLogDebug( "Successfully received %lu bytes.",\r
+ ( unsigned long ) bytesRequested );\r
+ }\r
+\r
+ return bytesReceived;\r
+}\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+IotNetworkError_t IotNetworkAfr_Close( void * pConnection )\r
+{\r
+ int32_t socketStatus = SOCKETS_ERROR_NONE;\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
+\r
+ if( socketStatus != SOCKETS_ERROR_NONE )\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
+\r
+ return IOT_NETWORK_SUCCESS;\r
+}\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+IotNetworkError_t IotNetworkAfr_Destroy( void * pConnection )\r
+{\r
+ /* Cast network connection to the correct type. */\r
+ _networkConnection_t * pNetworkConnection = ( _networkConnection_t * ) pConnection;\r
+\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
+ }\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
+ pdTRUE,\r
+ pdTRUE,\r
+ portMAX_DELAY );\r
+ }\r
+\r
+ _destroyConnection( pNetworkConnection );\r
+ }\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