Skip to content

Commit 83d1d8b

Browse files
Merge pull request FreeRTOS#3 from FreeRTOS/labs/ipv6_multi
Labs/ipv6 multi merge to fork
2 parents 7174bb7 + d9f6e00 commit 83d1d8b

File tree

16 files changed

+427
-74
lines changed

16 files changed

+427
-74
lines changed

FreeRTOS_DNS.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@
130130
* uxIdentifier is a random identifier for this look-up, uxHostType is the type
131131
* of host wanted, dnsTYPE_A_HOST or dnsTYPE_AAA_HOST, i.e. IPv4 or IPv6 resp.
132132
*/
133-
_static size_t prvCreateDNSMessage( uint8_t * pucUDPPayloadBuffer,
134-
const char * pcHostName,
135-
TickType_t uxIdentifier,
136-
UBaseType_t uxHostType );
133+
static size_t prvCreateDNSMessage( uint8_t * pucUDPPayloadBuffer,
134+
const char * pcHostName,
135+
TickType_t uxIdentifier,
136+
UBaseType_t uxHostType );
137137

138138
/*
139139
* Simple routine that jumps over the NAME field of a resource record.
@@ -149,10 +149,10 @@
149149
* The IP address found will be stored in 'ppxAddressInfo' ( IPv4 or IPv6 ).
150150
* ppxAddressInfo may be NULL if the caller is not interested in the answers.
151151
*/
152-
_static uint32_t prvParseDNSReply( uint8_t * pucUDPPayloadBuffer,
153-
size_t uxBufferLength,
154-
struct freertos_addrinfo ** ppxAddressInfo,
155-
BaseType_t xExpected );
152+
static uint32_t prvParseDNSReply( uint8_t * pucUDPPayloadBuffer,
153+
size_t uxBufferLength,
154+
struct freertos_addrinfo ** ppxAddressInfo,
155+
BaseType_t xExpected );
156156

