mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-12-23 11:09:28 -05:00
Clean up defender demo (#422)
This commit is contained in:
parent
ced1845508
commit
5ba1e4cf95
4 changed files with 114 additions and 94 deletions
|
|
@ -96,8 +96,15 @@
|
||||||
*/
|
*/
|
||||||
#define DEFENDER_RESPONSE_WAIT_SECONDS ( 2 )
|
#define DEFENDER_RESPONSE_WAIT_SECONDS ( 2 )
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Name of the report id field in the response from the AWS IoT Device
|
||||||
|
* Defender service.
|
||||||
|
*/
|
||||||
#define DEFENDER_RESPONSE_REPORT_ID_FIELD "reportId"
|
#define DEFENDER_RESPONSE_REPORT_ID_FIELD "reportId"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The length of #DEFENDER_RESPONSE_REPORT_ID_FIELD.
|
||||||
|
*/
|
||||||
#define DEFENDER_RESPONSE_REPORT_ID_FIELD_LENGTH ( sizeof( DEFENDER_RESPONSE_REPORT_ID_FIELD ) - 1 )
|
#define DEFENDER_RESPONSE_REPORT_ID_FIELD_LENGTH ( sizeof( DEFENDER_RESPONSE_REPORT_ID_FIELD ) - 1 )
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -62,23 +62,29 @@ eMetricsCollectorStatus eGetNetworkStats( NetworkStats_t * pxOutNetworkStats )
|
||||||
|
|
||||||
configASSERT( pxOutNetworkStats != NULL );
|
configASSERT( pxOutNetworkStats != NULL );
|
||||||
|
|
||||||
if( eStatus == eMetricsCollectorSuccess )
|
/* Start with everything as zero. */
|
||||||
|
memset( pxOutNetworkStats, 0, sizeof( NetworkStats_t ) );
|
||||||
|
|
||||||
|
/* Get metrics from FreeRTOS+TCP tcp_netstat utility. */
|
||||||
|
xMetricsStatus = vGetMetrics( &xMetrics );
|
||||||
|
|
||||||
|
if( xMetricsStatus != 0 )
|
||||||
{
|
{
|
||||||
/* Start with everything as zero. */
|
LogError( ( "Failed to acquire metrics from FreeRTOS+TCP tcp_netstat utility. Status: %d.",
|
||||||
memset( pxOutNetworkStats, 0, sizeof( NetworkStats_t ) );
|
( int ) xMetricsStatus ) );
|
||||||
|
eStatus = eMetricsCollectorCollectionFailed;
|
||||||
/* Get metrics from FreeRTOS+TCP tcp_netstat utility. */
|
|
||||||
xMetricsStatus = vGetMetrics( &xMetrics );
|
|
||||||
|
|
||||||
if( xMetricsStatus != 0 )
|
|
||||||
{
|
|
||||||
eStatus = eMetricsCollectorCollectionFailed;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fill our response with values gotten from FreeRTOS+TCP. */
|
/* Fill our response with values gotten from FreeRTOS+TCP. */
|
||||||
if( eStatus == eMetricsCollectorSuccess )
|
if( eStatus == eMetricsCollectorSuccess )
|
||||||
{
|
{
|
||||||
|
LogDebug( ( "Network stats read. Bytes received: %u, packets received: %u, "
|
||||||
|
"bytes sent: %u, packets sent: %u.",
|
||||||
|
( unsigned int ) xMetrics.xInput.uxByteCount,
|
||||||
|
( unsigned int ) xMetrics.xInput.uxPacketCount,
|
||||||
|
( unsigned int ) xMetrics.XOutput.uxByteCount,
|
||||||
|
( unsigned int ) xMetrics.XOutput.uxPacketCount ) );
|
||||||
|
|
||||||
pxOutNetworkStats->ulBytesReceived = xMetrics.xInput.uxByteCount;
|
pxOutNetworkStats->ulBytesReceived = xMetrics.xInput.uxByteCount;
|
||||||
pxOutNetworkStats->ulPacketsReceived = xMetrics.xInput.uxPacketCount;
|
pxOutNetworkStats->ulPacketsReceived = xMetrics.xInput.uxPacketCount;
|
||||||
pxOutNetworkStats->ulBytesSent = xMetrics.XOutput.uxByteCount;
|
pxOutNetworkStats->ulBytesSent = xMetrics.XOutput.uxByteCount;
|
||||||
|
|
@ -97,19 +103,19 @@ eMetricsCollectorStatus eGetOpenTcpPorts( uint16_t * pusOutTcpPortsArray,
|
||||||
|
|
||||||
MetricsType_t xMetrics = { 0 };
|
MetricsType_t xMetrics = { 0 };
|
||||||
BaseType_t xMetricsStatus = 0;
|
BaseType_t xMetricsStatus = 0;
|
||||||
|
uint32_t ulCopyAmount = 0UL;
|
||||||
|
|
||||||
/* pusOutTcpPortsArray can be NULL. */
|
/* pusOutTcpPortsArray can be NULL. */
|
||||||
configASSERT( pulOutNumTcpOpenPorts != NULL );
|
configASSERT( pulOutNumTcpOpenPorts != NULL );
|
||||||
|
|
||||||
if( eStatus == eMetricsCollectorSuccess )
|
/* Get metrics from FreeRTOS+TCP tcp_netstat utility. */
|
||||||
{
|
xMetricsStatus = vGetMetrics( &xMetrics );
|
||||||
/* Get metrics from FreeRTOS+TCP tcp_netstat utility. */
|
|
||||||
xMetricsStatus = vGetMetrics( &xMetrics );
|
|
||||||
|
|
||||||
if( xMetricsStatus != 0 )
|
if( xMetricsStatus != 0 )
|
||||||
{
|
{
|
||||||
eStatus = eMetricsCollectorCollectionFailed;
|
LogError( ( "Failed to acquire metrics from FreeRTOS+TCP tcp_netstat utility. Status: %d.",
|
||||||
}
|
( int ) xMetricsStatus ) );
|
||||||
|
eStatus = eMetricsCollectorCollectionFailed;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( eStatus == eMetricsCollectorSuccess )
|
if( eStatus == eMetricsCollectorSuccess )
|
||||||
|
|
@ -121,14 +127,16 @@ eMetricsCollectorStatus eGetOpenTcpPorts( uint16_t * pusOutTcpPortsArray,
|
||||||
* given array. */
|
* given array. */
|
||||||
if( pusOutTcpPortsArray != NULL )
|
if( pusOutTcpPortsArray != NULL )
|
||||||
{
|
{
|
||||||
/* Lower the amount of ports copied if less are open than will fit
|
ulCopyAmount = xMetrics.xTCPPortList.uxCount;
|
||||||
* in the given array. */
|
|
||||||
if( xMetrics.xTCPPortList.uxCount < ulTcpPortsArrayLength )
|
/* Limit the copied ports to what can fit in the output array. */
|
||||||
|
if( ulTcpPortsArrayLength < xMetrics.xTCPPortList.uxCount )
|
||||||
{
|
{
|
||||||
ulTcpPortsArrayLength = xMetrics.xTCPPortList.uxCount;
|
LogWarn( ( "Ports returned truncated due to insufficient buffer size." ) );
|
||||||
|
ulCopyAmount = ulTcpPortsArrayLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy( pusOutTcpPortsArray, &xMetrics.xTCPPortList.usTCPPortList, ulTcpPortsArrayLength * sizeof( uint16_t ) );
|
memcpy( pusOutTcpPortsArray, &xMetrics.xTCPPortList.usTCPPortList, ulCopyAmount * sizeof( uint16_t ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -144,19 +152,19 @@ eMetricsCollectorStatus eGetOpenUdpPorts( uint16_t * pusOutUdpPortsArray,
|
||||||
|
|
||||||
MetricsType_t xMetrics = { 0 };
|
MetricsType_t xMetrics = { 0 };
|
||||||
BaseType_t xMetricsStatus = 0;
|
BaseType_t xMetricsStatus = 0;
|
||||||
|
uint32_t ulCopyAmount = 0UL;
|
||||||
|
|
||||||
/* pusOutUdpPortsArray can be NULL. */
|
/* pusOutUdpPortsArray can be NULL. */
|
||||||
configASSERT( pulOutNumUdpOpenPorts != NULL );
|
configASSERT( pulOutNumUdpOpenPorts != NULL );
|
||||||
|
|
||||||
if( eStatus == eMetricsCollectorSuccess )
|
/* Get metrics from FreeRTOS+TCP tcp_netstat utility. */
|
||||||
{
|
xMetricsStatus = vGetMetrics( &xMetrics );
|
||||||
/* Get metrics from FreeRTOS+TCP tcp_netstat utility. */
|
|
||||||
xMetricsStatus = vGetMetrics( &xMetrics );
|
|
||||||
|
|
||||||
if( xMetricsStatus != 0 )
|
if( xMetricsStatus != 0 )
|
||||||
{
|
{
|
||||||
eStatus = eMetricsCollectorCollectionFailed;
|
LogError( ( "Failed to acquire metrics from FreeRTOS+TCP tcp_netstat utility. Status: %d.",
|
||||||
}
|
( int ) xMetricsStatus ) );
|
||||||
|
eStatus = eMetricsCollectorCollectionFailed;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( eStatus == eMetricsCollectorSuccess )
|
if( eStatus == eMetricsCollectorSuccess )
|
||||||
|
|
@ -167,14 +175,16 @@ eMetricsCollectorStatus eGetOpenUdpPorts( uint16_t * pusOutUdpPortsArray,
|
||||||
* given array. */
|
* given array. */
|
||||||
if( pusOutUdpPortsArray != NULL )
|
if( pusOutUdpPortsArray != NULL )
|
||||||
{
|
{
|
||||||
/* Lower the amount of ports copied if less are open than will fit
|
ulCopyAmount = xMetrics.xUDPPortList.uxCount;
|
||||||
* in the given array. */
|
|
||||||
if( xMetrics.xUDPPortList.uxCount < ulUdpPortsArrayLength )
|
/* Limit the copied ports to what can fit in the output array. */
|
||||||
|
if( ulUdpPortsArrayLength < xMetrics.xUDPPortList.uxCount )
|
||||||
{
|
{
|
||||||
ulUdpPortsArrayLength = xMetrics.xUDPPortList.uxCount;
|
LogWarn( ( "Ports returned truncated due to insufficient buffer size." ) );
|
||||||
|
ulCopyAmount = ulUdpPortsArrayLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy( pusOutUdpPortsArray, &xMetrics.xUDPPortList.usUDPPortList, ulUdpPortsArrayLength * sizeof( uint16_t ) );
|
memcpy( pusOutUdpPortsArray, &xMetrics.xUDPPortList.usUDPPortList, ulCopyAmount * sizeof( uint16_t ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -191,20 +201,21 @@ eMetricsCollectorStatus eGetEstablishedConnections( Connection_t * pxOutConnecti
|
||||||
|
|
||||||
MetricsType_t xMetrics = { 0 };
|
MetricsType_t xMetrics = { 0 };
|
||||||
BaseType_t xMetricsStatus = 0;
|
BaseType_t xMetricsStatus = 0;
|
||||||
|
uint32_t ulCopyAmount = 0UL;
|
||||||
uint32_t ulLocalIp = 0UL;
|
uint32_t ulLocalIp = 0UL;
|
||||||
|
uint32_t i;
|
||||||
|
|
||||||
/* pxOutConnectionsArray can be NULL. */
|
/* pxOutConnectionsArray can be NULL. */
|
||||||
configASSERT( pulOutNumEstablishedConnections != NULL );
|
configASSERT( pulOutNumEstablishedConnections != NULL );
|
||||||
|
|
||||||
if( eStatus == eMetricsCollectorSuccess )
|
/* Get metrics from FreeRTOS+TCP tcp_netstat utility. */
|
||||||
{
|
xMetricsStatus = vGetMetrics( &xMetrics );
|
||||||
/* Get metrics from FreeRTOS+TCP tcp_netstat utility. */
|
|
||||||
xMetricsStatus = vGetMetrics( &xMetrics );
|
|
||||||
|
|
||||||
if( xMetricsStatus != 0 )
|
if( xMetricsStatus != 0 )
|
||||||
{
|
{
|
||||||
eStatus = eMetricsCollectorCollectionFailed;
|
LogError( ( "Failed to acquire metrics from FreeRTOS+TCP tcp_netstat utility. Status: %d.",
|
||||||
}
|
( int ) xMetricsStatus ) );
|
||||||
|
eStatus = eMetricsCollectorCollectionFailed;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( eStatus == eMetricsCollectorSuccess )
|
if( eStatus == eMetricsCollectorSuccess )
|
||||||
|
|
@ -216,28 +227,27 @@ eMetricsCollectorStatus eGetEstablishedConnections( Connection_t * pxOutConnecti
|
||||||
* the given array. */
|
* the given array. */
|
||||||
if( pxOutConnectionsArray != NULL )
|
if( pxOutConnectionsArray != NULL )
|
||||||
{
|
{
|
||||||
|
ulCopyAmount = xMetrics.xTCPSocketList.uxCount;
|
||||||
|
|
||||||
/* Get local IP as the tcp_netstat utility does not give it. */
|
/* Get local IP as the tcp_netstat utility does not give it. */
|
||||||
ulLocalIp = FreeRTOS_GetIPAddress();
|
ulLocalIp = FreeRTOS_GetIPAddress();
|
||||||
|
|
||||||
/* Lower the amount of socket infos populated if less are open than will fit
|
/* Limit the outputted connections to what can fit in the output array. */
|
||||||
* in the given array. */
|
if( ulConnectionsArrayLength < xMetrics.xTCPSocketList.uxCount )
|
||||||
if( xMetrics.xTCPSocketList.uxCount < ulConnectionsArrayLength )
|
|
||||||
{
|
{
|
||||||
ulConnectionsArrayLength = xMetrics.xTCPSocketList.uxCount;
|
LogWarn( ( "Ports returned truncated due to insufficient buffer size." ) );
|
||||||
|
ulCopyAmount = ulConnectionsArrayLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If xMetrics.xTCPSocketList.uxCount > ulConnectionsArrayLength, we
|
for( i = 0; i < ulCopyAmount; i++ )
|
||||||
* return the first ulConnectionsArrayLength ports. */
|
|
||||||
while( ulConnectionsArrayLength > 0 )
|
|
||||||
{
|
{
|
||||||
ulConnectionsArrayLength--;
|
pxOutConnectionsArray[ i ].ulLocalIp = ulLocalIp;
|
||||||
pxOutConnectionsArray[ ulConnectionsArrayLength ].ulLocalIp = ulLocalIp;
|
pxOutConnectionsArray[ i ].usLocalPort =
|
||||||
pxOutConnectionsArray[ ulConnectionsArrayLength ].usLocalPort =
|
xMetrics.xTCPSocketList.xTCPList[ i ].usLocalPort;
|
||||||
xMetrics.xTCPSocketList.xTCPList[ ulConnectionsArrayLength ].usLocalPort;
|
pxOutConnectionsArray[ i ].ulRemoteIp =
|
||||||
pxOutConnectionsArray[ ulConnectionsArrayLength ].ulRemoteIp =
|
xMetrics.xTCPSocketList.xTCPList[ i ].ulRemoteIP;
|
||||||
xMetrics.xTCPSocketList.xTCPList[ ulConnectionsArrayLength ].ulRemoteIP;
|
pxOutConnectionsArray[ i ].usRemotePort =
|
||||||
pxOutConnectionsArray[ ulConnectionsArrayLength ].usRemotePort =
|
xMetrics.xTCPSocketList.xTCPList[ i ].usRemotePort;
|
||||||
xMetrics.xTCPSocketList.xTCPList[ ulConnectionsArrayLength ].usRemotePort;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,8 @@
|
||||||
#ifndef METRICS_COLLECTOR_H_
|
#ifndef METRICS_COLLECTOR_H_
|
||||||
#define METRICS_COLLECTOR_H_
|
#define METRICS_COLLECTOR_H_
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Return codes from metrics collector APIs.
|
* @brief Return codes from metrics collector APIs.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -166,9 +166,9 @@ static eReportBuilderStatus prvWritePortsArray( char * pcBuffer,
|
||||||
uint32_t ulOpenPortsArrayLength,
|
uint32_t ulOpenPortsArrayLength,
|
||||||
uint32_t * pulOutCharsWritten )
|
uint32_t * pulOutCharsWritten )
|
||||||
{
|
{
|
||||||
char * pCurrentWritePos = pcBuffer;
|
char * pcCurrentWritePos = pcBuffer;
|
||||||
uint32_t i, ulRemainingBufferLength = ulBufferLength;
|
uint32_t i, ulRemainingBufferLength = ulBufferLength;
|
||||||
uint32_t ulCharactersWritten;
|
int32_t ulCharactersWritten;
|
||||||
eReportBuilderStatus eStatus = eReportBuilderSuccess;
|
eReportBuilderStatus eStatus = eReportBuilderSuccess;
|
||||||
|
|
||||||
configASSERT( pcBuffer != NULL );
|
configASSERT( pcBuffer != NULL );
|
||||||
|
|
@ -178,9 +178,9 @@ static eReportBuilderStatus prvWritePortsArray( char * pcBuffer,
|
||||||
/* Write the JSON array open marker. */
|
/* Write the JSON array open marker. */
|
||||||
if( ulRemainingBufferLength > 1 )
|
if( ulRemainingBufferLength > 1 )
|
||||||
{
|
{
|
||||||
*pCurrentWritePos = reportbuilderJSON_ARRAY_OPEN_MARKER;
|
*pcCurrentWritePos = reportbuilderJSON_ARRAY_OPEN_MARKER;
|
||||||
ulRemainingBufferLength -= 1;
|
ulRemainingBufferLength -= 1;
|
||||||
pCurrentWritePos += 1;
|
pcCurrentWritePos += 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -190,7 +190,7 @@ static eReportBuilderStatus prvWritePortsArray( char * pcBuffer,
|
||||||
/* Write the array elements. */
|
/* Write the array elements. */
|
||||||
for( i = 0; ( ( i < ulOpenPortsArrayLength ) && ( eStatus == eReportBuilderSuccess ) ); i++ )
|
for( i = 0; ( ( i < ulOpenPortsArrayLength ) && ( eStatus == eReportBuilderSuccess ) ); i++ )
|
||||||
{
|
{
|
||||||
ulCharactersWritten = snprintf( pCurrentWritePos,
|
ulCharactersWritten = snprintf( pcCurrentWritePos,
|
||||||
ulRemainingBufferLength,
|
ulRemainingBufferLength,
|
||||||
reportbuilderJSON_PORT_OBJECT_FORMAT,
|
reportbuilderJSON_PORT_OBJECT_FORMAT,
|
||||||
pusOpenPortsArray[ i ] );
|
pusOpenPortsArray[ i ] );
|
||||||
|
|
@ -203,7 +203,7 @@ static eReportBuilderStatus prvWritePortsArray( char * pcBuffer,
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ulRemainingBufferLength -= ( uint32_t ) ulCharactersWritten;
|
ulRemainingBufferLength -= ( uint32_t ) ulCharactersWritten;
|
||||||
pCurrentWritePos += ulCharactersWritten;
|
pcCurrentWritePos += ulCharactersWritten;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -212,16 +212,16 @@ static eReportBuilderStatus prvWritePortsArray( char * pcBuffer,
|
||||||
/* Discard the last comma. */
|
/* Discard the last comma. */
|
||||||
if( ulOpenPortsArrayLength > 0 )
|
if( ulOpenPortsArrayLength > 0 )
|
||||||
{
|
{
|
||||||
pCurrentWritePos -= 1;
|
pcCurrentWritePos -= 1;
|
||||||
ulRemainingBufferLength += 1;
|
ulRemainingBufferLength += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write the JSON array close marker. */
|
/* Write the JSON array close marker. */
|
||||||
if( ulRemainingBufferLength > 1 )
|
if( ulRemainingBufferLength > 1 )
|
||||||
{
|
{
|
||||||
*pCurrentWritePos = reportbuilderJSON_ARRAY_CLOSE_MARKER;
|
*pcCurrentWritePos = reportbuilderJSON_ARRAY_CLOSE_MARKER;
|
||||||
ulRemainingBufferLength -= 1;
|
ulRemainingBufferLength -= 1;
|
||||||
pCurrentWritePos += 1;
|
pcCurrentWritePos += 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -244,9 +244,9 @@ static eReportBuilderStatus prvWriteConnectionsArray( char * pcBuffer,
|
||||||
uint32_t ulConnectionsArrayLength,
|
uint32_t ulConnectionsArrayLength,
|
||||||
uint32_t * pulOutCharsWritten )
|
uint32_t * pulOutCharsWritten )
|
||||||
{
|
{
|
||||||
char * pCurrentWritePos = pcBuffer;
|
char * pcCurrentWritePos = pcBuffer;
|
||||||
uint32_t i, ulRemainingBufferLength = ulBufferLength;
|
uint32_t i, ulRemainingBufferLength = ulBufferLength;
|
||||||
uint32_t ulCharactersWritten;
|
int32_t ulCharactersWritten;
|
||||||
eReportBuilderStatus eStatus = eReportBuilderSuccess;
|
eReportBuilderStatus eStatus = eReportBuilderSuccess;
|
||||||
const Connection_t * pxConn;
|
const Connection_t * pxConn;
|
||||||
|
|
||||||
|
|
@ -257,9 +257,9 @@ static eReportBuilderStatus prvWriteConnectionsArray( char * pcBuffer,
|
||||||
/* Write the JSON array open marker. */
|
/* Write the JSON array open marker. */
|
||||||
if( ulRemainingBufferLength > 1 )
|
if( ulRemainingBufferLength > 1 )
|
||||||
{
|
{
|
||||||
*pCurrentWritePos = reportbuilderJSON_ARRAY_OPEN_MARKER;
|
*pcCurrentWritePos = reportbuilderJSON_ARRAY_OPEN_MARKER;
|
||||||
ulRemainingBufferLength -= 1;
|
ulRemainingBufferLength -= 1;
|
||||||
pCurrentWritePos += 1;
|
pcCurrentWritePos += 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -270,7 +270,7 @@ static eReportBuilderStatus prvWriteConnectionsArray( char * pcBuffer,
|
||||||
for( i = 0; ( ( i < ulConnectionsArrayLength ) && ( eStatus == eReportBuilderSuccess ) ); i++ )
|
for( i = 0; ( ( i < ulConnectionsArrayLength ) && ( eStatus == eReportBuilderSuccess ) ); i++ )
|
||||||
{
|
{
|
||||||
pxConn = &( pxConnectionsArray[ i ] );
|
pxConn = &( pxConnectionsArray[ i ] );
|
||||||
ulCharactersWritten = snprintf( pCurrentWritePos,
|
ulCharactersWritten = snprintf( pcCurrentWritePos,
|
||||||
ulRemainingBufferLength,
|
ulRemainingBufferLength,
|
||||||
reportbuilderJSON_CONNECTION_OBJECT_FORMAT,
|
reportbuilderJSON_CONNECTION_OBJECT_FORMAT,
|
||||||
pxConn->usLocalPort,
|
pxConn->usLocalPort,
|
||||||
|
|
@ -288,7 +288,7 @@ static eReportBuilderStatus prvWriteConnectionsArray( char * pcBuffer,
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ulRemainingBufferLength -= ulCharactersWritten;
|
ulRemainingBufferLength -= ulCharactersWritten;
|
||||||
pCurrentWritePos += ulCharactersWritten;
|
pcCurrentWritePos += ulCharactersWritten;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -297,16 +297,16 @@ static eReportBuilderStatus prvWriteConnectionsArray( char * pcBuffer,
|
||||||
/* Discard the last comma. */
|
/* Discard the last comma. */
|
||||||
if( ulConnectionsArrayLength > 0 )
|
if( ulConnectionsArrayLength > 0 )
|
||||||
{
|
{
|
||||||
pCurrentWritePos -= 1;
|
pcCurrentWritePos -= 1;
|
||||||
ulRemainingBufferLength += 1;
|
ulRemainingBufferLength += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write the JSON array close marker. */
|
/* Write the JSON array close marker. */
|
||||||
if( ulRemainingBufferLength > 1 )
|
if( ulRemainingBufferLength > 1 )
|
||||||
{
|
{
|
||||||
*pCurrentWritePos = reportbuilderJSON_ARRAY_CLOSE_MARKER;
|
*pcCurrentWritePos = reportbuilderJSON_ARRAY_CLOSE_MARKER;
|
||||||
ulRemainingBufferLength -= 1;
|
ulRemainingBufferLength -= 1;
|
||||||
pCurrentWritePos += 1;
|
pcCurrentWritePos += 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -331,14 +331,15 @@ eReportBuilderStatus eGenerateJsonReport( char * pcBuffer,
|
||||||
uint32_t ulReportId,
|
uint32_t ulReportId,
|
||||||
uint32_t * pulOutReportLength )
|
uint32_t * pulOutReportLength )
|
||||||
{
|
{
|
||||||
char * pCurrentWritePos = pcBuffer;
|
char * pcCurrentWritePos = pcBuffer;
|
||||||
uint32_t ulRemainingBufferLength = ulBufferLength, bufferWritten;
|
uint32_t ulRemainingBufferLength = ulBufferLength, bufferWritten;
|
||||||
eReportBuilderStatus eStatus = eReportBuilderSuccess;
|
eReportBuilderStatus eStatus = eReportBuilderSuccess;
|
||||||
uint32_t ulCharactersWritten;
|
int32_t ulCharactersWritten;
|
||||||
|
|
||||||
configASSERT( pcBuffer != NULL );
|
configASSERT( pcBuffer != NULL );
|
||||||
configASSERT( pxMetrics != NULL );
|
configASSERT( pxMetrics != NULL );
|
||||||
configASSERT( pulOutReportLength != NULL );
|
configASSERT( pulOutReportLength != NULL );
|
||||||
|
configASSERT( ulBufferLength != 0 );
|
||||||
|
|
||||||
if( ( pcBuffer == NULL ) ||
|
if( ( pcBuffer == NULL ) ||
|
||||||
( ulBufferLength == 0 ) ||
|
( ulBufferLength == 0 ) ||
|
||||||
|
|
@ -357,7 +358,7 @@ eReportBuilderStatus eGenerateJsonReport( char * pcBuffer,
|
||||||
/* Write part1. */
|
/* Write part1. */
|
||||||
if( eStatus == eReportBuilderSuccess )
|
if( eStatus == eReportBuilderSuccess )
|
||||||
{
|
{
|
||||||
ulCharactersWritten = snprintf( pCurrentWritePos,
|
ulCharactersWritten = snprintf( pcCurrentWritePos,
|
||||||
ulRemainingBufferLength,
|
ulRemainingBufferLength,
|
||||||
reportbuilderJSON_REPORT_FORMAT_PART1,
|
reportbuilderJSON_REPORT_FORMAT_PART1,
|
||||||
ulReportId,
|
ulReportId,
|
||||||
|
|
@ -372,14 +373,14 @@ eReportBuilderStatus eGenerateJsonReport( char * pcBuffer,
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ulRemainingBufferLength -= ulCharactersWritten;
|
ulRemainingBufferLength -= ulCharactersWritten;
|
||||||
pCurrentWritePos += ulCharactersWritten;
|
pcCurrentWritePos += ulCharactersWritten;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write TCP ports array. */
|
/* Write TCP ports array. */
|
||||||
if( eStatus == eReportBuilderSuccess )
|
if( eStatus == eReportBuilderSuccess )
|
||||||
{
|
{
|
||||||
eStatus = prvWritePortsArray( pCurrentWritePos,
|
eStatus = prvWritePortsArray( pcCurrentWritePos,
|
||||||
ulRemainingBufferLength,
|
ulRemainingBufferLength,
|
||||||
pxMetrics->pusOpenTcpPortsArray,
|
pxMetrics->pusOpenTcpPortsArray,
|
||||||
pxMetrics->ulOpenTcpPortsArrayLength,
|
pxMetrics->ulOpenTcpPortsArrayLength,
|
||||||
|
|
@ -387,7 +388,7 @@ eReportBuilderStatus eGenerateJsonReport( char * pcBuffer,
|
||||||
|
|
||||||
if( eStatus == eReportBuilderSuccess )
|
if( eStatus == eReportBuilderSuccess )
|
||||||
{
|
{
|
||||||
pCurrentWritePos += bufferWritten;
|
pcCurrentWritePos += bufferWritten;
|
||||||
ulRemainingBufferLength -= bufferWritten;
|
ulRemainingBufferLength -= bufferWritten;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -399,7 +400,7 @@ eReportBuilderStatus eGenerateJsonReport( char * pcBuffer,
|
||||||
/* Write part2. */
|
/* Write part2. */
|
||||||
if( eStatus == eReportBuilderSuccess )
|
if( eStatus == eReportBuilderSuccess )
|
||||||
{
|
{
|
||||||
ulCharactersWritten = snprintf( pCurrentWritePos,
|
ulCharactersWritten = snprintf( pcCurrentWritePos,
|
||||||
ulRemainingBufferLength,
|
ulRemainingBufferLength,
|
||||||
reportbuilderJSON_REPORT_FORMAT_PART2,
|
reportbuilderJSON_REPORT_FORMAT_PART2,
|
||||||
pxMetrics->ulOpenTcpPortsArrayLength );
|
pxMetrics->ulOpenTcpPortsArrayLength );
|
||||||
|
|
@ -412,14 +413,14 @@ eReportBuilderStatus eGenerateJsonReport( char * pcBuffer,
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ulRemainingBufferLength -= ulCharactersWritten;
|
ulRemainingBufferLength -= ulCharactersWritten;
|
||||||
pCurrentWritePos += ulCharactersWritten;
|
pcCurrentWritePos += ulCharactersWritten;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write UDP ports array. */
|
/* Write UDP ports array. */
|
||||||
if( eStatus == eReportBuilderSuccess )
|
if( eStatus == eReportBuilderSuccess )
|
||||||
{
|
{
|
||||||
eStatus = prvWritePortsArray( pCurrentWritePos,
|
eStatus = prvWritePortsArray( pcCurrentWritePos,
|
||||||
ulRemainingBufferLength,
|
ulRemainingBufferLength,
|
||||||
pxMetrics->pusOpenUdpPortsArray,
|
pxMetrics->pusOpenUdpPortsArray,
|
||||||
pxMetrics->ulOpenUdpPortsArrayLength,
|
pxMetrics->ulOpenUdpPortsArrayLength,
|
||||||
|
|
@ -427,7 +428,7 @@ eReportBuilderStatus eGenerateJsonReport( char * pcBuffer,
|
||||||
|
|
||||||
if( eStatus == eReportBuilderSuccess )
|
if( eStatus == eReportBuilderSuccess )
|
||||||
{
|
{
|
||||||
pCurrentWritePos += bufferWritten;
|
pcCurrentWritePos += bufferWritten;
|
||||||
ulRemainingBufferLength -= bufferWritten;
|
ulRemainingBufferLength -= bufferWritten;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -439,7 +440,7 @@ eReportBuilderStatus eGenerateJsonReport( char * pcBuffer,
|
||||||
/* Write part3. */
|
/* Write part3. */
|
||||||
if( eStatus == eReportBuilderSuccess )
|
if( eStatus == eReportBuilderSuccess )
|
||||||
{
|
{
|
||||||
ulCharactersWritten = snprintf( pCurrentWritePos,
|
ulCharactersWritten = snprintf( pcCurrentWritePos,
|
||||||
ulRemainingBufferLength,
|
ulRemainingBufferLength,
|
||||||
reportbuilderJSON_REPORT_FORMAT_PART3,
|
reportbuilderJSON_REPORT_FORMAT_PART3,
|
||||||
pxMetrics->ulOpenUdpPortsArrayLength,
|
pxMetrics->ulOpenUdpPortsArrayLength,
|
||||||
|
|
@ -456,14 +457,14 @@ eReportBuilderStatus eGenerateJsonReport( char * pcBuffer,
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ulRemainingBufferLength -= ulCharactersWritten;
|
ulRemainingBufferLength -= ulCharactersWritten;
|
||||||
pCurrentWritePos += ulCharactersWritten;
|
pcCurrentWritePos += ulCharactersWritten;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write connections array. */
|
/* Write connections array. */
|
||||||
if( eStatus == eReportBuilderSuccess )
|
if( eStatus == eReportBuilderSuccess )
|
||||||
{
|
{
|
||||||
eStatus = prvWriteConnectionsArray( pCurrentWritePos,
|
eStatus = prvWriteConnectionsArray( pcCurrentWritePos,
|
||||||
ulRemainingBufferLength,
|
ulRemainingBufferLength,
|
||||||
pxMetrics->pxEstablishedConnectionsArray,
|
pxMetrics->pxEstablishedConnectionsArray,
|
||||||
pxMetrics->ulEstablishedConnectionsArrayLength,
|
pxMetrics->ulEstablishedConnectionsArrayLength,
|
||||||
|
|
@ -471,7 +472,7 @@ eReportBuilderStatus eGenerateJsonReport( char * pcBuffer,
|
||||||
|
|
||||||
if( eStatus == eReportBuilderSuccess )
|
if( eStatus == eReportBuilderSuccess )
|
||||||
{
|
{
|
||||||
pCurrentWritePos += bufferWritten;
|
pcCurrentWritePos += bufferWritten;
|
||||||
ulRemainingBufferLength -= bufferWritten;
|
ulRemainingBufferLength -= bufferWritten;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -483,7 +484,7 @@ eReportBuilderStatus eGenerateJsonReport( char * pcBuffer,
|
||||||
/* Write part4. */
|
/* Write part4. */
|
||||||
if( eStatus == eReportBuilderSuccess )
|
if( eStatus == eReportBuilderSuccess )
|
||||||
{
|
{
|
||||||
ulCharactersWritten = snprintf( pCurrentWritePos,
|
ulCharactersWritten = snprintf( pcCurrentWritePos,
|
||||||
ulRemainingBufferLength,
|
ulRemainingBufferLength,
|
||||||
reportbuilderJSON_REPORT_FORMAT_PART4,
|
reportbuilderJSON_REPORT_FORMAT_PART4,
|
||||||
pxMetrics->ulEstablishedConnectionsArrayLength );
|
pxMetrics->ulEstablishedConnectionsArrayLength );
|
||||||
|
|
@ -496,7 +497,7 @@ eReportBuilderStatus eGenerateJsonReport( char * pcBuffer,
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ulRemainingBufferLength -= ulCharactersWritten;
|
ulRemainingBufferLength -= ulCharactersWritten;
|
||||||
pCurrentWritePos += ulCharactersWritten;
|
pcCurrentWritePos += ulCharactersWritten;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue