]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
PR: Initialize Proximity Ranging global context
authorPeddolla Harshavardhan Reddy <peddolla@qti.qualcomm.com>
Fri, 25 Apr 2025 07:32:52 +0000 (13:02 +0530)
committerJouni Malinen <j@w1.fi>
Thu, 16 Oct 2025 20:50:44 +0000 (23:50 +0300)
Add changes to initialize and deinitialize the Proximity Ranging (PR)
global context and Makefile changes to enable the compilation of this
feature. The Proximity Ranging context will be global making it common
to all interfaces.

The compilation of changes related to Proximity Ranging can be
enabled using the CONFIG_PR flag.

Signed-off-by: Peddolla Harshavardhan Reddy <peddolla@qti.qualcomm.com>
src/common/proximity_ranging.c [new file with mode: 0644]
src/common/proximity_ranging.h [new file with mode: 0644]
wpa_supplicant/Android.mk
wpa_supplicant/Makefile
wpa_supplicant/pr_supplicant.c [new file with mode: 0644]
wpa_supplicant/pr_supplicant.h [new file with mode: 0644]
wpa_supplicant/wpa_supplicant.c
wpa_supplicant/wpa_supplicant_i.h

diff --git a/src/common/proximity_ranging.c b/src/common/proximity_ranging.c
new file mode 100644 (file)
index 0000000..1f8b4e3
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Proxmity Ranging
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ *
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
+ */
+
+#include "includes.h"
+
+#include "utils/common.h"
+#include "proximity_ranging.h"
+
+
+struct pr_data * pr_init(const struct pr_config *cfg)
+{
+       struct pr_data *pr;
+
+       pr = os_zalloc(sizeof(*pr) + sizeof(*cfg));
+       if (!pr)
+               return NULL;
+
+       pr->cfg = (struct pr_config *) (pr + 1);
+       os_memcpy(pr->cfg, cfg, sizeof(*cfg));
+       if (cfg->dev_name)
+               pr->cfg->dev_name = os_strdup(cfg->dev_name);
+       else
+               pr->cfg->dev_name = NULL;
+
+       dl_list_init(&pr->devices);
+
+       return pr;
+}
+
+
+void pr_deinit(struct pr_data *pr)
+{
+       struct pr_device *dev, *prev;
+
+       if (!pr)
+               return;
+
+       os_free(pr->cfg->dev_name);
+
+       dl_list_for_each_safe(dev, prev, &pr->devices, struct pr_device, list)
+               dl_list_del(&dev->list);
+
+       os_free(pr);
+       wpa_printf(MSG_DEBUG, "PR: Deinit done");
+}
diff --git a/src/common/proximity_ranging.h b/src/common/proximity_ranging.h
new file mode 100644 (file)
index 0000000..70436d5
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Proxmity Ranging
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ *
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
+ */
+
+#ifndef PROXIMITY_RANGING_H
+#define PROXIMITY_RANGING_H
+
+#include "utils/list.h"
+
+/**
+ * PR_MAX_PEER - Maximum number of Proximity Ranging peers that device can store
+ */
+#define PR_MAX_PEER 100
+
+/**
+ * struct pr_device_info - Proximity ranging peer information
+ */
+struct pr_device {
+       struct dl_list list;
+       struct os_reltime last_seen;
+
+       /**
+        * pr_device_addr - PR Device Address of the peer
+        */
+       u8 pr_device_addr[ETH_ALEN];
+};
+
+
+struct pr_config {
+       u8 dev_addr[ETH_ALEN];
+
+       /**
+        * dev_name - Device Name
+        */
+       char *dev_name;
+
+       /**
+        * cb_ctx - Context to use with callback functions
+        */
+       void *cb_ctx;
+};
+
+struct pr_data {
+       /**
+        * cfg - PR module configuration
+        *
+        * This is included in the same memory allocation with the
+        * struct pr_data and as such, must not be freed separately.
+        */
+       struct pr_config *cfg;
+
+       struct dl_list devices;
+};
+
+struct pr_data * pr_init(const struct pr_config *cfg);
+void pr_deinit(struct pr_data *pr);
+
+#endif /* PROXIMITY_RANGING_H */
index cb07e7364352e2fa0128d6be1ce1776716ee85bd..e09768a9d9c78c36af94e870c2b60532ec0b7372 100644 (file)
@@ -290,6 +290,12 @@ NEED_OFFCHANNEL=y
 L_CFLAGS += -DCONFIG_NAN_USD
 endif
 
+ifdef CONFIG_PR
+OBJS += src/common/proximity_ranging.c
+OBJS += pr_supplicant.c
+L_CFLAGS += -DCONFIG_PR
+endif
+
 ifdef CONFIG_OWE
 L_CFLAGS += -DCONFIG_OWE
 NEED_ECC=y
