xref: /wlan-driver/qcacld-3.0/core/wma/src/wma_fips_api.c (revision 5113495b16420b49004c444715d2daae2066e7dc)
1 /*
2  * Copyright (c) 2017, 2020 The Linux Foundation. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for
5  * any purpose with or without fee is hereby granted, provided that the
6  * above copyright notice and this permission notice appear in all
7  * copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16  * PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 /**
20  * DOC: wma_fips_api.c
21  *
22  * WLAN Host Device Driver FIPS Certification Feature
23  */
24 
25 #include "wma.h"
26 #include "wma_fips_api.h"
27 #include "wmi_unified_api.h"
28 
29 static wma_fips_cb fips_callback;
30 static void *fips_context;
31 
32 static int
wma_fips_event_handler(void * handle,uint8_t * event,uint32_t len)33 wma_fips_event_handler(void *handle, uint8_t *event, uint32_t len)
34 {
35 	tp_wma_handle wma_handle;
36 	wmi_unified_t wmi_handle;
37 	struct wmi_host_fips_event_param param;
38 	wma_fips_cb callback;
39 	QDF_STATUS status;
40 
41 	wma_handle = handle;
42 	if (wma_validate_handle(wma_handle))
43 		return QDF_STATUS_E_INVAL;
44 
45 	wmi_handle = wma_handle->wmi_handle;
46 	if (wmi_validate_handle(wmi_handle))
47 		return QDF_STATUS_E_INVAL;
48 
49 	status = wmi_extract_fips_event_data(wmi_handle, event, &param);
50 
51 	wma_info("Received FIPS event, pdev:%u status:%u data_len:%u",
52 		 param.pdev_id, param.error_status, param.data_len);
53 
54 	/* make sure extraction error is propagated to upper layers */
55 	if (QDF_IS_STATUS_ERROR(status))
56 		param.error_status = FIPS_ERROR_OPER_TIMEOUT;
57 
58 	callback = fips_callback;
59 	fips_callback = NULL;
60 	if (callback)
61 		callback(fips_context, &param);
62 
63 	return 0;
64 }
65 
wma_fips_request(WMA_HANDLE handle,struct fips_params * param,wma_fips_cb callback,void * context)66 QDF_STATUS wma_fips_request(WMA_HANDLE handle,
67 			    struct fips_params *param,
68 			    wma_fips_cb callback,
69 			    void *context)
70 {
71 	tp_wma_handle wma_handle = handle;
72 	wmi_unified_t wmi_handle;
73 	QDF_STATUS status;
74 
75 	if (wma_validate_handle(wma_handle))
76 		return QDF_STATUS_E_INVAL;
77 
78 	wmi_handle = wma_handle->wmi_handle;
79 	if (wmi_validate_handle(wmi_handle))
80 		return QDF_STATUS_E_INVAL;
81 
82 	fips_callback = callback;
83 	fips_context = context;
84 	status = wmi_unified_pdev_fips_cmd_send(wmi_handle, param);
85 	if (QDF_IS_STATUS_ERROR(status)) {
86 		wma_err("wmi_unified_pdev_fips_cmd_send() error: %u",
87 			status);
88 		fips_callback = NULL;
89 	}
90 
91 	return status;
92 }
93 
wma_fips_register_event_handlers(WMA_HANDLE handle)94 QDF_STATUS wma_fips_register_event_handlers(WMA_HANDLE handle)
95 {
96 	tp_wma_handle wma_handle = handle;
97 
98 	return wmi_unified_register_event_handler(wma_handle->wmi_handle,
99 						  wmi_pdev_fips_event_id,
100 						  wma_fips_event_handler,
101 						  WMA_RX_WORK_CTX);
102 }
103