xref: /wlan-driver/qca-wifi-host-cmn/ftm/dispatcher/src/wlan_ftm_ucfg_api.c (revision 5113495b16420b49004c444715d2daae2066e7dc)
1 /*
2  * Copyright (c) 2018 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: This implementation of init/deint functions for FTM services.
22  */
23 
24 #include <wlan_ftm_ucfg_api.h>
25 #include <wlan_cfg80211_ftm.h>
26 #include "../../core/src/wlan_ftm_svc_i.h"
27 #include <wlan_cmn.h>
28 #include <qdf_module.h>
29 
ucfg_wlan_ftm_testmode_cmd(struct wlan_objmgr_pdev * pdev,uint8_t * data,uint32_t len)30 QDF_STATUS ucfg_wlan_ftm_testmode_cmd(struct wlan_objmgr_pdev *pdev,
31 					uint8_t *data, uint32_t len)
32 {
33 	struct wifi_ftm_pdev_priv_obj *ftm_pdev_obj;
34 	uint8_t pdev_id;
35 
36 	ftm_pdev_obj = wlan_objmgr_pdev_get_comp_private_obj(pdev,
37 							WLAN_UMAC_COMP_FTM);
38 	if (!ftm_pdev_obj) {
39 		ftm_err("Failed to get ftm pdev component");
40 		return QDF_STATUS_E_FAILURE;
41 	}
42 
43 	ftm_pdev_obj->length = 0;
44 	pdev_id = wlan_objmgr_pdev_get_pdev_id(pdev);
45 
46 	return wlan_ftm_cmd_send(pdev, data, len, pdev_id);
47 }
48 
49 QDF_STATUS
wlan_ftm_process_utf_event(struct wlan_objmgr_pdev * pdev,uint8_t * event_buf,uint32_t len)50 wlan_ftm_process_utf_event(struct wlan_objmgr_pdev *pdev,
51 			    uint8_t *event_buf, uint32_t len)
52 {
53 	struct wifi_ftm_pdev_priv_obj *ftm_pdev_obj;
54 	uint32_t utf_datalen;
55 	uint8_t *utf_data;
56 	struct ftm_seg_hdr_info seghdr_info;
57 	u_int8_t total_segments, current_seq;
58 
59 	ftm_pdev_obj = wlan_objmgr_pdev_get_comp_private_obj(pdev,
60 			WLAN_UMAC_COMP_FTM);
61 	if (!ftm_pdev_obj) {
62 		ftm_err("Failed to get ftm pdev component");
63 		return QDF_STATUS_E_FAILURE;
64 	}
65 
66 	utf_data = event_buf;
67 	seghdr_info = *(struct ftm_seg_hdr_info *)(event_buf);
68 	ftm_pdev_obj->current_seq = (seghdr_info.segment_info & 0xF);
69 
70 	current_seq = (seghdr_info.segment_info & 0xF);
71 	total_segments = (seghdr_info.segment_info >> 4) & 0xF;
72 
73 	utf_datalen = len - sizeof(seghdr_info);
74 
75 	if (current_seq == 0) {
76 		ftm_pdev_obj->expected_seq = 0;
77 		ftm_pdev_obj->offset = 0;
78 	} else {
79 		if (ftm_pdev_obj->expected_seq != current_seq) {
80 			ftm_debug("seq mismatch exp Seq %d got seq %d\n",
81 				ftm_pdev_obj->expected_seq, current_seq);
82 		}
83 	}
84 
85 	if ((len > FTM_CMD_MAX_BUF_LENGTH) ||
86 	    (ftm_pdev_obj->offset > (FTM_CMD_MAX_BUF_LENGTH - utf_datalen))) {
87 		ftm_err("Invalid utf data len :%d", len);
88 		return QDF_STATUS_E_FAILURE;
89 	}
90 	qdf_mem_copy(&ftm_pdev_obj->data[ftm_pdev_obj->offset],
91 			&utf_data[sizeof(seghdr_info)], utf_datalen);
92 
93 	ftm_pdev_obj->offset = ftm_pdev_obj->offset + utf_datalen;
94 	ftm_pdev_obj->expected_seq++;
95 
96 	if (ftm_pdev_obj->expected_seq == total_segments) {
97 		if (ftm_pdev_obj->offset != seghdr_info.len) {
98 			ftm_debug("len mismatch len %zu total len %d\n",
99 				ftm_pdev_obj->offset, seghdr_info.len);
100 		}
101 
102 		ftm_pdev_obj->length = ftm_pdev_obj->offset;
103 
104 		/**
105 		 * If the response is for a command from FTM daemon,
106 		 * send this response data to cfg80211
107 		 */
108 		if (ftm_pdev_obj->cmd_type == WIFI_FTM_CMD_NL80211) {
109 			if (wlan_cfg80211_ftm_rx_event(pdev, ftm_pdev_obj->data,
110 				ftm_pdev_obj->length) != QDF_STATUS_SUCCESS) {
111 				return QDF_STATUS_E_FAILURE;
112 			}
113 			ftm_pdev_obj->cmd_type = WIFI_FTM_CMD_UNKNOWN;
114 		}
115 	}
116 
117 	return QDF_STATUS_SUCCESS;
118 }
119 
120 #ifdef QCA_WIFI_FTM_IOCTL
ucfg_wlan_ftm_testmode_rsp(struct wlan_objmgr_pdev * pdev,uint8_t * data)121 QDF_STATUS ucfg_wlan_ftm_testmode_rsp(struct wlan_objmgr_pdev *pdev,
122 				      uint8_t *data)
123 {
124 	struct wifi_ftm_pdev_priv_obj *ftm_pdev_obj;
125 	uint32_t *len;
126 
127 	ftm_pdev_obj =
128 		wlan_objmgr_pdev_get_comp_private_obj(pdev,
129 						      WLAN_UMAC_COMP_FTM);
130 	if (!ftm_pdev_obj) {
131 		ftm_err("Failed to get ftm pdev component");
132 		return QDF_STATUS_E_FAILURE;
133 	}
134 
135 	if (ftm_pdev_obj->length) {
136 		len = (uint32_t *)data;
137 		*len = ftm_pdev_obj->length;
138 		qdf_mem_copy((data + 4), ftm_pdev_obj->data,
139 			     ftm_pdev_obj->length);
140 
141 		ftm_pdev_obj->length = 0;
142 		return QDF_STATUS_SUCCESS;
143 	}
144 
145 	return QDF_STATUS_E_FAILURE;
146 }
147 #endif
148