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 "MtkRadioAccessFamily.h" |
| 37 | #include "Phone_utils.h" |
| 38 | // Radio Access Family |
| 39 | // 2G |
| 40 | const int MtkRadioAccessFamily::RAF_UNKNOWN = RIL_RadioAccessFamily::RAF_UNKNOWN; |
| 41 | const int MtkRadioAccessFamily::RAF_GSM = RIL_RadioAccessFamily::RAF_GSM; |
| 42 | const int MtkRadioAccessFamily::RAF_GPRS = RIL_RadioAccessFamily::RAF_GPRS; |
| 43 | const int MtkRadioAccessFamily::RAF_EDGE = RIL_RadioAccessFamily::RAF_EDGE; |
| 44 | const int MtkRadioAccessFamily::RAF_IS95A = RIL_RadioAccessFamily::RAF_IS95A; |
| 45 | const int MtkRadioAccessFamily::RAF_IS95B = RIL_RadioAccessFamily::RAF_IS95B; |
| 46 | const int MtkRadioAccessFamily::RAF_1xRTT = RIL_RadioAccessFamily::RAF_1xRTT; |
| 47 | // 3G |
| 48 | const int MtkRadioAccessFamily::RAF_EVDO_0 = RIL_RadioAccessFamily::RAF_EVDO_0; |
| 49 | const int MtkRadioAccessFamily::RAF_EVDO_A = RIL_RadioAccessFamily::RAF_EVDO_A; |
| 50 | const int MtkRadioAccessFamily::RAF_EVDO_B = RIL_RadioAccessFamily::RAF_EVDO_B; |
| 51 | const int MtkRadioAccessFamily::RAF_EHRPD = RIL_RadioAccessFamily::RAF_EHRPD; |
| 52 | const int MtkRadioAccessFamily::RAF_HSUPA = RIL_RadioAccessFamily::RAF_HSUPA; |
| 53 | const int MtkRadioAccessFamily::RAF_HSDPA = RIL_RadioAccessFamily::RAF_HSDPA; |
| 54 | const int MtkRadioAccessFamily::RAF_HSPA = RIL_RadioAccessFamily::RAF_HSPA; |
| 55 | const int MtkRadioAccessFamily::RAF_HSPAP = RIL_RadioAccessFamily::RAF_HSPAP; |
| 56 | const int MtkRadioAccessFamily::RAF_UMTS = RIL_RadioAccessFamily::RAF_UMTS; |
| 57 | const int MtkRadioAccessFamily::RAF_TD_SCDMA = |
| 58 | RIL_RadioAccessFamily::RAF_TD_SCDMA; |
| 59 | // 4G |
| 60 | const int MtkRadioAccessFamily::RAF_LTE = RIL_RadioAccessFamily::RAF_LTE; |
| 61 | const int MtkRadioAccessFamily::RAF_LTE_CA = 19; //RIL_RadioAccessFamily::RAF_LTE_CA; |
| 62 | |
| 63 | // Grouping of RAFs |
| 64 | // 2G |
| 65 | const int MtkRadioAccessFamily::GSM = RAF_GSM | RAF_GPRS | RAF_EDGE; |
| 66 | const int MtkRadioAccessFamily::CDMA = RAF_IS95A | RAF_IS95B | RAF_1xRTT; |
| 67 | // 3G |
| 68 | const int MtkRadioAccessFamily::EVDO = RAF_EVDO_0 | RAF_EVDO_A | RAF_EVDO_B |
| 69 | | RAF_EHRPD; |
| 70 | const int MtkRadioAccessFamily::HS = RAF_HSUPA | RAF_HSDPA | RAF_HSPA |
| 71 | | RAF_HSPAP; |
| 72 | const int MtkRadioAccessFamily::WCDMA = HS | RAF_UMTS | RAF_TD_SCDMA; |
| 73 | // 4G |
| 74 | const int MtkRadioAccessFamily::LTE = RAF_LTE | RAF_LTE_CA; |
| 75 | |
| 76 | MtkRadioAccessFamily::MtkRadioAccessFamily() { |
| 77 | // TODO Auto-generated constructor stub |
| 78 | |
| 79 | } |
| 80 | |
| 81 | MtkRadioAccessFamily::~MtkRadioAccessFamily() { |
| 82 | // TODO Auto-generated destructor stub |
| 83 | } |
| 84 | |
| 85 | int MtkRadioAccessFamily::getRafFromNetworkType(int type) { |
| 86 | int raf; |
| 87 | |
| 88 | switch (type) { |
| 89 | case Phone_utils::NETWORK_MODE_WCDMA_PREF: |
| 90 | raf = GSM | WCDMA; |
| 91 | break; |
| 92 | case Phone_utils::NETWORK_MODE_GSM_ONLY: |
| 93 | raf = GSM; |
| 94 | break; |
| 95 | case Phone_utils::NETWORK_MODE_WCDMA_ONLY: |
| 96 | raf = WCDMA; |
| 97 | break; |
| 98 | case Phone_utils::NETWORK_MODE_GSM_UMTS: |
| 99 | raf = GSM | WCDMA; |
| 100 | break; |
| 101 | case Phone_utils::NETWORK_MODE_CDMA: |
| 102 | raf = CDMA | EVDO; |
| 103 | break; |
| 104 | case Phone_utils::NETWORK_MODE_LTE_CDMA_EVDO: |
| 105 | raf = LTE | CDMA | EVDO; |
| 106 | break; |
| 107 | case Phone_utils::NETWORK_MODE_LTE_GSM_WCDMA: |
| 108 | raf = LTE | GSM | WCDMA; |
| 109 | break; |
| 110 | case Phone_utils::NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA: |
| 111 | raf = LTE | CDMA | EVDO | GSM | WCDMA; |
| 112 | break; |
| 113 | case Phone_utils::NETWORK_MODE_LTE_ONLY: |
| 114 | raf = LTE; |
| 115 | break; |
| 116 | case Phone_utils::NETWORK_MODE_LTE_WCDMA: |
| 117 | raf = LTE | WCDMA; |
| 118 | break; |
| 119 | case Phone_utils::NETWORK_MODE_CDMA_NO_EVDO: |
| 120 | raf = CDMA; |
| 121 | break; |
| 122 | case Phone_utils::NETWORK_MODE_EVDO_NO_CDMA: |
| 123 | raf = EVDO; |
| 124 | break; |
| 125 | case Phone_utils::NETWORK_MODE_GLOBAL: |
| 126 | raf = GSM | WCDMA | CDMA | EVDO; |
| 127 | break; |
| 128 | case Phone_utils::NETWORK_MODE_TDSCDMA_ONLY: |
| 129 | raf = RAF_TD_SCDMA; |
| 130 | break; |
| 131 | case Phone_utils::NETWORK_MODE_TDSCDMA_WCDMA: |
| 132 | raf = RAF_TD_SCDMA | WCDMA; |
| 133 | break; |
| 134 | case Phone_utils::NETWORK_MODE_LTE_TDSCDMA: |
| 135 | raf = LTE | RAF_TD_SCDMA; |
| 136 | break; |
| 137 | case Phone_utils::NETWORK_MODE_TDSCDMA_GSM: |
| 138 | raf = RAF_TD_SCDMA | GSM; |
| 139 | break; |
| 140 | case Phone_utils::NETWORK_MODE_LTE_TDSCDMA_GSM: |
| 141 | raf = LTE | RAF_TD_SCDMA | GSM; |
| 142 | break; |
| 143 | case Phone_utils::NETWORK_MODE_TDSCDMA_GSM_WCDMA: |
| 144 | raf = RAF_TD_SCDMA | GSM | WCDMA; |
| 145 | break; |
| 146 | case Phone_utils::NETWORK_MODE_LTE_TDSCDMA_WCDMA: |
| 147 | raf = LTE | RAF_TD_SCDMA | WCDMA; |
| 148 | break; |
| 149 | case Phone_utils::NETWORK_MODE_LTE_TDSCDMA_GSM_WCDMA: |
| 150 | raf = LTE | RAF_TD_SCDMA | GSM | WCDMA; |
| 151 | break; |
| 152 | case Phone_utils::NETWORK_MODE_TDSCDMA_CDMA_EVDO_GSM_WCDMA: |
| 153 | raf = RAF_TD_SCDMA | CDMA | EVDO | GSM | WCDMA; |
| 154 | break; |
| 155 | case Phone_utils::NETWORK_MODE_LTE_TDSCDMA_CDMA_EVDO_GSM_WCDMA: |
| 156 | raf = LTE | RAF_TD_SCDMA | CDMA | EVDO | GSM | WCDMA; |
| 157 | break; |
| 158 | case Phone_utils::NETWORK_MODE_LTE_GSM: |
| 159 | raf = LTE | GSM; |
| 160 | break; |
| 161 | case Phone_utils::NETWORK_MODE_LTE_TDD_ONLY: |
| 162 | raf = LTE; |
| 163 | break; |
| 164 | case Phone_utils::NETWORK_MODE_CDMA_GSM: |
| 165 | raf = CDMA | GSM; |
| 166 | break; |
| 167 | case Phone_utils::NETWORK_MODE_CDMA_EVDO_GSM: |
| 168 | raf = CDMA | EVDO | GSM; |
| 169 | break; |
| 170 | case Phone_utils::NETWORK_MODE_LTE_CDMA_EVDO_GSM: |
| 171 | raf = LTE | CDMA | EVDO | GSM; |
| 172 | break; |
| 173 | default: |
| 174 | raf = RAF_UNKNOWN; |
| 175 | break; |
| 176 | } |
| 177 | |
| 178 | return raf; |
| 179 | } |
| 180 | |
| 181 | /** |
| 182 | * if the raf includes ANY bit set for a group |
| 183 | * adjust it to contain ALL the bits for that group |
| 184 | */ |
| 185 | int MtkRadioAccessFamily::getAdjustedRaf(int raf) { |
| 186 | raf = ((GSM & raf) > 0) ? (GSM | raf) : raf; |
| 187 | raf = ((WCDMA & raf) > 0) ? (WCDMA | raf) : raf; |
| 188 | raf = ((CDMA & raf) > 0) ? (CDMA | raf) : raf; |
| 189 | raf = ((EVDO & raf) > 0) ? (EVDO | raf) : raf; |
| 190 | raf = ((LTE & raf) > 0) ? (LTE | raf) : raf; |
| 191 | |
| 192 | return raf; |
| 193 | } |
| 194 | |
| 195 | int MtkRadioAccessFamily::getNetworkTypeFromRaf(int raf) { |
| 196 | int type; |
| 197 | |
| 198 | raf = getAdjustedRaf(raf); |
| 199 | |
| 200 | switch (raf) { |
| 201 | case (GSM | WCDMA): |
| 202 | type = Phone_utils::NETWORK_MODE_WCDMA_PREF; |
| 203 | break; |
| 204 | case GSM: |
| 205 | type = Phone_utils::NETWORK_MODE_GSM_ONLY; |
| 206 | break; |
| 207 | case WCDMA: |
| 208 | type = Phone_utils::NETWORK_MODE_WCDMA_ONLY; |
| 209 | break; |
| 210 | case (CDMA | EVDO): |
| 211 | type = Phone_utils::NETWORK_MODE_CDMA; |
| 212 | break; |
| 213 | case (LTE | CDMA | EVDO): |
| 214 | type = Phone_utils::NETWORK_MODE_LTE_CDMA_EVDO; |
| 215 | break; |
| 216 | case (LTE | GSM | WCDMA): |
| 217 | type = Phone_utils::NETWORK_MODE_LTE_GSM_WCDMA; |
| 218 | break; |
| 219 | case (LTE | CDMA | EVDO | GSM | WCDMA): |
| 220 | type = Phone_utils::NETWORK_MODE_LTE_CDMA_EVDO_GSM_WCDMA; |
| 221 | break; |
| 222 | case LTE: |
| 223 | type = Phone_utils::NETWORK_MODE_LTE_ONLY; |
| 224 | break; |
| 225 | case (LTE | WCDMA): |
| 226 | type = Phone_utils::NETWORK_MODE_LTE_WCDMA; |
| 227 | break; |
| 228 | case CDMA: |
| 229 | type = Phone_utils::NETWORK_MODE_CDMA_NO_EVDO; |
| 230 | break; |
| 231 | case EVDO: |
| 232 | type = Phone_utils::NETWORK_MODE_EVDO_NO_CDMA; |
| 233 | break; |
| 234 | case (GSM | WCDMA | CDMA | EVDO): |
| 235 | type = Phone_utils::NETWORK_MODE_GLOBAL; |
| 236 | break; |
| 237 | case RAF_TD_SCDMA: |
| 238 | type = Phone_utils::NETWORK_MODE_TDSCDMA_ONLY; |
| 239 | break; |
| 240 | case (LTE | RAF_TD_SCDMA): |
| 241 | type = Phone_utils::NETWORK_MODE_LTE_TDSCDMA; |
| 242 | break; |
| 243 | case (RAF_TD_SCDMA | GSM): |
| 244 | type = Phone_utils::NETWORK_MODE_TDSCDMA_GSM; |
| 245 | break; |
| 246 | case (LTE | RAF_TD_SCDMA | GSM): |
| 247 | type = Phone_utils::NETWORK_MODE_LTE_TDSCDMA_GSM; |
| 248 | break; |
| 249 | case (LTE | GSM): |
| 250 | type = Phone_utils::NETWORK_MODE_LTE_GSM; |
| 251 | break; |
| 252 | case (CDMA | GSM): |
| 253 | type = Phone_utils::NETWORK_MODE_CDMA_GSM; |
| 254 | break; |
| 255 | case (CDMA | EVDO | GSM): |
| 256 | type = Phone_utils::NETWORK_MODE_CDMA_EVDO_GSM; |
| 257 | break; |
| 258 | case (LTE | CDMA | EVDO | GSM): |
| 259 | type = Phone_utils::NETWORK_MODE_LTE_CDMA_EVDO_GSM; |
| 260 | break; |
| 261 | default: |
| 262 | type = Phone_utils::PREFERRED_NETWORK_MODE; |
| 263 | break; |
| 264 | } |
| 265 | |
| 266 | return type; |
| 267 | } |