diff --git a/Kbuild b/Kbuild index f8d649eedb3f..5c7a30e90335 100644 --- a/Kbuild +++ b/Kbuild @@ -1036,6 +1036,17 @@ ACTION_OUI_OBJS := $(ACTION_OUI_DIR)/core/src/wlan_action_oui_main.o \ $(ACTION_OUI_DIR)/dispatcher/src/wlan_action_oui_ucfg_api.o endif +######## PACKET CAPTURE ######## + +PKT_CAPTURE_DIR := components/pkt_capture +PKT_CAPTURE_INC := -I$(WLAN_ROOT)/$(PKT_CAPTURE_DIR)/core/inc \ + -I$(WLAN_ROOT)/$(PKT_CAPTURE_DIR)/dispatcher/inc + +ifeq ($(CONFIG_WLAN_FEATURE_PKT_CAPTURE), y) +PKT_CAPTURE_OBJS := $(PKT_CAPTURE_DIR)/core/src/wlan_pkt_capture_main.o \ + $(PKT_CAPTURE_DIR)/dispatcher/src/wlan_pkt_capture_ucfg_api.o +endif + ########## CLD TARGET_IF ####### CLD_TARGET_IF_DIR := components/target_if @@ -1984,6 +1995,7 @@ INCS += $(HOST_DIAG_LOG_INC) INCS += $(DISA_INC) INCS += $(ACTION_OUI_INC) +INCS += $(PKT_CAPTURE_INC) INCS += $(UMAC_DISP_INC) INCS += $(UMAC_SCAN_INC) @@ -2092,6 +2104,10 @@ ifeq ($(CONFIG_WLAN_FEATURE_ACTION_OUI), y) OBJS += $(ACTION_OUI_OBJS) endif +ifeq ($(CONFIG_WLAN_FEATURE_PKT_CAPTURE), y) +OBJS += $(PKT_CAPTURE_OBJS) +endif + OBJS += $(UMAC_DISP_OBJS) OBJS += $(UMAC_SCAN_OBJS) OBJS += $(UMAC_COMMON_OBJS) @@ -2687,6 +2703,8 @@ cppflags-$(CONFIG_MCC_TO_SCC_SWITCH) += -DFEATURE_WLAN_MCC_TO_SCC_SWITCH cppflags-$(CONFIG_FEATURE_WLAN_D0WOW) += -DFEATURE_WLAN_D0WOW +cppflags-$(CONFIG_WLAN_FEATURE_PKT_CAPTURE) += -DWLAN_FEATURE_PKT_CAPTURE + cppflags-$(CONFIG_QCA_WIFI_NAPIER_EMULATION) += -DQCA_WIFI_NAPIER_EMULATION cppflags-$(CONFIG_SHADOW_V2) += -DCONFIG_SHADOW_V2 cppflags-$(CONFIG_QCA6290_HEADERS_DEF) += -DQCA6290_HEADERS_DEF diff --git a/components/pkt_capture/core/inc/wlan_pkt_capture_main.h b/components/pkt_capture/core/inc/wlan_pkt_capture_main.h new file mode 100644 index 000000000000..053e1083d9fa --- /dev/null +++ b/components/pkt_capture/core/inc/wlan_pkt_capture_main.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: Declare private API which shall be used internally only + * in pkt_capture component. This file shall include prototypes of + * various notification handlers and logging functions. + * + * Note: This API should be never accessed out of pkt_capture component. + */ + +#ifndef _WLAN_PKT_CAPTURE_MAIN_H_ +#define _WLAN_PKT_CAPTURE_MAIN_H_ + +#include +#include "wlan_pkt_capture_priv.h" +#include "wlan_pkt_capture_objmgr.h" + +#define pkt_capture_log(level, args...) \ + QDF_TRACE(QDF_MODULE_ID_PKT_CAPTURE, level, ## args) + +#define pkt_capture_logfl(level, format, args...) \ + pkt_capture_log(level, FL(format), ## args) + +#define pkt_capture_fatal(format, args...) \ + pkt_capture_logfl(QDF_TRACE_LEVEL_FATAL, format, ## args) +#define pkt_capture_err(format, args...) \ + pkt_capture_logfl(QDF_TRACE_LEVEL_ERROR, format, ## args) +#define pkt_capture_warn(format, args...) \ + pkt_capture_logfl(QDF_TRACE_LEVEL_WARN, format, ## args) +#define pkt_capture_info(format, args...) \ + pkt_capture_logfl(QDF_TRACE_LEVEL_INFO, format, ## args) +#define pkt_capture_debug(format, args...) \ + pkt_capture_logfl(QDF_TRACE_LEVEL_DEBUG, format, ## args) + +#define PKT_CAPTURE_ENTER() pkt_capture_debug("enter") +#define PKT_CAPTURE_EXIT() pkt_capture_debug("exit") + +/** + * pkt_capture_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 +pkt_capture_vdev_create_notification(struct wlan_objmgr_vdev *vdev, void *arg); + +/** + * pkt_capture_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 +pkt_capture_vdev_destroy_notification(struct wlan_objmgr_vdev *vdev, void *arg); + +#endif /* end of _WLAN_PKT_CAPTURE_MAIN_H_ */ diff --git a/components/pkt_capture/core/inc/wlan_pkt_capture_objmgr.h b/components/pkt_capture/core/inc/wlan_pkt_capture_objmgr.h new file mode 100644 index 000000000000..b89541e83ebc --- /dev/null +++ b/components/pkt_capture/core/inc/wlan_pkt_capture_objmgr.h @@ -0,0 +1,81 @@ +/* + * 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 _WLAN_PKT_CAPTURE_OBJMGR_H +#define _WLAN_PKT_CAPTURE_OBJMGR_H + +#include "wlan_cmn.h" +#include "wlan_objmgr_cmn.h" +#include "wlan_objmgr_vdev_obj.h" +#include "wlan_objmgr_global_obj.h" + +/** + * pkt_capture_vdev_get_ref() - Wrapper to increment pkt_capture ref count + * @vdev: vdev object + * + * Wrapper for pkt_capture to increment ref count after checking valid + * object state. + * + * Return: SUCCESS/FAILURE + */ +static inline +QDF_STATUS pkt_capture_vdev_get_ref(struct wlan_objmgr_vdev *vdev) +{ + return wlan_objmgr_vdev_try_get_ref(vdev, WLAN_PKT_CAPTURE_ID); +} + +/** + * pkt_capture_vdev_put_ref() - Wrapper to decrement pkt_capture ref count + * @vdev: vdev object + * + * Wrapper for pkt_capture to decrement ref count of vdev. + * + * Return: SUCCESS/FAILURE + */ +static inline +void pkt_capture_vdev_put_ref(struct wlan_objmgr_vdev *vdev) +{ + return wlan_objmgr_vdev_release_ref(vdev, WLAN_PKT_CAPTURE_ID); +} + +/** + * pkt_capture_vdev_get_priv() - Wrapper to retrieve vdev priv obj + * @vdev: vdev pointer + * + * Wrapper for pkt_capture to get vdev private object pointer. + * + * Return: Private object of vdev + */ +static inline struct pkt_capture_vdev_priv * +pkt_capture_vdev_get_priv(struct wlan_objmgr_vdev *vdev) +{ + struct pkt_capture_vdev_priv *vdev_priv; + + vdev_priv = wlan_objmgr_vdev_get_comp_private_obj( + vdev, + WLAN_UMAC_COMP_PKT_CAPTURE); + QDF_BUG(vdev_priv); + + return vdev_priv; +} + +#endif /* _WLAN_PKT_CAPTURE_OBJMGR_H */ diff --git a/components/pkt_capture/core/inc/wlan_pkt_capture_priv.h b/components/pkt_capture/core/inc/wlan_pkt_capture_priv.h new file mode 100644 index 000000000000..d7f40c345b63 --- /dev/null +++ b/components/pkt_capture/core/inc/wlan_pkt_capture_priv.h @@ -0,0 +1,39 @@ +/* + * 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 pkt_capture component. This file shall include prototypes of + * pkt_capture parsing and send logic. + * + * Note: This API should be never accessed out of pkt_capture component. + */ + +#ifndef _WLAN_PKT_CAPTURE_PRIV_STRUCT_H_ +#define _WLAN_PKT_CAPTURE_PRIV_STRUCT_H_ + +#include "wlan_pkt_capture_objmgr.h" + +/** + * struct pkt_capture_vdev_priv - Private object to be stored in vdev + * @vdev: pointer to vdev object + */ +struct pkt_capture_vdev_priv { + struct wlan_objmgr_vdev *vdev; +}; +#endif /* End of _WLAN_PKT_CAPTURE_PRIV_STRUCT_H_ */ diff --git a/components/pkt_capture/core/src/wlan_pkt_capture_main.c b/components/pkt_capture/core/src/wlan_pkt_capture_main.c new file mode 100644 index 000000000000..e066a7625efb --- /dev/null +++ b/components/pkt_capture/core/src/wlan_pkt_capture_main.c @@ -0,0 +1,97 @@ +/* + * 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 pkt_capture component only. + */ + +#include "wlan_pkt_capture_main.h" + +/** + * pkt_capture_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 +pkt_capture_vdev_create_notification(struct wlan_objmgr_vdev *vdev, void *arg) +{ + struct pkt_capture_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_PKT_CAPTURE, + (void *)vdev_priv, QDF_STATUS_SUCCESS); + if (!QDF_IS_STATUS_SUCCESS(status)) { + pkt_capture_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; +} + +/** + * pkt_capture_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 +pkt_capture_vdev_destroy_notification(struct wlan_objmgr_vdev *vdev, void *arg) +{ + struct pkt_capture_vdev_priv *vdev_priv = NULL; + QDF_STATUS status = QDF_STATUS_E_FAILURE; + + vdev_priv = pkt_capture_vdev_get_priv(vdev); + if (!vdev_priv) { + pkt_capture_err("vdev priv is NULL"); + goto exit; + } + + status = wlan_objmgr_vdev_component_obj_detach( + vdev, + WLAN_UMAC_COMP_PKT_CAPTURE, + (void *)vdev_priv); + if (!QDF_IS_STATUS_SUCCESS(status)) + pkt_capture_err("Failed to detach priv with psoc"); + + qdf_mem_free(vdev_priv); +exit: + return status; +} diff --git a/components/pkt_capture/dispatcher/inc/wlan_pkt_capture_ucfg_api.h b/components/pkt_capture/dispatcher/inc/wlan_pkt_capture_ucfg_api.h new file mode 100644 index 000000000000..a9ce41289feb --- /dev/null +++ b/components/pkt_capture/dispatcher/inc/wlan_pkt_capture_ucfg_api.h @@ -0,0 +1,61 @@ +/* + * 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 pkt_capture called by north bound + * HDD/OSIF/LIM + */ + +#ifndef _WLAN_PKT_CAPTURE_UCFG_API_H_ +#define _WLAN_PKT_CAPTURE_UCFG_API_H_ + +#include +#include +#include "wlan_pkt_capture_objmgr.h" + +#ifdef WLAN_FEATURE_PKT_CAPTURE +/** + * ucfg_pkt_capture_init() - Packet capture component initialization. + * + * This function gets called when packet capture initializing. + * + * Return: QDF_STATUS_SUCCESS - in case of success. + */ +QDF_STATUS ucfg_pkt_capture_init(void); + +/** + * ucfg_pkt_capture_deinit() - Packet capture component de-init. + * + * This function gets called when packet capture de-init. + * + * Return: None + */ +void ucfg_pkt_capture_deinit(void); +#else +static inline +QDF_STATUS ucfg_pkt_capture_init(void) +{ + return QDF_STATUS_SUCCESS; +} + +static inline +void ucfg_pkt_capture_deinit(void) +{ +} +#endif /* WLAN_FEATURE_PKT_CAPTURE */ +#endif /* _WLAN_PKT_CAPTURE_UCFG_API_H_ */ diff --git a/components/pkt_capture/dispatcher/src/wlan_pkt_capture_ucfg_api.c b/components/pkt_capture/dispatcher/src/wlan_pkt_capture_ucfg_api.c new file mode 100644 index 000000000000..1a9665e85ef8 --- /dev/null +++ b/components/pkt_capture/dispatcher/src/wlan_pkt_capture_ucfg_api.c @@ -0,0 +1,86 @@ +/* + * 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 pkt_capture called by north bound HDD/OSIF. + */ + +#include "wlan_pkt_capture_objmgr.h" +#include "wlan_pkt_capture_main.h" +#include "wlan_pkt_capture_ucfg_api.h" + +/** + * ucfg_pkt_capture_init() - Packet capture component initialization. + * + * This function gets called when packet capture initializing. + * + * Return: QDF_STATUS_SUCCESS - in case of success. + */ +QDF_STATUS ucfg_pkt_capture_init(void) +{ + QDF_STATUS status; + + status = wlan_objmgr_register_vdev_create_handler( + WLAN_UMAC_COMP_PKT_CAPTURE, + pkt_capture_vdev_create_notification, NULL); + if (!QDF_IS_STATUS_SUCCESS(status)) { + pkt_capture_err("Failed to register vdev create handler"); + goto exit; + } + + status = wlan_objmgr_register_vdev_destroy_handler( + WLAN_UMAC_COMP_PKT_CAPTURE, + pkt_capture_vdev_destroy_notification, NULL); + if (QDF_IS_STATUS_SUCCESS(status)) { + pkt_capture_debug("vdev create/del notifications registered"); + goto exit; + } + + pkt_capture_err("Failed to register vdev delete handler"); + wlan_objmgr_unregister_vdev_create_handler( + WLAN_UMAC_COMP_PKT_CAPTURE, + pkt_capture_vdev_create_notification, + NULL); +exit: + return status; +} + +/** + * ucfg_pkt_capture_deinit() - Packet capture component de-init. + * + * This function gets called when packet capture de-init. + * + * Return: None + */ +void ucfg_pkt_capture_deinit(void) +{ + QDF_STATUS status; + + status = wlan_objmgr_unregister_vdev_create_handler( + WLAN_UMAC_COMP_PKT_CAPTURE, + pkt_capture_vdev_create_notification, NULL); + if (!QDF_IS_STATUS_SUCCESS(status)) + pkt_capture_err("Failed to unregister vdev create handler"); + + status = wlan_objmgr_unregister_vdev_destroy_handler( + WLAN_UMAC_COMP_PKT_CAPTURE, + pkt_capture_vdev_destroy_notification, + NULL); + if (!QDF_IS_STATUS_SUCCESS(status)) + pkt_capture_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 effeeb23ecd7..c13d9ea803ab 100644 --- a/core/hdd/src/wlan_hdd_main.c +++ b/core/hdd/src/wlan_hdd_main.c @@ -175,6 +175,7 @@ #include "ol_txrx.h" #include "wlan_hdd_sta_info.h" #include "mac_init_api.h" +#include "wlan_pkt_capture_ucfg_api.h" #ifdef MODULE #define WLAN_MODULE_NAME module_name(THIS_MODULE) @@ -342,6 +343,7 @@ static const struct category_info cinfo[MAX_SUPPORTED_CATEGORY] = { [QDF_MODULE_ID_DIRECT_BUF_RX] = {QDF_TRACE_LEVEL_ALL}, [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}, }; struct notifier_block hdd_netdev_notifier; @@ -14268,8 +14270,14 @@ static QDF_STATUS hdd_component_init(void) if (QDF_IS_STATUS_ERROR(status)) goto tdls_deinit; + status = ucfg_pkt_capture_init(); + if (QDF_IS_STATUS_ERROR(status)) + goto blm_deinit; + return QDF_STATUS_SUCCESS; +blm_deinit: + ucfg_blm_deinit(); tdls_deinit: ucfg_tdls_deinit(); @@ -14313,6 +14321,7 @@ mlme_global_deinit: static void hdd_component_deinit(void) { /* deinitialize non-converged components */ + ucfg_pkt_capture_deinit(); ucfg_blm_deinit(); ucfg_tdls_deinit(); policy_mgr_deinit();