qcacld-3.0: Add FTM TIME SYNC component

Add support for FTM TIME SYNC feature.

Change-Id: Idd022b3b105febd25b9353d7f7c4a046c9143585
CRs-Fixed: 2615242
diff --git a/Kbuild b/Kbuild
index 5c7a30e..ad03ca4 100644
--- a/Kbuild
+++ b/Kbuild
@@ -1047,6 +1047,17 @@
 		$(PKT_CAPTURE_DIR)/dispatcher/src/wlan_pkt_capture_ucfg_api.o
 endif
 
+########## FTM TIME SYNC ##########
+
+FTM_TIME_SYNC_DIR := components/ftm_time_sync
+FTM_TIME_SYNC_INC := -I$(WLAN_ROOT)/$(FTM_TIME_SYNC_DIR)/core/inc \
+		  -I$(WLAN_ROOT)/$(FTM_TIME_SYNC_DIR)/dispatcher/inc
+
+ifeq ($(CONFIG_FEATURE_WLAN_TIME_SYNC_FTM), y)
+FTM_TIME_SYNC_OBJS := $(FTM_TIME_SYNC_DIR)/core/src/ftm_time_sync_main.o \
+		$(FTM_TIME_SYNC_DIR)/dispatcher/src/ftm_time_sync_ucfg_api.o
+endif
+
 ########## CLD TARGET_IF #######
 CLD_TARGET_IF_DIR := components/target_if
 
@@ -1996,6 +2007,7 @@
 INCS +=		$(DISA_INC)
 INCS +=		$(ACTION_OUI_INC)
 INCS +=		$(PKT_CAPTURE_INC)
+INCS +=		$(FTM_TIME_SYNC_INC)
 
 INCS +=		$(UMAC_DISP_INC)
 INCS +=		$(UMAC_SCAN_INC)
@@ -2108,6 +2120,10 @@
 OBJS +=		$(PKT_CAPTURE_OBJS)
 endif
 
+ifeq ($(CONFIG_FEATURE_WLAN_TIME_SYNC_FTM), y)
+OBJS +=		$(FTM_TIME_SYNC_OBJS)
+endif
+
 OBJS +=		$(UMAC_DISP_OBJS)
 OBJS +=		$(UMAC_SCAN_OBJS)
 OBJS +=		$(UMAC_COMMON_OBJS)
@@ -2205,6 +2221,7 @@
 cppflags-$(CONFIG_PLD_USB_CNSS) += -DCONFIG_PLD_USB_CNSS
 cppflags-$(CONFIG_PLD_SDIO_CNSS2) += -DCONFIG_PLD_SDIO_CNSS2
 cppflags-$(CONFIG_WLAN_RECORD_RX_PADDR) += -DHIF_RECORD_RX_PADDR
+cppflags-$(CONFIG_FEATURE_WLAN_TIME_SYNC_FTM) += -DFEATURE_WLAN_TIME_SYNC_FTM
 
 #For both legacy and lithium chip's monitor mode config
 ifeq ($(CONFIG_FEATURE_MONITOR_MODE_SUPPORT), y)
