zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.14k stars 6.23k forks source link

mDNS response is not sent out over STM32U575zi-WiFi #75020

Open VineetaNarkhede-eaton opened 3 weeks ago

VineetaNarkhede-eaton commented 3 weeks ago

Discussed in https://github.com/zephyrproject-rtos/zephyr/discussions/71540

Originally posted by **VineetaNarkhede-eaton** April 16, 2024 Hi, I am facing an issue in running mDNS over STM32U575zi on WiFi interface. Device (Dev board) is in AP mode and connected with Laptop over WiFi. Enabled the mDNS responder in zephyr. Hostname configured is "zephyr" When I send mdns query from Laptop i.e zephyr.local, the query is successfully reaching the device from the laptop. However, the response from the device does not appear to be reaching the laptop. I have verified that the response is reaching till WiFi driver and the response data is valid. Wireshark logs on the laptop shows query but no response visible. Interestingly, mDNS query-response works sometimes suddenly(very rare) without any code changes. I tried the solution provided on this issue https://github.com/zephyrproject-rtos/zephyr/discussions/48327, but no improvement in the result. **Setup**: Dev board: NUCLEO-U575ZI-Q WiFi chip:1YN-CY43439 zephyr OS : v3.2.0 infineon_zephyr_connectivity commit id : 272e2b8da908c7d796ec62757cc8abbe03a91e4c I would appreciate any help with this matter.
jukkar commented 3 weeks ago

I was hoping a proper issue instead of pressing the "convert to issue" button as this just copies the first question to an issue. Lot of relevant information missing now. Anyway, lets start by first figuring out what wifi driver are you using, mentioning chip does not really help here.

VineetaNarkhede-eaton commented 3 weeks ago

Hi @jukkar,

Apologies, if "convert to issue" is not a right approach in this scenario. We are using customized Infineon WiFi driver. During migration to zephyr 3.6.0, We found that airoc_wifi driver is tightly coupled for PSOC6 controller and it can't be easily integrated with our current code for STM32U575zi, hence currently we are using our customized wifi driver code which we were running with zephyr 3.2.0 also.

Regarding the comment given by rajolegajendra-eaton on this discussion, I would like to understand the significance of NET_IF_LOWER_UP and NET_IF_UP. Can we replace NET_IF_LOWER_UP with NET_IF_UP in net_if_tx() function to solve this issue?

jukkar commented 3 weeks ago

Can we replace NET_IF_LOWER_UP with NET_IF_UP in net_if_tx() function to solve this issue?

No, you should not do that. NET_IF_UP presents admin state of the interface i.e., it is set when the application or user turns on the interface. The NET_IF_LOWER_UP is set when the carrier is turned on. For wifi this means that when the wifi connection is "ready". So it looks like the wifi interface carrier status is turned "ON" too early by the driver when the interface in fact is not yet ready for the connection.

rajolegajendra-eaton commented 1 week ago

Can we replace NET_IF_LOWER_UP with NET_IF_UP in net_if_tx() function to solve this issue?

No, you should not do that. NET_IF_UP presents admin state of the interface i.e., it is set when the application or user turns on the interface. The NET_IF_LOWER_UP is set when the carrier is turned on. For wifi this means that when the wifi connection is "ready". So it looks like the wifi interface carrier status is turned "ON" too early by the driver when the interface in fact is not yet ready for the connection.

Hello @jukkar, We have noticed one change in NET_IF_INIT() macro which is getting called by NET_DEVICE_DT_INST_DEFINE() macro. It is setting flag bit for NET_IF_LOWER_UP as highlighted in following image: image This sets the flag as carrier ON. As mentioned earlier we are initializing WiFi in application and not before main. So carrier must be turned on only after Network Link is Up and Valid IP is assigned. Since carrier flag is set before wireless network is setup, so iface will not have Valid IP address. When mDNS is initialized from init_listener() using SYS_INIT() so it finds iface src address as null and gives bus fault. What is the significance of setting flag to NET_IF_LOWER_UP in NET_IF_INIT()? Found one commit where this change was done. Link is here. image cc: @VineetaNarkhede-eaton

rajolegajendra-eaton commented 1 week ago

@jukkar , We are waiting for your response.

Above issue can be resolved if we change NET_IF_LOWER_UP flag to NET_IF_NO_AUTO_START.

jukkar commented 6 days ago

You have out of tree driver and application, it very difficult to understand what your code is doing.

cc: @rlubos if you have any extra ideas

rlubos commented 6 days ago

This sets the flag as carrier ON. As mentioned earlier we are initializing WiFi in application and not before main. So carrier must be turned on only after Network Link is Up and Valid IP is assigned.

The carrier is set to ON by default, for legacy reasons (and we don't push to change it as Linux does the same). If the particular interface is not ready to use after system initialization, it should be changed to off.

Every network interface has possibility to run boot-time initialization by registering init() function from struct net_if_api (the API struct is statically provided when registering interface with NET_DEVICE_DT_INST_DEFINE() or similar). You should set carrier to OFF there.

You can take ESP driver as a reference here, it seems to be a similar case: https://github.com/zephyrproject-rtos/zephyr/blob/main/drivers/wifi/esp32/src/esp_wifi_drv.c#L681

rajolegajendra-eaton commented 1 day ago

You can take ESP driver as a reference here, it seems to be a similar case: https://github.com/zephyrproject-rtos/zephyr/blob/main/drivers/wifi/esp32/src/esp_wifi_drv.c#L681

Hello @rlubos, Thanks for the reference, we have tried it and it seems Bus Fault issue is resolved. Will add an update here once testing is completed. cc: @VineetaNarkhede-eaton