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