net: wifi: P2p support - #112772
Conversation
|
The following west manifest projects have changed revision in this Pull Request:
⛔ DNM label due to: 2 projects with PR revision Note: This message is automatically posted and updated by the Manifest GitHub Action. |
ad68817 to
871d34f
Compare
| help | ||
| This option specifies the size of the stack used by the wifi scan task. | ||
|
|
||
| config NXP_WIFI_P2P_SUPPORT |
There was a problem hiding this comment.
do we need this NXP_WIFI_P2P_SUPPORT?
if P2P is only used for supplicant case, then we can just use WIFI_NM_WPA_SUPPLICANT_P2P
There was a problem hiding this comment.
Yes, this is aligned with FreeRTOS P2P flag.
There was a problem hiding this comment.
NXP_WIFI_P2P_SUPPORT is not needed, just use following in nxp_wifi.h
#if CONFIG_WIFI_NM_WPA_SUPPLICANT_P2P
#define CONFIG_WPA_SUPP_P2P 1
#endif
| break; | ||
| } | ||
| #ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_P2P | ||
| LOG_DBG("WLAN: %s Started", bss_type == WLAN_BSS_TYPE_WIFIDIRECT ? "GO" : "UAP"); |
There was a problem hiding this comment.
is it necessary to add CONFIG_WPA_SUPP_P2P for the definition and all the usage of WLAN_BSS_TYPE_WIFIDIRECT ?
There was a problem hiding this comment.
CONFIG_WPA_SUPP_P2P is used to aligned with FreeRTOS in wifi_nxp.
| module = WIFI_NXP | ||
|
|
||
| config HEAP_MEM_POOL_ADD_SIZE_NXP_WIFI | ||
| def_int 102400 if WIFI_NM_WPA_SUPPLICANT_P2P |
There was a problem hiding this comment.
there is already HEAP_MEM_POOL_ADD_SIZE_HOSTAP, which check def_int 80000 if WIFI_NM_WPA_SUPPLICANT_P2P, it's not enough?
There was a problem hiding this comment.
Well, I increased this due to not enough memory when doing memory alloc after enabling P2P flag. I didn't notice the HEAP_MEM_POOL_ADD_SIZE_HOSTAP. Let me check this.
There was a problem hiding this comment.
I increased HEAP_MEM_POOL_ADD_SIZE_NXP_WIFI due to memory alloc fail in wifi driver. The HEAP_MEM_POOL_ADD_SIZE_HOSTAP is for wpa_supplicant and hostapd, while HEAP_MEM_POOL_ADD_SIZE_NXP_WIFI is for l2 layer and wifi driver.
There was a problem hiding this comment.
This means extra 74K heap is needed when WIFI_NM_WPA_SUPPLICANT_P2P is enabled on wifi shell supplicant example, is this expected?
There was a problem hiding this comment.
The value is suggested by AI. Need to increase HEAP_MEM_POOL_ADD_SIZE_NXP_WIFI but maybe not that much. If you think the value is too big, I can reduce it based on verification.
4d489a2 to
cb17cb5
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds Wi‑Fi P2P (Wi‑Fi Direct) support for NXP Wi‑Fi by introducing a dedicated P2P interface type in Zephyr’s Wi‑Fi NM/network interface helpers, updating the Wi‑Fi shell to target a P2P iface, and extending the NXP driver to register and handle an additional net_if for Wi‑Fi Direct.
Changes:
- Add P2P as a first-class Wi‑Fi NM interface type and provide helpers to query/select a P2P net_if (
wifi_nm_iface_is_p2p(),net_if_get_wifi_p2p()). - Update
wifi_shellP2P commands to operate on the P2P interface (instead of STA) when P2P is enabled. - Extend the NXP Wi‑Fi driver/network glue to support an additional Wi‑Fi Direct net_if and route RX/TX and events by BSS type.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| west.yml | Points hal_nxp and hostap module revisions at PR heads to pick up upstream P2P-related changes. |
| subsys/net/l2/wifi/wifi_shell.c | Adds IFACE_TYPE_P2P selection and switches P2P shell commands to use the P2P iface. |
| subsys/net/l2/wifi/wifi_nm.c | Adds wifi_nm_iface_is_p2p() implementation (guarded by P2P config). |
| subsys/net/ip/net_if.c | Adds net_if_get_wifi_p2p() helper to find a dedicated P2P iface or fall back to first Wi‑Fi iface. |
| samples/net/wifi/shell/nxp/overlay_hostap_rw612.conf | Adds commented config hints for enabling P2P on RW612 sample setup. |
| modules/hostap/src/supp_main.c | Adjusts default supplicant iface selection logic to only set it on the first added interface. |
| include/zephyr/net/wifi_nm.h | Extends wifi_nm_iface_type with P2P and adds a public wifi_nm_iface_is_p2p() API (with stub when disabled). |
| include/zephyr/net/net_if.h | Adds public net_if_get_wifi_p2p() API (with stub when disabled). |
| drivers/wifi/nxp/src/nxp_wifi_net.c | Adds WFD interface handling, BSS-type→net_if lookup, and updates packet/event routing to support P2P. |
| drivers/wifi/nxp/src/nxp_wifi_drv.c | Adds a third net_if instance for WFD, defers WLAN start until all netifs are initialized, and routes events by BSS type. |
| drivers/wifi/nxp/Kconfig.nxp | Adjusts heap default for P2P and introduces an NXP P2P support Kconfig symbol. |
| drivers/wifi/nxp/incl/nxp_wifi_net.h | Updates exported APIs for WFD support and adds declarations for new helpers. |
| config NXP_WIFI_P2P_SUPPORT | ||
| bool "Wi-Fi P2P (Wi-Fi Direct) Support" | ||
| default y if WIFI_NM_WPA_SUPPLICANT_P2P | ||
| help | ||
| Registers a dedicated Zephyr net_if for Wi-Fi P2P (Wi-Fi Direct). | ||
| This enables IP networking over a P2P group interface and allows | ||
| P2P shell commands to target the P2P iface directly. | ||
|
|
There was a problem hiding this comment.
The config will be used in NXP wifi driver.
| } | ||
|
|
||
| /** | ||
| * Called from each of the three iface_api.init callbacks. |
| #define NXP_WIFI_NETIF_COUNT 1 | ||
| #endif | ||
|
|
||
| atomic_t s_netif_init_count = ATOMIC_INIT(0); |
| /* Get P2P interface netif structure pointer | ||
| * | ||
| * \rerurn A pointer to P2P interface netif structure | ||
| * | ||
| */ |
9794065 to
3845dbe
Compare
|
c990b63 to
7e8e1d1
Compare
| return net_if_get_first_wifi(); | ||
| } | ||
|
|
||
| #ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_P2P |
There was a problem hiding this comment.
Since WIFI_TYPE_P2P is unconditionally defined in the enum, and net_if_get_wifi_sap() / wifi_nm_iface_is_sap() have no Kconfig guard either, would it be cleaner to make net_if_get_wifi_p2p() and wifi_nm_iface_is_p2p() unconditionally compiled as well? The implementation already falls back to net_if_get_first_wifi() when no P2P iface is registered, so it's safe to call regardless of config.
| intf->netif = iface; | ||
|
|
||
| #ifdef CONFIG_WIFI_NM | ||
| wifi_nm_register_mgd_type_iface(wifi_nm_get_instance("wifi_supplicant"), |
There was a problem hiding this comment.
wifi_nm_register_mgd_type_iface can be removed, same as https://github.com/zephyrproject-rtos/zephyr/pull/115881/changes#diff-0217087697365d39aa8ff242a77f1c2180afb8328dfb9d3563cd098e5dea8f10
|
|
||
| if (recv_interface == MLAN_BSS_TYPE_STA || recv_interface == MLAN_BSS_TYPE_UAP) { | ||
| if (recv_interface == MLAN_BSS_TYPE_STA || recv_interface == MLAN_BSS_TYPE_UAP | ||
| #ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_P2P |
There was a problem hiding this comment.
Nit: The #ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_P2P guard around || recv_interface == MLAN_BSS_TYPE_WIFIDIRECT is unnecessary here — when P2P is disabled, recv_interface will never be MLAN_BSS_TYPE_WIFIDIRECT anyway. Removing the guard makes the code cleaner without any behavioral change. Note that MLAN_BSS_TYPE_UAP comparisons are not guarded by CONFIG_NXP_WIFI_SOFTAP_SUPPORT either, same is WIFI_TYPE_P2P
There was a problem hiding this comment.
Removed the flag here and several other places. Please help review again. Thanks!
| return 0; | ||
| if (net_addr_pton(NET_AF_INET, CONFIG_NXP_WIFI_P2P_IP_MASK, | ||
| &netmask_addr) < 0) { | ||
| LOG_ERR("Invalid CONFIG_NXP_WIFI_SOFTAP_IP_MASK"); |
There was a problem hiding this comment.
should be CONFIG_NXP_WIFI_P2P_IP_MASK
| LOG_DBG("WLAN: GO Stopped"); | ||
| if (net_addr_pton(NET_AF_INET, CONFIG_NXP_WIFI_P2P_IP_ADDRESS, | ||
| &dhcps_addr4) < 0) { | ||
| LOG_ERR("Invalid CONFIG_NXP_WIFI_SOFTAP_IP_ADDRESS"); |
There was a problem hiding this comment.
should be CONFIG_NXP_WIFI_P2P_IP_ADDRESS
| help | ||
| This option specifies the size of the stack used by the wifi scan task. | ||
|
|
||
| config NXP_WIFI_P2P_SUPPORT |
There was a problem hiding this comment.
NXP_WIFI_P2P_SUPPORT is not needed, just use following in nxp_wifi.h
#if CONFIG_WIFI_NM_WPA_SUPPLICANT_P2P
#define CONFIG_WPA_SUPP_P2P 1
#endif
| module = WIFI_NXP | ||
|
|
||
| config HEAP_MEM_POOL_ADD_SIZE_NXP_WIFI | ||
| def_int 102400 if WIFI_NM_WPA_SUPPLICANT_P2P |
There was a problem hiding this comment.
This means extra 74K heap is needed when WIFI_NM_WPA_SUPPLICANT_P2P is enabled on wifi shell supplicant example, is this expected?
| CONFIG_WIFI_NM_WPA_SUPPLICANT_LOG_LEVEL_INF=y | ||
|
|
||
| # P2P | ||
| #CONFIG_WIFI_NM_WPA_SUPPLICANT_P2P=y |
There was a problem hiding this comment.
Commented-out configs should not be added to the overlay file. If P2P support is needed, it should be properly enabled rather than left as comments.
Instead of requiring users to manually set these values, the defaults should be defined in Kconfig where the symbols are declared:
Take CONFIG_WIFI_NM_MAX_MANAGED_INTERFACES as an example: add
default 3 if WIFI_NM_WPA_SUPPLICANT_P2P && WIFI_NM_HOSTAPD_AP
in subsys/net/l2/wifi/Kconfig under config WIFI_NM_MAX_MANAGED_INTERFACES.
Similarly for the others (ZVFS_EVENTFD_MAX, NET_IF_MAX_IPV6_COUNT, NET_IF_MAX_IPV4_COUNT, NET_DHCPV4_SERVER_INSTANCES, ZVFS_POLL_MAX) — add appropriate default ... if WIFI_NM_WPA_SUPPLICANT_P2P (or && WIFI_NM_HOSTAPD_AP where applicable) at their Kconfig definition sites.
This way, enabling CONFIG_WIFI_NM_WPA_SUPPLICANT_P2P automatically pulls in the correct resource limits without requiring manual overlay configuration.
There was a problem hiding this comment.
The configs follow CONFIG_WIFI_NM_WPA_SUPPLICANT_P2P are due to new P2P interface added and will surely cost extra memoru. Currently, only NXP has independent interface for P2P. If update those configs in Kconfig, then once P2P is enabled, extra memory will be consumed for all vendors.
There was a problem hiding this comment.
Already removed. Will find a solution in the future.
|
|
||
| if (net_addr_pton(NET_AF_INET, CONFIG_NXP_WIFI_P2P_IP_BASE, | ||
| &base_addr) < 0) { | ||
| LOG_ERR("Invalid CONFIG_NXP_WIFI_SOFTAP_IP_BASE"); |
There was a problem hiding this comment.
CONFIG_NXP_WIFI_P2P_IP_BASE for LOG_ERR
| if (net_addr_pton(NET_AF_INET, CONFIG_NXP_WIFI_P2P_IP_ADDRESS, | ||
| &dhcps_addr4) < 0) { | ||
| LOG_ERR("Invalid CONFIG_NXP_WIFI_SOFTAP_IP_ADDRESS"); | ||
| return 0; |
There was a problem hiding this comment.
CONFIG_NXP_WIFI_P2P_IP_ADDRESS for LOG_ERR
Introduce WIFI_TYPE_P2P to the wifi_nm_iface_type enum and register a corresponding net_if_get_wifi_p2p() lookup function. All P2P shell commands are updated to use IFACE_TYPE_P2P instead of IFACE_TYPE_STA, with automatic fallback to the STA interface when no dedicated P2P interface is registered. Fix the supplicant context default-interface selection in add_interface(): use == 1 instead of > 0 so that the first registered interface (STA) is captured as ctx->iface rather than being overwritten by subsequent UAP/P2P registrations. All new symbols are guarded by CONFIG_WIFI_NM_WPA_SUPPLICANT_P2P. Signed-off-by: Hui Bai <hui.bai@nxp.com>
Add new commands to activate WPS-PBC and WPS-PIN for P2P interface wifi p2p wps_pbc wifi p2p wps_pin Signed-off-by: Hui Bai <hui.bai@nxp.com>
Register a new Zephyr net_if instance for P2P interface - Increase heap pool for P2P support. - Defer wlan init via atomic counter until all net_if callbacks fire - Add nxp_wifi_p2p_init() - Add net_get_if_by_bss_type() to replace direct g_mlan/g_uap refs - Extend net_wlan_set_mac_address() with wfd_mac parameter - Wire up register_frame, deinit_ap, set_p2p_powersave ops - Fix LLC-header removal: use net_pkt_data() after net_buf_pull() - Increase DHCP instance to 2. One is for softAP, the other is for AGO Signed-off-by: Hui Bai <hui.bai@nxp.com>



NXP P2P support