1 /* 2 * Copyright (c) 2017-2019 The Linux Foundation. All rights reserved. 3 * 4 * 5 * Permission to use, copy, modify, and/or distribute this software for 6 * any purpose with or without fee is hereby granted, provided that the 7 * above copyright notice and this permission notice appear in all 8 * copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 11 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 12 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 13 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 14 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 15 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 16 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 17 * PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20 /** 21 * DOC: target_if_reg.c 22 * This file contains regulatory target interfaces. 23 */ 24 25 #include <wmi_unified_api.h> 26 #include <reg_services_public_struct.h> 27 #include <wlan_reg_tgt_api.h> 28 #include <target_if.h> 29 #include <target_if_reg.h> 30 #include <wmi_unified_reg_api.h> 31 #include <qdf_platform.h> 32 #include <target_if_reg_11d.h> 33 #include <target_if_reg_lte.h> 34 #include <wlan_reg_ucfg_api.h> 35 36 /** 37 * get_chan_list_cc_event_id() - Get chan_list_cc event i 38 * 39 * Return: Event id 40 */ 41 static inline uint32_t get_chan_list_cc_event_id(void) 42 { 43 return wmi_reg_chan_list_cc_event_id; 44 } 45 46 /** 47 * tgt_if_regulatory_is_regdb_offloaded() - Check if regdb is offloaded 48 * @psoc: Pointer to psoc 49 * 50 * Return: true if regdb if offloaded, else false 51 */ 52 static bool tgt_if_regulatory_is_regdb_offloaded(struct wlan_objmgr_psoc *psoc) 53 { 54 wmi_unified_t wmi_handle = get_wmi_unified_hdl_from_psoc(psoc); 55 56 if (!wmi_handle) 57 return false; 58 59 return wmi_service_enabled(wmi_handle, wmi_service_regulatory_db); 60 } 61 62 /** 63 * tgt_if_regulatory_is_there_serv_ready_extn() - Check for service ready 64 * extension 65 * @psoc: Pointer to psoc object 66 * 67 * Return: true if service ready extension is present, else false. 68 */ 69 static bool tgt_if_regulatory_is_there_serv_ready_extn( 70 struct wlan_objmgr_psoc *psoc) 71 { 72 wmi_unified_t wmi_handle = get_wmi_unified_hdl_from_psoc(psoc); 73 74 if (!wmi_handle) 75 return false; 76 77 return wmi_service_enabled(wmi_handle, wmi_service_ext_msg); 78 } 79 80 /** 81 * target_if_regulatory_get_rx_ops() - Get regdb rx ops 82 * @psoc: Pointer to psoc object 83 * 84 * Return: Reg rx_ops 85 */ 86 struct wlan_lmac_if_reg_rx_ops * 87 target_if_regulatory_get_rx_ops(struct wlan_objmgr_psoc *psoc) 88 { 89 return &psoc->soc_cb.rx_ops.reg_rx_ops; 90 } 91 92 QDF_STATUS target_if_reg_set_offloaded_info(struct wlan_objmgr_psoc *psoc) 93 { 94 struct wlan_lmac_if_reg_rx_ops *reg_rx_ops; 95 96 reg_rx_ops = target_if_regulatory_get_rx_ops(psoc); 97 if (!reg_rx_ops) { 98 target_if_err("reg_rx_ops is NULL"); 99 return QDF_STATUS_E_FAILURE; 100 } 101 102 if (reg_rx_ops->reg_set_regdb_offloaded) 103 reg_rx_ops->reg_set_regdb_offloaded( 104 psoc, 105 tgt_if_regulatory_is_regdb_offloaded(psoc)); 106 107 if (reg_rx_ops->reg_set_11d_offloaded) 108 reg_rx_ops->reg_set_11d_offloaded( 109 psoc, tgt_if_regulatory_is_11d_offloaded(psoc)); 110 111 return QDF_STATUS_SUCCESS; 112 } 113 114 /** 115 * tgt_reg_chan_list_update_handler() - Channel list update handler 116 * @handle: scn handle 117 * @event_buf: pointer to event buffer 118 * @len: buffer length 119 * 120 * Return: 0 on success 121 */ 122 static int tgt_reg_chan_list_update_handler(ol_scn_t handle, uint8_t *event_buf, 123 uint32_t len) 124 { 125 struct wlan_objmgr_psoc *psoc; 126 struct wlan_lmac_if_reg_rx_ops *reg_rx_ops; 127 struct cur_regulatory_info *reg_info; 128 QDF_STATUS status; 129 struct wmi_unified *wmi_handle; 130 int ret_val = 0; 131 132 TARGET_IF_ENTER(); 133 134 psoc = target_if_get_psoc_from_scn_hdl(handle); 135 if (!psoc) { 136 target_if_err("psoc ptr is NULL"); 137 return -EINVAL; 138 } 139 140 reg_rx_ops = target_if_regulatory_get_rx_ops(psoc); 141 if (!reg_rx_ops->master_list_handler) { 142 target_if_err("master_list_handler is NULL"); 143 return -EINVAL; 144 } 145 146 wmi_handle = get_wmi_unified_hdl_from_psoc(psoc); 147 if (!wmi_handle) { 148 target_if_err("invalid wmi handle"); 149 return -EINVAL; 150 } 151 152 reg_info = qdf_mem_malloc(sizeof(*reg_info)); 153 if (!reg_info) { 154 target_if_err("memory allocation failed"); 155 return -ENOMEM; 156 } 157 158 if (wmi_extract_reg_chan_list_update_event(wmi_handle, 159 event_buf, reg_info, len) 160 != QDF_STATUS_SUCCESS) { 161 target_if_err("Extraction of channel list event failed"); 162 ret_val = -EFAULT; 163 goto clean; 164 } 165 166 if (reg_info->phy_id >= PSOC_MAX_PHY_REG_CAP) { 167 target_if_err_rl("phy_id %d is out of bounds", 168 reg_info->phy_id); 169 ret_val = -EFAULT; 170 goto clean; 171 } 172 173 reg_info->psoc = psoc; 174 175 status = reg_rx_ops->master_list_handler(reg_info); 176 if (status != QDF_STATUS_SUCCESS) { 177 target_if_err("Failed to process master channel list handler"); 178 ret_val = -EFAULT; 179 } 180 181 clean: 182 qdf_mem_free(reg_info->reg_rules_2g_ptr); 183 qdf_mem_free(reg_info->reg_rules_5g_ptr); 184 qdf_mem_free(reg_info); 185 186 target_if_debug("processed reg channel list ret_val %d", ret_val); 187 188 return ret_val; 189 } 190 191 /** 192 * tgt_if_regulatory_register_master_list_handler() - Register master channel 193 * list 194 * @psoc: Pointer to psoc 195 * @arg: Pointer to argument list 196 * 197 * Return: QDF_STATUS 198 */ 199 static QDF_STATUS tgt_if_regulatory_register_master_list_handler( 200 struct wlan_objmgr_psoc *psoc, void *arg) 201 { 202 wmi_unified_t wmi_handle = get_wmi_unified_hdl_from_psoc(psoc); 203 204 if (!wmi_handle) 205 return QDF_STATUS_E_FAILURE; 206 207 return wmi_unified_register_event_handler( 208 wmi_handle, wmi_reg_chan_list_cc_event_id, 209 tgt_reg_chan_list_update_handler, WMI_RX_UMAC_CTX); 210 } 211 212 /** 213 * tgt_if_regulatory_unregister_master_list_handler() - Unregister master 214 * channel list 215 * @psoc: Pointer to psoc 216 * @arg: Pointer to argument list 217 * 218 * Return: QDF_STATUS 219 */ 220 static QDF_STATUS tgt_if_regulatory_unregister_master_list_handler( 221 struct wlan_objmgr_psoc *psoc, void *arg) 222 { 223 wmi_unified_t wmi_handle = get_wmi_unified_hdl_from_psoc(psoc); 224 225 if (!wmi_handle) 226 return QDF_STATUS_E_FAILURE; 227 228 return wmi_unified_unregister_event_handler( 229 wmi_handle, wmi_reg_chan_list_cc_event_id); 230 } 231 232 /** 233 * tgt_if_regulatory_set_country_code() - Set country code 234 * @psoc: Pointer to psoc 235 * @arg: Pointer to argument list 236 * 237 * Return: QDF_STATUS 238 */ 239 static QDF_STATUS tgt_if_regulatory_set_country_code( 240 struct wlan_objmgr_psoc *psoc, void *arg) 241 { 242 wmi_unified_t wmi_handle = get_wmi_unified_hdl_from_psoc(psoc); 243 244 if (!wmi_handle) 245 return QDF_STATUS_E_FAILURE; 246 247 return wmi_unified_set_country_cmd_send(wmi_handle, arg); 248 } 249 250 /** 251 * tgt_if_regulatory_set_user_country_code() - Set user country code 252 * @psoc: Pointer to psoc 253 * @pdev_id: Pdev id 254 * @rd: Pointer to regdomain structure 255 * 256 * Return: QDF_STATUS 257 */ 258 static QDF_STATUS tgt_if_regulatory_set_user_country_code( 259 struct wlan_objmgr_psoc *psoc, uint8_t pdev_id, struct cc_regdmn_s *rd) 260 { 261 wmi_unified_t wmi_handle = get_wmi_unified_hdl_from_psoc(psoc); 262 263 if (!wmi_handle) 264 return QDF_STATUS_E_FAILURE; 265 266 if (wmi_unified_set_user_country_code_cmd_send( 267 wmi_handle, pdev_id, rd) != QDF_STATUS_SUCCESS 268 ) { 269 target_if_err("Set user country code failed"); 270 return QDF_STATUS_E_FAILURE; 271 } 272 273 return QDF_STATUS_SUCCESS; 274 } 275 276 QDF_STATUS tgt_if_regulatory_modify_freq_range(struct wlan_objmgr_psoc *psoc) 277 { 278 struct wlan_psoc_host_hal_reg_capabilities_ext *reg_cap; 279 280 reg_cap = ucfg_reg_get_hal_reg_cap(psoc); 281 if (!reg_cap) { 282 target_if_err("reg cap is NULL"); 283 return QDF_STATUS_E_FAILURE; 284 } 285 286 if (!(reg_cap->wireless_modes & WMI_HOST_REGDMN_MODE_11A)) { 287 reg_cap->low_5ghz_chan = 0; 288 reg_cap->high_5ghz_chan = 0; 289 } 290 291 if (!(reg_cap->wireless_modes & 292 (WMI_HOST_REGDMN_MODE_11B | WMI_HOST_REGDMN_MODE_PUREG))) { 293 reg_cap->low_2ghz_chan = 0; 294 reg_cap->high_2ghz_chan = 0; 295 } 296 297 target_if_debug("phy_id = %d - low_2ghz_chan = %d high_2ghz_chan = %d low_5ghz_chan = %d high_5ghz_chan = %d", 298 reg_cap->phy_id, 299 reg_cap->low_2ghz_chan, 300 reg_cap->high_2ghz_chan, 301 reg_cap->low_5ghz_chan, 302 reg_cap->high_5ghz_chan); 303 304 return QDF_STATUS_SUCCESS; 305 } 306 307 QDF_STATUS target_if_register_regulatory_tx_ops( 308 struct wlan_lmac_if_tx_ops *tx_ops) 309 { 310 struct wlan_lmac_if_reg_tx_ops *reg_ops = &tx_ops->reg_ops; 311 312 reg_ops->register_master_handler = 313 tgt_if_regulatory_register_master_list_handler; 314 315 reg_ops->unregister_master_handler = 316 tgt_if_regulatory_unregister_master_list_handler; 317 318 reg_ops->set_country_code = tgt_if_regulatory_set_country_code; 319 320 reg_ops->fill_umac_legacy_chanlist = NULL; 321 322 reg_ops->set_country_failed = NULL; 323 324 reg_ops->register_11d_new_cc_handler = 325 tgt_if_regulatory_register_11d_new_cc_handler; 326 327 reg_ops->unregister_11d_new_cc_handler = 328 tgt_if_regulatory_unregister_11d_new_cc_handler; 329 330 reg_ops->start_11d_scan = tgt_if_regulatory_start_11d_scan; 331 332 reg_ops->stop_11d_scan = tgt_if_regulatory_stop_11d_scan; 333 334 reg_ops->is_there_serv_ready_extn = 335 tgt_if_regulatory_is_there_serv_ready_extn; 336 337 reg_ops->set_user_country_code = 338 tgt_if_regulatory_set_user_country_code; 339 340 reg_ops->register_ch_avoid_event_handler = 341 tgt_if_regulatory_register_ch_avoid_event_handler; 342 343 reg_ops->unregister_ch_avoid_event_handler = 344 tgt_if_regulatory_unregister_ch_avoid_event_handler; 345 346 return QDF_STATUS_SUCCESS; 347 } 348