Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CYW43: Allow setting hostname. #8918

Closed
wants to merge 2 commits into from

Conversation

iabdalkader
Copy link
Contributor

@codecov-commenter
Copy link

codecov-commenter commented Jul 17, 2022

Codecov Report

Merging #8918 (a89edc6) into master (d84220b) will increase coverage by 0.01%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master    #8918      +/-   ##
==========================================
+ Coverage   98.33%   98.35%   +0.01%     
==========================================
  Files         157      156       -1     
  Lines       20346    20229     -117     
==========================================
- Hits        20008    19896     -112     
+ Misses        338      333       -5     
Impacted Files Coverage Δ
extmod/moducryptolib.c 91.30% <0.00%> (-0.86%) ⬇️
py/objobject.c 88.88% <0.00%> (-0.40%) ⬇️
py/obj.c 97.83% <0.00%> (-0.08%) ⬇️
extmod/moductypes.c 97.84% <0.00%> (-0.05%) ⬇️
py/objexcept.c 96.39% <0.00%> (-0.02%) ⬇️
py/runtime.c 99.71% <0.00%> (-0.01%) ⬇️
py/vm.c 100.00% <0.00%> (ø)
py/obj.h 100.00% <0.00%> (ø)
py/misc.h 100.00% <0.00%> (ø)
py/objint.c 100.00% <0.00%> (ø)
... and 20 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d84220b...a89edc6. Read the comment docs.

@iabdalkader iabdalkader changed the title Cyw43 hostname CYW43: Allow setting hostname. Jul 17, 2022
@dpgeorge
Copy link
Member

How did you test this change? The call to netif_set_hostname() is done when wlan.active(True) is called, so if you reconfigure the hostname after that, it probably won't work.

It might be worth adding a call to netif_set_hostname() in network_cyw43's config method.

I didn't want to use an arbitrary hostname length, so I used DNS_MAX_NAME_LENGTH which is 256 bytes, but it can be redefined.

I think 256 is overkill. I'd suggest to make a new define and default to something like 16.

drivers/cyw43/cyw43.h Outdated Show resolved Hide resolved
@iabdalkader
Copy link
Contributor Author

How did you test this change? The call to netif_set_hostname() is done when wlan.active(True) is called, so if you reconfigure the hostname after that, it probably won't work.

The idea was to support config('hostname') followed by active(True), the hostname can't (shouldn't ?) be changed after active. I tested this change and it works both with the router web interface and with avahi-resolve-address.

@dpgeorge
Copy link
Member

The idea was to support config('hostname') followed by active(True)

On esp32 you need to run active(True) before config(hostname=...), or it raises a OSError: TCP/IP IF Not Ready exception. We need to try and make these things consistent across ports.

the hostname can't (shouldn't ?) be changed after active

The hostname is not used (at least by DHCP) until you run connect(ssid, ...), so you have a chance to set the hostname between activating and connecting (that's not true though for bringing up an AP interface, which needs to be configured before activating).

We need to settle on a standard for the order of configuring a NIC. Probably it makes sense to configure before activating (eg for ETH it would, because activating means starting up the ETH interface, there is no separate connect call).

But, actually, I think this PR will still work running config after active, because netif_set_hostname() just sets a pointer to the hostname string, and you can change that string after setting it and the changes will still be seen by lwIP.

@iabdalkader
Copy link
Contributor Author

We need to settle on a standard for the order of configuring a NIC. Probably it makes sense to configure before activating

I agree, that's just the logical order, and I think it's the other port that should match this.

Where should the default hostname (i.e PYBD) and default hostname length (16) be defined ? rp2 port doesn't have an mpconfigboard_common.h file, which was my first thought.

* Allow boards to configure/override the default hostname
used for netif and mDNS.
@dpgeorge
Copy link
Member

dpgeorge commented Aug 5, 2022

Where should the default hostname (i.e PYBD) and default hostname length (16) be defined ?

Where you put it in cyw43.h is fine, thanks.

Rebased and merged in b6c2196 and 9dfabcd

@dpgeorge dpgeorge closed this Aug 5, 2022
@iabdalkader iabdalkader deleted the cyw43_hostname branch August 5, 2022 14:44
@iabdalkader
Copy link
Contributor Author

@dpgeorge Why does MICROPY_PY_NETWORK_CYW43_USE_LIB_DRIVER disable some of the config options like security and hostname ?

@robert-hh
Copy link
Contributor

@iabdalkader:
Trying to build the binaries with MICROPY_PY_NETWORK_CYW43_USE_LIB_DRIVER=0 fails.
How did you succeed and test setting hostname?

@iabdalkader
Copy link
Contributor Author

@robert-hh I'm not really sure, @dpgeorge added in some last minute changes when merging this PR. I see some errors with MICROPY_PY_NETWORK_CYW43_USE_LIB_DRIVER=0 which might not be related to this PR at all.

@robert-hh
Copy link
Contributor

If I compare that to your initial commit, the #if !MICROPY_PY_NETWORK_CYW43_USE_LIB_DRIVER were added around the hostname handling statements. But then hostname support does not exist in the standard build, which sets MICROPY_PY_NETWORK_CYW43_USE_LIB_DRIVER=1.
And if I drop that conditional compile, the compile using the lib driver fails because of the missing hostname element in the cyw43_t.
Which configuration did you use for testing? The drivers/cyw43 or lib/cyw43?

@iabdalkader
Copy link
Contributor Author

I tested with stm32 port, I guess that doesn't use the open-sourced lib/cyw43.

@robert-hh
Copy link
Contributor

That works, and indeed it does not use lib/cyw43. People expected support for Pico_W as well.

Damien changed the code such that it compiles at least on the rp2, but only when using the lib version. To make it conformant, lib/cyw43 had to be changed in having the hostname field in the cyw43_t as well, and the related #define symbols. Or hostname has to move into a different data structure.

@iabdalkader
Copy link
Contributor Author

Note there are other config options that get disabled as well with that define (like security), and I agree they should be compatible.

@CubicDE
Copy link

CubicDE commented Jan 30, 2023

Hey, are there any updates on this?
Can the hostname be set?

@robert-hh
Copy link
Contributor

It should be available in the nightly builds.

@jimmo
Copy link
Member

jimmo commented Jan 31, 2023

It should be available in the nightly builds.

@CubicDE @robert-hh In the nightly build for Pico W, in progress (planned for upcoming v1.20) for PYBD/Portenta.

@jimmo
Copy link
Member

jimmo commented Feb 1, 2023

@CubicDE #10635

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't set hostname in AP mode
6 participants