rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | //SPDX-License-Identifier: MediaTekProprietary |
| 2 | /* Copyright Statement: |
| 3 | * |
| 4 | * This software/firmware and related documentation ("MediaTek Software") are |
| 5 | * protected under relevant copyright laws. The information contained herein |
| 6 | * is confidential and proprietary to MediaTek Inc. and/or its licensors. |
| 7 | * Without the prior written permission of MediaTek inc. and/or its licensors, |
| 8 | * any reproduction, modification, use or disclosure of MediaTek Software, |
| 9 | * and information contained herein, in whole or in part, shall be strictly prohibited. |
| 10 | */ |
| 11 | /* MediaTek Inc. (C) 2010. All rights reserved. |
| 12 | * |
| 13 | * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES |
| 14 | * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE") |
| 15 | * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON |
| 16 | * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES, |
| 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT. |
| 19 | * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE |
| 20 | * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR |
| 21 | * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH |
| 22 | * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES |
| 23 | * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES |
| 24 | * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK |
| 25 | * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR |
| 26 | * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND |
| 27 | * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE, |
| 28 | * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE, |
| 29 | * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO |
| 30 | * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. |
| 31 | * |
| 32 | * The following software/firmware and/or related documentation ("MediaTek Software") |
| 33 | * have been modified by MediaTek Inc. All revisions are subject to any receiver's |
| 34 | * applicable license agreements with MediaTek Inc. |
| 35 | */ |
| 36 | #include "ecall/eCall.h" |
| 37 | |
| 38 | #include <vendor-ril/telephony/ril.h> |
| 39 | #include <string> |
| 40 | #include <vector> |
| 41 | #include <glib.h> |
| 42 | #include <cutils/jstring.h> |
| 43 | #include <time.h> |
| 44 | #include <signal.h> |
| 45 | #include <pthread.h> |
| 46 | #include <string.h> |
| 47 | #include <memory> |
| 48 | |
| 49 | #include "util/utils.h" |
| 50 | #include "cc.h" |
| 51 | #include "common.h" |
| 52 | #include "sms/sms.h" |
| 53 | #include "sms/gsm/sms_pdu.h" |
| 54 | #include "./gost/utils/GostEcallUtils.h" |
| 55 | #include "./gost/sslp/SslpManager.h" |
| 56 | #include "./gost/sslp/ecall/EcallUtils.h" |
| 57 | #include "network.h" |
| 58 | |
| 59 | #undef LOG_TAG |
| 60 | #define LOG_TAG "DEMO_ECALL" |
| 61 | #define PROP_ECALL_TEST_CASE "vendor.gost.ecall.ecall_case_test" |
| 62 | #define PROP_ECALL_DEREGIST_TIME "vendor.gost.ecall.nad_deregistration_time_minute" |
| 63 | #define PROP_ECALL_REDIAL_TIMER "vendor.ecall.redial.timer" //default 120s |
| 64 | |
| 65 | int fast_argc = 0; |
| 66 | std::vector<std::string> fast_argv; |
| 67 | int fast_ecall_socket_id = -1; |
| 68 | static ECALL_TYPE ecall_type = ECALL_TYPE::EN16454_ECALL; |
| 69 | static bool inNeedRegister = false; |
| 70 | static bool gostFastEcallFlg = false; |
| 71 | static bool is_ecall_audio_path = false; |
| 72 | |
| 73 | int gost_sms_argc = 0; |
| 74 | std::vector<std::string> gost_sms_argv; |
| 75 | int gost_sms_socket_id = -1; |
| 76 | |
| 77 | typedef enum { |
| 78 | REDIAL_DOING = 1, |
| 79 | REDIAL_SUCCESS = 2, |
| 80 | REDIAL_EXPIRES = 3, |
| 81 | REDIAL_UNKNOWN = 4, |
| 82 | }ecall_redial_status; |
| 83 | |
| 84 | int act_fecall_socid = -1; |
| 85 | int act_feCall_Id = -1; |
| 86 | static ecall_redial_status redial_tag = REDIAL_UNKNOWN; |
| 87 | static bool normal_ecall_tag = false; |
| 88 | |
| 89 | #ifdef ECALL_SUPPORT |
| 90 | extern speech_status getSpeechStatus(); |
| 91 | extern void setSpeechAndStatus(int value); |
| 92 | int resetIVS(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI); |
| 93 | int dialFastEcall(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI); |
| 94 | void start_ecll_timer(timer_t timer, int signal_value, int milliseconds); |
| 95 | //RIL_REQUEST_ECALL_SET_MSD |
| 96 | int setMSD(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI); |
| 97 | int T7GostEcallSmsMsd(sigval_t sig); |
| 98 | int setNadRegState(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI); |
| 99 | int gostStartDeregisterTimer(); |
| 100 | |
| 101 | static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER; |
| 102 | //#define PROP_ECALL_MSD_DATA "vendor.ecall.msd.data" |
| 103 | static char* msd_data = NULL; |
| 104 | |
| 105 | //LOCAL_SET_MSD_DATA_FOR_TEST |
| 106 | int setMsdDateForTest(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI) { |
| 107 | if (argc < 1 || argv[1] == NULL) { |
| 108 | RLOGD("setMsdDateForTest invalid parameters"); |
| 109 | free(pRI); |
| 110 | return -1; |
| 111 | } |
| 112 | char *msd_data_src = (char*) argv[1]; |
| 113 | int len = strlen(msd_data_src); |
| 114 | |
| 115 | if (len % 2 == 1) { |
| 116 | RLOGD("setMsdDateForTest invalid parameters, length is't right"); |
| 117 | free(pRI); |
| 118 | return -1; |
| 119 | } |
| 120 | if(msd_data) { |
| 121 | free(msd_data); |
| 122 | msd_data = NULL; |
| 123 | } |
| 124 | msd_data = strdup(msd_data_src); |
| 125 | RLOGD("setMsdDateForTest() data: %s", (msd_data == NULL ? "": msd_data)); |
| 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | static timer_t sT2; |
| 130 | static timer_t sT5; |
| 131 | static timer_t sT6; |
| 132 | static timer_t sT7; |
| 133 | static timer_t sRedialTimer; |
| 134 | static timer_t sAutoAnsTimer; |
| 135 | static timer_t gostResendMsdTimer; |
| 136 | static timer_t gostDeregistrationTimer; |
| 137 | |
| 138 | #define T2_TIMEOUT 60*60*1000 |
| 139 | #define T5_TIMEOUT 5*1000 |
| 140 | #define T6_TIMEOUT 5*1000 |
| 141 | #define T7_TIMEOUT 20*1000 |
| 142 | //#define REDIAL_TIMEOUT 2*60*1000 |
| 143 | #define AUTOANS_TIMEOUT 60*60*1000 |
| 144 | |
| 145 | static int sT2_sig_value = 2; |
| 146 | static int sT5_sig_value = 5; |
| 147 | static int sT6_sig_value = 6; |
| 148 | static int sT7_sig_value = 7; |
| 149 | static int redial_sig_value = 8; |
| 150 | static int autoAns_sig_value = 9; |
| 151 | static int gost_resend_msd_value = 11; |
| 152 | static int gost_deregistration_value = 12; |
| 153 | |
| 154 | bool isEcallAudioPath() { |
| 155 | RLOGD("%s , is_ecall_audio_path: %d", __FUNCTION__, is_ecall_audio_path); |
| 156 | return is_ecall_audio_path; |
| 157 | } |
| 158 | |
| 159 | bool isEcallAutoanswerTimerFinish() { |
| 160 | struct itimerspec timespec; |
| 161 | if(timer_gettime(sAutoAnsTimer, ×pec) == -1) { |
| 162 | RLOGD("%s(), get time fail(%s)", __FUNCTION__, strerror(errno)); |
| 163 | return true; |
| 164 | } |
| 165 | RLOGD("%s(), tv_sec=%ld, tv_nsec=%ld", __FUNCTION__,timespec.it_value.tv_sec, timespec.it_value.tv_nsec); |
| 166 | if((timespec.it_value.tv_sec == 0) && (timespec.it_value.tv_nsec == 0) ) { |
| 167 | RLOGD("%s(), timer_id(%ld) had stopped", __FUNCTION__, (long)sAutoAnsTimer); |
| 168 | return true; |
| 169 | } |
| 170 | return false; |
| 171 | } |
| 172 | |
| 173 | void setEcallAudioPathOn(bool on) { |
| 174 | RLOGD("%s() , is_ecall_audio_path: %d, on: %d", __FUNCTION__, is_ecall_audio_path, on); |
| 175 | |
| 176 | if((is_ecall_audio_path != on) && (isEcallAutoanswerTimerFinish())) { |
| 177 | is_ecall_audio_path = on; |
| 178 | } |
| 179 | RLOGD("%s() , is_ecall_audio_path: %d", __FUNCTION__, is_ecall_audio_path); |
| 180 | } |
| 181 | |
| 182 | void autoAnswerEcall(bool on) { |
| 183 | RLOGD("%s() , is_ecall_audio_path: %d, on: %d", __FUNCTION__, is_ecall_audio_path, on); |
| 184 | if(is_ecall_audio_path != on) { |
| 185 | is_ecall_audio_path = on; |
| 186 | } |
| 187 | if(on) { |
| 188 | char* argv[2] = {"", "1"}; |
| 189 | autoAnswerCall(2, argv, RIL_SOCKET_ID(0), NULL); //unused socket id; |
| 190 | } else { |
| 191 | char* argv[2] = {"", "0"}; |
| 192 | autoAnswerCall(2, argv, RIL_SOCKET_ID(0), NULL); //unused socket id; |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | void saveFastEcallData(int argc, char** argv ,RIL_SOCKET_ID id) { |
| 197 | fast_ecall_socket_id = id; |
| 198 | fast_argc = argc; |
| 199 | fast_argv.clear(); |
| 200 | for(int i = 0; i < argc; i++) { |
| 201 | RLOGD("fast_argv[%d] = %s", i, (argv[i]==NULL)? "NULL":argv[i]); |
| 202 | fast_argv.push_back(argv[i]); |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | void resetEcallIVSandAudio(int mode, RIL_SOCKET_ID id) { |
| 207 | RequestInfo* pRI = creatRILInfoAndInit(RIL_REQUEST_ECALL_RESET_IVS, mode, id); |
| 208 | resetIVS(0, NULL, id, pRI); |
| 209 | // char* argv[2] = { "RIL_REQUEST_SET_MUTE", "0" }; |
| 210 | // setMute(2, argv, id, NULL); |
| 211 | } |
| 212 | |
| 213 | void ecall_timer_handler(sigval_t sig) { |
| 214 | RLOGD("ecall_timer_handler, sig_value: %d", sig.sival_int); |
| 215 | int s; |
| 216 | s = pthread_mutex_lock(&mtx); |
| 217 | if(s != 0) { |
| 218 | RLOGE("ecall_timer_handler, pthead_mutex_lock fail"); |
| 219 | } |
| 220 | if(sig.sival_int == sT2_sig_value) { |
| 221 | RLOGD("T2 timeout, call_Id=%d, socket_id=%d", act_feCall_Id, act_fecall_socid); |
| 222 | if(act_feCall_Id == -1 || act_fecall_socid == -1) { |
| 223 | goto done; |
| 224 | } |
| 225 | RequestInfo* pRI = creatRILInfoAndInit(RIL_REQUEST_HANGUP, UDP, RIL_SOCKET_ID(act_fecall_socid)); |
| 226 | char* id = const_cast<char*>(std::to_string(act_feCall_Id).c_str()); |
| 227 | char* argv[2] = { "RIL_REQUEST_HANGUP", "" }; |
| 228 | argv[1] = id; |
| 229 | hangupConnection(2, argv, RIL_SOCKET_ID(act_fecall_socid), pRI); |
| 230 | act_fecall_socid = -1; |
| 231 | act_feCall_Id = -1; |
| 232 | } else if(sig.sival_int == sT5_sig_value |
| 233 | || sig.sival_int == sT6_sig_value |
| 234 | || sig.sival_int == sT7_sig_value) { |
| 235 | normal_ecall_tag = false; |
| 236 | resetEcallIVSandAudio(UDP, RIL_SOCKET_ID(fast_ecall_socket_id)); |
| 237 | if(0 != T7GostEcallSmsMsd(sig)) |
| 238 | { |
| 239 | if(sig.sival_int == sT5_sig_value || sig.sival_int == sT7_sig_value) { |
| 240 | fast_argc = 0; |
| 241 | fast_argv.clear(); |
| 242 | } |
| 243 | } |
| 244 | } else if(sig.sival_int == redial_sig_value) { |
| 245 | redial_tag = REDIAL_EXPIRES; |
| 246 | RequestInfo* pRI = creatRILInfoAndInit(RIL_REQUEST_ECALL_RESET_IVS, UDP,RIL_SOCKET_ID(fast_ecall_socket_id)); |
| 247 | resetIVS(0, NULL, RIL_SOCKET_ID(fast_ecall_socket_id), pRI); |
| 248 | fast_argc = 0; |
| 249 | fast_argv.clear(); |
| 250 | start_ecll_timer(sAutoAnsTimer, autoAns_sig_value, AUTOANS_TIMEOUT); |
| 251 | autoAnswerEcall(true); |
| 252 | } else if(sig.sival_int == autoAns_sig_value) { |
| 253 | autoAnswerEcall(false); |
| 254 | } else if(sig.sival_int == gost_resend_msd_value) { |
| 255 | //send msd |
| 256 | char** argv = new char*[gost_sms_argv.size()]; |
| 257 | argv[gost_sms_argv.size()] = nullptr; |
| 258 | for(int i=0; i < gost_sms_argv.size(); i++) { |
| 259 | char* temp = new char[gost_sms_argv[i].size()]; |
| 260 | strcpy(temp, gost_sms_argv[i].c_str()); |
| 261 | argv[i] = temp; |
| 262 | } |
| 263 | |
| 264 | RequestInfo *pRI = creatRILInfoAndInit(RIL_REQUEST_SEND_SMS, UDP, (RIL_SOCKET_ID)gost_sms_socket_id); |
| 265 | sendSMS(gost_sms_argc, argv, pRI->socket_id, pRI); |
| 266 | |
| 267 | for(int i=0; i < gost_sms_argv.size(); i++) { |
| 268 | delete argv[i]; |
| 269 | } |
| 270 | delete argv; |
| 271 | } else if(sig.sival_int == gost_deregistration_value) { |
| 272 | RIL_SOCKET_ID id = (RIL_SOCKET_ID)fast_ecall_socket_id; |
| 273 | if(id == -1) { |
| 274 | id = (RIL_SOCKET_ID)get_default_sim_all_except_data(); |
| 275 | } |
| 276 | RequestInfo* pRI = creatRILInfoAndInit(RIL_REQUEST_ECALL_SET_REGISTRATION_STATE, UDP, id); |
| 277 | char* argv[2] = { "RIL_REQUEST_ECALL_SET_REGISTRATION_STATE", "0" }; |
| 278 | setNadRegState(2, argv, id, pRI); |
| 279 | } |
| 280 | else { |
| 281 | RLOGE("ecall_timer_handler, sig_value is invalid!"); |
| 282 | } |
| 283 | done: |
| 284 | s = pthread_mutex_unlock(&mtx); |
| 285 | if(s != 0) { |
| 286 | RLOGE("ecall_timer_handler, pthread_mutex_unlock fail"); |
| 287 | } |
| 288 | |
| 289 | } |
| 290 | |
| 291 | void init_ecall_timer(timer_t* timer, int signal_value) { |
| 292 | |
| 293 | struct sigevent sevp; |
| 294 | memset(&sevp, 0, sizeof(sevp)); |
| 295 | sevp.sigev_value.sival_int = signal_value; |
| 296 | sevp.sigev_notify = SIGEV_THREAD; |
| 297 | sevp.sigev_notify_function = ecall_timer_handler; |
| 298 | |
| 299 | if(timer_create(CLOCK_MONOTONIC, &sevp, timer) == -1) { |
| 300 | RLOGE("init_ecall_timer() failed reason=[%s]", strerror(errno)); |
| 301 | } |
| 302 | RLOGD("init_ecall_timer(), timer_Id = %ld, signal_value=%d", (long)(*timer), signal_value); |
| 303 | } |
| 304 | |
| 305 | void init_ecall_timer_all() { |
| 306 | init_ecall_timer(&sT2,sT2_sig_value); |
| 307 | init_ecall_timer(&sT5,sT5_sig_value); |
| 308 | init_ecall_timer(&sT6,sT6_sig_value); |
| 309 | init_ecall_timer(&sT7,sT7_sig_value); |
| 310 | init_ecall_timer(&sRedialTimer,redial_sig_value); |
| 311 | init_ecall_timer(&sAutoAnsTimer,autoAns_sig_value); |
| 312 | init_ecall_timer(&gostResendMsdTimer,gost_resend_msd_value); |
| 313 | init_ecall_timer(&gostDeregistrationTimer, gost_deregistration_value); |
| 314 | } |
| 315 | |
| 316 | void start_ecll_timer(timer_t timer, int signal_value, int milliseconds) { |
| 317 | RLOGD("start_ecll_timer(), timer_id=%ld, signal_value=%d, time=%d",(long)timer, signal_value, milliseconds); |
| 318 | |
| 319 | struct itimerspec expire; |
| 320 | expire.it_interval.tv_sec = 0; |
| 321 | expire.it_interval.tv_nsec = 0; |
| 322 | expire.it_value.tv_sec = milliseconds/1000; |
| 323 | expire.it_value.tv_nsec = (milliseconds%1000)*1000000; |
| 324 | if (timer_settime(timer, 0, &expire, NULL) == -1) { |
| 325 | RLOGE("timer_settime failed reason=[%s]", strerror(errno)); |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | void stop_ecall_timer(timer_t timer, int signal_value) { |
| 330 | RLOGD("stop_ecall_timer(), timer_id=%ld, signal_value=%d", (long)timer, signal_value); |
| 331 | struct itimerspec timespec; |
| 332 | if(timer_gettime(timer, ×pec) == -1) { |
| 333 | RLOGD("stop_ecall_timer(), get time fail(%s)", strerror(errno)); |
| 334 | return; |
| 335 | } |
| 336 | RLOGD("stop_ecall_timer(), tv_sec=%ld, tv_nsec=%ld",timespec.it_value.tv_sec, timespec.it_value.tv_nsec); |
| 337 | if((timespec.it_value.tv_sec == 0) && (timespec.it_value.tv_nsec == 0) ) { |
| 338 | RLOGD("stop_ecall_timer(), timer_id(%ld) had stopped, just return", (long)timer); |
| 339 | return; |
| 340 | } else { |
| 341 | start_ecll_timer(timer, signal_value, 0); |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | void saveEcallRecord(RIL_ECall_Indication ind) { |
| 346 | std::string str; |
| 347 | if(ind == RIL_UNSOL_ECALL_ALACK_POSITIVE_RECEIVED) { |
| 348 | str = "ECALL_ALACK_POSITIVE_RECEIVED"; |
| 349 | } else if(ind == RIL_UNSOL_ECALL_ALACK_CLEARDOWN_RECEIVED) { |
| 350 | str = "ECALL_ALACK_CLEARDOWN_RECEIVED"; |
| 351 | } else { |
| 352 | str = ""; |
| 353 | } |
| 354 | struct timespec real; |
| 355 | clock_gettime(CLOCK_REALTIME, &real); |
| 356 | RLOGD("saveEcallRecord(%s) tv_s:%ld, tv_ns:%ld",str.c_str(), real.tv_sec, real.tv_nsec); |
| 357 | char utc_time[100]={0}; |
| 358 | strftime(utc_time, sizeof(utc_time), "%D %T", gmtime(&real.tv_sec)); |
| 359 | printf("saveEcallRecord, %s,UTC: data_time=%ld\n", str.c_str(),utc_time); |
| 360 | RLOGD("saveEcallRecord, %s,UTC: data_time=%ld", str.c_str(),utc_time); |
| 361 | char local_time[100]={0}; |
| 362 | struct tm t; |
| 363 | strftime(local_time, sizeof(local_time), "%D %T", localtime_r(&real.tv_sec, &t)); |
| 364 | printf("saveEcallRecord, %s,local: data_time=%ld\n", str.c_str(),local_time); |
| 365 | RLOGD("saveEcallRecord, %s,UTC: data_time=%ld", str.c_str(),utc_time); |
| 366 | } |
| 367 | |
| 368 | void redialFastEcall(RIL_SOCKET_ID socket_id) { |
| 369 | if(isGostEcall()) |
| 370 | { |
| 371 | RLOGD("gost ecall redialFastEcall return for test"); |
| 372 | return; |
| 373 | } |
| 374 | RequestInfo* pRI = creatRILInfoAndInit(RIL_REQUEST_ECALL_FAST_MAKE_ECALL, UDP, socket_id); |
| 375 | char** argv = new char*[fast_argv.size()]; |
| 376 | for(int i=0; i < fast_argv.size(); i++) { |
| 377 | argv[i] = new char[fast_argv[i].size() +1]; |
| 378 | memset(argv[i], 0 , fast_argv[i].size() +1); |
| 379 | strncpy(argv[i], fast_argv[i].c_str(),fast_argv[i].size()); |
| 380 | argv[i][fast_argv[i].size()] = '\0'; |
| 381 | } |
| 382 | |
| 383 | dialFastEcall(fast_argc, argv, socket_id, pRI); |
| 384 | |
| 385 | for(int i=0; i < fast_argv.size(); i++) { |
| 386 | delete [] argv[i]; |
| 387 | } |
| 388 | delete []argv; |
| 389 | } |
| 390 | |
| 391 | void handleEcallIndication(const void* data, int datalen, RIL_SOCKET_ID soc_id) { |
| 392 | if (data == NULL || datalen != sizeof(RIL_Ecall_Unsol_Indications)) { |
| 393 | if (data == NULL) { |
| 394 | RLOGE("handleEcallIndication invalid response: NULL"); |
| 395 | } else { |
| 396 | RLOGE("handleEcallIndication: invalid response length %d expecting len: %d", |
| 397 | sizeof(RIL_Ecall_Unsol_Indications), data); |
| 398 | } |
| 399 | return ; |
| 400 | } |
| 401 | |
| 402 | RIL_Ecall_Unsol_Indications *p_cur = (RIL_Ecall_Unsol_Indications *)data; |
| 403 | RLOGD("handleEcallIndication, call_id: %d, ind: %d",p_cur->call_id, p_cur->ind); |
| 404 | switch(p_cur->ind){ |
| 405 | case RIL_UNSOL_ECALL_SENDING_START: // = 1, |
| 406 | { |
| 407 | RLOGD("handleEcallIndication: normal_ecall_tag=%d", normal_ecall_tag); |
| 408 | if(!normal_ecall_tag){ |
| 409 | //char msd_data[MSD_MAX_LENGTH]= {0}; |
| 410 | //utils::mtk_property_get(PROP_ECALL_MSD_DATA, msd_data, NULL); |
| 411 | RLOGD("msd_data: %s", msd_data==NULL ? "":msd_data); |
| 412 | if(msd_data != NULL) { |
| 413 | // char* arg[2] = { "RIL_REQUEST_SET_MUTE", "1" }; |
| 414 | // setMute(2, arg, soc_id, NULL); |
| 415 | RequestInfo* pRI = creatRILInfoAndInit(RIL_REQUEST_ECALL_SET_MSD, RSPD, soc_id); |
| 416 | char* argv[3] = {"RIL_REQUEST_ECALL_SET_MSD", "", "" }; |
| 417 | argv[1] = const_cast<char*>(std::to_string(p_cur->call_id).c_str()); |
| 418 | argv[2] = msd_data; |
| 419 | setMSD(3, argv, soc_id, pRI); |
| 420 | } |
| 421 | } else { |
| 422 | stop_ecall_timer(sT5, sT5_sig_value); |
| 423 | } |
| 424 | break; |
| 425 | } |
| 426 | case RIL_UNSOL_ECALL_SENDING_MSD: // = 2, |
| 427 | { |
| 428 | start_ecll_timer(sT7,sT7_sig_value, T7_TIMEOUT); |
| 429 | act_fecall_socid = soc_id; |
| 430 | act_feCall_Id = p_cur->call_id; |
| 431 | break; |
| 432 | } |
| 433 | case RIL_UNSOL_ECALL_LLACK_RECEIVED: // = 3, |
| 434 | { |
| 435 | fast_argc = 0; |
| 436 | fast_argv.clear(); |
| 437 | stop_ecall_timer(sT7, sT7_sig_value); |
| 438 | start_ecll_timer(sT6, sT6_sig_value, T6_TIMEOUT); |
| 439 | act_fecall_socid = soc_id; |
| 440 | act_feCall_Id = p_cur->call_id; |
| 441 | normal_ecall_tag = false; |
| 442 | break; |
| 443 | } |
| 444 | case RIL_UNSOL_ECALL_ALACK_POSITIVE_RECEIVED: // = 4, |
| 445 | { |
| 446 | stop_ecall_timer(sT6, sT6_sig_value); |
| 447 | resetEcallIVSandAudio(RSPD, soc_id); |
| 448 | saveEcallRecord(p_cur->ind); |
| 449 | break; |
| 450 | } |
| 451 | case RIL_UNSOL_ECALL_ALACK_CLEARDOWN_RECEIVED: // = 5, |
| 452 | { |
| 453 | stop_ecall_timer(sT6, sT6_sig_value); |
| 454 | stop_ecall_timer(sT2, sT2_sig_value); |
| 455 | resetEcallIVSandAudio(RSPD, soc_id); |
| 456 | saveEcallRecord(p_cur->ind); |
| 457 | RequestInfo* pRI = creatRILInfoAndInit(RIL_REQUEST_HANGUP, RSPD, soc_id); |
| 458 | char* id = const_cast<char*>(std::to_string(p_cur->call_id).c_str()); |
| 459 | char* argv[2] = { "RIL_REQUEST_HANGUP", "" }; |
| 460 | argv[1] = id; |
| 461 | hangupConnection(2, argv, soc_id, pRI); |
| 462 | break; |
| 463 | } |
| 464 | case RIL_UNSOL_ECALL_ACTIVE: // =11, |
| 465 | { |
| 466 | if(redial_tag == REDIAL_DOING) { |
| 467 | redial_tag = REDIAL_SUCCESS; |
| 468 | stop_ecall_timer(sRedialTimer, redial_sig_value); |
| 469 | } |
| 470 | stop_ecall_timer(sAutoAnsTimer, autoAns_sig_value); |
| 471 | autoAnswerEcall(false); |
| 472 | start_ecll_timer(sT2, sT2_sig_value,T2_TIMEOUT); |
| 473 | start_ecll_timer(sT5,sT5_sig_value, T5_TIMEOUT); |
| 474 | break; |
| 475 | } |
| 476 | case RIL_UNSOL_ECALL_DISCONNECTED: //=12, |
| 477 | { |
| 478 | start_ecll_timer(sAutoAnsTimer,autoAns_sig_value, AUTOANS_TIMEOUT); |
| 479 | autoAnswerEcall(true); |
| 480 | stop_ecall_timer(sT2, sT2_sig_value); |
| 481 | if(isGostEcall()) |
| 482 | { |
| 483 | //start deregistration time |
| 484 | start_ecll_timer(gostDeregistrationTimer, gost_deregistration_value, gostStartDeregisterTimer()); |
| 485 | } |
| 486 | |
| 487 | break; |
| 488 | } |
| 489 | case RIL_UNSOL_ECALL_ABNORMAL_HANGUP: //=15, |
| 490 | { |
| 491 | RLOGD(" make fast ecall redial start, redial_tag: %d", redial_tag); |
| 492 | if(redial_tag != REDIAL_DOING) { |
| 493 | stop_ecall_timer(sT2, sT2_sig_value); |
| 494 | stop_ecall_timer(sT5,sT5_sig_value); |
| 495 | stop_ecall_timer(sT6,sT6_sig_value); |
| 496 | stop_ecall_timer(sT7,sT7_sig_value); |
| 497 | int32_t timer = utils::mtk_property_get_int32(PROP_ECALL_REDIAL_TIMER, 120); |
| 498 | RLOGD(" make fast ecall redial start, vendor.ecall.redial.timer: %d", timer); |
| 499 | start_ecll_timer(sRedialTimer, redial_sig_value, timer*1000); |
| 500 | } |
| 501 | if(redial_tag != REDIAL_SUCCESS || redial_tag != REDIAL_EXPIRES){ |
| 502 | redial_tag = REDIAL_DOING; |
| 503 | RequestInfo* pRI = creatRILInfoAndInit(RIL_REQUEST_ECALL_RESET_IVS, UDP, soc_id); |
| 504 | resetIVS(0, NULL, soc_id, pRI); |
| 505 | redialFastEcall(soc_id); |
| 506 | } |
| 507 | break; |
| 508 | } |
| 509 | //case RIL_UNSOL_ECALL_IMS_MSD_ACK: // = 20, |
| 510 | //case RIL_UNSOL_ECALL_IMS_UPDATE_MSD: // = 21, |
| 511 | //case RIL_UNSOL_ECALL_UNSPECIFIED: // = 0xffff, |
| 512 | default: |
| 513 | RLOGD("handleEcallIndication don't handlt the value(%d)", p_cur->ind); |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | //RIL_REQUEST_ECALL_SET_IVS |
| 518 | int setIVS(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI) { |
| 519 | android::Parcel p; |
| 520 | size_t pos = p.dataPosition(); |
| 521 | |
| 522 | if (getSpeechStatus() == SPEECH_OFF) { |
| 523 | if (get_audio_path() == 0) { |
| 524 | setSpeechAndStatus(1); |
| 525 | } else { |
| 526 | setSpeechAndStatus(2); |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | //paramter int. 0 disable, 1 enable |
| 531 | p.writeInt32(1); |
| 532 | p.writeInt32(atoi(argv[1]) ? 1 : 0); |
| 533 | p.setDataPosition(pos); |
| 534 | pRI->pCI->dispatchFunction(p, pRI); |
| 535 | return 0; |
| 536 | } |
| 537 | |
| 538 | //RIL_REQUEST_ECALL_SET_MSD |
| 539 | int setMSD(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI) { |
| 540 | android::Parcel p; |
| 541 | size_t pos = p.dataPosition(); |
| 542 | int digitCount; |
| 543 | uint8_t uct; |
| 544 | int digitLimit; |
| 545 | char *msd_data_src = (char *) argv[2]; |
| 546 | unsigned char msd_data_dst[MSD_MAX_LENGTH]; |
| 547 | int len = strlen(msd_data_src); |
| 548 | |
| 549 | if (argc < 2 || argv[2] == NULL || len % 2 == 1) { |
| 550 | //add log msg |
| 551 | free(pRI); |
| 552 | return -1; |
| 553 | } |
| 554 | |
| 555 | if (getSpeechStatus() == SPEECH_OFF) { |
| 556 | if (get_audio_path() == 0) { |
| 557 | setSpeechAndStatus(1); |
| 558 | } else { |
| 559 | setSpeechAndStatus(2); |
| 560 | } |
| 561 | } |
| 562 | //call_id |
| 563 | p.writeInt32(atoi(argv[1])); |
| 564 | //msd_data Convert MSD to byte representation |
| 565 | RLOGD("msd_data_src: msd_data_src length = %d %s\n", strlen(msd_data_src), |
| 566 | msd_data_src); |
| 567 | ConvertMsd((const char *) argv[2], msd_data_dst); |
| 568 | |
| 569 | digitLimit = MIN(len / 2, MSD_MAX_LENGTH); |
| 570 | p.writeInt32(digitLimit); |
| 571 | |
| 572 | for (digitCount = 0; digitCount < digitLimit; digitCount++) { |
| 573 | p.write(&(msd_data_dst[digitCount]), sizeof(uint8_t)); |
| 574 | } |
| 575 | |
| 576 | p.setDataPosition(pos); |
| 577 | pRI->pCI->dispatchFunction(p, pRI); |
| 578 | return 0; |
| 579 | } |
| 580 | //RIL_REQUEST_ECALL_SET_PSAP |
| 581 | int setPASP(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI) { |
| 582 | android::Parcel p; |
| 583 | size_t pos = p.dataPosition(); |
| 584 | |
| 585 | if (getSpeechStatus() == SPEECH_OFF) { |
| 586 | if (get_audio_path() == 0) { |
| 587 | setSpeechAndStatus(1); |
| 588 | } else { |
| 589 | setSpeechAndStatus(2); |
| 590 | } |
| 591 | } |
| 592 | |
| 593 | //paramter int. 0 disable, 1 enable |
| 594 | p.writeInt32(1); |
| 595 | p.writeInt32(atoi(argv[1]) ? 1 : 0); |
| 596 | p.setDataPosition(pos); |
| 597 | pRI->pCI->dispatchFunction(p, pRI); |
| 598 | return 0; |
| 599 | } |
| 600 | |
| 601 | //RIL_REQUEST_ECALL_IVS_PUSH_MSD |
| 602 | int IVSPushMSD(int argc, char **argv, RIL_SOCKET_ID socket_id, |
| 603 | RequestInfo *pRI) { |
| 604 | android::Parcel p; |
| 605 | |
| 606 | if (getSpeechStatus() == SPEECH_OFF) { |
| 607 | if (get_audio_path() == 0) { |
| 608 | setSpeechAndStatus(1); |
| 609 | } else { |
| 610 | setSpeechAndStatus(2); |
| 611 | } |
| 612 | } |
| 613 | |
| 614 | //paramter none |
| 615 | pRI->pCI->dispatchFunction(p, pRI); |
| 616 | return 0; |
| 617 | } |
| 618 | //RIL_REQUEST_ECALL_PSAP_PULL_MSD |
| 619 | int PSAPPushMSD(int argc, char **argv, RIL_SOCKET_ID socket_id, |
| 620 | RequestInfo *pRI) { |
| 621 | android::Parcel p; |
| 622 | |
| 623 | if (getSpeechStatus() == SPEECH_OFF) { |
| 624 | if (get_audio_path() == 0) { |
| 625 | setSpeechAndStatus(1); |
| 626 | } else { |
| 627 | setSpeechAndStatus(2); |
| 628 | } |
| 629 | } |
| 630 | |
| 631 | //paramter none |
| 632 | pRI->pCI->dispatchFunction(p, pRI); |
| 633 | return 0; |
| 634 | } |
| 635 | int setCTRLSequence(int argc, char **argv, RIL_SOCKET_ID socket_id, |
| 636 | RequestInfo *pRI) { |
| 637 | android::Parcel p; |
| 638 | size_t pos = p.dataPosition(); |
| 639 | |
| 640 | if (argc < 1 || argc > 4) { |
| 641 | //add log msg |
| 642 | free(pRI); |
| 643 | return -1; |
| 644 | } |
| 645 | //CTRL Sequence |
| 646 | p.writeInt32(3); |
| 647 | writeStringToParcel(p, (const char *) argv[1]); |
| 648 | writeStringToParcel(p, (const char *) argv[2]); |
| 649 | writeStringToParcel(p, (const char *) argv[3]); |
| 650 | |
| 651 | p.setDataPosition(pos); |
| 652 | pRI->pCI->dispatchFunction(p, pRI); |
| 653 | |
| 654 | return 0; |
| 655 | } |
| 656 | //RIL_REQUEST_ECALL_RESET_IVS |
| 657 | int resetIVS(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI) { |
| 658 | android::Parcel p; |
| 659 | |
| 660 | if (getSpeechStatus() == SPEECH_OFF) { |
| 661 | if (get_audio_path() == 0) { |
| 662 | setSpeechAndStatus(1); |
| 663 | } else { |
| 664 | setSpeechAndStatus(2); |
| 665 | } |
| 666 | } |
| 667 | |
| 668 | //paramter none |
| 669 | pRI->pCI->dispatchFunction(p, pRI); |
| 670 | return 0; |
| 671 | } |
| 672 | //RIL_REQUEST_ECALL_SET_TEST_NUM |
| 673 | int setTestNum(int argc, char **argv, RIL_SOCKET_ID socket_id, |
| 674 | RequestInfo *pRI) { |
| 675 | android::Parcel p; |
| 676 | size_t pos = p.dataPosition(); |
| 677 | |
| 678 | if(argc -1 == 0) { |
| 679 | p.writeInt32(0); |
| 680 | p.writeInt32(0); |
| 681 | writeStringToParcel(p, ""); |
| 682 | } else if (argc -1 == 1) { |
| 683 | p.writeInt32(1); |
| 684 | p.writeInt32(atoi(argv[1]) ? 1 : 0); |
| 685 | writeStringToParcel(p, ""); |
| 686 | } else if (argc - 1 == 2) { |
| 687 | p.writeInt32(2); |
| 688 | p.writeInt32(atoi(argv[1]) ? 1 : 0); |
| 689 | writeStringToParcel(p, (const char *) argv[2]); |
| 690 | } else { |
| 691 | RLOGD("parameters is invalid"); |
| 692 | free(pRI); |
| 693 | return -1; |
| 694 | } |
| 695 | p.setDataPosition(pos); |
| 696 | pRI->pCI->dispatchFunction(p, pRI); |
| 697 | return 0; |
| 698 | } |
| 699 | |
| 700 | //RIL_REQUEST_ECALL_SET_RECONF_NUM |
| 701 | int setReconfNum(int argc, char **argv, RIL_SOCKET_ID socket_id, |
| 702 | RequestInfo *pRI) { |
| 703 | android::Parcel p; |
| 704 | size_t pos = p.dataPosition(); |
| 705 | if(argc -1 == 0) { |
| 706 | p.writeInt32(0); |
| 707 | p.writeInt32(0); |
| 708 | writeStringToParcel(p, ""); |
| 709 | } else if (argc -1 == 1) { |
| 710 | p.writeInt32(1); |
| 711 | p.writeInt32(atoi(argv[1]) ? 1 : 0); |
| 712 | writeStringToParcel(p, ""); |
| 713 | } else if (argc - 1 == 2) { |
| 714 | p.writeInt32(2); |
| 715 | p.writeInt32(atoi(argv[1]) ? 1 : 0); |
| 716 | writeStringToParcel(p, (const char *) argv[2]); |
| 717 | } else { |
| 718 | RLOGD("parameters is invalid"); |
| 719 | free(pRI); |
| 720 | return -1; |
| 721 | } |
| 722 | p.setDataPosition(pos); |
| 723 | pRI->pCI->dispatchFunction(p, pRI); |
| 724 | return 0; |
| 725 | } |
| 726 | |
| 727 | //RIL_REQUEST_ECALL_MAKE_ECALL |
| 728 | int makeECall(int argc, char **argv, RIL_SOCKET_ID socket_id, |
| 729 | RequestInfo *pRI) { |
| 730 | android::Parcel p; |
| 731 | size_t pos = p.dataPosition(); |
| 732 | //paramter int, type |
| 733 | int type; |
| 734 | type = atoi(argv[1]); |
| 735 | if (type < 0 || type > 3) { |
| 736 | RLOGW("makeECall type is invaild. set default 0!"); |
| 737 | type = 0; |
| 738 | } |
| 739 | |
| 740 | p.writeInt32(1); |
| 741 | p.writeInt32(type); |
| 742 | p.setDataPosition(pos); |
| 743 | setEcallAudioPathOn(true); |
| 744 | pRI->pCI->dispatchFunction(p, pRI); |
| 745 | return 0; |
| 746 | } |
| 747 | |
| 748 | //RIL_REQUEST_ECALL_FAST_MAKE_ECALL |
| 749 | /*cmd:1, ecall_cat, |
| 750 | *2, ecall_variant, |
| 751 | *3, address |
| 752 | *4, msd_data |
| 753 | */ |
| 754 | int dialFastEcall(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI) |
| 755 | { |
| 756 | if(isGostEcall()) |
| 757 | { |
| 758 | if(inNeedRegister) |
| 759 | { |
| 760 | RLOGD("%s:%d", __FUNCTION__, __LINE__); |
| 761 | gostFastEcallFlg = true; |
| 762 | gostNetworkSelectionSet(socket_id); |
| 763 | while(inNeedRegister) |
| 764 | { |
| 765 | sleep(1); |
| 766 | RLOGD("%s:%d", __FUNCTION__, __LINE__); |
| 767 | } |
| 768 | stop_ecall_timer(gostDeregistrationTimer,gost_deregistration_value); |
| 769 | } |
| 770 | } |
| 771 | saveFastEcallData(argc, argv, socket_id); |
| 772 | if (argc < 5 || argv[3] == NULL || argv[4] == NULL) { |
| 773 | //add log msg |
| 774 | free(pRI); |
| 775 | return -1; |
| 776 | } |
| 777 | android::Parcel p; |
| 778 | size_t pos = p.dataPosition(); |
| 779 | int digitCount; |
| 780 | uint8_t uct; |
| 781 | int digitLimit; |
| 782 | char *msd_data_src = (char *)argv[4]; |
| 783 | unsigned char msd_data_dst[MSD_MAX_LENGTH]; |
| 784 | int len = strlen(msd_data_src); |
| 785 | |
| 786 | if (len%2 == 1) { |
| 787 | //add log msg |
| 788 | free(pRI); |
| 789 | return -1; |
| 790 | } |
| 791 | //ecall_cat |
| 792 | p.writeInt32(atoi(argv[1])); |
| 793 | //ecall_variant |
| 794 | p.writeInt32(atoi(argv[2])); |
| 795 | //address; |
| 796 | if(strcasecmp(argv[3], "null") == 0) |
| 797 | { |
| 798 | writeStringToParcel(p, ""); |
| 799 | } else { |
| 800 | writeStringToParcel(p, (const char *)argv[3]); |
| 801 | } |
| 802 | |
| 803 | //msd_data Convert MSD to byte representation |
| 804 | RLOGD("msd_data_src: %s , length = %d", msd_data_src, strlen(msd_data_src)); |
| 805 | ConvertMsd((const char *)argv[4], msd_data_dst); |
| 806 | |
| 807 | digitLimit= MIN(len/2, MSD_MAX_LENGTH); |
| 808 | p.writeInt32(digitLimit); |
| 809 | |
| 810 | for (digitCount = 0 ; digitCount < digitLimit; digitCount ++) { |
| 811 | p.write(&(msd_data_dst[digitCount]), sizeof(uint8_t)); |
| 812 | } |
| 813 | |
| 814 | p.setDataPosition(pos); |
| 815 | normal_ecall_tag = true; |
| 816 | setEcallAudioPathOn(true); |
| 817 | pRI->pCI->dispatchFunction(p, pRI); |
| 818 | |
| 819 | return 0; |
| 820 | } |
| 821 | |
| 822 | |
| 823 | //RIL_REQUEST_ECALL_SET_PRI |
| 824 | int setEmsdpri(int argc, char **argv, RIL_SOCKET_ID socket_id, |
| 825 | RequestInfo *pRI) { |
| 826 | if (argc != 5) { |
| 827 | RLOGW("parameter is invalid"); |
| 828 | free(pRI); |
| 829 | return 0; |
| 830 | } |
| 831 | int data1 = atoi(argv[1]); |
| 832 | int data2 = atoi(argv[2]); |
| 833 | int data3 = atoi(argv[3]); |
| 834 | int data4 = atoi(argv[4]); |
| 835 | |
| 836 | if (data1 + data2 + data3 + data4 != 10) { |
| 837 | RLOGW("parameter is invalid , %d,%d,%d,%d", data1, data2, data3, data4); |
| 838 | free(pRI); |
| 839 | return 0; |
| 840 | } |
| 841 | android::Parcel p; |
| 842 | size_t pos = p.dataPosition(); |
| 843 | p.writeInt32(4); |
| 844 | p.writeInt32(data1); |
| 845 | p.writeInt32(data2); |
| 846 | p.writeInt32(data3); |
| 847 | p.writeInt32(data4); |
| 848 | p.setDataPosition(pos); |
| 849 | pRI->pCI->dispatchFunction(p, pRI); |
| 850 | return 0; |
| 851 | } |
| 852 | |
| 853 | //RIL_REQUEST_ECALL_SET_NAD_DEREGISTRATION_TIME |
| 854 | /* |
| 855 | * "data" is const ints* |
| 856 | * ((const int *)data)[0] is purpose, 0-for eCall(currently only support 0, can be extended in future) |
| 857 | * ((const int *)data)[1] is mode, 1-set timer; 0-reset timer |
| 858 | * ((const int *)data)[2] is timer1, timer value (minute) set for emergency call |
| 859 | * ((const int *)data)[3] is timer2, timer value (minute) set for rest/reconfiguration call, |
| 860 | * |
| 861 | * in current, timer1 and timer2 prefer to be the same value. |
| 862 | */ |
| 863 | int setNadDeregTime(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI) { |
| 864 | if (argc != 5) { |
| 865 | RLOGW("parameter is invalid"); |
| 866 | free(pRI); |
| 867 | return 0; |
| 868 | } |
| 869 | |
| 870 | int purpose = atoi(argv[1]); |
| 871 | int mode = (atoi(argv[2]) != 0) ? 1 : 0; |
| 872 | int timer1 = atoi(argv[3]); |
| 873 | int timer2 = atoi(argv[4]); |
| 874 | if (timer1 != timer2) { |
| 875 | RLOGW("setNadDeregTime, parameter is invalid:data3 != data4"); |
| 876 | free(pRI); |
| 877 | return 0; |
| 878 | } |
| 879 | |
| 880 | android::Parcel p; |
| 881 | size_t pos = p.dataPosition(); |
| 882 | p.writeInt32(4); |
| 883 | p.writeInt32(purpose); |
| 884 | p.writeInt32(mode); |
| 885 | p.writeInt32(timer1); |
| 886 | p.writeInt32(timer2); |
| 887 | p.setDataPosition(pos); |
| 888 | pRI->pCI->dispatchFunction(p, pRI); |
| 889 | return 0; |
| 890 | } |
| 891 | |
| 892 | /** |
| 893 | * RIL_REQUEST_ECALL_SET_REGISTRATION_STATE |
| 894 | * |
| 895 | * REQUEST to set nad registration state of ecall only sim |
| 896 | * |
| 897 | * "data" is const ints* |
| 898 | * ((const int *)data)[0] is state, 0-deregister from NW, enter the eCall inactivity procedure; |
| 899 | * 1-register to NW, leave the eCall inactivity procedure(not support, reserved for future use) |
| 900 | * "response" is NULL |
| 901 | * |
| 902 | * Valid errors: |
| 903 | * SUCCESS |
| 904 | * GENERIC_FAILURE |
| 905 | */ |
| 906 | int setNadRegState(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI) { |
| 907 | if(argc != 2) { |
| 908 | RLOGW("parameter is invalid"); |
| 909 | free(pRI); |
| 910 | return 0; |
| 911 | } |
| 912 | |
| 913 | int state = (atoi(argv[1])!= 0) ? 1 : 0; |
| 914 | |
| 915 | android::Parcel p; |
| 916 | size_t pos = p.dataPosition(); |
| 917 | p.writeInt32(1); |
| 918 | p.writeInt32(state); |
| 919 | p.setDataPosition(pos); |
| 920 | pRI->pCI->dispatchFunction(p, pRI); |
| 921 | return 0; |
| 922 | } |
| 923 | |
| 924 | int setEcallType(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI) { |
| 925 | if(argc < 2) { |
| 926 | RLOGW("[error],setEcallType parameter error!"); |
| 927 | free(pRI); |
| 928 | return 0; |
| 929 | } |
| 930 | RLOGD("setEcallType is %s",argv[1]); |
| 931 | int value = atoi(argv[1]); |
| 932 | switch(value) { |
| 933 | case 1: |
| 934 | { |
| 935 | ecall_type = ECALL_TYPE::EN16454_ECALL; |
| 936 | break; |
| 937 | } |
| 938 | case 2: |
| 939 | { |
| 940 | ecall_type = ECALL_TYPE::GOST_ECALL; |
| 941 | break; |
| 942 | } |
| 943 | case 3: |
| 944 | { |
| 945 | ecall_type = ECALL_TYPE::NG_ECALL; |
| 946 | break; |
| 947 | } |
| 948 | default: |
| 949 | RLOGD("setEcallType error %s",argv[1]); |
| 950 | } |
| 951 | |
| 952 | if(pRI) { |
| 953 | free(pRI); |
| 954 | } |
| 955 | return 0; |
| 956 | } |
| 957 | |
| 958 | int getEcallType(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI) { |
| 959 | RLOGD("%s, %d", __FUNCTION__, ecall_type); |
| 960 | |
| 961 | if(ecall_type == ECALL_TYPE::EN16454_ECALL) { |
| 962 | printf("the current test type is: EN16454 ECALL\n"); |
| 963 | } else if(ecall_type == ECALL_TYPE::GOST_ECALL) { |
| 964 | printf("the current test type is: GOST ECALL\n"); |
| 965 | } else if (ecall_type == ECALL_TYPE::NG_ECALL) { |
| 966 | printf("the current test type is: NG ECALL (IMS)\n"); |
| 967 | } else { |
| 968 | printf("the current test type is: unknown\n"); |
| 969 | } |
| 970 | |
| 971 | if(pRI) { |
| 972 | free(pRI); |
| 973 | } |
| 974 | return 0; |
| 975 | } |
| 976 | |
| 977 | bool isEn16454Ecall() { |
| 978 | bool value = (ecall_type == ECALL_TYPE::EN16454_ECALL); |
| 979 | RLOGD("%s=%d, type = %d", __FUNCTION__, value, ecall_type); |
| 980 | return value; |
| 981 | } |
| 982 | |
| 983 | bool isGostEcall() { |
| 984 | bool value = (ecall_type == ECALL_TYPE::GOST_ECALL); |
| 985 | RLOGD("%s=%d, type = %d", __FUNCTION__, value, ecall_type); |
| 986 | return value; |
| 987 | } |
| 988 | |
| 989 | bool isNgEcall() { |
| 990 | bool value = (ecall_type == ECALL_TYPE::NG_ECALL); |
| 991 | RLOGD("%s=%d, type = %d", __FUNCTION__, value, ecall_type); |
| 992 | return value; |
| 993 | } |
| 994 | |
| 995 | void gostSaveSmsData(int argc, char** argv ,RIL_SOCKET_ID id) { |
| 996 | gost_sms_socket_id = id; |
| 997 | gost_sms_argc = argc; |
| 998 | gost_sms_argv.clear(); |
| 999 | for(int i = 0; i < argc; i++) { |
| 1000 | gost_sms_argv.push_back(argv[i]); |
| 1001 | } |
| 1002 | } |
| 1003 | |
| 1004 | void gostDelSaveSmsData() { |
| 1005 | if(fast_argc != 0) |
| 1006 | { |
| 1007 | fast_argc = 0; |
| 1008 | fast_argv.clear(); |
| 1009 | } |
| 1010 | } |
| 1011 | |
| 1012 | #define INT_MEM_TRANSMIT_ATTEMPTS 10 |
| 1013 | #define INT_MEM_TRANSMIT_INTERVAL (60*60*1000) |
| 1014 | static int gost_attempts = INT_MEM_TRANSMIT_ATTEMPTS; |
| 1015 | static int gost_interval = INT_MEM_TRANSMIT_INTERVAL; |
| 1016 | |
| 1017 | void gostSetInNeedRegister(bool flags) |
| 1018 | { |
| 1019 | RLOGD("%s:flags(%d) change!", __FUNCTION__, flags); |
| 1020 | inNeedRegister = flags; |
| 1021 | } |
| 1022 | void gostFastEcallFlgSet(bool flags) |
| 1023 | { |
| 1024 | RLOGD("%s:flags(%d) change!", __FUNCTION__, flags); |
| 1025 | gostFastEcallFlg = flags; |
| 1026 | } |
| 1027 | |
| 1028 | int gostTransmitAttemptsSet(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI) |
| 1029 | { |
| 1030 | if(argc < 2) { |
| 1031 | RLOGW("[error],gostTransmitAttemptsSet parameter error!"); |
| 1032 | free(pRI); |
| 1033 | return 0; |
| 1034 | } |
| 1035 | |
| 1036 | int attempts = atoi(argv[1]);; |
| 1037 | gost_attempts = attempts; |
| 1038 | RLOGD("%s:gost_attempts(%d)", __FUNCTION__, gost_attempts); |
| 1039 | |
| 1040 | if(pRI) { |
| 1041 | free(pRI); |
| 1042 | } |
| 1043 | return 0; |
| 1044 | } |
| 1045 | |
| 1046 | int gostStartDeregisterTimer() |
| 1047 | { |
| 1048 | char configNum[16]= {0}; |
| 1049 | int timerValue; |
| 1050 | utils::mtk_property_get(PROP_ECALL_DEREGIST_TIME, configNum, "60"); |
| 1051 | timerValue = atoi(configNum) * 60 * 1000; |
| 1052 | RLOGD("%s:configNum(%d)", __FUNCTION__, timerValue); |
| 1053 | return timerValue; |
| 1054 | } |
| 1055 | |
| 1056 | int gostTransmitIntervalSet(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI) |
| 1057 | { |
| 1058 | if(argc < 2) { |
| 1059 | RLOGW("[error],gostTransmitIntervalSet parameter error!"); |
| 1060 | free(pRI); |
| 1061 | return 0; |
| 1062 | } |
| 1063 | |
| 1064 | int interval = atoi(argv[1]);; |
| 1065 | gost_interval = interval; |
| 1066 | RLOGD("%s:gost_interval(%d)", __FUNCTION__, gost_interval); |
| 1067 | |
| 1068 | if(pRI) { |
| 1069 | free(pRI); |
| 1070 | } |
| 1071 | return 0; |
| 1072 | } |
| 1073 | |
| 1074 | int gostTransmitDefaultSet(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI) |
| 1075 | { |
| 1076 | gost_attempts = INT_MEM_TRANSMIT_ATTEMPTS; |
| 1077 | gost_interval = INT_MEM_TRANSMIT_INTERVAL; |
| 1078 | RLOGD("%s:gost_attempts(%d), gost_interval(%d)", __FUNCTION__, gost_attempts, gost_interval); |
| 1079 | |
| 1080 | if(pRI) { |
| 1081 | free(pRI); |
| 1082 | } |
| 1083 | return 0; |
| 1084 | } |
| 1085 | |
| 1086 | int gostNetworkSelectionSet(int soc_id) |
| 1087 | { |
| 1088 | RLOGD("%s:soc_id(%d)", __FUNCTION__, soc_id); |
| 1089 | if(isGostEcall() && gostFastEcallFlg) |
| 1090 | { |
| 1091 | RequestInfo *pRI = creatRILInfoAndInit(RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC, UDP, (RIL_SOCKET_ID)(soc_id)); |
| 1092 | if(pRI == NULL) |
| 1093 | { |
| 1094 | RLOGE("error PRI is NULL"); |
| 1095 | return 0; |
| 1096 | } |
| 1097 | char* argv[1] = {"RIL_REQUEST_SET_NETWORK_SELECTION_AUTOMATIC"}; |
| 1098 | setNetworkSelectionModeAutomatic(1, argv, (RIL_SOCKET_ID)(soc_id), pRI); |
| 1099 | } |
| 1100 | return 0; |
| 1101 | } |
| 1102 | |
| 1103 | int gostEcallResendMsd(bool flg) |
| 1104 | { |
| 1105 | static int resendnum = 0; |
| 1106 | |
| 1107 | //no resend |
| 1108 | if(!flg) |
| 1109 | { |
| 1110 | if(resendnum != 0) |
| 1111 | { |
| 1112 | stop_ecall_timer(gostResendMsdTimer,gost_resend_msd_value); |
| 1113 | } |
| 1114 | resendnum = 0; |
| 1115 | return 0; |
| 1116 | } |
| 1117 | |
| 1118 | //abandon |
| 1119 | if(resendnum > gost_attempts) |
| 1120 | { |
| 1121 | resendnum = 0; |
| 1122 | stop_ecall_timer(gostResendMsdTimer,gost_resend_msd_value); |
| 1123 | return 0; |
| 1124 | } |
| 1125 | |
| 1126 | //resend |
| 1127 | resendnum++; |
| 1128 | start_ecll_timer(gostResendMsdTimer, gost_resend_msd_value, gost_interval); |
| 1129 | } |
| 1130 | |
| 1131 | int T7GostEcallSmsMsd(sigval_t sig) { |
| 1132 | char** argv = new char*[fast_argv.size()]; |
| 1133 | char msd[512]; |
| 1134 | char saveEcallData[512]; |
| 1135 | char sdata[512]; |
| 1136 | |
| 1137 | if((sig.sival_int != sT7_sig_value) && (sig.sival_int != sT5_sig_value)) |
| 1138 | { |
| 1139 | return -1; |
| 1140 | } |
| 1141 | |
| 1142 | if(isGostEcall()) |
| 1143 | { |
| 1144 | //for test |
| 1145 | char testCase[140]= {0}; |
| 1146 | utils::mtk_property_get(PROP_ECALL_TEST_CASE, testCase, "test"); |
| 1147 | if(strcmp(testCase, "33470") == 0) |
| 1148 | { |
| 1149 | RLOGD("%s:testCase(%s) not need send sms", __FUNCTION__, testCase); |
| 1150 | return -1; |
| 1151 | } |
| 1152 | |
| 1153 | if(fast_argv.size() < 5) { |
| 1154 | RLOGD("%s:testCase(%s) fast_argv size(%d) is not right", __FUNCTION__, testCase,fast_argv.size()); |
| 1155 | return -1; |
| 1156 | } |
| 1157 | for(int i=0; i < fast_argv.size(); i++) { |
| 1158 | argv[i] = new char[fast_argv[i].size() +1]; |
| 1159 | memset(argv[i], 0 , fast_argv[i].size() +1); |
| 1160 | strncpy(argv[i], fast_argv[i].c_str(),fast_argv[i].size()); |
| 1161 | argv[i][fast_argv[i].size()] = '\0'; |
| 1162 | } |
| 1163 | |
| 1164 | RLOGD("num:%s, data:%s\n", argv[3], argv[4]); |
| 1165 | char *msd_data_src = (char *)argv[4]; |
| 1166 | int len = strlen(msd_data_src); |
| 1167 | std::shared_ptr<SslpManager> manager = std::make_shared<SslpManager>(); |
| 1168 | std::string data = manager->encodeAllRecords(service_support_layer_protocol::EGTS_ECALL_SERVICE, |
| 1169 | service_support_layer_protocol::EGTS_ECALL_SERVICE, |
| 1170 | EcallUtils::EGTS_SR_RAW_MSD_DATA, |
| 1171 | msd_data_src); |
| 1172 | //encode |
| 1173 | RLOGD("T7:data.c_str():%s\n", data.c_str()); |
| 1174 | int pt = GOST_EGTS_PT_APPDATA; |
| 1175 | gostTransferLayerEncode(msd, 0, const_cast<char*> (data.c_str()), pt, sizeof(msd)); |
| 1176 | RLOGD("T7:msd:%s\n", msd); |
| 1177 | gostSendSmsForMsd(fast_ecall_socket_id, argv[3], msd); |
| 1178 | for(int i=0; i < fast_argv.size(); i++) { |
| 1179 | delete [] argv[i]; |
| 1180 | } |
| 1181 | delete []argv; |
| 1182 | |
| 1183 | return 0; |
| 1184 | } |
| 1185 | |
| 1186 | return -1; |
| 1187 | } |
| 1188 | |
| 1189 | #define GOST_OK 0 |
| 1190 | #define GOST_ERROR -1 |
| 1191 | int gostInitEcallViaSms(int soc_id, char *num, int ecalltype, char *msd) |
| 1192 | { |
| 1193 | //init ecall |
| 1194 | RequestInfo *pRI = creatRILInfoAndInit(RIL_REQUEST_ECALL_FAST_MAKE_ECALL, UDP, (RIL_SOCKET_ID)(soc_id)); |
| 1195 | if(pRI == NULL) |
| 1196 | { |
| 1197 | RLOGE("error PRI is NULL"); |
| 1198 | return 0; |
| 1199 | } |
| 1200 | |
| 1201 | int argc = 5; |
| 1202 | char *argv[5]; |
| 1203 | argv[0] = "RIL_REQUEST_ECALL_FAST_MAKE_ECALL"; |
| 1204 | if(ecalltype) |
| 1205 | { |
| 1206 | argv[1] = "2";//1:Manual 2:auto |
| 1207 | } |
| 1208 | else |
| 1209 | { |
| 1210 | argv[1] = "1";//1:Manual 2:auto |
| 1211 | } |
| 1212 | argv[2] = "2"; //1:test ecall 2:Emergency eCall 3:Reconfiguration eCall |
| 1213 | // argv[3] = "1"; //1:Pull mode 2:push mode |
| 1214 | argv[3] = num; |
| 1215 | argv[4] = msd; |
| 1216 | dialFastEcall(argc, argv, (RIL_SOCKET_ID)(soc_id), pRI); |
| 1217 | return 0; |
| 1218 | } |
| 1219 | |
| 1220 | int gostParseSmsHandle(int soc_id, char *num, char *msg) |
| 1221 | { |
| 1222 | char msd[512] = {0}; |
| 1223 | char sdata[512] = {0}; |
| 1224 | char server_data[512] = {0}; |
| 1225 | int server_len; |
| 1226 | int parseStatus; |
| 1227 | gost_transfer_head_t stransferHead; |
| 1228 | |
| 1229 | memset(&stransferHead, 0, sizeof(stransferHead)); |
| 1230 | parseStatus = gostTransferLayerDecode(msg, server_data, &server_len, &stransferHead); |
| 1231 | const char* SFRD = server_data; |
| 1232 | uint16_t FDL = server_len; |
| 1233 | std::shared_ptr<SslpManager> sMg = std::make_shared<SslpManager>(); |
| 1234 | parseStatus += sMg->decodeAllRecords(SFRD, FDL); |
| 1235 | std::uint16_t cmd = UINT16_MAX; |
| 1236 | if(sMg->isIncludedCmdCode(EcallUtils::EGTS_ECALL_REQ)) { |
| 1237 | cmd = EcallUtils::EGTS_ECALL_REQ; |
| 1238 | } else if(sMg->isIncludedCmdCode(EcallUtils::EGTS_ECALL_MSD_REQ)) { |
| 1239 | cmd = EcallUtils::EGTS_ECALL_MSD_REQ; |
| 1240 | } else if(sMg->isIncludedCmdCode(EcallUtils::EGTS_ECALL_DEREGISTRATION)) { |
| 1241 | cmd = EcallUtils::EGTS_ECALL_DEREGISTRATION; |
| 1242 | } |
| 1243 | if(cmd == UINT16_MAX) { |
| 1244 | MTK_RLOGW("don't support this ack,just return"); |
| 1245 | return -1; |
| 1246 | } |
| 1247 | MTK_RLOGD("the cmd = 0X%04X, parseStatus = %d", cmd, parseStatus); |
| 1248 | std::string sslp_ack = sMg->encodeAck(service_support_layer_protocol::EGTS_COMMANDS_SERVICE, |
| 1249 | service_support_layer_protocol::EGTS_COMMANDS_SERVICE, |
| 1250 | CmdUtils::EGTS_SR_COMMAND_DATA, |
| 1251 | cmd, |
| 1252 | (parseStatus == GOST_OK)); |
| 1253 | strncpy(sdata, sslp_ack.c_str(), 512); |
| 1254 | int pt = GOST_EGTS_PT_RESPONSE; |
| 1255 | gostResponseTypeSfrdEncode(sdata, stransferHead, parseStatus); |
| 1256 | gostTransferLayerEncode(msd, 0, sdata, pt, sizeof(msd)); |
| 1257 | //send SMS ACK |
| 1258 | gostSendSmsForMsd(soc_id, num, msd); |
| 1259 | |
| 1260 | if (parseStatus == GOST_OK) { |
| 1261 | if(cmd == EcallUtils::EGTS_ECALL_REQ) { |
| 1262 | int ecalltype = sMg->getEcallReqPara(); // 0 manual , 1: auto |
| 1263 | //make fast ECALL; |
| 1264 | if(msd_data == NULL) { |
| 1265 | RLOGW("msd_data is empty, please input"); |
| 1266 | return -1; |
| 1267 | } |
| 1268 | |
| 1269 | char ecallNum[64] = {0}; |
| 1270 | if(fast_argv.size() > 4) |
| 1271 | { |
| 1272 | strcpy(ecallNum, fast_argv[3].c_str()); |
| 1273 | } |
| 1274 | gostInitEcallViaSms(soc_id, ecallNum, ecalltype, msd_data); |
| 1275 | } else if(cmd == EcallUtils::EGTS_ECALL_MSD_REQ) { |
| 1276 | //check whether need send SMS by decoding transport value in command. |
| 1277 | if(sMg->isNeedNewSms()) { |
| 1278 | //TBD: send new SMS; |
| 1279 | if(msd_data == NULL) { |
| 1280 | RLOGW("msd_data is empty, please input"); |
| 1281 | return -1; |
| 1282 | } |
| 1283 | std::string msdData(msd_data); |
| 1284 | std::shared_ptr<SslpManager> sMg = std::make_shared<SslpManager>(); |
| 1285 | std::string records = sMg->encodeAllRecords(service_support_layer_protocol::EGTS_ECALL_SERVICE, |
| 1286 | service_support_layer_protocol::EGTS_ECALL_SERVICE, EcallUtils::EGTS_SR_RAW_MSD_DATA, msdData); |
| 1287 | //transport encode and sms send |
| 1288 | int pt = GOST_EGTS_PT_APPDATA; |
| 1289 | memset(msd, 0, sizeof(msd)); |
| 1290 | gostTransferLayerEncode(msd, 0, const_cast<char*> (records.c_str()), pt, sizeof(msd)); |
| 1291 | gostSendSmsForMsd(soc_id, num, msd); |
| 1292 | } |
| 1293 | } else if(cmd == EcallUtils::EGTS_ECALL_DEREGISTRATION) { |
| 1294 | MTK_RLOGD("send RIL_REQUEST_ECALL_SET_REGISTRATION_STATE 0"); |
| 1295 | RIL_SOCKET_ID id = (RIL_SOCKET_ID)fast_ecall_socket_id; |
| 1296 | if(id == -1) { |
| 1297 | id = (RIL_SOCKET_ID)get_default_sim_all_except_data(); |
| 1298 | } |
| 1299 | RequestInfo* pRI = creatRILInfoAndInit(RIL_REQUEST_ECALL_SET_REGISTRATION_STATE, UDP, id); |
| 1300 | char* argv[2] = { "RIL_REQUEST_ECALL_SET_REGISTRATION_STATE", "0" }; |
| 1301 | setNadRegState(2, argv, id, pRI); |
| 1302 | } |
| 1303 | } |
| 1304 | return 0; |
| 1305 | } |
| 1306 | #endif /*ECALL_SUPPORT*/ |