1  /*
2   * Copyright (c) 2020, The Linux Foundation. All rights reserved.
3   * Copyright (c) 2022-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  /*
19   * DOC: Implements CM UTF
20   */
21  
22  #ifndef WLAN_CM_UTF_H
23  #define WLAN_CM_UTF_H
24  
25  #include <qdf_debugfs.h>
26  #include <qdf_mem.h>
27  #include <qdf_trace.h>
28  #include <qdf_module.h>
29  #include <qdf_event.h>
30  #include <qdf_defer.h>
31  #include <wlan_cm_public_struct.h>
32  #include <wlan_mgmt_txrx_utils_api.h>
33  #include <wlan_reg_services_api.h>
34  #include <wlan_scan_tgt_api.h>
35  #include <wlan_cfg80211.h>
36  
37  #define NUM_UTF_DEBUGFS_INFOS 2
38  
39  /*
40   * <ini>
41   * wlan_cm_utf - WLAN CM UTF Configuration
42   * @Min: 0
43   * @Max: 1
44   * @Default: 0
45   *
46   * This ini is used to config wlan cm utf
47   *
48   * Related: None
49   *
50   * Usage: External
51   *
52   * </ini>
53   */
54  #define CFG_WLAN_CM_UTF CFG_INI_UINT( \
55  	"wlan_cm_utf", \
56  	0, \
57  	1, \
58  	0, \
59  	CFG_VALUE_OR_DEFAULT, \
60  	"WLAN CM UTF Configuration")
61  
62  #define CFG_WLAN_CM_UTF_PARAM CFG(CFG_WLAN_CM_UTF)
63  /**
64   * enum wlan_cm_utf_test - CM UTF Test ID
65   * @CM_UTF_ID_CONNECT_SUCCESS: Connect Success
66   * @CM_UTF_ID_DISCONNECT_SUCCESS: Disconnect Success
67   * @CM_UTF_ID_PEER_CREATE_FAILURE: Peer Create Failure
68   * @CM_UTF_ID_PEER_CREATE_TIMEOUT: No Peer Create Response
69   * @CM_UTF_ID_PEER_DELETE_TIMEOUT: No Peer Delete Response
70   * @CM_UTF_ID_AUTH_FAILURE: Auth Req Failure
71   * @CM_UTF_ID_AUTH_TIMEOUT: No Auth Response
72   * @CM_UTF_ID_ASSOC_FAILURE: Assoc Req Failure
73   * @CM_UTF_ID_ASSOC_TIMEOUT: No Assoc Response
74   * @CM_UTF_ID_CONNECT_SCAN_FAILURE: SSID Not Found
75   * @CM_UTF_ID_CONNECT_SER_TIMEOUT: Serialization Active Cmd Timeout for Connect
76   * @CM_UTF_ID_DISCONNECT_SER_TIMEOUT: Ser Active Cmd Timeout for Disconnect
77   * @CM_UTF_ID_CONNECT_SER_FAILED: Serialization Cmd Queue Failure for Connect
78   * @CM_UTF_ID_DISCONNECT_SER_FAILED: Ser Cmd Queue Failure for Disconnect
79   * @CM_UTF_ID_MAX: Maximum enumeration
80   */
81  enum wlan_cm_utf_test {
82  	CM_UTF_ID_CONNECT_SUCCESS,
83  	CM_UTF_ID_DISCONNECT_SUCCESS,
84  	CM_UTF_ID_PEER_CREATE_FAILURE,
85  	CM_UTF_ID_PEER_CREATE_TIMEOUT,
86  	CM_UTF_ID_PEER_DELETE_TIMEOUT,
87  	CM_UTF_ID_AUTH_FAILURE,
88  	CM_UTF_ID_AUTH_TIMEOUT,
89  	CM_UTF_ID_ASSOC_FAILURE,
90  	CM_UTF_ID_ASSOC_TIMEOUT,
91  	CM_UTF_ID_CONNECT_SCAN_FAILURE,
92  	CM_UTF_ID_CONNECT_SER_TIMEOUT,
93  	CM_UTF_ID_DISCONNECT_SER_TIMEOUT,
94  	CM_UTF_ID_CONNECT_SER_FAILED,//Need ser utf
95  	CM_UTF_ID_DISCONNECT_SER_FAILED,//Need ser utf
96  	CM_UTF_ID_MAX,
97  };
98  
99  /**
100   * enum wlan_cm_utf_evt - CM UTF Resp event
101   * @CM_UTF_BSS_PEER_CREATE_RESP: Peer Create Response
102   * @CM_UTF_BSS_PEER_DELETE_RESP: Peer Delete Response
103   * @CM_UTF_CONNECT_RESP: Connect Response
104   * @CM_UTF_DISCONNECT_RESP: Disconnect Response
105   * @CM_UTF_PEER_DELETE_IND: Peer Delete Indication
106   */
107  enum wlan_cm_utf_evt {
108  	CM_UTF_BSS_PEER_CREATE_RESP,
109  	CM_UTF_BSS_PEER_DELETE_RESP,
110  	CM_UTF_CONNECT_RESP,
111  	CM_UTF_DISCONNECT_RESP,
112  	CM_UTF_PEER_DELETE_IND,
113  };
114  
115  /**
116   * struct wlan_cm_utf_node - CM UTF node to hold CM req info
117   * @evt_id: CM UTF event id
118   * @peer_mac: Peer Mac
119   * @conn_req: Connect Request
120   * @disconn_req: Disconnect Request
121   */
122  struct wlan_cm_utf_node {
123  	enum wlan_cm_utf_evt evt_id;
124  	struct qdf_mac_addr *peer_mac;
125  	struct wlan_cm_vdev_connect_req conn_req;
126  	struct wlan_cm_vdev_discon_req disconn_req;
127  };
128  
129  /**
130   * struct wlan_cm_utf - CM UTF handle
131   * @cm_utf_node: linked list node for linking entries
132   * @vdev: Vdev object
133   * @debugfs_de: debugfs entry
134   * @test_id: Test case Id
135   * @req: cfg80211 connect request params
136   * @cm_utf_timer: CM UTF timer
137   * @cm_utf_test_timer: CM UTF timer for each test
138   * @utf_node: CM UTF node to hold CM req info
139   * @last_cmd_id: last command id
140   * @last_cmd_source: last command source
141   * @cm_utf_work: CM UTF work queue for processing events
142   */
143  struct wlan_cm_utf {
144  	qdf_list_node_t cm_utf_node;
145  	struct wlan_objmgr_vdev *vdev;
146  	struct dentry *debugfs_de[NUM_UTF_DEBUGFS_INFOS];
147  	enum wlan_cm_utf_test test_id;
148  	struct wlan_cm_connect_req req;
149  	qdf_timer_t  cm_utf_timer;
150  	qdf_timer_t  cm_utf_test_timer;
151  	struct wlan_cm_utf_node utf_node;
152  	uint32_t last_cmd_id;
153  	enum wlan_cm_source last_cmd_source;
154  	qdf_work_t cm_utf_work;
155  };
156  
157  /*
158   * Debugfs read/write functions
159   */
160  /**
161   * wlan_cm_utf_cm_test_id_show() - debugfs function to display CM test case name
162   * @m: seq_file handle
163   * @v: not used, offset of read
164   */
165  int wlan_cm_utf_cm_test_id_show(qdf_debugfs_file_t m, void *v);
166  
167  int wlan_cm_utf_scan_db_update_show(qdf_debugfs_file_t m, void *v);
168  
169  /**
170   * wlan_cm_utf_cm_test_id_write() - debugfs write to start CM UTF test
171   * @file: file handler to access cm utf handle
172   * @buf: received data buffer
173   * @count: length of received buffer
174   * @ppos: Not used
175   *
176   * Return: count
177   */
178  ssize_t wlan_cm_utf_cm_test_id_write(struct file *file,
179  				     const char __user *buf,
180  				     size_t count, loff_t *ppos);
181  
182  /**
183   * wlan_cm_utf_scan_db_update_write() - debugfs write to add manual scan entry
184   * @file: file handler to access cm utf handle
185   * @buf: received data buffer
186   * @count: length of received buffer
187   * @ppos: Not used
188   *
189   * Return: count
190   */
191  ssize_t wlan_cm_utf_scan_db_update_write(struct file *file,
192  					 const char __user *buf,
193  					 size_t count, loff_t *ppos);
194  
195  /**
196   * wlan_cm_utf_attach() - Connection manager UTF init API
197   * @vdev: Vdev object
198   *
199   * Return: QDF_STATUS
200   */
201  QDF_STATUS wlan_cm_utf_attach(struct wlan_objmgr_vdev *vdev);
202  
203  /**
204   * wlan_cm_utf_detach() - Connection manager UTF deinit API
205   * @vdev: Vdev object
206   *
207   * Return: QDF_STATUS
208   */
209  void wlan_cm_utf_detach(struct wlan_objmgr_vdev *vdev);
210  
211  /**
212   * wlan_cm_utf_bss_peer_create_req() - Connection manager UTF bss peer
213   * create request handler
214   * @vdev: VDEV object
215   * @peer_mac: Peer mac address
216   *
217   * Return: QDF_STATUS
218   */
219  QDF_STATUS wlan_cm_utf_bss_peer_create_req(struct wlan_objmgr_vdev *vdev,
220  					   struct qdf_mac_addr *peer_mac);
221  
222  /**
223   * wlan_cm_utf_connect_req_active() - Connection manager UTF handler when connect
224   * request is activated
225   * @vdev: VDEV object
226   * @vdev_connect_req: Vdev connect request
227   *
228   * Return: QDF_STATUS
229   */
230  QDF_STATUS wlan_cm_utf_connect_req_active(
231  			struct wlan_objmgr_vdev *vdev,
232  			struct wlan_cm_vdev_connect_req *vdev_connect_req);
233  
234  /**
235   * wlan_cm_utf_connect_req() - Connection manager UTF connect request handler
236   * @vdev: VDEV object
237   * @vdev_connect_req: Vdev connect request
238   *
239   * Return: QDF_STATUS
240   */
241  QDF_STATUS wlan_cm_utf_connect_req(
242  			struct wlan_objmgr_vdev *vdev,
243  			struct wlan_cm_vdev_connect_req *vdev_connect_req);
244  
245  /**
246   * wlan_cm_utf_disconnect_req() - Connection manager UTF disconnect
247   * request handler
248   * @vdev: VDEV object
249   * @vdev_disconnect_req: Vdev disconnect request
250   *
251   * Return: QDF_STATUS
252   */
253  QDF_STATUS wlan_cm_utf_disconnect_req(
254  		struct wlan_objmgr_vdev *vdev,
255  		struct wlan_cm_vdev_discon_req *vdev_disconnect_req);
256  
257  /**
258   * wlan_cm_utf_bss_peer_delete_req() - Connection manager UTF bss peer
259   * delete request handler
260   * @vdev: VDEV object
261   *
262   * Return: QDF_STATUS
263   */
264  QDF_STATUS wlan_cm_utf_bss_peer_delete_req(struct wlan_objmgr_vdev *vdev);
265  
266  /**
267   * wlan_cm_utf_vdev_down() - Connection manager UTF vdev down request handler
268   * @vdev: VDEV object
269   *
270   * Return: QDF_STATUS
271   */
272  QDF_STATUS wlan_cm_utf_vdev_down(struct wlan_objmgr_vdev *vdev);
273  
274  /**
275   * osif_cm_utf_register_cb() - API to register connection manager callbacks
276   *
277   * Return: QDF_STATUS
278   */
279  QDF_STATUS osif_cm_utf_register_cb(void);
280  #endif //WLAN_CM_UTF_H
281