46#ifndef DEFENDER_DO_NOT_USE_CUSTOM_CONFIG
47 #include "defender_config.h"
87#define STRING_LITERAL_LENGTH( literal ) ( ( uint16_t ) ( sizeof( literal ) - 1U ) )
95#define DEFENDER_THINGNAME_MAX_LENGTH 128U
104#define DEFENDER_REPORT_MIN_PERIOD_SECONDS 300
134#define DEFENDER_API_PREFIX "$aws/things/"
135#define DEFENDER_API_LENGTH_PREFIX STRING_LITERAL_LENGTH( DEFENDER_API_PREFIX )
137#define DEFENDER_API_BRIDGE "/defender/metrics/"
138#define DEFENDER_API_LENGTH_BRIDGE STRING_LITERAL_LENGTH( DEFENDER_API_BRIDGE )
140#define DEFENDER_API_JSON_FORMAT "json"
141#define DEFENDER_API_LENGTH_JSON_FORMAT STRING_LITERAL_LENGTH( DEFENDER_API_JSON_FORMAT )
143#define DEFENDER_API_CBOR_FORMAT "cbor"
144#define DEFENDER_API_LENGTH_CBOR_FORMAT STRING_LITERAL_LENGTH( DEFENDER_API_CBOR_FORMAT )
146#define DEFENDER_API_ACCEPTED_SUFFIX "/accepted"
147#define DEFENDER_API_LENGTH_ACCEPTED_SUFFIX STRING_LITERAL_LENGTH( DEFENDER_API_ACCEPTED_SUFFIX )
149#define DEFENDER_API_REJECTED_SUFFIX "/rejected"
150#define DEFENDER_API_LENGTH_REJECTED_SUFFIX STRING_LITERAL_LENGTH( DEFENDER_API_REJECTED_SUFFIX )
152#define DEFENDER_API_NULL_SUFFIX ""
153#define DEFENDER_API_LENGTH_NULL_SUFFIX ( 0U )
165#define DEFENDER_API_COMMON_LENGTH( thingNameLength, reportFormatLength, suffixLength ) \
166 ( DEFENDER_API_LENGTH_PREFIX + \
167 ( thingNameLength ) + \
168 DEFENDER_API_LENGTH_BRIDGE + \
169 ( reportFormatLength ) + \
179#define DEFENDER_API_LENGTH_JSON_PUBLISH( thingNameLength ) \
180 DEFENDER_API_COMMON_LENGTH( thingNameLength, \
181 DEFENDER_API_LENGTH_JSON_FORMAT, \
182 DEFENDER_API_LENGTH_NULL_SUFFIX )
189#define DEFENDER_API_LENGTH_JSON_ACCEPTED( thingNameLength ) \
190 DEFENDER_API_COMMON_LENGTH( thingNameLength, \
191 DEFENDER_API_LENGTH_JSON_FORMAT, \
192 DEFENDER_API_LENGTH_ACCEPTED_SUFFIX )
199#define DEFENDER_API_LENGTH_JSON_REJECTED( thingNameLength ) \
200 DEFENDER_API_COMMON_LENGTH( thingNameLength, \
201 DEFENDER_API_LENGTH_JSON_FORMAT, \
202 DEFENDER_API_LENGTH_REJECTED_SUFFIX )
209#define DEFENDER_API_LENGTH_CBOR_PUBLISH( thingNameLength ) \
210 DEFENDER_API_COMMON_LENGTH( thingNameLength, \
211 DEFENDER_API_LENGTH_CBOR_FORMAT, \
212 DEFENDER_API_LENGTH_NULL_SUFFIX )
219#define DEFENDER_API_LENGTH_CBOR_ACCEPTED( thingNameLength ) \
220 DEFENDER_API_COMMON_LENGTH( thingNameLength, \
221 DEFENDER_API_LENGTH_CBOR_FORMAT, \
222 DEFENDER_API_LENGTH_ACCEPTED_SUFFIX )
229#define DEFENDER_API_LENGTH_CBOR_REJECTED( thingNameLength ) \
230 DEFENDER_API_COMMON_LENGTH( thingNameLength, \
231 DEFENDER_API_LENGTH_CBOR_FORMAT, \
232 DEFENDER_API_LENGTH_REJECTED_SUFFIX )
239#define DEFENDER_API_MAX_LENGTH( thingNameLength ) \
240 DEFENDER_API_LENGTH_CBOR_ACCEPTED( thingNameLength )
250#define DEFENDER_API_COMMON( thingName, reportFormat, suffix ) \
251 ( DEFENDER_API_PREFIX \
253 DEFENDER_API_BRIDGE \
268#define DEFENDER_API_JSON_PUBLISH( thingName ) \
269 DEFENDER_API_COMMON( thingName, \
270 DEFENDER_API_JSON_FORMAT, \
271 DEFENDER_API_NULL_SUFFIX )
282#define DEFENDER_API_JSON_ACCEPTED( thingName ) \
283 DEFENDER_API_COMMON( thingName, \
284 DEFENDER_API_JSON_FORMAT, \
285 DEFENDER_API_ACCEPTED_SUFFIX )
296#define DEFENDER_API_JSON_REJECTED( thingName ) \
297 DEFENDER_API_COMMON( thingName, \
298 DEFENDER_API_JSON_FORMAT, \
299 DEFENDER_API_REJECTED_SUFFIX )
310#define DEFENDER_API_CBOR_PUBLISH( thingName ) \
311 DEFENDER_API_COMMON( thingName, \
312 DEFENDER_API_CBOR_FORMAT, \
313 DEFENDER_API_NULL_SUFFIX )
324#define DEFENDER_API_CBOR_ACCEPTED( thingName ) \
325 DEFENDER_API_COMMON( thingName, \
326 DEFENDER_API_CBOR_FORMAT, \
327 DEFENDER_API_ACCEPTED_SUFFIX )
338#define DEFENDER_API_CBOR_REJECTED( thingName ) \
339 DEFENDER_API_COMMON( thingName, \
340 DEFENDER_API_CBOR_FORMAT, \
341 DEFENDER_API_REJECTED_SUFFIX )
351#if ( defined( DEFENDER_USE_LONG_KEYS ) && ( DEFENDER_USE_LONG_KEYS == 1 ) )
352 #define DEFENDER_REPORT_SELECT_KEY( longKey, shortKey ) longKey
354 #define DEFENDER_REPORT_SELECT_KEY( longKey, shortKey ) shortKey
363#define DEFENDER_REPORT_HEADER_KEY DEFENDER_REPORT_SELECT_KEY( "header", "hed" )
369#define DEFENDER_REPORT_LENGTH_HEADER_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_HEADER_KEY )
375#define DEFENDER_REPORT_METRICS_KEY DEFENDER_REPORT_SELECT_KEY( "metrics", "met" )
381#define DEFENDER_REPORT_LENGTH_METRICS_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_METRICS_KEY )
387#define DEFENDER_REPORT_ID_KEY DEFENDER_REPORT_SELECT_KEY( "report_id", "rid" )
393#define DEFENDER_REPORT_LENGTH_ID_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_ID_KEY )
399#define DEFENDER_REPORT_VERSION_KEY DEFENDER_REPORT_SELECT_KEY( "version", "v" )
405#define DEFENDER_REPORT_LENGTH_VERSION_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_VERSION_KEY )
411#define DEFENDER_REPORT_TCP_CONNECTIONS_KEY DEFENDER_REPORT_SELECT_KEY( "tcp_connections", "tc" )
417#define DEFENDER_REPORT_LENGTH_TCP_CONNECTIONS_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_TCP_CONNECTIONS_KEY )
423#define DEFENDER_REPORT_ESTABLISHED_CONNECTIONS_KEY DEFENDER_REPORT_SELECT_KEY( "established_connections", "ec" )
429#define DEFENDER_REPORT_LENGTH_ESTABLISHED_CONNECTIONS_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_ESTABLISHED_CONNECTIONS_KEY )
435#define DEFENDER_REPORT_CONNECTIONS_KEY DEFENDER_REPORT_SELECT_KEY( "connections", "cs" )
441#define DEFENDER_REPORT_LENGTH_CONNECTIONS_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_CONNECTIONS_KEY )
447#define DEFENDER_REPORT_REMOTE_ADDR_KEY DEFENDER_REPORT_SELECT_KEY( "remote_addr", "rad" )
453#define DEFENDER_REPORT_LENGTH_REMOTE_ADDR_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_REMOTE_ADDR_KEY )
459#define DEFENDER_REPORT_LOCAL_PORT_KEY DEFENDER_REPORT_SELECT_KEY( "local_port", "lp" )
465#define DEFENDER_REPORT_LENGTH_LOCAL_PORT_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_LOCAL_PORT_KEY )
471#define DEFENDER_REPORT_LOCAL_INTERFACE_KEY DEFENDER_REPORT_SELECT_KEY( "local_interface", "li" )
477#define DEFENDER_REPORT_LENGTH_LOCAL_INTERFACE_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_LOCAL_INTERFACE_KEY )
483#define DEFENDER_REPORT_TOTAL_KEY DEFENDER_REPORT_SELECT_KEY( "total", "t" )
489#define DEFENDER_REPORT_LENGTH_TOTAL_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_TOTAL_KEY )
495#define DEFENDER_REPORT_TCP_LISTENING_PORTS_KEY DEFENDER_REPORT_SELECT_KEY( "listening_tcp_ports", "tp" )
501#define DEFENDER_REPORT_LENGTH_TCP_LISTENING_PORTS_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_TCP_LISTENING_PORTS_KEY )
507#define DEFENDER_REPORT_PORTS_KEY DEFENDER_REPORT_SELECT_KEY( "ports", "pts" )
513#define DEFENDER_REPORT_LENGTH_PORTS_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_PORTS_KEY )
519#define DEFENDER_REPORT_PORT_KEY DEFENDER_REPORT_SELECT_KEY( "port", "pt" )
525#define DEFENDER_REPORT_LENGTH_PORT_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_PORT_KEY )
531#define DEFENDER_REPORT_INTERFACE_KEY DEFENDER_REPORT_SELECT_KEY( "interface", "if" )
537#define DEFENDER_REPORT_LENGTH_INTERFACE_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_INTERFACE_KEY )
543#define DEFENDER_REPORT_UDP_LISTENING_PORTS_KEY DEFENDER_REPORT_SELECT_KEY( "listening_udp_ports", "up" )
549#define DEFENDER_REPORT_LENGTH_UDP_LISTENING_PORTS_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_UDP_LISTENING_PORTS_KEY )
555#define DEFENDER_REPORT_NETWORK_STATS_KEY DEFENDER_REPORT_SELECT_KEY( "network_stats", "ns" )
561#define DEFENDER_REPORT_LENGTH_NETWORK_STATS_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_NETWORK_STATS_KEY )
567#define DEFENDER_REPORT_BYTES_IN_KEY DEFENDER_REPORT_SELECT_KEY( "bytes_in", "bi" )
573#define DEFENDER_REPORT_LENGTH_BYTES_IN_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_BYTES_IN_KEY )
579#define DEFENDER_REPORT_BYTES_OUT_KEY DEFENDER_REPORT_SELECT_KEY( "bytes_out", "bo" )
585#define DEFENDER_REPORT_LENGTH_BYTES_OUT_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_BYTES_OUT_KEY )
591#define DEFENDER_REPORT_PKTS_IN_KEY DEFENDER_REPORT_SELECT_KEY( "packets_in", "pi" )
597#define DEFENDER_REPORT_LENGTH_PKTS_IN_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_PKTS_IN_KEY )
603#define DEFENDER_REPORT_PKTS_OUT_KEY DEFENDER_REPORT_SELECT_KEY( "packets_out", "po" )
609#define DEFENDER_REPORT_LENGTH_PKS_OUT_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_LENGTH_PKS_OUT_KEY )
615#define DEFENDER_REPORT_CUSTOM_METRICS_KEY DEFENDER_REPORT_SELECT_KEY( "custom_metrics", "cmet" )
621#define DEFENDER_REPORT_LENGTH_CUSTOM_METRICS_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_LENGTH_CUSTOM_METRICS_KEY )
627#define DEFENDER_REPORT_NUMBER_KEY "number"
633#define DEFENDER_REPORT_LENGTH_NUMBER_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_LENGTH_NUMBER_KEY )
639#define DEFENDER_REPORT_NUMBER_LIST_KEY "number_list"
645#define DEFENDER_REPORT_LENGTH_NUMBER_LIST_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_LENGTH_NUMBER_LIST_KEY )
651#define DEFENDER_REPORT_STRING_LIST_KEY "string_list"
657#define DEFENDER_REPORT_LENGTH_STRING_LIST_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_LENGTH_STRING_LIST_KEY )
663#define DEFENDER_REPORT_IP_LIST_KEY "ip_list"
669#define DEFENDER_REPORT_LENGTH_IP_LIST_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_LENGTH_IP_LIST_KEY )
721 uint16_t bufferLength,
722 const char * pThingName,
723 uint16_t thingNameLength,
725 uint16_t * pOutLength );
791 uint16_t topicLength,
793 const char ** ppOutThingName,
794 uint16_t * pOutThingNameLength );
DefenderStatus_t Defender_GetTopic(char *pBuffer, uint16_t bufferLength, const char *pThingName, uint16_t thingNameLength, DefenderTopic_t api, uint16_t *pOutLength)
Populate the topic string for a Device Defender operation.
Definition: defender.c:384
DefenderStatus_t Defender_MatchTopic(const char *pTopic, uint16_t topicLength, DefenderTopic_t *pOutApi, const char **ppOutThingName, uint16_t *pOutThingNameLength)
Check if the given topic is one of the Device Defender topics.
Definition: defender.c:465
Default config values for the AWS IoT Device Defender Client Library.
DefenderStatus_t
Return codes from defender APIs.
Definition: defender.h:58
DefenderTopic_t
Topic values for subscription requests.
Definition: defender.h:71
@ DefenderBadParameter
Definition: defender.h:62
@ DefenderBufferTooSmall
Definition: defender.h:63
@ DefenderNoMatch
Definition: defender.h:61
@ DefenderError
Definition: defender.h:59
@ DefenderSuccess
Definition: defender.h:60
@ DefenderCborReportPublish
Definition: defender.h:76
@ DefenderInvalidTopic
Definition: defender.h:72
@ DefenderJsonReportPublish
Definition: defender.h:73
@ DefenderJsonReportAccepted
Definition: defender.h:74
@ DefenderJsonReportRejected
Definition: defender.h:75
@ DefenderCborReportRejected
Definition: defender.h:78
@ DefenderCborReportAccepted
Definition: defender.h:77