Skip to content

net: wifi: P2p support - #112772

Open
nxf58150 wants to merge 3 commits into
zephyrproject-rtos:mainfrom
nxp-upstream:p2p_support
Open

net: wifi: P2p support#112772
nxf58150 wants to merge 3 commits into
zephyrproject-rtos:mainfrom
nxp-upstream:p2p_support

Conversation

@nxf58150

@nxf58150 nxf58150 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

NXP P2P support

@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

The following west manifest projects have changed revision in this Pull Request:

Name Old Revision New Revision Diff
hal_nxp zephyrproject-rtos/hal_nxp@5218647 zephyrproject-rtos/hal_nxp#761 zephyrproject-rtos/hal_nxp#761/files
hostap zephyrproject-rtos/hostap@d467a11 (main) zephyrproject-rtos/hostap#147 zephyrproject-rtos/hostap#147/files

DNM label due to: 2 projects with PR revision

Note: This message is automatically posted and updated by the Manifest GitHub Action.

Comment thread drivers/wifi/nxp/Kconfig.nxp Outdated
help
This option specifies the size of the stack used by the wifi scan task.

config NXP_WIFI_P2P_SUPPORT

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is aligned with FreeRTOS P2P flag.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

Comment thread drivers/wifi/nxp/src/nxp_wifi_drv.c Outdated
break;
}
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_P2P
LOG_DBG("WLAN: %s Started", bss_type == WLAN_BSS_TYPE_WIFIDIRECT ? "GO" : "UAP");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it necessary to add CONFIG_WPA_SUPP_P2P for the definition and all the usage of WLAN_BSS_TYPE_WIFIDIRECT ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CONFIG_WPA_SUPP_P2P is used to aligned with FreeRTOS in wifi_nxp.

Comment thread drivers/wifi/nxp/Kconfig.nxp Outdated
module = WIFI_NXP

config HEAP_MEM_POOL_ADD_SIZE_NXP_WIFI
def_int 102400 if WIFI_NM_WPA_SUPPLICANT_P2P

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is already HEAP_MEM_POOL_ADD_SIZE_HOSTAP, which check def_int 80000 if WIFI_NM_WPA_SUPPLICANT_P2P, it's not enough?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means extra 74K heap is needed when WIFI_NM_WPA_SUPPLICANT_P2P is enabled on wifi shell supplicant example, is this expected?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@nxf58150
nxf58150 force-pushed the p2p_support branch 2 times, most recently from 4d489a2 to cb17cb5 Compare July 24, 2026 09:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_shell P2P 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.

Comment thread drivers/wifi/nxp/Kconfig.nxp Outdated
Comment on lines +458 to +465
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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The config will be used in NXP wifi driver.

Comment thread west.yml
Comment thread west.yml
Comment thread drivers/wifi/nxp/src/nxp_wifi_drv.c Outdated
}

/**
* Called from each of the three iface_api.init callbacks.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

Comment thread drivers/wifi/nxp/src/nxp_wifi_drv.c Outdated
#define NXP_WIFI_NETIF_COUNT 1
#endif

atomic_t s_netif_init_count = ATOMIC_INIT(0);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

Comment on lines +481 to +485
/* Get P2P interface netif structure pointer
*
* \rerurn A pointer to P2P interface netif structure
*
*/

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

@maass-hamburg maass-hamburg changed the title P2p support net: wifi: P2p support Aug 5, 2026
@nxf58150
nxf58150 force-pushed the p2p_support branch 11 times, most recently from 9794065 to 3845dbe Compare August 13, 2026 02:53
@sonarqubecloud

Copy link
Copy Markdown

@nxf58150
nxf58150 force-pushed the p2p_support branch 2 times, most recently from c990b63 to 7e8e1d1 Compare August 18, 2026 01:53
Comment thread subsys/net/ip/net_if.c Outdated
return net_if_get_first_wifi();
}

#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_P2P

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flag removed.

Comment thread drivers/wifi/nxp/src/nxp_wifi_drv.c Outdated
intf->netif = iface;

#ifdef CONFIG_WIFI_NM
wifi_nm_register_mgd_type_iface(wifi_nm_get_instance("wifi_supplicant"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

Comment thread drivers/wifi/nxp/src/nxp_wifi_net.c Outdated

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the flag here and several other places. Please help review again. Thanks!

Comment thread drivers/wifi/nxp/src/nxp_wifi_drv.c Outdated
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");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be CONFIG_NXP_WIFI_P2P_IP_MASK

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.

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");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be CONFIG_NXP_WIFI_P2P_IP_ADDRESS

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

Comment thread drivers/wifi/nxp/Kconfig.nxp Outdated
help
This option specifies the size of the stack used by the wifi scan task.

config NXP_WIFI_P2P_SUPPORT

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread drivers/wifi/nxp/Kconfig.nxp Outdated
module = WIFI_NXP

config HEAP_MEM_POOL_ADD_SIZE_NXP_WIFI
def_int 102400 if WIFI_NM_WPA_SUPPLICANT_P2P

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@MaochenWang1 MaochenWang1 Aug 24, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already removed. Will find a solution in the future.

Comment thread drivers/wifi/nxp/src/nxp_wifi_drv.c Outdated

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");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CONFIG_NXP_WIFI_P2P_IP_BASE for LOG_ERR

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CONFIG_NXP_WIFI_P2P_IP_ADDRESS for LOG_ERR

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants