xref: /wlan-driver/qca-wifi-host-cmn/iot_sim/core/iot_sim_cmn_api_i.h (revision 5113495b16420b49004c444715d2daae2066e7dc)
1 /*
2  * Copyright (c) 2020, 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_CMN_API_I_H_
19 #define _IOT_SIM_CMN_API_I_H_
20 
21 #include "iot_sim_defs_i.h"
22 #include <qdf_net_types.h>
23 
24 #define MAX_BUFFER_SIZE 2048
25 /*
26  *                   IOT SIM User Buf Format
27  *
28  * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
29  * | FrmType/subtype |  Seq  | Offset | Length | content | Mac Addr |
30  * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31  * |     1Byte       | 2Byte | 2Bytes | 2Bytes | Length  | 6 Bytes  |
32  *
33  */
34 #define USER_BUF_LEN (1 + 2 + 2 + 2 + MAX_BUFFER_SIZE + 6)
35 /*
36  *		IOT SIM User Buf Format for Drop
37  * ++++++++++++++++++++++++++++++++++++++++++++++++++++++
38  * |FrmType/subtype| Seq |category|action| drop |MacAddr|
39  * ++++++++++++++++++++++++++++++++++++++++++++++++++++++
40  * |   2Characters |2char| 2chars |2chars| 1char|17chars|
41  *
42  */
43 #define USER_BUF_LEN_DROP (2 + 2 + 2 + 2 + 1 + 17)
44 /*
45  *		IOT SIM User Buf Format for Drop
46  * ++++++++++++++++++++++++++++++++++++++++++++++++++++++
47  * |FrmType/subtype| Seq |category|action| delay |MacAddr|
48  * ++++++++++++++++++++++++++++++++++++++++++++++++++++++
49  * |   2Characters |2char| 2chars |2chars| 4char|17chars|
50  *
51  */
52 #define USER_BUF_LEN_DELAY (2 + 2 + 2 + 2 + 4 + 17)
53 
54 /**
55  * wlan_iot_sim_pdev_obj_create_handler() - handler for pdev object create
56  * @pdev: reference to global pdev object
57  * @arg:  reference to argument provided during registration of handler
58  *
59  * This is a handler to indicate pdev object created. Hence iot_sim_context
60  * object can be created and attached to pdev component list.
61  *
62  * Return: QDF_STATUS_SUCCESS on success
63  *         QDF_STATUS_E_FAILURE if pdev is null
64  *         QDF_STATUS_E_NOMEM on failure of iot_sim object allocation
65  */
66 QDF_STATUS wlan_iot_sim_pdev_obj_create_handler(struct wlan_objmgr_pdev *pdev,
67 						void *arg);
68 
69 /**
70  * wlan_iot_sim_pdev_obj_destroy_handler() - handler for pdev object delete
71  * @pdev: reference to global pdev object
72  * @arg:  reference to argument provided during registration of handler
73  *
74  * This is a handler to indicate pdev object going to be deleted.
75  * Hence iot_sim_context object can be detached from pdev component list.
76  * Then iot_sim_context object can be deleted.
77  *
78  * Return: QDF_STATUS_SUCCESS on success
79  *         QDF_STATUS_E_FAILURE on failure
80  */
81 QDF_STATUS wlan_iot_sim_pdev_obj_destroy_handler(struct wlan_objmgr_pdev *pdev,
82 						 void *arg);
83 
84 /**
85  * iot_sim_get_index_for_action_frm - Provides the action frame index
86  * @frm: action frame
87  * @cat: action frame category
88  * @act: action frame details
89  * @rx: TRUE if its getting called in the rx path
90  *
91  * Provides the simulation database index for the action frame.
92  *
93  * Return: QDF_STATUS_SUCCESS on success
94  *         QDF_STATUS_E_FAILURE on failure
95  */
96 QDF_STATUS iot_sim_get_index_for_action_frm(uint8_t *frm, uint8_t *cat,
97 					    uint8_t *act, bool rx);
98 
99 /**
100  * iot_sim_find_peer_from_mac() - function to find the iot sim peer data
101  *                                based on the mac address provided
102  *
103  * @isc: iot_sim pdev private object
104  * @mac: mac address of the peer
105  *
106  * Return: iot_sim_rule_per_peer reference if exists else NULL
107  */
108 struct iot_sim_rule_per_peer *
109 iot_sim_find_peer_from_mac(struct iot_sim_context *isc,
110 			   struct qdf_mac_addr *mac);
111 
112 /**
113  * iot_sim_frame_update() - Management frame update
114  * @pdev: reference to global pdev object
115  * @nbuf: frame buffer
116  * @param: beacon template parameters
117  * @tx: TRUE in case of tx
118  * @rx_param: mgmt_rx_event_params
119  *
120  * This function updates the outgoing management frame with
121  * the content stored in iot_sim_context.
122  *
123  * Return: QDF_STATUS_SUCCESS on success
124  * QDF_STATUS_E_FAILURE on failure
125  */
126 QDF_STATUS iot_sim_frame_update(struct wlan_objmgr_pdev *pdev,
127 				qdf_nbuf_t nbuf,
128 				struct beacon_tmpl_params *param,
129 				bool tx,
130 				struct mgmt_rx_event_params *rx_param);
131 
132 /**
133  * iot_sim_get_ctx_from_pdev() - API to get iot_sim context object
134  *                               from pdev
135  * @pdev : Reference to psoc global object
136  *
137  * This API used to get iot sim context object from global psoc reference.
138  * Null check should be done before invoking this inline function.
139  *
140  * Return : Reference to iot_sim_context object
141  *
142  */
143 static inline struct iot_sim_context *
iot_sim_get_ctx_from_pdev(struct wlan_objmgr_pdev * pdev)144 iot_sim_get_ctx_from_pdev(struct wlan_objmgr_pdev *pdev)
145 {
146 	struct iot_sim_context *isc = NULL;
147 
148 	if (pdev) {
149 		isc = wlan_objmgr_pdev_get_comp_private_obj(pdev,
150 							    WLAN_IOT_SIM_COMP);
151 	}
152 
153 	return isc;
154 }
155 
156 /**
157  * iot_sim_delete_rule_for_mac() - function to delete content change rule
158  *                                 for given peer mac
159  * @isc: iot sim context
160  * @oper: iot sim operation
161  * @seq: authentication sequence number, mostly 0 for non-authentication frame
162  * @type: 802.11 frame type
163  * @subtype: 802.11 frame subtype
164  * @mac: peer mac address
165  * @action: action frame or not
166  *
167  * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE otherwise
168  */
169 QDF_STATUS
170 iot_sim_delete_rule_for_mac(struct iot_sim_context *isc,
171 			    enum iot_sim_operations oper,
172 			    uint16_t seq, uint8_t type,
173 			    uint8_t subtype,
174 			    struct qdf_mac_addr *mac,
175 			    bool action);
176 /**
177  * iot_sim_parse_user_input_content_change() - function to parse user input into
178  *					       predefined format for content
179  *					       change operation.
180  * @isc: iot sim context
181  * @userbuf: local copy of user input
182  * @count: length of userbuf
183  * @t_st: address of type variable
184  * @seq: address of seq variable
185  * @offset: address of offset variable
186  * @length: address of length variable
187  * @content: double pointer to storage to store frame content after processing
188  * @mac: pointer to mac address
189  *
190  * All arguments passed will be filled upon success
191  *
192  * Return: QDF_STATUS_SUCCESS on success
193  *	   QDF_STATUS_E_FAILURE otherwise
194  */
195 QDF_STATUS
196 iot_sim_parse_user_input_content_change(struct iot_sim_context *isc,
197 					char *userbuf, ssize_t count,
198 					uint8_t *t_st, uint16_t *seq,
199 					uint16_t *offset, uint16_t *length,
200 					uint8_t **content,
201 					struct qdf_mac_addr *mac);
202 #endif /* _IOT_SIM_CMN_API_I_H_ */
203