2 * FreeRTOS Kernel V10.0.0
\r
3 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
\r
6 * this software and associated documentation files (the "Software"), to deal in
\r
7 * the Software without restriction, including without limitation the rights to
\r
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
\r
9 * the Software, and to permit persons to whom the Software is furnished to do so,
\r
10 * subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software. If you wish to use our Amazon
\r
14 * FreeRTOS name, please do so in a fair use way that does not cause confusion.
\r
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
18 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
19 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
23 * http://www.FreeRTOS.org
\r
24 * http://aws.amazon.com/freertos
\r
26 * 1 tab == 4 spaces!
\r
29 /******************************************************************************
\r
31 * See the following URL for information on the commands defined in this file:
\r
32 * http://www.FreeRTOS.org/FreeRTOS-Plus/FreeRTOS_Plus_UDP/Embedded_Ethernet_Examples/Ethernet_Related_CLI_Commands.shtml
\r
34 ******************************************************************************/
\r
37 /* FreeRTOS includes. */
\r
38 #include "FreeRTOS.h"
\r
41 /* Standard includes. */
\r
46 /* FreeRTOS+CLI includes. */
\r
47 #include "FreeRTOS_CLI.h"
\r
49 /* FreeRTOS+UDP includes, just to make the stats available to the CLI
\r
51 #include "FreeRTOS_UDP_IP.h"
\r
52 #include "FreeRTOS_Sockets.h"
\r
55 * Defines a command that prints out IP address information.
\r
57 static BaseType_t prvDisplayIPConfig( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
60 * Defines a command that prints out the gathered demo debug stats.
\r
62 static BaseType_t prvDisplayIPDebugStats( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
65 * Defines a command that sends an ICMP ping request to an IP address.
\r
67 static BaseType_t prvPingCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString );
\r
69 /* Structure that defines the "ip-config" command line command. */
\r
70 static const CLI_Command_Definition_t xIPConfig =
\r
73 "ip-config:\r\n Displays IP address configuration\r\n\r\n",
\r
78 #if configINCLUDE_DEMO_DEBUG_STATS != 0
\r
79 /* Structure that defines the "ip-debug-stats" command line command. */
\r
80 static const CLI_Command_Definition_t xIPDebugStats =
\r
82 "ip-debug-stats", /* The command string to type. */
\r
83 "ip-debug-stats:\r\n Shows some IP stack stats useful for debug - an example only.\r\n\r\n",
\r
84 prvDisplayIPDebugStats, /* The function to run. */
\r
85 0 /* No parameters are expected. */
\r
87 #endif /* configINCLUDE_DEMO_DEBUG_STATS */
\r
89 #if ipconfigSUPPORT_OUTGOING_PINGS == 1
\r
91 /* Structure that defines the "ping" command line command. This takes an IP
\r
92 address or host name and (optionally) the number of bytes to ping as
\r
94 static const CLI_Command_Definition_t xPing =
\r
97 "ping <ipaddress> <optional:bytes to send>:\r\n for example, ping 192.168.0.3 8, or ping www.example.com\r\n\r\n",
\r
98 prvPingCommand, /* The function to run. */
\r
99 -1 /* Ping can take either one or two parameter, so the number of parameters has to be determined by the ping command implementation. */
\r
102 #endif /* ipconfigSUPPORT_OUTGOING_PINGS */
\r
105 /*-----------------------------------------------------------*/
\r
107 void vRegisterUDPCLICommands( void )
\r
109 /* Register all the command line commands defined immediately above. */
\r
110 FreeRTOS_CLIRegisterCommand( &xIPConfig );
\r
112 #if configINCLUDE_DEMO_DEBUG_STATS == 1
\r
114 FreeRTOS_CLIRegisterCommand( &xIPDebugStats );
\r
116 #endif /* configINCLUDE_DEMO_DEBUG_STATS */
\r
118 #if ipconfigSUPPORT_OUTGOING_PINGS == 1
\r
120 FreeRTOS_CLIRegisterCommand( &xPing );
\r
122 #endif /* ipconfigSUPPORT_OUTGOING_PINGS */
\r
124 /*-----------------------------------------------------------*/
\r
126 #if ipconfigSUPPORT_OUTGOING_PINGS == 1
\r
128 static BaseType_t prvPingCommand( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
130 char * pcParameter;
\r
131 BaseType_t lParameterStringLength, xReturn;
\r
132 uint32_t ulIPAddress, ulBytesToPing;
\r
133 const uint32_t ulDefaultBytesToPing = 8UL;
\r
134 char cBuffer[ 16 ];
\r
136 /* Remove compile time warnings about unused parameters, and check the
\r
137 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
138 write buffer length is adequate, so does not check for buffer overflows. */
\r
139 ( void ) pcCommandString;
\r
140 ( void ) xWriteBufferLen;
\r
141 configASSERT( pcWriteBuffer );
\r
143 /* Start with an empty string. */
\r
144 pcWriteBuffer[ 0 ] = 0x00;
\r
146 /* Obtain the number of bytes to ping. */
\r
147 pcParameter = ( char * ) FreeRTOS_CLIGetParameter
\r
149 pcCommandString, /* The command string itself. */
\r
150 2, /* Return the second parameter. */
\r
151 &lParameterStringLength /* Store the parameter string length. */
\r
154 if( pcParameter == NULL )
\r
156 /* The number of bytes was not specified, so default it. */
\r
157 ulBytesToPing = ulDefaultBytesToPing;
\r
161 ulBytesToPing = atol( pcParameter );
\r
164 /* Obtain the IP address string. */
\r
165 pcParameter = ( char * ) FreeRTOS_CLIGetParameter
\r
167 pcCommandString, /* The command string itself. */
\r
168 1, /* Return the first parameter. */
\r
169 &lParameterStringLength /* Store the parameter string length. */
\r
172 /* Sanity check something was returned. */
\r
173 configASSERT( pcParameter );
\r
175 /* Attempt to obtain the IP address. If the first character is not a
\r
176 digit, assume the host name has been passed in. */
\r
177 if( ( *pcParameter >= '0' ) && ( *pcParameter <= '9' ) )
\r
179 ulIPAddress = FreeRTOS_inet_addr( pcParameter );
\r
183 /* Terminate the host name. */
\r
184 pcParameter[ lParameterStringLength ] = 0x00;
\r
186 /* Attempt to resolve host. */
\r
187 ulIPAddress = FreeRTOS_gethostbyname( pcParameter );
\r
190 /* Convert IP address, which may have come from a DNS lookup, to string. */
\r
191 FreeRTOS_inet_ntoa( ulIPAddress, cBuffer );
\r
193 if( ulIPAddress != 0 )
\r
195 xReturn = FreeRTOS_SendPingRequest( ulIPAddress, ( uint16_t ) ulBytesToPing, portMAX_DELAY );
\r
202 if( xReturn == pdFALSE )
\r
204 sprintf( pcWriteBuffer, "%s", "Could not send ping request\r\n" );
\r
208 sprintf( pcWriteBuffer, "Ping sent to %s with identifier %d\r\n", cBuffer, ( int ) xReturn );
\r
213 /*-----------------------------------------------------------*/
\r
215 #endif /* ipconfigSUPPORT_OUTGOING_PINGS */
\r
217 #if configINCLUDE_DEMO_DEBUG_STATS != 0
\r
219 static BaseType_t prvDisplayIPDebugStats( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
221 static BaseType_t xIndex = -1;
\r
222 extern xExampleDebugStatEntry_t xIPTraceValues[];
\r
223 BaseType_t xReturn;
\r
225 /* Remove compile time warnings about unused parameters, and check the
\r
226 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
227 write buffer length is adequate, so does not check for buffer overflows. */
\r
228 ( void ) pcCommandString;
\r
229 ( void ) xWriteBufferLen;
\r
230 configASSERT( pcWriteBuffer );
\r
234 if( xIndex < xExampleDebugStatEntries() )
\r
236 sprintf( pcWriteBuffer, "%s %d\r\n", ( char * ) xIPTraceValues[ xIndex ].pucDescription, ( int ) xIPTraceValues[ xIndex ].ulData );
\r
241 /* Reset the index for the next time it is called. */
\r
244 /* Ensure nothing remains in the write buffer. */
\r
245 pcWriteBuffer[ 0 ] = 0x00;
\r
251 /*-----------------------------------------------------------*/
\r
253 #endif /* configINCLUDE_DEMO_DEBUG_STATS */
\r
255 static BaseType_t prvDisplayIPConfig( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString )
\r
257 static BaseType_t xIndex = 0;
\r
258 BaseType_t xReturn;
\r
259 uint32_t ulAddress;
\r
261 /* Remove compile time warnings about unused parameters, and check the
\r
262 write buffer is not NULL. NOTE - for simplicity, this example assumes the
\r
263 write buffer length is adequate, so does not check for buffer overflows. */
\r
264 ( void ) pcCommandString;
\r
265 ( void ) xWriteBufferLen;
\r
266 configASSERT( pcWriteBuffer );
\r
271 FreeRTOS_GetAddressConfiguration( &ulAddress, NULL, NULL, NULL );
\r
272 sprintf( pcWriteBuffer, "\r\nIP address " );
\r
278 FreeRTOS_GetAddressConfiguration( NULL, &ulAddress, NULL, NULL );
\r
279 sprintf( pcWriteBuffer, "\r\nNet mask " );
\r
285 FreeRTOS_GetAddressConfiguration( NULL, NULL, &ulAddress, NULL );
\r
286 sprintf( pcWriteBuffer, "\r\nGateway address " );
\r
292 FreeRTOS_GetAddressConfiguration( NULL, NULL, NULL, &ulAddress );
\r
293 sprintf( pcWriteBuffer, "\r\nDNS server address " );
\r
300 sprintf( pcWriteBuffer, "\r\n\r\n" );
\r
306 if( ulAddress != 0 )
\r
308 FreeRTOS_inet_ntoa( ulAddress, ( &( pcWriteBuffer[ strlen( pcWriteBuffer ) ] ) ) );
\r
313 /*-----------------------------------------------------------*/
\r