1*5113495bSYour Name /*
2*5113495bSYour Name * Copyright (c) 2018-2020 The Linux Foundation. All rights reserved.
3*5113495bSYour Name *
4*5113495bSYour Name *
5*5113495bSYour Name * Permission to use, copy, modify, and/or distribute this software for
6*5113495bSYour Name * any purpose with or without fee is hereby granted, provided that the
7*5113495bSYour Name * above copyright notice and this permission notice appear in all
8*5113495bSYour Name * copies.
9*5113495bSYour Name *
10*5113495bSYour Name * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11*5113495bSYour Name * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12*5113495bSYour Name * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13*5113495bSYour Name * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14*5113495bSYour Name * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15*5113495bSYour Name * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16*5113495bSYour Name * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17*5113495bSYour Name * PERFORMANCE OF THIS SOFTWARE.
18*5113495bSYour Name */
19*5113495bSYour Name
20*5113495bSYour Name /**
21*5113495bSYour Name * DOC: This implementation of init/deint functions for FTM services.
22*5113495bSYour Name */
23*5113495bSYour Name
24*5113495bSYour Name #include "wlan_ftm_svc_i.h"
25*5113495bSYour Name #include <wlan_lmac_if_def.h>
26*5113495bSYour Name #include <wlan_ftm_ucfg_api.h>
27*5113495bSYour Name #include "target_if.h"
28*5113495bSYour Name
29*5113495bSYour Name static inline struct wlan_lmac_if_ftm_tx_ops *
wlan_psoc_get_ftm_txops(struct wlan_objmgr_psoc * psoc)30*5113495bSYour Name wlan_psoc_get_ftm_txops(struct wlan_objmgr_psoc *psoc)
31*5113495bSYour Name {
32*5113495bSYour Name struct wlan_lmac_if_tx_ops *tx_ops;
33*5113495bSYour Name
34*5113495bSYour Name tx_ops = wlan_psoc_get_lmac_if_txops(psoc);
35*5113495bSYour Name if (!tx_ops) {
36*5113495bSYour Name ftm_err("tx_ops is NULL");
37*5113495bSYour Name return NULL;
38*5113495bSYour Name }
39*5113495bSYour Name
40*5113495bSYour Name return &tx_ops->ftm_tx_ops;
41*5113495bSYour Name }
42*5113495bSYour Name
43*5113495bSYour Name static QDF_STATUS
ftm_pdev_obj_init(struct wifi_ftm_pdev_priv_obj * ftm_pdev_obj)44*5113495bSYour Name ftm_pdev_obj_init(struct wifi_ftm_pdev_priv_obj *ftm_pdev_obj)
45*5113495bSYour Name {
46*5113495bSYour Name ftm_pdev_obj->data = qdf_mem_malloc(FTM_CMD_MAX_BUF_LENGTH);
47*5113495bSYour Name if (!ftm_pdev_obj->data)
48*5113495bSYour Name return QDF_STATUS_E_NOMEM;
49*5113495bSYour Name
50*5113495bSYour Name ftm_pdev_obj->length = 0;
51*5113495bSYour Name
52*5113495bSYour Name ftm_pdev_obj->cmd_type = WIFI_FTM_CMD_UNKNOWN;
53*5113495bSYour Name return QDF_STATUS_SUCCESS;
54*5113495bSYour Name }
55*5113495bSYour Name
56*5113495bSYour Name QDF_STATUS
wlan_ftm_pdev_obj_create_notification(struct wlan_objmgr_pdev * pdev,void * arg_list)57*5113495bSYour Name wlan_ftm_pdev_obj_create_notification(struct wlan_objmgr_pdev *pdev,
58*5113495bSYour Name void *arg_list)
59*5113495bSYour Name {
60*5113495bSYour Name QDF_STATUS status;
61*5113495bSYour Name struct wifi_ftm_pdev_priv_obj *ftm_pdev_obj;
62*5113495bSYour Name uint32_t device_mode;
63*5113495bSYour Name struct wlan_objmgr_psoc *psoc;
64*5113495bSYour Name struct target_psoc_info *target_psoc_info;
65*5113495bSYour Name
66*5113495bSYour Name psoc = wlan_pdev_get_psoc(pdev);
67*5113495bSYour Name if (!psoc)
68*5113495bSYour Name return QDF_STATUS_E_FAULT;
69*5113495bSYour Name
70*5113495bSYour Name target_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
71*5113495bSYour Name if (!target_psoc_info)
72*5113495bSYour Name return QDF_STATUS_E_FAULT;
73*5113495bSYour Name
74*5113495bSYour Name device_mode = target_psoc_get_device_mode(target_psoc_info);
75*5113495bSYour Name
76*5113495bSYour Name if (device_mode != QDF_GLOBAL_FTM_MODE)
77*5113495bSYour Name return QDF_STATUS_SUCCESS;
78*5113495bSYour Name
79*5113495bSYour Name ftm_pdev_obj = qdf_mem_malloc(sizeof(*ftm_pdev_obj));
80*5113495bSYour Name
81*5113495bSYour Name if (!ftm_pdev_obj)
82*5113495bSYour Name return QDF_STATUS_E_NOMEM;
83*5113495bSYour Name
84*5113495bSYour Name ftm_pdev_obj->pdev = pdev;
85*5113495bSYour Name status = ftm_pdev_obj_init(ftm_pdev_obj);
86*5113495bSYour Name
87*5113495bSYour Name if (QDF_IS_STATUS_ERROR(status)) {
88*5113495bSYour Name ftm_err("ftm pdev obj init failed");
89*5113495bSYour Name qdf_mem_free(ftm_pdev_obj);
90*5113495bSYour Name return status;
91*5113495bSYour Name }
92*5113495bSYour Name
93*5113495bSYour Name status = wlan_objmgr_pdev_component_obj_attach(pdev,
94*5113495bSYour Name WLAN_UMAC_COMP_FTM,
95*5113495bSYour Name ftm_pdev_obj,
96*5113495bSYour Name QDF_STATUS_SUCCESS);
97*5113495bSYour Name
98*5113495bSYour Name if (QDF_IS_STATUS_ERROR(status)) {
99*5113495bSYour Name ftm_err("ftm pdev obj attach failed");
100*5113495bSYour Name qdf_mem_free(ftm_pdev_obj);
101*5113495bSYour Name return status;
102*5113495bSYour Name }
103*5113495bSYour Name
104*5113495bSYour Name return status;
105*5113495bSYour Name }
106*5113495bSYour Name
107*5113495bSYour Name static QDF_STATUS
ftm_pdev_obj_deinit(struct wifi_ftm_pdev_priv_obj * ftm_pdev_obj)108*5113495bSYour Name ftm_pdev_obj_deinit(struct wifi_ftm_pdev_priv_obj *ftm_pdev_obj)
109*5113495bSYour Name {
110*5113495bSYour Name if (ftm_pdev_obj->data) {
111*5113495bSYour Name qdf_mem_free(ftm_pdev_obj->data);
112*5113495bSYour Name
113*5113495bSYour Name ftm_pdev_obj->data = NULL;
114*5113495bSYour Name ftm_pdev_obj->length = 0;
115*5113495bSYour Name }
116*5113495bSYour Name
117*5113495bSYour Name return QDF_STATUS_SUCCESS;
118*5113495bSYour Name }
119*5113495bSYour Name
120*5113495bSYour Name QDF_STATUS
wlan_ftm_pdev_obj_destroy_notification(struct wlan_objmgr_pdev * pdev,void * arg_list)121*5113495bSYour Name wlan_ftm_pdev_obj_destroy_notification(struct wlan_objmgr_pdev *pdev,
122*5113495bSYour Name void *arg_list)
123*5113495bSYour Name {
124*5113495bSYour Name QDF_STATUS status;
125*5113495bSYour Name struct wifi_ftm_pdev_priv_obj *ftm_pdev_obj;
126*5113495bSYour Name struct wlan_objmgr_psoc *psoc;
127*5113495bSYour Name struct target_psoc_info *target_psoc_info;
128*5113495bSYour Name uint32_t device_mode;
129*5113495bSYour Name
130*5113495bSYour Name psoc = wlan_pdev_get_psoc(pdev);
131*5113495bSYour Name if (!psoc)
132*5113495bSYour Name return QDF_STATUS_E_FAULT;
133*5113495bSYour Name
134*5113495bSYour Name target_psoc_info = wlan_psoc_get_tgt_if_handle(psoc);
135*5113495bSYour Name if (!target_psoc_info)
136*5113495bSYour Name return QDF_STATUS_E_FAULT;
137*5113495bSYour Name
138*5113495bSYour Name device_mode = target_psoc_get_device_mode(target_psoc_info);
139*5113495bSYour Name if (device_mode != QDF_GLOBAL_FTM_MODE)
140*5113495bSYour Name return QDF_STATUS_SUCCESS;
141*5113495bSYour Name
142*5113495bSYour Name ftm_pdev_obj =
143*5113495bSYour Name wlan_objmgr_pdev_get_comp_private_obj(pdev, WLAN_UMAC_COMP_FTM);
144*5113495bSYour Name
145*5113495bSYour Name if (!ftm_pdev_obj) {
146*5113495bSYour Name ftm_err("invalid wifi ftm obj");
147*5113495bSYour Name return QDF_STATUS_E_FAULT;
148*5113495bSYour Name }
149*5113495bSYour Name
150*5113495bSYour Name status = wlan_objmgr_pdev_component_obj_detach(pdev, WLAN_UMAC_COMP_FTM,
151*5113495bSYour Name ftm_pdev_obj);
152*5113495bSYour Name
153*5113495bSYour Name status = ftm_pdev_obj_deinit(ftm_pdev_obj);
154*5113495bSYour Name ftm_pdev_obj->pdev = NULL;
155*5113495bSYour Name
156*5113495bSYour Name qdf_mem_free(ftm_pdev_obj);
157*5113495bSYour Name
158*5113495bSYour Name return status;
159*5113495bSYour Name }
160*5113495bSYour Name
161*5113495bSYour Name QDF_STATUS
wlan_ftm_testmode_attach(struct wlan_objmgr_psoc * psoc)162*5113495bSYour Name wlan_ftm_testmode_attach(struct wlan_objmgr_psoc *psoc)
163*5113495bSYour Name {
164*5113495bSYour Name struct wlan_lmac_if_ftm_tx_ops *ftm_tx_ops;
165*5113495bSYour Name
166*5113495bSYour Name ftm_tx_ops = wlan_psoc_get_ftm_txops(psoc);
167*5113495bSYour Name if (!ftm_tx_ops) {
168*5113495bSYour Name ftm_err("ftm_tx_ops is NULL");
169*5113495bSYour Name return QDF_STATUS_E_FAULT;
170*5113495bSYour Name }
171*5113495bSYour Name
172*5113495bSYour Name if (ftm_tx_ops->ftm_attach)
173*5113495bSYour Name return ftm_tx_ops->ftm_attach(psoc);
174*5113495bSYour Name else
175*5113495bSYour Name return QDF_STATUS_SUCCESS;
176*5113495bSYour Name }
177*5113495bSYour Name
178*5113495bSYour Name QDF_STATUS
wlan_ftm_testmode_detach(struct wlan_objmgr_psoc * psoc)179*5113495bSYour Name wlan_ftm_testmode_detach(struct wlan_objmgr_psoc *psoc)
180*5113495bSYour Name {
181*5113495bSYour Name struct wlan_lmac_if_ftm_tx_ops *ftm_tx_ops;
182*5113495bSYour Name
183*5113495bSYour Name ftm_tx_ops = wlan_psoc_get_ftm_txops(psoc);
184*5113495bSYour Name if (!ftm_tx_ops) {
185*5113495bSYour Name ftm_err("ftm_tx_ops is NULL");
186*5113495bSYour Name return QDF_STATUS_E_FAULT;
187*5113495bSYour Name }
188*5113495bSYour Name
189*5113495bSYour Name if (ftm_tx_ops->ftm_detach)
190*5113495bSYour Name return ftm_tx_ops->ftm_detach(psoc);
191*5113495bSYour Name else
192*5113495bSYour Name return QDF_STATUS_SUCCESS;
193*5113495bSYour Name }
194*5113495bSYour Name
195*5113495bSYour Name QDF_STATUS
wlan_ftm_cmd_send(struct wlan_objmgr_pdev * pdev,uint8_t * buf,uint32_t len,uint8_t pdev_id)196*5113495bSYour Name wlan_ftm_cmd_send(struct wlan_objmgr_pdev *pdev, uint8_t *buf,
197*5113495bSYour Name uint32_t len, uint8_t pdev_id)
198*5113495bSYour Name {
199*5113495bSYour Name struct wlan_lmac_if_ftm_tx_ops *ftm_tx_ops;
200*5113495bSYour Name struct wlan_objmgr_psoc *psoc;
201*5113495bSYour Name
202*5113495bSYour Name psoc = wlan_pdev_get_psoc(pdev);
203*5113495bSYour Name if (!psoc)
204*5113495bSYour Name return QDF_STATUS_E_NOENT;
205*5113495bSYour Name
206*5113495bSYour Name ftm_tx_ops = wlan_psoc_get_ftm_txops(psoc);
207*5113495bSYour Name if (!ftm_tx_ops) {
208*5113495bSYour Name ftm_err("ftm_tx_ops is NULL");
209*5113495bSYour Name return QDF_STATUS_E_FAULT;
210*5113495bSYour Name }
211*5113495bSYour Name
212*5113495bSYour Name if (ftm_tx_ops->ftm_cmd_send)
213*5113495bSYour Name return ftm_tx_ops->ftm_cmd_send(pdev, buf, len, pdev_id);
214*5113495bSYour Name
215*5113495bSYour Name return QDF_STATUS_SUCCESS;
216*5113495bSYour Name }
217