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