|
224 | 224 | { |
225 | 225 | FreeRTOS_printf( ( "vDHCPProcess: FreeRTOS_recvfrom returns %d\n", ( int ) lBytes ) ); |
226 | 226 | } |
| 227 | + else if( lBytes >= 0 ) |
| 228 | + { |
| 229 | + vReleaseSinglePacketFromUDPSocket( EP_DHCPData.xDHCPSocket ); |
| 230 | + } |
| 231 | + else |
| 232 | + { |
| 233 | + } |
227 | 234 |
|
228 | 235 | break; |
229 | 236 | } |
|
257 | 264 | pxIterator = NULL; |
258 | 265 | } |
259 | 266 |
|
260 | | - if( pxIterator != NULL ) |
| 267 | + if( ( pxIterator != NULL ) && ( pxIterator->xDHCPData.eDHCPState == pxIterator->xDHCPData.eExpectedState ) ) |
261 | 268 | { |
262 | 269 | /* The second parameter pdTRUE tells to check for a UDP message. */ |
263 | 270 | vDHCPProcessEndPoint( pdFALSE, pdTRUE, pxIterator ); |
|
269 | 276 | } |
270 | 277 | else |
271 | 278 | { |
272 | | - /* Target not found, fetch the message and delete it. */ |
| 279 | + /* Target not found or there is a state mismatch, fetch the message and delete it. */ |
273 | 280 | /* PAss the address of a pointer pucUDPPayload, because zero-copy is used. */ |
274 | 281 | lBytes = FreeRTOS_recvfrom( EP_DHCPData.xDHCPSocket, &( pucUDPPayload ), 0, FREERTOS_ZERO_COPY, NULL, NULL ); |
275 | 282 |
|
276 | 283 | if( ( lBytes > 0 ) && ( pucUDPPayload != NULL ) ) |
277 | 284 | { |
278 | 285 | /* Remove it now, destination not found. */ |
279 | 286 | FreeRTOS_ReleaseUDPPayloadBuffer( pucUDPPayload ); |
280 | | - FreeRTOS_printf( ( "vDHCPProcess: Removed a %d-byte message: target not found\n", ( int ) lBytes ) ); |
| 287 | + |
| 288 | + if( pxIterator == NULL ) |
| 289 | + { |
| 290 | + FreeRTOS_printf( ( "vDHCPProcess: Removed a %d-byte message: target not found\n", ( int ) lBytes ) ); |
| 291 | + } |
| 292 | + else |
| 293 | + { |
| 294 | + FreeRTOS_printf( ( "vDHCPProcess: Wrong state: expected: %d got: %d : ignore\n", |
| 295 | + pxIterator->xDHCPData.eExpectedState, pxIterator->xDHCPData.eDHCPState ) ); |
| 296 | + } |
281 | 297 | } |
282 | 298 | } |
283 | 299 | } |
|
489 | 505 | { |
490 | 506 | /* Give up, start again. */ |
491 | 507 | EP_DHCPData.eDHCPState = eInitialWait; |
| 508 | + |
| 509 | + /* Reset expected state so that DHCP packets from |
| 510 | + * different DHCP servers if available already in the DHCP socket can |
| 511 | + * be processed */ |
| 512 | + EP_DHCPData.eExpectedState = eInitialWait; |
492 | 513 | } |
493 | 514 | } |
494 | 515 | } |
|
992 | 1013 | { |
993 | 1014 | /* Start again. */ |
994 | 1015 | EP_DHCPData.eDHCPState = eInitialWait; |
| 1016 | + |
| 1017 | + /* Reset expected state so that DHCP packets from |
| 1018 | + * different DHCP servers if available already in the DHCP socket can |
| 1019 | + * be processed */ |
| 1020 | + EP_DHCPData.eExpectedState = eInitialWait; |
995 | 1021 | } |
996 | 1022 | } |
997 | 1023 |
|
|
0 commit comments