diff --git a/components/ftm_time_sync/core/inc/ftm_time_sync_main.h b/components/ftm_time_sync/core/inc/ftm_time_sync_main.h
new file mode 100644
index 0000000..a7d5a8d
--- /dev/null
+++ b/components/ftm_time_sync/core/inc/ftm_time_sync_main.h
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2020, The Linux Foundation. All rights reserved.
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/**
+ * DOC: Declare private API which shall be used internally only
+ * in ftm_time_sync component. This file shall include prototypes of
+ * various notification handlers and logging functions.
+ *
+ * Note: This API should be never accessed out of ftm_time_sync component.
+ */
+
+#ifndef _FTM_TIME_SYNC_MAIN_H_
+#define _FTM_TIME_SYNC_MAIN_H_
+
+#include <qdf_types.h>
+#include "ftm_time_sync_priv.h"
+#include "ftm_time_sync_objmgr.h"
+
+#define ftm_time_sync_log(level, args...) \
+	QDF_TRACE(QDF_MODULE_ID_FTM_TIME_SYNC, level, ## args)
+
+#define ftm_time_sync_logfl(level, format, args...) \
+	ftm_time_sync_log(level, FL(format), ## args)
+
+#define ftm_time_sync_fatal(format, args...) \
+		ftm_time_sync_logfl(QDF_TRACE_LEVEL_FATAL, format, ## args)
+#define ftm_time_sync_err(format, args...) \
+		ftm_time_sync_logfl(QDF_TRACE_LEVEL_ERROR, format, ## args)
+#define ftm_time_sync_warn(format, args...) \
+		ftm_time_sync_logfl(QDF_TRACE_LEVEL_WARN, format, ## args)
+#define ftm_time_sync_info(format, args...) \
+		ftm_time_sync_logfl(QDF_TRACE_LEVEL_INFO, format, ## args)
+#define ftm_time_sync_debug(format, args...) \
+		ftm_time_sync_logfl(QDF_TRACE_LEVEL_DEBUG, format, ## args)
+
+#define FTM_TIME_SYNC_ENTER() ftm_time_sync_debug("enter")
+#define FTM_TIME_SYNC_EXIT() ftm_time_sync_debug("exit")
+
+/**
+ * ftm_time_sync_vdev_create_notification(): Handler for vdev create notify.
+ * @vdev: vdev which is going to be created by objmgr
+ * @arg: argument for notification handler.
+ *
+ * Allocate and attach vdev private object.
+ *
+ * Return: QDF_STATUS status in case of success else return error.
+ */
+QDF_STATUS ftm_timesync_vdev_create_notification(struct wlan_objmgr_vdev *vdev,
+						 void *arg);
+
+/**
+ * ftm_time_sync_vdev_destroy_notification(): Handler for vdev destroy notify.
+ * @vdev: vdev which is going to be destroyed by objmgr
+ * @arg: argument for notification handler.
+ *
+ * Deallocate and detach vdev private object.
+ *
+ * Return QDF_STATUS status in case of success else return error
+ */
+QDF_STATUS
+ftm_timesync_vdev_destroy_notification(struct wlan_objmgr_vdev *vdev,
+				       void *arg);
+
+#endif /* end of _FTM_TIME_SYNC_MAIN_H_ */
diff --git a/components/ftm_time_sync/core/inc/ftm_time_sync_objmgr.h b/components/ftm_time_sync/core/inc/ftm_time_sync_objmgr.h
new file mode 100644
index 0000000..59b6168
--- /dev/null
+++ b/components/ftm_time_sync/core/inc/ftm_time_sync_objmgr.h
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2020, The Linux Foundation. All rights reserved.
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/**
+ * DOC: This file contains various object manager related wrappers and helpers
+ */
+
+#ifndef _FTM_TIME_SYNC_OBJMGR_H
+#define _FTM_TIME_SYNC_OBJMGR_H
+
+#include "wlan_cmn.h"
+#include "wlan_objmgr_cmn.h"
+#include "wlan_objmgr_vdev_obj.h"
+#include "wlan_objmgr_global_obj.h"
+
+/**
+ * ftm_timesync_vdev_get_ref() - Wrapper to increment ftm_timesync ref count
+ * @vdev: vdev object
+ *
+ * Wrapper for ftm_timesync to increment ref count after checking valid
+ * object state.
+ *
+ * Return: SUCCESS/FAILURE
+ */
+static inline
+QDF_STATUS ftm_timesync_vdev_get_ref(struct wlan_objmgr_vdev *vdev)
+{
+	return wlan_objmgr_vdev_try_get_ref(vdev, FTM_TIME_SYNC_ID);
+}
+
+/**
+ * ftm_timesync_vdev_put_ref() - Wrapper to decrement ftm_timesync ref count
+ * @vdev: vdev object
+ *
+ * Wrapper for ftm_timesync to decrement ref count of vdev.
+ *
+ * Return: SUCCESS/FAILURE
+ */
+static inline
+void ftm_timesync_vdev_put_ref(struct wlan_objmgr_vdev *vdev)
+{
+	return wlan_objmgr_vdev_release_ref(vdev, FTM_TIME_SYNC_ID);
+}
+
+/**
+ * ftm_timesync_vdev_get_priv(): Wrapper to retrieve vdev priv obj
+ * @vdev: vdev pointer
+ *
+ * Wrapper for ftm_timesync to get vdev private object pointer.
+ *
+ * Return: Private object of vdev
+ */
+static inline struct ftm_timesync_vdev_priv *
+ftm_timesync_vdev_get_priv(struct wlan_objmgr_vdev *vdev)
+{
+	struct ftm_timesync_vdev_priv *vdev_priv;
+
+	vdev_priv = wlan_objmgr_vdev_get_comp_private_obj(
+					vdev, WLAN_UMAC_COMP_FTM_TIME_SYNC);
+	QDF_BUG(vdev_priv);
+
+	return vdev_priv;
+}
+
+#endif /* _FTM_TIME_SYNC_OBJMGR_H */
diff --git a/components/ftm_time_sync/core/inc/ftm_time_sync_priv.h b/components/ftm_time_sync/core/inc/ftm_time_sync_priv.h
new file mode 100644
index 0000000..ddeb57e
--- /dev/null
+++ b/components/ftm_time_sync/core/inc/ftm_time_sync_priv.h
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2020, The Linux Foundation. All rights reserved.
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/**
+ * DOC: Declare private API which shall be used internally only
+ * in ftm_timesync component. This file shall include prototypes of
+ * ftm_timesync parsing and send logic.
+ *
+ * Note: This API should be never accessed out of ftm_timesync component.
+ */
+
+#ifndef _FTM_TIME_SYNC_PRIV_STRUCT_H_
+#define _FTM_TIME_SYNC_PRIV_STRUCT_H_
+
+#include <qdf_list.h>
+#include <qdf_types.h>
+#include "ftm_time_sync_objmgr.h"
+
+#define WLAN_FTM_TIME_SYNC_PAIR_MAX 32
+
+/**
+ * struct wlan_time_sync_pair - wlan time sync pair
+ * @qtime_master: master qtime
+ * @qtime_slave: slave qtime
+ */
+struct wlan_time_sync_pair {
+	uint64_t qtime_master;
+	uint64_t qtime_slave;
+};
+
+/**
+ * struct ftm_timesync_vdev_priv - Private object to be stored in vdev
+ * @qtime_ref: qtime ref
+ * @mac_ref: mac time ref
+ * @time_pair: array of master/slave qtime pair
+ */
+
+struct ftm_timesync_priv {
+	uint64_t qtime_ref;
+	uint64_t mac_ref;
+	struct wlan_time_sync_pair time_pair[WLAN_FTM_TIME_SYNC_PAIR_MAX];
+};
+
+/**
+ * struct ftm_timesync_vdev_priv - Private object to be stored in vdev
+ * @vdev: pointer to vdev object
+ * @ftm_ts_priv: time sync private struct
+ */
+struct ftm_timesync_vdev_priv {
+	struct wlan_objmgr_vdev *vdev;
+	struct ftm_timesync_priv ftm_ts_priv;
+};
+
+#endif /* End  of _FTM_TIME_SYNC_PRIV_STRUCT_H_ */
diff --git a/components/ftm_time_sync/core/src/ftm_time_sync_main.c b/components/ftm_time_sync/core/src/ftm_time_sync_main.c
new file mode 100644
index 0000000..e16139e
--- /dev/null
+++ b/components/ftm_time_sync/core/src/ftm_time_sync_main.c
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2020, The Linux Foundation. All rights reserved.
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/**
+ * DOC: Implement various notification handlers which are accessed
+ * internally in ftm_timesync component only.
+ */
+
+#include "ftm_time_sync_main.h"
+
+QDF_STATUS
+ftm_timesync_vdev_create_notification(struct wlan_objmgr_vdev *vdev, void *arg)
+{
+	struct ftm_timesync_vdev_priv *vdev_priv;
+	QDF_STATUS status;
+
+	vdev_priv = qdf_mem_malloc(sizeof(*vdev_priv));
+	if (!vdev_priv) {
+		status = QDF_STATUS_E_NOMEM;
+		goto exit;
+	}
+
+	status = wlan_objmgr_vdev_component_obj_attach(
+				vdev, WLAN_UMAC_COMP_FTM_TIME_SYNC,
+				(void *)vdev_priv, QDF_STATUS_SUCCESS);
+	if (QDF_IS_STATUS_ERROR(status)) {
+		ftm_time_sync_err("Failed to attach priv with vdev");
+		goto free_vdev_priv;
+	}
+
+	vdev_priv->vdev = vdev;
+	goto exit;
+
+free_vdev_priv:
+	qdf_mem_free(vdev_priv);
+	status = QDF_STATUS_E_INVAL;
+exit:
+	return status;
+}
+
+QDF_STATUS
+ftm_timesync_vdev_destroy_notification(struct wlan_objmgr_vdev *vdev, void *arg)
+{
+	struct ftm_timesync_vdev_priv *vdev_priv = NULL;
+	QDF_STATUS status = QDF_STATUS_E_FAILURE;
+
+	vdev_priv = ftm_timesync_vdev_get_priv(vdev);
+	if (!vdev_priv) {
+		ftm_time_sync_err("vdev priv is NULL");
+		goto exit;
+	}
+
+	status = wlan_objmgr_vdev_component_obj_detach(
+					vdev, WLAN_UMAC_COMP_FTM_TIME_SYNC,
+					(void *)vdev_priv);
+	if (QDF_IS_STATUS_ERROR(status))
+		ftm_time_sync_err("Failed to detach priv with vdev");
+
+	qdf_mem_free(vdev_priv);
+	vdev_priv = NULL;
+
+exit:
+	return status;
+}
diff --git a/components/ftm_time_sync/dispatcher/inc/ftm_time_sync_ucfg_api.h b/components/ftm_time_sync/dispatcher/inc/ftm_time_sync_ucfg_api.h
new file mode 100644
index 0000000..8f7169d
--- /dev/null
+++ b/components/ftm_time_sync/dispatcher/inc/ftm_time_sync_ucfg_api.h
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2020, The Linux Foundation. All rights reserved.
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/**
+ * DOC: Declare public API related to the ftm timesync called by north bound
+ * HDD/OSIF/LIM
+ */
+
+#ifndef _FTM_TIME_SYNC_UCFG_API_H_
+#define _FTM_TIME_SYNC_UCFG_API_H_
+
+#include <qdf_status.h>
+#include <qdf_types.h>
+//#include "ftm_time_sync_public_struct.h"
+#include "ftm_time_sync_objmgr.h"
+
+#ifdef FEATURE_WLAN_TIME_SYNC_FTM
+
+/**
+ * ucfg_ftm_timesync_init() - FTM time sync component initialization.
+ *
+ * This function initializes the ftm time sync component and registers
+ * the handlers which are invoked on vdev creation.
+ *
+ * Return: For successful registration - QDF_STATUS_SUCCESS,
+ *	   else QDF_STATUS error codes.
+ */
+QDF_STATUS ucfg_ftm_timesync_init(void);
+
+/**
+ * ucfg_ftm_timesync_deinit() - FTM time sync component deinit.
+ *
+ * This function deinits ftm time sync component.
+ *
+ * Return: None
+ */
+void ucfg_ftm_timesync_deinit(void);
+
+#else
+
+static inline
+QDF_STATUS ucfg_ftm_timesync_init(void)
+{
+	return QDF_STATUS_SUCCESS;
+}
+
+static inline
+void ucfg_ftm_timesync_deinit(void)
+{
+}
+
+#endif /* FEATURE_WLAN_TIME_SYNC_FTM */
+#endif /* _FTM_TIME_SYNC_UCFG_API_H_ */
diff --git a/components/ftm_time_sync/dispatcher/src/ftm_time_sync_ucfg_api.c b/components/ftm_time_sync/dispatcher/src/ftm_time_sync_ucfg_api.c
new file mode 100644
index 0000000..cd4412c
--- /dev/null
+++ b/components/ftm_time_sync/dispatcher/src/ftm_time_sync_ucfg_api.c
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2020, The Linux Foundation. All rights reserved.
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/**
+ * DOC: Public API implementation of ftm timesync called by north bound iface.
+ */
+
+#include "ftm_time_sync_ucfg_api.h"
+#include "ftm_time_sync_main.h"
+#include <qdf_str.h>
+
+QDF_STATUS ucfg_ftm_timesync_init(void)
+{
+	QDF_STATUS status;
+
+	status = wlan_objmgr_register_vdev_create_handler(
+				WLAN_UMAC_COMP_FTM_TIME_SYNC,
+				ftm_timesync_vdev_create_notification, NULL);
+	if (!QDF_IS_STATUS_SUCCESS(status)) {
+		ftm_time_sync_err("Failed to register vdev create handler");
+		goto exit;
+	}
+
+	status = wlan_objmgr_register_vdev_destroy_handler(
+				WLAN_UMAC_COMP_FTM_TIME_SYNC,
+				ftm_timesync_vdev_destroy_notification, NULL);
+	if (QDF_IS_STATUS_SUCCESS(status)) {
+		ftm_time_sync_debug("vdev create/delete notif registered");
+		goto exit;
+	}
+
+	ftm_time_sync_err("Failed to register vdev delete handler");
+	wlan_objmgr_unregister_vdev_create_handler(
+			WLAN_UMAC_COMP_FTM_TIME_SYNC,
+			ftm_timesync_vdev_create_notification, NULL);
+
+exit:
+	return status;
+}
+
+void ucfg_ftm_timesync_deinit(void)
+{
+	QDF_STATUS status;
+
+	status = wlan_objmgr_unregister_vdev_create_handler(
+				WLAN_UMAC_COMP_FTM_TIME_SYNC,
+				ftm_timesync_vdev_create_notification, NULL);
+	if (!QDF_IS_STATUS_SUCCESS(status))
+		ftm_time_sync_err("Failed to unregister vdev create handler");
+
+	status = wlan_objmgr_unregister_vdev_destroy_handler(
+				WLAN_UMAC_COMP_FTM_TIME_SYNC,
+				ftm_timesync_vdev_destroy_notification,
+				NULL);
+	if (!QDF_IS_STATUS_SUCCESS(status))
+		ftm_time_sync_err("Failed to unregister vdev delete handler");
+}
diff --git a/core/hdd/src/wlan_hdd_main.c b/core/hdd/src/wlan_hdd_main.c
index 9e1d461..35130f2 100644
--- a/core/hdd/src/wlan_hdd_main.c
+++ b/core/hdd/src/wlan_hdd_main.c
@@ -172,6 +172,7 @@
 #include <wlan_hdd_debugfs_coex.h>
 #include <wlan_hdd_debugfs_config.h>
 #include "wlan_blm_ucfg_api.h"
+#include "ftm_time_sync_ucfg_api.h"
 #include "ol_txrx.h"
 #include "wlan_hdd_sta_info.h"
 #include "mac_init_api.h"
@@ -344,6 +345,7 @@
 	[QDF_MODULE_ID_SPECTRAL] = {QDF_TRACE_LEVEL_ALL},
 	[QDF_MODULE_ID_WIFIPOS] = {QDF_TRACE_LEVEL_ALL},
 	[QDF_MODULE_ID_PKT_CAPTURE] = {QDF_TRACE_LEVEL_ALL},
+	[QDF_MODULE_ID_FTM_TIME_SYNC] = {QDF_TRACE_LEVEL_ALL},
 };
 
 struct notifier_block hdd_netdev_notifier;
@@ -14274,13 +14276,18 @@
 	if (QDF_IS_STATUS_ERROR(status))
 		goto blm_deinit;
 
+	status = ucfg_ftm_timesync_init();
+	if (QDF_IS_STATUS_ERROR(status))
+		goto pkt_capture_deinit;
+
 	return QDF_STATUS_SUCCESS;
 
+pkt_capture_deinit:
+	ucfg_pkt_capture_deinit();
 blm_deinit:
 	ucfg_blm_deinit();
 tdls_deinit:
 	ucfg_tdls_deinit();
-
 policy_deinit:
 	policy_mgr_deinit();
 interop_issues_ap_deinit:
@@ -14321,6 +14328,7 @@
 static void hdd_component_deinit(void)
 {
 	/* deinitialize non-converged components */
+	ucfg_ftm_timesync_deinit();
 	ucfg_pkt_capture_deinit();
 	ucfg_blm_deinit();
 	ucfg_tdls_deinit();