]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
NAN: Add a basic NAN module
authorIlan Peer <ilan.peer@intel.com>
Tue, 23 Dec 2025 11:45:55 +0000 (13:45 +0200)
committerJouni Malinen <j@w1.fi>
Thu, 29 Jan 2026 10:31:55 +0000 (12:31 +0200)
Add basic NAN module as a starting point for NAN logic implementation.
Currently the module has basic support for start/stop.

Signed-off-by: Ilan Peer <ilan.peer@intel.com>
src/nan/Makefile [new file with mode: 0644]
src/nan/nan.c [new file with mode: 0644]
src/nan/nan.h [new file with mode: 0644]
src/nan/nan_i.h [new file with mode: 0644]

diff --git a/src/nan/Makefile b/src/nan/Makefile
new file mode 100644 (file)
index 0000000..bd8a66a
--- /dev/null
@@ -0,0 +1,3 @@
+LIB_OBJS= nan.o
+
+include ../lib.rules
diff --git a/src/nan/nan.c b/src/nan/nan.c
new file mode 100644 (file)
index 0000000..76a08c8
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * Wi-Fi Aware - NAN module
+ * Copyright (C) 2025 Intel Corporation
+ *
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
+ */
+
+#include "includes.h"
+#include "common.h"
+#include "nan.h"
+#include "nan_i.h"
+
+
+struct nan_data * nan_init(const struct nan_config *cfg)
+{
+       struct nan_data *nan;
+
+       if (!cfg->start || !cfg->stop)
+               return NULL;
+
+       nan = os_zalloc(sizeof(*nan));
+       if (!nan)
+               return NULL;
+
+       nan->cfg = os_memdup(cfg, sizeof(*cfg));
+       if (!nan->cfg) {
+               os_free(nan);
+               return NULL;
+       }
+
+       wpa_printf(MSG_DEBUG, "NAN: Initialized");
+
+       return nan;
+}
+
+
+void nan_deinit(struct nan_data *nan)
+{
+       wpa_printf(MSG_DEBUG, "NAN: Deinit");
+       os_free(nan->cfg);
+       os_free(nan);
+}
+
+
+int nan_start(struct nan_data *nan, struct nan_cluster_config *config)
+{
+       int ret;
+
+       wpa_printf(MSG_DEBUG, "NAN: Starting/joining NAN cluster");
+
+       if (nan->nan_started) {
+               wpa_printf(MSG_DEBUG, "NAN: Already started");
+               return -1;
+       }
+
+       ret = nan->cfg->start(nan->cfg->cb_ctx, config);
+       if (ret) {
+               wpa_printf(MSG_DEBUG, "NAN: Failed to start - ret=%d", ret);
+               return ret;
+       }
+       nan->nan_started = 1;
+
+       return 0;
+}
+
+
+void nan_flush(struct nan_data *nan)
+{
+       wpa_printf(MSG_DEBUG, "NAN: Reset internal state");
+
+       if (!nan->nan_started) {
+               wpa_printf(MSG_DEBUG, "NAN: Already stopped");
+               return;
+       }
+
+       nan->nan_started = 0;
+}
+
+
+void nan_stop(struct nan_data *nan)
+{
+       wpa_printf(MSG_DEBUG, "NAN: Stopping");
+
+       if (!nan->nan_started) {
+               wpa_printf(MSG_DEBUG, "NAN: Already stopped");
+               return;
+       }
+
+       nan_flush(nan);
+       nan->cfg->stop(nan->cfg->cb_ctx);
+}
diff --git a/src/nan/nan.h b/src/nan/nan.h
new file mode 100644 (file)
index 0000000..0c44760
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Wi-Fi Aware - NAN module
+ * Copyright (C) 2025 Intel Corporation
+ *
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
+ */
+
+#ifndef NAN_H
+#define NAN_H
+
+struct nan_cluster_config;
+
+struct nan_config {
+       void *cb_ctx;
+
+       /**
+        * start - Start NAN
+        * @ctx: Callback context from cb_ctx
+        * @config: NAN cluster configuration
+        */
+       int (*start)(void *ctx, struct nan_cluster_config *config);
+
+       /**
+        * stop - Stop NAN
+        * @ctx: Callback context from cb_ctx
+        */
+       void (*stop)(void *ctx);
+};
+
+struct nan_data * nan_init(const struct nan_config *cfg);
+void nan_deinit(struct nan_data *nan);
+int nan_start(struct nan_data *nan, struct nan_cluster_config *config);
+void nan_stop(struct nan_data *nan);
+void nan_flush(struct nan_data *nan);
+
+#endif /* NAN_H */
diff --git a/src/nan/nan_i.h b/src/nan/nan_i.h
new file mode 100644 (file)
index 0000000..473f41c
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * Wi-Fi Aware - Internal definitions for NAN module
+ * Copyright (C) 2025 Intel Corporation
+ *
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
+ */
+
+#ifndef NAN_I_H
+#define NAN_I_H
+
+struct nan_config;
+
+struct nan_data {
+       struct nan_config *cfg;
+       u8 nan_started:1;
+};
+
+#endif /* NAN_I_H */