157157
/*
158158
* Check if hostname is a literal IP-address, check if the host is found in
@@ -1505,10 +1505,10 @@
15051505
* @return Total size of the generated message, which is the space from the last written byte
15061506
* to the beginning of the buffer.
15071507
*/
1508-
_static size_t prvCreateDNSMessage( uint8_t * pucUDPPayloadBuffer,
1509-
const char * pcHostName,
1510-
TickType_t uxIdentifier,
1511-
UBaseType_t uxHostType )
1508+
static size_t prvCreateDNSMessage( uint8_t * pucUDPPayloadBuffer,
1509+
const char * pcHostName,
1510+
TickType_t uxIdentifier,
1511+
UBaseType_t uxHostType )
15121512
{
15131513
DNSMessage_t * pxDNSMessageHeader;
15141514
size_t uxStart, uxIndex;
@@ -1958,10 +1958,10 @@
19581958
* An error code (dnsPARSE_ERROR) if there was an error in the DNS response.
19591959
* 0 if xExpected set to pdFALSE.
19601960
*/
1961-
_static uint32_t prvParseDNSReply( uint8_t * pucUDPPayloadBuffer,
1962-
size_t uxBufferLength,
1963-
struct freertos_addrinfo ** ppxAddressInfo,
1964-
BaseType_t xExpected )
1961+
static uint32_t prvParseDNSReply( uint8_t * pucUDPPayloadBuffer,
1962+
size_t uxBufferLength,
1963+
struct freertos_addrinfo ** ppxAddressInfo,
1964+
BaseType_t xExpected )
19651965
{
19661966
DNSMessage_t * pxDNSMessageHeader;
19671967
/* This pointer is not used to modify anything */

portable/NetworkInterface/STM32Hxx/NetworkInterface.c

Lines changed: 80 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "FreeRTOS_Sockets.h"
4242
#include "FreeRTOS_IP_Private.h"
4343
#include "FreeRTOS_DNS.h"
44+
#include "FreeRTOS_Routing.h"
4445
#include "NetworkBufferManagement.h"
4546
#include "NetworkInterface.h"
4647

@@ -105,6 +106,8 @@ static SemaphoreHandle_t xTransmissionMutex;
105106
static ETH_HandleTypeDef xEthHandle;
106107
static ETH_TxPacketConfig xTxConfig;
107108

109+
static NetworkInterface_t * pxMyInterface = NULL;
110+
108111
/*
109112
* About the section ".ethernet_data" : the DMA wants the descriptors and buffers allocated in the
110113
* RAM3 memory, which can be added to the .LD file as follows::
@@ -170,6 +173,24 @@ static void vClearOptionBit( volatile uint32_t * pulValue,
170173

171174
static size_t uxGetOwnCount( ETH_HandleTypeDef * heth );
172175

176+
/* FreeRTOS+TCP/multi :
177+
* Each network device has 3 access functions:
178+
* - Initialise the device
179+
* - Output a network packet
180+
* - Return the PHY Link-Status (LS)
181+
* They can be defined as static because the function addresses
182+
* addresses will be stored in struct NetworkInterface_t. */
183+
184+
static BaseType_t xSTM32H_NetworkInterfaceInitialise( NetworkInterface_t * pxInterface );
185+
186+
static BaseType_t xSTM32H_NetworkInterfaceOutput( NetworkInterface_t * pxInterface,
187+
NetworkBufferDescriptor_t * const pxBuffer,
188+
BaseType_t xReleaseAfterSend );
189+
190+
static BaseType_t xSTM32H_GetPhyLinkStatus( NetworkInterface_t * pxInterface );
191+
192+
NetworkInterface_t * pxSTM32Hxx_FillInterfaceDescriptor( BaseType_t xEMACIndex,
193+
NetworkInterface_t * pxInterface );
173194
/*-----------------------------------------------------------*/
174195

175196
static EthernetPhy_t xPhyObject;
@@ -205,21 +226,27 @@ static uint8_t * pucGetRXBuffer( size_t uxSize )
205226
}
206227
/*-----------------------------------------------------------*/
207228

208-
BaseType_t xNetworkInterfaceInitialise( void )
229+
static BaseType_t xSTM32H_NetworkInterfaceInitialise( NetworkInterface_t * pxInterface )
209230
{
210231
BaseType_t xResult;
232+
NetworkEndPoint_t * pxEndPoint;
211233
HAL_StatusTypeDef xHalEthInitStatus;
212234
size_t uxIndex = 0;
213235

214236
if( xMacInitStatus == eMACInit )
215237
{
238+
pxMyInterface = pxInterface;
239+
240+
pxEndPoint = FreeRTOS_FirstEndPoint( pxInterface );
241+
configASSERT( pxEndPoint != NULL );
242+
216243
/*
217244
* Initialize ETH Handler
218245
* It assumes that Ethernet GPIO and clock configuration
219246
* are already done in the ETH_MspInit()
220247
*/
221248
xEthHandle.Instance = ETH;
222-
xEthHandle.Init.MACAddr = ( uint8_t * ) FreeRTOS_GetMACAddress();
249+
xEthHandle.Init.MACAddr = ( uint8_t * ) pxEndPoint->xMACAddress.ucBytes;
223250
xEthHandle.Init.MediaInterface = HAL_ETH_RMII_MODE;
224251
xEthHandle.Init.TxDesc = DMATxDscrTab;
225252
xEthHandle.Init.RxDesc = DMARxDscrTab;
@@ -325,7 +352,7 @@ BaseType_t xNetworkInterfaceInitialise( void )
325352
}
326353
/*-----------------------------------------------------------*/
327354

328-
BaseType_t xGetPhyLinkStatus( void )
355+
static BaseType_t xSTM32H_GetPhyLinkStatus( NetworkInterface_t * pxInterface )
329356
{
330357
BaseType_t xReturn;
331358

@@ -342,34 +369,73 @@ BaseType_t xGetPhyLinkStatus( void )
342369
}
343370
/*-----------------------------------------------------------*/
344371

345-
BaseType_t xNetworkInterfaceOutput( NetworkBufferDescriptor_t * const pxDescriptor,
346-
BaseType_t xReleaseAfterSend )
372+
#if ( ipconfigCOMPATIBLE_WITH_SINGLE != 0 )
373+
374+
/* Do not call the following function directly. It is there for downward compatibility.
375+
* The function FreeRTOS_IPInit() will call it to initialice the interface and end-point
376+
* objects. See the description in FreeRTOS_Routing.h. */
377+
NetworkInterface_t * pxFillInterfaceDescriptor( BaseType_t xEMACIndex,
378+
NetworkInterface_t * pxInterface )
379+
{
380+
pxSTM32Hxx_FillInterfaceDescriptor( xEMACIndex, pxInterface );
381+
}
382+
383+
#endif /* ( ipconfigCOMPATIBLE_WITH_SINGLE != 0 ) */
384+
/*-----------------------------------------------------------*/
385+
386+
NetworkInterface_t * pxSTM32Hxx_FillInterfaceDescriptor( BaseType_t xEMACIndex,
387+
NetworkInterface_t * pxInterface )
388+
{
389+
static char pcName[ 17 ];
390+
391+
/* This function pxSTM32Hxx_FillInterfaceDescriptor() adds a network-interface.
392+
* Make sure that the object pointed to by 'pxInterface'
393+
* is declared static or global, and that it will remain to exist. */
394+
395+
snprintf( pcName, sizeof( pcName ), "eth%u", ( unsigned ) xEMACIndex );
396+
397+
memset( pxInterface, '\0', sizeof( *pxInterface ) );
398+
pxInterface->pcName = pcName; /* Just for logging, debugging. */
399+
pxInterface->pvArgument = ( void * ) xEMACIndex; /* Has only meaning for the driver functions. */
400+
pxInterface->pfInitialise = xSTM32H_NetworkInterfaceInitialise;
401+
pxInterface->pfOutput = xSTM32H_NetworkInterfaceOutput;
402+
pxInterface->pfGetPhyLinkStatus = xSTM32H_GetPhyLinkStatus;
403+
404+
FreeRTOS_AddNetworkInterface( pxInterface );
405+
406+
return pxInterface;
407+
}
408+
/*-----------------------------------------------------------*/
409+
410+
static BaseType_t xSTM32H_NetworkInterfaceOutput( NetworkInterface_t * pxInterface,
411+
NetworkBufferDescriptor_t * const pxBuffer,
412+
BaseType_t xReleaseAfterSend )
347413
{
348414
BaseType_t xResult = pdFAIL;
349415
TickType_t xBlockTimeTicks = pdMS_TO_TICKS( 100U );
350416
uint8_t * pucTXBuffer;
351417

352418
#if ( ipconfigZERO_COPY_TX_DRIVER != 0 )
353419
/* Zero-copy method, pass the buffer. */
354-
pucTXBuffer = pxDescriptor->pucEthernetBuffer;
420+
pucTXBuffer = pxBuffer->pucEthernetBuffer;
355421

356422
/* As the buffer is passed to the driver, it must exist.
357423
* The library takes care of this. */
358424
configASSERT( xReleaseAfterSend != pdFALSE );
359425
#else
360426
pucTXBuffer = Tx_Buff[ xEthHandle.TxDescList.CurTxDesc ];
361427
/* The copy method, left here for educational purposes. */
362-
configASSERT( pxDescriptor->xDataLength <= sizeof( Tx_Buff[ 0 ] ) );
428+
configASSERT( pxBuffer->xDataLength <= sizeof( Tx_Buff[ 0 ] ) );
363429
#endif
364430

365431
ETH_BufferTypeDef xTransmitBuffer =
366432
{
367433
.buffer = pucTXBuffer,
368-
.len = pxDescriptor->xDataLength,
434+
.len = pxBuffer->xDataLength,
369435
.next = NULL /* FreeRTOS+TCP does not use linked buffers. */
370436
};
371437
/* This is the total length, which is equal to the buffer. */
372-
xTxConfig.Length = pxDescriptor->xDataLength;
438+
xTxConfig.Length = pxBuffer->xDataLength;
373439
xTxConfig.TxBuffer = &( xTransmitBuffer );
374440

375441
/* This counting semaphore counts the number of free TX DMA descriptors. */
@@ -395,7 +461,7 @@ BaseType_t xNetworkInterfaceOutput( NetworkBufferDescriptor_t * const pxDescript
395461
}
396462
#else
397463
{
398-
memcpy( pucTXBuffer, pxDescriptor->pucEthernetBuffer, pxDescriptor->xDataLength );
464+
memcpy( pucTXBuffer, pxBuffer->pucEthernetBuffer, pxBuffer->xDataLength );
399465

400466
/* A memory barrier to make sure that the outgoing packets has been written
401467
* to the physical memory. */
@@ -418,7 +484,7 @@ BaseType_t xNetworkInterfaceOutput( NetworkBufferDescriptor_t * const pxDescript
418484

419485
if( xReleaseAfterSend != pdFALSE )
420486
{
421-
vReleaseNetworkBufferAndDescriptor( pxDescriptor );
487+
vReleaseNetworkBufferAndDescriptor( pxBuffer );
422488
}
423489

424490
return xResult;
@@ -638,6 +704,9 @@ static BaseType_t prvNetworkInterfaceInput( void )
638704
.pvData = ( void * ) pxReceivedBuffer
639705
};
640706

707+
pxReceivedBuffer->pxInterface = pxMyInterface;
708+
pxReceivedBuffer->pxEndPoint = FreeRTOS_MatchingEndpoint( pxMyInterface, pxReceivedBuffer->pucEthernetBuffer );
709+
641710
/* Send the data to the TCP/IP stack. */
642711
if( xSendEventStructToIPTask( &( xRxEvent ), 0 ) != pdFALSE )
643712
{

test/cbmc/proofs/ARP/ARPProcessPacket/ARPProcessPacket_harness.c

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,55 @@
66
#include "FreeRTOS_IP.h"
77
#include "FreeRTOS_IP_Private.h"
88
#include "FreeRTOS_ARP.h"
9+
#include "FreeRTOS_Routing.h"
10+
11+
/* Global variables accessible throughout the program. Used in adding
12+
* Network interface/endpoint. */
13+
NetworkInterface_t xNetworkInterface1;
14+
NetworkEndPoint_t xEndPoint1;
15+
16+
const uint8_t ucIPAddress2[ 4 ];
17+
const uint8_t ucNetMask2[ 4 ];
18+
const uint8_t ucGatewayAddress2[ 4 ];
19+
const uint8_t ucDNSServerAddress2[ 4 ];
20+
const uint8_t ucMACAddress[ 6 ];
921

1022
void harness()
1123
{
24+
NetworkBufferDescriptor_t xLocalNetworkBufferDescriptor;
1225
ARPPacket_t xARPFrame;
26+
NetworkEndPoint_t xLocalEndPoint;
27+
28+
/* The Ethernet buffer must contain the ARP packet. */
29+
xLocalNetworkBufferDescriptor.pucEthernetBuffer = &xARPFrame;
30+
31+
/* Non-deterministically add an end-point to the descriptor. */
32+
xLocalNetworkBufferDescriptor.pxEndPoint = nondet_bool() ? NULL : &xLocalEndPoint;
33+
34+
/* Assume that the list of interfaces/endpoints is not initialized. */
35+
__CPROVER_assume( pxNetworkInterfaces == NULL );
36+
__CPROVER_assume( pxNetworkEndPoints == NULL );
37+
38+
/* Non-deterministically add a network-interface. */
39+
if( nondet_bool() )
40+
{
41+
/* Add the network interfaces to the list. */
42+
FreeRTOS_AddNetworkInterface( &xNetworkInterface1 );
43+
44+
/* Non-deterministically add an end-point to the network-interface. */
45+
if( nondet_bool() )
46+
{
47+
/* Fill the endpoints and put them in the network interface. */
48+
FreeRTOS_FillEndPoint( &xNetworkInterface1,
49+
&xEndPoint1,
50+
ucIPAddress2,
51+
ucNetMask2,
52+
ucGatewayAddress2,
53+
ucDNSServerAddress2,
54+
ucMACAddress );
55+
}
56+
}
1357

14-
eARPProcessPacket( &xARPFrame );
58+
/* A valid network buffer must be passed to the function under test. */
59+
eARPProcessPacket( &xLocalNetworkBufferDescriptor );
1560
}

test/cbmc/proofs/ARP/ARPProcessPacket/Configurations.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
"CBMCFLAGS":
44
[
55
"--unwind 1",
6-
"--unwindset vARPRefreshCacheEntry.0:7,memcmp.0:17",
6+
"--unwindset vARPRefreshCacheEntry.0:7,memcmp.0:17,FreeRTOS_FindEndPointOnIP_IPv4.0:2",
77
"--nondet-static"
88
],
99
"OBJS":
1010
[
1111
"$(ENTRY)_harness.goto",
12-
"$(FREERTOS_PLUS_TCP)/FreeRTOS_ARP.goto"
12+
"$(FREERTOS_PLUS_TCP)/FreeRTOS_ARP.goto",
13+
"$(FREERTOS_PLUS_TCP)/FreeRTOS_Routing.goto"
1314
],
1415
"DEF":
1516
[

test/cbmc/proofs/ARP/ARPRefreshCacheEntry/ARPRefreshCacheEntry_harness.c

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,62 @@
55
/* FreeRTOS+TCP includes. */
66
#include "FreeRTOS_IP.h"
77
#include "FreeRTOS_ARP.h"
8+
#include "FreeRTOS_Routing.h"
9+
10+
/* Global variables accessible throughout the program. Used in adding
11+
* Network interface/endpoint. */
12+
NetworkInterface_t xNetworkInterface1;
13+
NetworkEndPoint_t xEndPoint1;
14+
15+
const uint8_t ucIPAddress2[ 4 ];
16+
const uint8_t ucNetMask2[ 4 ];
17+
const uint8_t ucGatewayAddress2[ 4 ];
18+
const uint8_t ucDNSServerAddress2[ 4 ];
19+
const uint8_t ucMACAddress[ 6 ];
20+
21+
/** A list of all network end-points. Each element has a next pointer. */
22+
extern struct xNetworkEndPoint * pxNetworkEndPoints;
23+
24+
/** A list of all network interfaces: */
25+
extern struct xNetworkInterface * pxNetworkInterfaces;
826

927
void harness()
1028
{
1129
MACAddress_t xMACAddress;
1230
uint32_t ulIPAddress;
31+
struct xNetworkEndPoint xLocalEndPoint;
32+
struct xNetworkEndPoint * pxLocalEndPointPointer;
33+
MACAddress_t * pxLocalMACPointer;
34+
35+
/* Assume that the list of interfaces/endpoints is not initialized.
36+
* Note: These variables are defined in FreeRTOS_Routing.c in global scope.
37+
* They serve as a list to the network interfaces and the corresponding
38+
* endpoints respectively. And are defined as NULL initially. */
39+
__CPROVER_assume( pxNetworkInterfaces == NULL );
40+
__CPROVER_assume( pxNetworkEndPoints == NULL );
41+
42+
/* Non-deterministically add a network-interface and its endpoint. */
43+
if( nondet_bool() )
44+
{
45+
/* Add the network interfaces to the list. */
46+
FreeRTOS_AddNetworkInterface( &xNetworkInterface1 );
47+
48+
/* Fill the endpoints and put them in the network interface. */
49+
FreeRTOS_FillEndPoint( &xNetworkInterface1,
50+
&xEndPoint1,
51+
ucIPAddress2,
52+
ucNetMask2,
53+
ucGatewayAddress2,
54+
ucDNSServerAddress2,
55+
ucMACAddress );
56+
}
57+
58+
/* Arbitrarily assign a NULL/non-NULL value to the pointer. */
59+
pxLocalEndPointPointer = nondet_bool() ? NULL : &xLocalEndPoint;
60+
61+
/* Arbitrarily assign a NULL/non-NULL value to the pointer. */
62+
pxLocalMACPointer = nondet_bool() ? NULL : &xMACAddress;
1363

14-
vARPRefreshCacheEntry( &xMACAddress, ulIPAddress );
15-
vARPRefreshCacheEntry( NULL, ulIPAddress );
64+
/* Call the function under test. */
65+
vARPRefreshCacheEntry( pxLocalMACPointer, ulIPAddress, pxLocalEndPointPointer );
1666
}

test/cbmc/proofs/ARP/ARPRefreshCacheEntry/Configurations.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"OBJS":
1010
[
1111
"$(ENTRY)_harness.goto",
12-
"$(FREERTOS_PLUS_TCP)/FreeRTOS_ARP.goto"
12+
"$(FREERTOS_PLUS_TCP)/FreeRTOS_ARP.goto",
13+
"$(FREERTOS_PLUS_TCP)/FreeRTOS_Routing.goto"
1314
],
1415
"DEF":
1516
[

0 commit comments

Comments
 (0)