-
Notifications
You must be signed in to change notification settings - Fork 7.4k
net: wifi: fix the bug by non-wifi network call #90371
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
Conversation
Hello @LeonCT, and thank you very much for your first pull request to the Zephyr project! |
3168f44
to
ad83c0c
Compare
Added network type check to fix the system crash caused by non-wifi network card calling wifi api interface Company:BSH Crop Signed-off-by: Chen Tao <[email protected]>
|
Hi @LeonCT! To celebrate this milestone and showcase your contribution, we'd love to award you the Zephyr Technical Contributor badge. If you're interested, please claim your badge by filling out this form: Claim Your Zephyr Badge. Thank you for your valuable input, and we look forward to seeing more of your contributions in the future! 🪁 |
In the get_wifi_api function, there is no check to see if the network card type is wifi, which will cause other types of network cards (such as Ethernet devices) to successfully assign the dev api element to the final return value of the function. This will cause a direct crash when other functions call the returned wifi api. The following are the differences between the apis of the two network card device driver layers:
wifi(eg.drivers\wifi\esp32\src\esp_wifi_drv.c):
static const struct wifi_mgmt_ops esp32_wifi_mgmt = {
.scan = esp32_wifi_scan,
.connect = esp32_wifi_connect,
.disconnect = esp32_wifi_disconnect,
.ap_enable = esp32_wifi_ap_enable,
.ap_disable = esp32_wifi_ap_disable,
.iface_status = esp32_wifi_status,
#if defined(CONFIG_NET_STATISTICS_WIFI)
.get_stats = esp32_wifi_stats,
#endif
};
ethernet(eg.drivers\ethernet\eth_lan865x.c)
static const struct ethernet_api lan865x_api_func = {
.iface_api.init = lan865x_iface_init,
.get_capabilities = lan865x_port_get_capabilities,
.set_config = lan865x_set_config,
.send = lan865x_port_send,
};
Obviously, the APIs of the above two drivers are different, but after being called by the macro NET_DEVICE_DT_INST_DEFINE, they will be assigned to the api element of the device dev.
3.Device verification:
Based on the NXP frdm-rw612 development board, write a WiFi connection example program. Since the development board has both Ethernet and wireless network cards, two network card devices will be enumerated when the system starts. When the function net_if_get_default() is used to obtain the default network card, the obtained network card device is Ethernet, but if the function net_mgmt is used to initiate a WiFi connection at this time, it will directly cause the system to crash. After using the repair code, it will return the call error code instead of the system crash.
application demo code for wifi connect:
-log print output

Original code run: