Skip to content

Commit 0ab2d98

Browse files
committed
[nrf fromlist] net: wifi: Add Wi-Fi direct P2P discovery API support
Add supplicant api and mgmt ops support for P2P discovery. Upstream PR #: 97183 Signed-off-by: Kapil Bhatt <[email protected]>
1 parent 41dffb3 commit 0ab2d98

File tree

8 files changed

+497
-3
lines changed

8 files changed

+497
-3
lines changed

include/zephyr/net/wifi_mgmt.h

Lines changed: 125 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ enum net_request_wifi_cmd {
139139
NET_REQUEST_WIFI_CMD_BSS_MAX_IDLE_PERIOD,
140140
/** Configure background scanning */
141141
NET_REQUEST_WIFI_CMD_BGSCAN,
142+
/** Wi-Fi Direct (P2P) operations*/
143+
NET_REQUEST_WIFI_CMD_P2P_OPER,
142144
/** @cond INTERNAL_HIDDEN */
143145
NET_REQUEST_WIFI_CMD_MAX
144146
/** @endcond */
@@ -339,6 +341,11 @@ NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_BSS_MAX_IDLE_PERIOD);
339341

340342
NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_BGSCAN);
341343

344+
#define NET_REQUEST_WIFI_P2P_OPER \
345+
(NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_P2P_OPER)
346+
347+
NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_P2P_OPER);
348+
342349
/** @cond INTERNAL_HIDDEN */
343350

