kellerkindt / w5500

W5500 ethernet module driver written in rust
Apache License 2.0
40 stars 18 forks source link

DHCP Support #14

Open jonahbron opened 5 years ago

jonahbron commented 5 years ago

Need to add DHCP support so that an IP address can be dynamically acquired.

kellerkindt commented 5 years ago

One needs to send and receive two UDP packages, track the intermediate state and detect the when it needs renewal: https://en.wikipedia.org/wiki/Dynamic_Host_Configuration_Protocol

Might be related for duration tracking: rust-embedded/embedded-hal#59

That... might help us https://github.com/Wiznet/W5500_EVB

jonahbron commented 5 years ago

Good, this initial direction will help greatly, thank you.

ryan-summers commented 1 year ago

One other approach is to actually just use the W5500 in MACRAW mode and put smoltcp on top of it. In this way, you get all the goodness of smoltcp (i.e. DHCP, DNS, mDNS, etc.) without having to duplicate the implementation in this crate. Check out https://github.com/quartiq/booster/blob/main/src/hardware/external_mac.rs for a reference implementation on how to do this. It's on my TODO list to pull the external-mac operation into it's own crate as well to enable this.

rvdende commented 1 year ago

Has anyone got W5500 working with DHCP? I've got TCP working when specifying an ipaddress, but I have no idea how to get DHCP added when initializing the device.

ryan-summers commented 1 year ago

As I mentioned above, you can get DHCP working by using Smoltcp just fine, and I do this in the booster crate linked above :).

In it's current state, this crate does not support DHCP without using smoltcp.

rvdende commented 1 year ago

I tried with smoltcp-nal, not smoltcp itself. Sorry I'm a bit new to rust so its a bit daunting to init the devices. I was hoping a minimal example to get DHCP. At this stage I'm stuck having to hardcode the ip :( Heres my attempt:

So the main branch is working, the smoltcp branch is failing. this is the diff: https://github.com/netrondev/iotrs_stm32f4/compare/main...smoltcp

ryan-summers commented 1 year ago

@rvdende Sorry, I don't have a ton of time on my hands, so it's hard for me to review your code and tell you exactly what's wrong. If you want to review a working example used in production, check out Booster's initialization routines, which use the smoltcp-nal, smoltcp. and the W5500: https://github.com/quartiq/booster/blob/main/src/hardware/setup.rs#L283-L381 https://github.com/quartiq/booster/blob/main/src/hardware/net_interface.rs

cnmozzie commented 1 year ago

this is my minimal example that I take from the "booster" repo. I hope it can help you

rvdende commented 1 year ago

this is my minimal example that I take from the "booster" repo. I hope it can help you

Thank you @cnmozzie !! I'm going to try this as soon as possible.

rvdende commented 1 year ago

@cnmozzie thanks again for the example code, I got it working on my stm32F407 :)