xref: /wlan-dirver/qca-wifi-host-cmn/umac/mlme/connection_mgr/core/src/wlan_cm_main.c (revision 45a38684b07295822dc8eba39e293408f203eec8)
1 /*
2  * Copyright (c) 2012-2015, 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 /**
18  * DOC: Implements init/deinit specific apis of connection manager
19  */
20 
21 #include "wlan_cm_main.h"
22 #include "wlan_cm_sm.h"
23 
24 QDF_STATUS wlan_cm_init(struct vdev_mlme_obj *vdev_mlme)
25 {
26 	struct wlan_objmgr_vdev *vdev = vdev_mlme->vdev;
27 	enum QDF_OPMODE op_mode = wlan_vdev_mlme_get_opmode(vdev);
28 	QDF_STATUS status;
29 
30 	if (op_mode != QDF_STA_MODE && op_mode != QDF_P2P_CLIENT_MODE)
31 		return QDF_STATUS_SUCCESS;
32 
33 	vdev_mlme->cnx_mgr_ctx = qdf_mem_malloc(sizeof(struct cnx_mgr));
34 	if (!vdev_mlme->cnx_mgr_ctx)
35 		return QDF_STATUS_E_NOMEM;
36 
37 	vdev_mlme->cnx_mgr_ctx->vdev = vdev_mlme->vdev;
38 	status = cm_sm_create(vdev_mlme->cnx_mgr_ctx);
39 	if (QDF_IS_STATUS_ERROR(status)) {
40 		mlme_err("CM MLME SM allocation failed");
41 		qdf_mem_free(vdev_mlme->cnx_mgr_ctx);
42 		vdev_mlme->cnx_mgr_ctx = NULL;
43 		return QDF_STATUS_E_NOMEM;
44 	}
45 	qdf_list_create(&vdev_mlme->cnx_mgr_ctx->req_list, CM_MAX_REQ);
46 
47 	return QDF_STATUS_SUCCESS;
48 }
49 
50 QDF_STATUS wlan_cm_deinit(struct vdev_mlme_obj *vdev_mlme)
51 {
52 	struct wlan_objmgr_vdev *vdev = vdev_mlme->vdev;
53 	enum QDF_OPMODE op_mode = wlan_vdev_mlme_get_opmode(vdev);
54 
55 	if (op_mode != QDF_STA_MODE && op_mode != QDF_P2P_CLIENT_MODE)
56 		return QDF_STATUS_SUCCESS;
57 
58 	qdf_list_destroy(&vdev_mlme->cnx_mgr_ctx->req_list);
59 	cm_sm_destroy(vdev_mlme->cnx_mgr_ctx);
60 	qdf_mem_free(vdev_mlme->cnx_mgr_ctx);
61 	vdev_mlme->cnx_mgr_ctx = NULL;
62 
63 	return QDF_STATUS_SUCCESS;
64 }
65