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) 2010. 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 | #include <pthread.h> |
| 36 | #include <vendor-ril/telephony/ril.h> |
| 37 | #include <stdlib.h> |
| 38 | #include <stdio.h> |
| 39 | #include <cutils/jstring.h> |
| 40 | #include <log/log.h> |
| 41 | #include <unistd.h> |
| 42 | #include <math.h> |
| 43 | #include <string> |
| 44 | #include <vector> |
| 45 | #include <stdint.h> |
| 46 | #include "ModemCategory.h" |
| 47 | #include "common.h" |
| 48 | #include "em/em.h" |
| 49 | #include "Radio_capability_switch_util.h" |
| 50 | #include "../util/utils.h" |
| 51 | #include "MtkRadioAccessFamily.h" |
| 52 | |
| 53 | #if EM_MODE_SUPPORT |
| 54 | |
| 55 | #undef LOG_TAG |
| 56 | #define LOG_TAG "EM_BANDMODE" |
| 57 | |
| 58 | static const int WCDMA = 1; |
| 59 | static const int TDSCDMA = 2; |
| 60 | |
| 61 | static const int INDEX_GSM_BAND = 0; |
| 62 | static const int INDEX_UMTS_BAND = 1; |
| 63 | static const int INDEX_LTE_FDD_BAND = 2; |
| 64 | static const int INDEX_LTE_TDD_BAND = 3; |
| 65 | static const int INDEX_LTE_BAND_96 = 4; |
| 66 | static const int INDEX_LTE_BAND_128 = 5; |
| 67 | static const int INDEX_LTE_BAND_160 = 6; |
| 68 | static const int INDEX_LTE_BAND_192 = 7; |
| 69 | static const int INDEX_LTE_BAND_224 = 8; |
| 70 | static const int INDEX_LTE_BAND_256 = 9; |
| 71 | static const int INDEX_CDMA_BAND = 10; |
| 72 | static const int INDEX_BAND_MAX = 11; |
| 73 | static const int BAND_SET_INVALID = 1000; |
| 74 | static int mSimType = -1; |
| 75 | |
| 76 | /** GSM mode bit. */ |
| 77 | static const int GSM_EGSM900_BIT = 1; |
| 78 | static const int GSM_DCS1800_BIT = 3; |
| 79 | static const int GSM_PCS1900_BIT = 4; |
| 80 | static const int GSM_GSM850_BIT = 7; |
| 81 | static const std::vector<int> GSM_BAND_BIT{GSM_EGSM900_BIT,GSM_DCS1800_BIT,GSM_PCS1900_BIT,GSM_GSM850_BIT}; |
| 82 | |
| 83 | /** Event or message id. */ |
| 84 | static const int EVENT_QUERY_SUPPORTED = 100; |
| 85 | static const int EVENT_QUERY_CURRENT = 101; |
| 86 | static const int EVENT_SET_GSM = 110; |
| 87 | |
| 88 | static const int EVENT_SET_FAIL = 1; |
| 89 | static const int EVENT_RESET = 2; |
| 90 | |
| 91 | static const std::uint32_t GSM_MAX_VALUE = UINT8_MAX; //255 |
| 92 | static const std::uint32_t UMTS_MAX_VALUE = UINT16_MAX; //65535; |
| 93 | static const std::uint32_t LTE_MAX_VALUE = UINT32_MAX;//4294967295 |
| 94 | |
| 95 | /** AT Command. */ |
| 96 | static const std::string QUERY_SUPPORT_COMMAND = "AT+EPBSE=?"; |
| 97 | static const std::string QUERY_CURRENT_COMMAND = "AT+EPBSE?"; |
| 98 | static const std::string SET_COMMAND = "AT+EPBSE="; |
| 99 | static const std::string SAME_COMMAND = "+EPBSE:"; |
| 100 | |
| 101 | |
| 102 | static const int EVENT_QUERY_CURRENT_CDMA = 103; |
| 103 | static const int EVENT_SET_CDMA = 111; |
| 104 | |
| 105 | static const std::string QUERY_CURRENT_COMMAND_CDMA = "AT+ECBANDCFG?"; |
| 106 | static const std::string SET_COMMAND_CDMA = "AT+ECBANDCFG="; |
| 107 | static const std::string SAME_COMMAND_CDMA = "+ECBANDCFG:"; |
| 108 | |
| 109 | static pthread_mutex_t s_band_Mutex = PTHREAD_MUTEX_INITIALIZER; |
| 110 | static pthread_cond_t s_band_Cond = PTHREAD_COND_INITIALIZER; |
| 111 | #define BLOCK_LOCK() pthread_mutex_lock(&s_band_Mutex) |
| 112 | #define BLOCK_UNLOCK() pthread_mutex_unlock(&s_band_Mutex) |
| 113 | #define BLOCK_WAIT() pthread_cond_wait(&s_band_Cond, &s_band_Mutex) |
| 114 | #define BLOCK_WAKEUP() pthread_cond_broadcast(&s_band_Cond) |
| 115 | |
| 116 | bool mIsLteExtend = false; |
| 117 | int mCurrentEmbandmodeFlag = 0; |
| 118 | std::vector<long> gsmValues(INDEX_BAND_MAX); |
| 119 | long cdmaValues = 0; |
| 120 | |
| 121 | struct BandModeMap{ |
| 122 | std::string mName; |
| 123 | int mIndex; |
| 124 | int mBit; |
| 125 | bool mEnable; |
| 126 | bool mCheck; |
| 127 | BandModeMap(std::string name, int index, int bit ,bool enable, bool check) |
| 128 | : mName(name), mIndex(index), mBit(bit), mEnable(enable), mCheck(check) { |
| 129 | |
| 130 | } |
| 131 | BandModeMap(BandModeMap&& other): mName(std::move(other.mName)), |
| 132 | mIndex(std::move(other.mIndex)), |
| 133 | mBit(std::move(other.mBit)), |
| 134 | mEnable(std::move(other.mEnable)), |
| 135 | mCheck(std::move(other.mCheck)) { |
| 136 | |
| 137 | } |
| 138 | BandModeMap& operator=(const BandModeMap& other) = default; |
| 139 | }; |
| 140 | |
| 141 | static std::vector<BandModeMap> mModeArray; |
| 142 | static std::vector<BandModeMap> mCdmaModeArray; |
| 143 | static const std::vector<std::string> band_mode_gsm { "EGSM900", "DCS1800", |
| 144 | "PCS1900", "GSM850" }; |
| 145 | |
| 146 | static const std::vector<std::string> band_mode_wcdma { "WCDMA-IMT-2000", |
| 147 | "WCDMA-PCS-1900", "WCDMA-DCS-1800", "WCDMA-AWS-1700", "WCDMA-CLR-850", |
| 148 | "WCDMA-800", "WCDMA-IMT-E-2600", "WCDMA-GSM-900", "WCDMA-1800", |
| 149 | "WCDMA-1700" }; |
| 150 | |
| 151 | static const std::vector<std::string> band_mode_tdscdma { "TD_SCDMA Band A", |
| 152 | "TD_SCDMA Band B", "TD_SCDMA Band C", "TD_SCDMA Band D", |
| 153 | "TD_SCDMA Band E", "TD_SCDMA Band F" }; |
| 154 | |
| 155 | static const std::vector<std::string> band_mode_lte_fdd { "Band 1", "Band 2", |
| 156 | "Band 3", "Band 4", "Band 5", "Band 6", "Band 7", "Band 8", "Band 9", |
| 157 | "Band 10", "Band 11", "Band 12", "Band 13", "Band 14", "Band 15", |
| 158 | "Band 16", "Band 17", "Band 18", "Band 19", "Band 20", "Band 21", |
| 159 | "Band 22", "Band 23", "Band 24", "Band 25", "Band 26", "Band 27", |
| 160 | "Band 28", "Band 29", "Band 30", "Band 31", "Band 32" }; |
| 161 | |
| 162 | static const std::vector<std::string> band_mode_lte_tdd { "Band 33", "Band 34", |
| 163 | "Band 35", "Band 36", "Band 37", "Band 38", "Band 39", "Band 40", |
| 164 | "Band 41", "Band 42", "Band 43", "Band 44" }; |
| 165 | |
| 166 | static const std::vector<std::string> band_mode_lte_96 { "Band 65", "Band 66", |
| 167 | "Band 67", "Band 68", "Band 69", "Band 70", "Band 71", "Band 72", |
| 168 | "Band 73", "Band 74", "Band 75", "Band 76", "Band 77", "Band 78", |
| 169 | "Band 79", "Band 80", "Band 81", "Band 82", "Band 83", "Band 84", |
| 170 | "Band 85", "Band 86", "Band 87", "Band 88", "Band 89", "Band 90", |
| 171 | "Band 91", "Band 92", "Band 93", "Band 94", "Band 95", "Band 96" }; |
| 172 | |
| 173 | static const std::vector<std::string> band_mode_lte_128 { "Band 97", "Band 98", |
| 174 | "Band 99", "Band 100", "Band 101", "Band 102", "Band 103", "Band 104", |
| 175 | "Band 105", "Band 106", "Band 107", "Band 108", "Band 109", "Band 110", |
| 176 | "Band 111", "Band 112", "Band 113", "Band 114", "Band 115", "Band 116", |
| 177 | "Band 117", "Band 118", "Band 119", "Band 120", "Band 121", "Band 122", |
| 178 | "Band 123", "Band 124", "Band 125", "Band 126", "Band 127", "Band 128" }; |
| 179 | |
| 180 | static const std::vector<std::string> band_mode_lte_160 { "Band 129", |
| 181 | "Band 130", "Band 131", "Band 132", "Band 133", "Band 134", "Band 135", |
| 182 | "Band 136", "Band 137", "Band 138", "Band 139", "Band 140", "Band 141", |
| 183 | "Band 142", "Band 143", "Band 144", "Band 145", "Band 146", "Band 147", |
| 184 | "Band 148", "Band 149", "Band 150", "Band 151", "Band 152", "Band 153", |
| 185 | "Band 154", "Band 155", "Band 156", "Band 157", "Band 158", "Band 159", |
| 186 | "Band 160" }; |
| 187 | |
| 188 | static const std::vector<std::string> band_mode_lte_192 { "Band 161", |
| 189 | "Band 162", "Band 163", "Band 164", "Band 165", "Band 166", "Band 167", |
| 190 | "Band 168", "Band 169", "Band 170", "Band 171", "Band 172", "Band 173", |
| 191 | "Band 174", "Band 175", "Band 176", "Band 177", "Band 178", "Band 179", |
| 192 | "Band 180", "Band 181", "Band 182", "Band 183", "Band 184", "Band 185", |
| 193 | "Band 186", "Band 187", "Band 188", "Band 189", "Band 190", "Band 191", |
| 194 | "Band 192" }; |
| 195 | |
| 196 | static const std::vector<std::string> band_mode_lte_224 { "Band 193", |
| 197 | "Band 194", "Band 195", "Band 196", "Band 197", "Band 198", "Band 199", |
| 198 | "Band 200", "Band 201", "Band 202", "Band 203", "Band 204", "Band 205", |
| 199 | "Band 206", "Band 207", "Band 208", "Band 209", "Band 210", "Band 211", |
| 200 | "Band 212", "Band 213", "Band 214", "Band 215", "Band 216", "Band 217", |
| 201 | "Band 218", "Band 219", "Band 220", "Band 221", "Band 222", "Band 223", |
| 202 | "Band 224" }; |
| 203 | |
| 204 | static const std::vector<std::string> band_mode_lte_256 { "Band 225", |
| 205 | "Band 226", "Band 227", "Band 228", "Band 229", "Band 230", "Band 231", |
| 206 | "Band 232", "Band 233", "Band 234", "Band 235", "Band 236", "Band 237", |
| 207 | "Band 238", "Band 239", "Band 240", "Band 241", "Band 242", "Band 243", |
| 208 | "Band 244", "Band 245", "Band 246", "Band 247", "Band 248", "Band 249", |
| 209 | "Band 250", "Band 251", "Band 252", "Band 253", "Band 254", "Band 255", |
| 210 | "Band 256" }; |
| 211 | |
| 212 | static const std::vector<std::string> band_mode_cdma { |
| 213 | "Band 0(North American Celluar Band)", |
| 214 | "Band 1(North American PCS band)", "Band 2(TACS band)", |
| 215 | "Band 3(JTACS band)", "Band 4(Korean PCS band)", "Band 5(NMT-450 Band)", |
| 216 | "Band 6(IMT-2000 band)", "Band 7(North American 700Mhz Celluar Band)", |
| 217 | "Band 8(1800-MHz Band)", "Band 9(900-MHz Band)", |
| 218 | "Band 10(Secondary 800 MHz Band)", "Band 11(400 MHz European PAMR Band", |
| 219 | "Band 12(800 MHz PAMR Band)", |
| 220 | "Band 13(2.5 GHz IMT-2000 Extension Band)", |
| 221 | "Band 14(US PCS 1.9GHz Band)", "Band 15(AWS Band)" }; |
| 222 | |
| 223 | int fgset = false; |
| 224 | int count = -1; |
| 225 | std::vector<std::string> choose_vals; |
| 226 | |
| 227 | static void sendATCommand(const char *cmd,int msg) |
| 228 | { |
| 229 | BLOCK_LOCK(); |
| 230 | mCurrentEmbandmodeFlag = msg; |
| 231 | emSendATCommand(cmd,mSimType); |
| 232 | RLOGD("sendATCommand: wait start"); |
| 233 | BLOCK_WAIT(); |
| 234 | RLOGD("sendATCommand: wait end"); |
| 235 | BLOCK_UNLOCK(); |
| 236 | return ; |
| 237 | } |
| 238 | |
| 239 | static void setCurrentMode(std::vector<long> values) { |
| 240 | for (auto& m : mModeArray) { |
| 241 | if ((values[m.mIndex] & (1L << m.mBit)) == 0) { |
| 242 | m.mCheck = false; |
| 243 | } else { |
| 244 | if (m.mEnable) { |
| 245 | m.mCheck = true; |
| 246 | } |
| 247 | } |
| 248 | //RLOGD("setCurrentMode labels: %s, enable: %d, check: %d", m.mName.c_str(), m.mEnable, m.mCheck); |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | static void setSupportedMode(std::vector<long> values) { |
| 253 | for (auto& m : mModeArray) { |
| 254 | if ((values[m.mIndex] & (1L << m.mBit)) == 0) { |
| 255 | m.mEnable = false; |
| 256 | } else { |
| 257 | m.mEnable = true; |
| 258 | } |
| 259 | //RLOGD("setSupportedMode labels: %s, enable: %d", m.mName.c_str(), m.mEnable); |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | static void setCurrentModeCdma(const long value) { |
| 264 | RLOGD("setCurrentModeCdma: %ld", value); |
| 265 | for (auto& m : mCdmaModeArray) { |
| 266 | if ((value & (1L << m.mBit)) == 0) { |
| 267 | m.mCheck = false; |
| 268 | } else { |
| 269 | if (m.mEnable) { |
| 270 | m.mCheck = true; |
| 271 | } |
| 272 | } |
| 273 | RLOGD("setCurrentModeCdma labels: %s, enable: %d, check: %d", m.mName.c_str(), m.mEnable, m.mCheck); |
| 274 | } |
| 275 | |
| 276 | } |
| 277 | |
| 278 | static void setSupportedModeCdma(const long value) { |
| 279 | RLOGD("setSupportedModeCdma: %ld", value); |
| 280 | for (auto& m : mCdmaModeArray) { |
| 281 | if ((value & (1L << m.mBit)) == 0) { |
| 282 | m.mEnable = false; |
| 283 | } else { |
| 284 | m.mEnable = true; |
| 285 | } |
| 286 | RLOGD("setSupportedModeCdma labels: %s, enable: %d", m.mName.c_str(), m.mEnable); |
| 287 | } |
| 288 | } |
| 289 | |
| 290 | static void showBandModeCdma(char* response, int msg) { |
| 291 | std::vector<std::string> out; |
| 292 | utils::tokenize(string(response), "\n", out); |
| 293 | for(auto i: out) { |
| 294 | if(i.find(SAME_COMMAND_CDMA) != std::string::npos) { |
| 295 | std::string splitString = i.substr(std::string(SAME_COMMAND_CDMA).size()); |
| 296 | RLOGD("showBandModeCdma splitString: %s", splitString.c_str()); |
| 297 | if (msg == EVENT_QUERY_CURRENT_CDMA) { |
| 298 | std::vector<std::string> getDigitalVal; |
| 299 | utils::tokenize(string(splitString), ",\n", getDigitalVal); |
| 300 | std::vector<long> values; |
| 301 | try { |
| 302 | for(auto str: getDigitalVal) { |
| 303 | if(str.empty() || str == "\n") { |
| 304 | continue; |
| 305 | } |
| 306 | long v = std::stol(str, 0 ,0); |
| 307 | values.push_back(v); |
| 308 | } |
| 309 | } catch (const out_of_range &e) { |
| 310 | RLOGD("out of range: %s", e.what()); |
| 311 | } catch (const invalid_argument &e) { |
| 312 | RLOGD("invalid argument: %s", e.what()); |
| 313 | } |
| 314 | if(values.size() < 2) { |
| 315 | RLOGD("showBandModeCdma size < 2"); |
| 316 | android::emResultNotify(RET_STRING_BANDMODE_FAIL); |
| 317 | return; |
| 318 | } |
| 319 | setSupportedModeCdma(values[0]); |
| 320 | setCurrentModeCdma(values[1]); |
| 321 | } |
| 322 | } |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | static void showBandModeGsm(char* response, int msg) { |
| 327 | std::vector<std::string> out; |
| 328 | utils::tokenize(string(response), "\n", out); |
| 329 | for(auto i: out) { |
| 330 | if(i.find(SAME_COMMAND) != std::string::npos) { |
| 331 | std::string splitString = i.substr(std::string(SAME_COMMAND).size()); |
| 332 | RLOGD("showBandModeGsm splitString: %s", splitString.c_str()); |
| 333 | std::vector<std::string> getDigitalVal; |
| 334 | utils::tokenize(string(splitString), ",\n", getDigitalVal); |
| 335 | if (getDigitalVal.size() > 0) { |
| 336 | std::vector<long> values; |
| 337 | for (int i = 0; i < INDEX_BAND_MAX; i++) { |
| 338 | if (getDigitalVal.size() <= i) { |
| 339 | values.push_back(0); |
| 340 | continue; |
| 341 | } |
| 342 | try { |
| 343 | values.push_back(std::stol(getDigitalVal[i], 0 ,0)); |
| 344 | } catch (const out_of_range &e) { |
| 345 | values.push_back(0); |
| 346 | RLOGD("out of range: %s", e.what()); |
| 347 | } catch (const invalid_argument &e) { |
| 348 | values.push_back(0); |
| 349 | RLOGD("invalid argument: %s", e.what()); |
| 350 | } |
| 351 | } |
| 352 | if (msg == EVENT_QUERY_SUPPORTED) { |
| 353 | setSupportedMode(values); |
| 354 | if (getDigitalVal.size() > 5) { |
| 355 | RLOGD("The Modem support Lte extend band"); |
| 356 | mIsLteExtend = true; |
| 357 | } else { |
| 358 | RLOGD("The Modem not support Lte extend band"); |
| 359 | mIsLteExtend = false; |
| 360 | } |
| 361 | } else { |
| 362 | setCurrentMode(values); |
| 363 | } |
| 364 | } else { |
| 365 | android::emResultNotify(RET_STRING_BANDMODE_FAIL); |
| 366 | RLOGD("getDigitalVal is null"); |
| 367 | } |
| 368 | } |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | static void printGetBand(int flag) { |
| 373 | RLOGD("printGetBand(%d), fgset(%d)", flag, fgset); |
| 374 | if(fgset) { |
| 375 | return; |
| 376 | } |
| 377 | if(flag == EVENT_QUERY_CURRENT) { |
| 378 | RLOGD("printGetBand start"); |
| 379 | std::string msg; |
| 380 | for (auto& i : mModeArray) { |
| 381 | if (i.mEnable && i.mCheck) { |
| 382 | if ((i.mIndex == INDEX_GSM_BAND) && (msg.find("GSM Mode:") == std::string::npos)) { |
| 383 | msg.append("GSM Mode:\n"); |
| 384 | } else if ((i.mIndex == INDEX_UMTS_BAND) && (msg.find("UMTS Mode:") == std::string::npos)) { |
| 385 | msg.append("\nUMTS Mode:\n"); |
| 386 | } else if ((i.mIndex >= INDEX_LTE_FDD_BAND) && (i.mIndex <= INDEX_LTE_BAND_256) && (msg.find("LTE Mode:") == std::string::npos)) { |
| 387 | msg.append("\nLTE Mode:\n"); |
| 388 | } |
| 389 | |
| 390 | msg.append("...."); |
| 391 | msg.append(i.mName); |
| 392 | msg.append("\n"); |
| 393 | } |
| 394 | } |
| 395 | for (auto& i : mCdmaModeArray) { |
| 396 | if (i.mEnable && i.mCheck) { |
| 397 | if ((i.mIndex == INDEX_CDMA_BAND) && (msg.find("CDMA Mode:") == std::string::npos)) { |
| 398 | msg.append("\nCDMA Mode: \n"); |
| 399 | } |
| 400 | msg.append("...."); |
| 401 | msg.append(i.mName); |
| 402 | msg.append("\n"); |
| 403 | } |
| 404 | } |
| 405 | msg.append("done\n"); |
| 406 | android::emResultNotify(msg.c_str()); |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | static void setBandModeCdma(const long value) { |
| 411 | RLOGD("setCdmaBandMode: %d", value); |
| 412 | string msg = SET_COMMAND_CDMA + std::to_string(value); |
| 413 | sendATCommand(msg.c_str(), EVENT_SET_CDMA); |
| 414 | } |
| 415 | |
| 416 | /** |
| 417 | * Set the selected modes. |
| 418 | * |
| 419 | * @param values the integers of mode values |
| 420 | * @return false means set failed or success |
| 421 | */ |
| 422 | static void setBandMode(std::vector<long> values) { |
| 423 | RLOGD("setBandMode values: %ld,%ld,%ld,%ld", values[0],values[1],values[2],values[3]); |
| 424 | if (values[0] > GSM_MAX_VALUE |
| 425 | || values[1] > UMTS_MAX_VALUE |
| 426 | || values[2] > LTE_MAX_VALUE |
| 427 | || values[3] > LTE_MAX_VALUE) { |
| 428 | android::emResultNotify(RET_STRING_BANDMODE_FAIL); |
| 429 | RLOGD("setBandMode,just return"); |
| 430 | return; |
| 431 | } |
| 432 | |
| 433 | std::vector<std::string> modeString {SET_COMMAND + std::to_string(values[0]) + std::string(",") + std::to_string(values[1]), ""}; |
| 434 | if (ModemCategory::isLteSupport()) { |
| 435 | modeString[0] += std::string(",") + std::to_string(values[2]) + std::string(",") + std::to_string(values[3]); |
| 436 | if (mIsLteExtend) { |
| 437 | for (int i = 4; i < INDEX_BAND_MAX - 1; i++) { |
| 438 | modeString[0] += std::string(",") + std::to_string(values[i]); |
| 439 | } |
| 440 | } |
| 441 | } |
| 442 | RLOGD("setGsmBandMode AT String: %s", modeString[0].c_str()); |
| 443 | sendATCommand(modeString[0].c_str(), EVENT_SET_GSM); |
| 444 | } |
| 445 | |
| 446 | static long getValFromBoxCdma() { |
| 447 | long value = 0; |
| 448 | for (auto& m : mCdmaModeArray) { |
| 449 | if (m.mCheck) { |
| 450 | value |= 1L << m.mBit; |
| 451 | } |
| 452 | } |
| 453 | return value; |
| 454 | } |
| 455 | |
| 456 | /** |
| 457 | * Get the selected mode values. |
| 458 | * |
| 459 | * @return values from the selected boxes |
| 460 | */ |
| 461 | static std::vector<long> getValFromBox(bool judge) { |
| 462 | std::vector<long> values(INDEX_BAND_MAX,0); |
| 463 | std::vector<long> values_temp(INDEX_BAND_MAX,0); |
| 464 | for (auto& m : mModeArray) { |
| 465 | if (m.mCheck) { |
| 466 | values[m.mIndex] |= 1L << m.mBit; |
| 467 | values_temp[m.mIndex] |= 1L << m.mBit; |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | if (judge) { |
| 472 | // band64 to band256 belongs to lte fdd, so check null together |
| 473 | for (int i = INDEX_LTE_BAND_96; i <= INDEX_LTE_BAND_256; i++) { |
| 474 | values_temp[INDEX_LTE_FDD_BAND] = values_temp[INDEX_LTE_FDD_BAND] | values_temp[i]; |
| 475 | } |
| 476 | // check FDD and TDD ,only all null is invalid |
| 477 | values_temp[INDEX_LTE_FDD_BAND] = values_temp[INDEX_LTE_FDD_BAND] | values_temp[INDEX_LTE_TDD_BAND]; |
| 478 | values_temp[INDEX_LTE_TDD_BAND] = values_temp[INDEX_LTE_FDD_BAND]; |
| 479 | |
| 480 | // null select is not allowed. |
| 481 | if (values[0] == 0) { |
| 482 | values[0] = GSM_MAX_VALUE; |
| 483 | } |
| 484 | if (values[1] == 0) { |
| 485 | values[1] = UMTS_MAX_VALUE; |
| 486 | } |
| 487 | if (values_temp[2] == 0 && values_temp[3] == 0) { |
| 488 | values[2] = LTE_MAX_VALUE; |
| 489 | values[3] = LTE_MAX_VALUE; |
| 490 | RLOGD("lte not to null"); |
| 491 | } |
| 492 | } |
| 493 | return values; |
| 494 | } |
| 495 | |
| 496 | static void printSupportBand(int flag) { |
| 497 | RLOGD("printSupportBand, fgset(%d), count(%d), flag(%d)",fgset, count, flag); |
| 498 | if(fgset && (count == 0) && (flag == EVENT_QUERY_CURRENT)) { |
| 499 | RLOGD("printSupportBand start"); |
| 500 | std::string msg; |
| 501 | for (auto& i : mModeArray) { |
| 502 | if (i.mEnable) { |
| 503 | if ((i.mIndex == INDEX_GSM_BAND) && (msg.find("GSM Mode:") == std::string::npos)) { |
| 504 | msg.append("GSM Mode:\n"); |
| 505 | } else if ((i.mIndex == INDEX_UMTS_BAND) && (msg.find("UMTS Mode:") == std::string::npos)) { |
| 506 | msg.append("\nUMTS Mode:\n"); |
| 507 | } else if ((i.mIndex >= INDEX_LTE_FDD_BAND) && (i.mIndex <= INDEX_LTE_BAND_256) && (msg.find("LTE Mode:") == std::string::npos)) { |
| 508 | msg.append("\nLTE Mode:\n"); |
| 509 | } |
| 510 | |
| 511 | msg.append("...."); |
| 512 | msg.append("("); |
| 513 | msg.append(std::to_string(i.mIndex)); |
| 514 | msg.append("."); |
| 515 | msg.append(std::to_string(i.mBit)); |
| 516 | msg.append("): "); |
| 517 | msg.append(i.mName); |
| 518 | msg.append("...."); |
| 519 | msg.append(i.mCheck ? "true":"false"); |
| 520 | msg.append("\n"); |
| 521 | } |
| 522 | } |
| 523 | for (auto& i : mCdmaModeArray) { |
| 524 | if (i.mEnable) { |
| 525 | if ((i.mIndex == INDEX_CDMA_BAND) && (msg.find("CDMA Mode:") == std::string::npos)) { |
| 526 | msg.append("\nCDMA Mode: \n"); |
| 527 | } |
| 528 | msg.append("...."); |
| 529 | msg.append("("); |
| 530 | msg.append(std::to_string(i.mIndex)); |
| 531 | msg.append("."); |
| 532 | msg.append(std::to_string(i.mBit)); |
| 533 | msg.append("): "); |
| 534 | msg.append(i.mName); |
| 535 | msg.append("...."); |
| 536 | msg.append(i.mIndex ? "true":"false"); |
| 537 | msg.append("\n"); |
| 538 | } |
| 539 | } |
| 540 | msg.append("done\n"); |
| 541 | android::emResultNotify(msg.c_str()); |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | static void* setGsmBandMode(void* arg) { |
| 546 | setBandMode(gsmValues); |
| 547 | return NULL; |
| 548 | } |
| 549 | |
| 550 | static void* setCdmaBandMode(void* arg) { |
| 551 | setBandModeCdma(cdmaValues); |
| 552 | return NULL; |
| 553 | } |
| 554 | |
| 555 | static void emBandmodeAtCmdHandle(char* response, int responselen) { |
| 556 | RLOGD("emBandmodeAtCmdHandle, flag=%d, data=%s", mCurrentEmbandmodeFlag, response); |
| 557 | switch (mCurrentEmbandmodeFlag) { |
| 558 | case EVENT_QUERY_CURRENT_CDMA: { |
| 559 | if ((responselen > 0) && (response != NULL)) { |
| 560 | showBandModeCdma(response, EVENT_QUERY_CURRENT_CDMA); |
| 561 | } else { |
| 562 | android::emResultNotify(RET_STRING_BANDMODE_FAIL); |
| 563 | RLOGD("don't support(%d)", EVENT_QUERY_CURRENT_CDMA); |
| 564 | } |
| 565 | BLOCK_WAKEUP(); |
| 566 | break; |
| 567 | } |
| 568 | case EVENT_QUERY_SUPPORTED: |
| 569 | { |
| 570 | if ((responselen > 0) && (response != NULL)) { |
| 571 | showBandModeGsm(response, EVENT_QUERY_SUPPORTED); |
| 572 | } else { |
| 573 | android::emResultNotify(RET_STRING_BANDMODE_FAIL); |
| 574 | RLOGD("don't support(%d)", EVENT_QUERY_SUPPORTED); |
| 575 | } |
| 576 | BLOCK_WAKEUP(); |
| 577 | break; |
| 578 | } |
| 579 | case EVENT_QUERY_CURRENT: |
| 580 | { |
| 581 | if ((responselen > 0) && (response != NULL)) { |
| 582 | showBandModeGsm(response, EVENT_QUERY_CURRENT); |
| 583 | } else { |
| 584 | android::emResultNotify(RET_STRING_BANDMODE_FAIL); |
| 585 | RLOGD("don't support(%d)", EVENT_QUERY_CURRENT); |
| 586 | } |
| 587 | printGetBand(EVENT_QUERY_CURRENT); |
| 588 | printSupportBand(EVENT_QUERY_CURRENT); |
| 589 | BLOCK_WAKEUP(); |
| 590 | if(fgset && (count > 0)) { |
| 591 | for(auto& val : choose_vals) { |
| 592 | RLOGD("handle values: %s", val.c_str()); |
| 593 | std::vector<std::string> out; |
| 594 | utils::tokenize(val, "=", out); |
| 595 | if(out.size() == 2) { |
| 596 | std::vector<std::string> indexs; |
| 597 | utils::tokenize(out[0], ".", indexs); |
| 598 | if(indexs.size() == 2) { |
| 599 | try { |
| 600 | int index = std::stoi(indexs[0]); |
| 601 | int bit = std::stoi(indexs[1]); |
| 602 | bool check = std::stoi(out[1]) > 0 ? true : false; |
| 603 | for (auto& i : mModeArray) { |
| 604 | if((i.mIndex == index) && (i.mBit == bit)) { |
| 605 | i.mCheck = check; |
| 606 | RLOGD("set gsm band: lales=%s, index=%d, bit=%d, enable=%d, check=%d", |
| 607 | i.mName.c_str(),i.mIndex, i.mBit, i.mEnable, i.mCheck); |
| 608 | } |
| 609 | } |
| 610 | for (auto& i : mCdmaModeArray) { |
| 611 | if((i.mIndex == index) && (i.mBit == bit)) { |
| 612 | if((i.mIndex == index) && (i.mBit == bit)) { |
| 613 | i.mCheck = check; |
| 614 | RLOGD("set gsm band: lales=%s, index=%d, bit=%d, enable=%d, check=%d", |
| 615 | i.mName.c_str(),i.mIndex, i.mBit, i.mEnable, i.mCheck); |
| 616 | } |
| 617 | } |
| 618 | } |
| 619 | } catch (const out_of_range &e) { |
| 620 | RLOGD("out of range: %s", e.what()); |
| 621 | } catch (const invalid_argument &e) { |
| 622 | RLOGD("invalid argument: %s", e.what()); |
| 623 | } |
| 624 | }else { |
| 625 | RLOGD("invalid parameters: %s", out[0].c_str()); |
| 626 | android::emResultNotify(RET_STRING_BANDMODE_FAIL); |
| 627 | return; |
| 628 | } |
| 629 | |
| 630 | } else { |
| 631 | RLOGD("invalid parameters: %s", val.c_str()); |
| 632 | android::emResultNotify(RET_STRING_BANDMODE_FAIL); |
| 633 | return; |
| 634 | } |
| 635 | } |
| 636 | cdmaValues = getValFromBoxCdma(); |
| 637 | gsmValues = getValFromBox(true); |
| 638 | pthread_t setBandMode_thread; |
| 639 | pthread_create(&setBandMode_thread,NULL, setGsmBandMode, NULL); |
| 640 | } |
| 641 | break; |
| 642 | } |
| 643 | case EVENT_SET_GSM: |
| 644 | { |
| 645 | BLOCK_WAKEUP(); |
| 646 | if ((responselen > 0) && (response != NULL)) { |
| 647 | RLOGD("Set Gsm bandmode success: %s", response); |
| 648 | if ((mSimType == 0) && ModemCategory::isCdma() && (!utils::is90Modem())) { |
| 649 | pthread_t setBandMode_thread; |
| 650 | pthread_create(&setBandMode_thread,NULL, setCdmaBandMode, NULL); |
| 651 | } else { |
| 652 | RLOGD("don't support cdma, response"); |
| 653 | android::emResultNotify(RET_STRING_BANDMODE_SUCCESS); |
| 654 | } |
| 655 | } else { |
| 656 | RLOGD("send gsm fail "); |
| 657 | android::emResultNotify(RET_STRING_BANDMODE_FAIL); |
| 658 | } |
| 659 | break; |
| 660 | } |
| 661 | case EVENT_SET_CDMA: |
| 662 | { |
| 663 | BLOCK_WAKEUP(); |
| 664 | if ((responselen > 0) && (response != NULL)) { |
| 665 | RLOGD("Set cdma bandmode success: %s", response); |
| 666 | android::emResultNotify(RET_STRING_BANDMODE_SUCCESS); |
| 667 | } else { |
| 668 | RLOGD("send cdma fail "); |
| 669 | android::emResultNotify(RET_STRING_BANDMODE_FAIL); |
| 670 | } |
| 671 | break; |
| 672 | } |
| 673 | default: |
| 674 | break; |
| 675 | } |
| 676 | } |
| 677 | |
| 678 | static void queryCurrentCdmaMode() { |
| 679 | if (utils::is93Modem()) { |
| 680 | //SAME_COMMAND_CDMA; |
| 681 | RLOGD("queryCurrentCdmaMode: %s", QUERY_CURRENT_COMMAND_CDMA.c_str()); |
| 682 | sendATCommand(QUERY_CURRENT_COMMAND_CDMA.c_str(), EVENT_QUERY_CURRENT_CDMA); |
| 683 | } else { |
| 684 | android::emResultNotify(RET_STRING_BANDMODE_FAIL); |
| 685 | RLOGD("don't support"); |
| 686 | } |
| 687 | } |
| 688 | |
| 689 | /** |
| 690 | * Query Modem supported band modes. |
| 691 | */ |
| 692 | static void querySupportMode() { |
| 693 | //SAME_COMMAND |
| 694 | RLOGD("querySupportMode AT String: %s", QUERY_SUPPORT_COMMAND.c_str()); |
| 695 | sendATCommand(QUERY_SUPPORT_COMMAND.c_str(), EVENT_QUERY_SUPPORTED); |
| 696 | } |
| 697 | |
| 698 | /** |
| 699 | * Query Modem is being used band modes. |
| 700 | */ |
| 701 | static void queryCurrentMode() { |
| 702 | //SAME_COMMAND |
| 703 | RLOGD("queryCurrentMode AT String: %s", QUERY_CURRENT_COMMAND.c_str()); |
| 704 | sendATCommand(QUERY_CURRENT_COMMAND.c_str(), EVENT_QUERY_CURRENT); |
| 705 | } |
| 706 | |
| 707 | static void initGsmArray() { |
| 708 | for (int i = 0; i < band_mode_gsm.size(); i++) { |
| 709 | mModeArray.emplace_back(band_mode_gsm[i], INDEX_GSM_BAND, GSM_BAND_BIT[i], false, false); |
| 710 | } |
| 711 | } |
| 712 | |
| 713 | static void initLteArray() { |
| 714 | for (int i = 0; i < band_mode_lte_fdd.size(); i++) { |
| 715 | mModeArray.emplace_back(band_mode_lte_fdd[i], INDEX_LTE_FDD_BAND, i, false, false); |
| 716 | } |
| 717 | for (int i = 0; i < band_mode_lte_tdd.size(); i++) { |
| 718 | mModeArray.emplace_back(band_mode_lte_tdd[i], INDEX_LTE_TDD_BAND, i, false, false); |
| 719 | } |
| 720 | for (int i = 0; i < band_mode_lte_96.size(); i++) { |
| 721 | mModeArray.emplace_back(band_mode_lte_96[i], INDEX_LTE_BAND_96, i, false, false); |
| 722 | } |
| 723 | for (int i = 0; i < band_mode_lte_128.size(); i++) { |
| 724 | mModeArray.emplace_back(band_mode_lte_128[i], INDEX_LTE_BAND_128, i, false, false); |
| 725 | } |
| 726 | for (int i = 0; i < band_mode_lte_160.size(); i++) { |
| 727 | mModeArray.emplace_back(band_mode_lte_160[i], INDEX_LTE_BAND_160, i, false, false); |
| 728 | } |
| 729 | for (int i = 0; i < band_mode_lte_192.size(); i++) { |
| 730 | mModeArray.emplace_back(band_mode_lte_192[i], INDEX_LTE_BAND_192, i, false, false); |
| 731 | } |
| 732 | for (int i = 0; i < band_mode_lte_224.size(); i++) { |
| 733 | mModeArray.emplace_back(band_mode_lte_224[i], INDEX_LTE_BAND_224, i, false, false); |
| 734 | } |
| 735 | for (int i = 0; i < band_mode_lte_256.size(); i++) { |
| 736 | mModeArray.emplace_back(band_mode_lte_256[i], INDEX_LTE_BAND_256, i, false, false); |
| 737 | } |
| 738 | } |
| 739 | |
| 740 | static void initTdscdmaArray() { |
| 741 | for (int i = 0; i < band_mode_tdscdma.size(); i++) { |
| 742 | mModeArray.emplace_back(band_mode_tdscdma[i], INDEX_UMTS_BAND, i, false, false); |
| 743 | } |
| 744 | } |
| 745 | |
| 746 | static void initWcdmaArray() { |
| 747 | for (int i = 0; i < band_mode_wcdma.size(); i++) { |
| 748 | mModeArray.emplace_back(band_mode_wcdma[i], INDEX_UMTS_BAND, i, false, false); |
| 749 | } |
| 750 | } |
| 751 | |
| 752 | static void initCdmaArray() { |
| 753 | for (int i = 0; i < band_mode_cdma.size(); i++) { |
| 754 | mCdmaModeArray.emplace_back(band_mode_cdma[i], INDEX_CDMA_BAND, i, false, false); |
| 755 | } |
| 756 | } |
| 757 | |
| 758 | static void * emBandmodeThread(void* arg) |
| 759 | { |
| 760 | mModeArray.clear(); |
| 761 | mCdmaModeArray.clear(); |
| 762 | initGsmArray(); |
| 763 | int modemType = ModemCategory::getModemType(); |
| 764 | if (modemType == TDSCDMA && ModemCategory::isCapabilitySim(mSimType)) { |
| 765 | initTdscdmaArray(); |
| 766 | if (ModemCategory::isLteSupport()) { |
| 767 | initLteArray(); |
| 768 | } |
| 769 | } else if (modemType == WCDMA && ModemCategory::isCapabilitySim(mSimType)) { |
| 770 | initWcdmaArray(); |
| 771 | if (ModemCategory::isLteSupport()) { |
| 772 | initLteArray(); |
| 773 | } |
| 774 | } else if (!(ModemCategory::isCapabilitySim(mSimType))) { |
| 775 | if (ModemCategory::checkViceSimCapability(mSimType, MtkRadioAccessFamily::RAF_UMTS)) { |
| 776 | initWcdmaArray(); |
| 777 | } |
| 778 | if (ModemCategory::checkViceSimCapability(mSimType, MtkRadioAccessFamily::RAF_LTE)) { |
| 779 | if (ModemCategory::isLteSupport()) { |
| 780 | initLteArray(); |
| 781 | } |
| 782 | } |
| 783 | } |
| 784 | |
| 785 | if (mSimType == 0 && ModemCategory::isCdma() && !utils::is90Modem()) { |
| 786 | initCdmaArray(); |
| 787 | } |
| 788 | if (ModemCategory::isCdma() && !utils::is90Modem() && (mSimType == 0)) { |
| 789 | queryCurrentCdmaMode(); |
| 790 | } |
| 791 | querySupportMode(); |
| 792 | queryCurrentMode(); |
| 793 | pthread_exit(0); |
| 794 | } |
| 795 | |
| 796 | //AT+EPBSE=gsm,umts,ltefdd,ltetdd |
| 797 | int emBandmodeStart(int len,int *item,int multilen,char *value[]) |
| 798 | { |
| 799 | mSimType = get_default_sim_all_except_data(); |
| 800 | RLOGD("emBandmodeStart called : simType:%d", mSimType); |
| 801 | //1. reset to default: select all supported bands: AT+EPBSE=255,63355 |
| 802 | if(len < 1) |
| 803 | { |
| 804 | RLOGD("emBandmodeStart: please select mode to test: 0: get, 1: set "); |
| 805 | android::emResultNotify(RET_STRING_BANDMODE_FAIL); |
| 806 | return -1; |
| 807 | } |
| 808 | if((item[0] > 1 ) || (item[0] < 0)){ |
| 809 | RLOGD("emBandmodeStart: invalid parameter %d",item[0]); |
| 810 | android::emResultNotify(RET_STRING_BANDMODE_FAIL); |
| 811 | return -1; |
| 812 | } |
| 813 | if(item[0] == 0){ |
| 814 | fgset = false; |
| 815 | }else{ |
| 816 | fgset = true; |
| 817 | count = multilen; |
| 818 | RLOGD("emBandmodeStart count = %d", count); |
| 819 | choose_vals.clear(); |
| 820 | if(count > 0){ |
| 821 | for(int i=0; i< count; i++) { |
| 822 | choose_vals.push_back(value[i]); |
| 823 | } |
| 824 | } |
| 825 | } |
| 826 | mCurrentEmbandmodeFlag = 0; |
| 827 | android::registerForATcmdResponse(emBandmodeAtCmdHandle); |
| 828 | pthread_t embandmode_thread; |
| 829 | pthread_create(&embandmode_thread,NULL, emBandmodeThread, NULL); |
| 830 | return (0); |
| 831 | } |
| 832 | #endif |
| 833 | |