1 /*
2  * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. 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  * DOC: define internal APIs related to the mlme component, legacy APIs are
18  *	called for the time being, but will be cleaned up after convergence
19  */
20 #include "wifi_pos_api.h"
21 #include "wlan_wifi_pos_interface.h"
22 #include "wma_pasn_peer_api.h"
23 
24 #if defined(WIFI_POS_CONVERGED) && defined(WLAN_FEATURE_RTT_11AZ_SUPPORT)
25 /**
26  * wlan_wifi_pos_pasn_peer_create() - Callback to create ranging peer
27  * @psoc: Pointer to PSOC
28  * @peer_addr: Address of the peer for which PASN peer is to be created
29  * @vdev_id: Vdev id
30  *
31  * Return: QDF_STATUS
32  */
wlan_wifi_pos_pasn_peer_create(struct wlan_objmgr_psoc * psoc,struct qdf_mac_addr * peer_addr,uint8_t vdev_id)33 static QDF_STATUS wlan_wifi_pos_pasn_peer_create(struct wlan_objmgr_psoc *psoc,
34 						 struct qdf_mac_addr *peer_addr,
35 						 uint8_t vdev_id)
36 {
37 	return wma_pasn_peer_create(psoc, peer_addr, vdev_id);
38 }
39 
40 /**
41  * wlan_wifi_pos_pasn_peer_delete() - Callback to delete ranging peer
42  * @psoc: Pointer to PSOC
43  * @peer_addr: Address of the peer for which PASN peer is to be deleted
44  * @vdev_id: Vdev id
45  * @no_fw_peer_delete: if true do not seend peer delete to firmware
46  *
47  * Return: QDF_STATUS
48  */
wlan_wifi_pos_pasn_peer_delete(struct wlan_objmgr_psoc * psoc,struct qdf_mac_addr * peer_addr,uint8_t vdev_id,bool no_fw_peer_delete)49 static QDF_STATUS wlan_wifi_pos_pasn_peer_delete(struct wlan_objmgr_psoc *psoc,
50 						 struct qdf_mac_addr *peer_addr,
51 						 uint8_t vdev_id,
52 						 bool no_fw_peer_delete)
53 {
54 	return wma_pasn_peer_remove(psoc, peer_addr, vdev_id,
55 				    no_fw_peer_delete);
56 }
57 
58 /**
59  * wlan_wifi_pos_vdev_delete_resume() - Resume vdev delete operation
60  * after deleting all pasn peers
61  * @vdev: Pointer to objmgr vdev
62  *
63  * Return: QDF_STATUS
64  */
65 static QDF_STATUS
wlan_wifi_pos_vdev_delete_resume(struct wlan_objmgr_vdev * vdev)66 wlan_wifi_pos_vdev_delete_resume(struct wlan_objmgr_vdev *vdev)
67 {
68 	return wma_pasn_peer_delete_all_complete(vdev);
69 }
70 
71 bool
wlan_wifi_pos_pasn_peer_delete_all(struct wlan_objmgr_psoc * psoc,uint8_t vdev_id)72 wlan_wifi_pos_pasn_peer_delete_all(struct wlan_objmgr_psoc *psoc,
73 				   uint8_t vdev_id)
74 {
75 	struct wlan_objmgr_vdev *vdev;
76 	QDF_STATUS status;
77 	struct scheduler_msg msg = {0};
78 	struct pasn_peer_delete_msg *req;
79 
80 	vdev = wlan_objmgr_get_vdev_by_id_from_psoc(psoc, vdev_id,
81 						    WLAN_WIFI_POS_TGT_IF_ID);
82 	if (!vdev) {
83 		mlme_err("Vdev is not found for id:%d", vdev_id);
84 		return false;
85 	}
86 
87 	if (!(vdev->vdev_mlme.vdev_opmode == QDF_STA_MODE ||
88 	      vdev->vdev_mlme.vdev_opmode == QDF_SAP_MODE)) {
89 		wlan_objmgr_vdev_release_ref(vdev, WLAN_WIFI_POS_TGT_IF_ID);
90 		return false;
91 	}
92 
93 	if (!wifi_pos_get_pasn_peer_count(vdev) ||
94 	    wifi_pos_is_delete_all_peer_in_progress(vdev)) {
95 		wlan_objmgr_vdev_release_ref(vdev, WLAN_WIFI_POS_TGT_IF_ID);
96 		return false;
97 	}
98 
99 	wlan_objmgr_vdev_release_ref(vdev, WLAN_WIFI_POS_TGT_IF_ID);
100 
101 	req = qdf_mem_malloc(sizeof(*req));
102 	if (!req)
103 		return false;
104 
105 	req->vdev_id = vdev_id;
106 
107 	msg.type = WIFI_POS_PASN_PEER_DELETE_ALL;
108 	msg.bodyptr = req;
109 
110 	status = scheduler_post_message(QDF_MODULE_ID_WIFIPOS,
111 					QDF_MODULE_ID_PE,
112 					QDF_MODULE_ID_PE, &msg);
113 	if (QDF_IS_STATUS_ERROR(status)) {
114 		qdf_mem_free(req);
115 		mlme_err("Delete all pasn peers failed");
116 		return false;
117 	}
118 
119 	return true;
120 }
121 
122 static struct wifi_pos_legacy_ops wifi_pos_ops = {
123 	.pasn_peer_create_cb = wlan_wifi_pos_pasn_peer_create,
124 	.pasn_peer_delete_cb = wlan_wifi_pos_pasn_peer_delete,
125 	.pasn_vdev_delete_resume_cb = wlan_wifi_pos_vdev_delete_resume,
126 };
127 
128 QDF_STATUS
wifi_pos_register_legacy_ops(struct wlan_objmgr_psoc * psoc)129 wifi_pos_register_legacy_ops(struct wlan_objmgr_psoc *psoc)
130 {
131 	return wifi_pos_set_legacy_ops(psoc, &wifi_pos_ops);
132 }
133 
134 QDF_STATUS
wifi_pos_deregister_legacy_ops(struct wlan_objmgr_psoc * psoc)135 wifi_pos_deregister_legacy_ops(struct wlan_objmgr_psoc *psoc)
136 {
137 	return wifi_pos_set_legacy_ops(psoc, NULL);
138 }
139 #endif
140