xref: /wlan-driver/qcacld-3.0/core/hdd/src/wlan_hdd_ftm.c (revision 5113495b16420b49004c444715d2daae2066e7dc)
1 /*
2  * Copyright (c) 2012-2020 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for
6  * any purpose with or without fee is hereby granted, provided that the
7  * above copyright notice and this permission notice appear in all
8  * copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 /**
21  * DOC: wlan_hdd_ftm.c
22  *
23  * This file contains the WLAN factory test mode implementation
24  */
25 
26 #include "cds_sched.h"
27 #include <cds_api.h>
28 #include "sir_types.h"
29 #include "qdf_types.h"
30 #include "sir_api.h"
31 #include "sir_mac_prot_def.h"
32 #include "sme_api.h"
33 #include "mac_init_api.h"
34 #include "wlan_qct_sys.h"
35 #include "wlan_hdd_misc.h"
36 #include "i_cds_packet.h"
37 #include "cds_reg_service.h"
38 #include "wlan_hdd_main.h"
39 #include "wlan_hdd_lpass.h"
40 #include "qwlan_version.h"
41 #include "wma_types.h"
42 
43 #ifdef QCA_WIFI_FTM
44 
45 #include "wlan_hdd_cfg80211.h"
46 #include "hif.h"
47 #include <wlan_ioctl_ftm.h>
48 #include <wlan_cfg80211_ftm.h>
49 
50 /**
51  * hdd_update_cds_config_ftm() - API to update cds configuration parameters
52  * for FTM mode.
53  * @hdd_ctx: HDD Context
54  *
55  * Return: 0 on success; errno on failure
56  */
57 
hdd_update_cds_config_ftm(struct hdd_context * hdd_ctx)58 int hdd_update_cds_config_ftm(struct hdd_context *hdd_ctx)
59 {
60 	struct cds_config_info *cds_cfg;
61 	QDF_STATUS status;
62 	bool self_recovery;
63 
64 	cds_cfg = qdf_mem_malloc(sizeof(*cds_cfg));
65 	if (!cds_cfg)
66 		return -ENOMEM;
67 
68 	status = ucfg_mlme_get_self_recovery(hdd_ctx->psoc, &self_recovery);
69 	if (QDF_IS_STATUS_ERROR(status)) {
70 		hdd_err("Failed to get self recovery ini config");
71 		return -EIO;
72 	}
73 
74 	cds_cfg->driver_type = QDF_DRIVER_TYPE_MFG;
75 	hdd_lpass_populate_cds_config(cds_cfg, hdd_ctx);
76 	cds_cfg->sub_20_channel_width = WLAN_SUB_20_CH_WIDTH_NONE;
77 	cds_cfg->self_recovery_enabled = self_recovery;
78 	cds_cfg->num_vdevs = hdd_ctx->config->num_vdevs;
79 	cds_init_ini_config(cds_cfg);
80 
81 	return 0;
82 }
83 
84 #ifdef LINUX_QCMBR
85 
86 /**
87  * wlan_hdd_qcmbr_ioctl() - Standard QCMBR ioctl handler
88  * @adapter: adapter upon which the ioctl was received
89  * @data: pointer to the raw command data in the ioctl request
90  *
91  * Return: 0 on success, non-zero on error
92  */
wlan_hdd_qcmbr_ioctl(struct hdd_adapter * adapter,void __user * data)93 static int wlan_hdd_qcmbr_ioctl(struct hdd_adapter *adapter, void __user *data)
94 {
95 	int ret, cmd;
96 	struct hdd_context *hdd_ctx = WLAN_HDD_GET_CTX(adapter);
97 
98 	ret = wlan_hdd_validate_context(hdd_ctx);
99 	if (ret)
100 		return ret;
101 
102 	if (get_user(cmd, (int *)data) != 0)
103 		return QDF_STATUS_E_FAILURE;
104 
105 	ret = wlan_ioctl_ftm_testmode_cmd(hdd_ctx->pdev, cmd,
106 				(uint8_t *)data + sizeof(cmd));
107 
108 	return ret;
109 }
110 
111 /**
112  * wlan_hdd_qcmbr_unified_ioctl() - Unified QCMBR ioctl handler
113  * @adapter: adapter upon which the ioctl was received
114  * @data: pointer to the raw command data in the ioctl request
115  *
116  * Return: 0 on success, non-zero on error
117  */
wlan_hdd_qcmbr_unified_ioctl(struct hdd_adapter * adapter,void __user * data)118 int wlan_hdd_qcmbr_unified_ioctl(struct hdd_adapter *adapter, void __user *data)
119 {
120 	int ret;
121 
122 	ret = wlan_hdd_qcmbr_ioctl(adapter, data);
123 
124 	return ret;
125 }
126 
127 #endif /* LINUX_QCMBR */
128 #endif /* QCA_WIFI_FTM */
129