mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-10-18 10:47:47 -04:00
Create mqtt_pkcs11_demo_helpers for AWS demos (#769)
* Create mqtt_pkcs11_demo_helpers by modifying mqtt_demo_helpers * Update formatting and variable naming * Fix multi-line parameter formatting * Update file headers to match latest release version
This commit is contained in:
parent
9b27a5de4e
commit
348ebbcbf1
8 changed files with 1304 additions and 1312 deletions
|
@ -78,7 +78,7 @@
|
||||||
#include "fleet_provisioning.h"
|
#include "fleet_provisioning.h"
|
||||||
|
|
||||||
/* Demo includes. */
|
/* Demo includes. */
|
||||||
#include "mqtt_operations.h"
|
#include "mqtt_pkcs11_demo_helpers.h"
|
||||||
#include "pkcs11_operations.h"
|
#include "pkcs11_operations.h"
|
||||||
#include "tinycbor_serializer.h"
|
#include "tinycbor_serializer.h"
|
||||||
#include "using_mbedtls_pkcs11.h"
|
#include "using_mbedtls_pkcs11.h"
|
||||||
|
@ -169,6 +169,19 @@ typedef enum
|
||||||
ResponseRejected
|
ResponseRejected
|
||||||
} ResponseStatus_t;
|
} ResponseStatus_t;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Each compilation unit that consumes the NetworkContext must define it.
|
||||||
|
* It should contain a single pointer to the type of your desired transport.
|
||||||
|
* When using multiple transports in the same compilation unit, define this pointer as void *.
|
||||||
|
*
|
||||||
|
* @note Transport stacks are defined in FreeRTOS-Plus/Source/Application-Protocols/network_transport.
|
||||||
|
*/
|
||||||
|
struct NetworkContext
|
||||||
|
{
|
||||||
|
TlsTransportParams_t * pxParams;
|
||||||
|
};
|
||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -199,18 +212,33 @@ static uint8_t pucPayloadBuffer[ democonfigNETWORK_BUFFER_SIZE ];
|
||||||
*/
|
*/
|
||||||
static size_t xPayloadLength;
|
static size_t xPayloadLength;
|
||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/**
|
||||||
|
* @brief The MQTT context used for MQTT operation.
|
||||||
|
*/
|
||||||
|
static MQTTContext_t xMqttContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Each compilation unit that consumes the NetworkContext must define it.
|
* @brief The network context used for mbedTLS operation.
|
||||||
* It should contain a single pointer to the type of your desired transport.
|
|
||||||
* When using multiple transports in the same compilation unit, define this pointer as void *.
|
|
||||||
*
|
|
||||||
* @note Transport stacks are defined in FreeRTOS-Plus/Source/Application-Protocols/network_transport.
|
|
||||||
*/
|
*/
|
||||||
struct NetworkContext
|
static NetworkContext_t xNetworkContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The parameters for the network context using mbedTLS operation.
|
||||||
|
*/
|
||||||
|
static TlsTransportParams_t xTlsTransportParams;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Static buffer used to hold MQTT messages being sent and received.
|
||||||
|
*/
|
||||||
|
static uint8_t ucSharedBuffer[ democonfigNETWORK_BUFFER_SIZE ];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Static buffer used to hold MQTT messages being sent and received.
|
||||||
|
*/
|
||||||
|
static MQTTFixedBuffer_t xBuffer =
|
||||||
{
|
{
|
||||||
TlsTransportParams_t * pxParams;
|
ucSharedBuffer,
|
||||||
|
democonfigNETWORK_BUFFER_SIZE
|
||||||
};
|
};
|
||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
@ -224,13 +252,9 @@ struct NetworkContext
|
||||||
* @param[in] pPublishInfo Pointer to publish info of the incoming publish.
|
* @param[in] pPublishInfo Pointer to publish info of the incoming publish.
|
||||||
* @param[in] usPacketIdentifier Packet identifier of the incoming publish.
|
* @param[in] usPacketIdentifier Packet identifier of the incoming publish.
|
||||||
*/
|
*/
|
||||||
static void prvProvisioningPublishCallback( MQTTPublishInfo_t * pPublishInfo,
|
static void prvProvisioningPublishCallback( MQTTContext_t * pxMqttContext,
|
||||||
uint16_t usPacketIdentifier );
|
MQTTPacketInfo_t * pxPacketInfo,
|
||||||
|
MQTTDeserializedInfo_t * pxDeserializedInfo );
|
||||||
/**
|
|
||||||
* @brief Run the MQTT process loop to get a response.
|
|
||||||
*/
|
|
||||||
static bool prvWaitForResponse( void );
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Subscribe to the CreateCertificateFromCsr accepted and rejected topics.
|
* @brief Subscribe to the CreateCertificateFromCsr accepted and rejected topics.
|
||||||
|
@ -269,27 +293,43 @@ static int prvFleetProvisioningTask( void * pvParameters );
|
||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
static void prvProvisioningPublishCallback( MQTTPublishInfo_t * pPublishInfo,
|
static void prvProvisioningPublishCallback( MQTTContext_t * pxMqttContext,
|
||||||
uint16_t usPacketIdentifier )
|
MQTTPacketInfo_t * pxPacketInfo,
|
||||||
|
MQTTDeserializedInfo_t * pxDeserializedInfo )
|
||||||
{
|
{
|
||||||
FleetProvisioningStatus_t status;
|
FleetProvisioningStatus_t xStatus;
|
||||||
FleetProvisioningTopic_t api;
|
FleetProvisioningTopic_t xApi;
|
||||||
|
MQTTPublishInfo_t * pxPublishInfo;
|
||||||
|
|
||||||
/* Silence compiler warnings about unused variables. */
|
configASSERT( pxMqttContext != NULL );
|
||||||
( void ) usPacketIdentifier;
|
configASSERT( pxPacketInfo != NULL );
|
||||||
|
configASSERT( pxDeserializedInfo != NULL );
|
||||||
|
|
||||||
status = FleetProvisioning_MatchTopic( pPublishInfo->pTopicName,
|
/* Suppress the unused parameter warning when asserts are disabled in
|
||||||
pPublishInfo->topicNameLength, &api );
|
* build. */
|
||||||
|
( void ) pxMqttContext;
|
||||||
|
|
||||||
if( status != FleetProvisioningSuccess )
|
/* Handle an incoming publish. The lower 4 bits of the publish packet
|
||||||
|
* type is used for the dup, QoS, and retain flags. Hence masking
|
||||||
|
* out the lower bits to check if the packet is publish. */
|
||||||
|
if( ( pxPacketInfo->type & 0xF0U ) == MQTT_PACKET_TYPE_PUBLISH )
|
||||||
|
{
|
||||||
|
configASSERT( pxDeserializedInfo->pPublishInfo != NULL );
|
||||||
|
pxPublishInfo = pxDeserializedInfo->pPublishInfo;
|
||||||
|
|
||||||
|
xStatus = FleetProvisioning_MatchTopic(pxPublishInfo->pTopicName,
|
||||||
|
pxPublishInfo->topicNameLength,
|
||||||
|
&xApi);
|
||||||
|
|
||||||
|
if (xStatus != FleetProvisioningSuccess)
|
||||||
{
|
{
|
||||||
LogWarn( ( "Unexpected publish message received. Topic: %.*s.",
|
LogWarn( ( "Unexpected publish message received. Topic: %.*s.",
|
||||||
( int ) pPublishInfo->topicNameLength,
|
( int ) pxPublishInfo->topicNameLength,
|
||||||
( const char * ) pPublishInfo->pTopicName ) );
|
( const char * ) pxPublishInfo->pTopicName ) );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if( api == FleetProvCborCreateCertFromCsrAccepted )
|
if (xApi == FleetProvCborCreateCertFromCsrAccepted)
|
||||||
{
|
{
|
||||||
LogInfo( ( "Received accepted response from Fleet Provisioning CreateCertificateFromCsr API." ) );
|
LogInfo( ( "Received accepted response from Fleet Provisioning CreateCertificateFromCsr API." ) );
|
||||||
|
|
||||||
|
@ -297,18 +337,18 @@ static void prvProvisioningPublishCallback( MQTTPublishInfo_t * pPublishInfo,
|
||||||
|
|
||||||
/* Copy the payload from the MQTT library's buffer to #pucPayloadBuffer. */
|
/* Copy the payload from the MQTT library's buffer to #pucPayloadBuffer. */
|
||||||
( void ) memcpy( ( void * ) pucPayloadBuffer,
|
( void ) memcpy( ( void * ) pucPayloadBuffer,
|
||||||
( const void * ) pPublishInfo->pPayload,
|
( const void * ) pxPublishInfo->pPayload,
|
||||||
( size_t ) pPublishInfo->payloadLength );
|
( size_t ) pxPublishInfo->payloadLength );
|
||||||
|
|
||||||
xPayloadLength = pPublishInfo->payloadLength;
|
xPayloadLength = pxPublishInfo->payloadLength;
|
||||||
}
|
}
|
||||||
else if( api == FleetProvCborCreateCertFromCsrRejected )
|
else if (xApi == FleetProvCborCreateCertFromCsrRejected)
|
||||||
{
|
{
|
||||||
LogError( ( "Received rejected response from Fleet Provisioning CreateCertificateFromCsr API." ) );
|
LogError( ( "Received rejected response from Fleet Provisioning CreateCertificateFromCsr API." ) );
|
||||||
|
|
||||||
xResponseStatus = ResponseRejected;
|
xResponseStatus = ResponseRejected;
|
||||||
}
|
}
|
||||||
else if( api == FleetProvCborRegisterThingAccepted )
|
else if (xApi == FleetProvCborRegisterThingAccepted)
|
||||||
{
|
{
|
||||||
LogInfo( ( "Received accepted response from Fleet Provisioning RegisterThing API." ) );
|
LogInfo( ( "Received accepted response from Fleet Provisioning RegisterThing API." ) );
|
||||||
|
|
||||||
|
@ -316,12 +356,12 @@ static void prvProvisioningPublishCallback( MQTTPublishInfo_t * pPublishInfo,
|
||||||
|
|
||||||
/* Copy the payload from the MQTT library's buffer to #pucPayloadBuffer. */
|
/* Copy the payload from the MQTT library's buffer to #pucPayloadBuffer. */
|
||||||
( void ) memcpy( ( void * ) pucPayloadBuffer,
|
( void ) memcpy( ( void * ) pucPayloadBuffer,
|
||||||
( const void * ) pPublishInfo->pPayload,
|
( const void * ) pxPublishInfo->pPayload,
|
||||||
( size_t ) pPublishInfo->payloadLength );
|
( size_t ) pxPublishInfo->payloadLength );
|
||||||
|
|
||||||
xPayloadLength = pPublishInfo->payloadLength;
|
xPayloadLength = pxPublishInfo->payloadLength;
|
||||||
}
|
}
|
||||||
else if( api == FleetProvCborRegisterThingRejected )
|
else if (xApi == FleetProvCborRegisterThingRejected)
|
||||||
{
|
{
|
||||||
LogError( ( "Received rejected response from Fleet Provisioning RegisterThing API." ) );
|
LogError( ( "Received rejected response from Fleet Provisioning RegisterThing API." ) );
|
||||||
|
|
||||||
|
@ -330,33 +370,16 @@ static void prvProvisioningPublishCallback( MQTTPublishInfo_t * pPublishInfo,
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LogError( ( "Received message on unexpected Fleet Provisioning topic. Topic: %.*s.",
|
LogError( ( "Received message on unexpected Fleet Provisioning topic. Topic: %.*s.",
|
||||||
( int ) pPublishInfo->topicNameLength,
|
( int ) pxPublishInfo->topicNameLength,
|
||||||
( const char * ) pPublishInfo->pTopicName ) );
|
( const char * ) pxPublishInfo->pTopicName ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
else
|
||||||
|
|
||||||
static bool prvWaitForResponse( void )
|
|
||||||
{
|
{
|
||||||
bool xStatus = false;
|
vHandleOtherIncomingPacket( pxPacketInfo, pxDeserializedInfo->packetIdentifier );
|
||||||
|
xResponseStatus = ResponseAccepted;
|
||||||
xResponseStatus = ResponseNotReceived;
|
|
||||||
|
|
||||||
/* xResponseStatus is updated from the MQTT publish callback. */
|
|
||||||
( void ) xProcessLoop();
|
|
||||||
|
|
||||||
if( xResponseStatus == ResponseNotReceived )
|
|
||||||
{
|
|
||||||
LogError( ( "Timed out waiting for response." ) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( xResponseStatus == ResponseAccepted )
|
|
||||||
{
|
|
||||||
xStatus = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return xStatus;
|
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
@ -364,7 +387,8 @@ static bool prvSubscribeToCsrResponseTopics( void )
|
||||||
{
|
{
|
||||||
bool xStatus;
|
bool xStatus;
|
||||||
|
|
||||||
xStatus = xSubscribeToTopic( FP_CBOR_CREATE_CERT_ACCEPTED_TOPIC,
|
xStatus = xSubscribeToTopic( &xMqttContext,
|
||||||
|
FP_CBOR_CREATE_CERT_ACCEPTED_TOPIC,
|
||||||
FP_CBOR_CREATE_CERT_ACCEPTED_LENGTH );
|
FP_CBOR_CREATE_CERT_ACCEPTED_LENGTH );
|
||||||
|
|
||||||
if( xStatus == false )
|
if( xStatus == false )
|
||||||
|
@ -376,7 +400,8 @@ static bool prvSubscribeToCsrResponseTopics( void )
|
||||||
|
|
||||||
if( xStatus == true )
|
if( xStatus == true )
|
||||||
{
|
{
|
||||||
xStatus = xSubscribeToTopic( FP_CBOR_CREATE_CERT_REJECTED_TOPIC,
|
xStatus = xSubscribeToTopic( &xMqttContext,
|
||||||
|
FP_CBOR_CREATE_CERT_REJECTED_TOPIC,
|
||||||
FP_CBOR_CREATE_CERT_REJECTED_LENGTH );
|
FP_CBOR_CREATE_CERT_REJECTED_LENGTH );
|
||||||
|
|
||||||
if( xStatus == false )
|
if( xStatus == false )
|
||||||
|
@ -395,7 +420,8 @@ static bool prvUnsubscribeFromCsrResponseTopics( void )
|
||||||
{
|
{
|
||||||
bool xStatus;
|
bool xStatus;
|
||||||
|
|
||||||
xStatus = xUnsubscribeFromTopic( FP_CBOR_CREATE_CERT_ACCEPTED_TOPIC,
|
xStatus = xUnsubscribeFromTopic( &xMqttContext,
|
||||||
|
FP_CBOR_CREATE_CERT_ACCEPTED_TOPIC,
|
||||||
FP_CBOR_CREATE_CERT_ACCEPTED_LENGTH );
|
FP_CBOR_CREATE_CERT_ACCEPTED_LENGTH );
|
||||||
|
|
||||||
if( xStatus == false )
|
if( xStatus == false )
|
||||||
|
@ -407,7 +433,8 @@ static bool prvUnsubscribeFromCsrResponseTopics( void )
|
||||||
|
|
||||||
if( xStatus == true )
|
if( xStatus == true )
|
||||||
{
|
{
|
||||||
xStatus = xUnsubscribeFromTopic( FP_CBOR_CREATE_CERT_REJECTED_TOPIC,
|
xStatus = xUnsubscribeFromTopic( &xMqttContext,
|
||||||
|
FP_CBOR_CREATE_CERT_REJECTED_TOPIC,
|
||||||
FP_CBOR_CREATE_CERT_REJECTED_LENGTH );
|
FP_CBOR_CREATE_CERT_REJECTED_LENGTH );
|
||||||
|
|
||||||
if( xStatus == false )
|
if( xStatus == false )
|
||||||
|
@ -426,7 +453,8 @@ static bool prvSubscribeToRegisterThingResponseTopics( void )
|
||||||
{
|
{
|
||||||
bool xStatus;
|
bool xStatus;
|
||||||
|
|
||||||
xStatus = xSubscribeToTopic( FP_CBOR_REGISTER_ACCEPTED_TOPIC( democonfigPROVISIONING_TEMPLATE_NAME ),
|
xStatus = xSubscribeToTopic( &xMqttContext,
|
||||||
|
FP_CBOR_REGISTER_ACCEPTED_TOPIC( democonfigPROVISIONING_TEMPLATE_NAME ),
|
||||||
FP_CBOR_REGISTER_ACCEPTED_LENGTH( fpdemoPROVISIONING_TEMPLATE_NAME_LENGTH ) );
|
FP_CBOR_REGISTER_ACCEPTED_LENGTH( fpdemoPROVISIONING_TEMPLATE_NAME_LENGTH ) );
|
||||||
|
|
||||||
if( xStatus == false )
|
if( xStatus == false )
|
||||||
|
@ -438,7 +466,8 @@ static bool prvSubscribeToRegisterThingResponseTopics( void )
|
||||||
|
|
||||||
if( xStatus == true )
|
if( xStatus == true )
|
||||||
{
|
{
|
||||||
xStatus = xSubscribeToTopic( FP_CBOR_REGISTER_REJECTED_TOPIC( democonfigPROVISIONING_TEMPLATE_NAME ),
|
xStatus = xSubscribeToTopic( &xMqttContext,
|
||||||
|
FP_CBOR_REGISTER_REJECTED_TOPIC( democonfigPROVISIONING_TEMPLATE_NAME ),
|
||||||
FP_CBOR_REGISTER_REJECTED_LENGTH( fpdemoPROVISIONING_TEMPLATE_NAME_LENGTH ) );
|
FP_CBOR_REGISTER_REJECTED_LENGTH( fpdemoPROVISIONING_TEMPLATE_NAME_LENGTH ) );
|
||||||
|
|
||||||
if( xStatus == false )
|
if( xStatus == false )
|
||||||
|
@ -457,7 +486,8 @@ static bool prvUnsubscribeFromRegisterThingResponseTopics( void )
|
||||||
{
|
{
|
||||||
bool xStatus;
|
bool xStatus;
|
||||||
|
|
||||||
xStatus = xUnsubscribeFromTopic( FP_CBOR_REGISTER_ACCEPTED_TOPIC( democonfigPROVISIONING_TEMPLATE_NAME ),
|
xStatus = xUnsubscribeFromTopic( &xMqttContext,
|
||||||
|
FP_CBOR_REGISTER_ACCEPTED_TOPIC( democonfigPROVISIONING_TEMPLATE_NAME ),
|
||||||
FP_CBOR_REGISTER_ACCEPTED_LENGTH( fpdemoPROVISIONING_TEMPLATE_NAME_LENGTH ) );
|
FP_CBOR_REGISTER_ACCEPTED_LENGTH( fpdemoPROVISIONING_TEMPLATE_NAME_LENGTH ) );
|
||||||
|
|
||||||
if( xStatus == false )
|
if( xStatus == false )
|
||||||
|
@ -469,7 +499,8 @@ static bool prvUnsubscribeFromRegisterThingResponseTopics( void )
|
||||||
|
|
||||||
if( xStatus == true )
|
if( xStatus == true )
|
||||||
{
|
{
|
||||||
xStatus = xUnsubscribeFromTopic( FP_CBOR_REGISTER_REJECTED_TOPIC( democonfigPROVISIONING_TEMPLATE_NAME ),
|
xStatus = xUnsubscribeFromTopic( &xMqttContext,
|
||||||
|
FP_CBOR_REGISTER_REJECTED_TOPIC( democonfigPROVISIONING_TEMPLATE_NAME ),
|
||||||
FP_CBOR_REGISTER_REJECTED_LENGTH( fpdemoPROVISIONING_TEMPLATE_NAME_LENGTH ) );
|
FP_CBOR_REGISTER_REJECTED_LENGTH( fpdemoPROVISIONING_TEMPLATE_NAME_LENGTH ) );
|
||||||
|
|
||||||
if( xStatus == false )
|
if( xStatus == false )
|
||||||
|
@ -530,10 +561,6 @@ int prvFleetProvisioningTask( void * pvParameters )
|
||||||
uint32_t ulDemoRunCount = 0U;
|
uint32_t ulDemoRunCount = 0U;
|
||||||
CK_RV xPkcs11Ret = CKR_OK;
|
CK_RV xPkcs11Ret = CKR_OK;
|
||||||
|
|
||||||
|
|
||||||
NetworkContext_t xNetworkContext = { 0 };
|
|
||||||
TlsTransportParams_t xTlsTransportParams = { 0 };
|
|
||||||
|
|
||||||
/* Silence compiler warnings about unused variables. */
|
/* Silence compiler warnings about unused variables. */
|
||||||
( void ) pvParameters;
|
( void ) pvParameters;
|
||||||
|
|
||||||
|
@ -584,7 +611,10 @@ int prvFleetProvisioningTask( void * pvParameters )
|
||||||
* connection fails, retries after a timeout. Timeout value will
|
* connection fails, retries after a timeout. Timeout value will
|
||||||
* exponentially increase until maximum attempts are reached. */
|
* exponentially increase until maximum attempts are reached. */
|
||||||
LogInfo( ( "Establishing MQTT session with claim certificate..." ) );
|
LogInfo( ( "Establishing MQTT session with claim certificate..." ) );
|
||||||
xStatus = xEstablishMqttSession( prvProvisioningPublishCallback,
|
xStatus = xEstablishMqttSession( &xMqttContext,
|
||||||
|
&xNetworkContext,
|
||||||
|
&xBuffer,
|
||||||
|
prvProvisioningPublishCallback,
|
||||||
pkcs11configLABEL_CLAIM_CERTIFICATE,
|
pkcs11configLABEL_CLAIM_CERTIFICATE,
|
||||||
pkcs11configLABEL_CLAIM_PRIVATE_KEY );
|
pkcs11configLABEL_CLAIM_PRIVATE_KEY );
|
||||||
|
|
||||||
|
@ -626,7 +656,8 @@ int prvFleetProvisioningTask( void * pvParameters )
|
||||||
if( xStatus == true )
|
if( xStatus == true )
|
||||||
{
|
{
|
||||||
/* Publish the CSR to the CreateCertificatefromCsr API. */
|
/* Publish the CSR to the CreateCertificatefromCsr API. */
|
||||||
xPublishToTopic( FP_CBOR_CREATE_CERT_PUBLISH_TOPIC,
|
xPublishToTopic( &xMqttContext,
|
||||||
|
FP_CBOR_CREATE_CERT_PUBLISH_TOPIC,
|
||||||
FP_CBOR_CREATE_CERT_PUBLISH_LENGTH,
|
FP_CBOR_CREATE_CERT_PUBLISH_LENGTH,
|
||||||
( char * ) pucPayloadBuffer,
|
( char * ) pucPayloadBuffer,
|
||||||
xPayloadLength );
|
xPayloadLength );
|
||||||
|
@ -639,12 +670,6 @@ int prvFleetProvisioningTask( void * pvParameters )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( xStatus == true )
|
|
||||||
{
|
|
||||||
/* Get the response to the CreateCertificatefromCsr request. */
|
|
||||||
xStatus = prvWaitForResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
if( xStatus == true )
|
if( xStatus == true )
|
||||||
{
|
{
|
||||||
/* From the response, extract the certificate, certificate ID, and
|
/* From the response, extract the certificate, certificate ID, and
|
||||||
|
@ -705,7 +730,8 @@ int prvFleetProvisioningTask( void * pvParameters )
|
||||||
if( xStatus == true )
|
if( xStatus == true )
|
||||||
{
|
{
|
||||||
/* Publish the RegisterThing request. */
|
/* Publish the RegisterThing request. */
|
||||||
xPublishToTopic( FP_CBOR_REGISTER_PUBLISH_TOPIC( democonfigPROVISIONING_TEMPLATE_NAME ),
|
xPublishToTopic( &xMqttContext,
|
||||||
|
FP_CBOR_REGISTER_PUBLISH_TOPIC( democonfigPROVISIONING_TEMPLATE_NAME ),
|
||||||
FP_CBOR_REGISTER_PUBLISH_LENGTH( fpdemoPROVISIONING_TEMPLATE_NAME_LENGTH ),
|
FP_CBOR_REGISTER_PUBLISH_LENGTH( fpdemoPROVISIONING_TEMPLATE_NAME_LENGTH ),
|
||||||
( char * ) pucPayloadBuffer,
|
( char * ) pucPayloadBuffer,
|
||||||
xPayloadLength );
|
xPayloadLength );
|
||||||
|
@ -718,12 +744,6 @@ int prvFleetProvisioningTask( void * pvParameters )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( xStatus == true )
|
|
||||||
{
|
|
||||||
/* Get the response to the RegisterThing request. */
|
|
||||||
xStatus = prvWaitForResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
if( xStatus == true )
|
if( xStatus == true )
|
||||||
{
|
{
|
||||||
/* Extract the Thing name from the response. */
|
/* Extract the Thing name from the response. */
|
||||||
|
@ -753,7 +773,7 @@ int prvFleetProvisioningTask( void * pvParameters )
|
||||||
* credentials. */
|
* credentials. */
|
||||||
if( xConnectionEstablished == true )
|
if( xConnectionEstablished == true )
|
||||||
{
|
{
|
||||||
xDisconnectMqttSession();
|
xDisconnectMqttSession( &xMqttContext, &xNetworkContext );
|
||||||
xConnectionEstablished = false;
|
xConnectionEstablished = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -762,7 +782,10 @@ int prvFleetProvisioningTask( void * pvParameters )
|
||||||
if( xStatus == true )
|
if( xStatus == true )
|
||||||
{
|
{
|
||||||
LogInfo( ( "Establishing MQTT session with provisioned certificate..." ) );
|
LogInfo( ( "Establishing MQTT session with provisioned certificate..." ) );
|
||||||
xStatus = xEstablishMqttSession( prvProvisioningPublishCallback,
|
xStatus = xEstablishMqttSession( &xMqttContext,
|
||||||
|
&xNetworkContext,
|
||||||
|
&xBuffer,
|
||||||
|
prvProvisioningPublishCallback,
|
||||||
pkcs11configLABEL_DEVICE_CERTIFICATE_FOR_TLS,
|
pkcs11configLABEL_DEVICE_CERTIFICATE_FOR_TLS,
|
||||||
pkcs11configLABEL_DEVICE_PRIVATE_KEY_FOR_TLS );
|
pkcs11configLABEL_DEVICE_PRIVATE_KEY_FOR_TLS );
|
||||||
|
|
||||||
|
@ -785,7 +808,7 @@ int prvFleetProvisioningTask( void * pvParameters )
|
||||||
if( xConnectionEstablished == true )
|
if( xConnectionEstablished == true )
|
||||||
{
|
{
|
||||||
/* Close the connection. */
|
/* Close the connection. */
|
||||||
xDisconnectMqttSession();
|
xDisconnectMqttSession( &xMqttContext, &xNetworkContext );
|
||||||
xConnectionEstablished = false;
|
xConnectionEstablished = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -560,10 +560,10 @@
|
||||||
<ClCompile Include="..\..\..\..\ThirdParty\tinycbor\src\cborpretty.c" />
|
<ClCompile Include="..\..\..\..\ThirdParty\tinycbor\src\cborpretty.c" />
|
||||||
<ClCompile Include="..\..\..\..\ThirdParty\tinycbor\src\cborpretty_stdio.c" />
|
<ClCompile Include="..\..\..\..\ThirdParty\tinycbor\src\cborpretty_stdio.c" />
|
||||||
<ClCompile Include="..\..\..\..\ThirdParty\tinycbor\src\cborvalidation.c" />
|
<ClCompile Include="..\..\..\..\ThirdParty\tinycbor\src\cborvalidation.c" />
|
||||||
|
<ClCompile Include="..\..\Mqtt_Demo_Helpers\mqtt_pkcs11_demo_helpers.c" />
|
||||||
<ClCompile Include="DemoTasks\FleetProvisioningDemoExample.c" />
|
<ClCompile Include="DemoTasks\FleetProvisioningDemoExample.c" />
|
||||||
<ClCompile Include="tinycbor_serializer.c" />
|
<ClCompile Include="tinycbor_serializer.c" />
|
||||||
<ClCompile Include="main.c" />
|
<ClCompile Include="main.c" />
|
||||||
<ClCompile Include="mqtt_operations.c" />
|
|
||||||
<ClCompile Include="pkcs11_operations.c" />
|
<ClCompile Include="pkcs11_operations.c" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -695,6 +695,7 @@
|
||||||
<ClInclude Include="..\..\..\..\ThirdParty\tinycbor\src\compilersupport_p.h" />
|
<ClInclude Include="..\..\..\..\ThirdParty\tinycbor\src\compilersupport_p.h" />
|
||||||
<ClInclude Include="..\..\..\..\ThirdParty\tinycbor\src\tinycbor-version.h" />
|
<ClInclude Include="..\..\..\..\ThirdParty\tinycbor\src\tinycbor-version.h" />
|
||||||
<ClInclude Include="..\..\..\..\ThirdParty\tinycbor\src\utf8_p.h" />
|
<ClInclude Include="..\..\..\..\ThirdParty\tinycbor\src\utf8_p.h" />
|
||||||
|
<ClInclude Include="..\..\Mqtt_Demo_Helpers\mqtt_pkcs11_demo_helpers.h" />
|
||||||
<ClInclude Include="core_pkcs11_config.h" />
|
<ClInclude Include="core_pkcs11_config.h" />
|
||||||
<ClInclude Include="fleet_provisioning_config.h" />
|
<ClInclude Include="fleet_provisioning_config.h" />
|
||||||
<ClInclude Include="tinycbor_serializer.h" />
|
<ClInclude Include="tinycbor_serializer.h" />
|
||||||
|
@ -703,7 +704,6 @@
|
||||||
<ClInclude Include="FreeRTOSConfig.h" />
|
<ClInclude Include="FreeRTOSConfig.h" />
|
||||||
<ClInclude Include="FreeRTOSIPConfig.h" />
|
<ClInclude Include="FreeRTOSIPConfig.h" />
|
||||||
<ClInclude Include="core_mqtt_config.h" />
|
<ClInclude Include="core_mqtt_config.h" />
|
||||||
<ClInclude Include="mqtt_operations.h" />
|
|
||||||
<ClInclude Include="pkcs11_operations.h" />
|
<ClInclude Include="pkcs11_operations.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
|
@ -470,7 +470,6 @@
|
||||||
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\x509write_csr.c">
|
<ClCompile Include="..\..\..\..\ThirdParty\mbedtls\library\x509write_csr.c">
|
||||||
<Filter>FreeRTOS+\mbedtls\library</Filter>
|
<Filter>FreeRTOS+\mbedtls\library</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="mqtt_operations.c" />
|
|
||||||
<ClCompile Include="..\..\..\..\ThirdParty\tinycbor\src\cborencoder.c">
|
<ClCompile Include="..\..\..\..\ThirdParty\tinycbor\src\cborencoder.c">
|
||||||
<Filter>FreeRTOS+\tinycbor</Filter>
|
<Filter>FreeRTOS+\tinycbor</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
@ -537,6 +536,7 @@
|
||||||
<ClCompile Include="..\..\..\..\Source\Utilities\mbedtls_freertos\mbedtls_bio_freertos_plus_tcp.c">
|
<ClCompile Include="..\..\..\..\Source\Utilities\mbedtls_freertos\mbedtls_bio_freertos_plus_tcp.c">
|
||||||
<Filter>FreeRTOS+\FreeRTOS IoT Libraries\platform\mbedtls</Filter>
|
<Filter>FreeRTOS+\FreeRTOS IoT Libraries\platform\mbedtls</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="..\..\Mqtt_Demo_Helpers\mqtt_pkcs11_demo_helpers.c" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\include\NetworkInterface.h">
|
<ClInclude Include="..\..\..\..\..\FreeRTOS-Plus\Source\FreeRTOS-Plus-TCP\include\NetworkInterface.h">
|
||||||
|
@ -904,7 +904,6 @@
|
||||||
<ClInclude Include="fleet_provisioning_config.h">
|
<ClInclude Include="fleet_provisioning_config.h">
|
||||||
<Filter>Config</Filter>
|
<Filter>Config</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="mqtt_operations.h" />
|
|
||||||
<ClInclude Include="..\..\..\..\ThirdParty\tinycbor\src\cborinternal_p.h">
|
<ClInclude Include="..\..\..\..\ThirdParty\tinycbor\src\cborinternal_p.h">
|
||||||
<Filter>FreeRTOS+\tinycbor</Filter>
|
<Filter>FreeRTOS+\tinycbor</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
@ -950,6 +949,7 @@
|
||||||
<ClInclude Include="..\..\..\..\Source\Application-Protocols\network_transport\using_mbedtls_pkcs11\using_mbedtls_pkcs11.h">
|
<ClInclude Include="..\..\..\..\Source\Application-Protocols\network_transport\using_mbedtls_pkcs11\using_mbedtls_pkcs11.h">
|
||||||
<Filter>FreeRTOS+\FreeRTOS IoT Libraries\platform\transport\include</Filter>
|
<Filter>FreeRTOS+\FreeRTOS IoT Libraries\platform\transport\include</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="..\..\Mqtt_Demo_Helpers\mqtt_pkcs11_demo_helpers.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Text Include="..\..\..\..\ThirdParty\mbedtls\CMakeLists.txt">
|
<Text Include="..\..\..\..\ThirdParty\mbedtls\CMakeLists.txt">
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,116 +0,0 @@
|
||||||
/*
|
|
||||||
* FreeRTOS V202112.00
|
|
||||||
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
||||||
* this software and associated documentation files (the "Software"), to deal in
|
|
||||||
* the Software without restriction, including without limitation the rights to
|
|
||||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
||||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
|
||||||
* subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
||||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
||||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*
|
|
||||||
* https://www.FreeRTOS.org
|
|
||||||
* https://github.com/FreeRTOS
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef MQTT_OPERATIONS_H_
|
|
||||||
#define MQTT_OPERATIONS_H_
|
|
||||||
|
|
||||||
/* MQTT API header. */
|
|
||||||
#include "core_mqtt.h"
|
|
||||||
|
|
||||||
/* corePKCS11 include. */
|
|
||||||
#include "core_pkcs11.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Application callback type to handle the incoming publishes.
|
|
||||||
*
|
|
||||||
* @param[in] pxPublishInfo Pointer to publish info of the incoming publish.
|
|
||||||
* @param[in] usPacketIdentifier Packet identifier of the incoming publish.
|
|
||||||
*/
|
|
||||||
typedef void (* MQTTPublishCallback_t )( MQTTPublishInfo_t * pxPublishInfo,
|
|
||||||
uint16_t usPacketIdentifier );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Establish a MQTT connection.
|
|
||||||
*
|
|
||||||
* @param[in] xPublishCallback The callback function to receive incoming
|
|
||||||
* publishes from the MQTT broker.
|
|
||||||
* @param[in] pcClientCertLabel The client certificate PKCS #11 label to use.
|
|
||||||
* @param[in] pcPrivateKeyLabel The private key PKCS #11 label for the client certificate.
|
|
||||||
*
|
|
||||||
* @return true if an MQTT session is established;
|
|
||||||
* false otherwise.
|
|
||||||
*/
|
|
||||||
bool xEstablishMqttSession( MQTTPublishCallback_t xPublishCallback,
|
|
||||||
char * pcClientCertLabel,
|
|
||||||
char * pcPrivateKeyLabel );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Disconnect the MQTT connection.
|
|
||||||
*
|
|
||||||
* @return true if the MQTT session was successfully disconnected;
|
|
||||||
* false otherwise.
|
|
||||||
*/
|
|
||||||
bool xDisconnectMqttSession( void );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Subscribe to a MQTT topic filter.
|
|
||||||
*
|
|
||||||
* @param[in] pcTopicFilter The topic filter to subscribe to.
|
|
||||||
* @param[in] usTopicFilterLength Length of the topic buffer.
|
|
||||||
*
|
|
||||||
* @return true if subscribe operation was successful;
|
|
||||||
* false otherwise.
|
|
||||||
*/
|
|
||||||
bool xSubscribeToTopic( const char * pcTopicFilter,
|
|
||||||
uint16_t usTopicFilterLength );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Unsubscribe from a MQTT topic filter.
|
|
||||||
*
|
|
||||||
* @param[in] pcTopicFilter The topic filter to unsubscribe from.
|
|
||||||
* @param[in] usTopicFilterLength Length of the topic buffer.
|
|
||||||
*
|
|
||||||
* @return true if unsubscribe operation was successful;
|
|
||||||
* false otherwise.
|
|
||||||
*/
|
|
||||||
bool xUnsubscribeFromTopic( const char * pcTopicFilter,
|
|
||||||
uint16_t usTopicFilterLength );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Publish a message to a MQTT topic.
|
|
||||||
*
|
|
||||||
* @param[in] pcTopic The topic to publish the message on.
|
|
||||||
* @param[in] usTopicLength Length of the topic.
|
|
||||||
* @param[in] pcMessage The message to publish.
|
|
||||||
* @param[in] xMessageLength Length of the message.
|
|
||||||
*
|
|
||||||
* @return true if PUBLISH was successfully sent;
|
|
||||||
* false otherwise.
|
|
||||||
*/
|
|
||||||
bool xPublishToTopic( const char * pcTopic,
|
|
||||||
uint16_t usTopicLength,
|
|
||||||
const char * pcMessage,
|
|
||||||
size_t xMessageLength );
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Invoke the core MQTT library's process loop function.
|
|
||||||
*
|
|
||||||
* @return true if process loop was successful;
|
|
||||||
* false otherwise.
|
|
||||||
*/
|
|
||||||
bool xProcessLoop( void );
|
|
||||||
|
|
||||||
#endif /* ifndef MQTT_OPERATIONS_H_ */
|
|
1013
FreeRTOS-Plus/Demo/AWS/Mqtt_Demo_Helpers/mqtt_pkcs11_demo_helpers.c
Normal file
1013
FreeRTOS-Plus/Demo/AWS/Mqtt_Demo_Helpers/mqtt_pkcs11_demo_helpers.c
Normal file
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,141 @@
|
||||||
|
/*
|
||||||
|
* FreeRTOS V202112.00
|
||||||
|
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to
|
||||||
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
* subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*
|
||||||
|
* https://www.FreeRTOS.org
|
||||||
|
* https://github.com/FreeRTOS
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef MQTT_PKCS11_DEMO_HELPERS_H
|
||||||
|
#define MQTT_PKCS11_DEMO_HELPERS_H
|
||||||
|
|
||||||
|
/* MQTT API header. */
|
||||||
|
#include "core_mqtt.h"
|
||||||
|
|
||||||
|
/* Transport interface implementation include header for TLS. */
|
||||||
|
#include "using_mbedtls_pkcs11.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Establish a MQTT connection.
|
||||||
|
*
|
||||||
|
* @param[in, out] pxMqttContext The memory for the MQTTContext_t that will be used for the
|
||||||
|
* MQTT connection.
|
||||||
|
* @param[out] pxNetworkContext The memory for the NetworkContext_t required for the
|
||||||
|
* MQTT connection.
|
||||||
|
* @param[in] pxNetworkBuffer The buffer space for initializing the @p pxMqttContext MQTT
|
||||||
|
* context used in the MQTT connection.
|
||||||
|
* @param[in] eventCallback The callback function used to receive incoming
|
||||||
|
* publishes and incoming acks from MQTT library.
|
||||||
|
* @param[in] pcClientCertLabel The client certificate PKCS #11 label to use.
|
||||||
|
* @param[in] pcPrivateKeyLabel The private key PKCS #11 label for the client certificate.
|
||||||
|
*
|
||||||
|
* @return The status of the final connection attempt.
|
||||||
|
*/
|
||||||
|
BaseType_t xEstablishMqttSession( MQTTContext_t * pxMqttContext,
|
||||||
|
NetworkContext_t * pxNetworkContext,
|
||||||
|
MQTTFixedBuffer_t * pxNetworkBuffer,
|
||||||
|
MQTTEventCallback_t eventCallback,
|
||||||
|
char * pcClientCertLabel,
|
||||||
|
char * pcPrivateKeyLabel );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Handle the incoming packet if it's not related to the device shadow.
|
||||||
|
*
|
||||||
|
* @param[in] pxPacketInfo Packet Info pointer for the incoming packet.
|
||||||
|
* @param[in] usPacketIdentifier Packet identifier of the incoming packet.
|
||||||
|
*/
|
||||||
|
void vHandleOtherIncomingPacket( MQTTPacketInfo_t * pxPacketInfo,
|
||||||
|
uint16_t usPacketIdentifier );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Close the MQTT connection.
|
||||||
|
*
|
||||||
|
* @param[in, out] pxMqttContext The MQTT context for the MQTT connection to close.
|
||||||
|
* @param[in, out] pxNetworkContext The network context for the TLS session to
|
||||||
|
* terminate.
|
||||||
|
*
|
||||||
|
* @return pdPASS if DISCONNECT was successfully sent;
|
||||||
|
* pdFAIL otherwise.
|
||||||
|
*/
|
||||||
|
BaseType_t xDisconnectMqttSession( MQTTContext_t * pxMqttContext,
|
||||||
|
NetworkContext_t * pxNetworkContext );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Subscribe to a MQTT topic filter.
|
||||||
|
*
|
||||||
|
* @param[in] pxMqttContext The MQTT context for the MQTT connection.
|
||||||
|
* @param[in] pcTopicFilter Pointer to the shadow topic buffer.
|
||||||
|
* @param[in] usTopicFilterLength Indicates the length of the shadow
|
||||||
|
* topic buffer.
|
||||||
|
*
|
||||||
|
* @return pdPASS if SUBSCRIBE was successfully sent;
|
||||||
|
* pdFAIL otherwise.
|
||||||
|
*/
|
||||||
|
BaseType_t xSubscribeToTopic( MQTTContext_t * pxMqttContext,
|
||||||
|
const char * pcTopicFilter,
|
||||||
|
uint16_t usTopicFilterLength );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sends an MQTT UNSUBSCRIBE to unsubscribe from the shadow
|
||||||
|
* topic.
|
||||||
|
*
|
||||||
|
* @param[in] pxMqttContext The MQTT context for the MQTT connection.
|
||||||
|
* @param[in] pcTopicFilter Pointer to the MQTT topic filter.
|
||||||
|
* @param[in] usTopicFilterLength Indicates the length of the topic filter.
|
||||||
|
*
|
||||||
|
* @return pdPASS if UNSUBSCRIBE was successfully sent;
|
||||||
|
* pdFAIL otherwise.
|
||||||
|
*/
|
||||||
|
BaseType_t xUnsubscribeFromTopic( MQTTContext_t * pxMqttContext,
|
||||||
|
const char * pcTopicFilter,
|
||||||
|
uint16_t usTopicFilterLength );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Publish a message to a MQTT topic.
|
||||||
|
*
|
||||||
|
* @param[in] pxMqttContext The MQTT context for the MQTT connection.
|
||||||
|
* @param[in] pcTopicFilter Points to the topic.
|
||||||
|
* @param[in] topicFilterLength The length of the topic.
|
||||||
|
* @param[in] pcPayload Points to the payload.
|
||||||
|
* @param[in] payloadLength The length of the payload.
|
||||||
|
*
|
||||||
|
* @return pdPASS if PUBLISH was successfully sent;
|
||||||
|
* pdFAIL otherwise.
|
||||||
|
*/
|
||||||
|
BaseType_t xPublishToTopic( MQTTContext_t * pxMqttContext,
|
||||||
|
const char * pcTopicFilter,
|
||||||
|
int32_t topicFilterLength,
|
||||||
|
const char * pcPayload,
|
||||||
|
size_t payloadLength );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Invoke the core MQTT library's process loop function.
|
||||||
|
*
|
||||||
|
* @param[in] pxMqttContext The MQTT context for the MQTT connection.
|
||||||
|
* @param[in] ulTimeoutMs Minimum time for the loop to run, if no error occurs.
|
||||||
|
*
|
||||||
|
* @return pdPASS if process loop was successful;
|
||||||
|
* pdFAIL otherwise.
|
||||||
|
*/
|
||||||
|
BaseType_t xProcessLoop( MQTTContext_t * pxMqttContext,
|
||||||
|
uint32_t ulTimeoutMs );
|
||||||
|
|
||||||
|
#endif /* ifndef MQTT_PKCS11_DEMO_HELPERS_H */
|
Loading…
Add table
Add a link
Reference in a new issue