[PATCH] Connman : Add support for P2P WPS (PIN/PBC) in ConnMan

Shailesh Rathod/LGSI Connectivity Team <[email protected]> Mon, 7 Jul 2025 07:04:54 +0000
Newsgroups dev.linux.lists.connman
Message-ID <SE1P216MB264701522C92F2327FD04590F04FA@SE1P216MB2647.KORP216.PROD.OUTLOOK.COM>
From 3ec1fad48a93a88d900e88c01e33a62309dce428 Mon Sep 17 00:00:00 2001
From: shailesh rathod <[email protected]>
Date: Mon, 9 Jun 2025 19:52:30 +0900
Subject: [PATCH] Add support for P2P WPS (PIN/PBC) in ConnMan

- Enable P2P WPS connection using either PIN or Push Button Configuration (PBC) methods.
- Store and retrieve the WPS PIN via ConnMan's configuration storage.
- Add "WiFi.PinWPS" property to the technology D-Bus interface for setting and saving the WPS PIN.
- Update peer connection logic to use the appropriate WPS method based on the presence of a PIN.
- Ensure proper memory management for the WPS PIN in the technology structure.
---
 src/peer.c       | 14 ++++++++++++--
 src/technology.c | 26 +++++++++++++++++++++++++-
 2 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/src/peer.c b/src/peer.c
index bad5c84..2b2c636 100644
--- a/src/peer.c
+++ b/src/peer.c
@@ -609,9 +609,19 @@ static int peer_connect(struct connman_peer *peer)
    if (is_connected(peer))
        return -EISCONN;
 
-   if (peer_driver->connect)
+   GKeyFile *keyfile = __connman_storage_load_global();
+
+   char *pin = g_key_file_get_string(keyfile, "WiFi", "WiFi.PinWPS", NULL);
+
+   if (peer_driver->connect){
+       if(!pin || strlen(pin)==0){
+       err = peer_driver->connect(peer,
+                   CONNMAN_PEER_WPS_PBC, NULL);
+       }else{
        err = peer_driver->connect(peer,
-                   CONNMAN_PEER_WPS_UNKNOWN, NULL);
+                   CONNMAN_PEER_WPS_PIN, pin);
+       }
+   }
 
    if (err == -ENOKEY) {
        err = __connman_agent_request_peer_authorization(peer,
diff --git a/src/technology.c b/src/technology.c
index 3f3b022..fc90663 100644
--- a/src/technology.c
+++ b/src/technology.c
@@ -86,6 +86,7 @@ struct connman_technology {
    bool hardblocked;
    bool dbus_registered;
    bool p2p_listen;
+   char * wps_pin;
 };
 
 static GSList *driver_list = NULL;
@@ -215,6 +216,12 @@ static void technology_save(struct connman_technology *technology)
                "Tethering.Freq",
                technology->tethering_freq);
 
+   if (technology->wps_pin) {
+               g_key_file_set_string(keyfile, identifier,
+                                   "WiFi.PinWPS",
+                                   technology->wps_pin);
+}
+
 done:
    g_free(identifier);
 
@@ -1220,7 +1227,24 @@ static DBusMessage *set_property(DBusConnection *conn,
    dbus_message_iter_get_basic(&value, &enable);
 
    return set_p2p_listen(technology, msg, enable);
-} else
+}else if (g_str_equal(name, "WiFi.PinWPS") == TRUE) {
+   const char *pin = NULL;
+
+   if (type != DBUS_TYPE_STRING)
+       return __connman_error_invalid_arguments(msg);
+
+   dbus_message_iter_get_basic(&value, &pin);
+
+   // Save the WPS PIN to the technology struct
+   g_free(technology->wps_pin);   // free old if any
+   technology->wps_pin = g_strdup(pin);
+
+   // Call save function
+   technology_save(technology);
+
+   if (err < 0)
+       return __connman_error_failed(msg, -err);
+}else
        return __connman_error_invalid_property(msg);
 
    return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);