AWS IoT Device Defender
v1.0.0
AWS IoT Device Defender Client Library
|
|
Go to the documentation of this file.
38 #ifndef DEFENDER_DO_NOT_USE_CUSTOM_CONFIG
39 #include "defender_config.h"
79 #define STRING_LITERAL_LENGTH( literal ) ( ( uint16_t ) ( sizeof( literal ) - 1U ) )
87 #define DEFENDER_THINGNAME_MAX_LENGTH 128U
96 #define DEFENDER_REPORT_MIN_PERIOD_SECONDS 300
126 #define DEFENDER_API_PREFIX "$aws/things/"
127 #define DEFENDER_API_LENGTH_PREFIX STRING_LITERAL_LENGTH( DEFENDER_API_PREFIX )
129 #define DEFENDER_API_BRIDGE "/defender/metrics/"
130 #define DEFENDER_API_LENGTH_BRIDGE STRING_LITERAL_LENGTH( DEFENDER_API_BRIDGE )
132 #define DEFENDER_API_JSON_FORMAT "json"
133 #define DEFENDER_API_LENGTH_JSON_FORMAT STRING_LITERAL_LENGTH( DEFENDER_API_JSON_FORMAT )
135 #define DEFENDER_API_CBOR_FORMAT "cbor"
136 #define DEFENDER_API_LENGTH_CBOR_FORMAT STRING_LITERAL_LENGTH( DEFENDER_API_CBOR_FORMAT )
138 #define DEFENDER_API_ACCEPTED_SUFFIX "/accepted"
139 #define DEFENDER_API_LENGTH_ACCEPTED_SUFFIX STRING_LITERAL_LENGTH( DEFENDER_API_ACCEPTED_SUFFIX )
141 #define DEFENDER_API_REJECTED_SUFFIX "/rejected"
142 #define DEFENDER_API_LENGTH_REJECTED_SUFFIX STRING_LITERAL_LENGTH( DEFENDER_API_REJECTED_SUFFIX )
144 #define DEFENDER_API_NULL_SUFFIX ""
145 #define DEFENDER_API_LENGTH_NULL_SUFFIX ( 0U )
157 #define DEFENDER_API_COMMON_LENGTH( thingNameLength, reportFormatLength, suffixLength ) \
158 ( DEFENDER_API_LENGTH_PREFIX + \
159 ( thingNameLength ) + \
160 DEFENDER_API_LENGTH_BRIDGE + \
161 ( reportFormatLength ) + \
171 #define DEFENDER_API_LENGTH_JSON_PUBLISH( thingNameLength ) \
172 DEFENDER_API_COMMON_LENGTH( thingNameLength, \
173 DEFENDER_API_LENGTH_JSON_FORMAT, \
174 DEFENDER_API_LENGTH_NULL_SUFFIX )
181 #define DEFENDER_API_LENGTH_JSON_ACCEPTED( thingNameLength ) \
182 DEFENDER_API_COMMON_LENGTH( thingNameLength, \
183 DEFENDER_API_LENGTH_JSON_FORMAT, \
184 DEFENDER_API_LENGTH_ACCEPTED_SUFFIX )
191 #define DEFENDER_API_LENGTH_JSON_REJECTED( thingNameLength ) \
192 DEFENDER_API_COMMON_LENGTH( thingNameLength, \
193 DEFENDER_API_LENGTH_JSON_FORMAT, \
194 DEFENDER_API_LENGTH_REJECTED_SUFFIX )
201 #define DEFENDER_API_LENGTH_CBOR_PUBLISH( thingNameLength ) \
202 DEFENDER_API_COMMON_LENGTH( thingNameLength, \
203 DEFENDER_API_LENGTH_CBOR_FORMAT, \
204 DEFENDER_API_LENGTH_NULL_SUFFIX )
211 #define DEFENDER_API_LENGTH_CBOR_ACCEPTED( thingNameLength ) \
212 DEFENDER_API_COMMON_LENGTH( thingNameLength, \
213 DEFENDER_API_LENGTH_CBOR_FORMAT, \
214 DEFENDER_API_LENGTH_ACCEPTED_SUFFIX )
221 #define DEFENDER_API_LENGTH_CBOR_REJECTED( thingNameLength ) \
222 DEFENDER_API_COMMON_LENGTH( thingNameLength, \
223 DEFENDER_API_LENGTH_CBOR_FORMAT, \
224 DEFENDER_API_LENGTH_REJECTED_SUFFIX )
231 #define DEFENDER_API_MAX_LENGTH( thingNameLength ) \
232 DEFENDER_API_LENGTH_CBOR_ACCEPTED( thingNameLength )
242 #define DEFENDER_API_COMMON( thingName, reportFormat, suffix ) \
243 ( DEFENDER_API_PREFIX \
245 DEFENDER_API_BRIDGE \
260 #define DEFENDER_API_JSON_PUBLISH( thingName ) \
261 DEFENDER_API_COMMON( thingName, \
262 DEFENDER_API_JSON_FORMAT, \
263 DEFENDER_API_NULL_SUFFIX )
274 #define DEFENDER_API_JSON_ACCEPTED( thingName ) \
275 DEFENDER_API_COMMON( thingName, \
276 DEFENDER_API_JSON_FORMAT, \
277 DEFENDER_API_ACCEPTED_SUFFIX )
288 #define DEFENDER_API_JSON_REJECTED( thingName ) \
289 DEFENDER_API_COMMON( thingName, \
290 DEFENDER_API_JSON_FORMAT, \
291 DEFENDER_API_REJECTED_SUFFIX )
302 #define DEFENDER_API_CBOR_PUBLISH( thingName ) \
303 DEFENDER_API_COMMON( thingName, \
304 DEFENDER_API_CBOR_FORMAT, \
305 DEFENDER_API_NULL_SUFFIX )
316 #define DEFENDER_API_CBOR_ACCEPTED( thingName ) \
317 DEFENDER_API_COMMON( thingName, \
318 DEFENDER_API_CBOR_FORMAT, \
319 DEFENDER_API_ACCEPTED_SUFFIX )
330 #define DEFENDER_API_CBOR_REJECTED( thingName ) \
331 DEFENDER_API_COMMON( thingName, \
332 DEFENDER_API_CBOR_FORMAT, \
333 DEFENDER_API_REJECTED_SUFFIX )
343 #if ( defined( DEFENDER_USE_LONG_KEYS ) && ( DEFENDER_USE_LONG_KEYS == 1 ) )
344 #define DEFENDER_REPORT_SELECT_KEY( longKey, shortKey ) ( longKey )
346 #define DEFENDER_REPORT_SELECT_KEY( longKey, shortKey ) ( shortKey )
355 #define DEFENDER_REPORT_HEADER_KEY DEFENDER_REPORT_SELECT_KEY( "header", "hed" )
361 #define DEFENDER_REPORT_LENGTH_HEADER_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_HEADER_KEY )
367 #define DEFENDER_REPORT_METRICS_KEY DEFENDER_REPORT_SELECT_KEY( "metrics", "met" )
373 #define DEFENDER_REPORT_LENGTH_METRICS_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_METRICS_KEY )
379 #define DEFENDER_REPORT_ID_KEY DEFENDER_REPORT_SELECT_KEY( "report_id", "rid" )
385 #define DEFENDER_REPORT_LENGTH_ID_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_ID_KEY )
391 #define DEFENDER_REPORT_VERSION_KEY DEFENDER_REPORT_SELECT_KEY( "version", "v" )
397 #define DEFENDER_REPORT_LENGTH_VERSION_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_VERSION_KEY )
403 #define DEFENDER_REPORT_TCP_CONNECTIONS_KEY DEFENDER_REPORT_SELECT_KEY( "tcp_connections", "tc" )
409 #define DEFENDER_REPORT_LENGTH_TCP_CONNECTIONS_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_TCP_CONNECTIONS_KEY )
415 #define DEFENDER_REPORT_ESTABLISHED_CONNECTIONS_KEY DEFENDER_REPORT_SELECT_KEY( "established_connections", "ec" )
421 #define DEFENDER_REPORT_LENGTH_ESTABLISHED_CONNECTIONS_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_ESTABLISHED_CONNECTIONS_KEY )
427 #define DEFENDER_REPORT_CONNECTIONS_KEY DEFENDER_REPORT_SELECT_KEY( "connections", "cs" )
433 #define DEFENDER_REPORT_LENGTH_CONNECTIONS_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_CONNECTIONS_KEY )
439 #define DEFENDER_REPORT_REMOTE_ADDR_KEY DEFENDER_REPORT_SELECT_KEY( "remote_addr", "rad" )
445 #define DEFENDER_REPORT_LENGTH_REMOTE_ADDR_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_REMOTE_ADDR_KEY )
451 #define DEFENDER_REPORT_LOCAL_PORT_KEY DEFENDER_REPORT_SELECT_KEY( "local_port", "lp" )
457 #define DEFENDER_REPORT_LENGTH_LOCAL_PORT_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_LOCAL_PORT_KEY )
463 #define DEFENDER_REPORT_LOCAL_INTERFACE_KEY DEFENDER_REPORT_SELECT_KEY( "local_interface", "li" )
469 #define DEFENDER_REPORT_LENGTH_LOCAL_INTERFACE_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_LOCAL_INTERFACE_KEY )
475 #define DEFENDER_REPORT_TOTAL_KEY DEFENDER_REPORT_SELECT_KEY( "total", "t" )
481 #define DEFENDER_REPORT_LENGTH_TOTAL_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_TOTAL_KEY )
487 #define DEFENDER_REPORT_TCP_LISTENING_PORTS_KEY DEFENDER_REPORT_SELECT_KEY( "listening_tcp_ports", "tp" )
493 #define DEFENDER_REPORT_LENGTH_TCP_LISTENING_PORTS_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_TCP_LISTENING_PORTS_KEY )
499 #define DEFENDER_REPORT_PORTS_KEY DEFENDER_REPORT_SELECT_KEY( "ports", "pts" )
505 #define DEFENDER_REPORT_LENGTH_PORTS_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_PORTS_KEY )
511 #define DEFENDER_REPORT_PORT_KEY DEFENDER_REPORT_SELECT_KEY( "port", "pt" )
517 #define DEFENDER_REPORT_LENGTH_PORT_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_PORT_KEY )
523 #define DEFENDER_REPORT_INTERFACE_KEY DEFENDER_REPORT_SELECT_KEY( "interface", "if" )
529 #define DEFENDER_REPORT_LENGTH_INTERFACE_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_INTERFACE_KEY )
535 #define DEFENDER_REPORT_UDP_LISTENING_PORTS_KEY DEFENDER_REPORT_SELECT_KEY( "listening_udp_ports", "up" )
541 #define DEFENDER_REPORT_LENGTH_UDP_LISTENING_PORTS_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_UDP_LISTENING_PORTS_KEY )
547 #define DEFENDER_REPORT_NETWORK_STATS_KEY DEFENDER_REPORT_SELECT_KEY( "network_stats", "ns" )
553 #define DEFENDER_REPORT_LENGTH_NETWORK_STATS_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_NETWORK_STATS_KEY )
559 #define DEFENDER_REPORT_BYTES_IN_KEY DEFENDER_REPORT_SELECT_KEY( "bytes_in", "bi" )
565 #define DEFENDER_REPORT_LENGTH_BYTES_IN_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_BYTES_IN_KEY )
571 #define DEFENDER_REPORT_BYTES_OUT_KEY DEFENDER_REPORT_SELECT_KEY( "bytes_out", "bo" )
577 #define DEFENDER_REPORT_LENGTH_BYTES_OUT_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_BYTES_OUT_KEY )
583 #define DEFENDER_REPORT_PKTS_IN_KEY DEFENDER_REPORT_SELECT_KEY( "packets_in", "pi" )
589 #define DEFENDER_REPORT_LENGTH_PKTS_IN_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_PKTS_IN_KEY )
595 #define DEFENDER_REPORT_PKTS_OUT_KEY DEFENDER_REPORT_SELECT_KEY( "packets_out", "po" )
601 #define DEFENDER_REPORT_LENGTH_PKS_OUT_KEY STRING_LITERAL_LENGTH( DEFENDER_REPORT_LENGTH_PKS_OUT_KEY )
653 uint16_t bufferLength,
654 const char * pThingName,
655 uint16_t thingNameLength,
657 uint16_t * pOutLength );
723 uint16_t topicLength,
725 const char ** ppOutThingName,
726 uint16_t * pOutThingNameLength );
@ DefenderError
Definition: defender.h:51
@ DefenderSuccess
Definition: defender.h:52
@ DefenderJsonReportRejected
Definition: defender.h:67
@ DefenderJsonReportPublish
Definition: defender.h:65
@ DefenderJsonReportAccepted
Definition: defender.h:66
Default config values for the AWS IoT Device Defender Client Library.
@ DefenderInvalidTopic
Definition: defender.h:64
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:50
@ DefenderBufferTooSmall
Definition: defender.h:55
@ DefenderCborReportPublish
Definition: defender.h:68
@ DefenderCborReportAccepted
Definition: defender.h:69
DefenderTopic_t
Topic values for subscription requests.
Definition: defender.h:63
@ DefenderBadParameter
Definition: defender.h:54
@ DefenderCborReportRejected
Definition: defender.h:70
@ DefenderNoMatch
Definition: defender.h:53
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