2 * FreeRTOS+TCP V2.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 /* WinPCap includes. */
\r
33 /* FreeRTOS includes. */
\r
34 #include "FreeRTOS.h"
\r
38 /* FreeRTOS+TCP includes. */
\r
39 #include "FreeRTOS_IP.h"
\r
40 #include "FreeRTOS_IP_Private.h"
\r
41 #include "NetworkBufferManagement.h"
\r
43 /* Thread-safe circular buffers are being used to pass data to and from the PCAP
\r
44 access functions. */
\r
45 #include "Win32-Extensions.h"
\r
46 #include "FreeRTOS_Stream_Buffer.h"
\r
48 /* Sizes of the thread safe circular buffers used to pass data to and from the
\r
49 WinPCAP Windows threads. */
\r
50 #define xSEND_BUFFER_SIZE 32768
\r
51 #define xRECV_BUFFER_SIZE 32768
\r
53 /* If ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES is set to 1, then the Ethernet
\r
54 driver will filter incoming packets and only pass the stack those packets it
\r
55 considers need processing. */
\r
56 #if( ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES == 0 )
\r
57 #define ipCONSIDER_FRAME_FOR_PROCESSING( pucEthernetBuffer ) eProcessBuffer
\r
59 #define ipCONSIDER_FRAME_FOR_PROCESSING( pucEthernetBuffer ) eConsiderFrameForProcessing( ( pucEthernetBuffer ) )
\r
62 /* Used to insert test code only. */
\r
63 #define niDISRUPT_PACKETS 0
\r
65 /*-----------------------------------------------------------*/
\r
68 * Windows threads that are outside of the control of the FreeRTOS simulator are
\r
69 * used to interface with the WinPCAP libraries.
\r
71 DWORD WINAPI prvWinPcapRecvThread( void *pvParam );
\r
72 DWORD WINAPI prvWinPcapSendThread( void *pvParam );
\r
75 * Print out a numbered list of network interfaces that are available on the
\r
78 static pcap_if_t * prvPrintAvailableNetworkInterfaces( void );
\r
81 * Open the network interface. The number of the interface to be opened is set
\r
82 * by the configNETWORK_INTERFACE_TO_USE constant in FreeRTOSConfig.h.
\r
84 static void prvOpenSelectedNetworkInterface( pcap_if_t *pxAllNetworkInterfaces );
\r
85 static void prvOpenInterface( const char *pucName );
\r
88 * Configure the capture filter to allow blocking reads, and to filter out
\r
89 * packets that are not of interest to this demo.
\r
91 static void prvConfigureCaptureBehaviour( void );
\r
94 * A function that simulates Ethernet interrupts by periodically polling the
\r
95 * WinPCap interface for new data.
\r
97 static void prvInterruptSimulatorTask( void *pvParameters );
\r
100 * Create the buffers that are used to pass data between the FreeRTOS simulator
\r
101 * and the Win32 threads that manage WinPCAP.
\r
103 static void prvCreateThreadSafeBuffers( void );
\r
106 * Utility function used to format print messages only.
\r
108 static const char *prvRemoveSpaces( char *pcBuffer, int aBuflen, const char *pcMessage );
\r
110 /*-----------------------------------------------------------*/
\r
112 /* Required by the WinPCap library. */
\r
113 static char cErrorBuffer[ PCAP_ERRBUF_SIZE ];
\r
115 /* An event used to wake up the Win32 thread that sends data through the WinPCAP
\r
117 static void *pvSendEvent = NULL;
\r
119 /* _HT_ made the PCAP interface number configurable through the program's
\r
120 parameters in order to test in different machines. */
\r
121 static BaseType_t xConfigNextworkInterfaceToUse = configNETWORK_INTERFACE_TO_USE;
\r
123 /* Handles to the Windows threads that handle the PCAP IO. */
\r
124 static HANDLE vWinPcapRecvThreadHandle = NULL;
\r
125 static HANDLE vWinPcapSendThreadHandle = NULL;;
\r
127 /* The interface being used by WinPCap. */
\r
128 static pcap_t *pxOpenedInterfaceHandle = NULL;
\r
130 /* Circular buffers used by the PCAP Win32 threads. */
\r
131 static StreamBuffer_t *xSendBuffer = NULL;
\r
132 static StreamBuffer_t *xRecvBuffer = NULL;
\r
134 /* The MAC address initially set to the constants defined in FreeRTOSConfig.h. */
\r
135 extern uint8_t ucMACAddress[ 6 ];
\r
137 /* Logs the number of WinPCAP send failures, for viewing in the debugger only. */
\r
138 static volatile uint32_t ulWinPCAPSendFailures = 0;
\r
140 /*-----------------------------------------------------------*/
\r
142 BaseType_t xNetworkInterfaceInitialise( void )
\r
144 BaseType_t xReturn = pdFALSE;
\r
145 pcap_if_t *pxAllNetworkInterfaces;
\r
147 /* Query the computer the simulation is being executed on to find the
\r
148 network interfaces it has installed. */
\r
149 pxAllNetworkInterfaces = prvPrintAvailableNetworkInterfaces();
\r
151 /* Open the network interface. The number of the interface to be opened is
\r
152 set by the configNETWORK_INTERFACE_TO_USE constant in FreeRTOSConfig.h.
\r
153 Calling this function will set the pxOpenedInterfaceHandle variable. If,
\r
154 after calling this function, pxOpenedInterfaceHandle is equal to NULL, then
\r
155 the interface could not be opened. */
\r
156 if( pxAllNetworkInterfaces != NULL )
\r
158 prvOpenSelectedNetworkInterface( pxAllNetworkInterfaces );
\r
161 if( pxOpenedInterfaceHandle != NULL )
\r
168 /*-----------------------------------------------------------*/
\r
170 static void prvCreateThreadSafeBuffers( void )
\r
172 /* The buffer used to pass data to be transmitted from a FreeRTOS task to
\r
173 the Win32 thread that sends via the WinPCAP library. */
\r
174 if( xSendBuffer == NULL)
\r
176 xSendBuffer = ( StreamBuffer_t * ) malloc( sizeof( *xSendBuffer ) - sizeof( xSendBuffer->ucArray ) + xSEND_BUFFER_SIZE + 1 );
\r
177 configASSERT( xSendBuffer );
\r
178 memset( xSendBuffer, '\0', sizeof( *xSendBuffer ) - sizeof( xSendBuffer->ucArray ) );
\r
179 xSendBuffer->LENGTH = xSEND_BUFFER_SIZE + 1;
\r
182 /* The buffer used to pass received data from the Win32 thread that receives
\r
183 via the WinPCAP library to the FreeRTOS task. */
\r
184 if( xRecvBuffer == NULL)
\r
186 xRecvBuffer = ( StreamBuffer_t * ) malloc( sizeof( *xRecvBuffer ) - sizeof( xRecvBuffer->ucArray ) + xRECV_BUFFER_SIZE + 1 );
\r
187 configASSERT( xRecvBuffer );
\r
188 memset( xRecvBuffer, '\0', sizeof( *xRecvBuffer ) - sizeof( xRecvBuffer->ucArray ) );
\r
189 xRecvBuffer->LENGTH = xRECV_BUFFER_SIZE + 1;
\r
192 /*-----------------------------------------------------------*/
\r
194 BaseType_t xNetworkInterfaceOutput( NetworkBufferDescriptor_t * const pxNetworkBuffer, BaseType_t bReleaseAfterSend )
\r
198 iptraceNETWORK_INTERFACE_TRANSMIT();
\r
199 configASSERT( xIsCallingFromIPTask() == pdTRUE );
\r
201 /* Both the length of the data being sent and the actual data being sent
\r
202 are placed in the thread safe buffer used to pass data between the FreeRTOS
\r
203 tasks and the Win32 thread that sends data via the WinPCAP library. Drop
\r
204 the packet if there is insufficient space in the buffer to hold both. */
\r
205 xSpace = uxStreamBufferGetSpace( xSendBuffer );
\r
207 if( ( pxNetworkBuffer->xDataLength <= ( ipconfigNETWORK_MTU + ipSIZE_OF_ETH_HEADER ) ) &&
\r
208 ( xSpace >= ( pxNetworkBuffer->xDataLength + sizeof( pxNetworkBuffer->xDataLength ) ) ) )
\r
210 /* First write in the length of the data, then write in the data
\r
212 uxStreamBufferAdd( xSendBuffer, 0, ( const uint8_t * ) &( pxNetworkBuffer->xDataLength ), sizeof( pxNetworkBuffer->xDataLength ) );
\r
213 uxStreamBufferAdd( xSendBuffer, 0, ( const uint8_t * ) pxNetworkBuffer->pucEthernetBuffer, pxNetworkBuffer->xDataLength );
\r
217 FreeRTOS_debug_printf( ( "xNetworkInterfaceOutput: send buffers full to store %lu\n", pxNetworkBuffer->xDataLength ) );
\r
220 /* Kick the Tx task in either case in case it doesn't know the buffer is
\r
222 SetEvent( pvSendEvent );
\r
224 /* The buffer has been sent so can be released. */
\r
225 if( bReleaseAfterSend != pdFALSE )
\r
227 vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer );
\r
232 /*-----------------------------------------------------------*/
\r
234 static pcap_if_t * prvPrintAvailableNetworkInterfaces( void )
\r
236 pcap_if_t * pxAllNetworkInterfaces = NULL, *xInterface;
\r
237 int32_t lInterfaceNumber = 1;
\r
238 char cBuffer[ 512 ];
\r
239 static BaseType_t xInvalidInterfaceDetected = pdFALSE;
\r
241 if( xInvalidInterfaceDetected == pdFALSE )
\r
243 if( pcap_findalldevs_ex( PCAP_SRC_IF_STRING, NULL, &pxAllNetworkInterfaces, cErrorBuffer ) == -1 )
\r
245 printf( "Could not obtain a list of network interfaces\n%s\n", cErrorBuffer );
\r
246 pxAllNetworkInterfaces = NULL;
\r
250 printf( "\r\n\r\nThe following network interfaces are available:\r\n\r\n" );
\r
253 if( pxAllNetworkInterfaces != NULL )
\r
255 /* Print out the list of network interfaces. The first in the list
\r
256 is interface '1', not interface '0'. */
\r
257 for( xInterface = pxAllNetworkInterfaces; xInterface != NULL; xInterface = xInterface->next )
\r
259 /* The descriptions of the devices can be full of spaces, clean them
\r
260 a little. printf() can only be used here because the network is not
\r
261 up yet - so no other network tasks will be running. */
\r
262 printf( "Interface %d - %s\n", lInterfaceNumber, prvRemoveSpaces( cBuffer, sizeof( cBuffer ), xInterface->name ) );
\r
263 printf( " (%s)\n", prvRemoveSpaces(cBuffer, sizeof( cBuffer ), xInterface->description ? xInterface->description : "No description" ) );
\r
265 lInterfaceNumber++;
\r
269 if( lInterfaceNumber == 1 )
\r
271 /* The interface number was never incremented, so the above for() loop
\r
272 did not execute meaning no interfaces were found. */
\r
273 printf( " \nNo network interfaces were found.\n" );
\r
274 pxAllNetworkInterfaces = NULL;
\r
277 printf( "\r\nThe interface that will be opened is set by " );
\r
278 printf( "\"configNETWORK_INTERFACE_TO_USE\", which\r\nshould be defined in FreeRTOSConfig.h\r\n" );
\r
280 if( ( xConfigNextworkInterfaceToUse < 1L ) || ( xConfigNextworkInterfaceToUse >= lInterfaceNumber ) )
\r
282 printf( "\r\nERROR: configNETWORK_INTERFACE_TO_USE is set to %d, which is an invalid value.\r\n", xConfigNextworkInterfaceToUse );
\r
283 printf( "Please set configNETWORK_INTERFACE_TO_USE to one of the interface numbers listed above,\r\n" );
\r
284 printf( "then re-compile and re-start the application. Only Ethernet (as opposed to WiFi)\r\n" );
\r
285 printf( "interfaces are supported.\r\n\r\nHALTING\r\n\r\n\r\n" );
\r
286 xInvalidInterfaceDetected = pdTRUE;
\r
288 if( pxAllNetworkInterfaces != NULL )
\r
290 /* Free the device list, as no devices are going to be opened. */
\r
291 pcap_freealldevs( pxAllNetworkInterfaces );
\r
292 pxAllNetworkInterfaces = NULL;
\r
297 printf( "Attempting to open interface number %d.\n", xConfigNextworkInterfaceToUse );
\r
301 return pxAllNetworkInterfaces;
\r
303 /*-----------------------------------------------------------*/
\r
305 static void prvOpenInterface( const char *pucName )
\r
307 static char pucInterfaceName[ 256 ];
\r
309 if( pucName != NULL )
\r
311 strncpy( pucInterfaceName, pucName, sizeof( pucInterfaceName ) );
\r
314 pxOpenedInterfaceHandle = pcap_open( pucInterfaceName, /* The name of the selected interface. */
\r
315 ipTOTAL_ETHERNET_FRAME_SIZE, /* The size of the packet to capture. */
\r
316 PCAP_OPENFLAG_PROMISCUOUS, /* Open in promiscuous mode as the MAC and
\r
317 IP address is going to be "simulated", and
\r
318 not be the real MAC and IP address. This allows
\r
319 traffic to the simulated IP address to be routed
\r
320 to uIP, and traffic to the real IP address to be
\r
321 routed to the Windows TCP/IP stack. */
\r
323 NULL, /* No authentication is required as this is
\r
324 not a remote capture session. */
\r
328 if ( pxOpenedInterfaceHandle == NULL )
\r
330 printf( "\n%s is not supported by WinPcap and cannot be opened\n", pucInterfaceName );
\r
334 /* Configure the capture filter to allow blocking reads, and to filter
\r
335 out packets that are not of interest to this demo. */
\r
336 prvConfigureCaptureBehaviour();
\r
339 /*-----------------------------------------------------------*/
\r
341 static void prvOpenSelectedNetworkInterface( pcap_if_t *pxAllNetworkInterfaces )
\r
343 pcap_if_t *xInterface;
\r
346 /* Walk the list of devices until the selected device is located. */
\r
347 xInterface = pxAllNetworkInterfaces;
\r
348 for( x = 0L; x < ( xConfigNextworkInterfaceToUse - 1L ); x++ )
\r
350 xInterface = xInterface->next;
\r
353 /* Open the selected interface. */
\r
354 prvOpenInterface( xInterface->name );
\r
356 /* The device list is no longer required. */
\r
357 pcap_freealldevs( pxAllNetworkInterfaces );
\r
359 /*-----------------------------------------------------------*/
\r
361 static void prvConfigureCaptureBehaviour( void )
\r
363 struct bpf_program xFilterCode;
\r
364 uint32_t ulNetMask;
\r
366 /* Set up a filter so only the packets of interest are passed to the IP
\r
367 stack. cErrorBuffer is used for convenience to create the string. Don't
\r
368 confuse this with an error message. */
\r
369 sprintf( cErrorBuffer, "broadcast or multicast or ether host %x:%x:%x:%x:%x:%x",
\r
370 ucMACAddress[0], ucMACAddress[1], ucMACAddress[2], ucMACAddress[3], ucMACAddress[4], ucMACAddress[5] );
\r
372 ulNetMask = ( configNET_MASK3 << 24UL ) | ( configNET_MASK2 << 16UL ) | ( configNET_MASK1 << 8L ) | configNET_MASK0;
\r
374 if( pcap_compile( pxOpenedInterfaceHandle, &xFilterCode, cErrorBuffer, 1, ulNetMask ) < 0 )
\r
376 printf( "\nThe packet filter string is invalid\n" );
\r
380 if( pcap_setfilter( pxOpenedInterfaceHandle, &xFilterCode ) < 0 )
\r
382 printf( "\nAn error occurred setting the packet filter.\n" );
\r
386 /* Create the buffers used to pass packets between the FreeRTOS simulator
\r
387 and the Win32 threads that are handling WinPCAP. */
\r
388 prvCreateThreadSafeBuffers();
\r
390 if( pvSendEvent == NULL )
\r
392 /* Create event used to signal the Win32 WinPCAP Tx thread. */
\r
393 pvSendEvent = CreateEvent( NULL, FALSE, TRUE, NULL );
\r
395 /* Create the Win32 thread that handles WinPCAP Rx. */
\r
396 vWinPcapRecvThreadHandle = CreateThread(
\r
397 NULL, /* Pointer to thread security attributes. */
\r
398 0, /* Initial thread stack size, in bytes. */
\r
399 prvWinPcapRecvThread, /* Pointer to thread function. */
\r
400 NULL, /* Argument for new thread. */
\r
401 0, /* Creation flags. */
\r
404 /* Use the cores that are not used by the FreeRTOS tasks. */
\r
405 SetThreadAffinityMask( vWinPcapRecvThreadHandle, ~0x01u );
\r
407 /* Create the Win32 thread that handlers WinPCAP Tx. */
\r
408 vWinPcapSendThreadHandle = CreateThread(
\r
409 NULL, /* Pointer to thread security attributes. */
\r
410 0, /* initial thread stack size, in bytes. */
\r
411 prvWinPcapSendThread, /* Pointer to thread function. */
\r
412 NULL, /* Argument for new thread. */
\r
413 0, /* Creation flags. */
\r
416 /* Use the cores that are not used by the FreeRTOS tasks. */
\r
417 SetThreadAffinityMask( vWinPcapSendThreadHandle, ~0x01u );
\r
419 /* Create a task that simulates an interrupt in a real system. This will
\r
420 block waiting for packets, then send a message to the IP task when data
\r
422 xTaskCreate( prvInterruptSimulatorTask, "MAC_ISR", configMINIMAL_STACK_SIZE, NULL, configMAC_ISR_SIMULATOR_PRIORITY, NULL );
\r
425 /*-----------------------------------------------------------*/
\r
427 /* WinPCAP function. */
\r
428 void pcap_callback( u_char *user, const struct pcap_pkthdr *pkt_header, const u_char *pkt_data )
\r
432 /* THIS IS CALLED FROM A WINDOWS THREAD - DO NOT ATTEMPT ANY FREERTOS CALLS
\r
433 OR TO PRINT OUT MESSAGES HERE. */
\r
435 /* Pass data to the FreeRTOS simulator on a thread safe circular buffer. */
\r
436 if( ( pkt_header->caplen <= ( ipconfigNETWORK_MTU + ipSIZE_OF_ETH_HEADER ) ) &&
\r
437 ( uxStreamBufferGetSpace( xRecvBuffer ) >= ( ( ( size_t ) pkt_header->caplen ) + sizeof( *pkt_header ) ) ) )
\r
439 uxStreamBufferAdd( xRecvBuffer, 0, ( const uint8_t* ) pkt_header, sizeof( *pkt_header ) );
\r
440 uxStreamBufferAdd( xRecvBuffer, 0, ( const uint8_t* ) pkt_data, ( size_t ) pkt_header->caplen );
\r
443 /*-----------------------------------------------------------*/
\r
445 DWORD WINAPI prvWinPcapRecvThread ( void *pvParam )
\r
449 /* THIS IS A WINDOWS THREAD - DO NOT ATTEMPT ANY FREERTOS CALLS OR TO PRINT
\r
450 OUT MESSAGES HERE. */
\r
454 pcap_dispatch( pxOpenedInterfaceHandle, 1, pcap_callback, ( u_char * ) "mydata" );
\r
457 /*-----------------------------------------------------------*/
\r
459 DWORD WINAPI prvWinPcapSendThread( void *pvParam )
\r
462 uint8_t ucBuffer[ ipconfigNETWORK_MTU + ipSIZE_OF_ETH_HEADER ];
\r
463 static char cErrorMessage[ 1024 ];
\r
464 const DWORD xMaxMSToWait = 1000;
\r
466 /* THIS IS A WINDOWS THREAD - DO NOT ATTEMPT ANY FREERTOS CALLS OR TO PRINT
\r
467 OUT MESSAGES HERE. */
\r
469 /* Remove compiler warnings about unused parameters. */
\r
474 /* Wait until notified of something to send. */
\r
475 WaitForSingleObject( pvSendEvent, xMaxMSToWait );
\r
477 /* Is there more than the length value stored in the circular buffer
\r
478 used to pass data from the FreeRTOS simulator into this Win32 thread? */
\r
479 while( uxStreamBufferGetSize( xSendBuffer ) > sizeof( xLength ) )
\r
481 uxStreamBufferGet( xSendBuffer, 0, ( uint8_t * ) &xLength, sizeof( xLength ), pdFALSE );
\r
482 uxStreamBufferGet( xSendBuffer, 0, ( uint8_t* ) ucBuffer, xLength, pdFALSE );
\r
483 if( pcap_sendpacket( pxOpenedInterfaceHandle, ucBuffer, xLength ) != 0 )
\r
485 ulWinPCAPSendFailures++;
\r
490 /*-----------------------------------------------------------*/
\r
492 static void prvInterruptSimulatorTask( void *pvParameters )
\r
494 struct pcap_pkthdr xHeader;
\r
495 static struct pcap_pkthdr *pxHeader;
\r
496 const uint8_t *pucPacketData;
\r
497 uint8_t ucRecvBuffer[ ipconfigNETWORK_MTU + ipSIZE_OF_ETH_HEADER ];
\r
498 NetworkBufferDescriptor_t *pxNetworkBuffer;
\r
499 IPStackEvent_t xRxEvent = { eNetworkRxEvent, NULL };
\r
500 eFrameProcessingResult_t eResult;
\r
502 /* Remove compiler warnings about unused parameters. */
\r
503 ( void ) pvParameters;
\r
507 /* Does the circular buffer used to pass data from the Win32 thread that
\r
508 handles WinPCAP Rx into the FreeRTOS simulator contain another packet? */
\r
509 if( uxStreamBufferGetSize( xRecvBuffer ) > sizeof( xHeader ) )
\r
511 /* Get the next packet. */
\r
512 uxStreamBufferGet( xRecvBuffer, 0, (uint8_t*)&xHeader, sizeof( xHeader ), pdFALSE );
\r
513 uxStreamBufferGet( xRecvBuffer, 0, (uint8_t*)ucRecvBuffer, ( size_t ) xHeader.len, pdFALSE );
\r
514 pucPacketData = ucRecvBuffer;
\r
515 pxHeader = &xHeader;
\r
517 iptraceNETWORK_INTERFACE_RECEIVE();
\r
519 eResult = ipCONSIDER_FRAME_FOR_PROCESSING( pucPacketData );
\r
520 if( eResult == eProcessBuffer )
\r
522 /* Will the data fit into the frame buffer? */
\r
523 if( pxHeader->len <= ipTOTAL_ETHERNET_FRAME_SIZE )
\r
525 /* Obtain a buffer into which the data can be placed. This
\r
526 is only an interrupt simulator, not a real interrupt, so it
\r
527 is ok to call the task level function here, but note that
\r
528 some buffer implementations cannot be called from a real
\r
530 pxNetworkBuffer = pxGetNetworkBufferWithDescriptor( pxHeader->len, 0 );
\r
532 if( pxNetworkBuffer != NULL )
\r
534 memcpy( pxNetworkBuffer->pucEthernetBuffer, pucPacketData, pxHeader->len );
\r
535 pxNetworkBuffer->xDataLength = ( size_t ) pxHeader->len;
\r
537 #if( niDISRUPT_PACKETS == 1 )
\r
539 pxNetworkBuffer = vRxFaultInjection( pxNetworkBuffer, pucPacketData );
\r
541 #endif /* niDISRUPT_PACKETS */
\r
543 if( pxNetworkBuffer != NULL )
\r
545 xRxEvent.pvData = ( void * ) pxNetworkBuffer;
\r
547 /* Data was received and stored. Send a message to
\r
548 the IP task to let it know. */
\r
549 if( xSendEventStructToIPTask( &xRxEvent, ( TickType_t ) 0 ) == pdFAIL )
\r
551 /* The buffer could not be sent to the stack so
\r
552 must be released again. This is only an
\r
553 interrupt simulator, not a real interrupt, so it
\r
554 is ok to use the task level function here, but
\r
555 note no all buffer implementations will allow
\r
556 this function to be executed from a real
\r
558 vReleaseNetworkBufferAndDescriptor( pxNetworkBuffer );
\r
559 iptraceETHERNET_RX_EVENT_LOST();
\r
564 /* The packet was already released or stored inside
\r
565 vRxFaultInjection(). Don't release it here. */
\r
570 iptraceETHERNET_RX_EVENT_LOST();
\r
575 /* Log that a packet was dropped because it would have
\r
576 overflowed the buffer, but there may be more buffers to
\r
583 /* There is no real way of simulating an interrupt. Make sure
\r
584 other tasks can run. */
\r
585 vTaskDelay( configWINDOWS_MAC_INTERRUPT_SIMULATOR_DELAY );
\r
589 /*-----------------------------------------------------------*/
\r
591 static const char *prvRemoveSpaces( char *pcBuffer, int aBuflen, const char *pcMessage )
\r
593 char *pcTarget = pcBuffer;
\r
595 /* Utility function used to formap messages being printed only. */
\r
596 while( ( *pcMessage != 0 ) && ( pcTarget < ( pcBuffer + aBuflen - 1 ) ) )
\r
598 *( pcTarget++ ) = *pcMessage;
\r
600 if( isspace( *pcMessage ) != pdFALSE )
\r
602 while( isspace( *pcMessage ) != pdFALSE )
\r