index 96299841deb8de1abf973c8bb8fbfd28586fba26..b72d9399e17ee0d9f37adf1ccc606a0c62acec4f 100644 (file)
@@ -324,6 +324,12 @@ NEED_OFFCHANNEL=y
 CFLAGS += -DCONFIG_NAN_USD
 endif
 
+ifdef CONFIG_PR
+OBJS += ../src/common/proximity_ranging.o
+OBJS += pr_supplicant.o
+CFLAGS += -DCONFIG_PR
+endif
+
 ifdef CONFIG_OWE
 CFLAGS += -DCONFIG_OWE
 NEED_ECC=y
diff --git a/wpa_supplicant/pr_supplicant.c b/wpa_supplicant/pr_supplicant.c
new file mode 100644 (file)
index 0000000..d5672dc
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Proxmity Ranging
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ *
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
+ */
+
+#include "includes.h"
+
+#include "utils/common.h"
+#include "common/proximity_ranging.h"
+#include "wpa_supplicant_i.h"
+#include "config.h"
+#include "pr_supplicant.h"
+
+
+int wpas_pr_init(struct wpa_global *global, struct wpa_supplicant *wpa_s)
+{
+       struct pr_config pr;
+
+       if (global->pr)
+               return 0;
+
+       os_memset(&pr, 0, sizeof(pr));
+
+       os_memcpy(pr.dev_addr, wpa_s->own_addr, ETH_ALEN);
+       pr.cb_ctx = wpa_s;
+       pr.dev_name = wpa_s->conf->device_name;
+
+       global->pr = pr_init(&pr);
+       if (!global->pr) {
+               wpa_printf(MSG_DEBUG, "PR: Failed to init PR");
+               return -1;
+       }
+       global->pr_init_wpa_s = wpa_s;
+
+       return 0;
+}
+
+
+void wpas_pr_deinit(struct wpa_supplicant *wpa_s)
+{
+       if (wpa_s == wpa_s->global->pr_init_wpa_s) {
+               pr_deinit(wpa_s->global->pr);
+               wpa_s->global->pr = NULL;
+               wpa_s->global->pr_init_wpa_s = NULL;
+       }
+}
diff --git a/wpa_supplicant/pr_supplicant.h b/wpa_supplicant/pr_supplicant.h
new file mode 100644 (file)
index 0000000..46cd285
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Proxmity Ranging
+ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
+ *
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
+ */
+
+#ifndef PR_SUPPLICANT_H
+#define PR_SUPPLICANT_H
+
+#ifdef CONFIG_PR
+
+int wpas_pr_init(struct wpa_global *global, struct wpa_supplicant *wpa_s);
+void wpas_pr_deinit(struct wpa_supplicant *wpa_s);
+
+#else /* CONFIG_PR */
+
+static inline int wpas_pr_init(struct wpa_global *global,
+                              struct wpa_supplicant *wpa_s)
+{
+       return -1;
+}
+
+static inline void wpas_pr_deinit(struct wpa_supplicant *wpa_s)
+{
+}
+
+#endif /* CONFIG_PR */
+
+#endif /* PR_SUPPLICANT_H */
index c9257bc853f2c0003061b2eec1ac4ead7f820441..27047d185841748c4a84ab88ebe91068c2c01a04 100644 (file)
@@ -66,6 +66,7 @@
 #include "mesh.h"
 #include "dpp_supplicant.h"
 #include "nan_usd.h"
+#include "pr_supplicant.h"
 #ifdef CONFIG_MESH
 #include "ap/ap_config.h"
 #include "ap/hostapd.h"
@@ -740,6 +741,8 @@ static void wpa_supplicant_cleanup(struct wpa_supplicant *wpa_s)
 
        wpas_p2p_deinit(wpa_s);
 
+       wpas_pr_deinit(wpa_s);
+
 #ifdef CONFIG_OFFCHANNEL
        offchannel_deinit(wpa_s);
 #endif /* CONFIG_OFFCHANNEL */
@@ -7969,6 +7972,9 @@ static int wpa_supplicant_init_iface(struct wpa_supplicant *wpa_s,
                return -1;
        }
 
+       if (wpas_pr_init(wpa_s->global, wpa_s) < 0)
+               return -1;
+
        if (wpa_bss_init(wpa_s) < 0)
                return -1;
 
index dbdbb69c55f312bc4703364dde44a117c775f339..676c017020a30b8ab21199e15a898e33bdb75bed 100644 (file)
@@ -293,9 +293,11 @@ struct wpa_global {
        size_t drv_count;
        struct os_time suspend_time;
        struct p2p_data *p2p;
+       struct pr_data *pr;
        struct wpa_supplicant *p2p_init_wpa_s;
        struct wpa_supplicant *p2p_group_formation;
        struct wpa_supplicant *p2p_invite_group;
+       struct wpa_supplicant *pr_init_wpa_s;
        u8 p2p_dev_addr[ETH_ALEN];
        struct os_reltime p2p_go_wait_client;
        struct dl_list p2p_srv_bonjour; /* struct p2p_srv_bonjour */