summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMuneeb Ahmed <54290492+muneebahmed10@users.noreply.github.com>2020-07-08 19:11:13 -0700
committerGitHub <noreply@github.com>2020-07-08 19:11:13 -0700
commit2ee9fe649eccd4c50a5ac9b2a0c4d750816e990e (patch)
tree634fa2dea0264123030f2532796cfbb803216c90
parent265d9d78d7bb003305ff2d33519311b89ed3f0ee (diff)
downloadfreertos-git-2ee9fe649eccd4c50a5ac9b2a0c4d750816e990e.tar.gz
Update MQTT files for network context (#133)
* Update MQTT files for network context * Add transport interface header * Update include path for lightweight demo
-rw-r--r--FreeRTOS-Plus/Demo/FreeRTOS-IoT-Libraries-LTS-Beta2/mqtt/mqtt_light_weight/WIN32.vcxproj2
-rw-r--r--FreeRTOS-Plus/Demo/FreeRTOS-IoT-Libraries-LTS-Beta2/mqtt/mqtt_light_weight/mqtt_config.h3
-rw-r--r--FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta2/c_sdk/platform/transport_interface.h72
-rw-r--r--FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta2/c_sdk/standard/mqtt/include/mqtt.h20
-rw-r--r--FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta2/c_sdk/standard/mqtt/include/mqtt_lightweight.h23
-rw-r--r--FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta2/c_sdk/standard/mqtt/src/mqtt.c13
-rw-r--r--FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta2/c_sdk/standard/mqtt/src/mqtt_lightweight.c14
7 files changed, 95 insertions, 52 deletions
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS-IoT-Libraries-LTS-Beta2/mqtt/mqtt_light_weight/WIN32.vcxproj b/FreeRTOS-Plus/Demo/FreeRTOS-IoT-Libraries-LTS-Beta2/mqtt/mqtt_light_weight/WIN32.vcxproj
index 230fe0574..70f1e92bc 100644
--- a/FreeRTOS-Plus/Demo/FreeRTOS-IoT-Libraries-LTS-Beta2/mqtt/mqtt_light_weight/WIN32.vcxproj
+++ b/FreeRTOS-Plus/Demo/FreeRTOS-IoT-Libraries-LTS-Beta2/mqtt/mqtt_light_weight/WIN32.vcxproj
@@ -58,7 +58,7 @@
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
- <AdditionalIncludeDirectories>..\..\..\..\Source\FreeRTOS-Plus-Trace\Include;..\..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\include;..\..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\portable\BufferManagement;..\..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\portable\Compiler\MSVC;..\..\common\logging-stack;..\common\WinPCap;..\..\..\..\..\FreeRTOS\Source\include;..\..\..\..\..\FreeRTOS\Source\portable\MSVC-MingW;..\..\..\..\Source\FreeRTOS-IoT-Libraries-LTS-Beta2\c_sdk\standard\mqtt\include;.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <AdditionalIncludeDirectories>..\..\..\..\Source\FreeRTOS-Plus-Trace\Include;..\..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\include;..\..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\portable\BufferManagement;..\..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\portable\Compiler\MSVC;..\..\common\logging-stack;..\common\WinPCap;..\..\..\..\..\FreeRTOS\Source\include;..\..\..\..\..\FreeRTOS\Source\portable\MSVC-MingW;..\..\..\..\Source\FreeRTOS-IoT-Libraries-LTS-Beta2\c_sdk\platform;..\..\..\..\Source\FreeRTOS-IoT-Libraries-LTS-Beta2\c_sdk\standard\mqtt\include;.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_WIN32_WINNT=0x0500;WINVER=0x400;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>false</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
diff --git a/FreeRTOS-Plus/Demo/FreeRTOS-IoT-Libraries-LTS-Beta2/mqtt/mqtt_light_weight/mqtt_config.h b/FreeRTOS-Plus/Demo/FreeRTOS-IoT-Libraries-LTS-Beta2/mqtt/mqtt_light_weight/mqtt_config.h
index d86fca6e7..1ed08bbb5 100644
--- a/FreeRTOS-Plus/Demo/FreeRTOS-IoT-Libraries-LTS-Beta2/mqtt/mqtt_light_weight/mqtt_config.h
+++ b/FreeRTOS-Plus/Demo/FreeRTOS-IoT-Libraries-LTS-Beta2/mqtt/mqtt_light_weight/mqtt_config.h
@@ -52,7 +52,4 @@
#include "logging_stack.h"
/************ End of logging configuration ****************/
-/* Set network context to socket (int). */
-typedef int NetworkContext_t;
-
#endif /* ifndef MQTT_CONFIG_H_ */
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta2/c_sdk/platform/transport_interface.h b/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta2/c_sdk/platform/transport_interface.h
new file mode 100644
index 000000000..398022140
--- /dev/null
+++ b/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta2/c_sdk/platform/transport_interface.h
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy of
+ * this software and associated documentation files (the "Software"), to deal in
+ * the Software without restriction, including without limitation the rights to
+ * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ * the Software, and to permit persons to whom the Software is furnished to do so,
+ * subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+ * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef TRANSPORT_INTERFACE_H_
+#define TRANSPORT_INTERFACE_H_
+
+#include <stdint.h>
+#include <stddef.h>
+
+/**
+ * @brief The NetworkContext is an incomplete type. An implementation of this
+ * interface must define NetworkContext as per the requirements. This context
+ * is passed into the network interface functions.
+ */
+struct NetworkContext;
+typedef struct NetworkContext NetworkContext_t;
+
+/**
+ * @brief Transport interface for receiving data on the network.
+ *
+ * @param[in] pNetworkContext Implementation-defined network context.
+ * @param[in] pBuffer Buffer to receive the data into.
+ * @param[in] bytesToRecv Number of bytes requested from the network.
+ *
+ * @return The number of bytes received or a negative error code.
+ */
+typedef int32_t ( * TransportRecv_t )( NetworkContext_t * pNetworkContext,
+ void * pBuffer,
+ size_t bytesToRecv );
+
+/**
+ * @brief Transport interface for sending data over the network.
+ *
+ * @param[in] pNetworkContext Implementation-defined network context.
+ * @param[in] pBuffer Buffer containing the bytes to send over the network stack.
+ * @param[in] bytesToSend Number of bytes to send over the network.
+ *
+ * @return The number of bytes sent or a negative error code.
+ */
+typedef int32_t ( * TransportSend_t )( NetworkContext_t * pNetworkContext,
+ const void * pBuffer,
+ size_t bytesToSend );
+
+/**
+ * @brief The transport layer interface.
+ */
+typedef struct TransportInterface
+{
+ TransportRecv_t recv; /**< Transport receive interface. */
+ TransportSend_t send; /**< Transport send interface. */
+ NetworkContext_t * pNetworkContext; /**< Implementation-defined network context. */
+} TransportInterface_t;
+
+#endif /* ifndef TRANSPORT_INTERFACE_H_ */
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta2/c_sdk/standard/mqtt/include/mqtt.h b/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta2/c_sdk/standard/mqtt/include/mqtt.h
index 7dfef1285..8db419707 100644
--- a/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta2/c_sdk/standard/mqtt/include/mqtt.h
+++ b/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta2/c_sdk/standard/mqtt/include/mqtt.h
@@ -26,6 +26,8 @@
#include "mqtt_config.h"
#include "mqtt_lightweight.h"
+#include "transport_interface.h"
+
/**
* @brief Invalid packet identifier.
*
@@ -42,13 +44,6 @@ typedef struct MQTTPubAckInfo MQTTPubAckInfo_t;
struct MQTTContext;
typedef struct MQTTContext MQTTContext_t;
-struct MQTTTransportInterface;
-typedef struct MQTTTransportInterface MQTTTransportInterface_t;
-
-typedef int32_t (* MQTTTransportSendFunc_t )( NetworkContext_t context,
- const void * pMessage,
- size_t bytesToSend );
-
typedef uint32_t (* MQTTGetCurrentTimeFunc_t )( void );
typedef void (* MQTTEventCallback_t )( MQTTContext_t * pContext,
@@ -85,13 +80,6 @@ typedef enum MQTTPubAckType
MQTTPubcomp
} MQTTPubAckType_t;
-struct MQTTTransportInterface
-{
- MQTTTransportSendFunc_t send;
- MQTTTransportRecvFunc_t recv;
- NetworkContext_t networkContext;
-};
-
struct MQTTApplicationCallbacks
{
MQTTGetCurrentTimeFunc_t getTime;
@@ -112,7 +100,7 @@ struct MQTTContext
MQTTPubAckInfo_t incomingPublishRecords[ MQTT_STATE_ARRAY_MAX_COUNT ];
size_t incomingPublishCount;
- MQTTTransportInterface_t transportInterface;
+ TransportInterface_t transportInterface;
MQTTFixedBuffer_t networkBuffer;
uint16_t nextPacketId;
@@ -147,7 +135,7 @@ struct MQTTContext
* #MQTTSuccess otherwise.
*/
MQTTStatus_t MQTT_Init( MQTTContext_t * pContext,
- const MQTTTransportInterface_t * pTransportInterface,
+ const TransportInterface_t * pTransportInterface,
const MQTTApplicationCallbacks_t * pCallbacks,
const MQTTFixedBuffer_t * pNetworkBuffer );
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta2/c_sdk/standard/mqtt/include/mqtt_lightweight.h b/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta2/c_sdk/standard/mqtt/include/mqtt_lightweight.h
index f1799febc..73ac80449 100644
--- a/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta2/c_sdk/standard/mqtt/include/mqtt_lightweight.h
+++ b/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta2/c_sdk/standard/mqtt/include/mqtt_lightweight.h
@@ -37,6 +37,8 @@
/* Include config file before other headers. */
#include "mqtt_config.h"
+#include "transport_interface.h"
+
/* MQTT packet types. */
#define MQTT_PACKET_TYPE_CONNECT ( ( uint8_t ) 0x10U ) /**< @brief CONNECT (client-to-server). */
#define MQTT_PACKET_TYPE_CONNACK ( ( uint8_t ) 0x20U ) /**< @brief CONNACK (server-to-client). */
@@ -75,23 +77,6 @@ struct MQTTPacketInfo;
typedef struct MQTTPacketInfo MQTTPacketInfo_t;
/**
- * @brief Signature of the transport interface receive function.
- *
- * A function with this signature must be provided to the MQTT library to read
- * data off the network.
- *
- * @param[in] context The network context provided with this function.
- * @param[out] pBuffer Buffer to receive network data.
- * @param[in] bytesToRecv Bytes to receive from the network. pBuffer must be at
- * least this size.
- *
- * @return The number of bytes received; negative value on failure.
- */
-typedef int32_t (* MQTTTransportRecvFunc_t )( NetworkContext_t context,
- void * pBuffer,
- size_t bytesToRecv );
-
-/**
* @brief Return codes from MQTT functions.
*/
typedef enum MQTTStatus
@@ -539,8 +524,8 @@ MQTTStatus_t MQTT_DeserializeAck( const MQTTPacketInfo_t * pIncomingPacket,
* #MQTTBadResponse if an invalid packet is read, and
* #MQTTNoDataAvailable if there is nothing to read.
*/
-MQTTStatus_t MQTT_GetIncomingPacketTypeAndLength( MQTTTransportRecvFunc_t readFunc,
- NetworkContext_t networkContext,
+MQTTStatus_t MQTT_GetIncomingPacketTypeAndLength( TransportRecv_t readFunc,
+ NetworkContext_t * pNetworkContext,
MQTTPacketInfo_t * pIncomingPacket );
#endif /* ifndef MQTT_LIGHTWEIGHT_H */
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta2/c_sdk/standard/mqtt/src/mqtt.c b/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta2/c_sdk/standard/mqtt/src/mqtt.c
index 50db50da5..ea5247b6e 100644
--- a/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta2/c_sdk/standard/mqtt/src/mqtt.c
+++ b/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta2/c_sdk/standard/mqtt/src/mqtt.c
@@ -323,7 +323,7 @@ static int32_t sendPacket( MQTTContext_t * pContext,
/* Loop until the entire packet is sent. */
while( bytesRemaining > 0UL )
{
- bytesSent = pContext->transportInterface.send( pContext->transportInterface.networkContext,
+ bytesSent = pContext->transportInterface.send( pContext->transportInterface.pNetworkContext,
pIndex,
bytesRemaining );
@@ -408,13 +408,14 @@ static int32_t recvExact( const MQTTContext_t * pContext,
size_t bytesRemaining = bytesToRecv;
int32_t totalBytesRecvd = 0, bytesRecvd;
uint32_t entryTimeMs = 0U, elapsedTimeMs = 0U;
- MQTTTransportRecvFunc_t recvFunc = NULL;
+ TransportRecv_t recvFunc = NULL;
MQTTGetCurrentTimeFunc_t getTimeStampMs = NULL;
bool receiveError = false;
assert( pContext != NULL );
assert( bytesToRecv <= pContext->networkBuffer.size );
assert( pContext->callbacks.getTime != NULL );
+
pIndex = pContext->networkBuffer.pBuffer;
recvFunc = pContext->transportInterface.recv;
getTimeStampMs = pContext->callbacks.getTime;
@@ -423,7 +424,7 @@ static int32_t recvExact( const MQTTContext_t * pContext,
while( ( bytesRemaining > 0U ) && ( receiveError == false ) )
{
- bytesRecvd = recvFunc( pContext->transportInterface.networkContext,
+ bytesRecvd = recvFunc( pContext->transportInterface.pNetworkContext,
pIndex,
bytesRemaining );
@@ -935,7 +936,7 @@ static MQTTStatus_t receiveSingleIteration( MQTTContext_t * pContext,
assert( pContext != NULL );
status = MQTT_GetIncomingPacketTypeAndLength( pContext->transportInterface.recv,
- pContext->transportInterface.networkContext,
+ pContext->transportInterface.pNetworkContext,
&incomingPacket );
if( status == MQTTNoDataAvailable )
@@ -1107,7 +1108,7 @@ static MQTTStatus_t receiveConnack( const MQTTContext_t * pContext,
* returned after a transport receive timeout, an error, or a successful
* receive of packet type and length. */
status = MQTT_GetIncomingPacketTypeAndLength( pContext->transportInterface.recv,
- pContext->transportInterface.networkContext,
+ pContext->transportInterface.pNetworkContext,
pIncomingPacket );
/* The loop times out based on 2 conditions.
@@ -1297,7 +1298,7 @@ static MQTTStatus_t validatePublishParams( const MQTTContext_t * pContext,
/*-----------------------------------------------------------*/
MQTTStatus_t MQTT_Init( MQTTContext_t * pContext,
- const MQTTTransportInterface_t * pTransportInterface,
+ const TransportInterface_t * pTransportInterface,
const MQTTApplicationCallbacks_t * pCallbacks,
const MQTTFixedBuffer_t * pNetworkBuffer )
{
diff --git a/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta2/c_sdk/standard/mqtt/src/mqtt_lightweight.c b/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta2/c_sdk/standard/mqtt/src/mqtt_lightweight.c
index cc285aa65..fae42e79c 100644
--- a/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta2/c_sdk/standard/mqtt/src/mqtt_lightweight.c
+++ b/FreeRTOS-Plus/Source/FreeRTOS-IoT-Libraries-LTS-Beta2/c_sdk/standard/mqtt/src/mqtt_lightweight.c
@@ -559,8 +559,8 @@ static void serializePublishCommon( const MQTTPublishInfo_t * pPublishInfo,
assert( ( ( size_t ) ( pIndex - pFixedBuffer->pBuffer ) ) <= pFixedBuffer->size );
}
-static size_t getRemainingLength( MQTTTransportRecvFunc_t recvFunc,
- NetworkContext_t networkContext )
+static size_t getRemainingLength( TransportRecv_t recvFunc,
+ NetworkContext_t * pNetworkContext )
{
size_t remainingLength = 0, multiplier = 1, bytesDecoded = 0, expectedSize = 0;
uint8_t encodedByte = 0;
@@ -575,7 +575,7 @@ static size_t getRemainingLength( MQTTTransportRecvFunc_t recvFunc,
}
else
{
- bytesReceived = recvFunc( networkContext, &encodedByte, 1U );
+ bytesReceived = recvFunc( pNetworkContext, &encodedByte, 1U );
if( bytesReceived == 1 )
{
@@ -2119,8 +2119,8 @@ MQTTStatus_t MQTT_DeserializeAck( const MQTTPacketInfo_t * pIncomingPacket,
/*-----------------------------------------------------------*/
-MQTTStatus_t MQTT_GetIncomingPacketTypeAndLength( MQTTTransportRecvFunc_t readFunc,
- NetworkContext_t networkContext,
+MQTTStatus_t MQTT_GetIncomingPacketTypeAndLength( TransportRecv_t readFunc,
+ NetworkContext_t * pNetworkContext,
MQTTPacketInfo_t * pIncomingPacket )
{
MQTTStatus_t status = MQTTSuccess;
@@ -2134,7 +2134,7 @@ MQTTStatus_t MQTT_GetIncomingPacketTypeAndLength( MQTTTransportRecvFunc_t readFu
else
{
/* Read a single byte. */
- bytesReceived = readFunc( networkContext,
+ bytesReceived = readFunc( pNetworkContext,
&( pIncomingPacket->type ),
1U );
}
@@ -2145,7 +2145,7 @@ MQTTStatus_t MQTT_GetIncomingPacketTypeAndLength( MQTTTransportRecvFunc_t readFu
if( incomingPacketValid( pIncomingPacket->type ) == true )
{
pIncomingPacket->remainingLength = getRemainingLength( readFunc,
- networkContext );
+ pNetworkContext );
if( pIncomingPacket->remainingLength == MQTT_REMAINING_LENGTH_INVALID )
{