[修改] 增加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,573 @@
/*
* AWS IoT Device Defender Client v1.3.0
* Copyright (C) 2020 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 defender.c
* @brief Implementation of the AWS IoT Device Defender Client Library.
*/
/* Standard includes. */
#include <assert.h>
#include <stddef.h>
#include <string.h>
/* Defender API include. */
#include "defender.h"
/**
* @brief Get the topic length for a given defender API.
*
* @param[in] thingNameLength The length of the thing name as registered with AWS IoT.
* @param[in] api The defender API value.
*
* @return The topic length for the given defender API.
*/
static uint16_t getTopicLength( uint16_t thingNameLength,
DefenderTopic_t api );
/**
* @brief Write the format and suffix part for the given defender API to the buffer.
*
* Format: json or cbor.
* Suffix: /accepted or /rejected or empty.
*
* @param[in] pBuffer The buffer to write the format and suffix part into.
* @param[in] api The defender API value.
*
* @note This function assumes that the buffer is large enough to hold the
* value.
*/
static void writeFormatAndSuffix( char * pBuffer,
DefenderTopic_t api );
/**
* @brief Check if the unparsed topic so far starts with the defender prefix.
*
* The defender prefix is "$aws/things/".
*
* @param[in] pRemainingTopic Starting location of the unparsed topic.
* @param[in] remainingTopicLength The length of the unparsed topic.
*
* @return #DefenderSuccess if the unparsed topic starts with the defender
* prefix; #DefenderNoMatch otherwise.
*/
static DefenderStatus_t matchPrefix( const char * pRemainingTopic,
uint16_t remainingTopicLength );
/**
* @brief Extract the length of thing name in the unparsed topic so far.
*
* The end of thing name is marked by a forward slash. A zero length thing name
* is not valid.
*
* This function extracts the same thing name from the following topic strings:
* - $aws/things/THING_NAME/defender/metrics/json
* - $aws/things/THING_NAME
* The second topic is not a valid defender topic and the matching will fail
* when we try to match the bridge part.
*
* @param[in] pRemainingTopic Starting location of the unparsed topic.
* @param[in] remainingTopicLength The length of the unparsed topic.
* @param[out] pOutThingNameLength The length of the thing name in the topic string.
*
* @return #DefenderSuccess if a valid thing name is found; #DefenderNoMatch
* otherwise.
*/
static DefenderStatus_t extractThingNameLength( const char * pRemainingTopic,
uint16_t remainingTopicLength,
uint16_t * pOutThingNameLength );
/**
* @brief Check if the unparsed topic so far starts with the defender bridge.
*
* The defender bridge is "/defender/metrics/".
*
* @param[in] pRemainingTopic Starting location of the unparsed topic.
* @param[in] remainingTopicLength The length of the unparsed topic.
*
* @return #DefenderSuccess if the unparsed topic starts with the defender
* bridge; #DefenderNoMatch otherwise.
*/
static DefenderStatus_t matchBridge( const char * pRemainingTopic,
uint16_t remainingTopicLength );
/**
* @brief Check if the unparsed topic so far exactly matches one of the defender
* api topics.
*
* The defender api topics are the following:
* - json
* - json/accepted
* - json/rejected
* - cbor
* - cbor/accepted
* - cbor/rejected
*
* The function also outputs the defender API value if a match is found.
*
* @param[in] pRemainingTopic Starting location of the unparsed topic.
* @param[in] remainingTopicLength The length of the unparsed topic.
* @param[out] pOutApi The defender topic API value.
*
* @return #DefenderSuccess if the unparsed topic exactly matches one of the
* defender api topics; #DefenderNoMatch otherwise.
*/
static DefenderStatus_t matchApi( const char * pRemainingTopic,
uint16_t remainingTopicLength,
DefenderTopic_t * pOutApi );
/*-----------------------------------------------------------*/
static uint16_t getTopicLength( uint16_t thingNameLength,
DefenderTopic_t api )
{
uint16_t topicLength = 0U;
assert( ( thingNameLength != 0U ) && ( thingNameLength <= DEFENDER_THINGNAME_MAX_LENGTH ) );
assert( ( api > DefenderInvalidTopic ) && ( api < DefenderMaxTopic ) );
switch( api )
{
case DefenderJsonReportPublish:
topicLength = DEFENDER_API_LENGTH_JSON_PUBLISH( thingNameLength );
break;
case DefenderJsonReportAccepted:
topicLength = DEFENDER_API_LENGTH_JSON_ACCEPTED( thingNameLength );
break;
case DefenderJsonReportRejected:
topicLength = DEFENDER_API_LENGTH_JSON_REJECTED( thingNameLength );
break;
case DefenderCborReportPublish:
topicLength = DEFENDER_API_LENGTH_CBOR_PUBLISH( thingNameLength );
break;
case DefenderCborReportAccepted:
topicLength = DEFENDER_API_LENGTH_CBOR_ACCEPTED( thingNameLength );
break;
/* The default is here just to silence compiler warnings in a way which
* does not bring coverage down. The assert at the beginning of this
* function ensures that the only api value hitting this case can be
* DefenderCborReportRejected. */
case DefenderCborReportRejected:
default:
topicLength = DEFENDER_API_LENGTH_CBOR_REJECTED( thingNameLength );
break;
}
return topicLength;
}
/*-----------------------------------------------------------*/
static void writeFormatAndSuffix( char * pBuffer,
DefenderTopic_t api )
{
/* The following variables are to address MISRA Rule 7.4 violation of
* passing const char * for const void * param of memcpy. */
const char * pDefenderApiJsonFormat = DEFENDER_API_JSON_FORMAT;
const char * pDefenderApiCborFormat = DEFENDER_API_CBOR_FORMAT;
const char * pDefenderApiAcceptedSuffix = DEFENDER_API_ACCEPTED_SUFFIX;
const char * pDefenderApiRejectedSuffix = DEFENDER_API_REJECTED_SUFFIX;
assert( pBuffer != NULL );
assert( ( api > DefenderInvalidTopic ) && ( api < DefenderMaxTopic ) );
switch( api )
{
case DefenderJsonReportPublish:
( void ) memcpy( ( void * ) pBuffer,
( const void * ) pDefenderApiJsonFormat,
( size_t ) DEFENDER_API_LENGTH_JSON_FORMAT );
break;
case DefenderJsonReportAccepted:
( void ) memcpy( ( void * ) pBuffer,
( const void * ) pDefenderApiJsonFormat,
( size_t ) DEFENDER_API_LENGTH_JSON_FORMAT );
( void ) memcpy( ( void * ) &( pBuffer[ DEFENDER_API_LENGTH_JSON_FORMAT ] ),
( const void * ) pDefenderApiAcceptedSuffix,
( size_t ) DEFENDER_API_LENGTH_ACCEPTED_SUFFIX );
break;
case DefenderJsonReportRejected:
( void ) memcpy( ( void * ) pBuffer,
( const void * ) pDefenderApiJsonFormat,
DEFENDER_API_LENGTH_JSON_FORMAT );
( void ) memcpy( ( void * ) &( pBuffer[ DEFENDER_API_LENGTH_JSON_FORMAT ] ),
( const void * ) pDefenderApiRejectedSuffix,
( size_t ) DEFENDER_API_LENGTH_REJECTED_SUFFIX );
break;
case DefenderCborReportPublish:
( void ) memcpy( ( void * ) pBuffer,
( const void * ) pDefenderApiCborFormat,
( size_t ) DEFENDER_API_LENGTH_CBOR_FORMAT );
break;
case DefenderCborReportAccepted:
( void ) memcpy( ( void * ) pBuffer,
( const void * ) pDefenderApiCborFormat,
DEFENDER_API_LENGTH_CBOR_FORMAT );
( void ) memcpy( ( void * ) &( pBuffer[ DEFENDER_API_LENGTH_CBOR_FORMAT ] ),
( const void * ) pDefenderApiAcceptedSuffix,
( size_t ) DEFENDER_API_LENGTH_ACCEPTED_SUFFIX );
break;
/* The default is here just to silence compiler warnings in a way which
* does not bring coverage down. The assert at the beginning of this
* function ensures that the only api value hitting this case can be
* DefenderCborReportRejected. */
case DefenderCborReportRejected:
default:
( void ) memcpy( ( void * ) pBuffer,
( const void * ) pDefenderApiCborFormat,
( size_t ) DEFENDER_API_LENGTH_CBOR_FORMAT );
( void ) memcpy( ( void * ) &( pBuffer[ DEFENDER_API_LENGTH_CBOR_FORMAT ] ),
( const void * ) pDefenderApiRejectedSuffix,
( size_t ) DEFENDER_API_LENGTH_REJECTED_SUFFIX );
break;
}
}
/*-----------------------------------------------------------*/
static DefenderStatus_t matchPrefix( const char * pRemainingTopic,
uint16_t remainingTopicLength )
{
DefenderStatus_t ret = DefenderNoMatch;
assert( pRemainingTopic != NULL );
if( remainingTopicLength >= DEFENDER_API_LENGTH_PREFIX )
{
if( strncmp( pRemainingTopic,
DEFENDER_API_PREFIX,
( size_t ) DEFENDER_API_LENGTH_PREFIX ) == 0 )
{
ret = DefenderSuccess;
}
}
return ret;
}
/*-----------------------------------------------------------*/
static DefenderStatus_t extractThingNameLength( const char * pRemainingTopic,
uint16_t remainingTopicLength,
uint16_t * pOutThingNameLength )
{
DefenderStatus_t ret = DefenderNoMatch;
uint16_t i = 0U;
assert( pRemainingTopic != NULL );
assert( pOutThingNameLength != NULL );
/* Find the first forward slash. It marks the end of the thing name. */
for( i = 0U; i < remainingTopicLength; i++ )
{
if( pRemainingTopic[ i ] == '/' )
{
break;
}
}
/* Zero length thing name is not valid. */
if( i > 0U )
{
*pOutThingNameLength = i;
ret = DefenderSuccess;
}
return ret;
}
/*-----------------------------------------------------------*/
static DefenderStatus_t matchBridge( const char * pRemainingTopic,
uint16_t remainingTopicLength )
{
DefenderStatus_t ret = DefenderNoMatch;
assert( pRemainingTopic != NULL );
if( remainingTopicLength >= DEFENDER_API_LENGTH_BRIDGE )
{
if( strncmp( pRemainingTopic,
DEFENDER_API_BRIDGE,
( size_t ) DEFENDER_API_LENGTH_BRIDGE ) == 0 )
{
ret = DefenderSuccess;
}
}
return ret;
}
/*-----------------------------------------------------------*/
static DefenderStatus_t matchApi( const char * pRemainingTopic,
uint16_t remainingTopicLength,
DefenderTopic_t * pOutApi )
{
DefenderStatus_t ret = DefenderNoMatch;
uint16_t i = 0U;
/* Table of defender APIs. */
static const DefenderTopic_t defenderApi[] =
{
DefenderJsonReportPublish,
DefenderJsonReportAccepted,
DefenderJsonReportRejected,
DefenderCborReportPublish,
DefenderCborReportAccepted,
DefenderCborReportRejected,
};
/* Table of topic API strings in the same order as the above defenderApi table. */
static const char * const defenderApiTopic[] =
{
DEFENDER_API_JSON_FORMAT,
DEFENDER_API_JSON_FORMAT DEFENDER_API_ACCEPTED_SUFFIX,
DEFENDER_API_JSON_FORMAT DEFENDER_API_REJECTED_SUFFIX,
DEFENDER_API_CBOR_FORMAT,
DEFENDER_API_CBOR_FORMAT DEFENDER_API_ACCEPTED_SUFFIX,
DEFENDER_API_CBOR_FORMAT DEFENDER_API_REJECTED_SUFFIX,
};
/* Table of topic API string lengths in the same order as the above defenderApi table. */
static const uint16_t defenderApiTopicLength[] =
{
DEFENDER_API_LENGTH_JSON_FORMAT,
DEFENDER_API_LENGTH_JSON_FORMAT + DEFENDER_API_LENGTH_ACCEPTED_SUFFIX,
DEFENDER_API_LENGTH_JSON_FORMAT + DEFENDER_API_LENGTH_REJECTED_SUFFIX,
DEFENDER_API_LENGTH_CBOR_FORMAT,
DEFENDER_API_LENGTH_CBOR_FORMAT + DEFENDER_API_LENGTH_ACCEPTED_SUFFIX,
DEFENDER_API_LENGTH_CBOR_FORMAT + DEFENDER_API_LENGTH_REJECTED_SUFFIX,
};
for( i = 0U; i < sizeof( defenderApi ) / sizeof( defenderApi[ 0 ] ); i++ )
{
if( ( remainingTopicLength == defenderApiTopicLength[ i ] ) &&
( strncmp( pRemainingTopic,
defenderApiTopic[ i ],
( size_t ) defenderApiTopicLength[ i ] ) == 0 ) )
{
*pOutApi = defenderApi[ i ];
ret = DefenderSuccess;
break;
}
}
return ret;
}
/*-----------------------------------------------------------*/
DefenderStatus_t Defender_GetTopic( char * pBuffer,
uint16_t bufferLength,
const char * pThingName,
uint16_t thingNameLength,
DefenderTopic_t api,
uint16_t * pOutLength )
{
DefenderStatus_t ret = DefenderSuccess;
uint16_t topicLength = 0U, offset = 0U;
/* The following variables are to address MISRA Rule 7.4 violation of
* passing const char * for const void * param of memcpy. */
const char * pDefenderApiPrefix = DEFENDER_API_PREFIX;
const char * pDefenderApiBridge = DEFENDER_API_BRIDGE;
if( ( pBuffer == NULL ) ||
( pThingName == NULL ) ||
( thingNameLength == 0U ) || ( thingNameLength > DEFENDER_THINGNAME_MAX_LENGTH ) ||
( api <= DefenderInvalidTopic ) || ( api >= DefenderMaxTopic ) ||
( pOutLength == NULL ) )
{
ret = DefenderBadParameter;
LogError( ( "Invalid input parameter. pBuffer: %p, bufferLength: %u, "
"pThingName: %p, thingNameLength: %u, api: %d, pOutLength: %p.",
( const void * ) pBuffer,
( unsigned int ) bufferLength,
( const void * ) pThingName,
( unsigned int ) thingNameLength,
api,
( void * ) pOutLength ) );
}
if( ret == DefenderSuccess )
{
topicLength = getTopicLength( thingNameLength, api );
if( bufferLength < topicLength )
{
ret = DefenderBufferTooSmall;
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( ret == DefenderSuccess )
{
/* At this point, it is certain that we have a large enough buffer to
* write the topic string into. */
/* Write prefix first. */
( void ) memcpy( ( void * ) &( pBuffer[ offset ] ),
( const void * ) pDefenderApiPrefix,
( size_t ) DEFENDER_API_LENGTH_PREFIX );
offset += DEFENDER_API_LENGTH_PREFIX;
/* Write thing name next. */
( void ) memcpy( ( void * ) &( pBuffer[ offset ] ),
( const void * ) pThingName,
( size_t ) thingNameLength );
offset += thingNameLength;
/* Write bridge next. */
( void ) memcpy( ( void * ) &( pBuffer[ offset ] ),
( const void * ) pDefenderApiBridge,
( size_t ) DEFENDER_API_LENGTH_BRIDGE );
offset += DEFENDER_API_LENGTH_BRIDGE;
/* Write report format and suffix. */
writeFormatAndSuffix( &( pBuffer[ offset ] ), api );
*pOutLength = topicLength;
}
return ret;
}
/*-----------------------------------------------------------*/
DefenderStatus_t Defender_MatchTopic( const char * pTopic,
uint16_t topicLength,
DefenderTopic_t * pOutApi,
const char ** ppOutThingName,
uint16_t * pOutThingNameLength )
{
DefenderStatus_t ret = DefenderSuccess;
uint16_t remainingTopicLength = 0U, consumedTopicLength = 0U, thingNameLength = 0U;
if( ( pTopic == NULL ) || ( pOutApi == NULL ) )
{
ret = DefenderBadParameter;
LogError( ( "Invalid input parameter. pTopic: %p, pOutApi: %p.",
( const void * ) pTopic,
( void * ) pOutApi ) );
}
/* Nothing is consumed yet. */
remainingTopicLength = topicLength;
consumedTopicLength = 0;
if( ret == DefenderSuccess )
{
ret = matchPrefix( &( pTopic[ consumedTopicLength ] ),
remainingTopicLength );
if( ret == DefenderSuccess )
{
remainingTopicLength -= DEFENDER_API_LENGTH_PREFIX;
consumedTopicLength += DEFENDER_API_LENGTH_PREFIX;
}
else
{
LogDebug( ( "The topic does not contain defender prefix $aws/things/." ) );
}
}
if( ret == DefenderSuccess )
{
ret = extractThingNameLength( &( pTopic[ consumedTopicLength ] ),
remainingTopicLength,
&( thingNameLength ) );
if( ret == DefenderSuccess )
{
remainingTopicLength -= thingNameLength;
consumedTopicLength += thingNameLength;
}
else
{
LogDebug( ( "The topic does not contain a valid thing name." ) );
}
}
if( ret == DefenderSuccess )
{
ret = matchBridge( &( pTopic[ consumedTopicLength ] ),
remainingTopicLength );
if( ret == DefenderSuccess )
{
remainingTopicLength -= DEFENDER_API_LENGTH_BRIDGE;
consumedTopicLength += DEFENDER_API_LENGTH_BRIDGE;
}
else
{
LogDebug( ( "The topic does not contain the defender bridge /defender/metrics/." ) );
}
}
if( ret == DefenderSuccess )
{
ret = matchApi( &( pTopic[ consumedTopicLength ] ),
remainingTopicLength,
pOutApi );
if( ret != DefenderSuccess )
{
LogDebug( ( "The topic does not contain valid report format or suffix "
" needed to be a valid defender topic." ) );
}
}
/* Update the out parameters for thing name and thing length location, if we
* successfully matched the topic. */
if( ret == DefenderSuccess )
{
if( ppOutThingName != NULL )
{
/* Thing name comes after the defender prefix. */
*ppOutThingName = &( pTopic[ DEFENDER_API_LENGTH_PREFIX ] );
}
if( pOutThingNameLength != NULL )
{
*pOutThingNameLength = thingNameLength;
}
}
/* Update the output parameter for API if the topic did not match. In case
* of a match, it is updated in the matchApi function. */
if( ret == DefenderNoMatch )
{
*pOutApi = DefenderInvalidTopic;
}
return ret;
}
/*-----------------------------------------------------------*/

View File

@ -0,0 +1,805 @@
/*
* AWS IoT Device Defender Client v1.3.0
* Copyright (C) 2020 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 defender.h
* @brief Interface for the AWS IoT Device Defender Client Library.
*/
#ifndef DEFENDER_H_
#define DEFENDER_H_
/* Standard includes. */
#include <stdint.h>
/* *INDENT-OFF* */
#ifdef __cplusplus
extern "C" {
#endif
/* *INDENT-ON* */
/* DEFENDER_DO_NOT_USE_CUSTOM_CONFIG allows building the Device Defender library
* without a config file. If a config file is provided, DEFENDER_DO_NOT_USE_CUSTOM_CONFIG
* macro must not be defined.
*/
#ifndef DEFENDER_DO_NOT_USE_CUSTOM_CONFIG
#include "defender_config.h"
#endif
/* Default config values. */
#include "defender_config_defaults.h"
/**
* @ingroup defender_enum_types
* @brief Return codes from defender APIs.
*/
typedef enum
{
DefenderError = 0, /**< Generic Error. */
DefenderSuccess, /**< Success. */
DefenderNoMatch, /**< The provided topic does not match any defender topic. */
DefenderBadParameter, /**< Invalid parameters were passed. */
DefenderBufferTooSmall /**< The output buffer is too small. */
} DefenderStatus_t;
/**
* @ingroup defender_enum_types
* @brief Topic values for subscription requests.
*/
typedef enum
{
DefenderInvalidTopic = -1, /**< Invalid topic. */
DefenderJsonReportPublish, /**< Topic for publishing a JSON report. */
DefenderJsonReportAccepted, /**< Topic for getting a JSON report accepted response. */
DefenderJsonReportRejected, /**< Topic for getting a JSON report rejected response. */
DefenderCborReportPublish, /**< Topic for publishing a CBOR report. */
DefenderCborReportAccepted, /**< Topic for getting a CBOR report accepted response. */
DefenderCborReportRejected, /**< Topic for getting a CBOR report rejected response. */
DefenderMaxTopic
} DefenderTopic_t;
/*-----------------------------------------------------------*/
/**
* @brief Helper macro to calculate the length of a string literal.
*/
#define STRING_LITERAL_LENGTH( literal ) ( ( uint16_t ) ( sizeof( literal ) - 1U ) )
/*-----------------------------------------------------------*/
/**
* @ingroup defender_constants
* @brief Maximum length of a thing's name as permitted by AWS IoT Core.
*/
#define DEFENDER_THINGNAME_MAX_LENGTH 128U
/**
* @ingroup defender_constants
* @brief Minimum period between 2 consecutive defender reports sent by the
* device.
*
* This is as per AWS IoT Device Defender Service reference.
*/
#define DEFENDER_REPORT_MIN_PERIOD_SECONDS 300
/*-----------------------------------------------------------*/
/*
* A Defender topic has the following format:
*
* <Prefix><Thing Name><Bridge><Report Format><Suffix>
*
* Where:
* <Prefix> = $aws/things/
* <Thing Name> = Name of the thing.
* <Bridge> = /defender/metrics/
* <Report Format> = json or cbor
* <Suffix> = /accepted or /rejected or empty
*
* Examples:
* $aws/things/THING_NAME/defender/metrics/json
* $aws/things/THING_NAME/defender/metrics/json/accepted
* $aws/things/THING_NAME/defender/metrics/json/rejected
* $aws/things/THING_NAME/defender/metrics/cbor
* $aws/things/THING_NAME/defender/metrics/cbor/accepted
* $aws/things/THING_NAME/defender/metrics/json/rejected
*/
/**
* @cond DOXYGEN_IGNORE
* Doxygen should ignore these macros as they are private.
*/
#define DEFENDER_API_PREFIX "$aws/things/"
#define DEFENDER_API_LENGTH_PREFIX STRING_LITERAL_LENGTH( DEFENDER_API_PREFIX )
#define DEFENDER_API_BRIDGE "/defender/metrics/"
#define DEFENDER_API_LENGTH_BRIDGE STRING_LITERAL_LENGTH( DEFENDER_API_BRIDGE )
#define DEFENDER_API_JSON_FORMAT "json"
#define DEFENDER_API_LENGTH_JSON_FORMAT STRING_LITERAL_LENGTH( DEFENDER_API_JSON_FORMAT )
#define DEFENDER_API_CBOR_FORMAT "cbor"
#define DEFENDER_API_LENGTH_CBOR_FORMAT STRING_LITERAL_LENGTH( DEFENDER_API_CBOR_FORMAT )
#define DEFENDER_API_ACCEPTED_SUFFIX "/accepted"
#define DEFENDER_API_LENGTH_ACCEPTED_SUFFIX STRING_LITERAL_LENGTH( DEFENDER_API_ACCEPTED_SUFFIX )
#define DEFENDER_API_REJECTED_SUFFIX "/rejected"
#define DEFENDER_API_LENGTH_REJECTED_SUFFIX STRING_LITERAL_LENGTH( DEFENDER_API_REJECTED_SUFFIX )
#define DEFENDER_API_NULL_SUFFIX ""
#define DEFENDER_API_LENGTH_NULL_SUFFIX ( 0U )
/** @endcond */
/*-----------------------------------------------------------*/
/**
* @cond DOXYGEN_IGNORE
* Doxygen should ignore this macro as it is private.
*/
/* Defender API topic lengths. */
#define DEFENDER_API_COMMON_LENGTH( thingNameLength, reportFormatLength, suffixLength ) \
( DEFENDER_API_LENGTH_PREFIX + \
( thingNameLength ) + \
DEFENDER_API_LENGTH_BRIDGE + \
( reportFormatLength ) + \
( suffixLength ) )
/** @endcond */
/**
* @brief Length of the topic string for publishing a JSON report.
*
* @param[in] thingNameLength Length of the thing name as registered with AWS IoT Core.
*/
#define DEFENDER_API_LENGTH_JSON_PUBLISH( thingNameLength ) \
DEFENDER_API_COMMON_LENGTH( thingNameLength, \
DEFENDER_API_LENGTH_JSON_FORMAT, \
DEFENDER_API_LENGTH_NULL_SUFFIX )
/**
* @brief Length of the topic string for getting a JSON report accepted response.
*
* @param[in] thingNameLength Length of the thing name as registered with AWS IoT Core.
*/
#define DEFENDER_API_LENGTH_JSON_ACCEPTED( thingNameLength ) \
DEFENDER_API_COMMON_LENGTH( thingNameLength, \
DEFENDER_API_LENGTH_JSON_FORMAT, \
DEFENDER_API_LENGTH_ACCEPTED_SUFFIX )
/**
* @brief Length of the topic string for getting a JSON report rejected response.
*
* @param[in] thingNameLength Length of the thing name as registered with AWS IoT Core.
*/
#define DEFENDER_API_LENGTH_JSON_REJECTED( thingNameLength ) \
DEFENDER_API_COMMON_LENGTH( thingNameLength, \
DEFENDER_API_LENGTH_JSON_FORMAT, \
DEFENDER_API_LENGTH_REJECTED_SUFFIX )
/**
* @brief Length of the topic string for publishing a CBOR report.
*
* @param[in] thingNameLength Length of the thing name as registered with AWS IoT Core.
*/
#define DEFENDER_API_LENGTH_CBOR_PUBLISH( thingNameLength ) \
DEFENDER_API_COMMON_LENGTH( thingNameLength, \
DEFENDER_API_LENGTH_CBOR_FORMAT, \
DEFENDER_API_LENGTH_NULL_SUFFIX )
/**
* @brief Length of the topic string for getting a CBOR report accepted response.
*
* @param[in] thingNameLength Length of the thing name. as registered with AWS IoT Core.
*/
#define DEFENDER_API_LENGTH_CBOR_ACCEPTED( thingNameLength ) \
DEFENDER_API_COMMON_LENGTH( thingNameLength, \
DEFENDER_API_LENGTH_CBOR_FORMAT, \
DEFENDER_API_LENGTH_ACCEPTED_SUFFIX )
/**
* @brief Length of the topic string for getting a CBOR report rejected response.
*
* @param[in] thingNameLength Length of the thing name as registered with AWS IoT Core.
*/
#define DEFENDER_API_LENGTH_CBOR_REJECTED( thingNameLength ) \
DEFENDER_API_COMMON_LENGTH( thingNameLength, \
DEFENDER_API_LENGTH_CBOR_FORMAT, \
DEFENDER_API_LENGTH_REJECTED_SUFFIX )
/**
* @brief Maximum length of the topic string for any defender operation.
*
* @param[in] thingNameLength Length of the thing name as registered with AWS IoT Core.
*/
#define DEFENDER_API_MAX_LENGTH( thingNameLength ) \
DEFENDER_API_LENGTH_CBOR_ACCEPTED( thingNameLength )
/*-----------------------------------------------------------*/
/**
* @cond DOXYGEN_IGNORE
* Doxygen should ignore this macro as it is private.
*/
/* Defender API topics. */
#define DEFENDER_API_COMMON( thingName, reportFormat, suffix ) \
( DEFENDER_API_PREFIX \
thingName \
DEFENDER_API_BRIDGE \
reportFormat \
suffix )
/** @endcond */
/**
* @brief Topic string for publishing a JSON report.
*
* This macro should be used when the thing name is known at the compile time.
* If the thing name is not known at compile time, the #Defender_GetTopic API
* should be used instead.
*
* @param thingName The thing name as registered with AWS IoT Core.
*/
#define DEFENDER_API_JSON_PUBLISH( thingName ) \
DEFENDER_API_COMMON( thingName, \
DEFENDER_API_JSON_FORMAT, \
DEFENDER_API_NULL_SUFFIX )
/**
* @brief Topic string for getting a JSON report accepted response.
*
* This macro should be used when the thing name is known at the compile time.
* If the thing name is not known at compile time, the #Defender_GetTopic API
* should be used instead.
*
* @param thingName The thing name as registered with AWS IoT Core.
*/
#define DEFENDER_API_JSON_ACCEPTED( thingName ) \
DEFENDER_API_COMMON( thingName, \
DEFENDER_API_JSON_FORMAT, \
DEFENDER_API_ACCEPTED_SUFFIX )
/**
* @brief Topic string for getting a JSON report rejected response.
*
* This macro should be used when the thing name is known at the compile time.
* If the thing name is not known at compile time, the #Defender_GetTopic API
* should be used instead.
*
* @param thingName The thing name as registered with AWS IoT Core.
*/
#define DEFENDER_API_JSON_REJECTED( thingName ) \
DEFENDER_API_COMMON( thingName, \
DEFENDER_API_JSON_FORMAT, \
DEFENDER_API_REJECTED_SUFFIX )
/**
* @brief Topic string for publishing a CBOR report.
*
* This macro should be used when the thing name is known at the compile time.
* If the thing name is not known at compile time, the #Defender_GetTopic API
* should be used instead.
*
* @param thingName The thing name as registered with AWS IoT Core.
*/
#define DEFENDER_API_CBOR_PUBLISH( thingName ) \
DEFENDER_API_COMMON( thingName, \
DEFENDER_API_CBOR_FORMAT, \
DEFENDER_API_NULL_SUFFIX )
/**
* @brief Topic string for getting a CBOR report accepted response.
*
* This macro should be used when the thing name is known at the compile time.
* If the thing name is not known at compile time, the #Defender_GetTopic API
* should be used instead.
*
* @param thingName The thing name as registered with AWS IoT Core.
*/
#define DEFENDER_API_CBOR_ACCEPTED( thingName ) \
DEFENDER_API_COMMON( thingName, \
DEFENDER_API_CBOR_FORMAT, \
DEFENDER_API_ACCEPTED_SUFFIX )
/**
* @brief Topic string for getting a CBOR report rejected response.
*
* This macro should be used when the thing name is known at the compile time.
* If the thing name is not known at compile time, the #Defender_GetTopic API
* should be used instead.
*
* @param thingName The thing name as registered with AWS IoT Core.
*/
#define DEFENDER_API_CBOR_REJECTED( thingName ) \
DEFENDER_API_COMMON( thingName, \
DEFENDER_API_CBOR_FORMAT, \
DEFENDER_API_REJECTED_SUFFIX )
/*-----------------------------------------------------------*/
/**
* @cond DOXYGEN_IGNORE
* Doxygen should ignore this macro as it is private.
*/
/* Keys used in defender report. */
#if ( defined( DEFENDER_USE_LONG_KEYS ) && ( DEFENDER_USE_LONG_KEYS == 1 ) )
#define DEFENDER_REPORT_SELECT_KEY( longKey, shortKey ) longKey
#else
#define DEFENDER_REPORT_SELECT_KEY( longKey, shortKey ) shortKey
#endif
/** @endcond */
/**
* @ingroup defender_constants
* @brief "header" key in the defender report.
*/
#define DEFENDER_REPORT_HEADER_KEY DEFENDER_REPORT_SELECT_KEY( "header", "hed" )
/**
* @ingroup defender_constants
* @brief Length of the "header" key in the defender report.
*/
#define DEFENDER_REPORT_LENGTH_HEADER_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_HEADER_KEY )
/**
* @ingroup defender_constants
* @brief "metrics" key in the defender report.
*/
#define DEFENDER_REPORT_METRICS_KEY DEFENDER_REPORT_SELECT_KEY( "metrics", "met" )
/**
* @ingroup defender_constants
* @brief Length of the "metrics" key in the defender report.
*/
#define DEFENDER_REPORT_LENGTH_METRICS_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_METRICS_KEY )
/**
* @ingroup defender_constants
* @brief "report_id" key in the defender report.
*/
#define DEFENDER_REPORT_ID_KEY DEFENDER_REPORT_SELECT_KEY( "report_id", "rid" )
/**
* @ingroup defender_constants
* @brief Length of the "report_id" key in the defender report.
*/
#define DEFENDER_REPORT_LENGTH_ID_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_ID_KEY )
/**
* @ingroup defender_constants
* @brief "version" key in the defender report.
*/
#define DEFENDER_REPORT_VERSION_KEY DEFENDER_REPORT_SELECT_KEY( "version", "v" )
/**
* @ingroup defender_constants
* @brief Length of the "version" key in the defender report.
*/
#define DEFENDER_REPORT_LENGTH_VERSION_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_VERSION_KEY )
/**
* @ingroup defender_constants
* @brief "tcp_connections" key in the defender report.
*/
#define DEFENDER_REPORT_TCP_CONNECTIONS_KEY DEFENDER_REPORT_SELECT_KEY( "tcp_connections", "tc" )
/**
* @ingroup defender_constants
* @brief Length of the "tcp_connections" key in the defender report.
*/
#define DEFENDER_REPORT_LENGTH_TCP_CONNECTIONS_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_TCP_CONNECTIONS_KEY )
/**
* @ingroup defender_constants
* @brief "established_connections" key in the defender report.
*/
#define DEFENDER_REPORT_ESTABLISHED_CONNECTIONS_KEY DEFENDER_REPORT_SELECT_KEY( "established_connections", "ec" )
/**
* @ingroup defender_constants
* @brief Length of the "established_connections" key in the defender report.
*/
#define DEFENDER_REPORT_LENGTH_ESTABLISHED_CONNECTIONS_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_ESTABLISHED_CONNECTIONS_KEY )
/**
* @ingroup defender_constants
* @brief "connections" key in the defender report.
*/
#define DEFENDER_REPORT_CONNECTIONS_KEY DEFENDER_REPORT_SELECT_KEY( "connections", "cs" )
/**
* @ingroup defender_constants
* @brief Length of the "connections" key in the defender report.
*/
#define DEFENDER_REPORT_LENGTH_CONNECTIONS_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_CONNECTIONS_KEY )
/**
* @ingroup defender_constants
* @brief "remote_addr" key in the defender report.
*/
#define DEFENDER_REPORT_REMOTE_ADDR_KEY DEFENDER_REPORT_SELECT_KEY( "remote_addr", "rad" )
/**
* @ingroup defender_constants
* @brief Length of the "remote_addr" key in the defender report.
*/
#define DEFENDER_REPORT_LENGTH_REMOTE_ADDR_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_REMOTE_ADDR_KEY )
/**
* @ingroup defender_constants
* @brief "local_port" key in the defender report.
*/
#define DEFENDER_REPORT_LOCAL_PORT_KEY DEFENDER_REPORT_SELECT_KEY( "local_port", "lp" )
/**
* @ingroup defender_constants
* @brief Length of the "local_port" key in the defender report.
*/
#define DEFENDER_REPORT_LENGTH_LOCAL_PORT_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_LOCAL_PORT_KEY )
/**
* @ingroup defender_constants
* @brief "local_interface" key in the defender report.
*/
#define DEFENDER_REPORT_LOCAL_INTERFACE_KEY DEFENDER_REPORT_SELECT_KEY( "local_interface", "li" )
/**
* @ingroup defender_constants
* @brief Length of the "local_interface" key in the defender report.
*/
#define DEFENDER_REPORT_LENGTH_LOCAL_INTERFACE_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_LOCAL_INTERFACE_KEY )
/**
* @ingroup defender_constants
* @brief "total" key in the defender report.
*/
#define DEFENDER_REPORT_TOTAL_KEY DEFENDER_REPORT_SELECT_KEY( "total", "t" )
/**
* @ingroup defender_constants
* @brief Length of the "total" key in the defender report.
*/
#define DEFENDER_REPORT_LENGTH_TOTAL_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_TOTAL_KEY )
/**
* @ingroup defender_constants
* @brief "listening_tcp_ports" key in the defender report.
*/
#define DEFENDER_REPORT_TCP_LISTENING_PORTS_KEY DEFENDER_REPORT_SELECT_KEY( "listening_tcp_ports", "tp" )
/**
* @ingroup defender_constants
* @brief Length of the "listening_tcp_ports" key in the defender report.
*/
#define DEFENDER_REPORT_LENGTH_TCP_LISTENING_PORTS_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_TCP_LISTENING_PORTS_KEY )
/**
* @ingroup defender_constants
* @brief "ports" key in the defender report.
*/
#define DEFENDER_REPORT_PORTS_KEY DEFENDER_REPORT_SELECT_KEY( "ports", "pts" )
/**
* @ingroup defender_constants
* @brief Length of the "ports" key in the defender report.
*/
#define DEFENDER_REPORT_LENGTH_PORTS_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_PORTS_KEY )
/**
* @ingroup defender_constants
* @brief "port" key in the defender report.
*/
#define DEFENDER_REPORT_PORT_KEY DEFENDER_REPORT_SELECT_KEY( "port", "pt" )
/**
* @ingroup defender_constants
* @brief Length of the "port" key in the defender report.
*/
#define DEFENDER_REPORT_LENGTH_PORT_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_PORT_KEY )
/**
* @ingroup defender_constants
* @brief "interface" key in the defender report.
*/
#define DEFENDER_REPORT_INTERFACE_KEY DEFENDER_REPORT_SELECT_KEY( "interface", "if" )
/**
* @ingroup defender_constants
* @brief Length of the "interface" key in the defender report.
*/
#define DEFENDER_REPORT_LENGTH_INTERFACE_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_INTERFACE_KEY )
/**
* @ingroup defender_constants
* @brief "listening_udp_ports" key in the defender report.
*/
#define DEFENDER_REPORT_UDP_LISTENING_PORTS_KEY DEFENDER_REPORT_SELECT_KEY( "listening_udp_ports", "up" )
/**
* @ingroup defender_constants
* @brief Length of the "listening_udp_ports" key in the defender report.
*/
#define DEFENDER_REPORT_LENGTH_UDP_LISTENING_PORTS_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_UDP_LISTENING_PORTS_KEY )
/**
* @ingroup defender_constants
* @brief "network_stats" key in the defender report.
*/
#define DEFENDER_REPORT_NETWORK_STATS_KEY DEFENDER_REPORT_SELECT_KEY( "network_stats", "ns" )
/**
* @ingroup defender_constants
* @brief Length of the "network_stats" key in the defender report.
*/
#define DEFENDER_REPORT_LENGTH_NETWORK_STATS_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_NETWORK_STATS_KEY )
/**
* @ingroup defender_constants
* @brief "bytes_in" key in the defender report.
*/
#define DEFENDER_REPORT_BYTES_IN_KEY DEFENDER_REPORT_SELECT_KEY( "bytes_in", "bi" )
/**
* @ingroup defender_constants
* @brief Length of the "bytes_in" key in the defender report.
*/
#define DEFENDER_REPORT_LENGTH_BYTES_IN_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_BYTES_IN_KEY )
/**
* @ingroup defender_constants
* @brief "bytes_out" key in the defender report.
*/
#define DEFENDER_REPORT_BYTES_OUT_KEY DEFENDER_REPORT_SELECT_KEY( "bytes_out", "bo" )
/**
* @ingroup defender_constants
* @brief Length of the "bytes_out" key in the defender report.
*/
#define DEFENDER_REPORT_LENGTH_BYTES_OUT_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_BYTES_OUT_KEY )
/**
* @ingroup defender_constants
* @brief "packets_in" key in the defender report.
*/
#define DEFENDER_REPORT_PKTS_IN_KEY DEFENDER_REPORT_SELECT_KEY( "packets_in", "pi" )
/**
* @ingroup defender_constants
* @brief Length of the "packets_in" key in the defender report.
*/
#define DEFENDER_REPORT_LENGTH_PKTS_IN_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_PKTS_IN_KEY )
/**
* @ingroup defender_constants
* @brief "packets_out" key in the defender report.
*/
#define DEFENDER_REPORT_PKTS_OUT_KEY DEFENDER_REPORT_SELECT_KEY( "packets_out", "po" )
/**
* @ingroup defender_constants
* @brief Length of the "packets_out" key in the defender report.
*/
#define DEFENDER_REPORT_LENGTH_PKS_OUT_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_LENGTH_PKS_OUT_KEY )
/**
* @ingroup defender_constants
* @brief "custom_metrics" key in the defender report.
*/
#define DEFENDER_REPORT_CUSTOM_METRICS_KEY DEFENDER_REPORT_SELECT_KEY( "custom_metrics", "cmet" )
/**
* @ingroup defender_constants
* @brief Length of the "custom_metrics" key in the defender report.
*/
#define DEFENDER_REPORT_LENGTH_CUSTOM_METRICS_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_LENGTH_CUSTOM_METRICS_KEY )
/**
* @ingroup defender_constants
* @brief "number" key in the defender report.
*/
#define DEFENDER_REPORT_NUMBER_KEY "number"
/**
* @ingroup defender_constants
* @brief Length of the "number" key in the defender report.
*/
#define DEFENDER_REPORT_LENGTH_NUMBER_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_LENGTH_NUMBER_KEY )
/**
* @ingroup defender_constants
* @brief "number_list" key in the defender report.
*/
#define DEFENDER_REPORT_NUMBER_LIST_KEY "number_list"
/**
* @ingroup defender_constants
* @brief Length of the "number_list" key in the defender report.
*/
#define DEFENDER_REPORT_LENGTH_NUMBER_LIST_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_LENGTH_NUMBER_LIST_KEY )
/**
* @ingroup defender_constants
* @brief "string_list" key in the defender report.
*/
#define DEFENDER_REPORT_STRING_LIST_KEY "string_list"
/**
* @ingroup defender_constants
* @brief Length of the "string_list" key in the defender report.
*/
#define DEFENDER_REPORT_LENGTH_STRING_LIST_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_LENGTH_STRING_LIST_KEY )
/**
* @ingroup defender_constants
* @brief "ip_list" key in the defender report.
*/
#define DEFENDER_REPORT_IP_LIST_KEY "ip_list"
/**
* @ingroup defender_constants
* @brief Length of the "ip_list" key in the defender report.
*/
#define DEFENDER_REPORT_LENGTH_IP_LIST_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_LENGTH_IP_LIST_KEY )
/*-----------------------------------------------------------*/
/**
* @brief Populate the topic string for a Device Defender operation.
*
* @param[in] pBuffer The buffer to write the topic string into.
* @param[in] bufferLength The length of the buffer.
* @param[in] pThingName The device's thingName as registered with AWS IoT.
* @param[in] thingNameLength The length of the thing name.
* @param[in] api The desired Device Defender API.
* @param[out] pOutLength The length of the topic string written to the buffer.
*
* @return #DefenderSuccess if the topic string is written to the buffer;
* #DefenderBadParameter if invalid parameters are passed;
* #DefenderBufferTooSmall if the buffer cannot hold the full topic string.
*
* <b>Example</b>
* @code{c}
*
* // The following example shows how to use the Defender_GetTopic API to
* // generate a topic string for getting a JSON report accepted response.
*
* #define TOPIC_BUFFER_LENGTH ( 256U )
*
* // Every device should have a unique thing name registered with AWS IoT Core.
* // This example assumes that the device has a unique serial number which is
* // registered as the thing name with AWS IoT Core.
* const char * pThingName = GetDeviceSerialNumber();
* uint16_t thingNameLength = ( uint16_t )strlen( pThingname );
* char topicBuffer[ TOPIC_BUFFER_LENGTH ] = { 0 };
* uint16_t topicLength = 0;
* DefenderStatus_t status = DefenderSuccess;
*
* status = Defender_GetTopic( &( topicBuffer[ 0 ] ),
* TOPIC_BUFFER_LENGTH,
* pThingName,
* thingNameLength,
* DefenderJsonReportAccepted,
* &( topicLength ) );
*
* if( status == DefenderSuccess )
* {
* // The buffer topicBuffer contains the topic string of length
* // topicLength for getting a JSON report accepted response. Subscribe
* // to this topic using an MQTT client of your choice.
* }
* @endcode
*/
/* @[declare_defender_gettopic] */
DefenderStatus_t Defender_GetTopic( char * pBuffer,
uint16_t bufferLength,
const char * pThingName,
uint16_t thingNameLength,
DefenderTopic_t api,
uint16_t * pOutLength );
/* @[declare_defender_gettopic] */
/*-----------------------------------------------------------*/
/**
* @brief Check if the given topic is one of the Device Defender topics.
*
* The function outputs which API the topic is for. It also optionally outputs
* the starting location and length of the thing name in the given topic.
*
* @param[in] pTopic The topic string to check.
* @param[in] topicLength The length of the topic string.
* @param[out] pOutApi The defender topic API value.
* @param[out] ppOutThingName Optional parameter to output the beginning of the
* thing name in the topic string. Pass NULL if not needed.
* @param[out] pOutThingNameLength Optional parameter to output the length of
* the thing name in the topic string. Pass NULL if not needed.
*
* @return #DefenderSuccess if the topic is one of the defender topics;
* #DefenderBadParameter if invalid parameters are passed;
* #DefenderNoMatch if the topic is NOT one of the defender topics (parameter
* pOutApi gets #DefenderInvalidTopic).
*
* <b>Example</b>
* @code{c}
*
* // The following example shows how to use the Defender_MatchTopic API to
* // check if an incoming MQTT publish message is a Device Defender message.
*
* DefenderTopic_t api;
* DefenderStatus_t status = DefenderSuccess;
*
* // 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 client used. We pass the last two argument as NULL as we are not
* // interested in the thing name in the topic string.
* status = Defender_MatchTopic( pTopic,
* topicLength,
* &( api ),
* NULL,
* NULL );
*
* if( status == DefenderSuccess )
* {
* if( api == DefenderJsonReportAccepted )
* {
* // The published JSON report was accepted by the AWS IoT Device
* // Defender service. You can parse the response using your choice
* // of JSON parser and ensure that the report Id is same as was sent
* // in the defender report.
* }
* else if( api == DefenderJsonReportRejected )
* {
* // The published JSON report was rejected by the AWS IoT Device
* // Defender service.
* }
* else
* {
* // Unexpected response.
* }
* }
* @endcode
*/
/* @[declare_defender_matchtopic] */
DefenderStatus_t Defender_MatchTopic( const char * pTopic,
uint16_t topicLength,
DefenderTopic_t * pOutApi,
const char ** ppOutThingName,
uint16_t * pOutThingNameLength );
/* @[declare_defender_matchtopic] */
/*-----------------------------------------------------------*/
/* *INDENT-OFF* */
#ifdef __cplusplus
}
#endif
/* *INDENT-ON* */
#endif /* DEFENDER_H_ */

View File

@ -0,0 +1,181 @@
/*
* AWS IoT Device Defender Client v1.3.0
* Copyright (C) 2020 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 defender_config_defaults.h
* @brief Default config values for the AWS IoT Device Defender Client Library.
*/
#ifndef DEFENDER_CONFIG_DEFAULTS_H_
#define DEFENDER_CONFIG_DEFAULTS_H_
/* The macro definition for DEFENDER_DO_NOT_USE_CUSTOM_CONFIG is for Doxygen
* documentation only. */
/**
* @brief Define this macro to build the AWS IoT Device Defender Client Library
* without the custom config file defender_config.h.
*
* Without the custom config, the the AWS IoT Device Defender Client Library
* builds with default values of config macros defined in the
* defender_config_defaults.h file.
*
* If a custom config file is provided, then DEFENDER_DO_NOT_USE_CUSTOM_CONFIG
* must not be defined.
*
* <b>Default value</b>: DEFENDER_DO_NOT_USE_CUSTOM_CONFIG is <b>not</b> defined
* by default and the library expects a defender_config.h file.
*/
#ifdef DOXYGEN
#define DEFENDER_DO_NOT_USE_CUSTOM_CONFIG
#endif
/**
* @brief Set it to 1 to enable use of long key names in the defender report.
*
* AWS IoT Device Defender Service supports both long and short names for keys
* in the report sent by a device. For example,
*
* A device defender report using long key names:
* @code{c}
* {
* "header": {
* "report_id": 1530304554,
* "version": "1.0"
* },
* "metrics": {
* "network_stats": {
* "bytes_in": 29358693495,
* "bytes_out": 26485035,
* "packets_in": 10013573555,
* "packets_out": 11382615
* }
* }
* }
* @endcode
*
* An equivalent report using short key names:
* @code{c}
* {
* "hed": {
* "rid": 1530304554,
* "v": "1.0"
* },
* "met": {
* "ns": {
* "bi": 29358693495,
* "bo": 26485035,
* "pi": 10013573555,
* "po": 11382615
* }
* }
* }
* @endcode
*
* <b>Default value</b>: 0 as short key names are preferred option for resource
* constrained devices because they result in smaller report size. If you want
* to use long key names instead, set DEFENDER_USE_LONG_KEYS to 1 in the
* defender_config.h file.
*/
#ifndef DEFENDER_USE_LONG_KEYS
#define DEFENDER_USE_LONG_KEYS 0
#endif
/**
* @brief Macro used in the Device Defender client 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 Device Defender client 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 defender_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 Device Defender client library on compilation.
*/
#ifndef LogError
#define LogError( message )
#endif
/**
* @brief Macro used in the Device Defender client 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 Device Defender client 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 defender_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 Device Defender client library on compilation.
*/
#ifndef LogWarn
#define LogWarn( message )
#endif
/**
* @brief Macro used in the Device Defender client 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 Device Defender client 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 defender_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 Device Defender client library on compilation.
*/
#ifndef LogInfo
#define LogInfo( message )
#endif
/**
* @brief Macro used in the Device Defender client 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 Device Defender client 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 defender_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 Device Defender client library on compilation.
*/
#ifndef LogDebug
#define LogDebug( message )
#endif
#endif /* DEFENDER_CONFIG_DEFAULTS_H_ */