[修改] 增加freeRTOS

1. 版本FreeRTOSv202212.01,命名为kernel;
This commit is contained in:
2023-05-06 16:43:01 +00:00
commit a345df017b
20944 changed files with 11094377 additions and 0 deletions

View File

@ -0,0 +1,766 @@
/*
* AWS IoT Fleet Provisioning v1.1.0
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* 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.
*/
/**
* @file fleet_provisioning.c
* @brief Implementation of the AWS IoT Fleet Provisioning Library.
*/
/* Standard includes. */
#include <assert.h>
#include <stddef.h>
#include <string.h>
/* Fleet Provisioning API include. */
#include "fleet_provisioning.h"
/**
* @brief Identifier for which of the topic suffixes for a given format and
* Fleet Provisioning MQTT API.
*/
typedef enum
{
TopicPublish,
TopicAccepted,
TopicRejected,
TopicInvalidSuffix
} TopicSuffix_t;
/**
* @brief Identifier for which of the topics in each Fleet Provisioning MQTT API.
*/
typedef enum
{
TopicJsonPublish,
TopicJsonAccepted,
TopicJsonRejected,
TopicCborPublish,
TopicCborAccepted,
TopicCborRejected,
TopicInvalidFormatSuffix
} TopicFormatSuffix_t;
/**
* @brief Get the topic length for a given RegisterThing topic.
*
* @param[in] templateNameLength the length of the template name registered with
* AWS IoT.
* @param[in] format The RegisterThing API format to use.
* @param[in] topic The RegisterThing API format to use.
*
* @return the template length for the given RegisterThing topic.
*/
static uint16_t getRegisterThingTopicLength( uint16_t templateNameLength,
FleetProvisioningFormat_t format,
FleetProvisioningApiTopics_t topic );
/**
* @brief Write the given piece of the topic to the remaining buffer and advance
* the remaining buffer pointer.
*
* The caller is responsible for assuring that there is enough space remaining
* in the buffer to write the given string.
*
* @param[in,out] pBufferCursor Pointer to the remaining buffer.
* @param[in] fragment The piece of the topic string to write.
* @param[in] length The length of @p fragment.
*/
static void writeTopicFragmentAndAdvance( char ** pBufferCursor,
const char * fragment,
uint16_t length );
/**
* @brief Check the parameters for FleetProvisioning_GetRegisterThingTopic().
*
* @param[in] pTopicBuffer The buffer to write the topic string into.
* @param[in] format The desired RegisterThing format.
* @param[in] topic The desired RegisterThing topic.
* @param[in] pTemplateName The name of the provisioning template configured
* with AWS IoT.
* @param[in] templateNameLength The length of @p pTemplateName.
* @param[in] pOutLength The length of the topic string written to
* the buffer.
*
* @return FleetProvisioningSuccess if no errors are found with the parameters;
* FleetProvisioningBadParameter otherwise.
*/
static FleetProvisioningStatus_t GetRegisterThingTopicCheckParams( const char * pTopicBuffer,
FleetProvisioningFormat_t format,
FleetProvisioningApiTopics_t topic,
const char * pTemplateName,
uint16_t templateNameLength,
const uint16_t * pOutLength );
/**
* @brief Match the suffix from the remaining topic string and return the
* corresponding suffix.
*
* Suffix: empty, /accepted, or /rejected.
*
* @param[in] pRemainingTopic The remaining portion of the topic.
* @param[in] remainingLength The remaining length of the topic.
*
* @return The matching #TopicSuffix_t.
*/
static TopicSuffix_t parseTopicSuffix( const char * pRemainingTopic,
uint16_t remainingLength );
/**
* @brief Match the format and suffix from the remaining topic string and
* return the corresponding format and suffix.
*
* Format: json or cbor.
* Suffix: empty, /accepted, or /rejected.
*
* @param[in] pRemainingTopic The remaining portion of the topic.
* @param[in] remainingLength The remaining length of the topic.
*
* @return The matching #TopicFormatSuffix_t.
*/
static TopicFormatSuffix_t parseTopicFormatSuffix( const char * pRemainingTopic,
uint16_t remainingLength );
/**
* @brief Match a topic string with the CreateCertificateFromCsr topics.
*
* @param[in] pTopic The topic string to match.
* @param[in] topicLength The length of the topic string.
*
* @return The matching #FleetProvisioningTopic_t if the topic string is a
* Fleet Provisioning CreateCertificateFromCsr topic, else
* FleetProvisioningInvalidTopic.
*/
static FleetProvisioningTopic_t parseCreateCertificateFromCsrTopic( const char * pTopic,
uint16_t topicLength );
/**
* @brief Match a topic string with the CreateKeysAndCertificate topics.
*
* @param[in] pTopic The topic string to match.
* @param[in] topicLength The length of the topic string.
*
* @return The matching FleetProvisioningTopic_t if the topic string is a
* Fleet Provisioning CreateKeysAndCertificate topic, else
* FleetProvisioningInvalidTopic.
*/
static FleetProvisioningTopic_t parseCreateKeysAndCertificateTopic( const char * pTopic,
uint16_t topicLength );
/**
* @brief Match a topic string with the RegisterThing topics.
*
* @param[in] pTopic The topic string to match.
* @param[in] topicLength The length of the topic string.
*
* @return The matching #FleetProvisioningTopic_t if the topic string is a
* Fleet Provisioning RegisterThing topic, else
* FleetProvisioningInvalidTopic.
*/
static FleetProvisioningTopic_t parseRegisterThingTopic( const char * pTopic,
uint16_t topicLength );
/**
* @brief Check if the remaining buffer starts with a specified string. If so,
* moves the remaining buffer pointer past the matched section and updates the
* remaining length.
*
* @param[in,out] pBufferCursor Pointer to the remaining portion of the buffer.
* @param[in,out] pRemainingLength The remaining length of the buffer.
* @param[in] matchString The string to match against.
* @param[in] matchLength The length of @p matchString.
*
* @return FleetProvisioningSuccess if the string matches and is skipped over;
* FleetProvisioningNoMatch otherwise.
*/
static FleetProvisioningStatus_t consumeIfMatch( const char ** pBufferCursor,
uint16_t * pRemainingLength,
const char * matchString,
uint16_t matchLength );
/**
* @brief Move the remaining topic pointer past the template name in the
* unparsed topic so far, and update the remaining topic length.
*
* The end of thing name is marked by a forward slash. A zero length thing name
* is not valid.
*
* This function extracts the same template name from the following topic strings:
* - $aws/provisioning-templates/TEMPLATE_NAME/provision/json/accepted
* - $aws/provisioning-templates/TEMPLATE_NAME
* The second topic is not a valid Fleet Provisioning topic and the matching
* will fail when we try to match the bridge part.
*
* @param[in,out] pTopicCursor Pointer to the remaining topic string.
* @param[in,out] pRemainingLength Pointer to the length of the remaining topic string.
*
* @return FleetProvisioningSuccess if a valid template name is skipped over;
* FleetProvisioningNoMatch otherwise.
*/
static FleetProvisioningStatus_t consumeTemplateName( const char ** pTopicCursor,
uint16_t * pRemainingLength );
/*-----------------------------------------------------------*/
static uint16_t getRegisterThingTopicLength( uint16_t templateNameLength,
FleetProvisioningFormat_t format,
FleetProvisioningApiTopics_t topic )
{
uint16_t topicLength = 0U;
assert( ( templateNameLength != 0U ) &&
( templateNameLength <= FP_TEMPLATENAME_MAX_LENGTH ) );
assert( ( format == FleetProvisioningJson ) || ( format == FleetProvisioningCbor ) );
assert( ( topic >= FleetProvisioningPublish ) && ( topic <= FleetProvisioningRejected ) );
topicLength = FP_REGISTER_API_LENGTH_PREFIX +
templateNameLength +
FP_REGISTER_API_LENGTH_BRIDGE;
if( format == FleetProvisioningJson )
{
topicLength += FP_API_LENGTH_JSON_FORMAT;
}
if( format == FleetProvisioningCbor )
{
topicLength += FP_API_LENGTH_CBOR_FORMAT;
}
if( topic == FleetProvisioningAccepted )
{
topicLength += FP_API_LENGTH_ACCEPTED_SUFFIX;
}
if( topic == FleetProvisioningRejected )
{
topicLength += FP_API_LENGTH_REJECTED_SUFFIX;
}
return topicLength;
}
/*-----------------------------------------------------------*/
static void writeTopicFragmentAndAdvance( char ** pBufferCursor,
const char * fragment,
uint16_t length )
{
assert( pBufferCursor != NULL );
assert( *pBufferCursor != NULL );
assert( fragment != NULL );
( void ) memcpy( ( void * ) *pBufferCursor,
( const void * ) fragment,
( size_t ) length );
*pBufferCursor += length;
}
/*-----------------------------------------------------------*/
static FleetProvisioningStatus_t GetRegisterThingTopicCheckParams( const char * pTopicBuffer,
FleetProvisioningFormat_t format,
FleetProvisioningApiTopics_t topic,
const char * pTemplateName,
uint16_t templateNameLength,
const uint16_t * pOutLength )
{
FleetProvisioningStatus_t ret = FleetProvisioningError;
if( ( pTopicBuffer == NULL ) ||
( format < FleetProvisioningJson ) ||
( format > FleetProvisioningCbor ) ||
( topic < FleetProvisioningPublish ) ||
( topic > FleetProvisioningRejected ) ||
( pTemplateName == NULL ) ||
( templateNameLength == 0U ) ||
( templateNameLength > FP_TEMPLATENAME_MAX_LENGTH ) ||
( pOutLength == NULL ) )
{
ret = FleetProvisioningBadParameter;
LogError( ( "Invalid input parameter. pTopicBuffer: %p, format: %d, topic: %d,"
" pTemplateName: %p, templateNameLength: %u, pOutLength: %p.",
( const void * ) pTopicBuffer,
( int ) format,
( int ) topic,
( const void * ) pTemplateName,
( unsigned int ) templateNameLength,
( const void * ) pOutLength ) );
}
else
{
ret = FleetProvisioningSuccess;
}
return ret;
}
/*-----------------------------------------------------------*/
static TopicSuffix_t parseTopicSuffix( const char * pRemainingTopic,
uint16_t remainingLength )
{
TopicSuffix_t ret = TopicInvalidSuffix;
FleetProvisioningStatus_t status = FleetProvisioningNoMatch;
const char * pTopicCursor = pRemainingTopic;
uint16_t cursorLength = remainingLength;
assert( pRemainingTopic != NULL );
/* Check if publish topic */
if( cursorLength == 0U )
{
ret = TopicPublish;
status = FleetProvisioningSuccess;
}
/* Check if accepted topic */
if( status == FleetProvisioningNoMatch )
{
status = consumeIfMatch( &pTopicCursor,
&cursorLength,
FP_API_ACCEPTED_SUFFIX,
FP_API_LENGTH_ACCEPTED_SUFFIX );
if( status == FleetProvisioningSuccess )
{
if( cursorLength == 0U )
{
ret = TopicAccepted;
}
else
{
status = FleetProvisioningError;
}
}
}
/* Check if rejected topic */
if( status == FleetProvisioningNoMatch )
{
status = consumeIfMatch( &pTopicCursor,
&cursorLength,
FP_API_REJECTED_SUFFIX,
FP_API_LENGTH_REJECTED_SUFFIX );
if( status == FleetProvisioningSuccess )
{
if( cursorLength == 0U )
{
ret = TopicRejected;
}
}
}
return ret;
}
/*-----------------------------------------------------------*/
static TopicFormatSuffix_t parseTopicFormatSuffix( const char * pRemainingTopic,
uint16_t remainingLength )
{
/* Table of JSON format and suffixes in same order as TopicSuffix_t. */
static const TopicFormatSuffix_t jsonSuffixes[] =
{
TopicJsonPublish,
TopicJsonAccepted,
TopicJsonRejected,
TopicInvalidFormatSuffix
};
/* Table of CBOR format and suffixes in same order as TopicSuffix_t. */
static const TopicFormatSuffix_t cborSuffixes[] =
{
TopicCborPublish,
TopicCborAccepted,
TopicCborRejected,
TopicInvalidFormatSuffix
};
TopicFormatSuffix_t ret = TopicInvalidFormatSuffix;
TopicSuffix_t suffix = TopicInvalidSuffix;
FleetProvisioningStatus_t status = FleetProvisioningNoMatch;
const char * pTopicCursor = pRemainingTopic;
uint16_t cursorLength = remainingLength;
assert( pRemainingTopic != NULL );
/* Check if JSON format */
status = consumeIfMatch( &pTopicCursor,
&cursorLength,
FP_API_JSON_FORMAT,
FP_API_LENGTH_JSON_FORMAT );
if( status == FleetProvisioningSuccess )
{
/* Match suffix */
suffix = parseTopicSuffix( pTopicCursor, cursorLength );
ret = jsonSuffixes[ suffix ];
}
if( status == FleetProvisioningNoMatch )
{
/* Check if CBOR format */
status = consumeIfMatch( &pTopicCursor,
&cursorLength,
FP_API_CBOR_FORMAT,
FP_API_LENGTH_CBOR_FORMAT );
if( status == FleetProvisioningSuccess )
{
/* Match suffix */
suffix = parseTopicSuffix( pTopicCursor, cursorLength );
ret = cborSuffixes[ suffix ];
}
}
return ret;
}
/*-----------------------------------------------------------*/
static FleetProvisioningTopic_t parseCreateCertificateFromCsrTopic( const char * pTopic,
uint16_t topicLength )
{
/* Table of topics in the same order as TopicFormatSuffix_t. */
static const FleetProvisioningTopic_t createCertificateFromCsrApi[] =
{
FleetProvJsonCreateCertFromCsrPublish,
FleetProvJsonCreateCertFromCsrAccepted,
FleetProvJsonCreateCertFromCsrRejected,
FleetProvCborCreateCertFromCsrPublish,
FleetProvCborCreateCertFromCsrAccepted,
FleetProvCborCreateCertFromCsrRejected,
FleetProvisioningInvalidTopic
};
FleetProvisioningTopic_t ret = FleetProvisioningInvalidTopic;
FleetProvisioningStatus_t status = FleetProvisioningError;
TopicFormatSuffix_t rest = TopicInvalidFormatSuffix;
const char * pTopicCursor = pTopic;
uint16_t cursorLength = topicLength;
assert( pTopic != NULL );
/* Check if prefix matches */
status = consumeIfMatch( &pTopicCursor,
&cursorLength,
FP_CREATE_CERT_API_PREFIX,
FP_CREATE_CERT_API_LENGTH_PREFIX );
if( status == FleetProvisioningSuccess )
{
/* Match format and suffix */
rest = parseTopicFormatSuffix( pTopicCursor, cursorLength );
ret = createCertificateFromCsrApi[ rest ];
}
return ret;
}
/*-----------------------------------------------------------*/
static FleetProvisioningTopic_t parseCreateKeysAndCertificateTopic( const char * pTopic,
uint16_t topicLength )
{
/* Table of topics in the same order as TopicFormatSuffix_t. */
static const FleetProvisioningTopic_t createKeysAndCertificateApi[] =
{
FleetProvJsonCreateKeysAndCertPublish,
FleetProvJsonCreateKeysAndCertAccepted,
FleetProvJsonCreateKeysAndCertRejected,
FleetProvCborCreateKeysAndCertPublish,
FleetProvCborCreateKeysAndCertAccepted,
FleetProvCborCreateKeysAndCertRejected,
FleetProvisioningInvalidTopic
};
FleetProvisioningTopic_t ret = FleetProvisioningInvalidTopic;
FleetProvisioningStatus_t status = FleetProvisioningError;
TopicFormatSuffix_t rest = TopicInvalidFormatSuffix;
const char * pTopicCursor = pTopic;
uint16_t cursorLength = topicLength;
assert( pTopic != NULL );
/* Check if prefix matches */
status = consumeIfMatch( &pTopicCursor,
&cursorLength,
FP_CREATE_KEYS_API_PREFIX,
FP_CREATE_KEYS_API_LENGTH_PREFIX );
if( status == FleetProvisioningSuccess )
{
/* Match format and suffix */
rest = parseTopicFormatSuffix( pTopicCursor, cursorLength );
ret = createKeysAndCertificateApi[ rest ];
}
return ret;
}
/*-----------------------------------------------------------*/
static FleetProvisioningTopic_t parseRegisterThingTopic( const char * pTopic,
uint16_t topicLength )
{
/* Table of topics in the same order as TopicFormatSuffix_t. */
static const FleetProvisioningTopic_t registerThingApi[] =
{
FleetProvJsonRegisterThingPublish,
FleetProvJsonRegisterThingAccepted,
FleetProvJsonRegisterThingRejected,
FleetProvCborRegisterThingPublish,
FleetProvCborRegisterThingAccepted,
FleetProvCborRegisterThingRejected,
FleetProvisioningInvalidTopic
};
FleetProvisioningTopic_t ret = FleetProvisioningInvalidTopic;
FleetProvisioningStatus_t status = FleetProvisioningError;
TopicFormatSuffix_t rest = TopicInvalidFormatSuffix;
const char * pTopicCursor = pTopic;
uint16_t cursorLength = topicLength;
assert( pTopic != NULL );
/* Check if prefix matches */
status = consumeIfMatch( &pTopicCursor,
&cursorLength,
FP_REGISTER_API_PREFIX,
FP_REGISTER_API_LENGTH_PREFIX );
if( status == FleetProvisioningSuccess )
{
/* Skip template name */
status = consumeTemplateName( &pTopicCursor,
&cursorLength );
}
if( status == FleetProvisioningSuccess )
{
/* Check if bridge matches */
status = consumeIfMatch( &pTopicCursor,
&cursorLength,
FP_REGISTER_API_BRIDGE,
FP_REGISTER_API_LENGTH_BRIDGE );
}
if( status == FleetProvisioningSuccess )
{
/* Match format and suffix */
rest = parseTopicFormatSuffix( pTopicCursor, cursorLength );
ret = registerThingApi[ rest ];
}
return ret;
}
/*-----------------------------------------------------------*/
static FleetProvisioningStatus_t consumeIfMatch( const char ** pBufferCursor,
uint16_t * pRemainingLength,
const char * matchString,
uint16_t matchLength )
{
FleetProvisioningStatus_t status = FleetProvisioningError;
int32_t cmpVal = -1;
assert( pBufferCursor != NULL );
assert( *pBufferCursor != NULL );
assert( pRemainingLength != NULL );
assert( matchString != NULL );
if( *pRemainingLength < matchLength )
{
status = FleetProvisioningNoMatch;
}
else
{
cmpVal = strncmp( *pBufferCursor,
matchString,
( size_t ) matchLength );
if( cmpVal != 0 )
{
status = FleetProvisioningNoMatch;
}
else
{
status = FleetProvisioningSuccess;
*pBufferCursor += matchLength;
*pRemainingLength -= matchLength;
}
}
return status;
}
/*-----------------------------------------------------------*/
static FleetProvisioningStatus_t consumeTemplateName( const char ** pTopicCursor,
uint16_t * pRemainingLength )
{
FleetProvisioningStatus_t ret = FleetProvisioningNoMatch;
uint16_t i = 0U;
assert( pTopicCursor != NULL );
assert( *pTopicCursor != NULL );
assert( pRemainingLength != NULL );
/* Find the first forward slash. It marks the end of the template name. */
for( i = 0U; i < *pRemainingLength; i++ )
{
if( ( *pTopicCursor )[ i ] == '/' )
{
break;
}
}
/* Zero length template name is not valid. */
if( i > 0U )
{
ret = FleetProvisioningSuccess;
*pTopicCursor += i;
*pRemainingLength -= i;
}
return ret;
}
/*-----------------------------------------------------------*/
FleetProvisioningStatus_t FleetProvisioning_GetRegisterThingTopic( char * pTopicBuffer,
uint16_t bufferLength,
FleetProvisioningFormat_t format,
FleetProvisioningApiTopics_t topic,
const char * pTemplateName,
uint16_t templateNameLength,
uint16_t * pOutLength )
{
FleetProvisioningStatus_t status = FleetProvisioningError;
uint16_t topicLength = 0U;
char * pBufferCursor = pTopicBuffer;
status = GetRegisterThingTopicCheckParams( pTopicBuffer,
format,
topic,
pTemplateName,
templateNameLength,
pOutLength );
if( status == FleetProvisioningSuccess )
{
topicLength = getRegisterThingTopicLength( templateNameLength, format, topic );
if( bufferLength < topicLength )
{
status = FleetProvisioningBufferTooSmall;
LogError( ( "The buffer is too small to hold the topic string. "
"Provided buffer size: %u, Required buffer size: %u.",
( unsigned int ) bufferLength,
( unsigned int ) topicLength ) );
}
}
if( status == FleetProvisioningSuccess )
{
/* At this point, it is certain that we have a large enough buffer to
* write the topic string into. */
/* Write prefix first. */
writeTopicFragmentAndAdvance( &pBufferCursor,
FP_REGISTER_API_PREFIX,
FP_REGISTER_API_LENGTH_PREFIX );
/* Write template name next. */
writeTopicFragmentAndAdvance( &pBufferCursor,
pTemplateName,
templateNameLength );
/* Write bridge next. */
writeTopicFragmentAndAdvance( &pBufferCursor,
FP_REGISTER_API_BRIDGE,
FP_REGISTER_API_LENGTH_BRIDGE );
/* Write report format. */
if( format == FleetProvisioningJson )
{
writeTopicFragmentAndAdvance( &pBufferCursor,
FP_API_JSON_FORMAT,
FP_API_LENGTH_JSON_FORMAT );
}
if( format == FleetProvisioningCbor )
{
writeTopicFragmentAndAdvance( &pBufferCursor,
FP_API_CBOR_FORMAT,
FP_API_LENGTH_CBOR_FORMAT );
}
/* Write report suffix. */
if( topic == FleetProvisioningAccepted )
{
writeTopicFragmentAndAdvance( &pBufferCursor,
FP_API_ACCEPTED_SUFFIX,
FP_API_LENGTH_ACCEPTED_SUFFIX );
}
if( topic == FleetProvisioningRejected )
{
writeTopicFragmentAndAdvance( &pBufferCursor,
FP_API_REJECTED_SUFFIX,
FP_API_LENGTH_REJECTED_SUFFIX );
}
*pOutLength = topicLength;
}
return status;
}
/*-----------------------------------------------------------*/
FleetProvisioningStatus_t FleetProvisioning_MatchTopic( const char * pTopic,
uint16_t topicLength,
FleetProvisioningTopic_t * pOutApi )
{
FleetProvisioningStatus_t ret = FleetProvisioningNoMatch;
if( ( pTopic == NULL ) || ( pOutApi == NULL ) )
{
ret = FleetProvisioningBadParameter;
LogError( ( "Invalid input parameter. pTopic: %p, pOutApi: %p.",
( const void * ) pTopic,
( void * ) pOutApi ) );
}
else
{
*pOutApi = parseCreateCertificateFromCsrTopic( pTopic, topicLength );
if( *pOutApi == FleetProvisioningInvalidTopic )
{
*pOutApi = parseCreateKeysAndCertificateTopic( pTopic, topicLength );
}
if( *pOutApi == FleetProvisioningInvalidTopic )
{
*pOutApi = parseRegisterThingTopic( pTopic, topicLength );
}
if( *pOutApi != FleetProvisioningInvalidTopic )
{
ret = FleetProvisioningSuccess;
}
}
return ret;
}
/*-----------------------------------------------------------*/

