Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 1 | /* |
Dustin Brown | b277dd6 | 2018-01-26 15:17:33 -0800 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 The Linux Foundation. All rights reserved. |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 3 | * |
| 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 Puligilla | fdd201e | 2017-02-02 18:43:46 -0800 | [diff] [blame] | 34 | #include <wlan_osif_priv.h> |
Arunk Khandavalli | a6305a3 | 2018-01-25 11:19:18 +0530 | [diff] [blame] | 35 | #include <wlan_reg_ucfg_api.h> |
| 36 | #include <target_if.h> |
Sandeep Puligilla | 019a1bd | 2018-02-04 22:57:44 -0800 | [diff] [blame^] | 37 | #include <os_if_spectral_netlink.h> |
Sandeep Puligilla | fdd201e | 2017-02-02 18:43:46 -0800 | [diff] [blame] | 38 | |
Amar Singhal | cab1b4f | 2017-05-09 14:40:07 -0700 | [diff] [blame] | 39 | #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 Johnson | 72a1798 | 2017-08-28 11:49:53 -0700 | [diff] [blame] | 44 | static void hdd_init_pdev_os_priv(struct hdd_context *hdd_ctx, |
Sandeep Puligilla | fdd201e | 2017-02-02 18:43:46 -0800 | [diff] [blame] | 45 | struct pdev_osif_priv *os_priv) |
| 46 | { |
| 47 | /* Initialize the OS private structure*/ |
| 48 | os_priv->wiphy = hdd_ctx->wiphy; |
Jeff Johnson | 174c47a | 2017-09-29 10:11:03 -0700 | [diff] [blame] | 49 | os_priv->legacy_osif_priv = hdd_ctx; |
Sandeep Puligilla | 8de3c1c | 2017-04-13 17:56:18 -0700 | [diff] [blame] | 50 | wlan_cfg80211_scan_priv_init(hdd_ctx->hdd_pdev); |
Sandeep Puligilla | 019a1bd | 2018-02-04 22:57:44 -0800 | [diff] [blame^] | 51 | os_if_spectral_netlink_init(hdd_ctx->hdd_pdev); |
Sandeep Puligilla | 8de3c1c | 2017-04-13 17:56:18 -0700 | [diff] [blame] | 52 | } |
| 53 | |
Dustin Brown | b277dd6 | 2018-01-26 15:17:33 -0800 | [diff] [blame] | 54 | static void hdd_deinit_pdev_os_priv(struct wlan_objmgr_pdev *pdev) |
Sandeep Puligilla | 8de3c1c | 2017-04-13 17:56:18 -0700 | [diff] [blame] | 55 | { |
Dustin Brown | b277dd6 | 2018-01-26 15:17:33 -0800 | [diff] [blame] | 56 | wlan_cfg80211_scan_priv_deinit(pdev); |
Sandeep Puligilla | fdd201e | 2017-02-02 18:43:46 -0800 | [diff] [blame] | 57 | } |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 58 | |
Jeff Johnson | e46a84b | 2017-08-29 14:27:58 -0700 | [diff] [blame] | 59 | static void hdd_init_vdev_os_priv(struct hdd_adapter *adapter, |
Wu Gao | e960db6 | 2017-03-13 21:00:11 +0800 | [diff] [blame] | 60 | struct vdev_osif_priv *os_priv) |
| 61 | { |
| 62 | /* Initialize the vdev OS private structure*/ |
| 63 | os_priv->wdev = adapter->dev->ieee80211_ptr; |
Jeff Johnson | 174c47a | 2017-09-29 10:11:03 -0700 | [diff] [blame] | 64 | os_priv->legacy_osif_priv = adapter; |
Frank Liu | d4b2fa0 | 2017-03-29 11:46:48 +0800 | [diff] [blame] | 65 | wlan_cfg80211_tdls_priv_init(os_priv); |
Wu Gao | e960db6 | 2017-03-13 21:00:11 +0800 | [diff] [blame] | 66 | } |
| 67 | |
Wu Gao | 2ae0b59 | 2017-03-13 21:10:16 +0800 | [diff] [blame] | 68 | static 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 Johnson | 5cf5ad2 | 2017-10-03 11:56:07 -0700 | [diff] [blame] | 81 | int hdd_objmgr_create_and_store_psoc(struct hdd_context *hdd_ctx, |
| 82 | uint8_t psoc_id) |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 83 | { |
Dustin Brown | b277dd6 | 2018-01-26 15:17:33 -0800 | [diff] [blame] | 84 | QDF_STATUS status; |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 85 | struct wlan_objmgr_psoc *psoc; |
| 86 | |
| 87 | psoc = wlan_objmgr_psoc_obj_create(psoc_id, WLAN_DEV_OL); |
| 88 | if (!psoc) |
Rajeev Kumar | 138ef91 | 2017-01-13 15:19:48 -0800 | [diff] [blame] | 89 | return -ENOMEM; |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 90 | |
Dustin Brown | b277dd6 | 2018-01-26 15:17:33 -0800 | [diff] [blame] | 91 | 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 Gao | 2ae0b59 | 2017-03-13 21:10:16 +0800 | [diff] [blame] | 98 | hdd_init_psoc_qdf_ctx(psoc); |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 99 | hdd_ctx->hdd_psoc = psoc; |
| 100 | |
Rajeev Kumar | 138ef91 | 2017-01-13 15:19:48 -0800 | [diff] [blame] | 101 | return 0; |
Dustin Brown | b277dd6 | 2018-01-26 15:17:33 -0800 | [diff] [blame] | 102 | |
| 103 | psoc_destroy: |
| 104 | wlan_objmgr_psoc_obj_delete(psoc); |
| 105 | |
| 106 | return qdf_status_to_os_return(status); |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 107 | } |
| 108 | |
Jeff Johnson | 72a1798 | 2017-08-28 11:49:53 -0700 | [diff] [blame] | 109 | int hdd_objmgr_release_and_destroy_psoc(struct hdd_context *hdd_ctx) |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 110 | { |
Dustin Brown | b277dd6 | 2018-01-26 15:17:33 -0800 | [diff] [blame] | 111 | QDF_STATUS status; |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 112 | struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc; |
| 113 | |
| 114 | hdd_ctx->hdd_psoc = NULL; |
Dustin Brown | b277dd6 | 2018-01-26 15:17:33 -0800 | [diff] [blame] | 115 | |
| 116 | QDF_BUG(psoc); |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 117 | if (!psoc) |
Rajeev Kumar | 99e4cf6 | 2017-01-13 15:31:19 -0800 | [diff] [blame] | 118 | return -EINVAL; |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 119 | |
Selvaraj, Sridhar | 3a1823f | 2017-02-01 17:32:21 +0530 | [diff] [blame] | 120 | wlan_objmgr_print_ref_all_objects_per_psoc(psoc); |
| 121 | |
Dustin Brown | b277dd6 | 2018-01-26 15:17:33 -0800 | [diff] [blame] | 122 | 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 Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 126 | } |
| 127 | |
Jeff Johnson | 72a1798 | 2017-08-28 11:49:53 -0700 | [diff] [blame] | 128 | int hdd_objmgr_create_and_store_pdev(struct hdd_context *hdd_ctx) |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 129 | { |
Dustin Brown | b277dd6 | 2018-01-26 15:17:33 -0800 | [diff] [blame] | 130 | QDF_STATUS status; |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 131 | struct wlan_objmgr_psoc *psoc = hdd_ctx->hdd_psoc; |
| 132 | struct wlan_objmgr_pdev *pdev; |
Sandeep Puligilla | fdd201e | 2017-02-02 18:43:46 -0800 | [diff] [blame] | 133 | struct pdev_osif_priv *priv; |
Amar Singhal | cab1b4f | 2017-05-09 14:40:07 -0700 | [diff] [blame] | 134 | struct wlan_psoc_host_hal_reg_capabilities_ext *reg_cap_ptr; |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 135 | |
| 136 | if (!psoc) { |
| 137 | hdd_err("Psoc NULL"); |
Rajeev Kumar | f49dfdb | 2017-01-13 15:40:35 -0800 | [diff] [blame] | 138 | return -EINVAL; |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 139 | } |
| 140 | |
Sandeep Puligilla | fdd201e | 2017-02-02 18:43:46 -0800 | [diff] [blame] | 141 | priv = qdf_mem_malloc(sizeof(*priv)); |
| 142 | if (priv == NULL) { |
| 143 | hdd_err("pdev os obj create failed"); |
| 144 | return -ENOMEM; |
| 145 | } |
Amar Singhal | cab1b4f | 2017-05-09 14:40:07 -0700 | [diff] [blame] | 146 | |
Arunk Khandavalli | a6305a3 | 2018-01-25 11:19:18 +0530 | [diff] [blame] | 147 | reg_cap_ptr = ucfg_reg_get_hal_reg_cap(psoc); |
Amar Singhal | cab1b4f | 2017-05-09 14:40:07 -0700 | [diff] [blame] | 148 | 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 Puligilla | fdd201e | 2017-02-02 18:43:46 -0800 | [diff] [blame] | 154 | pdev = wlan_objmgr_pdev_obj_create(psoc, priv); |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 155 | if (!pdev) { |
| 156 | hdd_err("pdev obj create failed"); |
Arunk Khandavalli | a6305a3 | 2018-01-25 11:19:18 +0530 | [diff] [blame] | 157 | status = QDF_STATUS_E_NOMEM; |
| 158 | goto free_priv; |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 159 | } |
Amar Singhal | cab1b4f | 2017-05-09 14:40:07 -0700 | [diff] [blame] | 160 | |
Dustin Brown | b277dd6 | 2018-01-26 15:17:33 -0800 | [diff] [blame] | 161 | 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 Khandavalli | a6305a3 | 2018-01-25 11:19:18 +0530 | [diff] [blame] | 168 | 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 Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 174 | hdd_ctx->hdd_pdev = pdev; |
Kiran Kumar Lokere | a3de226 | 2017-04-12 12:15:04 -0700 | [diff] [blame] | 175 | sme_store_pdev(hdd_ctx->hHal, hdd_ctx->hdd_pdev); |
Wu Gao | e960db6 | 2017-03-13 21:00:11 +0800 | [diff] [blame] | 176 | hdd_init_pdev_os_priv(hdd_ctx, priv); |
Rajeev Kumar | f49dfdb | 2017-01-13 15:40:35 -0800 | [diff] [blame] | 177 | return 0; |
Dustin Brown | b277dd6 | 2018-01-26 15:17:33 -0800 | [diff] [blame] | 178 | |
| 179 | pdev_destroy: |
| 180 | wlan_objmgr_pdev_obj_delete(pdev); |
Arunk Khandavalli | a6305a3 | 2018-01-25 11:19:18 +0530 | [diff] [blame] | 181 | free_priv: |
Dustin Brown | b277dd6 | 2018-01-26 15:17:33 -0800 | [diff] [blame] | 182 | qdf_mem_free(priv); |
| 183 | |
| 184 | return qdf_status_to_os_return(status); |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 185 | } |
| 186 | |
Jeff Johnson | 72a1798 | 2017-08-28 11:49:53 -0700 | [diff] [blame] | 187 | int hdd_objmgr_release_and_destroy_pdev(struct hdd_context *hdd_ctx) |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 188 | { |
Dustin Brown | b277dd6 | 2018-01-26 15:17:33 -0800 | [diff] [blame] | 189 | QDF_STATUS status; |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 190 | struct wlan_objmgr_pdev *pdev = hdd_ctx->hdd_pdev; |
Sandeep Puligilla | fdd201e | 2017-02-02 18:43:46 -0800 | [diff] [blame] | 191 | struct pdev_osif_priv *osif_priv; |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 192 | |
| 193 | hdd_ctx->hdd_pdev = NULL; |
Dustin Brown | b277dd6 | 2018-01-26 15:17:33 -0800 | [diff] [blame] | 194 | |
| 195 | QDF_BUG(pdev); |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 196 | if (!pdev) |
Rajeev Kumar | ecf87ff | 2017-01-13 15:46:07 -0800 | [diff] [blame] | 197 | return -EINVAL; |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 198 | |
Arunk Khandavalli | a6305a3 | 2018-01-25 11:19:18 +0530 | [diff] [blame] | 199 | target_if_free_pdev_tgt_info(pdev); |
Dustin Brown | b277dd6 | 2018-01-26 15:17:33 -0800 | [diff] [blame] | 200 | |
Arunk Khandavalli | a6305a3 | 2018-01-25 11:19:18 +0530 | [diff] [blame] | 201 | hdd_deinit_pdev_os_priv(pdev); |
Jeff Johnson | ae6bb80 | 2017-03-23 13:26:10 -0700 | [diff] [blame] | 202 | osif_priv = wlan_pdev_get_ospriv(pdev); |
| 203 | wlan_pdev_reset_ospriv(pdev); |
Sandeep Puligilla | fdd201e | 2017-02-02 18:43:46 -0800 | [diff] [blame] | 204 | qdf_mem_free(osif_priv); |
| 205 | |
Dustin Brown | b277dd6 | 2018-01-26 15:17:33 -0800 | [diff] [blame] | 206 | 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 Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 210 | } |
| 211 | |
Dustin Brown | 7d043f6 | 2017-03-27 12:07:36 -0700 | [diff] [blame] | 212 | int hdd_objmgr_create_and_store_vdev(struct wlan_objmgr_pdev *pdev, |
Jeff Johnson | e46a84b | 2017-08-29 14:27:58 -0700 | [diff] [blame] | 213 | struct hdd_adapter *adapter) |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 214 | { |
Dustin Brown | f4a6e0f | 2017-11-28 10:03:52 -0800 | [diff] [blame] | 215 | QDF_STATUS status; |
| 216 | int errno; |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 217 | struct wlan_objmgr_vdev *vdev; |
| 218 | struct wlan_objmgr_peer *peer; |
Wu Gao | e960db6 | 2017-03-13 21:00:11 +0800 | [diff] [blame] | 219 | struct vdev_osif_priv *osif_priv; |
Dustin Brown | f4a6e0f | 2017-11-28 10:03:52 -0800 | [diff] [blame] | 220 | struct wlan_vdev_create_params vdev_params = {0}; |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 221 | |
Dustin Brown | f4a6e0f | 2017-11-28 10:03:52 -0800 | [diff] [blame] | 222 | QDF_BUG(pdev); |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 223 | if (!pdev) { |
Dustin Brown | f4a6e0f | 2017-11-28 10:03:52 -0800 | [diff] [blame] | 224 | hdd_err("pdev is null"); |
Rajeev Kumar | deabf3e | 2017-01-13 15:55:05 -0800 | [diff] [blame] | 225 | return -EINVAL; |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 226 | } |
| 227 | |
Wu Gao | e960db6 | 2017-03-13 21:00:11 +0800 | [diff] [blame] | 228 | osif_priv = qdf_mem_malloc(sizeof(*osif_priv)); |
| 229 | if (!osif_priv) { |
Dustin Brown | f4a6e0f | 2017-11-28 10:03:52 -0800 | [diff] [blame] | 230 | hdd_err("Failed to allocate osif_priv; out of memory"); |
Wu Gao | e960db6 | 2017-03-13 21:00:11 +0800 | [diff] [blame] | 231 | return -ENOMEM; |
| 232 | } |
Wu Gao | e960db6 | 2017-03-13 21:00:11 +0800 | [diff] [blame] | 233 | hdd_init_vdev_os_priv(adapter, osif_priv); |
Dustin Brown | f4a6e0f | 2017-11-28 10:03:52 -0800 | [diff] [blame] | 234 | |
| 235 | vdev_params.opmode = adapter->device_mode; |
Wu Gao | e960db6 | 2017-03-13 21:00:11 +0800 | [diff] [blame] | 236 | vdev_params.osifp = osif_priv; |
Dustin Brown | f4a6e0f | 2017-11-28 10:03:52 -0800 | [diff] [blame] | 237 | qdf_mem_copy(vdev_params.macaddr, |
| 238 | adapter->mac_addr.bytes, |
| 239 | QDF_NET_MAC_ADDR_MAX_LEN); |
Wu Gao | e960db6 | 2017-03-13 21:00:11 +0800 | [diff] [blame] | 240 | |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 241 | vdev = wlan_objmgr_vdev_obj_create(pdev, &vdev_params); |
| 242 | if (!vdev) { |
Dustin Brown | f4a6e0f | 2017-11-28 10:03:52 -0800 | [diff] [blame] | 243 | hdd_err("Failed to create vdev object"); |
| 244 | errno = -ENOMEM; |
| 245 | goto osif_priv_free; |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 246 | } |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 247 | |
Dustin Brown | 0d2eeae | 2017-03-24 15:21:32 -0700 | [diff] [blame] | 248 | /* |
| 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 Brown | f4a6e0f | 2017-11-28 10:03:52 -0800 | [diff] [blame] | 251 | * getting a reference here. |
Dustin Brown | 0d2eeae | 2017-03-24 15:21:32 -0700 | [diff] [blame] | 252 | */ |
Dustin Brown | f4a6e0f | 2017-11-28 10:03:52 -0800 | [diff] [blame] | 253 | 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 Brown | 0d2eeae | 2017-03-24 15:21:32 -0700 | [diff] [blame] | 268 | |
Selvaraj, Sridhar | 3a1823f | 2017-02-01 17:32:21 +0530 | [diff] [blame] | 269 | adapter->hdd_vdev = vdev; |
Jeff Johnson | 1b780e4 | 2017-10-31 14:11:45 -0700 | [diff] [blame] | 270 | adapter->session_id = wlan_vdev_get_id(vdev); |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 271 | |
Rajeev Kumar | deabf3e | 2017-01-13 15:55:05 -0800 | [diff] [blame] | 272 | return 0; |
Dustin Brown | f4a6e0f | 2017-11-28 10:03:52 -0800 | [diff] [blame] | 273 | |
| 274 | vdev_put_ref: |
| 275 | wlan_objmgr_vdev_release_ref(vdev, WLAN_HDD_ID_OBJ_MGR); |
| 276 | |
| 277 | vdev_destroy: |
| 278 | wlan_objmgr_vdev_obj_delete(vdev); |
| 279 | |
| 280 | osif_priv_free: |
| 281 | qdf_mem_free(osif_priv); |
| 282 | |
| 283 | return errno; |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 284 | } |
| 285 | |
Dustin Brown | b277dd6 | 2018-01-26 15:17:33 -0800 | [diff] [blame] | 286 | int hdd_objmgr_release_and_destroy_vdev(struct hdd_adapter *adapter) |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 287 | { |
Dustin Brown | b277dd6 | 2018-01-26 15:17:33 -0800 | [diff] [blame] | 288 | QDF_STATUS status; |
| 289 | struct wlan_objmgr_vdev *vdev = adapter->hdd_vdev; |
Wu Gao | e960db6 | 2017-03-13 21:00:11 +0800 | [diff] [blame] | 290 | struct vdev_osif_priv *osif_priv; |
Dustin Brown | b277dd6 | 2018-01-26 15:17:33 -0800 | [diff] [blame] | 291 | uint8_t *self_mac_addr; |
Dustin Brown | 0d2eeae | 2017-03-24 15:21:32 -0700 | [diff] [blame] | 292 | |
| 293 | adapter->hdd_vdev = NULL; |
Jeff Johnson | 1b780e4 | 2017-10-31 14:11:45 -0700 | [diff] [blame] | 294 | adapter->session_id = HDD_SESSION_ID_INVALID; |
Dustin Brown | 0d2eeae | 2017-03-24 15:21:32 -0700 | [diff] [blame] | 295 | |
Dustin Brown | b277dd6 | 2018-01-26 15:17:33 -0800 | [diff] [blame] | 296 | QDF_BUG(vdev); |
| 297 | if (!vdev) |
| 298 | return -EINVAL; |
Dustin Brown | 0d2eeae | 2017-03-24 15:21:32 -0700 | [diff] [blame] | 299 | |
Dustin Brown | b277dd6 | 2018-01-26 15:17:33 -0800 | [diff] [blame] | 300 | osif_priv = wlan_vdev_get_ospriv(vdev); |
| 301 | wlan_vdev_reset_ospriv(vdev); |
Dustin Brown | 0d2eeae | 2017-03-24 15:21:32 -0700 | [diff] [blame] | 302 | |
Dustin Brown | b277dd6 | 2018-01-26 15:17:33 -0800 | [diff] [blame] | 303 | QDF_BUG(osif_priv); |
| 304 | if (osif_priv) { |
| 305 | wlan_cfg80211_tdls_priv_deinit(osif_priv); |
| 306 | qdf_mem_free(osif_priv); |
| 307 | } |
Dustin Brown | 0d2eeae | 2017-03-24 15:21:32 -0700 | [diff] [blame] | 308 | |
Dustin Brown | b277dd6 | 2018-01-26 15:17:33 -0800 | [diff] [blame] | 309 | 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 Brown | 0d2eeae | 2017-03-24 15:21:32 -0700 | [diff] [blame] | 317 | } |
| 318 | |
Dustin Brown | 7d043f6 | 2017-03-27 12:07:36 -0700 | [diff] [blame] | 319 | int hdd_objmgr_add_peer_object(struct wlan_objmgr_vdev *vdev, |
Jeff Johnson | c1e6278 | 2017-11-09 09:50:17 -0800 | [diff] [blame] | 320 | enum QDF_OPMODE adapter_mode, |
Rachit Kankane | 2487f8f | 2017-04-19 14:30:19 +0530 | [diff] [blame] | 321 | uint8_t *mac_addr, |
| 322 | bool is_p2p_type) |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 323 | { |
| 324 | enum wlan_peer_type peer_type; |
Selvaraj, Sridhar | d761f25 | 2017-01-19 13:08:39 +0530 | [diff] [blame] | 325 | struct wlan_objmgr_peer *peer; |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 326 | |
| 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 Kankane | 2487f8f | 2017-04-19 14:30:19 +0530 | [diff] [blame] | 332 | if (is_p2p_type) { |
| 333 | peer_type = WLAN_PEER_P2P_CLI; |
| 334 | } else { |
| 335 | peer_type = WLAN_PEER_STA; |
| 336 | } |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 337 | } else if (adapter_mode == QDF_IBSS_MODE) { |
| 338 | peer_type = WLAN_PEER_IBSS; |
Naveen Rawat | 95eb406 | 2017-11-02 16:46:41 -0700 | [diff] [blame] | 339 | } else if (adapter_mode == QDF_NDI_MODE) { |
| 340 | peer_type = WLAN_PEER_NDP; |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 341 | } else { |
| 342 | hdd_err("Unsupported device mode %d", adapter_mode); |
Rajeev Kumar | 7842768 | 2017-01-13 16:13:11 -0800 | [diff] [blame] | 343 | return -EINVAL; |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | if (!vdev) { |
| 347 | hdd_err("vdev NULL"); |
| 348 | QDF_ASSERT(0); |
Rajeev Kumar | 7842768 | 2017-01-13 16:13:11 -0800 | [diff] [blame] | 349 | return -EFAULT; |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 350 | } |
| 351 | |
Selvaraj, Sridhar | d761f25 | 2017-01-19 13:08:39 +0530 | [diff] [blame] | 352 | peer = wlan_objmgr_peer_obj_create(vdev, peer_type, mac_addr); |
| 353 | if (!peer) |
Rajeev Kumar | 7842768 | 2017-01-13 16:13:11 -0800 | [diff] [blame] | 354 | return -ENOMEM; |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 355 | |
Kiran Kumar Lokere | 1d411bb | 2017-11-29 15:24:05 -0800 | [diff] [blame] | 356 | hdd_debug("Peer object "MAC_ADDRESS_STR" add success! Type: %d", |
Rachit Kankane | 2487f8f | 2017-04-19 14:30:19 +0530 | [diff] [blame] | 357 | MAC_ADDR_ARRAY(mac_addr), peer_type); |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 358 | |
Rajeev Kumar | 7842768 | 2017-01-13 16:13:11 -0800 | [diff] [blame] | 359 | return 0; |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 360 | } |
| 361 | |
Dustin Brown | 7d043f6 | 2017-03-27 12:07:36 -0700 | [diff] [blame] | 362 | int hdd_objmgr_remove_peer_object(struct wlan_objmgr_vdev *vdev, |
| 363 | uint8_t *mac_addr) |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 364 | { |
| 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 Kumar | dfa3707 | 2017-01-13 16:27:22 -0800 | [diff] [blame] | 371 | return -EINVAL; |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | psoc = wlan_vdev_get_psoc(vdev); |
| 375 | if (!psoc) { |
| 376 | hdd_err("Psoc NUll"); |
| 377 | QDF_ASSERT(0); |
Rajeev Kumar | dfa3707 | 2017-01-13 16:27:22 -0800 | [diff] [blame] | 378 | return -EINVAL; |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 379 | } |
| 380 | |
Selvaraj, Sridhar | 3a1823f | 2017-02-01 17:32:21 +0530 | [diff] [blame] | 381 | peer = wlan_objmgr_get_peer(psoc, mac_addr, WLAN_HDD_ID_OBJ_MGR); |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 382 | if (peer) { |
wadesong | db4d958 | 2017-12-20 15:28:34 +0800 | [diff] [blame] | 383 | wlan_objmgr_peer_obj_delete(peer); |
| 384 | |
Selvaraj, Sridhar | d761f25 | 2017-01-19 13:08:39 +0530 | [diff] [blame] | 385 | /* Unref to decrement ref happened in find_peer */ |
Selvaraj, Sridhar | 3a1823f | 2017-02-01 17:32:21 +0530 | [diff] [blame] | 386 | wlan_objmgr_peer_release_ref(peer, WLAN_HDD_ID_OBJ_MGR); |
Selvaraj, Sridhar | d761f25 | 2017-01-19 13:08:39 +0530 | [diff] [blame] | 387 | |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 388 | hdd_info("Peer obj "MAC_ADDRESS_STR" deleted", |
| 389 | MAC_ADDR_ARRAY(mac_addr)); |
Rajeev Kumar | dfa3707 | 2017-01-13 16:27:22 -0800 | [diff] [blame] | 390 | return 0; |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | hdd_err("Peer obj "MAC_ADDRESS_STR" not found", |
| 394 | MAC_ADDR_ARRAY(mac_addr)); |
| 395 | |
Rajeev Kumar | dfa3707 | 2017-01-13 16:27:22 -0800 | [diff] [blame] | 396 | return -EINVAL; |
Rajeev Kumar | 699debf | 2017-01-06 14:17:00 -0800 | [diff] [blame] | 397 | } |
Mukul Sharma | 5678be4 | 2017-01-24 12:20:01 +0530 | [diff] [blame] | 398 | |
Kabilan Kannan | f56f9d5 | 2017-04-05 03:31:34 -0700 | [diff] [blame] | 399 | int 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 Brown | 7d043f6 | 2017-03-27 12:07:36 -0700 | [diff] [blame] | 426 | int hdd_objmgr_set_peer_mlme_state(struct wlan_objmgr_vdev *vdev, |
Kabilan Kannan | f56f9d5 | 2017-04-05 03:31:34 -0700 | [diff] [blame] | 427 | enum wlan_peer_state peer_state) |
Mukul Sharma | 5678be4 | 2017-01-24 12:20:01 +0530 | [diff] [blame] | 428 | { |
| 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 Johnson | 6875531 | 2017-02-10 11:46:55 -0800 | [diff] [blame] | 435 | if (!peer) { |
Mukul Sharma | 5678be4 | 2017-01-24 12:20:01 +0530 | [diff] [blame] | 436 | hdd_err("peer is null"); |
Jeff Johnson | 6875531 | 2017-02-10 11:46:55 -0800 | [diff] [blame] | 437 | |
Mukul Sharma | 5678be4 | 2017-01-24 12:20:01 +0530 | [diff] [blame] | 438 | return -EINVAL; |
| 439 | } |
| 440 | |
Jeff Johnson | 6875531 | 2017-02-10 11:46:55 -0800 | [diff] [blame] | 441 | 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 Sharma | 5678be4 | 2017-01-24 12:20:01 +0530 | [diff] [blame] | 446 | } |
| 447 | |