DHCP client constantly sending discover requests, receiving no response, custom eth chip

Resch2061
Posts: 40
Joined: Mon May 01, 2017 1:56 pm

DHCP client constantly sending discover requests, receiving no response, custom eth chip

Postby Resch2061 » Tue Oct 30, 2018 3:11 pm

Hello all, it's me again.

My apologies in advance if this is perhaps not exactly suited for this forum, as it's more about LWIP and TCPIP than the ESP32... Nonetheless, I'm doing this on an ESP32 chip, and I don't really know where else to put it.

As you may have gathered from a previous topic of mine, I'm interested in using a different Ethernet chip. The one I've got my eyes on is an ENC28J60. I've managed to write most of the driver for it, and now I'm working on integrating it with LWIP's TCPIP stack. I've changed quite a few lines in the IDF to make this possible - most noticably within the file tcpip_adapter_lwip.c, which is where the brunt of the TCPIP related code happens.
So far so good - LWIP's TCPIP stack is attempting to send a request nicely, after initializing the chip on the hardware side, integrating it with the existing TCPIP adapter logic, and sending the appropriate events, as you can see in this really lengthy log:

Code: Select all

// ESP32 initialization

I (101) cpu_start: Pro cpu up.
I (101) cpu_start: Single core mode
I (101) heap_init: Initializing. RAM available for dynamic allocation:
D (105) heap_init: New heap initialised at 0x3ffae6e0
I (110) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
D (116) heap_init: New heap initialised at 0x3ffb3fe8
I (121) heap_init: At 3FFB3FE8 len 0002C018 (176 KiB): DRAM
I (127) heap_init: At 3FFE0440 len 00003BC0 (14 KiB): D/IRAM
I (134) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
D (140) heap_init: New heap initialised at 0x40089db8
I (145) heap_init: At 40089DB8 len 00016248 (88 KiB): IRAM
I (152) cpu_start: Pro cpu start user code
D (164) clk: RTC_SLOW_CLK calibration value: 3292902
D (24) intr_alloc: Connected src 46 to int 2 (cpu 0)
D (25) intr_alloc: Connected src 57 to int 3 (cpu 0)
D (25) intr_alloc: Connected src 24 to int 9 (cpu 0)
I (30) cpu_start: Starting scheduler on PRO CPU.
D (35) heap_init: New heap initialised at 0x3ffe0440
D (39) heap_init: New heap initialised at 0x3ffe4350
D (44) intr_alloc: Connected src 16 to int 12 (cpu 0)
D (50) nvs: nvs_flash_init_custom partition=nvs start=9 count=6
netif: netmask of interface  set to 255.0.0.0
netif: GW address of interface  set to 127.0.0.1
netif_set_ipaddr: netif address being changed
netif: IP address of interface  set to 127.0.0.1
netif: added interface lo IP addr 127.0.0.1 netmask 255.0.0.0 gw 127.0.0.1
tcpip_task_hdlxxx : 3ffb8cc4, prio:18,stack:3072

// Initialize ENC28J60 driver

I (86) ENC28J60: Init.
I (270) ENC28J60: Finished initializing. Revision: 6
D (376) event: SYSTEM_EVENT_ETH_START
I (376) MAIN: ETH START
D (376) ENC28J60: Link status changed. New: 1 Old: 0
D (380) ENC28J60: Read mac addr.
D (380) ENC28J60: MAC ADDR 72:4b:2d:b0:3c:b
I (388) MAIN: STARING TCPIP ADAPTER WITH MAC ADDR 72:4b:2d:b0:3c:0b IP 0.0.0.0 // this is happening in the event handler.

// from here, LWIP gets started.

tcpip_thread: API message 0x3ffb7a30
netif: netmask of interface  set to 0.0.0.0
netif: GW address of interface  set to 0.0.0.0
netif: IP address of interface  set to 0.0.0.0
netif: added interface ej IP addr 0.0.0.0 netmask 0.0.0.0 gw 0.0.0.0
D (418) event: SYSTEM_EVENT_ETH_CONNECETED
I (422) MAIN: ETH CONN
tcpip_thread: API message 0x3ffb7a00
netif: netmask of interface ej set to 0.0.0.0
netif: GW address of interface ej set to 0.0.0.0
netif: IP address of interface ej set to 0.0.0.0
netif: setting default interface ej

// back to the tcpip adapter...

D (466) tcpip_adapter: dhcp client init ip/mask/gw to all-0
D (472) tcpip_adapter: if2 start ip lost tmr: enter
D (476) tcpip_adapter: if2 start ip lost tmr: only sta support ip lost timer
dhcp_start(netif=0x3ffbb2c0) ej1
dhcp_start(): starting new DHCP client
dhcp_start(): allocated dhcpdhcp_start(): starting DHCP configuration
dhcp_discover()
transaction id xid(72ae3ca8)
dhcp_discover: making request
dhcp_discover: realloc()ing
dhcp_discover: sendto(DISCOVER, IP_ADDR_BROADCAST, DHCP_SERVER_PORT)
ip4_output_if: ej1

// So the DHCP client gets started, the packet gets made - all good.

ip4_output_if: call netif->output()
etharp_send_ip: sending packet 0x3ffbdcc8
dhcp_discover: deleting()ing
dhcp_discover: SELECTING
dhcp_discover(): set request timeout 1000 msecs
etharp_timer
dhcp_coarse_tmr()
tcpip_thread: CALLBACK 0x3ffb7f4c
D (1379) ENC28J60: Packet queued! Len: 350
D (1380) ENC28J60: Sending 350 bytes - timeout ms: 1000
D (1725) ENC28J60: TX success.

// And boom - it has been sent. I'm seeing the exact same data in Wireshark too, which is good. Now we wait for an answer...

tcpip_thread: PACKET 0x3ffbdd50
etharp_ip_input: updating ETHARP table.
etharp_find_entry: found empty entry 0
etharp_find_entry: no empty entry found and not allowed to recycle
ip4_input: UDP packet to DHCP client port 57621
ip4_input: packet not for us.
But here something goes wrong. While the TCPIP stack appears to be attempting to update the ARP table, it doesn't seem to work, and I'm not quite sure why. Neither does anything happen from here on anymore. I *know* the router I'm connected to supports DHCP, as when I type ipconfig /renew, there's a *lot* of DHCP traffic on Wireshark. The router properly gives me the IP address 192.168.1.249, as well - which we can even see in the last section of the log. Perhaps the router is rejecting the discovery request - I really don't know.

EDIT:
I just saw this happen in my log:

Code: Select all

D (599035) ENC28J60: 1 packets awaiting.
D (599037) ENC28J60: READ 60 BYTES
tcpip_thread: PACKET 0x3ffbb43c
etharp_update_arp_entry: 192.168.1.1 - 00:1e:42:16:b3:72
etharp_find_entry: found empty entry 0
etharp_find_entry: no empty entry found and not allowed to recycle
etharp_arp_input: incoming ARP request
etharp_arp_input: we are unconfigured, ARP request ignored.
Makes sense it's unconfigured - it hasn't received a DHCP offer message, and the other ones.

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: DHCP client constantly sending discover requests, receiving no response, custom eth chip

Postby WiFive » Tue Oct 30, 2018 11:41 pm

Lua-rtos-esp32 has support for j600 maybe it will help to compare

Who is online

Users browsing this forum: No registered users and 146 guests