rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | /* Copyright Statement: |
| 2 | * |
| 3 | * This software/firmware and related documentation ("MediaTek Software") are |
| 4 | * protected under relevant copyright laws. The information contained herein |
| 5 | * is confidential and proprietary to MediaTek Inc. and/or its licensors. |
| 6 | * Without the prior written permission of MediaTek inc. and/or its licensors, |
| 7 | * any reproduction, modification, use or disclosure of MediaTek Software, |
| 8 | * and information contained herein, in whole or in part, shall be strictly prohibited. |
| 9 | * |
| 10 | * MediaTek Inc. (C) 2016. All rights reserved. |
| 11 | * |
| 12 | * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES |
| 13 | * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE") |
| 14 | * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON |
| 15 | * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES, |
| 16 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF |
| 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT. |
| 18 | * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE |
| 19 | * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR |
| 20 | * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH |
| 21 | * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES |
| 22 | * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES |
| 23 | * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK |
| 24 | * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR |
| 25 | * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND |
| 26 | * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE, |
| 27 | * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE, |
| 28 | * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO |
| 29 | * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. |
| 30 | * |
| 31 | * The following software/firmware and/or related documentation ("MediaTek Software") |
| 32 | * have been modified by MediaTek Inc. All revisions are subject to any receiver's |
| 33 | * applicable license agreements with MediaTek Inc. |
| 34 | */ |
| 35 | |
| 36 | #include <string> |
| 37 | #include "WorldPhoneUtil.h" |
| 38 | #include "RatConfiguration.h" |
| 39 | #include "utils.h" |
| 40 | #include "log_extra.h" |
| 41 | |
| 42 | #undef LOG_TAG |
| 43 | #define LOG_TAG "DEMO_WorldPhoneUtil" |
| 44 | const int WorldPhoneUtil::ACTIVE_MD_TYPE_UNKNOWN = 0; |
| 45 | const int WorldPhoneUtil::ACTIVE_MD_TYPE_WG = 1;//3G(WCDMA)+2G(GSM) |
| 46 | const int WorldPhoneUtil::ACTIVE_MD_TYPE_TG = 2;//3G(TDS-CDMA)+2G(GSM) |
| 47 | const int WorldPhoneUtil::ACTIVE_MD_TYPE_LWG = 3;//4G(TDD-LTE+FDD-LTE)+3G(WCDMA)+2G(GSM) |
| 48 | const int WorldPhoneUtil::ACTIVE_MD_TYPE_LTG = 4;//4G(TDD-LTE+FDD-LTE)+3G(TDS-CDMA)+2G(GSM) |
| 49 | //4G(TDD-LTE+FDD-LTE)+3G(WCDMA+EVDO)+2G(GSM+CDMA2000) |
| 50 | const int WorldPhoneUtil::ACTIVE_MD_TYPE_LWCG = 5; |
| 51 | const int WorldPhoneUtil::ACTIVE_MD_TYPE_LtTG = 6;//4G(TDD-LTE)+3G(TDS-CDMA)+2G(GSM) |
| 52 | const int WorldPhoneUtil::ACTIVE_MD_TYPE_LfWG = 7;//4G(FDD-LTE)+3G(WCDMA)+2G(GSM) |
| 53 | |
| 54 | |
| 55 | const int WorldPhoneUtil::MD_TYPE_UNKNOWN = 0; |
| 56 | const int WorldPhoneUtil::MD_TYPE_WG = 3; |
| 57 | const int WorldPhoneUtil::MD_TYPE_TG = 4; |
| 58 | const int WorldPhoneUtil::MD_TYPE_LWG = 5; |
| 59 | const int WorldPhoneUtil::MD_TYPE_LTG = 6; |
| 60 | const int WorldPhoneUtil::MD_TYPE_FDD = 100; |
| 61 | const int WorldPhoneUtil::MD_TYPE_TDD = 101; |
| 62 | |
| 63 | const int WorldPhoneUtil::MD_WORLD_MODE_UNKNOWN = 0; |
| 64 | const int WorldPhoneUtil::MD_WORLD_MODE_LTG = 8; //uLTG |
| 65 | const int WorldPhoneUtil::MD_WORLD_MODE_LWG = 9; //uLWG |
| 66 | const int WorldPhoneUtil::MD_WORLD_MODE_LWTG = 10; //uLWTG |
| 67 | const int WorldPhoneUtil::MD_WORLD_MODE_LWCG = 11; //uLWCG |
| 68 | const int WorldPhoneUtil::MD_WORLD_MODE_LWCTG = 12; //uLWTCG(Auto mode) |
| 69 | const int WorldPhoneUtil::MD_WORLD_MODE_LTTG = 13; //LtTG |
| 70 | const int WorldPhoneUtil::MD_WORLD_MODE_LFWG = 14; //LfWG |
| 71 | const int WorldPhoneUtil::MD_WORLD_MODE_LFWCG = 15; //uLfWCG |
| 72 | const int WorldPhoneUtil::MD_WORLD_MODE_LCTG = 16; //uLCTG |
| 73 | const int WorldPhoneUtil::MD_WORLD_MODE_LTCTG = 17; //uLtCTG |
| 74 | const int WorldPhoneUtil::MD_WORLD_MODE_LTWG = 18; //uLtWG |
| 75 | const int WorldPhoneUtil::MD_WORLD_MODE_LTWCG = 19; //uLTWCG |
| 76 | const int WorldPhoneUtil::MD_WORLD_MODE_LFTG = 20; //uLfTG |
| 77 | const int WorldPhoneUtil::MD_WORLD_MODE_LFCTG = 21; //uLfCTG |
| 78 | |
| 79 | std::string WorldPhoneUtil::PROPERTY_RAT_CONFIG = "ro.boot.opt_ps1_rat"; |
| 80 | std::string WorldPhoneUtil::PROPERTY_ACTIVE_MD = "vendor.ril.active.md"; |
| 81 | std::string WorldPhoneUtil::WCDMA = "W"; |
| 82 | std::string WorldPhoneUtil::TDSCDMA = "T"; |
| 83 | std::string WorldPhoneUtil::CDMA = "C"; |
| 84 | const int WorldPhoneUtil::UTRAN_DIVISION_DUPLEX_MODE_UNKNOWN = 0; |
| 85 | const int WorldPhoneUtil::UTRAN_DIVISION_DUPLEX_MODE_FDD = 1; |
| 86 | const int WorldPhoneUtil::UTRAN_DIVISION_DUPLEX_MODE_TDD = 2; |
| 87 | |
| 88 | // World mode result cause for EN. |
| 89 | const int WorldPhoneUtil::WORLD_MODE_RESULT_SUCCESS = 100; |
| 90 | const int WorldPhoneUtil::WORLD_MODE_RESULT_ERROR = 101; |
| 91 | const int WorldPhoneUtil::WORLD_MODE_RESULT_WM_ID_NOT_SUPPORT = 102; |
| 92 | |
| 93 | /* bitmask */ |
| 94 | /* the defination must be sync with ratconfig.c */ |
| 95 | const int WorldPhoneUtil::MASK_CDMA = (1 << 5); |
| 96 | const int WorldPhoneUtil::MASK_LTEFDD = (1 << 4); |
| 97 | const int WorldPhoneUtil::MASK_LTETDD = (1 << 3); |
| 98 | const int WorldPhoneUtil::MASK_WCDMA = (1 << 2); |
| 99 | const int WorldPhoneUtil::MASK_TDSCDMA = (1 << 1); |
| 100 | const int WorldPhoneUtil::MASK_GSM = (1); |
| 101 | |
| 102 | const int WorldPhoneUtil::MODEM_FDD = 1; |
| 103 | const int WorldPhoneUtil::MODEM_TD = 2; |
| 104 | const int WorldPhoneUtil::MODEM_NO3G = 3; |
| 105 | |
| 106 | WorldPhoneUtil::WorldPhoneUtil() { |
| 107 | // TODO Auto-generated constructor stub |
| 108 | |
| 109 | } |
| 110 | |
| 111 | WorldPhoneUtil::~WorldPhoneUtil() { |
| 112 | // TODO Auto-generated destructor stub |
| 113 | } |
| 114 | |
| 115 | bool WorldPhoneUtil::isWorldPhoneSupport() { |
| 116 | return (RatConfiguration::isWcdmaSupported() |
| 117 | && RatConfiguration::isTdscdmaSupported()); |
| 118 | } |
| 119 | |
| 120 | bool WorldPhoneUtil::isLteSupport() { |
| 121 | return (RatConfiguration::isLteFddSupported() |
| 122 | || RatConfiguration::isLteTddSupported()); |
| 123 | } |
| 124 | |
| 125 | bool WorldPhoneUtil::isWorldModeSupport() { |
| 126 | //bool is_support = (utils::mtk_property_get_int32("ro.vendor.mtk_md_world_mode_support", 0) == 1); |
| 127 | //return is_support; |
| 128 | return true; |
| 129 | } |
| 130 | |
| 131 | int WorldPhoneUtil::get3GDivisionDuplexMode() { |
| 132 | int duplexMode = UTRAN_DIVISION_DUPLEX_MODE_UNKNOWN; |
| 133 | int activeMdType = getActiveModemType(); |
| 134 | |
| 135 | switch (activeMdType) { |
| 136 | case ACTIVE_MD_TYPE_WG: |
| 137 | case ACTIVE_MD_TYPE_LWG: |
| 138 | case ACTIVE_MD_TYPE_LWCG: |
| 139 | case ACTIVE_MD_TYPE_LfWG: |
| 140 | duplexMode = UTRAN_DIVISION_DUPLEX_MODE_FDD; |
| 141 | break; |
| 142 | case ACTIVE_MD_TYPE_TG: |
| 143 | case ACTIVE_MD_TYPE_LTG: |
| 144 | case ACTIVE_MD_TYPE_LtTG: |
| 145 | duplexMode = UTRAN_DIVISION_DUPLEX_MODE_TDD; |
| 146 | break; |
| 147 | default: |
| 148 | duplexMode = UTRAN_DIVISION_DUPLEX_MODE_UNKNOWN; |
| 149 | break; |
| 150 | } |
| 151 | LOG_D(LOG_TAG, "get3GDivisionDuplexMode= %d", duplexMode); |
| 152 | return duplexMode; |
| 153 | } |
| 154 | |
| 155 | int WorldPhoneUtil::getActiveModemType() { |
| 156 | int modemType = 0; |
| 157 | int activeMdType = ACTIVE_MD_TYPE_UNKNOWN; |
| 158 | int activeMode = -1; |
| 159 | if (!isWorldModeSupport()) { |
| 160 | modemType = getWorldModeId(); |
| 161 | switch (modemType) { |
| 162 | case MD_TYPE_WG: |
| 163 | activeMdType = ACTIVE_MD_TYPE_WG; |
| 164 | break; |
| 165 | case MD_TYPE_TG: |
| 166 | activeMdType = ACTIVE_MD_TYPE_TG; |
| 167 | break; |
| 168 | case MD_TYPE_LWG: |
| 169 | activeMdType = ACTIVE_MD_TYPE_LWG; |
| 170 | break; |
| 171 | case MD_TYPE_LTG: |
| 172 | activeMdType = ACTIVE_MD_TYPE_LTG; |
| 173 | break; |
| 174 | default: |
| 175 | activeMdType = ACTIVE_MD_TYPE_UNKNOWN; |
| 176 | break; |
| 177 | } |
| 178 | } else { |
| 179 | modemType = getWorldModeId(); |
| 180 | activeMode = utils::mtk_property_get_int32("vendor.ril.nw.worldmode.activemode",ACTIVE_MD_TYPE_UNKNOWN); |
| 181 | switch (modemType) { |
| 182 | case MD_WORLD_MODE_LTG: |
| 183 | case MD_WORLD_MODE_LCTG: |
| 184 | case MD_WORLD_MODE_LFTG: |
| 185 | case MD_WORLD_MODE_LFCTG: |
| 186 | activeMdType = ACTIVE_MD_TYPE_LTG; |
| 187 | break; |
| 188 | case MD_WORLD_MODE_LWG: |
| 189 | case MD_WORLD_MODE_LTWG: |
| 190 | activeMdType = ACTIVE_MD_TYPE_LWG; |
| 191 | break; |
| 192 | case MD_WORLD_MODE_LWTG: |
| 193 | case MD_WORLD_MODE_LWCTG: |
| 194 | if (activeMode > 0){ |
| 195 | if (activeMode == 1){ |
| 196 | //FDD mode |
| 197 | activeMdType = ACTIVE_MD_TYPE_LWG; |
| 198 | } else if (activeMode == 2){ |
| 199 | //TDD mode |
| 200 | activeMdType = ACTIVE_MD_TYPE_LTG; |
| 201 | } |
| 202 | } |
| 203 | break; |
| 204 | case MD_WORLD_MODE_LWCG: |
| 205 | case MD_WORLD_MODE_LFWCG: |
| 206 | case MD_WORLD_MODE_LTWCG: |
| 207 | activeMdType = ACTIVE_MD_TYPE_LWCG; |
| 208 | break; |
| 209 | case MD_WORLD_MODE_LTTG: |
| 210 | case MD_WORLD_MODE_LTCTG: |
| 211 | activeMdType = ACTIVE_MD_TYPE_LtTG; |
| 212 | break; |
| 213 | case MD_WORLD_MODE_LFWG: |
| 214 | activeMdType = ACTIVE_MD_TYPE_LfWG; |
| 215 | break; |
| 216 | default: |
| 217 | activeMdType = ACTIVE_MD_TYPE_UNKNOWN; |
| 218 | break; |
| 219 | } |
| 220 | } |
| 221 | LOG_D(LOG_TAG, "getActiveModemType=%d activeMode=%d",activeMdType , activeMode); |
| 222 | return activeMdType; |
| 223 | } |
| 224 | |
| 225 | int WorldPhoneUtil::getWorldModeId() { |
| 226 | int modemType = 0; |
| 227 | modemType = utils::mtk_property_get_int32(PROPERTY_ACTIVE_MD.c_str(),MD_TYPE_UNKNOWN); |
| 228 | return modemType; |
| 229 | } |
| 230 | |
| 231 | int WorldPhoneUtil::getModemType() { |
| 232 | int mode = MODEM_NO3G; |
| 233 | int mask = get3GDivisionDuplexMode(); |
| 234 | if ((1 == mask) || (2 == mask)) { |
| 235 | mode = mask; |
| 236 | } |
| 237 | LOG_D(LOG_TAG, "mode = %d", mode); |
| 238 | return mode; |
| 239 | } |