/**
 *  @brief MLAN uap ioctl handler
 *
 *  @param adapter	A pointer to mlan_adapter structure
 *  @param pioctl_req	A pointer to ioctl request buffer
 *
 *  @return		MLAN_STATUS_SUCCESS --success, otherwise fail
 */
mlan_status
wlan_ops_uap_ioctl(t_void * adapter, pmlan_ioctl_req pioctl_req)
{
    pmlan_adapter pmadapter = (pmlan_adapter) adapter;
    mlan_status status = MLAN_STATUS_SUCCESS;
    mlan_ds_bss *bss = MNULL;
    mlan_ds_get_info *pget_info = MNULL;
    mlan_ds_misc_cfg *misc = MNULL;
    mlan_ds_sec_cfg *sec = MNULL;
    mlan_ds_pm_cfg *pm = MNULL;
    mlan_ds_snmp_mib *snmp = MNULL;
    mlan_ds_11d_cfg *cfg11d = MNULL;
    mlan_ds_11h_cfg *cfg11h = MNULL;
    mlan_ds_radio_cfg *radiocfg = MNULL;
    mlan_ds_rate *rate = MNULL;
    mlan_private *pmpriv = pmadapter->priv[pioctl_req->bss_index];

    ENTER();

    switch (pioctl_req->req_id) {
    case MLAN_IOCTL_BSS:
        bss = (mlan_ds_bss *) pioctl_req->pbuf;
        if (bss->sub_command == MLAN_OID_BSS_MAC_ADDR)
            status = wlan_uap_bss_ioctl_mac_address(pmadapter, pioctl_req);
        else if (bss->sub_command == MLAN_OID_BSS_STOP)
            status = wlan_uap_bss_ioctl_stop(pmadapter, pioctl_req);
        else if (bss->sub_command == MLAN_OID_BSS_START)
            status = wlan_uap_bss_ioctl_start(pmadapter, pioctl_req);
        else if (bss->sub_command == MLAN_OID_UAP_BSS_CONFIG)
            status = wlan_uap_bss_ioctl_config(pmadapter, pioctl_req);
        else if (bss->sub_command == MLAN_OID_UAP_DEAUTH_STA)
            status = wlan_uap_bss_ioctl_deauth_sta(pmadapter, pioctl_req);
        else if (bss->sub_command == MLAN_OID_UAP_BSS_RESET)
            status = wlan_uap_bss_ioctl_reset(pmadapter, pioctl_req);
#if defined(STA_SUPPORT) && defined(UAP_SUPPORT)
        else if (bss->sub_command == MLAN_OID_BSS_ROLE)
            status = wlan_bss_ioctl_bss_role(pmadapter, pioctl_req);
#endif
#ifdef WIFI_DIRECT_SUPPORT
        else if (bss->sub_command == MLAN_OID_WIFI_DIRECT_MODE)
            status = wlan_bss_ioctl_wifi_direct_mode(pmadapter, pioctl_req);
#endif
        break;
    case MLAN_IOCTL_GET_INFO:
        pget_info = (mlan_ds_get_info *) pioctl_req->pbuf;
        if (pget_info->sub_command == MLAN_OID_GET_VER_EXT)
            status = wlan_get_info_ver_ext(pmadapter, pioctl_req);
        else if (pget_info->sub_command == MLAN_OID_GET_DEBUG_INFO)
            status = wlan_get_info_debug_info(pmadapter, pioctl_req);
        else if (pget_info->sub_command == MLAN_OID_GET_STATS)
            status = wlan_uap_get_stats(pmadapter, pioctl_req);
        else if (pget_info->sub_command == MLAN_OID_UAP_STA_LIST)
            status = wlan_uap_get_sta_list(pmadapter, pioctl_req);
        else if (pget_info->sub_command == MLAN_OID_GET_BSS_INFO)
            status = wlan_uap_get_bss_info(pmadapter, pioctl_req);
        else if (pget_info->sub_command == MLAN_OID_GET_FW_INFO) {
            pioctl_req->data_read_written =
                sizeof(mlan_fw_info) + MLAN_SUB_COMMAND_SIZE;
            memcpy(pmadapter, &pget_info->param.fw_info.mac_addr,
                   pmpriv->curr_addr, MLAN_MAC_ADDR_LENGTH);
            pget_info->param.fw_info.fw_ver = pmadapter->fw_release_number;
            pget_info->param.fw_info.fw_bands = pmadapter->fw_bands;
            pget_info->param.fw_info.hw_dev_mcs_support =
                pmadapter->hw_dev_mcs_support;
        }
        break;
    case MLAN_IOCTL_MISC_CFG:
        misc = (mlan_ds_misc_cfg *) pioctl_req->pbuf;
        if (misc->sub_command == MLAN_OID_MISC_INIT_SHUTDOWN)
            status = wlan_misc_ioctl_init_shutdown(pmadapter, pioctl_req);
        if (misc->sub_command == MLAN_OID_MISC_SOFT_RESET)
            status = wlan_uap_misc_ioctl_soft_reset(pmadapter, pioctl_req);
        if (misc->sub_command == MLAN_OID_MISC_HOST_CMD)
            status = wlan_misc_ioctl_host_cmd(pmadapter, pioctl_req);
        if (misc->sub_command == MLAN_OID_MISC_GEN_IE)
            status = wlan_uap_misc_ioctl_gen_ie(pmadapter, pioctl_req);
        if (misc->sub_command == MLAN_OID_MISC_CUSTOM_IE)
            status =
                wlan_misc_ioctl_custom_ie_list(pmadapter, pioctl_req, MTRUE);
        if (misc->sub_command == MLAN_OID_MISC_TX_DATAPAUSE)
            status = wlan_uap_misc_ioctl_txdatapause(pmadapter, pioctl_req);
        if (misc->sub_command == MLAN_OID_MISC_RX_MGMT_IND)
            status = wlan_reg_rx_mgmt_ind(pmadapter, pioctl_req);
#ifdef DEBUG_LEVEL1
        if (misc->sub_command == MLAN_OID_MISC_DRVDBG)
            status = wlan_set_drvdbg(pmadapter, pioctl_req);
#endif
        break;
    case MLAN_IOCTL_PM_CFG:
        pm = (mlan_ds_pm_cfg *) pioctl_req->pbuf;
        if (pm->sub_command == MLAN_OID_PM_CFG_PS_MODE)
            status = wlan_uap_pm_ioctl_mode(pmadapter, pioctl_req);
        if (pm->sub_command == MLAN_OID_PM_CFG_DEEP_SLEEP)
            status = wlan_uap_pm_ioctl_deepsleep(pmadapter, pioctl_req);
        if (pm->sub_command == MLAN_OID_PM_CFG_HS_CFG) {
            status = wlan_pm_ioctl_hscfg(pmadapter, pioctl_req);
        }
        if (pm->sub_command == MLAN_OID_PM_INFO) {
            status = wlan_get_pm_info(pmadapter, pioctl_req);
        }
        break;
    case MLAN_IOCTL_SNMP_MIB:
        snmp = (mlan_ds_snmp_mib *) pioctl_req->pbuf;
        if (snmp->sub_command == MLAN_OID_SNMP_MIB_DOT11D)
            status = wlan_uap_snmp_mib_11d(pmadapter, pioctl_req);
        if (snmp->sub_command == MLAN_OID_SNMP_MIB_DOT11H)
            status = wlan_uap_snmp_mib_11h(pmadapter, pioctl_req);
        break;
    case MLAN_IOCTL_SEC_CFG:
        sec = (mlan_ds_sec_cfg *) pioctl_req->pbuf;
        if (sec->sub_command == MLAN_OID_SEC_CFG_ENCRYPT_KEY)
            status = wlan_uap_sec_ioctl_set_encrypt_key(pmadapter, pioctl_req);
        if (sec->sub_command == MLAN_OID_SEC_CFG_WAPI_ENABLED)
            status = wlan_uap_sec_ioctl_wapi_enable(pmadapter, pioctl_req);
        break;
    case MLAN_IOCTL_11N_CFG:
        status = wlan_11n_cfg_ioctl(pmadapter, pioctl_req);
        break;
    case MLAN_IOCTL_11D_CFG:
        cfg11d = (mlan_ds_11d_cfg *) pioctl_req->pbuf;
        if (cfg11d->sub_command == MLAN_OID_11D_DOMAIN_INFO)
            status = wlan_uap_domain_info(pmadapter, pioctl_req);
        break;
    case MLAN_IOCTL_11H_CFG:
        cfg11h = (mlan_ds_11h_cfg *) pioctl_req->pbuf;
        if (cfg11h->sub_command == MLAN_OID_11H_CHANNEL_CHECK)
            status = wlan_uap_11h_channel_check_req(pmadapter, pioctl_req);
#if defined(DFS_TESTING_SUPPORT)
        if (cfg11h->sub_command == MLAN_OID_11H_DFS_TESTING)
            status = wlan_11h_ioctl_dfs_testing(pmadapter, pioctl_req);
#endif
        break;
    case MLAN_IOCTL_RADIO_CFG:
        radiocfg = (mlan_ds_radio_cfg *) pioctl_req->pbuf;
        if (radiocfg->sub_command == MLAN_OID_RADIO_CTRL)
            status = wlan_radio_ioctl_radio_ctl(pmadapter, pioctl_req);
#ifdef WIFI_DIRECT_SUPPORT
        if (radiocfg->sub_command == MLAN_OID_REMAIN_CHAN_CFG)
            status = wlan_radio_ioctl_remain_chan_cfg(pmadapter, pioctl_req);
#endif
        if (radiocfg->sub_command == MLAN_OID_ANT_CFG)
            status = wlan_radio_ioctl_ant_cfg(pmadapter, pioctl_req);
        break;
    case MLAN_IOCTL_RATE:
        rate = (mlan_ds_rate *) pioctl_req->pbuf;
        if (rate->sub_command == MLAN_OID_RATE_CFG)
            status = wlan_rate_ioctl_cfg(pmadapter, pioctl_req);
        break;
    default:
        pioctl_req->status_code = MLAN_ERROR_IOCTL_INVALID;
        break;
    }
    LEAVE();
    return status;
}
/** 
 *  @brief MLAN uap ioctl handler
 *
 *  @param adapter	A pointer to mlan_adapter structure
 *  @param pioctl_req	A pointer to ioctl request buffer
 *
 *  @return		MLAN_STATUS_SUCCESS --success, otherwise fail
 */
