xref: /wlan-dirver/qca-wifi-host-cmn/iot_sim/core/iot_sim_cmn_api_i.h (revision 6d768494e5ce14eb1603a695c86739d12ecc6ec2)
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 /**
45  * wlan_iot_sim_pdev_obj_create_handler() - handler for pdev object create
46  * @pdev: reference to global pdev object
47  * @arg:  reference to argument provided during registration of handler
48  *
49  * This is a handler to indicate pdev object created. Hence iot_sim_context
50  * object can be created and attached to pdev component list.
51  *
52  * Return: QDF_STATUS_SUCCESS on success
53  *         QDF_STATUS_E_FAILURE if pdev is null
54  *         QDF_STATUS_E_NOMEM on failure of iot_sim object allocation
55  */
56 QDF_STATUS wlan_iot_sim_pdev_obj_create_handler(struct wlan_objmgr_pdev *pdev,
57 						void *arg);
58 
59 /**
60  * wlan_iot_sim_pdev_obj_destroy_handler() - handler for pdev object delete
61  * @pdev: reference to global pdev object
62  * @arg:  reference to argument provided during registration of handler
63  *
64  * This is a handler to indicate pdev object going to be deleted.
65  * Hence iot_sim_context object can be detached from pdev component list.
66  * Then iot_sim_context object can be deleted.
67  *
68  * Return: QDF_STATUS_SUCCESS on success
69  *         QDF_STATUS_E_FAILURE on failure
70  */
71 QDF_STATUS wlan_iot_sim_pdev_obj_destroy_handler(struct wlan_objmgr_pdev *pdev,
72 						 void *arg);
73 
74 /**
75  * iot_sim_get_index_for_action_frm - Provides the action frame index
76  * @frm: action frame
77  * @cat: action frame category
78  * @act: action frame details
79  *
80  * Provides the simulation database index for the action frame.
81  *
82  * Return: QDF_STATUS_SUCCESS on success
83  *         QDF_STATUS_E_FAILURE on failure
84  */
85 QDF_STATUS iot_sim_get_index_for_action_frm(uint8_t *frm, uint8_t *cat,
86 					    uint8_t *act);
87 
88 /**
89  * iot_sim_frame_update() - Management frame update
90  * @pdev: reference to global pdev object
91  * @nbuf: frame buffer
92  * @tx: TRUE in case of tx
93  *
94  * This function updates the outgoing management frame with
95  * the content stored in iot_sim_context.
96  *
97  * Return: QDF_STATUS_SUCCESS on success
98  * QDF_STATUS_E_FAILURE on failure
99  */
100 QDF_STATUS iot_sim_frame_update(struct wlan_objmgr_pdev *pdev,
101 				qdf_nbuf_t nbuf,
102 				struct beacon_tmpl_params *param,
103 				bool tx);
104 
105 /*
106  * iot_sim_get_ctx_from_pdev() - API to get iot_sim context object
107  *                               from pdev
108  * @pdev : Reference to psoc global object
109  *
110  * This API used to get iot sim context object from global psoc reference.
111  * Null check should be done before invoking this inline function.
112  *
113  * Return : Reference to iot_sim_context object
114  *
115  */
116 static inline struct iot_sim_context *
117 iot_sim_get_ctx_from_pdev(struct wlan_objmgr_pdev *pdev)
118 {
119 	struct iot_sim_context *isc = NULL;
120 
121 	if (pdev) {
122 		isc = wlan_objmgr_pdev_get_comp_private_obj(pdev,
123 							    WLAN_IOT_SIM_COMP);
124 	}
125 
126 	return isc;
127 }
128 
129 /*
130  * iot_sim_delete_rule_for_mac - function to delete content change rule
131  *                               for given peer mac
132  * @isc: iot sim context
133  * @oper: iot sim operation
134  * @seq: authentication sequence number, mostly 0 for non-authentication frame
135  * @type: 802.11 frame type
136  * @subtype: 802.11 frame subtype
137  * @mac: peer mac address
138  * @action: action frame or not
139  *
140  * Return: QDF_STATUS_SUCCESS on success, QDF_STATUS_E_FAILURE otherwise
141  */
142 QDF_STATUS
143 iot_sim_delete_rule_for_mac(struct iot_sim_context *isc,
144 			    enum iot_sim_operations oper,
145 			    uint16_t seq, uint8_t type,
146 			    uint8_t subtype,
147 			    struct qdf_mac_addr *mac,
148 			    bool action);
149 /*
150  * iot_sim_parse_user_input_content_change - function to parse user input into
151  *					     predefined format for content
152  *					     change operation. All arguments
153  *					     passed will be filled upon success
154  * @isc: iot sim context
155  * @userbuf: local copy of user input
156  * @count: length of userbuf
157  * @t_st: address of type variable
158  * @seq: address of seq variable
159  * @offset: address of offset variable
160  * @length: address of length variable
161  * @content: double pointer to storage to store frame content after processing
162  * @mac: pointer to mac address
163  *
164  * Return: QDF_STATUS_SUCCESS on success
165  *	   QDF_STATUS_E_FAILURE otherwise
166  */
167 QDF_STATUS
168 iot_sim_parse_user_input_content_change(struct iot_sim_context *isc,
169 					char *userbuf, ssize_t count,
170 					uint8_t *t_st, uint16_t *seq,
171 					uint16_t *offset, uint16_t *length,
172 					uint8_t **content,
173 					struct qdf_mac_addr *mac);
174 #endif /* _IOT_SIM_CMN_API_I_H_ */
175