344351
enum {
@@ -359,7 +366,7 @@ enum {
359366
NET_EVENT_WIFI_CMD_AP_STA_CONNECTED_VAL,
360367
NET_EVENT_WIFI_CMD_AP_STA_DISCONNECTED_VAL,
361368
NET_EVENT_WIFI_CMD_SUPPLICANT_VAL,
362-
369+
NET_EVENT_WIFI_CMD_P2P_DEVICE_FOUND_VAL,
363370
NET_EVENT_WIFI_CMD_MAX,
364371
};
365372

@@ -406,6 +413,8 @@ enum net_event_wifi_cmd {
406413
NET_MGMT_CMD(NET_EVENT_WIFI_CMD_AP_STA_DISCONNECTED),
407414
/** Supplicant specific event */
408415
NET_MGMT_CMD(NET_EVENT_WIFI_CMD_SUPPLICANT),
416+
/** P2P device found */
417+
NET_MGMT_CMD(NET_EVENT_WIFI_CMD_P2P_DEVICE_FOUND),
409418
};
410419

411420
/** Event emitted for Wi-Fi scan result */
@@ -468,6 +477,51 @@ enum net_event_wifi_cmd {
468477
#define NET_EVENT_WIFI_AP_STA_DISCONNECTED \
469478
(NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_AP_STA_DISCONNECTED)
470479

480+
/** Event emitted for P2P device found event */
481+
#define NET_EVENT_WIFI_P2P_DEVICE_FOUND \
482+
(NET_WIFI_EVENT | NET_EVENT_WIFI_CMD_P2P_DEVICE_FOUND)
483+
484+
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_P2P
485+
/** Maximum length for P2P device name */
486+
#define WIFI_P2P_DEVICE_NAME_MAX_LEN 32
487+
/** Size of P2P primary device type (8 bytes) */
488+
#define WIFI_P2P_PRI_DEV_TYPE_SIZE 8
489+
/** Maximum length for P2P primary device type string */
490+
#define WIFI_P2P_PRI_DEV_TYPE_STR_MAX_LEN 32
491+
/** Maximum length for P2P WPS configuration methods string */
492+
#define WIFI_P2P_CONFIG_METHODS_STR_MAX_LEN 16
493+
/** Maximum length for P2P manufacturer name */
494+
#define WIFI_P2P_MANUFACTURER_MAX_LEN 64
495+
/** Maximum length for P2P model name */
496+
#define WIFI_P2P_MODEL_NAME_MAX_LEN 32
497+
498+
/** @brief Wi-Fi P2P device info */
499+
struct wifi_p2p_device_info {
500+
/** Device MAC address */
501+
uint8_t mac[WIFI_MAC_ADDR_LEN];
502+
/** Device name (max 32 chars + null terminator) */
503+
char device_name[WIFI_P2P_DEVICE_NAME_MAX_LEN + 1];
504+
/** Primary device type */
505+
uint8_t pri_dev_type[WIFI_P2P_PRI_DEV_TYPE_SIZE];
506+
/** Primary device type string */
507+
char pri_dev_type_str[WIFI_P2P_PRI_DEV_TYPE_STR_MAX_LEN];
508+
/** Signal strength (RSSI) */
509+
int8_t rssi;
510+
/** WPS configuration methods supported */
511+
uint16_t config_methods;
512+
/** WPS configuration methods string */
513+
char config_methods_str[WIFI_P2P_CONFIG_METHODS_STR_MAX_LEN];
514+
/** Device capability */
515+
uint8_t dev_capab;
516+
/** Group capability */
517+
uint8_t group_capab;
518+
/** Manufacturer (max 64 chars + null terminator) */
519+
char manufacturer[WIFI_P2P_MANUFACTURER_MAX_LEN + 1];
520+
/** Model name (max 32 chars + null terminator) */
521+
char model_name[WIFI_P2P_MODEL_NAME_MAX_LEN + 1];
522+
};
523+
#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_P2P */
524+
471525
/** @brief Wi-Fi version */
472526
struct wifi_version {
473527
/** Driver version */
@@ -1114,6 +1168,9 @@ union wifi_mgmt_events {
11141168
#endif /* CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS */
11151169
struct wifi_twt_params twt_params;
11161170
struct wifi_ap_sta_info ap_sta_info;
1171+
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_P2P
1172+
struct wifi_p2p_device_info p2p_device_info;
1173+
#endif
11171174
};
11181175

11191176
/** @endcond */
@@ -1397,6 +1454,51 @@ struct wifi_wps_config_params {
13971454
char pin[WIFI_WPS_PIN_MAX_LEN + 1];
13981455
};
13991456

1457+
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_P2P
1458+
/** Wi-Fi P2P operation */
1459+
enum wifi_p2p_op {
1460+
/** P2P find/discovery */
1461+
WIFI_P2P_FIND = 0,
1462+
/** P2P stop find/discovery */
1463+
WIFI_P2P_STOP_FIND,
1464+
/** P2P query peer info use broadcast MAC (ff:ff:ff:ff:ff:ff) to list all peers,
1465+
* or specific MAC address to query a single peer
1466+
*/
1467+
WIFI_P2P_PEER,
1468+
};
1469+
1470+
/** Wi-Fi P2P discovery type */
1471+
enum wifi_p2p_discovery_type {
1472+
/** Start with full scan, then only social channels */
1473+
WIFI_P2P_FIND_START_WITH_FULL = 0,
1474+
/** Only social channels (1, 6, 11) */
1475+
WIFI_P2P_FIND_ONLY_SOCIAL,
1476+
/** Progressive - scan through all channels one at a time */
1477+
WIFI_P2P_FIND_PROGRESSIVE,
1478+
};
1479+
1480+
/** Maximum number of P2P peers that can be returned in a single query */
1481+
#define WIFI_P2P_MAX_PEERS CONFIG_WIFI_P2P_MAX_PEERS
1482+
1483+
/** Wi-Fi P2P parameters */
1484+
struct wifi_p2p_params {
1485+
/** P2P operation */
1486+
enum wifi_p2p_op oper;
1487+
/** Discovery type (for find operation) */
1488+
enum wifi_p2p_discovery_type discovery_type;
1489+
/** Timeout in seconds (0 = no timeout, run until stopped) */
1490+
uint16_t timeout;
1491+
/** Peer device address (for peer operation) */
1492+
uint8_t peer_addr[WIFI_MAC_ADDR_LEN];
1493+
/** Flag to list only discovered peers (for peers operation) */
1494+
bool discovered_only;
1495+
/** Pointer to array for peer info results */
1496+
struct wifi_p2p_device_info *peers;
1497+
/** Actual number of peers returned */
1498+
uint16_t peer_count;
1499+
};
1500+
#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_P2P */
1501+
14001502
/** Wi-Fi AP status
14011503
*/
14021504
enum wifi_sap_iface_state {
@@ -1785,6 +1887,17 @@ struct wifi_mgmt_ops {
17851887
*/
17861888
int (*set_bgscan)(const struct device *dev, struct wifi_bgscan_params *params);
17871889
#endif
1890+
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_P2P
1891+
/** Wi-Fi Direct (P2P) operations for device discovery
1892+
*
1893+
* @param dev Pointer to the device structure for the driver instance.
1894+
* @param params P2P operation parameters including operation type, discovery settings,
1895+
* timeout values and peer information retrieval options
1896+
*
1897+
* @return 0 if ok, < 0 if error
1898+
*/
1899+
int (*p2p_oper)(const struct device *dev, struct wifi_p2p_params *params);
1900+
#endif
17881901
};
17891902

17901903
/** Wi-Fi management offload API */
@@ -1916,6 +2029,17 @@ void wifi_mgmt_raise_ap_sta_connected_event(struct net_if *iface,
19162029
void wifi_mgmt_raise_ap_sta_disconnected_event(struct net_if *iface,
19172030
struct wifi_ap_sta_info *sta_info);
19182031

2032+
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_P2P
2033+
/**
2034+
* @brief Raise P2P device found event
2035+
*
2036+
* @param iface Network interface
2037+
* @param device_info P2P device information
2038+
*/
2039+
void wifi_mgmt_raise_p2p_device_found_event(struct net_if *iface,
2040+
struct wifi_p2p_device_info *peer_info);
2041+
#endif /* CONFIG_WIFI_NM_WPA_SUPPLICANT_P2P */
2042+
19192043
/**
19202044
* @}
19212045
*/

0 commit comments

Comments
 (0)