mlan_status
mlan_uap_ioctl(t_void * adapter, pmlan_ioctl_req pioctl_req)
{
    pmlan_adapter pmadapter = (pmlan_adapter) adapter;
    mlan_status status = MLAN_STATUS_SUCCESS;
    mlan_ds_bss *bss = MNULL;
    mlan_ds_get_info *pget_info = MNULL;
    mlan_ds_misc_cfg *misc = MNULL;
    mlan_ds_sec_cfg *sec = MNULL;
    mlan_ds_pm_cfg *pm = MNULL;
    mlan_private *pmpriv = pmadapter->priv[pioctl_req->bss_num];

    ENTER();

    switch (pioctl_req->req_id) {
    case MLAN_IOCTL_BSS:
        bss = (mlan_ds_bss *) pioctl_req->pbuf;
        if (bss->sub_command == MLAN_OID_BSS_MAC_ADDR)
            status = wlan_uap_bss_ioctl_mac_address(pmadapter, pioctl_req);
        else if (bss->sub_command == MLAN_OID_BSS_STOP)
            status = wlan_uap_bss_ioctl_stop(pmadapter, pioctl_req);
        else if (bss->sub_command == MLAN_OID_BSS_START)
            status = wlan_uap_bss_ioctl_start(pmadapter, pioctl_req);
        else if (bss->sub_command == MLAN_OID_UAP_BSS_CONFIG)
            status = wlan_uap_bss_ioctl_config(pmadapter, pioctl_req);
        else if (bss->sub_command == MLAN_OID_UAP_DEAUTH_STA)
            status = wlan_uap_bss_ioctl_deauth_sta(pmadapter, pioctl_req);
        else if (bss->sub_command == MLAN_OID_UAP_BSS_RESET)
            status = wlan_uap_bss_ioctl_reset(pmadapter, pioctl_req);
        break;
    case MLAN_IOCTL_GET_INFO:
        pget_info = (mlan_ds_get_info *) pioctl_req->pbuf;
        if (pget_info->sub_command == MLAN_OID_GET_VER_EXT)
            status = wlan_uap_get_info_ver_ext(pmadapter, pioctl_req);
        else if (pget_info->sub_command == MLAN_OID_GET_DEBUG_INFO)
            status = wlan_get_info_debug_info(pmadapter, pioctl_req);
        else if (pget_info->sub_command == MLAN_OID_GET_STATS)
            status = wlan_uap_get_stats(pmadapter, pioctl_req);
        else if (pget_info->sub_command == MLAN_OID_UAP_STA_LIST)
            status = wlan_uap_get_sta_list(pmadapter, pioctl_req);
        else if (pget_info->sub_command == MLAN_OID_GET_BSS_INFO)
            status = wlan_uap_get_bss_info(pmadapter, pioctl_req);
        else if (pget_info->sub_command == MLAN_OID_GET_FW_INFO) {
            pioctl_req->data_read_written =
                sizeof(mlan_fw_info) + MLAN_SUB_COMMAND_SIZE;
            memcpy(pmadapter, &pget_info->param.fw_info.mac_addr,
                   pmpriv->curr_addr, MLAN_MAC_ADDR_LENGTH);
            pget_info->param.fw_info.fw_ver = pmadapter->fw_release_number;
        }
        break;
    case MLAN_IOCTL_MISC_CFG:
        misc = (mlan_ds_misc_cfg *) pioctl_req->pbuf;
        if (misc->sub_command == MLAN_OID_MISC_INIT_SHUTDOWN)
            status = wlan_misc_ioctl_init_shutdown(pmadapter, pioctl_req);
        if (misc->sub_command == MLAN_OID_MISC_SOFT_RESET)
            status = wlan_uap_misc_ioctl_soft_reset(pmadapter, pioctl_req);
        if (misc->sub_command == MLAN_OID_MISC_HOST_CMD)
            status = wlan_misc_ioctl_host_cmd(pmadapter, pioctl_req);
        if (misc->sub_command == MLAN_OID_MISC_GEN_IE)
            status = wlan_uap_misc_ioctl_gen_ie(pmadapter, pioctl_req);
        if (misc->sub_command == MLAN_OID_MISC_CUSTOM_IE)
            status = wlan_misc_ioctl_custom_ie_list(pmadapter, pioctl_req);
        break;
    case MLAN_IOCTL_PM_CFG:
        pm = (mlan_ds_pm_cfg *) pioctl_req->pbuf;
        if (pm->sub_command == MLAN_OID_PM_CFG_PS_MODE)
            status = wlan_uap_pm_ioctl_mode(pmadapter, pioctl_req);
        if (pm->sub_command == MLAN_OID_PM_CFG_DEEP_SLEEP)
            status = wlan_uap_pm_ioctl_deepsleep(pmadapter, pioctl_req);
        if (pm->sub_command == MLAN_OID_PM_CFG_HS_CFG) {
            status = wlan_pm_ioctl_hscfg(pmadapter, pioctl_req);
        }
        if (pm->sub_command == MLAN_OID_PM_INFO) {
            status = wlan_get_pm_info(pmadapter, pioctl_req);
        }
        break;

    case MLAN_IOCTL_SEC_CFG:
        sec = (mlan_ds_sec_cfg *) pioctl_req->pbuf;
        if (sec->sub_command == MLAN_OID_SEC_CFG_ENCRYPT_KEY)
            status = wlan_uap_sec_ioctl_set_encrypt_key(pmadapter, pioctl_req);
        if (sec->sub_command == MLAN_OID_SEC_CFG_WAPI_ENABLED)
            status = wlan_uap_sec_ioctl_wapi_enable(pmadapter, pioctl_req);
        break;
    case MLAN_IOCTL_11N_CFG:
        status = wlan_11n_cfg_ioctl(pmadapter, pioctl_req);
        break;

    default:
        break;
    }
    LEAVE();
    return status;
}