blob: 8ad5b5895dc5c07c1b5bfbcd8107b2e788f2f2d3 [file] [log] [blame]
Rajeev Kumar699debf2017-01-06 14:17:00 -08001/*
Dustin Brownb277dd62018-01-26 15:17:33 -08002 * Copyright (c) 2017-2018 The Linux Foundation. All rights reserved.
Rajeev Kumar699debf2017-01-06 14:17:00 -08003 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
28/**
29 * DOC: HDD object manager API source file to create/destroy PSOC,
30 * PDEV, VDEV and PEER objects.
31 */
32
33#include <wlan_hdd_object_manager.h>
Sandeep Puligillafdd201e2017-02-02 18:43:46 -080034#include <wlan_osif_priv.h>
Arunk Khandavallia6305a32018-01-25 11:19:18 +053035#include <wlan_reg_ucfg_api.h>
36#include <target_if.h>
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -080037#include <os_if_spectral_netlink.h>
Sandeep Puligillafdd201e2017-02-02 18:43:46 -080038
Amar Singhalcab1b4f2017-05-09 14:40:07 -070039#define LOW_2GHZ_FREQ 2312
40#define HIGH_2GHZ_FREQ 2732
41#define LOW_5GHZ_FREQ 4912
42#define HIGH_5GHZ_FREQ 6100
43
Jeff Johnson72a17982017-08-28 11:49:53 -070044static void hdd_init_pdev_os_priv(struct hdd_context *hdd_ctx,
Sandeep Puligillafdd201e2017-02-02 18:43:46 -080045 struct pdev_osif_priv *os_priv)
46{
47 /* Initialize the OS private structure*/
48 os_priv->wiphy = hdd_ctx->wiphy;
Jeff Johnson174c47a2017-09-29 10:11:03 -070049 os_priv->legacy_osif_priv = hdd_ctx;
Sandeep Puligilla8de3c1c2017-04-13 17:56:18 -070050 wlan_cfg80211_scan_priv_init(hdd_ctx->hdd_pdev);
Sandeep Puligilla019a1bd2018-02-04 22:57:44 -080051 os_if_spectral_netlink_init(hdd_ctx->hdd_pdev);
Sandeep Puligilla8de3c1c2017-04-13 17:56:18 -070052}
53
Dustin Brownb277dd62018-01-26 15:17:33 -080054static void hdd_deinit_pdev_os_priv(struct wlan_objmgr_pdev *pdev)
Sandeep Puligilla8de3c1c2017-04-13 17:56:18 -070055{
Dustin Brownb277dd62018-01-26 15:17:33 -080056 wlan_cfg80211_scan_priv_deinit(pdev);
Sandeep Puligillafdd201e2017-02-02 18:43:46 -080057}
Rajeev Kumar699debf2017-01-06 14:17:00 -080058
Jeff Johnsone46a84b2017-08-29 14:27:58 -070059static void hdd_init_vdev_os_priv(struct hdd_adapter *adapter,
Wu Gaoe960db62017-03-13 21:00:11 +080060 struct vdev_osif_priv *os_priv)
61{
62 /* Initialize the vdev OS private structure*/
63 os_priv->wdev = adapter->dev->ieee80211_ptr;
Jeff Johnson174c47a2017-09-29 10:11:03 -070064 os_priv->legacy_osif_priv = adapter;
Frank Liud4b2fa02017-03-29 11:46:48 +080065 wlan_cfg80211_tdls_priv_init(os_priv);
Wu Gaoe960db62017-03-13 21:00:11 +080066}
67
Wu Gao2ae0b592017-03-13 21:10:16 +080068static void hdd_init_psoc_qdf_ctx(struct wlan_objmgr_psoc *psoc)
69{
70 qdf_device_t qdf_ctx;
71
72 qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
73 if (!qdf_ctx) {
74 hdd_err("qdf ctx is null, can't set to soc object");
75 return;
76 }
77
78 wlan_psoc_set_qdf_dev(psoc, qdf_ctx);
79}
80
Jeff Johnson5cf5ad22017-10-03 11:56:07 -070081int hdd_objmgr_create_and_store_psoc(struct hdd_context *hdd_ctx,
82 uint8_t psoc_id)
Rajeev Kumar699debf2017-01-06 14:17:00 -080083{
Dustin Brownb277dd62018-01-26 15:17:33 -080084 QDF_STATUS status;
Rajeev Kumar699debf2017-01-06 14:17:00 -080085 struct wlan_objmgr_psoc *psoc;
86
87 psoc = wlan_objmgr_psoc_obj_create(psoc_id, WLAN_DEV_OL);
88 if (!psoc)
Rajeev Kumar138ef912017-01-13 15:19:48 -080089 return -ENOMEM;
Rajeev Kumar699debf2017-01-06 14:17:00 -080090
Dustin Brownb277dd62018-01-26 15:17:33 -080091 status = wlan_objmgr_psoc_try_get_ref(psoc, WLAN_HDD_ID_OBJ_MGR);
92 if (QDF_IS_STATUS_ERROR(status)) {
93 hdd_err("Failed to acquire psoc ref; status:%d", status);
94 QDF_BUG(false);
95 goto psoc_destroy;
96 }
97
Wu Gao2ae0b592017-03-13 21:10:16 +080098 hdd_init_psoc_qdf_ctx(psoc);
Rajeev Kumar699debf2017-01-06 14:17:00 -080099 hdd_ctx->hdd_psoc = psoc;
100
Rajeev Kumar138ef912017-01-13 15:19:48 -0800101 return 0;
Dustin Brownb277dd62018-01-26 15:17:33 -0800102
103psoc_destroy:
104 wlan_objmgr_psoc_obj_delete(psoc);
105
106 return qdf_status_to_os_return(status);
Rajeev Kumar699debf2017-01-06 14:17:00 -0800107}
108
Jeff Johnson72a17982017-08-28 11:49:53 -0700109int hdd_objmgr_release_and_destroy_psoc(struct hdd_context *hdd_ctx)
Rajeev Kumar699debf2017-01-06 14:17:00 -0800110{
Dustin Brownb277dd62018-01-26 15:17:33 -0800111 QDF_STATUS status;
Rajeev Kumar699debf2017-01-06 14:17:00 -0800112 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
113
114 hdd_ctx->hdd_psoc = NULL;
Dustin Brownb277dd62018-01-26 15:17:33 -0800115
116 QDF_BUG(psoc);
Rajeev Kumar699debf2017-01-06 14:17:00 -0800117 if (!psoc)
Rajeev Kumar99e4cf62017-01-13 15:31:19 -0800118 return -EINVAL;
Rajeev Kumar699debf2017-01-06 14:17:00 -0800119
Selvaraj, Sridhar3a1823f2017-02-01 17:32:21 +0530120 wlan_objmgr_print_ref_all_objects_per_psoc(psoc);
121
Dustin Brownb277dd62018-01-26 15:17:33 -0800122 status = wlan_objmgr_psoc_obj_delete(psoc);
123 wlan_objmgr_psoc_release_ref(psoc, WLAN_HDD_ID_OBJ_MGR);
124
125 return qdf_status_to_os_return(status);
Rajeev Kumar699debf2017-01-06 14:17:00 -0800126}
127
Jeff Johnson72a17982017-08-28 11:49:53 -0700128int hdd_objmgr_create_and_store_pdev(struct hdd_context *hdd_ctx)
Rajeev Kumar699debf2017-01-06 14:17:00 -0800129{
Dustin Brownb277dd62018-01-26 15:17:33 -0800130 QDF_STATUS status;
Rajeev Kumar699debf2017-01-06 14:17:00 -0800131 struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc;
132 struct wlan_objmgr_pdev *pdev;
Sandeep Puligillafdd201e2017-02-02 18:43:46 -0800133 struct pdev_osif_priv *priv;
Amar Singhalcab1b4f2017-05-09 14:40:07 -0700134 struct wlan_psoc_host_hal_reg_capabilities_ext *reg_cap_ptr;
Rajeev Kumar699debf2017-01-06 14:17:00 -0800135
136 if (!psoc) {
137 hdd_err("Psoc NULL");
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -0800138 return -EINVAL;
Rajeev Kumar699debf2017-01-06 14:17:00 -0800139 }
140
Sandeep Puligillafdd201e2017-02-02 18:43:46 -0800141 priv = qdf_mem_malloc(sizeof(*priv));
142 if (priv == NULL) {
143 hdd_err("pdev os obj create failed");
144 return -ENOMEM;
145 }
Amar Singhalcab1b4f2017-05-09 14:40:07 -0700146
Arunk Khandavallia6305a32018-01-25 11:19:18 +0530147 reg_cap_ptr = ucfg_reg_get_hal_reg_cap(psoc);
Amar Singhalcab1b4f2017-05-09 14:40:07 -0700148 reg_cap_ptr->phy_id = 0;
149 reg_cap_ptr->low_2ghz_chan = LOW_2GHZ_FREQ;
150 reg_cap_ptr->high_2ghz_chan = HIGH_2GHZ_FREQ;
151 reg_cap_ptr->low_5ghz_chan = LOW_5GHZ_FREQ;
152 reg_cap_ptr->high_5ghz_chan = HIGH_5GHZ_FREQ;
153
Sandeep Puligillafdd201e2017-02-02 18:43:46 -0800154 pdev = wlan_objmgr_pdev_obj_create(psoc, priv);
Rajeev Kumar699debf2017-01-06 14:17:00 -0800155 if (!pdev) {
156 hdd_err("pdev obj create failed");
Arunk Khandavallia6305a32018-01-25 11:19:18 +0530157 status = QDF_STATUS_E_NOMEM;
158 goto free_priv;
Rajeev Kumar699debf2017-01-06 14:17:00 -0800159 }
Amar Singhalcab1b4f2017-05-09 14:40:07 -0700160
Dustin Brownb277dd62018-01-26 15:17:33 -0800161 status = wlan_objmgr_pdev_try_get_ref(pdev, WLAN_HDD_ID_OBJ_MGR);
162 if (QDF_IS_STATUS_ERROR(status)) {
163 hdd_err("Failed to acquire pdev ref; status:%d", status);
164 QDF_BUG(false);
165 goto pdev_destroy;
166 }
167
Arunk Khandavallia6305a32018-01-25 11:19:18 +0530168 status = target_if_alloc_pdev_tgt_info(pdev);
169 if (status != QDF_STATUS_SUCCESS) {
170 hdd_err("pdev tgt info alloc failed");
171 goto pdev_destroy;
172 }
173
Rajeev Kumar699debf2017-01-06 14:17:00 -0800174 hdd_ctx->hdd_pdev = pdev;
Kiran Kumar Lokerea3de2262017-04-12 12:15:04 -0700175 sme_store_pdev(hdd_ctx->hHal, hdd_ctx->hdd_pdev);
Wu Gaoe960db62017-03-13 21:00:11 +0800176 hdd_init_pdev_os_priv(hdd_ctx, priv);
Rajeev Kumarf49dfdb2017-01-13 15:40:35 -0800177 return 0;
Dustin Brownb277dd62018-01-26 15:17:33 -0800178
179pdev_destroy:
180 wlan_objmgr_pdev_obj_delete(pdev);
Arunk Khandavallia6305a32018-01-25 11:19:18 +0530181free_priv:
Dustin Brownb277dd62018-01-26 15:17:33 -0800182 qdf_mem_free(priv);
183
184 return qdf_status_to_os_return(status);
Rajeev Kumar699debf2017-01-06 14:17:00 -0800185}
186
Jeff Johnson72a17982017-08-28 11:49:53 -0700187int hdd_objmgr_release_and_destroy_pdev(struct hdd_context *hdd_ctx)
Rajeev Kumar699debf2017-01-06 14:17:00 -0800188{
Dustin Brownb277dd62018-01-26 15:17:33 -0800189 QDF_STATUS status;
Rajeev Kumar699debf2017-01-06 14:17:00 -0800190 struct wlan_objmgr_pdev *pdev = hdd_ctx->hdd_pdev;
Sandeep Puligillafdd201e2017-02-02 18:43:46 -0800191 struct pdev_osif_priv *osif_priv;
Rajeev Kumar699debf2017-01-06 14:17:00 -0800192
193 hdd_ctx->hdd_pdev = NULL;
Dustin Brownb277dd62018-01-26 15:17:33 -0800194
195 QDF_BUG(pdev);
Rajeev Kumar699debf2017-01-06 14:17:00 -0800196 if (!pdev)
Rajeev Kumarecf87ff2017-01-13 15:46:07 -0800197 return -EINVAL;
Rajeev Kumar699debf2017-01-06 14:17:00 -0800198
Arunk Khandavallia6305a32018-01-25 11:19:18 +0530199 target_if_free_pdev_tgt_info(pdev);
Dustin Brownb277dd62018-01-26 15:17:33 -0800200
Arunk Khandavallia6305a32018-01-25 11:19:18 +0530201 hdd_deinit_pdev_os_priv(pdev);
Jeff Johnsonae6bb802017-03-23 13:26:10 -0700202 osif_priv = wlan_pdev_get_ospriv(pdev);
203 wlan_pdev_reset_ospriv(pdev);
Sandeep Puligillafdd201e2017-02-02 18:43:46 -0800204 qdf_mem_free(osif_priv);
205
Dustin Brownb277dd62018-01-26 15:17:33 -0800206 status = wlan_objmgr_pdev_obj_delete(pdev);
207 wlan_objmgr_pdev_release_ref(pdev, WLAN_HDD_ID_OBJ_MGR);
208
209 return qdf_status_to_os_return(status);
Rajeev Kumar699debf2017-01-06 14:17:00 -0800210}
211
Dustin Brown7d043f62017-03-27 12:07:36 -0700212int hdd_objmgr_create_and_store_vdev(struct wlan_objmgr_pdev *pdev,
Jeff Johnsone46a84b2017-08-29 14:27:58 -0700213 struct hdd_adapter *adapter)
Rajeev Kumar699debf2017-01-06 14:17:00 -0800214{
Dustin Brownf4a6e0f2017-11-28 10:03:52 -0800215 QDF_STATUS status;
216 int errno;
Rajeev Kumar699debf2017-01-06 14:17:00 -0800217 struct wlan_objmgr_vdev *vdev;
218 struct wlan_objmgr_peer *peer;
Wu Gaoe960db62017-03-13 21:00:11 +0800219 struct vdev_osif_priv *osif_priv;
Dustin Brownf4a6e0f2017-11-28 10:03:52 -0800220 struct wlan_vdev_create_params vdev_params = {0};
Rajeev Kumar699debf2017-01-06 14:17:00 -0800221
Dustin Brownf4a6e0f2017-11-28 10:03:52 -0800222 QDF_BUG(pdev);
Rajeev Kumar699debf2017-01-06 14:17:00 -0800223 if (!pdev) {
Dustin Brownf4a6e0f2017-11-28 10:03:52 -0800224 hdd_err("pdev is null");
Rajeev Kumardeabf3e2017-01-13 15:55:05 -0800225 return -EINVAL;
Rajeev Kumar699debf2017-01-06 14:17:00 -0800226 }
227
Wu Gaoe960db62017-03-13 21:00:11 +0800228 osif_priv = qdf_mem_malloc(sizeof(*osif_priv));
229 if (!osif_priv) {
Dustin Brownf4a6e0f2017-11-28 10:03:52 -0800230 hdd_err("Failed to allocate osif_priv; out of memory");
Wu Gaoe960db62017-03-13 21:00:11 +0800231 return -ENOMEM;
232 }
Wu Gaoe960db62017-03-13 21:00:11 +0800233 hdd_init_vdev_os_priv(adapter, osif_priv);
Dustin Brownf4a6e0f2017-11-28 10:03:52 -0800234
235 vdev_params.opmode = adapter->device_mode;
Wu Gaoe960db62017-03-13 21:00:11 +0800236 vdev_params.osifp = osif_priv;
Dustin Brownf4a6e0f2017-11-28 10:03:52 -0800237 qdf_mem_copy(vdev_params.macaddr,
238 adapter->mac_addr.bytes,
239 QDF_NET_MAC_ADDR_MAX_LEN);
Wu Gaoe960db62017-03-13 21:00:11 +0800240
Rajeev Kumar699debf2017-01-06 14:17:00 -0800241 vdev = wlan_objmgr_vdev_obj_create(pdev, &vdev_params);
242 if (!vdev) {
Dustin Brownf4a6e0f2017-11-28 10:03:52 -0800243 hdd_err("Failed to create vdev object");
244 errno = -ENOMEM;
245 goto osif_priv_free;
Rajeev Kumar699debf2017-01-06 14:17:00 -0800246 }
Rajeev Kumar699debf2017-01-06 14:17:00 -0800247
Dustin Brown0d2eeae2017-03-24 15:21:32 -0700248 /*
249 * To enable legacy use cases, we need to delay physical vdev destroy
250 * until after the sme session has been closed. We accomplish this by
Dustin Brownf4a6e0f2017-11-28 10:03:52 -0800251 * getting a reference here.
Dustin Brown0d2eeae2017-03-24 15:21:32 -0700252 */
Dustin Brownf4a6e0f2017-11-28 10:03:52 -0800253 status = wlan_objmgr_vdev_try_get_ref(vdev, WLAN_HDD_ID_OBJ_MGR);
254 if (QDF_IS_STATUS_ERROR(status)) {
255 hdd_err("Failed to acquire vdev ref; status:%d", status);
256 errno = qdf_status_to_os_return(status);
257 goto vdev_destroy;
258 }
259
260 peer = wlan_objmgr_peer_obj_create(vdev, WLAN_PEER_SELF,
261 vdev_params.macaddr);
262 if (!peer) {
263 hdd_err("Failed to create self peer for adapter mode %d",
264 adapter->device_mode);
265 errno = -ENOMEM;
266 goto vdev_put_ref;
267 }
Dustin Brown0d2eeae2017-03-24 15:21:32 -0700268
Selvaraj, Sridhar3a1823f2017-02-01 17:32:21 +0530269 adapter->hdd_vdev = vdev;
Jeff Johnson1b780e42017-10-31 14:11:45 -0700270 adapter->session_id = wlan_vdev_get_id(vdev);
Rajeev Kumar699debf2017-01-06 14:17:00 -0800271
Rajeev Kumardeabf3e2017-01-13 15:55:05 -0800272 return 0;
Dustin Brownf4a6e0f2017-11-28 10:03:52 -0800273
274vdev_put_ref:
275 wlan_objmgr_vdev_release_ref(vdev, WLAN_HDD_ID_OBJ_MGR);
276
277vdev_destroy:
278 wlan_objmgr_vdev_obj_delete(vdev);
279
280osif_priv_free:
281 qdf_mem_free(osif_priv);
282
283 return errno;
Rajeev Kumar699debf2017-01-06 14:17:00 -0800284}
285
Dustin Brownb277dd62018-01-26 15:17:33 -0800286int hdd_objmgr_release_and_destroy_vdev(struct hdd_adapter *adapter)
Rajeev Kumar699debf2017-01-06 14:17:00 -0800287{
Dustin Brownb277dd62018-01-26 15:17:33 -0800288 QDF_STATUS status;
289 struct wlan_objmgr_vdev *vdev = adapter->hdd_vdev;
Wu Gaoe960db62017-03-13 21:00:11 +0800290 struct vdev_osif_priv *osif_priv;
Dustin Brownb277dd62018-01-26 15:17:33 -0800291 uint8_t *self_mac_addr;
Dustin Brown0d2eeae2017-03-24 15:21:32 -0700292
293 adapter->hdd_vdev = NULL;
Jeff Johnson1b780e42017-10-31 14:11:45 -0700294 adapter->session_id = HDD_SESSION_ID_INVALID;
Dustin Brown0d2eeae2017-03-24 15:21:32 -0700295
Dustin Brownb277dd62018-01-26 15:17:33 -0800296 QDF_BUG(vdev);
297 if (!vdev)
298 return -EINVAL;
Dustin Brown0d2eeae2017-03-24 15:21:32 -0700299
Dustin Brownb277dd62018-01-26 15:17:33 -0800300 osif_priv = wlan_vdev_get_ospriv(vdev);
301 wlan_vdev_reset_ospriv(vdev);
Dustin Brown0d2eeae2017-03-24 15:21:32 -0700302
Dustin Brownb277dd62018-01-26 15:17:33 -0800303 QDF_BUG(osif_priv);
304 if (osif_priv) {
305 wlan_cfg80211_tdls_priv_deinit(osif_priv);
306 qdf_mem_free(osif_priv);
307 }
Dustin Brown0d2eeae2017-03-24 15:21:32 -0700308
Dustin Brownb277dd62018-01-26 15:17:33 -0800309 self_mac_addr = wlan_vdev_mlme_get_macaddr(vdev);
310 if (hdd_objmgr_remove_peer_object(vdev, self_mac_addr))
311 hdd_err("Self peer delete failed");
312
313 status = wlan_objmgr_vdev_obj_delete(vdev);
314 wlan_objmgr_vdev_release_ref(vdev, WLAN_HDD_ID_OBJ_MGR);
315
316 return qdf_status_to_os_return(status);
Dustin Brown0d2eeae2017-03-24 15:21:32 -0700317}
318
Dustin Brown7d043f62017-03-27 12:07:36 -0700319int hdd_objmgr_add_peer_object(struct wlan_objmgr_vdev *vdev,
Jeff Johnsonc1e62782017-11-09 09:50:17 -0800320 enum QDF_OPMODE adapter_mode,
Rachit Kankane2487f8f2017-04-19 14:30:19 +0530321 uint8_t *mac_addr,
322 bool is_p2p_type)
Rajeev Kumar699debf2017-01-06 14:17:00 -0800323{
324 enum wlan_peer_type peer_type;
Selvaraj, Sridhard761f252017-01-19 13:08:39 +0530325 struct wlan_objmgr_peer *peer;
Rajeev Kumar699debf2017-01-06 14:17:00 -0800326
327 if ((adapter_mode == QDF_STA_MODE) ||
328 (adapter_mode == QDF_P2P_CLIENT_MODE)) {
329 peer_type = WLAN_PEER_AP;
330 } else if ((adapter_mode == QDF_SAP_MODE) ||
331 (adapter_mode == QDF_P2P_GO_MODE)) {
Rachit Kankane2487f8f2017-04-19 14:30:19 +0530332 if (is_p2p_type) {
333 peer_type = WLAN_PEER_P2P_CLI;
334 } else {
335 peer_type = WLAN_PEER_STA;
336 }
Rajeev Kumar699debf2017-01-06 14:17:00 -0800337 } else if (adapter_mode == QDF_IBSS_MODE) {
338 peer_type = WLAN_PEER_IBSS;
Naveen Rawat95eb4062017-11-02 16:46:41 -0700339 } else if (adapter_mode == QDF_NDI_MODE) {
340 peer_type = WLAN_PEER_NDP;
Rajeev Kumar699debf2017-01-06 14:17:00 -0800341 } else {
342 hdd_err("Unsupported device mode %d", adapter_mode);
Rajeev Kumar78427682017-01-13 16:13:11 -0800343 return -EINVAL;
Rajeev Kumar699debf2017-01-06 14:17:00 -0800344 }
345
346 if (!vdev) {
347 hdd_err("vdev NULL");
348 QDF_ASSERT(0);
Rajeev Kumar78427682017-01-13 16:13:11 -0800349 return -EFAULT;
Rajeev Kumar699debf2017-01-06 14:17:00 -0800350 }
351
Selvaraj, Sridhard761f252017-01-19 13:08:39 +0530352 peer = wlan_objmgr_peer_obj_create(vdev, peer_type, mac_addr);
353 if (!peer)
Rajeev Kumar78427682017-01-13 16:13:11 -0800354 return -ENOMEM;
Rajeev Kumar699debf2017-01-06 14:17:00 -0800355
Kiran Kumar Lokere1d411bb2017-11-29 15:24:05 -0800356 hdd_debug("Peer object "MAC_ADDRESS_STR" add success! Type: %d",
Rachit Kankane2487f8f2017-04-19 14:30:19 +0530357 MAC_ADDR_ARRAY(mac_addr), peer_type);
Rajeev Kumar699debf2017-01-06 14:17:00 -0800358
Rajeev Kumar78427682017-01-13 16:13:11 -0800359 return 0;
Rajeev Kumar699debf2017-01-06 14:17:00 -0800360}
361
Dustin Brown7d043f62017-03-27 12:07:36 -0700362int hdd_objmgr_remove_peer_object(struct wlan_objmgr_vdev *vdev,
363 uint8_t *mac_addr)
Rajeev Kumar699debf2017-01-06 14:17:00 -0800364{
365 struct wlan_objmgr_psoc *psoc;
366 struct wlan_objmgr_peer *peer;
367
368 if (!vdev) {
369 hdd_err("vdev NULL");
370 QDF_ASSERT(0);
Rajeev Kumardfa37072017-01-13 16:27:22 -0800371 return -EINVAL;
Rajeev Kumar699debf2017-01-06 14:17:00 -0800372 }
373
374 psoc = wlan_vdev_get_psoc(vdev);
375 if (!psoc) {
376 hdd_err("Psoc NUll");
377 QDF_ASSERT(0);
Rajeev Kumardfa37072017-01-13 16:27:22 -0800378 return -EINVAL;
Rajeev Kumar699debf2017-01-06 14:17:00 -0800379 }
380
Selvaraj, Sridhar3a1823f2017-02-01 17:32:21 +0530381 peer = wlan_objmgr_get_peer(psoc, mac_addr, WLAN_HDD_ID_OBJ_MGR);
Rajeev Kumar699debf2017-01-06 14:17:00 -0800382 if (peer) {
wadesongdb4d9582017-12-20 15:28:34 +0800383 wlan_objmgr_peer_obj_delete(peer);
384
Selvaraj, Sridhard761f252017-01-19 13:08:39 +0530385 /* Unref to decrement ref happened in find_peer */
Selvaraj, Sridhar3a1823f2017-02-01 17:32:21 +0530386 wlan_objmgr_peer_release_ref(peer, WLAN_HDD_ID_OBJ_MGR);
Selvaraj, Sridhard761f252017-01-19 13:08:39 +0530387
Rajeev Kumar699debf2017-01-06 14:17:00 -0800388 hdd_info("Peer obj "MAC_ADDRESS_STR" deleted",
389 MAC_ADDR_ARRAY(mac_addr));
Rajeev Kumardfa37072017-01-13 16:27:22 -0800390 return 0;
Rajeev Kumar699debf2017-01-06 14:17:00 -0800391 }
392
393 hdd_err("Peer obj "MAC_ADDRESS_STR" not found",
394 MAC_ADDR_ARRAY(mac_addr));
395
Rajeev Kumardfa37072017-01-13 16:27:22 -0800396 return -EINVAL;
Rajeev Kumar699debf2017-01-06 14:17:00 -0800397}
Mukul Sharma5678be42017-01-24 12:20:01 +0530398
Kabilan Kannanf56f9d52017-04-05 03:31:34 -0700399int hdd_objmgr_set_peer_mlme_auth_state(struct wlan_objmgr_vdev *vdev,
400 bool is_authenticated)
401{
402 struct wlan_objmgr_peer *peer;
403 QDF_STATUS status;
404
405 wlan_vdev_obj_lock(vdev);
406 peer = wlan_vdev_get_bsspeer(vdev);
407 wlan_vdev_obj_unlock(vdev);
408
409 if (!peer) {
410 hdd_err("peer is null");
411
412 return -EINVAL;
413 }
414 status = wlan_objmgr_peer_try_get_ref(peer, WLAN_TDLS_NB_ID);
415 if (status != QDF_STATUS_SUCCESS)
416 return -EINVAL;
417
418 wlan_peer_obj_lock(peer);
419 wlan_peer_mlme_set_auth_state(peer, is_authenticated);
420 wlan_peer_obj_unlock(peer);
421
422 wlan_objmgr_peer_release_ref(peer, WLAN_TDLS_NB_ID);
423 return 0;
424}
425
Dustin Brown7d043f62017-03-27 12:07:36 -0700426int hdd_objmgr_set_peer_mlme_state(struct wlan_objmgr_vdev *vdev,
Kabilan Kannanf56f9d52017-04-05 03:31:34 -0700427 enum wlan_peer_state peer_state)
Mukul Sharma5678be42017-01-24 12:20:01 +0530428{
429 struct wlan_objmgr_peer *peer;
430
431 wlan_vdev_obj_lock(vdev);
432 peer = wlan_vdev_get_bsspeer(vdev);
433 wlan_vdev_obj_unlock(vdev);
434
Jeff Johnson68755312017-02-10 11:46:55 -0800435 if (!peer) {
Mukul Sharma5678be42017-01-24 12:20:01 +0530436 hdd_err("peer is null");
Jeff Johnson68755312017-02-10 11:46:55 -0800437
Mukul Sharma5678be42017-01-24 12:20:01 +0530438 return -EINVAL;
439 }
440
Jeff Johnson68755312017-02-10 11:46:55 -0800441 wlan_peer_obj_lock(peer);
442 wlan_peer_mlme_set_state(peer, WLAN_ASSOC_STATE);
443 wlan_peer_obj_unlock(peer);
444
445 return 0;
Mukul Sharma5678be42017-01-24 12:20:01 +0530446}
447