AWS IoT Device Defender
v1.1.1
AWS IoT Device Defender Client Library
|
|
Go to the documentation of this file.
44 #ifndef DEFENDER_DO_NOT_USE_CUSTOM_CONFIG
45 #include "defender_config.h"
85 #define STRING_LITERAL_LENGTH( literal ) ( ( uint16_t ) ( sizeof( literal ) - 1U ) )
93 #define DEFENDER_THINGNAME_MAX_LENGTH 128U
102 #define DEFENDER_REPORT_MIN_PERIOD_SECONDS 300
132 #define DEFENDER_API_PREFIX "$aws/things/"
133 #define DEFENDER_API_LENGTH_PREFIX STRING_LITERAL_LENGTH( DEFENDER_API_PREFIX )
135 #define DEFENDER_API_BRIDGE "/defender/metrics/"
136 #define DEFENDER_API_LENGTH_BRIDGE STRING_LITERAL_LENGTH( DEFENDER_API_BRIDGE )
138 #define DEFENDER_API_JSON_FORMAT "json"
139 #define DEFENDER_API_LENGTH_JSON_FORMAT STRING_LITERAL_LENGTH( DEFENDER_API_JSON_FORMAT )
141 #define DEFENDER_API_CBOR_FORMAT "cbor"
142 #define DEFENDER_API_LENGTH_CBOR_FORMAT STRING_LITERAL_LENGTH( DEFENDER_API_CBOR_FORMAT )
144 #define DEFENDER_API_ACCEPTED_SUFFIX "/accepted"
145 #define DEFENDER_API_LENGTH_ACCEPTED_SUFFIX STRING_LITERAL_LENGTH( DEFENDER_API_ACCEPTED_SUFFIX )
147 #define DEFENDER_API_REJECTED_SUFFIX "/rejected"
148 #define DEFENDER_API_LENGTH_REJECTED_SUFFIX STRING_LITERAL_LENGTH( DEFENDER_API_REJECTED_SUFFIX )
150 #define DEFENDER_API_NULL_SUFFIX ""
151 #define DEFENDER_API_LENGTH_NULL_SUFFIX ( 0U )
163 #define DEFENDER_API_COMMON_LENGTH( thingNameLength, reportFormatLength, suffixLength ) \
164 ( DEFENDER_API_LENGTH_PREFIX + \
165 ( thingNameLength ) + \
166 DEFENDER_API_LENGTH_BRIDGE + \
167 ( reportFormatLength ) + \
177 #define DEFENDER_API_LENGTH_JSON_PUBLISH( thingNameLength ) \
178 DEFENDER_API_COMMON_LENGTH( thingNameLength, \
179 DEFENDER_API_LENGTH_JSON_FORMAT, \
180 DEFENDER_API_LENGTH_NULL_SUFFIX )
187 #define DEFENDER_API_LENGTH_JSON_ACCEPTED( thingNameLength ) \
188 DEFENDER_API_COMMON_LENGTH( thingNameLength, \
189 DEFENDER_API_LENGTH_JSON_FORMAT, \
190 DEFENDER_API_LENGTH_ACCEPTED_SUFFIX )
197 #define DEFENDER_API_LENGTH_JSON_REJECTED( thingNameLength ) \
198 DEFENDER_API_COMMON_LENGTH( thingNameLength, \
199 DEFENDER_API_LENGTH_JSON_FORMAT, \
200 DEFENDER_API_LENGTH_REJECTED_SUFFIX )
207 #define DEFENDER_API_LENGTH_CBOR_PUBLISH( thingNameLength ) \
208 DEFENDER_API_COMMON_LENGTH( thingNameLength, \
209 DEFENDER_API_LENGTH_CBOR_FORMAT, \
210 DEFENDER_API_LENGTH_NULL_SUFFIX )
217 #define DEFENDER_API_LENGTH_CBOR_ACCEPTED( thingNameLength ) \
218 DEFENDER_API_COMMON_LENGTH( thingNameLength, \
219 DEFENDER_API_LENGTH_CBOR_FORMAT, \
220 DEFENDER_API_LENGTH_ACCEPTED_SUFFIX )
227 #define DEFENDER_API_LENGTH_CBOR_REJECTED( thingNameLength ) \
228 DEFENDER_API_COMMON_LENGTH( thingNameLength, \
229 DEFENDER_API_LENGTH_CBOR_FORMAT, \
230 DEFENDER_API_LENGTH_REJECTED_SUFFIX )
237 #define DEFENDER_API_MAX_LENGTH( thingNameLength ) \
238 DEFENDER_API_LENGTH_CBOR_ACCEPTED( thingNameLength )
248 #define DEFENDER_API_COMMON( thingName, reportFormat, suffix ) \
249 ( DEFENDER_API_PREFIX \
251 DEFENDER_API_BRIDGE \
266 #define DEFENDER_API_JSON_PUBLISH( thingName ) \
267 DEFENDER_API_COMMON( thingName, \
268 DEFENDER_API_JSON_FORMAT, \
269 DEFENDER_API_NULL_SUFFIX )
280 #define DEFENDER_API_JSON_ACCEPTED( thingName ) \
281 DEFENDER_API_COMMON( thingName, \
282 DEFENDER_API_JSON_FORMAT, \
283 DEFENDER_API_ACCEPTED_SUFFIX )
294 #define DEFENDER_API_JSON_REJECTED( thingName ) \
295 DEFENDER_API_COMMON( thingName, \
296 DEFENDER_API_JSON_FORMAT, \
297 DEFENDER_API_REJECTED_SUFFIX )
308 #define DEFENDER_API_CBOR_PUBLISH( thingName ) \
309 DEFENDER_API_COMMON( thingName, \
310 DEFENDER_API_CBOR_FORMAT, \
311 DEFENDER_API_NULL_SUFFIX )
322 #define DEFENDER_API_CBOR_ACCEPTED( thingName ) \
323 DEFENDER_API_COMMON( thingName, \
324 DEFENDER_API_CBOR_FORMAT, \
325 DEFENDER_API_ACCEPTED_SUFFIX )
336 #define DEFENDER_API_CBOR_REJECTED( thingName ) \
337 DEFENDER_API_COMMON( thingName, \
338 DEFENDER_API_CBOR_FORMAT, \
339 DEFENDER_API_REJECTED_SUFFIX )
349 #if ( defined( DEFENDER_USE_LONG_KEYS ) && ( DEFENDER_USE_LONG_KEYS == 1 ) )
350 #define DEFENDER_REPORT_SELECT_KEY( longKey, shortKey ) longKey
352 #define DEFENDER_REPORT_SELECT_KEY( longKey, shortKey ) shortKey
361 #define DEFENDER_REPORT_HEADER_KEY DEFENDER_REPORT_SELECT_KEY( "header", "hed" )
367 #define DEFENDER_REPORT_LENGTH_HEADER_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_HEADER_KEY )
373 #define DEFENDER_REPORT_METRICS_KEY DEFENDER_REPORT_SELECT_KEY( "metrics", "met" )
379 #define DEFENDER_REPORT_LENGTH_METRICS_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_METRICS_KEY )
385 #define DEFENDER_REPORT_ID_KEY DEFENDER_REPORT_SELECT_KEY( "report_id", "rid" )
391 #define DEFENDER_REPORT_LENGTH_ID_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_ID_KEY )
397 #define DEFENDER_REPORT_VERSION_KEY DEFENDER_REPORT_SELECT_KEY( "version", "v" )
403 #define DEFENDER_REPORT_LENGTH_VERSION_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_VERSION_KEY )
409 #define DEFENDER_REPORT_TCP_CONNECTIONS_KEY DEFENDER_REPORT_SELECT_KEY( "tcp_connections", "tc" )
415 #define DEFENDER_REPORT_LENGTH_TCP_CONNECTIONS_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_TCP_CONNECTIONS_KEY )
421 #define DEFENDER_REPORT_ESTABLISHED_CONNECTIONS_KEY DEFENDER_REPORT_SELECT_KEY( "established_connections", "ec" )
427 #define DEFENDER_REPORT_LENGTH_ESTABLISHED_CONNECTIONS_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_ESTABLISHED_CONNECTIONS_KEY )
433 #define DEFENDER_REPORT_CONNECTIONS_KEY DEFENDER_REPORT_SELECT_KEY( "connections", "cs" )
439 #define DEFENDER_REPORT_LENGTH_CONNECTIONS_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_CONNECTIONS_KEY )
445 #define DEFENDER_REPORT_REMOTE_ADDR_KEY DEFENDER_REPORT_SELECT_KEY( "remote_addr", "rad" )
451 #define DEFENDER_REPORT_LENGTH_REMOTE_ADDR_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_REMOTE_ADDR_KEY )
457 #define DEFENDER_REPORT_LOCAL_PORT_KEY DEFENDER_REPORT_SELECT_KEY( "local_port", "lp" )
463 #define DEFENDER_REPORT_LENGTH_LOCAL_PORT_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_LOCAL_PORT_KEY )
469 #define DEFENDER_REPORT_LOCAL_INTERFACE_KEY DEFENDER_REPORT_SELECT_KEY( "local_interface", "li" )
475 #define DEFENDER_REPORT_LENGTH_LOCAL_INTERFACE_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_LOCAL_INTERFACE_KEY )
481 #define DEFENDER_REPORT_TOTAL_KEY DEFENDER_REPORT_SELECT_KEY( "total", "t" )
487 #define DEFENDER_REPORT_LENGTH_TOTAL_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_TOTAL_KEY )
493 #define DEFENDER_REPORT_TCP_LISTENING_PORTS_KEY DEFENDER_REPORT_SELECT_KEY( "listening_tcp_ports", "tp" )
499 #define DEFENDER_REPORT_LENGTH_TCP_LISTENING_PORTS_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_TCP_LISTENING_PORTS_KEY )
505 #define DEFENDER_REPORT_PORTS_KEY DEFENDER_REPORT_SELECT_KEY( "ports", "pts" )
511 #define DEFENDER_REPORT_LENGTH_PORTS_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_PORTS_KEY )
517 #define DEFENDER_REPORT_PORT_KEY DEFENDER_REPORT_SELECT_KEY( "port", "pt" )
523 #define DEFENDER_REPORT_LENGTH_PORT_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_PORT_KEY )
529 #define DEFENDER_REPORT_INTERFACE_KEY DEFENDER_REPORT_SELECT_KEY( "interface", "if" )
535 #define DEFENDER_REPORT_LENGTH_INTERFACE_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_INTERFACE_KEY )
541 #define DEFENDER_REPORT_UDP_LISTENING_PORTS_KEY DEFENDER_REPORT_SELECT_KEY( "listening_udp_ports", "up" )
547 #define DEFENDER_REPORT_LENGTH_UDP_LISTENING_PORTS_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_UDP_LISTENING_PORTS_KEY )
553 #define DEFENDER_REPORT_NETWORK_STATS_KEY DEFENDER_REPORT_SELECT_KEY( "network_stats", "ns" )
559 #define DEFENDER_REPORT_LENGTH_NETWORK_STATS_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_NETWORK_STATS_KEY )
565 #define DEFENDER_REPORT_BYTES_IN_KEY DEFENDER_REPORT_SELECT_KEY( "bytes_in", "bi" )
571 #define DEFENDER_REPORT_LENGTH_BYTES_IN_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_BYTES_IN_KEY )
577 #define DEFENDER_REPORT_BYTES_OUT_KEY DEFENDER_REPORT_SELECT_KEY( "bytes_out", "bo" )
583 #define DEFENDER_REPORT_LENGTH_BYTES_OUT_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_BYTES_OUT_KEY )
589 #define DEFENDER_REPORT_PKTS_IN_KEY DEFENDER_REPORT_SELECT_KEY( "packets_in", "pi" )
595 #define DEFENDER_REPORT_LENGTH_PKTS_IN_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_PKTS_IN_KEY )
601 #define DEFENDER_REPORT_PKTS_OUT_KEY DEFENDER_REPORT_SELECT_KEY( "packets_out", "po" )
607 #define DEFENDER_REPORT_LENGTH_PKS_OUT_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_LENGTH_PKS_OUT_KEY )
613 #define DEFENDER_REPORT_CUSTOM_METRICS_KEY DEFENDER_REPORT_SELECT_KEY( "custom_metrics", "cmet" )
619 #define DEFENDER_REPORT_LENGTH_CUSTOM_METRICS_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_LENGTH_CUSTOM_METRICS_KEY )
625 #define DEFENDER_REPORT_NUMBER_KEY "number"
631 #define DEFENDER_REPORT_LENGTH_NUMBER_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_LENGTH_NUMBER_KEY )
637 #define DEFENDER_REPORT_NUMBER_LIST_KEY "number_list"
643 #define DEFENDER_REPORT_LENGTH_NUMBER_LIST_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_LENGTH_NUMBER_LIST_KEY )
649 #define DEFENDER_REPORT_STRING_LIST_KEY "string_list"
655 #define DEFENDER_REPORT_LENGTH_STRING_LIST_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_LENGTH_STRING_LIST_KEY )
661 #define DEFENDER_REPORT_IP_LIST_KEY "ip_list"
667 #define DEFENDER_REPORT_LENGTH_IP_LIST_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_LENGTH_IP_LIST_KEY )
719 uint16_t bufferLength,
720 const char * pThingName,
721 uint16_t thingNameLength,
723 uint16_t * pOutLength );
789 uint16_t topicLength,
791 const char ** ppOutThingName,
792 uint16_t * pOutThingNameLength );
@ DefenderError
Definition: defender.h:57
@ DefenderSuccess
Definition: defender.h:58
@ DefenderJsonReportRejected
Definition: defender.h:73
@ DefenderJsonReportPublish
Definition: defender.h:71
@ DefenderJsonReportAccepted
Definition: defender.h:72
Default config values for the AWS IoT Device Defender Client Library.
@ DefenderInvalidTopic
Definition: defender.h:70
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:381
DefenderStatus_t
Return codes from defender APIs.
Definition: defender.h:56
@ DefenderBufferTooSmall
Definition: defender.h:61
@ DefenderCborReportPublish
Definition: defender.h:74
@ DefenderCborReportAccepted
Definition: defender.h:75
DefenderTopic_t
Topic values for subscription requests.
Definition: defender.h:69
@ DefenderBadParameter
Definition: defender.h:60
@ DefenderCborReportRejected
Definition: defender.h:76
@ DefenderNoMatch
Definition: defender.h:59
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:462