xref: /FreeRTOS-Plus-TCP-v4.0.0/test/unit-test/FreeRTOS_DHCP/FreeRTOS_DHCP_stubs.c (revision 245d5879903cfc6e52a466fc1067fe54f869740c)
1 /* Include Unity header */
2 #include <unity.h>
3 
4 /* Include standard libraries */
5 #include <stdlib.h>
6 #include <string.h>
7 #include <stdint.h>
8 #include "FreeRTOS.h"
9 #include "task.h"
10 #include "list.h"
11 
12 #include "FreeRTOS_IP.h"
13 #include "FreeRTOS_IP_Private.h"
14 
15 struct xNetworkEndPoint * pxNetworkEndPoints = NULL;
16 
17 NetworkInterface_t xInterfaces[ 1 ];
18 
19 DHCPData_t xDHCPData;
20 
21 volatile BaseType_t xInsideInterrupt = pdFALSE;
22 
23 /** @brief The expected IP version and header length coded into the IP header itself. */
24 #define ipIP_VERSION_AND_HEADER_LENGTH_BYTE    ( ( uint8_t ) 0x45 )
25 
26 #define xSizeofUDPBuffer                       300
27 
28 Socket_t xDHCPSocket;
29 extern Socket_t xDHCPv4Socket;
30 
31 eDHCPCallbackPhase_t eStubExpectedDHCPPhase;
32 struct xNetworkEndPoint * pxStubExpectedEndPoint;
33 uint32_t ulStubExpectedIPAddress;
34 eDHCPCallbackAnswer_t eStubExpectedReturn;
35 static uint8_t * ucGenericPtr;
36 static int32_t ulGenericLength;
37 static NetworkBufferDescriptor_t * pxGlobalNetworkBuffer[ 10 ];
38 static uint8_t GlobalBufferCounter = 0;
39 
40 static uint8_t pucUDPBuffer[ xSizeofUDPBuffer ];
41 
42 static uint8_t DHCP_header[] =
43 {
44     dhcpREPLY_OPCODE,       /**< Operation Code: Specifies the general type of message. */
45     0x01,                   /**< Hardware type used on the local network. */
46     0x06,                   /**< Hardware Address Length: Specifies how long hardware
47                              * addresses are in this message. */
48     0x02,                   /**< Hops. */
49     0x01, 0xAB, 0xCD, 0xEF, /**< A 32-bit identification field generated by the client,
50                              * to allow it to match up the request with replies received
51                              * from DHCP servers. */
52     0x01,                   /**< Number of seconds elapsed since a client began an attempt to acquire or renew a lease. */
53     0x00,                   /**< Just one bit used to indicate broadcast. */
54     0xC0, 0xA8, 0x00, 0x0A, /**< Client's IP address if it has one or 0 is put in this field. */
55     0x00, 0xAA, 0xAA, 0xAA, /**< The IP address that the server is assigning to the client. */
56     0x00, 0xAA, 0xAA, 0xAA, /**< The DHCP server address that the client should use. */
57     0x00, 0xAA, 0xAA, 0xAA  /**< Gateway IP address in case the server client are on different subnets. */
58 };
59 
60 UDPPacketHeader_t xDefaultPartUDPPacketHeader =
61 {
62     /* .ucBytes : */
63     {
64         0x11, 0x22, 0x33, 0x44, 0x55, 0x66,  /* Ethernet source MAC address. */
65         0x08, 0x00,                          /* Ethernet frame type. */
66         ipIP_VERSION_AND_HEADER_LENGTH_BYTE, /* ucVersionHeaderLength. */
67         0x00,                                /* ucDifferentiatedServicesCode. */
68         0x00, 0x00,                          /* usLength. */
69         0x00, 0x00,                          /* usIdentification. */
70         0x00, 0x00,                          /* usFragmentOffset. */
71         ipconfigUDP_TIME_TO_LIVE,            /* ucTimeToLive */
72         ipPROTOCOL_UDP,                      /* ucProtocol. */
73         0x00, 0x00,                          /* usHeaderChecksum. */
74         0x00, 0x00, 0x00, 0x00               /* Source IP address. */
75     }
76 };
77 
78 
79 /*
80  * IP-clash detection is currently only used internally. When DHCP doesn't respond, the
81  * driver can try out a random LinkLayer IP address (169.254.x.x).  It will send out a
82  * gratuitous ARP message and, after a period of time, check the variables here below:
83  */
84 #if ( ipconfigARP_USE_CLASH_DETECTION != 0 )
85     /* Becomes non-zero if another device responded to a gratuitous ARP message. */
86     BaseType_t xARPHadIPClash;
87     /* MAC-address of the other device containing the same IP-address. */
88     MACAddress_t xARPClashMacAddress;
89 #endif /* ipconfigARP_USE_CLASH_DETECTION */
90 
91 
92 /** @brief For convenience, a MAC address of all 0xffs is defined const for quick
93  * reference. */
94 const MACAddress_t xBroadcastMACAddress = { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } };
95 
96 /** @brief Structure that stores the netmask, gateway address and DNS server addresses. */
97 NetworkAddressingParameters_t xNetworkAddressing =
98 {
99     0xC0C0C0C0, /* 192.192.192.192 - Default IP address. */
100     0xFFFFFF00, /* 255.255.255.0 - Netmask. */
101     0xC0C0C001, /* 192.192.192.1 - Gateway Address. */
102     0x01020304, /* 1.2.3.4 - DNS server address. */
103     0xC0C0C0FF
104 };              /* 192.192.192.255 - Broadcast address. */
105 
106 /** @brief Structure that stores the netmask, gateway address and DNS server addresses. */
107 NetworkAddressingParameters_t xDefaultAddressing =
108 {
109     0xC0C0C0C0, /* 192.192.192.192 - Default IP address. */
110     0xFFFFFF00, /* 255.255.255.0 - Netmask. */
111     0xC0C0C001, /* 192.192.192.1 - Gateway Address. */
112     0x01020304, /* 1.2.3.4 - DNS server address. */
113     0xC0C0C0FF
114 };
115 
xPortGetMinimumEverFreeHeapSize(void)116 size_t xPortGetMinimumEverFreeHeapSize( void )
117 {
118     return 0;
119 }
120 
121 
xApplicationDNSQueryHook_Multi(struct xNetworkEndPoint * pxEndPoint,const char * pcName)122 BaseType_t xApplicationDNSQueryHook_Multi( struct xNetworkEndPoint * pxEndPoint,
123                                            const char * pcName )
124 {
125 }
126 
pxPortInitialiseStack(StackType_t * pxTopOfStack,StackType_t * pxEndOfStack,TaskFunction_t pxCode,void * pvParameters)127 StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack,
128                                      StackType_t * pxEndOfStack,
129                                      TaskFunction_t pxCode,
130                                      void * pvParameters )
131 {
132 }
133 
ulApplicationGetNextSequenceNumber(uint32_t ulSourceAddress,uint16_t usSourcePort,uint32_t ulDestinationAddress,uint16_t usDestinationPort)134 uint32_t ulApplicationGetNextSequenceNumber( uint32_t ulSourceAddress,
135                                              uint16_t usSourcePort,
136                                              uint32_t ulDestinationAddress,
137                                              uint16_t usDestinationPort )
138 {
139 }
xNetworkInterfaceInitialise(void)140 BaseType_t xNetworkInterfaceInitialise( void )
141 {
142 }
vApplicationIPNetworkEventHook_Multi(eIPCallbackEvent_t eNetworkEvent,struct xNetworkEndPoint * pxEndPoint)143 void vApplicationIPNetworkEventHook_Multi( eIPCallbackEvent_t eNetworkEvent,
144                                            struct xNetworkEndPoint * pxEndPoint )
145 {
146 }
vApplicationDaemonTaskStartupHook(void)147 void vApplicationDaemonTaskStartupHook( void )
148 {
149 }
vApplicationGetTimerTaskMemory(StaticTask_t ** ppxTimerTaskTCBBuffer,StackType_t ** ppxTimerTaskStackBuffer,uint32_t * pulTimerTaskStackSize)150 void vApplicationGetTimerTaskMemory( StaticTask_t ** ppxTimerTaskTCBBuffer,
151                                      StackType_t ** ppxTimerTaskStackBuffer,
152                                      uint32_t * pulTimerTaskStackSize )
153 {
154 }
vPortDeleteThread(void * pvTaskToDelete)155 void vPortDeleteThread( void * pvTaskToDelete )
156 {
157 }
vApplicationIdleHook(void)158 void vApplicationIdleHook( void )
159 {
160 }
vApplicationTickHook(void)161 void vApplicationTickHook( void )
162 {
163 }
ulGetRunTimeCounterValue(void)164 unsigned long ulGetRunTimeCounterValue( void )
165 {
166 }
vPortEndScheduler(void)167 void vPortEndScheduler( void )
168 {
169 }
xPortStartScheduler(void)170 BaseType_t xPortStartScheduler( void )
171 {
172 }
vPortEnterCritical(void)173 void vPortEnterCritical( void )
174 {
175 }
vPortExitCritical(void)176 void vPortExitCritical( void )
177 {
178 }
179 
pvPortMalloc(size_t xWantedSize)180 void * pvPortMalloc( size_t xWantedSize )
181 {
182     return malloc( xWantedSize );
183 }
184 
vPortFree(void * pv)185 void vPortFree( void * pv )
186 {
187     free( pv );
188 }
189 
vPortGenerateSimulatedInterrupt(uint32_t ulInterruptNumber)190 void vPortGenerateSimulatedInterrupt( uint32_t ulInterruptNumber )
191 {
192 }
vPortCloseRunningThread(void * pvTaskToDelete,volatile BaseType_t * pxPendYield)193 void vPortCloseRunningThread( void * pvTaskToDelete,
194                               volatile BaseType_t * pxPendYield )
195 {
196 }
vApplicationGetIdleTaskMemory(StaticTask_t ** ppxIdleTaskTCBBuffer,StackType_t ** ppxIdleTaskStackBuffer,uint32_t * pulIdleTaskStackSize)197 void vApplicationGetIdleTaskMemory( StaticTask_t ** ppxIdleTaskTCBBuffer,
198                                     StackType_t ** ppxIdleTaskStackBuffer,
199                                     uint32_t * pulIdleTaskStackSize )
200 {
201 }
vConfigureTimerForRunTimeStats(void)202 void vConfigureTimerForRunTimeStats( void )
203 {
204 }
205 
206 /*--------------------------------STUB Functions---------------------------------------*/
207 
xStubApplicationDHCPHook_Multi(eDHCPCallbackPhase_t eDHCPPhase,struct xNetworkEndPoint * pxEndPoint,IP_Address_t * pxIPAddress)208 eDHCPCallbackAnswer_t xStubApplicationDHCPHook_Multi( eDHCPCallbackPhase_t eDHCPPhase,
209                                                       struct xNetworkEndPoint * pxEndPoint,
210                                                       IP_Address_t * pxIPAddress )
211 {
212     TEST_ASSERT_EQUAL( eStubExpectedDHCPPhase, eDHCPPhase );
213     TEST_ASSERT_EQUAL( pxStubExpectedEndPoint, pxEndPoint );
214     TEST_ASSERT_EQUAL( ulStubExpectedIPAddress, pxIPAddress->ulIP_IPv4 );
215 
216     return eStubExpectedReturn;
217 }
218 
219 BaseType_t NetworkInterfaceOutputFunction_Stub_Called = 0;
220 
NetworkInterfaceOutputFunction_Stub(struct xNetworkInterface * pxDescriptor,NetworkBufferDescriptor_t * const pxNetworkBuffer,BaseType_t xReleaseAfterSend)221 BaseType_t NetworkInterfaceOutputFunction_Stub( struct xNetworkInterface * pxDescriptor,
222                                                 NetworkBufferDescriptor_t * const pxNetworkBuffer,
223                                                 BaseType_t xReleaseAfterSend )
224 {
225     NetworkInterfaceOutputFunction_Stub_Called++;
226     return 0;
227 }
228 
229 
GetNetworkBuffer(size_t SizeOfEthBuf,long unsigned int xTimeToBlock,int callbacks)230 static NetworkBufferDescriptor_t * GetNetworkBuffer( size_t SizeOfEthBuf,
231                                                      long unsigned int xTimeToBlock,
232                                                      int callbacks )
233 {
234     NetworkBufferDescriptor_t * pxNetworkBuffer = malloc( sizeof( NetworkBufferDescriptor_t ) + ipBUFFER_PADDING ) + ipBUFFER_PADDING;
235 
236     pxNetworkBuffer->pucEthernetBuffer = malloc( SizeOfEthBuf + ipBUFFER_PADDING ) + ipBUFFER_PADDING;
237 
238     /* Ignore the callback count. */
239     ( void ) callbacks;
240     /* Ignore the timeout. */
241     ( void ) xTimeToBlock;
242 
243     /* Set the global network buffer so that memory can be freed later on. */
244     pxGlobalNetworkBuffer[ GlobalBufferCounter++ ] = pxNetworkBuffer;
245 
246     return pxNetworkBuffer;
247 }
248 
ReleaseNetworkBuffer(void)249 static void ReleaseNetworkBuffer( void )
250 {
251     /* Free the ethernet buffer. */
252     free( ( ( uint8_t * ) pxGlobalNetworkBuffer[ --GlobalBufferCounter ]->pucEthernetBuffer ) - ipBUFFER_PADDING );
253     /* Free the network buffer. */
254     free( ( ( uint8_t * ) pxGlobalNetworkBuffer[ GlobalBufferCounter ] ) - ipBUFFER_PADDING );
255 }
256 
ReleaseUDPBuffer(const void * temp,int callbacks)257 static void ReleaseUDPBuffer( const void * temp,
258                               int callbacks )
259 {
260     /* Should just call network buffer. */
261     ReleaseNetworkBuffer();
262 }
263 
RecvFromStub(Socket_t xSocket,void * pvBuffer,size_t uxBufferLength,BaseType_t xFlags,struct freertos_sockaddr * pxSourceAddress,socklen_t * pxSourceAddressLength,int callbacks)264 static int32_t RecvFromStub( Socket_t xSocket,
265                              void * pvBuffer,
266                              size_t uxBufferLength,
267                              BaseType_t xFlags,
268                              struct freertos_sockaddr * pxSourceAddress,
269                              socklen_t * pxSourceAddressLength,
270                              int callbacks )
271 {
272     switch( callbacks )
273     {
274         case 0:
275             memset( pucUDPBuffer, 0, xSizeofUDPBuffer );
276             break;
277 
278         case 1:
279             /* Put in correct DHCP cookie. */
280             ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulDHCPCookie = dhcpCOOKIE;
281             /* Put incorrect DHCP opcode. */
282             ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucOpcode = dhcpREPLY_OPCODE + 10;
283             break;
284     }
285 
286     if( xFlags == FREERTOS_ZERO_COPY )
287     {
288         *( ( uint8_t ** ) pvBuffer ) = pucUDPBuffer;
289     }
290 
291     return xSizeofUDPBuffer;
292 }
293 
294 
FreeRTOS_recvfrom_Generic(Socket_t xSocket,void * pvBuffer,size_t uxBufferLength,BaseType_t xFlags,struct freertos_sockaddr * pxSourceAddress,socklen_t * pxSourceAddressLength,int callbacks)295 static int32_t FreeRTOS_recvfrom_Generic( Socket_t xSocket,
296                                           void * pvBuffer,
297                                           size_t uxBufferLength,
298                                           BaseType_t xFlags,
299                                           struct freertos_sockaddr * pxSourceAddress,
300                                           socklen_t * pxSourceAddressLength,
301                                           int callbacks )
302 {
303     if( xFlags == FREERTOS_ZERO_COPY )
304     {
305         *( ( uint8_t ** ) pvBuffer ) = ucGenericPtr;
306     }
307 
308     return ulGenericLength;
309 }
310 
FreeRTOS_recvfrom_Generic_NullBuffer(Socket_t xSocket,void * pvBuffer,size_t uxBufferLength,BaseType_t xFlags,struct freertos_sockaddr * pxSourceAddress,socklen_t * pxSourceAddressLength,int callbacks)311 static int32_t FreeRTOS_recvfrom_Generic_NullBuffer( Socket_t xSocket,
312                                                      void * pvBuffer,
313                                                      size_t uxBufferLength,
314                                                      BaseType_t xFlags,
315                                                      struct freertos_sockaddr * pxSourceAddress,
316                                                      socklen_t * pxSourceAddressLength,
317                                                      int callbacks )
318 {
319     pvBuffer = NULL;
320     return xSizeofUDPBuffer;
321 }
322 
323 
FreeRTOS_recvfrom_eWaitingOfferRecvfromLessBytesNoTimeout(Socket_t xSocket,void * pvBuffer,size_t uxBufferLength,BaseType_t xFlags,struct freertos_sockaddr * pxSourceAddress,socklen_t * pxSourceAddressLength,int callbacks)324 static int32_t FreeRTOS_recvfrom_eWaitingOfferRecvfromLessBytesNoTimeout( Socket_t xSocket,
325                                                                           void * pvBuffer,
326                                                                           size_t uxBufferLength,
327                                                                           BaseType_t xFlags,
328                                                                           struct freertos_sockaddr * pxSourceAddress,
329                                                                           socklen_t * pxSourceAddressLength,
330                                                                           int callbacks )
331 {
332     if( xFlags == FREERTOS_ZERO_COPY )
333     {
334         *( ( uint8_t ** ) pvBuffer ) = pucUDPBuffer;
335     }
336 
337     memset( pucUDPBuffer, 0, xSizeofUDPBuffer );
338 
339     return sizeof( DHCPMessage_IPv4_t ) - 1;
340 }
341 
FreeRTOS_recvfrom_ResetAndIncorrectStateWithSocketAlreadyCreated_validUDPmessage(Socket_t xSocket,void * pvBuffer,size_t uxBufferLength,BaseType_t xFlags,struct freertos_sockaddr * pxSourceAddress,socklen_t * pxSourceAddressLength,int callbacks)342 static int32_t FreeRTOS_recvfrom_ResetAndIncorrectStateWithSocketAlreadyCreated_validUDPmessage( Socket_t xSocket,
343                                                                                                  void * pvBuffer,
344                                                                                                  size_t uxBufferLength,
345                                                                                                  BaseType_t xFlags,
346                                                                                                  struct freertos_sockaddr * pxSourceAddress,
347                                                                                                  socklen_t * pxSourceAddressLength,
348                                                                                                  int callbacks )
349 {
350     if( xFlags == FREERTOS_ZERO_COPY + FREERTOS_MSG_PEEK )
351     {
352         *( ( uint8_t ** ) pvBuffer ) = pucUDPBuffer;
353     }
354 
355     memset( pucUDPBuffer, 0, xSizeofUDPBuffer );
356     /* Put in correct DHCP cookie. */
357     ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulDHCPCookie = dhcpCOOKIE;
358     ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucOpcode = dhcpREPLY_OPCODE;
359     ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulTransactionID = FreeRTOS_htonl( 0x01ABCDEF );
360 
361     xDHCPv4Socket = NULL;
362     return xSizeofUDPBuffer;
363 }
364 
FreeRTOS_recvfrom_ResetAndIncorrectStateWithSocketAlreadyCreated_validUDPmessage_TwoFlagOptions_nullbytes(Socket_t xSocket,void * pvBuffer,size_t uxBufferLength,BaseType_t xFlags,struct freertos_sockaddr * pxSourceAddress,socklen_t * pxSourceAddressLength,int callbacks)365 static int32_t FreeRTOS_recvfrom_ResetAndIncorrectStateWithSocketAlreadyCreated_validUDPmessage_TwoFlagOptions_nullbytes( Socket_t xSocket,
366                                                                                                                           void * pvBuffer,
367                                                                                                                           size_t uxBufferLength,
368                                                                                                                           BaseType_t xFlags,
369                                                                                                                           struct freertos_sockaddr * pxSourceAddress,
370                                                                                                                           socklen_t * pxSourceAddressLength,
371                                                                                                                           int callbacks )
372 {
373     int32_t lBytes = 0;
374 
375     xDHCPv4Socket = NULL;
376 
377     if( xFlags == FREERTOS_ZERO_COPY + FREERTOS_MSG_PEEK )
378     {
379         *( ( uint8_t ** ) pvBuffer ) = pucUDPBuffer;
380 
381         memset( pucUDPBuffer, 0, xSizeofUDPBuffer );
382         /* Put in correct DHCP cookie. */
383         ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulDHCPCookie = dhcpCOOKIE;
384         ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucOpcode = dhcpREPLY_OPCODE;
385         ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulTransactionID = FreeRTOS_htonl( 0x01ABCDEF );
386 
387         lBytes = xSizeofUDPBuffer;
388     }
389     else
390     {
391         pvBuffer = NULL;
392     }
393 
394     return lBytes;
395 }
396 
FreeRTOS_recvfrom_ResetAndIncorrectStateWithSocketAlreadyCreated_validUDPmessage_TwoFlagOptions_nullbuffer(Socket_t xSocket,void * pvBuffer,size_t uxBufferLength,BaseType_t xFlags,struct freertos_sockaddr * pxSourceAddress,socklen_t * pxSourceAddressLength,int callbacks)397 static int32_t FreeRTOS_recvfrom_ResetAndIncorrectStateWithSocketAlreadyCreated_validUDPmessage_TwoFlagOptions_nullbuffer( Socket_t xSocket,
398                                                                                                                            void * pvBuffer,
399                                                                                                                            size_t uxBufferLength,
400                                                                                                                            BaseType_t xFlags,
401                                                                                                                            struct freertos_sockaddr * pxSourceAddress,
402                                                                                                                            socklen_t * pxSourceAddressLength,
403                                                                                                                            int callbacks )
404 {
405     xDHCPv4Socket = NULL;
406 
407     if( xFlags == FREERTOS_ZERO_COPY + FREERTOS_MSG_PEEK )
408     {
409         *( ( uint8_t ** ) pvBuffer ) = pucUDPBuffer;
410 
411         memset( pucUDPBuffer, 0, xSizeofUDPBuffer );
412         /* Put in correct DHCP cookie. */
413         ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulDHCPCookie = dhcpCOOKIE;
414         ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucOpcode = dhcpREPLY_OPCODE;
415         ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulTransactionID = FreeRTOS_htonl( 0x01ABCDEF );
416     }
417     else
418     {
419         *( ( uint8_t ** ) pvBuffer ) = NULL;
420     }
421 
422     return xSizeofUDPBuffer;
423 }
424 
FreeRTOS_recvfrom_ResetAndIncorrectStateWithSocketAlreadyCreated_validUDPmessage_IncorrectDHCPCookie(Socket_t xSocket,void * pvBuffer,size_t uxBufferLength,BaseType_t xFlags,struct freertos_sockaddr * pxSourceAddress,socklen_t * pxSourceAddressLength,int callbacks)425 static int32_t FreeRTOS_recvfrom_ResetAndIncorrectStateWithSocketAlreadyCreated_validUDPmessage_IncorrectDHCPCookie( Socket_t xSocket,
426                                                                                                                      void * pvBuffer,
427                                                                                                                      size_t uxBufferLength,
428                                                                                                                      BaseType_t xFlags,
429                                                                                                                      struct freertos_sockaddr * pxSourceAddress,
430                                                                                                                      socklen_t * pxSourceAddressLength,
431                                                                                                                      int callbacks )
432 {
433     if( xFlags == FREERTOS_ZERO_COPY + FREERTOS_MSG_PEEK )
434     {
435         *( ( uint8_t ** ) pvBuffer ) = pucUDPBuffer;
436     }
437 
438     memset( pucUDPBuffer, 0, xSizeofUDPBuffer );
439     /* Put in correct DHCP cookie. */
440     ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulDHCPCookie = dhcpBROADCAST;
441     ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucOpcode = dhcpREPLY_OPCODE;
442     ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulTransactionID = FreeRTOS_htonl( 0x01ABCDEF );
443 
444     xDHCPv4Socket = NULL;
445     return xSizeofUDPBuffer;
446 }
447 
FreeRTOS_recvfrom_ResetAndIncorrectStateWithSocketAlreadyCreated_validUDPmessage_IncorrectOpCode(Socket_t xSocket,void * pvBuffer,size_t uxBufferLength,BaseType_t xFlags,struct freertos_sockaddr * pxSourceAddress,socklen_t * pxSourceAddressLength,int callbacks)448 static int32_t FreeRTOS_recvfrom_ResetAndIncorrectStateWithSocketAlreadyCreated_validUDPmessage_IncorrectOpCode( Socket_t xSocket,
449                                                                                                                  void * pvBuffer,
450                                                                                                                  size_t uxBufferLength,
451                                                                                                                  BaseType_t xFlags,
452                                                                                                                  struct freertos_sockaddr * pxSourceAddress,
453                                                                                                                  socklen_t * pxSourceAddressLength,
454                                                                                                                  int callbacks )
455 {
456     if( xFlags == FREERTOS_ZERO_COPY + FREERTOS_MSG_PEEK )
457     {
458         *( ( uint8_t ** ) pvBuffer ) = pucUDPBuffer;
459     }
460 
461     memset( pucUDPBuffer, 0, xSizeofUDPBuffer );
462     /* Put in correct DHCP cookie. */
463     ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulDHCPCookie = dhcpCOOKIE;
464     ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucOpcode = dhcpREQUEST_OPCODE;
465     ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulTransactionID = FreeRTOS_htonl( 0x01ABCDEF );
466 
467     xDHCPv4Socket = NULL;
468     return xSizeofUDPBuffer;
469 }
470 
FreeRTOS_recvfrom_eWaitingOfferRecvfromSucceedsFalseCookieNoTimeout(Socket_t xSocket,void * pvBuffer,size_t uxBufferLength,BaseType_t xFlags,struct freertos_sockaddr * pxSourceAddress,socklen_t * pxSourceAddressLength,int callbacks)471 static int32_t FreeRTOS_recvfrom_eWaitingOfferRecvfromSucceedsFalseCookieNoTimeout( Socket_t xSocket,
472                                                                                     void * pvBuffer,
473                                                                                     size_t uxBufferLength,
474                                                                                     BaseType_t xFlags,
475                                                                                     struct freertos_sockaddr * pxSourceAddress,
476                                                                                     socklen_t * pxSourceAddressLength,
477                                                                                     int callbacks )
478 {
479     if( xFlags == FREERTOS_ZERO_COPY )
480     {
481         *( ( uint8_t ** ) pvBuffer ) = pucUDPBuffer;
482     }
483 
484     memset( pucUDPBuffer, 0, xSizeofUDPBuffer );
485     ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulTransactionID = FreeRTOS_htonl( 0x01ABCDEF );
486 
487     return xSizeofUDPBuffer;
488 }
489 
FreeRTOS_recvfrom_eWaitingOfferRecvfromSucceedsFalseOpcodeNoTimeout(Socket_t xSocket,void * pvBuffer,size_t uxBufferLength,BaseType_t xFlags,struct freertos_sockaddr * pxSourceAddress,socklen_t * pxSourceAddressLength,int callbacks)490 static int32_t FreeRTOS_recvfrom_eWaitingOfferRecvfromSucceedsFalseOpcodeNoTimeout( Socket_t xSocket,
491                                                                                     void * pvBuffer,
492                                                                                     size_t uxBufferLength,
493                                                                                     BaseType_t xFlags,
494                                                                                     struct freertos_sockaddr * pxSourceAddress,
495                                                                                     socklen_t * pxSourceAddressLength,
496                                                                                     int callbacks )
497 {
498     if( xFlags == FREERTOS_ZERO_COPY )
499     {
500         *( ( uint8_t ** ) pvBuffer ) = pucUDPBuffer;
501     }
502 
503     memset( pucUDPBuffer, 0, xSizeofUDPBuffer );
504     /* Put in correct DHCP cookie. */
505     ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulDHCPCookie = dhcpCOOKIE;
506 
507     return xSizeofUDPBuffer;
508 }
509 
FreeRTOS_recvfrom_eWaitingOfferRecvfromSucceedsCorrectCookieAndOpcodeNoTimeout(Socket_t xSocket,void * pvBuffer,size_t uxBufferLength,BaseType_t xFlags,struct freertos_sockaddr * pxSourceAddress,socklen_t * pxSourceAddressLength,int callbacks)510 static int32_t FreeRTOS_recvfrom_eWaitingOfferRecvfromSucceedsCorrectCookieAndOpcodeNoTimeout( Socket_t xSocket,
511                                                                                                void * pvBuffer,
512                                                                                                size_t uxBufferLength,
513                                                                                                BaseType_t xFlags,
514                                                                                                struct freertos_sockaddr * pxSourceAddress,
515                                                                                                socklen_t * pxSourceAddressLength,
516                                                                                                int callbacks )
517 {
518     if( xFlags == FREERTOS_ZERO_COPY )
519     {
520         *( ( uint8_t ** ) pvBuffer ) = pucUDPBuffer;
521     }
522 
523     memset( pucUDPBuffer, 0, xSizeofUDPBuffer );
524     /* Put in correct DHCP cookie. */
525     ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulDHCPCookie = dhcpCOOKIE;
526     /* Put in correct DHCP opcode. */
527     ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucOpcode = dhcpREPLY_OPCODE;
528 
529     return xSizeofUDPBuffer;
530 }
531 
FreeRTOS_recvfrom_eWaitingOfferRecvfromSuccessCorrectTxID(Socket_t xSocket,void * pvBuffer,size_t uxBufferLength,BaseType_t xFlags,struct freertos_sockaddr * pxSourceAddress,socklen_t * pxSourceAddressLength,int callbacks)532 static int32_t FreeRTOS_recvfrom_eWaitingOfferRecvfromSuccessCorrectTxID( Socket_t xSocket,
533                                                                           void * pvBuffer,
534                                                                           size_t uxBufferLength,
535                                                                           BaseType_t xFlags,
536                                                                           struct freertos_sockaddr * pxSourceAddress,
537                                                                           socklen_t * pxSourceAddressLength,
538                                                                           int callbacks )
539 {
540     if( xFlags == FREERTOS_ZERO_COPY )
541     {
542         *( ( uint8_t ** ) pvBuffer ) = pucUDPBuffer;
543     }
544 
545     memset( pucUDPBuffer, 0, xSizeofUDPBuffer );
546     /* Put in correct DHCP cookie. */
547     ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulDHCPCookie = dhcpCOOKIE;
548     /* Put in correct DHCP opcode. */
549     ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucOpcode = dhcpREPLY_OPCODE;
550     /* Put in correct DHCP Tx ID. */
551     ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulTransactionID = FreeRTOS_htonl( xDHCPData.ulTransactionId );
552 
553     return xSizeofUDPBuffer;
554 }
555 
FreeRTOS_recvfrom_eWaitingOfferRecvfromSuccess_CorrectAddrType(Socket_t xSocket,void * pvBuffer,size_t uxBufferLength,BaseType_t xFlags,struct freertos_sockaddr * pxSourceAddress,socklen_t * pxSourceAddressLength,int callbacks)556 static int32_t FreeRTOS_recvfrom_eWaitingOfferRecvfromSuccess_CorrectAddrType( Socket_t xSocket,
557                                                                                void * pvBuffer,
558                                                                                size_t uxBufferLength,
559                                                                                BaseType_t xFlags,
560                                                                                struct freertos_sockaddr * pxSourceAddress,
561                                                                                socklen_t * pxSourceAddressLength,
562                                                                                int callbacks )
563 {
564     if( xFlags == FREERTOS_ZERO_COPY )
565     {
566         *( ( uint8_t ** ) pvBuffer ) = pucUDPBuffer;
567     }
568 
569     memset( pucUDPBuffer, 0, xSizeofUDPBuffer );
570     /* Put in correct DHCP cookie. */
571     ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulDHCPCookie = dhcpCOOKIE;
572     /* Put in correct DHCP opcode. */
573     ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucOpcode = dhcpREPLY_OPCODE;
574     /* Put in correct DHCP Tx ID. */
575     ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulTransactionID = FreeRTOS_htonl( xDHCPData.ulTransactionId );
576     /* Put in address type as ethernet. */
577     ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucAddressType = ( uint8_t ) dhcpADDRESS_TYPE_ETHERNET;
578 
579     return xSizeofUDPBuffer;
580 }
581 
FreeRTOS_recvfrom_eWaitingOfferRecvfromSuccess_CorrectAddrLen(Socket_t xSocket,void * pvBuffer,size_t uxBufferLength,BaseType_t xFlags,struct freertos_sockaddr * pxSourceAddress,socklen_t * pxSourceAddressLength,int callbacks)582 static int32_t FreeRTOS_recvfrom_eWaitingOfferRecvfromSuccess_CorrectAddrLen( Socket_t xSocket,
583                                                                               void * pvBuffer,
584                                                                               size_t uxBufferLength,
585                                                                               BaseType_t xFlags,
586                                                                               struct freertos_sockaddr * pxSourceAddress,
587                                                                               socklen_t * pxSourceAddressLength,
588                                                                               int callbacks )
589 {
590     if( xFlags == FREERTOS_ZERO_COPY )
591     {
592         *( ( uint8_t ** ) pvBuffer ) = pucUDPBuffer;
593     }
594 
595     memset( pucUDPBuffer, 0, xSizeofUDPBuffer );
596     /* Put in correct DHCP cookie. */
597     ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulDHCPCookie = dhcpCOOKIE;
598     /* Put in correct DHCP opcode. */
599     ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucOpcode = dhcpREPLY_OPCODE;
600     /* Put in correct DHCP Tx ID. */
601     ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulTransactionID = FreeRTOS_htonl( xDHCPData.ulTransactionId );
602     /* Put in address type as ethernet. */
603     ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucAddressType = ( uint8_t ) dhcpADDRESS_TYPE_ETHERNET;
604     /* Put in correct address length. */
605     ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucAddressLength = ( uint8_t ) dhcpETHERNET_ADDRESS_LENGTH;
606     ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulYourIPAddress_yiaddr = 0xFFFFFFFF;
607 
608     return xSizeofUDPBuffer;
609 }
610 
FreeRTOS_recvfrom_eWaitingOfferRecvfromSuccess_LocalHostAddr(Socket_t xSocket,void * pvBuffer,size_t uxBufferLength,BaseType_t xFlags,struct freertos_sockaddr * pxSourceAddress,socklen_t * pxSourceAddressLength,int callbacks)611 static int32_t FreeRTOS_recvfrom_eWaitingOfferRecvfromSuccess_LocalHostAddr( Socket_t xSocket,
612                                                                              void * pvBuffer,
613                                                                              size_t uxBufferLength,
614                                                                              BaseType_t xFlags,
615                                                                              struct freertos_sockaddr * pxSourceAddress,
616                                                                              socklen_t * pxSourceAddressLength,
617                                                                              int callbacks )
618 {
619     if( xFlags == FREERTOS_ZERO_COPY )
620     {
621         *( ( uint8_t ** ) pvBuffer ) = pucUDPBuffer;
622     }
623 
624     memset( pucUDPBuffer, 0, xSizeofUDPBuffer );
625     /* Put in correct DHCP cookie. */
626     ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulDHCPCookie = dhcpCOOKIE;
627     /* Put in correct DHCP opcode. */
628     ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucOpcode = dhcpREPLY_OPCODE;
629     /* Put in correct DHCP Tx ID. */
630     ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulTransactionID = FreeRTOS_htonl( xDHCPData.ulTransactionId );
631     /* Put in address type as ethernet. */
632     ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucAddressType = ( uint8_t ) dhcpADDRESS_TYPE_ETHERNET;
633     /* Put in correct address length. */
634     ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucAddressLength = ( uint8_t ) dhcpETHERNET_ADDRESS_LENGTH;
635     /* Non local host address. */
636     ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulYourIPAddress_yiaddr = 0x01FFFF7F;
637 
638     return xSizeofUDPBuffer;
639 }
640 
FreeRTOS_recvfrom_eWaitingOfferRecvfromSuccess_NonLocalHostAddr(Socket_t xSocket,void * pvBuffer,size_t uxBufferLength,BaseType_t xFlags,struct freertos_sockaddr * pxSourceAddress,socklen_t * pxSourceAddressLength,int callbacks)641 static int32_t FreeRTOS_recvfrom_eWaitingOfferRecvfromSuccess_NonLocalHostAddr( Socket_t xSocket,
642                                                                                 void * pvBuffer,
643                                                                                 size_t uxBufferLength,
644                                                                                 BaseType_t xFlags,
645                                                                                 struct freertos_sockaddr * pxSourceAddress,
646                                                                                 socklen_t * pxSourceAddressLength,
647                                                                                 int callbacks )
648 {
649     if( xFlags == FREERTOS_ZERO_COPY )
650     {
651         *( ( uint8_t ** ) pvBuffer ) = pucUDPBuffer;
652     }
653 
654     memset( pucUDPBuffer, 0, xSizeofUDPBuffer );
655     /* Put in correct DHCP cookie. */
656     ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulDHCPCookie = dhcpCOOKIE;
657     /* Put in correct DHCP opcode. */
658     ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucOpcode = dhcpREPLY_OPCODE;
659     /* Put in correct DHCP Tx ID. */
660     ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulTransactionID = FreeRTOS_htonl( xDHCPData.ulTransactionId + 1 );
661     /* Put in address type as ethernet. */
662     ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucAddressType = ( uint8_t ) dhcpADDRESS_TYPE_ETHERNET;
663     /* Put in correct address length. */
664     ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucAddressLength = ( uint8_t ) dhcpETHERNET_ADDRESS_LENGTH;
665     /* Non local host address. */
666     ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulYourIPAddress_yiaddr = 0x01FFFF3F;
667 
668     return xSizeofUDPBuffer;
669 }
670 
FreeRTOS_recvfrom_eWaitingOfferRecvfromSuccess_LocalMACAddrNotMatching(Socket_t xSocket,void * pvBuffer,size_t uxBufferLength,BaseType_t xFlags,struct freertos_sockaddr * pxSourceAddress,socklen_t * pxSourceAddressLength,int callbacks)671 static int32_t FreeRTOS_recvfrom_eWaitingOfferRecvfromSuccess_LocalMACAddrNotMatching( Socket_t xSocket,
672                                                                                        void * pvBuffer,
673                                                                                        size_t uxBufferLength,
674                                                                                        BaseType_t xFlags,
675                                                                                        struct freertos_sockaddr * pxSourceAddress,
676                                                                                        socklen_t * pxSourceAddressLength,
677                                                                                        int callbacks )
678 {
679     if( xFlags == FREERTOS_ZERO_COPY )
680     {
681         *( ( uint8_t ** ) pvBuffer ) = pucUDPBuffer;
682     }
683 
684     memset( pucUDPBuffer, 0, xSizeofUDPBuffer );
685     /* Put in correct DHCP cookie. */
686     ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulDHCPCookie = dhcpCOOKIE;
687     /* Put in correct DHCP opcode. */
688     ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucOpcode = dhcpREPLY_OPCODE;
689     /* Put in correct DHCP Tx ID. */
690     ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulTransactionID = FreeRTOS_htonl( xDHCPData.ulTransactionId );
691     /* Put in address type as ethernet. */
692     ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucAddressType = ( uint8_t ) dhcpADDRESS_TYPE_ETHERNET;
693     /* Put in correct address length. */
694     ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ucAddressLength = ( uint8_t ) dhcpETHERNET_ADDRESS_LENGTH;
695     /* Non local host address. */
696     ( ( struct xDHCPMessage_IPv4 * ) pucUDPBuffer )->ulYourIPAddress_yiaddr = 0x01FFFF3F;
697 
698     return xSizeofUDPBuffer;
699 }
700 /*-----------------------------------------------------------*/
701