1 /*
2  * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
3  * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 #ifndef _IOT_SIM_DEFS_I_H_
19 #define _IOT_SIM_DEFS_I_H_
20 
21 #include <wlan_objmgr_cmn.h>
22 #include <wlan_objmgr_global_obj.h>
23 #include <wlan_objmgr_pdev_obj.h>
24 #include <qdf_list.h>
25 #include <qdf_util.h>
26 #include <qdf_types.h>
27 #include <qdf_timer.h>
28 #include <wbuf.h>
29 #include <wlan_iot_sim_utils_api.h>
30 #include <wlan_iot_sim_public_structs.h>
31 
32 #define iot_sim_fatal(format, args...) \
33 	QDF_TRACE_FATAL(QDF_MODULE_ID_IOT_SIM, format, ## args)
34 #define iot_sim_err(format, args...) \
35 	QDF_TRACE_ERROR(QDF_MODULE_ID_IOT_SIM, format, ## args)
36 #define iot_sim_warn(format, args...) \
37 	QDF_TRACE_WARN(QDF_MODULE_ID_IOT_SIM, format, ## args)
38 #define iot_sim_info(format, args...) \
39 	QDF_TRACE_INFO(QDF_MODULE_ID_IOT_SIM, format, ## args)
40 #define iot_sim_debug(format, args...) \
41 	QDF_TRACE_DEBUG(QDF_MODULE_ID_IOT_SIM, format, ## args)
42 
43 #define iot_sim_fatal_nofl(format, args...) \
44 	QDF_TRACE_FATAL_NO_FL(QDF_MODULE_ID_IOT_SIM, format, ## args)
45 #define iot_sim_err_nofl(format, args...) \
46 	QDF_TRACE_ERROR_NO_FL(QDF_MODULE_ID_IOT_SIM, format, ## args)
47 #define iot_sim_warn_nofl(format, args...) \
48 	QDF_TRACE_WARN_NO_FL(QDF_MODULE_ID_IOT_SIM, format, ## args)
49 #define iot_sim_info_nofl(format, args...) \
50 	QDF_TRACE_INFO_NO_FL(QDF_MODULE_ID_IOT_SIM, format, ## args)
51 #define iot_sim_debug_nofl(format, args...) \
52 	QDF_TRACE_DEBUG_NO_FL(QDF_MODULE_ID_IOT_SIM, format, ## args)
53 
54 #define iot_sim_fatal_rl(format, args...) \
55 	QDF_TRACE_FATAL_RL(QDF_MODULE_ID_IOT_SIM, format, ## args)
56 #define iot_sim_err_rl(format, args...) \
57 	QDF_TRACE_ERROR_RL(QDF_MODULE_ID_IOT_SIM, format, ## args)
58 #define iot_sim_warn_rl(format, args...) \
59 	QDF_TRACE_WARN_RL(QDF_MODULE_ID_IOT_SIM, format, ## args)
60 #define iot_sim_info_rl(format, args...) \
61 	QDF_TRACE_INFO_RL(QDF_MODULE_ID_IOT_SIM, format, ## args)
62 #define iot_sim_debug_rl(format, args...) \
63 	QDF_TRACE_DEBUG_RL(QDF_MODULE_ID_IOT_SIM, format, ## args)
64 
65 #define iot_sim_fatal_rl_nofl(format, args...) \
66 	QDF_TRACE_FATAL_RL_NO_FL(QDF_MODULE_ID_IOT_SIM, format, ## args)
67 #define iot_sim_err_rl_nofl(format, args...) \
68 	QDF_TRACE_ERROR_RL_NO_FL(QDF_MODULE_ID_IOT_SIM, format, ## args)
69 #define iot_sim_warn_rl_nofl(format, args...) \
70 	QDF_TRACE_WARN_RL_NO_FL(QDF_MODULE_ID_IOT_SIM, format, ## args)
71 #define iot_sim_info_rl_nofl(format, args...) \
72 	QDF_TRACE_INFO_RL_NO_FL(QDF_MODULE_ID_IOT_SIM, format, ## args)
73 #define iot_sim_debug_rl_nofl(format, args...) \
74 	QDF_TRACE_DEBUG_RL_NO_FL(QDF_MODULE_ID_IOT_SIM, format, ## args)
75 
76 #define N_FRAME_TYPE 0x4
77 #define N_FRAME_SUBTYPE 0xF
78 #define MAX_SEQ 0x4
79 #define MAX_PEER_COUNT 0x2
80 #define MAX_ACTION 0x1B
81 #define RX_STATUS_SIZE 0x96
82 #define IOT_SIM_DEBUGFS_FILE_NUM 3
83 #define FRAME_TYPE_IS_BEACON(type, subtype) ((type) == 0 && (subtype) == 8)
84 #define FRAME_TYPE_IS_ACTION(type, subtype) ((type) == 0 && (subtype) == 13)
85 
86 #define IOT_SIM_DBG_FILE_PERM (QDF_FILE_USR_READ | \
87 			       QDF_FILE_USR_WRITE | \
88 			       QDF_FILE_GRP_READ | \
89 			       QDF_FILE_OTH_READ)
90 
91 enum iot_sim_action_cat_type {
92 	CAT_SPECTRUM,
93 	CAT_QOS,
94 	CAT_DLS,
95 	CAT_BA,
96 	CAT_RADIO,
97 	CAT_FAST_BSS_TRNST,
98 	CAT_HT,
99 	CAT_SA_QUERY,
100 	CAT_WNM,
101 	CAT_VHT,
102 	IOT_SIM_MAX_CAT,
103 };
104 
105 /**
106  * struct iot_sim_debugfs - contains dentry pointer for opened
107  *			    iot sim files and directory
108  * @iot_sim_dir_de: dentry pointer to pdev specific folder
109  * @iot_sim_file_de: dentry pointer representing operation specific files
110  */
111 struct iot_sim_debugfs {
112 	struct dentry *iot_sim_dir_de;
113 	struct dentry *iot_sim_file_de[IOT_SIM_DEBUGFS_FILE_NUM];
114 };
115 
116 /**
117  * struct iot_sim_rule - represent user configured rules
118  * @len: Length of the content provided by user
119  * @offset: offset at which modification done in capture frame
120  * @frm_content: actual user data in hex
121  * @drop: frame marked for drop
122  * @delay_dur: duration of delay
123  * @rule_bitmap:
124  * @nbuf_list:
125  * @peer:
126  * @sec_buf:
127  * @dwork:
128  * @rx_param:
129  * @iot_sim_delay_lock:
130  */
131 struct iot_sim_rule {
132 	uint16_t len;
133 	uint16_t offset;
134 	uint8_t *frm_content;
135 	bool drop;
136 	uint16_t delay_dur;
137 	uint8_t rule_bitmap;
138 	qdf_nbuf_t nbuf_list[2];
139 	struct wlan_objmgr_peer *peer;
140 	qdf_nbuf_t sec_buf;
141 	struct qdf_delayed_work *dwork;
142 	struct mgmt_rx_event_params *rx_param;
143 	qdf_spinlock_t iot_sim_delay_lock;
144 };
145 
146 /**
147  * struct iot_sim_rule_per_seq - rule structure per sequence iot sim files
148  *				 and directory
149  *
150  * @rule_per_type: 2d array of iot_sim_rule per type subtype
151  * @rule_per_action_frm: 2d array of iot_sim_rule per category/action
152  * @use_count: usage reference
153  */
154 struct iot_sim_rule_per_seq {
155 	struct iot_sim_rule *rule_per_type[N_FRAME_TYPE][N_FRAME_SUBTYPE];
156 	struct iot_sim_rule *rule_per_action_frm[IOT_SIM_MAX_CAT][MAX_ACTION];
157 	uint8_t use_count;
158 };
159 
160 /**
161  * struct iot_sim_rule_per_peer - peer specific structure for iot sim ops
162  *
163  * @node: list node
164  * @addr: address of peer
165  * @rule_per_seq: array of iot_sim_rule_per_seq
166  */
167 struct iot_sim_rule_per_peer {
168 	qdf_list_node_t node;
169 	struct qdf_mac_addr addr;
170 	struct iot_sim_rule_per_seq *rule_per_seq[MAX_SEQ];
171 };
172 
173 /**
174  * struct iot_sim_context - iot_sim pdev private object
175  * @pdev_obj:Reference to pdev global object
176  * @iot_sim_peer_list: peer list for peer specific rules
177  * @bcast_peer: broadcast peer entry for storing rules for all peers
178  * @peer_list:
179  * @iot_sim_lock:
180  * @iot_sim_dbgfs_ctx:
181  * @iot_sim_update_beacon_trigger:
182  * @bcn_buf:
183  */
184 struct iot_sim_context {
185 	struct wlan_objmgr_pdev *pdev_obj;
186 	/* IOT_SIM Peer list & Bcast Peer */
187 	struct iot_sim_rule_per_peer *iot_sim_peer_list, bcast_peer;
188 	qdf_list_t peer_list;
189 	qdf_spinlock_t iot_sim_lock;
190 	struct iot_sim_debugfs iot_sim_dbgfs_ctx;
191 	void (*iot_sim_update_beacon_trigger)(mlme_pdev_ext_t *);
192 	qdf_nbuf_t bcn_buf;
193 };
194 
195 /**
196  * enum iot_sim_operations - iot sim operations
197  * @CONTENT_CHANGE: Frame Content Change operation
198  * @DROP: Frame drop operation
199  * @DELAY: Frame delay operation
200  * @IOT_SIM_MAX_OPERATION: iot sim max operation
201  */
202 enum iot_sim_operations {
203 	CONTENT_CHANGE,
204 	DROP,
205 	DELAY,
206 	IOT_SIM_MAX_OPERATION
207 };
208 
209 /**
210  * enum iot_sim_subcmd - iot sim FW related subcommands
211  * @ADD_RULE: Add Rule
212  * @DEL_RULE: Delete Rule
213  * @ADD_RULE_ACTION: Add rule for action frame
214  * @DEL_RULE_ACTION: Del rule for action frame
215  * @IOT_SIM_MAX_SUBCMD: iot sim max subcmd
216  */
217 enum iot_sim_subcmd {
218 	ADD_RULE = 0,
219 	DEL_RULE,
220 	ADD_RULE_ACTION,
221 	DEL_RULE_ACTION,
222 	IOT_SIM_MAX_SUBCMD,
223 };
224 
225 struct iot_sim_cb_context {
226 	struct iot_sim_context *isc;
227 	struct iot_sim_rule *piot_sim_rule;
228 };
229 
230 #endif /* _IOT_SIM_DEFS_I_H_ */
231