View File

@ -0,0 +1,721 @@
/*
* AWS IoT Fleet Provisioning v1.1.0
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* 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.
*/
/**
* @file fleet_provisioning.h
* @brief Interface for the AWS IoT Fleet Provisioning Library.
*/
#ifndef FLEET_PROVISIONING_H_
#define FLEET_PROVISIONING_H_
/* Standard includes. */
#include <stdint.h>
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/* FLEET_PROVISIONING_DO_NOT_USE_CUSTOM_CONFIG allows building the Fleet
* Provisioning library without a config file. If a config file is provided,
* FLEET_PROVISIONING_DO_NOT_USE_CUSTOM_CONFIG macro must not be defined.
*/
#ifndef FLEET_PROVISIONING_DO_NOT_USE_CUSTOM_CONFIG
#include "fleet_provisioning_config.h"
#endif
/* Default config values. */
#include "fleet_provisioning_config_defaults.h"
/**
* @ingroup fleet_provisioning_enum_types
* @brief Return codes for Fleet Provisioning APIs.
*/
typedef enum
{
FleetProvisioningError = 0,
FleetProvisioningSuccess,
FleetProvisioningNoMatch,
FleetProvisioningBadParameter,
FleetProvisioningBufferTooSmall
} FleetProvisioningStatus_t;
/**
* @ingroup fleet_provisioning_enum_types
* @brief Fleet Provisioning topic values.
*/
typedef enum
{
FleetProvisioningInvalidTopic = 0,
FleetProvJsonCreateCertFromCsrPublish,
FleetProvJsonCreateCertFromCsrAccepted,
FleetProvJsonCreateCertFromCsrRejected,
FleetProvJsonCreateKeysAndCertPublish,
FleetProvJsonCreateKeysAndCertAccepted,
FleetProvJsonCreateKeysAndCertRejected,
FleetProvJsonRegisterThingPublish,
FleetProvJsonRegisterThingAccepted,
FleetProvJsonRegisterThingRejected,
FleetProvCborCreateCertFromCsrPublish,
FleetProvCborCreateCertFromCsrAccepted,
FleetProvCborCreateCertFromCsrRejected,
FleetProvCborCreateKeysAndCertPublish,
FleetProvCborCreateKeysAndCertAccepted,
FleetProvCborCreateKeysAndCertRejected,
FleetProvCborRegisterThingPublish,
FleetProvCborRegisterThingAccepted,
FleetProvCborRegisterThingRejected
} FleetProvisioningTopic_t;
/**
* @ingroup fleet_provisioning_enum_types
* @brief Topics for each Fleet Provisioning APIs.
*/
typedef enum
{
FleetProvisioningPublish,
FleetProvisioningAccepted,
FleetProvisioningRejected
} FleetProvisioningApiTopics_t;
/**
* @ingroup fleet_provisioning_enum_types
* @brief Message format for Fleet Provisioning APIs.
*/
typedef enum
{
FleetProvisioningJson,
FleetProvisioningCbor
} FleetProvisioningFormat_t;
/*-----------------------------------------------------------*/
/**
* @ingroup fleet_provisioning_constants
* @brief Maximum length of a thing's name as permitted by AWS IoT Core.
*/
#define FP_TEMPLATENAME_MAX_LENGTH 36U
/*-----------------------------------------------------------*/
/**
* @cond DOXYGEN_IGNORE
* Doxygen should ignore these macros as they are private.
*/
#define FP_CREATE_CERT_API_PREFIX "$aws/certificates/create-from-csr/"
#define FP_CREATE_CERT_API_LENGTH_PREFIX ( ( uint16_t ) ( sizeof( FP_CREATE_CERT_API_PREFIX ) - 1U ) )
#define FP_CREATE_KEYS_API_PREFIX "$aws/certificates/create/"
#define FP_CREATE_KEYS_API_LENGTH_PREFIX ( ( uint16_t ) ( sizeof( FP_CREATE_KEYS_API_PREFIX ) - 1U ) )
#define FP_REGISTER_API_PREFIX "$aws/provisioning-templates/"
#define FP_REGISTER_API_LENGTH_PREFIX ( ( uint16_t ) ( sizeof( FP_REGISTER_API_PREFIX ) - 1U ) )
#define FP_REGISTER_API_BRIDGE "/provision/"
#define FP_REGISTER_API_LENGTH_BRIDGE ( ( uint16_t ) ( sizeof( FP_REGISTER_API_BRIDGE ) - 1U ) )
#define FP_API_JSON_FORMAT "json"
#define FP_API_LENGTH_JSON_FORMAT ( ( uint16_t ) ( sizeof( FP_API_JSON_FORMAT ) - 1U ) )
#define FP_API_CBOR_FORMAT "cbor"
#define FP_API_LENGTH_CBOR_FORMAT ( ( uint16_t ) ( sizeof( FP_API_CBOR_FORMAT ) - 1U ) )
#define FP_API_ACCEPTED_SUFFIX "/accepted"
#define FP_API_LENGTH_ACCEPTED_SUFFIX ( ( uint16_t ) ( sizeof( FP_API_ACCEPTED_SUFFIX ) - 1U ) )
#define FP_API_REJECTED_SUFFIX "/rejected"
#define FP_API_LENGTH_REJECTED_SUFFIX ( ( uint16_t ) ( sizeof( FP_API_REJECTED_SUFFIX ) - 1U ) )
/** @endcond */
/*-----------------------------------------------------------*/
/* Fleet Provisioning CreateCertificateFromCSR macros */
/**
* @brief Topic string for publishing a JSON CreateCertificateFromCSR request.
*/
#define FP_JSON_CREATE_CERT_PUBLISH_TOPIC \
( FP_CREATE_CERT_API_PREFIX \
FP_API_JSON_FORMAT )
/**
* @brief Topic string for getting a JSON CreateCertificateFromCSR accepted response.
*/
#define FP_JSON_CREATE_CERT_ACCEPTED_TOPIC \
( FP_CREATE_CERT_API_PREFIX \
FP_API_JSON_FORMAT \
FP_API_ACCEPTED_SUFFIX )
/**
* @brief Topic string for getting a JSON CreateCertificateFromCSR error response.
*/
#define FP_JSON_CREATE_CERT_REJECTED_TOPIC \
( FP_CREATE_CERT_API_PREFIX \
FP_API_JSON_FORMAT \
FP_API_REJECTED_SUFFIX )
/**
* @brief Topic string for publishing a CBOR CreateCertificateFromCSR request.
*/
#define FP_CBOR_CREATE_CERT_PUBLISH_TOPIC \
( FP_CREATE_CERT_API_PREFIX \
FP_API_CBOR_FORMAT )
/**
* @brief Topic string for getting a CBOR CreateCertificateFromCSR accepted response.
*/
#define FP_CBOR_CREATE_CERT_ACCEPTED_TOPIC \
( FP_CREATE_CERT_API_PREFIX \
FP_API_CBOR_FORMAT \
FP_API_ACCEPTED_SUFFIX )
/**
* @brief Topic string for getting a CBOR CreateCertificateFromCSR error response.
*/
#define FP_CBOR_CREATE_CERT_REJECTED_TOPIC \
( FP_CREATE_CERT_API_PREFIX \
FP_API_CBOR_FORMAT \
FP_API_REJECTED_SUFFIX )
/**
* @brief Length of topic string for publishing a JSON CreateCertificateFromCSR request.
*/
#define FP_JSON_CREATE_CERT_PUBLISH_LENGTH \
( ( uint16_t ) ( sizeof( FP_JSON_CREATE_CERT_PUBLISH_TOPIC ) - 1U ) )
/**
* @brief Length of topic string for getting a JSON CreateCertificateFromCSR accepted response.
*/
#define FP_JSON_CREATE_CERT_ACCEPTED_LENGTH \
( ( uint16_t ) ( sizeof( FP_JSON_CREATE_CERT_ACCEPTED_TOPIC ) - 1U ) )
/**
* @brief Length of topic string for getting a JSON CreateCertificateFromCSR error response.
*/
#define FP_JSON_CREATE_CERT_REJECTED_LENGTH \
( ( uint16_t ) ( sizeof( FP_JSON_CREATE_CERT_REJECTED_TOPIC ) - 1U ) )
/**
* @brief Length of topic string for publishing a CBOR CreateCertificateFromCSR request.
*/
#define FP_CBOR_CREATE_CERT_PUBLISH_LENGTH \
( ( uint16_t ) ( sizeof( FP_CBOR_CREATE_CERT_PUBLISH_TOPIC ) - 1U ) )
/**
* @brief Length of topic string for getting a CBOR CreateCertificateFromCSR accepted response.
*/
#define FP_CBOR_CREATE_CERT_ACCEPTED_LENGTH \
( ( uint16_t ) ( sizeof( FP_CBOR_CREATE_CERT_ACCEPTED_TOPIC ) - 1U ) )
/**
* @brief Length of topic string for getting a CBOR CreateCertificateFromCSR error response.
*/
#define FP_CBOR_CREATE_CERT_REJECTED_LENGTH \
( ( uint16_t ) ( sizeof( FP_CBOR_CREATE_CERT_REJECTED_TOPIC ) - 1U ) )
/*-----------------------------------------------------------*/
/* Fleet Provisioning CreateKeysAndCertificate macros */
/**
* @brief Topic string for publishing a JSON CreateKeysAndCertificate request.
*/
#define FP_JSON_CREATE_KEYS_PUBLISH_TOPIC \
( FP_CREATE_KEYS_API_PREFIX \
FP_API_JSON_FORMAT )
/**
* @brief Topic string for getting a JSON CreateKeysAndCertificate accepted response.
*/
#define FP_JSON_CREATE_KEYS_ACCEPTED_TOPIC \
( FP_CREATE_KEYS_API_PREFIX \
FP_API_JSON_FORMAT \
FP_API_ACCEPTED_SUFFIX )
/**
* @brief Topic string for getting a JSON CreateKeysAndCertificate error
* response.
*/
#define FP_JSON_CREATE_KEYS_REJECTED_TOPIC \
( FP_CREATE_KEYS_API_PREFIX \
FP_API_JSON_FORMAT \
FP_API_REJECTED_SUFFIX )
/**
* @brief Topic string for publishing a CBOR CreateKeysAndCertificate request.
*/
#define FP_CBOR_CREATE_KEYS_PUBLISH_TOPIC \
( FP_CREATE_KEYS_API_PREFIX \
FP_API_CBOR_FORMAT )
/**
* @brief Topic string for getting a CBOR CreateKeysAndCertificate accepted response.
*/
#define FP_CBOR_CREATE_KEYS_ACCEPTED_TOPIC \
( FP_CREATE_KEYS_API_PREFIX \
FP_API_CBOR_FORMAT \
FP_API_ACCEPTED_SUFFIX )
/**
* @brief Topic string for getting a CBOR CreateKeysAndCertificate error
* response.
*/
#define FP_CBOR_CREATE_KEYS_REJECTED_TOPIC \
( FP_CREATE_KEYS_API_PREFIX \
FP_API_CBOR_FORMAT \
FP_API_REJECTED_SUFFIX )
/**
* @brief Length of topic string for publishing a JSON CreateKeysAndCertificate request.
*/
#define FP_JSON_CREATE_KEYS_PUBLISH_LENGTH \
( ( uint16_t ) ( sizeof( FP_JSON_CREATE_KEYS_PUBLISH_TOPIC ) - 1U ) )
/**
* @brief Length of topic string for getting a JSON CreateKeysAndCertificate accepted response.
*/
#define FP_JSON_CREATE_KEYS_ACCEPTED_LENGTH \
( ( uint16_t ) ( sizeof( FP_JSON_CREATE_KEYS_ACCEPTED_TOPIC ) - 1U ) )
/**
* @brief Length of topic string for getting a JSON CreateKeysAndCertificate error response.
*/
#define FP_JSON_CREATE_KEYS_REJECTED_LENGTH \
( ( uint16_t ) ( sizeof( FP_JSON_CREATE_KEYS_REJECTED_TOPIC ) - 1U ) )
/**
* @brief Length of topic string for publishing a CBOR CreateKeysAndCertificate request.
*/
#define FP_CBOR_CREATE_KEYS_PUBLISH_LENGTH \
( ( uint16_t ) ( sizeof( FP_CBOR_CREATE_KEYS_PUBLISH_TOPIC ) - 1U ) )
/**
* @brief Length of topic string for getting a CBOR CreateKeysAndCertificate accepted response.
*/
#define FP_CBOR_CREATE_KEYS_ACCEPTED_LENGTH \
( ( uint16_t ) ( sizeof( FP_CBOR_CREATE_KEYS_ACCEPTED_TOPIC ) - 1U ) )
/**
* @brief Length of topic string for getting a CBOR CreateKeysAndCertificate error response.
*/
#define FP_CBOR_CREATE_KEYS_REJECTED_LENGTH \
( ( uint16_t ) ( sizeof( FP_CBOR_CREATE_KEYS_REJECTED_TOPIC ) - 1U ) )
/*-----------------------------------------------------------*/
/* Fleet Provisioning RegisterThing macros */
/**
* @brief Topic string for publishing a JSON RegisterThing request.
*
* This macro should be used when the provisioning template name is known at
* compile time. If the provisioning template name is not known at compile time,
* the #FleetProvisioning_GetRegisterThingTopic API should be used instead.
*
* @param templateName The name of the provisioning template to use.
*/
#define FP_JSON_REGISTER_PUBLISH_TOPIC( templateName ) \
( FP_REGISTER_API_PREFIX \
templateName \
FP_REGISTER_API_BRIDGE \
FP_API_JSON_FORMAT )
/**
* @brief Topic string for getting a JSON RegisterThing accepted response.
*
* This macro should be used when the provisioning template name is known at
* compile time. If the provisioning template name is not known at compile time,
* the #FleetProvisioning_GetRegisterThingTopic API should be used instead.
*
* @param templateName The name of the provisioning template to use.
*/
#define FP_JSON_REGISTER_ACCEPTED_TOPIC( templateName ) \
( FP_REGISTER_API_PREFIX \
templateName \
FP_REGISTER_API_BRIDGE \
FP_API_JSON_FORMAT \
FP_API_ACCEPTED_SUFFIX )
/**
* @brief Topic string for getting a JSON RegisterThing error response.
*
* This macro should be used when the provisioning template name is known at
* compile time. If the provisioning template name is not known at compile time,
* the #FleetProvisioning_GetRegisterThingTopic API should be used instead.
*
* @param templateName The name of the provisioning template to use.
*/
#define FP_JSON_REGISTER_REJECTED_TOPIC( templateName ) \
( FP_REGISTER_API_PREFIX \
templateName \
FP_REGISTER_API_BRIDGE \
FP_API_JSON_FORMAT \
FP_API_REJECTED_SUFFIX )
/**
* @brief Topic string for publishing a CBOR RegisterThing request.
*
* This macro should be used when the provisioning template name is known at
* compile time. If the provisioning template name is not known at compile time,
* the #FleetProvisioning_GetRegisterThingTopic API should be used instead.
*
* @param templateName The name of the provisioning template to use.
*/
#define FP_CBOR_REGISTER_PUBLISH_TOPIC( templateName ) \
( FP_REGISTER_API_PREFIX \
templateName \
FP_REGISTER_API_BRIDGE \
FP_API_CBOR_FORMAT )
/**
* @brief Topic string for getting a CBOR RegisterThing accepted response.
*
* This macro should be used when the provisioning template name is known at
* compile time. If the provisioning template name is not known at compile time,
* the #FleetProvisioning_GetRegisterThingTopic API should be used instead.
*
* @param templateName The name of the provisioning template to use.
*/
#define FP_CBOR_REGISTER_ACCEPTED_TOPIC( templateName ) \
( FP_REGISTER_API_PREFIX \
templateName \
FP_REGISTER_API_BRIDGE \
FP_API_CBOR_FORMAT \
FP_API_ACCEPTED_SUFFIX )
/**
* @brief Topic string for getting a CBOR RegisterThing error response.
*
* This macro should be used when the provisioning template name is known at
* compile time. If the provisioning template name is not known at compile time,
* the #FleetProvisioning_GetRegisterThingTopic API should be used instead.
*
* @param templateName The name of the provisioning template to use.
*/
#define FP_CBOR_REGISTER_REJECTED_TOPIC( templateName ) \
( FP_REGISTER_API_PREFIX \
templateName \
FP_REGISTER_API_BRIDGE \
FP_API_CBOR_FORMAT \
FP_API_REJECTED_SUFFIX )
/**
* @brief Length of topic string for publishing a JSON RegisterThing request.
*
* This macro should be used when the provisioning template name is known at
* compile time. If the provisioning template name is not known at compile time,
* the #FleetProvisioning_GetRegisterThingTopic API should be used instead.
*
* @param templateNameLength The length of the provisioning template name.
*/
#define FP_JSON_REGISTER_PUBLISH_LENGTH( templateNameLength ) \
( FP_REGISTER_API_LENGTH_PREFIX + \
( templateNameLength ) + \
FP_REGISTER_API_LENGTH_BRIDGE + \
FP_API_LENGTH_JSON_FORMAT )
/**
* @brief Length of topic string for getting a JSON RegisterThing accepted response.
*
* This macro should be used when the provisioning template name is known at
* compile time. If the provisioning template name is not known at compile time,
* the #FleetProvisioning_GetRegisterThingTopic API should be used instead.
*
* @param templateNameLength The length of the provisioning template name.
*/
#define FP_JSON_REGISTER_ACCEPTED_LENGTH( templateNameLength ) \
( FP_REGISTER_API_LENGTH_PREFIX + \
( templateNameLength ) + \
FP_REGISTER_API_LENGTH_BRIDGE + \
FP_API_LENGTH_JSON_FORMAT + \
FP_API_LENGTH_ACCEPTED_SUFFIX )
/**
* @brief Length of topic string for getting a JSON RegisterThing error response.
*
* This macro should be used when the provisioning template name is known at
* compile time. If the provisioning template name is not known at compile time,
* the #FleetProvisioning_GetRegisterThingTopic API should be used instead.
*
* @param templateNameLength The length of the provisioning template name.
*/
#define FP_JSON_REGISTER_REJECTED_LENGTH( templateNameLength ) \
( FP_REGISTER_API_LENGTH_PREFIX + \
( templateNameLength ) + \
FP_REGISTER_API_LENGTH_BRIDGE + \
FP_API_LENGTH_JSON_FORMAT + \
FP_API_LENGTH_REJECTED_SUFFIX )
/**
* @brief Length of topic string for publishing a CBOR RegisterThing request.
*
* This macro should be used when the provisioning template name is known at
* compile time. If the provisioning template name is not known at compile time,
* the #FleetProvisioning_GetRegisterThingTopic API should be used instead.
*
* @param templateNameLength The length of the provisioning template name.
*/
#define FP_CBOR_REGISTER_PUBLISH_LENGTH( templateNameLength ) \
( FP_REGISTER_API_LENGTH_PREFIX + \
( templateNameLength ) + \
FP_REGISTER_API_LENGTH_BRIDGE + \
FP_API_LENGTH_CBOR_FORMAT )
/**
* @brief Length of topic string for getting a CBOR RegisterThing accepted response.
*
* This macro should be used when the provisioning template name is known at
* compile time. If the provisioning template name is not known at compile time,
* the #FleetProvisioning_GetRegisterThingTopic API should be used instead.
*
* @param templateNameLength The length of the provisioning template name.
*/
#define FP_CBOR_REGISTER_ACCEPTED_LENGTH( templateNameLength ) \
( FP_REGISTER_API_LENGTH_PREFIX + \
( templateNameLength ) + \
FP_REGISTER_API_LENGTH_BRIDGE + \
FP_API_LENGTH_CBOR_FORMAT + \
FP_API_LENGTH_ACCEPTED_SUFFIX )
/**
* @brief Length of topic string for getting a CBOR RegisterThing error response.
*
* This macro should be used when the provisioning template name is known at
* compile time. If the provisioning template name is not known at compile time,
* the #FleetProvisioning_GetRegisterThingTopic API should be used instead.
*
* @param templateNameLength The length of the provisioning template name.
*/
#define FP_CBOR_REGISTER_REJECTED_LENGTH( templateNameLength ) \
( FP_REGISTER_API_LENGTH_PREFIX + \
( templateNameLength ) + \
FP_REGISTER_API_LENGTH_BRIDGE + \
FP_API_LENGTH_CBOR_FORMAT + \
FP_API_LENGTH_REJECTED_SUFFIX )
/*-----------------------------------------------------------*/
/* Key names for Fleet Provisioning MQTT API JSON/CBOR payloads. */
/**
* @brief Key for the PEM-encoded certificate signing request in the
* CreateCertificateFromCSR request payload.
*/
#define FP_API_CSR_KEY "certificateSigningRequest"
/**
* @brief Key for the certificate ownership token in the
* CreateCertificateFromCSR and CreateKeysAndCertificate response payloads, and
* the RegisterThing request payload.
*/
#define FP_API_OWNERSHIP_TOKEN_KEY "certificateOwnershipToken"
/**
* @brief Key for the certificate ID in the CreateCertificateFromCSR and
* CreateKeysAndCertificate response payloads.
*/
#define FP_API_CERTIFICATE_ID_KEY "certificateId"
/**
* @brief Key for the PEM-encoded certificate in the CreateCertificateFromCSR
* and CreateKeysAndCertificate response payloads.
*/
#define FP_API_CERTIFICATE_PEM_KEY "certificatePem"
/**
* @brief Key for the private key in the CreateKeysAndCertificate response
* payload.
*/
#define FP_API_PRIVATE_KEY_KEY "privateKey"
/**
* @brief Key for the optional parameters in the RegisterThing request payload.
*/
#define FP_API_PARAMETERS_KEY "parameters"
/**
* @brief Key for the template-defined device configuration in the
* RegisterThing response payload.
*/
#define FP_API_DEVICE_CONFIG_KEY "deviceConfiguration"
/**
* @brief Key for the name of the created AWS IoT Thing in the RegisterThing
* response payload.
*/
#define FP_API_THING_NAME_KEY "thingName"
/**
* @brief Key for the status code in Fleet Provisioning error response
* payloads.
*/
#define FP_API_STATUS_CODE_KEY "statusCode"
/**
* @brief Key for the error code in Fleet Provisioning error response payloads.
*/
#define FP_API_ERROR_CODE_KEY "errorCode"
/**
* @brief Key for the error message in Fleet Provisioning error response
* payloads.
*/
#define FP_API_ERROR_MESSAGE_KEY "errorMessage"
/*-----------------------------------------------------------*/
/**
* @brief Populate the topic string for a Fleet Provisioning RegisterThing topic.
*
* @param[out] pTopicBuffer The buffer to write the topic string into.
* @param[in] bufferLength The length of @p pTopicBuffer.
* @param[in] format The desired RegisterThing format.
* @param[in] topic The desired RegisterThing topic.
* @param[in] pTemplateName The name of the provisioning template configured
* with AWS IoT.
* @param[in] templateNameLength The length of the provisioning template name.
* @param[out] pOutLength The length of the topic string written to the buffer.
*
* @return FleetProvisioningSuccess if the topic string is written to the buffer;
* FleetProvisioningBadParameter if invalid parameters, such as non-RegisterThing topics, are passed;
* FleetProvisioningBufferTooSmall if the buffer cannot hold the full topic string.
*
* <b>example</b>
* @code{c}
*
* // The following example shows how to use the FleetProvisioning_GetRegisterThingTopic
* // function to generate a topic string for getting an accepted response for
* // a JSON RegisterThing request.
*
* #define TOPIC_BUFFER_LENGTH ( 256u )
*
* // In order to use the AWS IoT Fleet Provisioning service, there must be a
* // provisioning template registered with AWS IoT Core.
* // This example assumes that the template is named "template_name".
* #define TEMPLATE_NAME "template_name"
* #define TEMPLATE_NAME_LENGTH ( ( uint16_t ) ( sizeof( TEMPLATE_NAME ) - 1U )
* char pTopicbuffer[ TOPIC_BUFFER_LENGTH ] = { 0 };
* uint16_t topicLength = 0;
* FleetProvisioningStatus_t status = FleetProvisioningError;
*
* status = FleetProvisioning_GetRegisterThingTopic( pTopicBuffer,
* TOPIC_BUFFER_LENGTH,
* FleetProvisioningJson,
* FleetProvisioningAccepted,
* TEMPLATE_NAME,
* TEMPLATE_NAME_LENGTH,
* &( topiclength ) );
*
* if( status == FleetProvisioningSuccess )
* {
* // The buffer pTopicBuffer contains the topic string of length
* // topicLength for getting a response for an accepted JSON RegisterThing
* // request. Subscribe to this topic using an MQTT library of your choice.
* }
* @endcode
*/
/* @[declare_fleet_provisioning_getregisterthingtopic] */
FleetProvisioningStatus_t FleetProvisioning_GetRegisterThingTopic( char * pTopicBuffer,
uint16_t bufferLength,
FleetProvisioningFormat_t format,
FleetProvisioningApiTopics_t topic,
const char * pTemplateName,
uint16_t templateNameLength,
uint16_t * pOutLength );
/* @[declare_fleet_provisioning_getregisterthingtopic] */
/*-----------------------------------------------------------*/
/**
* @brief Check if the given topic is one of the Fleet Provisioning topics.
*
* The function outputs which API the topic is for.
*
* @param[in] pTopic The topic string to check.
* @param[in] topicLength The length of the topic string.
* @param[out] pOutApi The Fleet Provisioning topic API value.
*
* @return FleetProvisioningSuccess if the topic is one of the Fleet Provisioning topics;
* FleetProvisioningBadParameter if invalid parameters are passed;
* FleetProvisioningNoMatch if the topic is NOT one of the Fleet Provisioning topics (parameter
* pOutApi gets FleetProvisioningInvalidTopic).
*
* <b>Example</b>
* @code{c}
*
* // The following example shows how to use the FleetProvisioning_MatchTopic
* // function to check if an incoming MQTT publish message is a Fleet
* // Provisioning message.
*
* FleetProvisioningTopic_t api;
* FleetProvisioningStatus_t status = FleetProvisioningError;
*
* // pTopic and topicLength are the topic string and length of the topic on
* // which the publish message is received. These are usually provided by the
* // MQTT library used.
* status = FleetProvisioning_MatchTopic( pTopic
* topicLength,
* &( api ) );
*
* if( status == FleetProvisioningSuccess )
* {
* if( api == FleetProvJsonCreateCertFromCsrAccepted )
* {
* // The published JSON request was accepted and completed by the AWS
* // IoT Fleet Provisioning service. You can parse the response using
* // your choice of JSON parser get the certificate, ID, and ownership
* // token.
* }
* else if( api == FleetProvJsonCreateCertFromCsrRejected )
* {
* // The published JSON request was rejected by the AWS IoT Fleet
* // Provisioning service.
* }
* else
* {
* // Unexpected response.
* }
* }
* @endcode
*/
/* @[declare_fleet_provisioning_matchtopic] */
FleetProvisioningStatus_t FleetProvisioning_MatchTopic( const char * pTopic,
uint16_t topicLength,
FleetProvisioningTopic_t * pOutApi );
/* @[declare_fleet_provisioning_matchtopic] */
/*-----------------------------------------------------------*/
/* *INDENT-OFF* */
#ifdef __cplusplus
}
#endif
/* *INDENT-ON* */
#endif /* FLEET_PROVISIONING_H_ */

