1 /*
2 * Copyright (c) 2019-2020 The Linux Foundation. All rights reserved.
3 * Copyright (c) 2024 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 PSOC MLME APIs
20 */
21
22 #include <qdf_module.h>
23 #include <wlan_objmgr_cmn.h>
24 #include <wlan_objmgr_global_obj.h>
25 #include <wlan_mlme_dbg.h>
26 #include <include/wlan_mlme_cmn.h>
27 #include <include/wlan_psoc_mlme.h>
28 #include <wlan_psoc_mlme_main.h>
29 #include <wlan_psoc_mlme_api.h>
30
mlme_psoc_get_priv(struct wlan_objmgr_psoc * psoc)31 struct psoc_mlme_obj *mlme_psoc_get_priv(struct wlan_objmgr_psoc *psoc)
32 {
33 struct psoc_mlme_obj *psoc_mlme;
34
35 psoc_mlme = wlan_objmgr_psoc_get_comp_private_obj(psoc,
36 WLAN_UMAC_COMP_MLME);
37 if (!psoc_mlme) {
38 mlme_err("PSOC MLME component object is NULL");
39 return NULL;
40 }
41
42 return psoc_mlme;
43 }
44
45 qdf_export_symbol(mlme_psoc_get_priv);
46
mlme_psoc_obj_create_handler(struct wlan_objmgr_psoc * psoc,void * arg)47 static QDF_STATUS mlme_psoc_obj_create_handler(struct wlan_objmgr_psoc *psoc,
48 void *arg)
49 {
50 struct psoc_mlme_obj *psoc_mlme;
51 QDF_STATUS status = QDF_STATUS_SUCCESS;
52
53 psoc_mlme = qdf_mem_malloc(sizeof(struct psoc_mlme_obj));
54 if (!psoc_mlme) {
55 mlme_err("Failed to allocate PSOS mlme Object");
56 return QDF_STATUS_E_NOMEM;
57 }
58
59 psoc_mlme->psoc = psoc;
60
61 status = mlme_psoc_ops_ext_hdl_create(psoc_mlme);
62 if (QDF_IS_STATUS_ERROR(status)) {
63 mlme_err("Failed to allocate psoc ext handle");
64 goto init_failed;
65 }
66
67 status = wlan_objmgr_psoc_component_obj_attach(psoc,
68 WLAN_UMAC_COMP_MLME,
69 psoc_mlme,
70 QDF_STATUS_SUCCESS);
71 if (QDF_IS_STATUS_ERROR(status)) {
72 mlme_err("Failed to attach psoc_ctx with psoc");
73 goto init_failed;
74 }
75
76 wlan_mlme_psoc_init_peer_trans_history(psoc_mlme);
77
78 return QDF_STATUS_SUCCESS;
79 init_failed:
80 qdf_mem_free(psoc_mlme);
81
82 return status;
83 }
84
mlme_psoc_obj_destroy_handler(struct wlan_objmgr_psoc * psoc,void * arg)85 static QDF_STATUS mlme_psoc_obj_destroy_handler(struct wlan_objmgr_psoc *psoc,
86 void *arg)
87 {
88 struct psoc_mlme_obj *psoc_mlme;
89
90 psoc_mlme = mlme_psoc_get_priv(psoc);
91 if (!psoc_mlme) {
92 mlme_err("PSOC MLME component object is NULL");
93 return QDF_STATUS_E_FAILURE;
94 }
95
96 wlan_mlme_psoc_flush_peer_trans_history(psoc);
97
98 wlan_objmgr_psoc_component_obj_detach(psoc, WLAN_UMAC_COMP_MLME,
99 psoc_mlme);
100
101 mlme_psoc_ops_ext_hdl_destroy(psoc_mlme);
102
103 qdf_mem_free(psoc_mlme);
104
105 return QDF_STATUS_SUCCESS;
106 }
107
wlan_psoc_mlme_init(void)108 QDF_STATUS wlan_psoc_mlme_init(void)
109 {
110 if (wlan_objmgr_register_psoc_create_handler
111 (WLAN_UMAC_COMP_MLME,
112 mlme_psoc_obj_create_handler, NULL)
113 != QDF_STATUS_SUCCESS)
114 return QDF_STATUS_E_FAILURE;
115
116 if (wlan_objmgr_register_psoc_destroy_handler
117 (WLAN_UMAC_COMP_MLME,
118 mlme_psoc_obj_destroy_handler, NULL)
119 != QDF_STATUS_SUCCESS) {
120 if (wlan_objmgr_unregister_psoc_create_handler
121 (WLAN_UMAC_COMP_MLME,
122 mlme_psoc_obj_create_handler, NULL)
123 != QDF_STATUS_SUCCESS)
124 return QDF_STATUS_E_FAILURE;
125
126 return QDF_STATUS_E_FAILURE;
127 }
128
129 return QDF_STATUS_SUCCESS;
130 }
131
wlan_psoc_mlme_deinit(void)132 QDF_STATUS wlan_psoc_mlme_deinit(void)
133 {
134 if (wlan_objmgr_unregister_psoc_create_handler
135 (WLAN_UMAC_COMP_MLME,
136 mlme_psoc_obj_create_handler, NULL)
137 != QDF_STATUS_SUCCESS)
138 return QDF_STATUS_E_FAILURE;
139
140 if (wlan_objmgr_unregister_psoc_destroy_handler
141 (WLAN_UMAC_COMP_MLME,
142 mlme_psoc_obj_destroy_handler, NULL)
143 != QDF_STATUS_SUCCESS)
144 return QDF_STATUS_E_FAILURE;
145
146 return QDF_STATUS_SUCCESS;
147 }
148