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 <vector> |
| 38 | |
| 39 | #include "common.h" |
| 40 | #include "em/em.h" |
| 41 | #include "Radio_capability_switch_util.h" |
| 42 | |
| 43 | #if EM_MODE_SUPPORT |
| 44 | |
| 45 | #undef LOG_TAG |
| 46 | #define LOG_TAG "EM_C2KMODEMSETTING" |
| 47 | const int TIME_REG = 0; |
| 48 | |
| 49 | const static int MSG_SET_DISABLE_1X_TIME = 1; |
| 50 | const static int MSG_SET_ENABLE_1X_TIME = 2; |
| 51 | const static int MSG_QUERY_STATUS_1X_TIME = 3; |
| 52 | |
| 53 | int c2kmodemsetting_id = -1; |
| 54 | //int c2kmodemsetting_option_cnt = -1; |
| 55 | int c2kmodemsetting_option[8] = { 0 }; |
| 56 | |
| 57 | int mCurrentC2KEmmodemSettingFlag = -1; |
| 58 | static void sendATCommand(const char *cmd, int msg) { |
| 59 | mCurrentC2KEmmodemSettingFlag = msg; |
| 60 | emSendATCommand(cmd,Radio_capability_switch_util::get_main_capability_phone_id()); |
| 61 | return; |
| 62 | } |
| 63 | |
| 64 | static void set1XTime(int command, int msg) { |
| 65 | std::vector<std::string> cmdOri(3); |
| 66 | cmdOri[0] = "AT+ECREGTYPE=0," + std::to_string((command == 1 ? 1 : 0)); |
| 67 | cmdOri[1] = ""; |
| 68 | cmdOri[2] = "DESTRILD:C2K"; |
| 69 | std::vector<std::string> cmds = getCdmaCmdArr(cmdOri); |
| 70 | std::string cmd; |
| 71 | for (auto s : cmds) { |
| 72 | cmd += s; |
| 73 | } |
| 74 | RLOGD("set1XTime AT command: %s", cmd); |
| 75 | sendATCommand(cmd.c_str(), msg); |
| 76 | } |
| 77 | |
| 78 | static void emC2kModemSetingsAtCmdHandle(char*response, int responselen) { |
| 79 | switch (mCurrentC2KEmmodemSettingFlag) { |
| 80 | case MSG_SET_DISABLE_1X_TIME: { |
| 81 | if ((responselen > 0) && (response != NULL)) { |
| 82 | RLOGD("Disable_Time_REG successful"); |
| 83 | emResultNotifyWithDone("Disable_Time_REG successful"); |
| 84 | } else { |
| 85 | RLOGD("Disable_Time_REG failed."); |
| 86 | emResultNotifyWithDone("Disable_Time_REG failed."); |
| 87 | } |
| 88 | break; |
| 89 | } |
| 90 | case MSG_SET_ENABLE_1X_TIME: { |
| 91 | if ((responselen > 0) && (response != NULL)) { |
| 92 | RLOGD("Enable_Time_REG successful."); |
| 93 | emResultNotifyWithDone("Enable_Time_REG successful."); |
| 94 | } else { |
| 95 | RLOGD("Enable_Time_REG failed."); |
| 96 | emResultNotifyWithDone("Enable_Time_REG failed."); |
| 97 | } |
| 98 | break; |
| 99 | } |
| 100 | case MSG_QUERY_STATUS_1X_TIME: |
| 101 | break; |
| 102 | default: |
| 103 | break; |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | static void * emC2kModemSettingThread(void* arg) { |
| 108 | RLOGD("c2k Modem Setting: %d ", c2kmodemsetting_option[0]); |
| 109 | switch (c2kmodemsetting_id) { |
| 110 | case TIME_REG: { |
| 111 | set1XTime(c2kmodemsetting_option[0], |
| 112 | (c2kmodemsetting_option[0] ? |
| 113 | MSG_SET_ENABLE_1X_TIME : MSG_SET_DISABLE_1X_TIME)); |
| 114 | break; |
| 115 | } |
| 116 | default: |
| 117 | break; |
| 118 | } |
| 119 | pthread_exit(0); |
| 120 | } |
| 121 | |
| 122 | int emC2kModemSettingStart(int argc, int multicnt, int *item) { |
| 123 | RLOGD("emC2kModemSettingStart called"); |
| 124 | int idmapping[1] = { TIME_REG }; |
| 125 | c2kmodemsetting_id = idmapping[item[0]]; |
| 126 | c2kmodemsetting_option[0] = item[1]; |
| 127 | android::registerForATcmdResponse(emC2kModemSetingsAtCmdHandle); |
| 128 | pthread_t emC2kModemSetting_thread; |
| 129 | pthread_create(&emC2kModemSetting_thread, NULL, emC2kModemSettingThread, |
| 130 | NULL); |
| 131 | return 0; |
| 132 | } |
| 133 | #endif /*EM_MODE_SUPPORT*/ |
| 134 | |