From: Ilan Peer <ilan.peer@xxxxxxxxx> 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@xxxxxxxxx> --- src/nan/Makefile | 3 ++ src/nan/nan.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++ src/nan/nan.h | 37 +++++++++++++++++++ src/nan/nan_i.h | 19 ++++++++++ 4 files changed, 151 insertions(+) create mode 100644 src/nan/Makefile create mode 100644 src/nan/nan.c create mode 100644 src/nan/nan.h create mode 100644 src/nan/nan_i.h diff --git a/src/nan/Makefile b/src/nan/Makefile new file mode 100644 index 0000000000..bd8a66a5b3 --- /dev/null +++ b/src/nan/Makefile @@ -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 index 0000000000..4030e5d698 --- /dev/null +++ b/src/nan/nan.c @@ -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, "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 index 0000000000..0c447605ec --- /dev/null +++ b/src/nan/nan.h @@ -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 index 0000000000..ade4229f70 --- /dev/null +++ b/src/nan/nan_i.h @@ -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 -- 2.49.0 _______________________________________________ Hostap mailing list Hostap@xxxxxxxxxxxxxxxxxxx http://lists.infradead.org/mailman/listinfo/hostap