xref: /wlan-dirver/qca-wifi-host-cmn/iot_sim/dispatcher/src/wlan_iot_sim_utils_api.c (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 #include <wlan_iot_sim_utils_api.h>
18 #include <qdf_module.h>
19 #include "../../core/iot_sim_cmn_api_i.h"
20 #include <wlan_iot_sim_tgt_api.h>
21 #include <wlan_objmgr_pdev_obj.h>
22 #include <wlan_objmgr_vdev_obj.h>
23 
24 #define IEEE80211_FRAME_BODY_OFFSET 0x18
25 
26 QDF_STATUS iot_sim_cmd_handler(struct wlan_objmgr_vdev *vdev, qdf_nbuf_t nbuf,
27 			       struct beacon_tmpl_params *param, bool tx)
28 {
29 	struct wlan_objmgr_pdev *pdev = vdev->vdev_objmgr.wlan_pdev;
30 
31 	return iot_sim_frame_update(pdev, nbuf, param, tx);
32 }
33 
34 QDF_STATUS iot_sim_register_callbacks(struct wlan_objmgr_pdev *pdev,
35 				      struct iot_sim_cbacks *cb)
36 {
37 	struct iot_sim_context *isc = NULL;
38 
39 	isc = wlan_objmgr_pdev_get_comp_private_obj(pdev, WLAN_IOT_SIM_COMP);
40 	if (!isc)
41 		return QDF_STATUS_E_NULL_VALUE;
42 
43 	isc->iot_sim_update_beacon_trigger = cb->update_beacon_trigger;
44 
45 	return QDF_STATUS_SUCCESS;
46 }
47 
48 QDF_STATUS
49 wlan_iot_sim_init(void)
50 {
51 	if (wlan_objmgr_register_pdev_create_handler(
52 		WLAN_IOT_SIM_COMP,
53 		wlan_iot_sim_pdev_obj_create_handler,
54 		NULL) !=
55 	    QDF_STATUS_SUCCESS) {
56 		return QDF_STATUS_E_FAILURE;
57 	}
58 	if (wlan_objmgr_register_pdev_destroy_handler(
59 		WLAN_IOT_SIM_COMP,
60 		wlan_iot_sim_pdev_obj_destroy_handler,
61 		NULL) !=
62 	    QDF_STATUS_SUCCESS) {
63 		return QDF_STATUS_E_FAILURE;
64 	}
65 
66 	return QDF_STATUS_SUCCESS;
67 }
68 
69 QDF_STATUS
70 wlan_iot_sim_deinit(void)
71 {
72 	if (wlan_objmgr_unregister_pdev_create_handler(
73 		WLAN_IOT_SIM_COMP,
74 		wlan_iot_sim_pdev_obj_create_handler,
75 		NULL) !=
76 	    QDF_STATUS_SUCCESS) {
77 		return QDF_STATUS_E_FAILURE;
78 	}
79 	if (wlan_objmgr_unregister_pdev_destroy_handler(
80 		WLAN_IOT_SIM_COMP,
81 		wlan_iot_sim_pdev_obj_destroy_handler,
82 		NULL) !=
83 	    QDF_STATUS_SUCCESS) {
84 		return QDF_STATUS_E_FAILURE;
85 	}
86 
87 	return QDF_STATUS_SUCCESS;
88 }
89 
90 void wlan_lmac_if_iot_sim_register_rx_ops(struct wlan_lmac_if_rx_ops *rx_ops)
91 {
92 	struct wlan_lmac_if_iot_sim_rx_ops *iot_sim_ops =
93 						&rx_ops->iot_sim_rx_ops;
94 
95 	iot_sim_ops->iot_sim_cmd_handler = iot_sim_cmd_handler;
96 	iot_sim_ops->iot_sim_register_cb = iot_sim_register_callbacks;
97 
98 }
99