Skip to content

Commit d4ffb9b

Browse files
committed
Return allocated buffer size from vNetworkInterfaceAllocateRAMToBuffers and use it to verify allocation requests when using Buffer Allocation 1
1 parent 28dd66c commit d4ffb9b

File tree

24 files changed

+76
-30
lines changed

24 files changed

+76
-30
lines changed

source/include/NetworkInterface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
*/
4949

5050
/* The following function is defined only when BufferAllocation_1.c is linked in the project. */
51-
void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] );
51+
size_t vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] );
5252

5353
BaseType_t xGetPhyLinkStatus( struct xNetworkInterface * pxInterface );
5454

source/portable/BufferManagement/BufferAllocation_1.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ static NetworkBufferDescriptor_t xNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DES
7070
* packet. No resizing will be done. */
7171
const BaseType_t xBufferAllocFixedSize = pdTRUE;
7272

73+
static size_t xMaxNetworkInterfaceAllocatedSizeBytes;
74+
7375
/* The semaphore used to obtain network buffers. */
7476
static SemaphoreHandle_t xNetworkBufferSemaphore = NULL;
7577

@@ -201,7 +203,7 @@ BaseType_t xNetworkBuffersInitialise( void )
201203
/* Initialise all the network buffers. The buffer storage comes
202204
* from the network interface, and different hardware has different
203205
* requirements. */
204-
vNetworkInterfaceAllocateRAMToBuffers( xNetworkBuffers );
206+
xMaxNetworkInterfaceAllocatedSizeBytes = vNetworkInterfaceAllocateRAMToBuffers( xNetworkBuffers );
205207

206208
for( x = 0U; x < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; x++ )
207209
{
@@ -238,7 +240,7 @@ NetworkBufferDescriptor_t * pxGetNetworkBufferWithDescriptor( size_t xRequestedS
238240
UBaseType_t uxCount;
239241

240242
if( ( xNetworkBufferSemaphore != NULL ) &&
241-
( xRequestedSizeBytes <= ( ipconfigNETWORK_MTU + ipSIZE_OF_ETH_HEADER ) ) )
243+
( xRequestedSizeBytes <= xMaxNetworkInterfaceAllocatedSizeBytes ) )
242244
{
243245
/* If there is a semaphore available, there is a network buffer
244246
* available. */
@@ -429,7 +431,7 @@ UBaseType_t uxGetNumberOfFreeNetworkBuffers( void )
429431
NetworkBufferDescriptor_t * pxResizeNetworkBufferWithDescriptor( NetworkBufferDescriptor_t * pxNetworkBuffer,
430432
size_t xNewSizeBytes )
431433
{
432-
if( xNewSizeBytes <= ( ipconfigNETWORK_MTU + ipSIZE_OF_ETH_HEADER ) )
434+
if( xNewSizeBytes <= xMaxNetworkInterfaceAllocatedSizeBytes )
433435
{
434436
/* In BufferAllocation_1.c all network buffer are allocated with a
435437
* maximum size of 'ipTOTAL_ETHERNET_FRAME_SIZE'.No need to resize the

source/portable/NetworkInterface/ATSAME5x/NetworkInterface.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,9 @@ void xRxCallback( void )
500500
#if ( ipUSE_STATIC_ALLOCATION == 1 )
501501

502502
/* Next provide the vNetworkInterfaceAllocateRAMToBuffers() function, which
503-
* simply fills in the pucEthernetBuffer member of each descriptor. */
504-
void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] )
503+
* simply fills in the pucEthernetBuffer member of each descriptor and returns
504+
* the allocated buffer size. */
505+
size_t vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] )
505506
{
506507
BaseType_t x;
507508

@@ -515,6 +516,9 @@ void xRxCallback( void )
515516
* future versions. */
516517
*( ( uint32_t * ) &ucBuffers[ x ][ 0 ] ) = ( uint32_t ) &( pxNetworkBuffers[ x ] );
517518
}
519+
520+
return ( NETWORK_BUFFER_SIZE - ipBUFFER_PADDING );
521+
518522
}
519523
#endif /* if ( ipUSE_STATIC_ALLOCATION == 1 ) */
520524

source/portable/NetworkInterface/DriverSAM/NetworkInterface.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,7 @@ static void vCheckBuffersAndQueue( void )
14091409
/*-----------------------------------------------------------*/
14101410

14111411
extern uint8_t ucNetworkPackets[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS * NETWORK_BUFFER_SIZE ];
1412-
void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] )
1412+
size_t vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] )
14131413
{
14141414
uint8_t * ucRAMBuffer = ucNetworkPackets;
14151415
uint32_t ulIndex;
@@ -1422,6 +1422,8 @@ void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkB
14221422
}
14231423

14241424
cache_clean_invalidate();
1425+
1426+
return ( NETWORK_BUFFER_SIZE - ipBUFFER_PADDING );
14251427
}
14261428
/*-----------------------------------------------------------*/
14271429

source/portable/NetworkInterface/LPC18xx/NetworkInterface.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ BaseType_t xNetworkInterfaceInitialise( void )
332332