View File

@ -0,0 +1,135 @@
/*
* AWS IoT Fleet Provisioning v1.1.0
* Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* SPDX-License-Identifier: MIT
*
* 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.
*/
/**
* @file fleet_provisioning_config_defaults.h
* @brief Default config values for the AWS IoT Fleet Provisioning Library.
*/
#ifndef FLEET_PROVISIONING_CONFIG_DEFAULTS_H_
#define FLEET_PROVISIONING_CONFIG_DEFAULTS_H_
/* The macro definition for FLEET_PROVISIONING_DO_NOT_USE_CUSTOM_CONFIG is for
* Doxygen documentation only. */
/**
* @brief Define this macro to build the AWS IoT Fleet Provisioning Library
* without the custom config file fleet_provisioning_config.h.
*
* Without the custom config, the the AWS IoT Fleet Provisioning Library builds
* with default values of config macros defined in the
* fleet_provisioning_config_defaults.h file.
*
* If a custom config file is provided, then
* FLEET_PROVISIONING_DO_NOT_USE_CUSTOM_CONFIG must not be defined.
*
* <b>Default value</b>: FLEET_PROVISIONING_DO_NOT_USE_CUSTOM_CONFIG is
* <b>not</b> defined by default and the library expects a
* fleet_provisioning_config.h file.
*/
#ifdef DOXYGEN
#define FLEET_PROVISIONING_DO_NOT_USE_CUSTOM_CONFIG
#endif
/**
* @brief Macro used in the Fleet Provisioning library to log error messages.
*
* To enable error logging, this macro should be mapped to an
* application-specific logging implementation.
*
* @note This logging macro is called in the Fleet Provisioning library with
* parameters wrapped in double parentheses to be ISO C89/C90 standard
* compliant. For a reference POSIX implementation of the logging macros, refer
* to the fleet_provisioning_config.h file, and the logging-stack in demos
* folder of the [AWS IoT Embedded C SDK
* repository](https://github.com/aws/aws-iot-device-sdk-embedded-C).
*
* <b>Default value</b>: Error logs are turned off, and no code is generated for
* calls to the macro in the Fleet Provisioning library on compilation.
*/
#ifndef LogError
#define LogError( message )
#endif
/**
* @brief Macro used in the Fleet Provisioning library to log warning messages.
*
* To enable warning logging, this macro should be mapped to an
* application-specific logging implementation.
*
* @note This logging macro is called in the Fleet Provisioning library with
* parameters wrapped in double parentheses to be ISO C89/C90 standard
* compliant. For a reference POSIX implementation of the logging macros, refer
* to the fleet_provisioning_config.h file, and the logging-stack in demos
* folder of the [AWS IoT Embedded C SDK
* repository](https://github.com/aws/aws-iot-device-sdk-embedded-C).
*
* <b>Default value</b>: Warning logs are turned off, and no code is generated
* for calls to the macro in the Fleet Provisioning library on compilation.
*/
#ifndef LogWarn
#define LogWarn( message )
#endif
/**
* @brief Macro used in the Fleet Provisioning library to log info messages.
*
* To enable info logging, this macro should be mapped to an
* application-specific logging implementation.
*
* @note This logging macro is called in the Fleet Provisioning library with
* parameters wrapped in double parentheses to be ISO C89/C90 standard
* compliant. For a reference POSIX implementation of the logging macros, refer
* to the fleet_provisioning_config.h file, and the logging-stack in demos
* folder of the [AWS IoT Embedded C SDK
* repository](https://github.com/aws/aws-iot-device-sdk-embedded-C).
*
* <b>Default value</b>: Info logs are turned off, and no code is generated for
* calls to the macro in the Fleet Provisioning library on compilation.
*/
#ifndef LogInfo
#define LogInfo( message )
#endif
/**
* @brief Macro used in the Fleet Provisioning library to log debug messages.
*
* To enable debug logging, this macro should be mapped to an
* application-specific logging implementation.
*
* @note This logging macro is called in the Fleet Provisioning library with
* parameters wrapped in double parentheses to be ISO C89/C90 standard
* compliant. For a reference POSIX implementation of the logging macros, refer
* to the fleet_provisioning_config.h file, and the logging-stack in demos
* folder of the [AWS IoT Embedded C SDK
* repository](https://github.com/aws/aws-iot-device-sdk-embedded-C).
*
* <b>Default value</b>: Debug logs are turned off, and no code is generated for
* calls to the macro in the Fleet Provisioning library on compilation.
*/
#ifndef LogDebug
#define LogDebug( message )
#endif
#endif /* FLEET_PROVISIONING_CONFIG_DEFAULTS_H_ */