WIZnet Developer Forum

Malformed DHCP/BOOTP packet

I’m trying to follow the HW stack demo found on old.wiznet.co.kr/microchip/#tab using the Explorer 16 platform with a TWIX5200 PICtail and I’m having trouble issuing a DHCP request.

I select the following options:

#define STACK_USE_UART // Application demo using UART for IP address display and stack configuration #define STACK_USE_DHCP_CLIENT // Dynamic Host Configuration Protocol client for obtaining IP address and other parameters #define STACK_USE_GENERIC_TCP_CLIENT_EXAMPLE // HTTP Client example in GenericTCPClient.c #define STACK_USE_DNS // Domain Name Service Client for resolving hostname strings to IP addresses #define STACK_USE_TCP_PERFORMANCE_TEST // Module for testing TCP TX performance characteristics #define STACK_USE_BERKELEY_API // Berekely Sockets APIs are available
I initialize the following sockets

{TCP_PURPOSE_GENERIC_TCP_CLIENT, TCP_ETH_RAM, W5200_TX_RAM_SIZE, W5200_RX_RAM_SIZE}, {TCP_PURPOSE_TCP_PERFORMANCE_TX, TCP_ETH_RAM, W5200_TX_RAM_SIZE, W5200_RX_RAM_SIZE}, {TCP_PURPOSE_TCP_PERFORMANCE_RX, TCP_ETH_RAM, W5200_TX_RAM_SIZE, W5200_RX_RAM_SIZE}, {TCP_PURPOSE_DEFAULT, TCP_ETH_RAM, W5200_TX_RAM_SIZE, W5200_RX_RAM_SIZE}, {TCP_PURPOSE_BERKELEY_CLIENT, TCP_ETH_RAM, W5200_TX_RAM_SIZE, W5200_RX_RAM_SIZE},
These result in a malformed BOOTP/DHCP packet and consequently, no ip address is assigned as can be seen in the Wireshark capture.

I’ve also attached a Wireshark capture of the same base TCPIP stack library (microchip_solutions_v2013-06-15) using the ETH97 hardware which shows a successful DHCP exchange.

Note that in the DHCP.h file, I have

#define DHCP_SERVER_PORT                (67u)

After SM_DHCP_GET_SOCKET state the UDPSocketInfo remote port is correct but the Wireshark log shows 0.

Please advise on how to obtain an IP address from a DHCP server using the W5200 HW stack.

Thank you.



Hi,
I do not know the hardware you are using, but I imagine it is for a 16-bit MPU right ?
If so, the problem that occurred to me is the alignment of different type values within the structure as a request sent to the server.
I had already spoken here [url]Problems while compiling dhcp.c file] (for W5500 but DHCP and DNS examples is very similar and I can also extend to W5100 device) and I pointed out how the structure that contains values of different length (bytes with ushorts and uintegers) is somehow bad optimized by the compiler.
Perhaps there is a compiler directive that prevents it but I have solved using the structure until the sending and instead of passing the structure to the function for fits the transmission buffer, read it and put every single byte that contains in order to maintain the expected sequence.
This change is viable on the sources for different compilers without imposing compilation options or other and this stratagem worked for both PIC24 and PIC32.
Let me know if it’s your case.

I appreciate the interest and comments. The code I am running, cited in the original post, was developed and published by Wiznet for Microchip. It’s still sold and supported:
http://www.microchip.com/Developmenttools/ProductDetails.aspx?PartNO=TWIZ5200

They started with the Microchip TCPIP software stack (which operates correctly with Microchips Ethernet controller). This stack was modified by Wiznet to take advantage of, and use, the W5200’s internal hardware stack. It is this build that fails on my PIC32.

The published package is well documented, with step by step instructions. I originally tried to port it to a different platform than the one used in the example, and when I couldn’t get that to work, I bought the Explorer 16, which was used in the video example (DHCP address assigned at time 1:50).
https://www.youtube.com/watch?v=8A4hECN5-6Y

You bring up a good point with the compiler. The example used C30, which is no longer available on Microchips web site (even in the archive section). I am using C32.

I’ll take a look at the packing of the structures.

Take a look at the -O2 optimization option that is enabled by default in the new IDE

Copyright © 2017 WIZnet Co., Ltd. All Rights Reserved.