333333
static __attribute__( ( section( "._ramAHB32" ) ) ) uint8_t ucNetworkPackets[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS * niBUFFER_1_PACKET_SIZE ] __attribute__( ( aligned( 32 ) ) );
334334

335-
void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] )
335+
size_t vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] )
336336
{
337337
uint8_t * ucRAMBuffer = ucNetworkPackets;
338338
uint32_t ul;
@@ -343,6 +343,8 @@ void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkB
343343
*( ( unsigned * ) ucRAMBuffer ) = ( unsigned ) ( &( pxNetworkBuffers[ ul ] ) );
344344
ucRAMBuffer += niBUFFER_1_PACKET_SIZE;
345345
}
346+
347+
return (niBUFFER_1_PACKET_SIZE - ipBUFFER_PADDING);
346348
}
347349
/*-----------------------------------------------------------*/
348350

source/portable/NetworkInterface/LPC54018/NetworkInterface.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,11 +372,13 @@ BaseType_t xNetworkInterfaceOutput( NetworkBufferDescriptor_t * const pxNetworkB
372372
/* statically allocate the buffers */
373373
/* allocating them as uint32_t's to force them into word alignment, a requirement of the DMA. */
374374
__ALIGN_BEGIN static uint32_t buffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ][ ( ipBUFFER_PADDING + ENET_RXBUFF_SIZE ) / sizeof( uint32_t ) + 1 ] __ALIGN_END;
375-
void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] )
375+
size_t vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] )
376376
{
377377
for( int x = 0; x < ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS; x++ )
378378
{
379379
pxNetworkBuffers[ x ].pucEthernetBuffer = ( uint8_t * ) &buffers[ x ][ 0 ] + ipBUFFER_PADDING;
380380
buffers[ x ][ 0 ] = ( uint32_t ) &pxNetworkBuffers[ x ];
381381
}
382+
383+
return ENET_RXBUFF_SIZE;
382384
}

source/portable/NetworkInterface/M487/NetworkInterface.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ BaseType_t xNetworkInterfaceOutput( NetworkBufferDescriptor_t * const pxDescript
180180
}
181181

182182

183-
void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] )
183+
size_t vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] )
184184
{
185185
uint8_t * ucRAMBuffer = ucNetworkPackets;
186186
uint32_t ul;
@@ -191,6 +191,8 @@ void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkB
191191
*( ( unsigned * ) ucRAMBuffer ) = ( unsigned ) ( &( pxNetworkBuffers[ ul ] ) );
192192
ucRAMBuffer += niBUFFER_1_PACKET_SIZE;
193193
}
194+
195+
return (niBUFFER_1_PACKET_SIZE - ipBUFFER_PADDING);
194196
}
195197

196198

source/portable/NetworkInterface/MPS2_AN385/NetworkInterface.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ static BaseType_t xMPS2_NetworkInterfaceOutput( NetworkInterface_t * pxInterface
368368
}
369369
/*-----------------------------------------------------------*/
370370

371-
void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] )
371+
size_t vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] )
372372
{
373373
/* FIX ME if you want to use BufferAllocation_1.c, which uses statically
374374
* allocated network buffers. */
@@ -377,6 +377,7 @@ void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkB
377377
* without implementing this function. */
378378
configASSERT( xRxTaskHandle == ( TaskHandle_t ) 1 );
379379
( void ) pxNetworkBuffers;
380+
return 0;
380381
}
381382
/*-----------------------------------------------------------*/
382383

source/portable/NetworkInterface/MPS3_AN552/NetworkInterface.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ static BaseType_t xLAN91C111_NetworkInterfaceOutput( NetworkInterface_t * pxInte
485485
}
486486
/*-----------------------------------------------------------*/
487487

488-
void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] )
488+
size_t vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] )
489489
{
490490
/* FIX ME if you want to use BufferAllocation_1.c, which uses statically
491491
* allocated network buffers. */
@@ -494,6 +494,7 @@ void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkB
494494
* without implementing this function. */
495495
configASSERT( 0 );
496496
( void ) pxNetworkBuffers;
497+
return 0;
497498
}
498499
/*-----------------------------------------------------------*/
499500

source/portable/NetworkInterface/MPS4_CS315/NetworkInterface.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ static BaseType_t xLAN91C111_NetworkInterfaceOutput( NetworkInterface_t * pxInte
485485
}
486486
/*-----------------------------------------------------------*/
487487

488-
void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] )
488+
size_t vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkBuffers[ ipconfigNUM_NETWORK_BUFFER_DESCRIPTORS ] )
489489
{
490490
/* FIX ME if you want to use BufferAllocation_1.c, which uses statically
491491
* allocated network buffers. */
@@ -494,6 +494,7 @@ void vNetworkInterfaceAllocateRAMToBuffers( NetworkBufferDescriptor_t pxNetworkB
494494
* without implementing this function. */
495495
configASSERT( 0 );
496496
( void ) pxNetworkBuffers;
497+
return 0;
497498
}
498499
/*-----------------------------------------------------------*/
499500

0 commit comments

Comments
 (0)