blob: cdbb72592c53548fd05fb2288fff7b33b0ccf407 [file] [log] [blame]
xjde81d1d2021-11-25 15:01:52 +08001 /*
2 * Copyright (C) 2006 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#include <string.h>
17#include <stddef.h>
18#include <stdlib.h>
19#include <stdio.h>
20#include <stdbool.h>
21#include<fcntl.h>
22#include<sys/stat.h>
23#include<sys/types.h>
24#include<unistd.h>
25#include <assert.h>
26#include <log/log.h>
27#include <vendor-ril/telephony/ril.h>
28#include <string>
29#include <mutex>
30#include <vector>
31#include <cutils/properties.h>
32
33#include "Radio_capability_switch_util.h"
34#include "common.h"
35#include "Phone_utils.h"
36#include "utils.h"
37#include "data.h"
38#include "cc.h"
39#include <liblog/lynq_deflog.h>
40#undef LOG_TAG
41#define LOG_TAG "DEMO_COMMON"
42
43static pthread_mutex_t s_DataMutex = PTHREAD_MUTEX_INITIALIZER;
44static pthread_cond_t s_DataCond = PTHREAD_COND_INITIALIZER;
45
46/*
47typedef enum {
48 STATE_IN_SERVICE =0,
49 STATE_OUT_OF_SERVICE =1,
50 STATE_EMERGENCY_ONLY =2,
51 STATE_POWER_OFF =3
52} Service_State;
53*/
54RfDesenseTxTest* m_RfDesense;
55static RIL_CardStatus_v6* cur_CardS_Status[2] = {NULL, NULL};
56static RIL_RadioCapability radio_capability[2];
57
58static int cur_voice_radio_tech[2] = {RADIO_TECH_UNKNOWN, RADIO_TECH_UNKNOWN};
59
60static int reg_voice_service_state[2] = {0, 0};
61static int reg_data_service_state[2] = {0, 0};
62static int reg_data_radio_tech[2] = {RADIO_TECH_UNKNOWN, RADIO_TECH_UNKNOWN};
63static int reg_voice_radio_tech[2] = {RADIO_TECH_UNKNOWN, RADIO_TECH_UNKNOWN};
64static int preferred_network_type[2] = {Phone_utils::PREFERRED_NETWORK_MODE, Phone_utils::PREFERRED_NETWORK_MODE};
65static int radio_status[2] = {RADIO_STATE_UNAVAILABLE, RADIO_STATE_UNAVAILABLE};
66static std::vector<int> call_state[2];
67
68static int default_sim_all = RIL_SOCKET_1;
69static int default_sim_all_except_data = RIL_SOCKET_1;
70static int default_sim_voice = RIL_SOCKET_1;
71static int default_sim_data = RIL_SOCKET_1;
72static int default_sim_sms = RIL_SOCKET_1;
73static bool isNeedReconnect = false;
74
75static std::int32_t token = 0;
76static std::mutex g_mutex;
77
78static int regCodeToRadioTechnology(int request, int code, int slot);
79
80void update_call_state(void *response, size_t responselen, int slot) {
81 int num = responselen / sizeof(RIL_Call *);
82 if(num == 0) {
83 call_state[slot].clear();
84 RLOGD("[SIM%d]clear call state", slot);
85 } else {
86 call_state[slot].clear();
87 for (int i = 0 ; i < num ; i++) {
88 RIL_Call *p_cur = ((RIL_Call **) response)[i];
89 /* each call info */
90 call_state[slot].push_back(p_cur->state);
91 RLOGD("[SIM%d][id:%d]update_call_state: %d", slot,p_cur->index, p_cur->state);
92 if(p_cur->isMT) {
93 resetMute();
94 }
95 }
96 }
97}
98
99int is_call_state_idle(int slot) {
100 bool is_idle = true;
101 if(!call_state[slot].empty()) {
102 is_idle = false;
103 }
104 RLOGD("[SIM%d]is_call_state_idle: %d", slot, is_idle);
105 return is_idle;
106}
107
108void update_preferred_network_type(int type, int slot) {
109 RLOGD("[SIM%d]update_preferred_network_type: %d", slot, type);
110 preferred_network_type[slot] = type;
111}
112
113int get_preferred_network_type(int slot) {
114 return preferred_network_type[slot];
115}
116
117static int needBlockReq(int request)
118{
119#ifdef ENABLE_BLOCK_FEATURE
120 return 1;
121#endif
122
123 switch (request){
124 case RIL_REQUEST_RADIO_POWER: return 1;
125 case RIL_REQUEST_SET_IMS_ENABLE: return 1;
126 //case RIL_REQUEST_DATA_REGISTRATION_STATE: return 1;
127 default: return 0;
128 }
129 return 0;
130}
131
132static int setupToken(int token, int mode, int block)
133{
134 switch (mode){
135 case INIT:
136 token |= INIT_TOKEN_MARK;
137 break;
138 case UDP:
139 token |= RIL_TOKEN_MARK;
140 break;
141 case ATCI:
142 token |= ATCI_TOKEN_MARK;
143 break;
144 case RSPD:
145 token |= RSP_DISP_TOKEN_MARK;
146 break;
147 case OTHER:
148 token |= OTHER_TOKEN_MARK;
149 break;
150 default:
151 break;
152 }
153
154 if(block)
155 token |= BLOCK_MARK;
156
157 return token;
158}
159
160bool isDataConnectEnable(int slot) {
161 char value[PROPERTY_VALUE_MAX] = {0};
162 utils::getMSimProperty(slot,PROP_DEFAULT_DATA_SIM_STATUS, value);
163 if(atoi(value) == 1) {
164 return true;
165 }
166 return false;
167}
168
169void updataDataConnectState(int slot, bool state) {
170 utils::setMSimProperty(slot,PROP_DEFAULT_DATA_SIM_STATUS, const_cast<char*>(state ? "1":"0"));
171}
172
173std::int32_t GenerateToken(int mode, int request) {
174 g_mutex.lock();
175 if (token +1 == TOKEN_MODE) {
176 token = 1;
177 } else {
178 token++;
179 }
180 std::int32_t t= 0;
181 t = setupToken(token,mode,needBlockReq(request));
182 g_mutex.unlock();
183 return t;
184}
185
186RequestInfo* creatRILInfoAndInit(int request, int mode, RIL_SOCKET_ID soc_id)
187{
188 RequestInfo *pRI = (RequestInfo *)calloc(1, sizeof(RequestInfo));
189 if(pRI ==NULL){
190 RLOGE("%s,memory alloc error!",__func__);
191 return NULL;
192 }
193 android::initRequestInfo(pRI,request,mode, soc_id);
194 return pRI;
195}
196
197void set_default_sim_all_except_data(int slot_id) {
198 RLOGD("set_default_sim_all excpet data: %d", slot_id);
199 default_sim_all_except_data = slot_id;
200 set_default_sim_voice(slot_id);
201 set_default_sim_sms(slot_id);
202}
203
204int get_default_sim_all_except_data() {
205 return default_sim_all_except_data;
206}
207
208void set_default_sim_all(int slot_id){
209 RLOGD("set_default_sim_all: %d", slot_id);
210 default_sim_all = slot_id;
211 set_default_sim_all_except_data(slot_id);
212 set_default_sim_data(slot_id);
213}
214
215int get_default_sim_all(){
216 return default_sim_all;
217}
218
219void set_default_sim_voice(int slot_id){
220 RLOGD("set_default_sim_voice: %d", slot_id);
221 default_sim_voice = slot_id;
222}
223
224int get_default_sim_voice(){
225 return default_sim_voice;
226}
227
228void set_default_sim_data(int slot) {
229 RLOGD("set_default_sim_data: %d", slot);
230 pthread_mutex_lock(&s_DataMutex);
231 if(get_default_sim_data() != slot) {
232 if(isDataConnectEnable(get_default_sim_data())) {
233 isNeedReconnect = true;
234 deactivateDataCall(0,NULL,(RIL_SOCKET_ID)0,NULL);
235 RLOGD("set_default_sim_data, wait deactive data call done");
236 pthread_cond_wait(&s_DataCond, &s_DataMutex);
237 RLOGD("set_default_sim_data, deactive data call done");
238 }
239 RLOGD("set_default_sim_data, set prop");
240 default_sim_data = slot;
241 utils::mtk_property_set(PROP_DEFAULT_DATA_SIM, std::to_string(default_sim_data + 1).c_str());
242 while(!isRadioAvailable(RIL_SOCKET_ID(slot))) {
243 sleep(1);
244 RLOGD("[SIM%d]set_default_sim_data(RIL_REQUEST_SET_RADIO_CAPABILITY): wait radio available", slot);
245 }
246 syncDataSettings(RIL_SOCKET_ID(slot));
247 if(utils::is_support_dsds()) {
248 Radio_capability_switch_util::sendRadioCapabilityRequest(slot);
249 }
250 }
251 pthread_mutex_unlock(&s_DataMutex);
252}
253
254bool isNeedConnect() {
255 return isNeedReconnect;
256}
257
258void resetConnect() {
259 isNeedReconnect = false;
260}
261int get_default_sim_data_for_switch() {
262 return default_sim_data;
263}
264
265int get_default_sim_data(){
266 default_sim_data = utils::mtk_property_get_int32(PROP_DEFAULT_DATA_SIM, 1) -1;
267 return default_sim_data;
268}
269
270void set_default_sim_sms(int slot_id){
271 RLOGD("set_default_sim_sms: %d", slot_id);
272 default_sim_sms = slot_id;
273}
274
275int get_default_sim_sms() {
276 return default_sim_sms;
277}
278
279static int regCodeToServiceState(int request,int code, int slot);
280static int reg_Code_To_Service_State(int request,int code, int slot);
281
282const char * radioStateToString(RIL_RadioState s) {
283 switch (s) {
284 case RADIO_STATE_OFF:
285 return "RADIO_OFF";
286 case RADIO_STATE_UNAVAILABLE:
287 return "RADIO_UNAVAILABLE";
288 case RADIO_STATE_SIM_NOT_READY:
289 return "RADIO_SIM_NOT_READY";
290 case RADIO_STATE_SIM_LOCKED_OR_ABSENT:
291 return "RADIO_SIM_LOCKED_OR_ABSENT";
292 case RADIO_STATE_SIM_READY:
293 return "RADIO_SIM_READY";
294 case RADIO_STATE_RUIM_NOT_READY:
295 return "RADIO_RUIM_NOT_READY";
296 case RADIO_STATE_RUIM_READY:
297 return "RADIO_RUIM_READY";
298 case RADIO_STATE_RUIM_LOCKED_OR_ABSENT:
299 return "RADIO_RUIM_LOCKED_OR_ABSENT";
300 case RADIO_STATE_NV_NOT_READY:
301 return "RADIO_NV_NOT_READY";
302 case RADIO_STATE_NV_READY:
303 return "RADIO_NV_READY";
304 case RADIO_STATE_ON:
305 return "RADIO_ON";
306 default:
307 return "<unknown state>";
308 }
309}
310
311const char *rilSocketIdToString(RIL_SOCKET_ID socket_id) {
312 switch (socket_id) {
313 case RIL_SOCKET_1:
314 return "RIL_SOCKET_1";
315#if (SIM_COUNT >= 2)
316 case RIL_SOCKET_2:
317 return "RIL_SOCKET_2";
318#endif
319#if (SIM_COUNT >= 3)
320 case RIL_SOCKET_3:
321 return "RIL_SOCKET_3";
322#endif
323#if (SIM_COUNT >= 4)
324 case RIL_SOCKET_4:
325 return "RIL_SOCKET_4";
326#endif
327 default:
328 return "not a valid RIL";
329 }
330}
331
332void update_radio_capa(RIL_RadioCapability* cap, int slot) {
333 memset(&radio_capability[slot], 0, sizeof(RIL_RadioCapability));
334 if(cap != NULL) {
335 strcpy(radio_capability[slot].logicalModemUuid,cap->logicalModemUuid);
336 radio_capability[slot].phase = cap->phase;
337 radio_capability[slot].rat = cap->rat;
338 radio_capability[slot].session = cap->session;
339 radio_capability[slot].status = cap->status;
340 radio_capability[slot].version = cap->version;
341 }
342}
343
344RIL_RadioCapability get_radio_capa(int slot) {
345 return radio_capability[slot];
346}
347
348void update_voice_radio_tech(int code, int slot) {
349 cur_voice_radio_tech[slot] = code;
350}
351
352int get_voice_radio_tech(int slot){
353 return cur_voice_radio_tech[slot];
354}
355
356void updateCardStatusV6(RIL_CardStatus_v6 *card_status,int slot)
357{
358 if(cur_CardS_Status[slot] != NULL) {
359 RLOGD("[slot%d]updateCardStatusV6", slot);
360 for(int i = 0; i < cur_CardS_Status[slot]->num_applications; i++) {
361 free(cur_CardS_Status[slot]->applications[i].aid_ptr);
362 cur_CardS_Status[slot]->applications[i].aid_ptr = NULL;
363 free(cur_CardS_Status[slot]->applications[i].app_label_ptr);
364 cur_CardS_Status[slot]->applications[i].app_label_ptr = NULL;
365 }
366 free(cur_CardS_Status[slot]);
367 cur_CardS_Status[slot] = NULL;
368 }
369 cur_CardS_Status[slot] = (RIL_CardStatus_v6 *)calloc(1, sizeof(RIL_CardStatus_v6));
370 memset(cur_CardS_Status[slot], 0, sizeof(RIL_CardStatus_v6));
371 cur_CardS_Status[slot]->card_state = card_status->card_state;
372 cur_CardS_Status[slot]->cdma_subscription_app_index = card_status->cdma_subscription_app_index;
373 cur_CardS_Status[slot]->gsm_umts_subscription_app_index = card_status->gsm_umts_subscription_app_index;
374 cur_CardS_Status[slot]->ims_subscription_app_index = card_status->ims_subscription_app_index;
375 cur_CardS_Status[slot]->num_applications = card_status->num_applications;
376 cur_CardS_Status[slot]->universal_pin_state = card_status->universal_pin_state;
377 RLOGD("[slot%d]updateCardStatusV6 card_state: %d, cdma_index: %d, gsm_index: %d, "
378 "ims_index: %d, num_applications: %d, universal_pin_state: %d",
379 slot,
380 cur_CardS_Status[slot]->card_state,
381 cur_CardS_Status[slot]->cdma_subscription_app_index,
382 cur_CardS_Status[slot]->gsm_umts_subscription_app_index,
383 cur_CardS_Status[slot]->ims_subscription_app_index,
384 cur_CardS_Status[slot]->num_applications,
385 cur_CardS_Status[slot]->universal_pin_state);
386 if(card_status)
387 {
388 for(int i = 0; i < card_status->num_applications; i++) {
389 cur_CardS_Status[slot]->applications[i].app_state = card_status->applications[i].app_state;
390 cur_CardS_Status[slot]->applications[i].app_type = card_status->applications[i].app_type;
391 cur_CardS_Status[slot]->applications[i].perso_substate = card_status->applications[i].perso_substate;
392 cur_CardS_Status[slot]->applications[i].pin1 = card_status->applications[i].pin1;
393 cur_CardS_Status[slot]->applications[i].pin1_replaced = card_status->applications[i].pin1_replaced;
394 cur_CardS_Status[slot]->applications[i].pin2 = card_status->applications[i].pin2;
395 cur_CardS_Status[slot]->applications[i].aid_ptr = strdup(card_status->applications[i].aid_ptr);
396 cur_CardS_Status[slot]->applications[i].app_label_ptr = strdup(card_status->applications[i].app_label_ptr);
397 }
398 } else {
399 RLOGD("[slot%d]updateCardStatusV6: sim card message is null", slot);
400 }
401}
402int getSimState(RIL_SOCKET_ID slot)
403{
404 int state = 0;
405 if(cur_CardS_Status[slot] != NULL)
406 {
407 state = cur_CardS_Status[slot]->card_state;
408 }
409 else
410 {
411 LYDBGLOG("cur_CardS_Status[slot] == NULL\n");
412 }
413 RLOGD("[slot%d][getSimState] , sim card state: %d", slot,state);
414 return state;
415
416}
417char* getAid(int slot)
418{
419 char* aid = "";
420 int index = -1;
421 if(cur_CardS_Status[slot] != NULL){
422 if(Phone_utils::get_phone_type(slot) == Phone_utils::PHONE_TYPE_CDMA) {
423 index = cur_CardS_Status[slot]->cdma_subscription_app_index;
424 } else {
425 index = cur_CardS_Status[slot]->gsm_umts_subscription_app_index;
426 }
427 if(index >= 0 && index < cur_CardS_Status[slot]->num_applications) {
428 aid = cur_CardS_Status[slot]->applications[index].aid_ptr;
429 }
430 }
431 RLOGD("[slot%d] index: %d, getAid: %s", slot, index, aid);
432 return aid;
433}
434
435void update_reg_voice_service_state(int request, char *code, int slot, int32_t token)
436{
437 if((reg_voice_service_state[slot] != atoi(code)) || ((token&RIL_TOKEN_MARK) == RIL_TOKEN_MARK)) {
438 reg_voice_service_state[slot] = atoi(code);
439 regCodeToServiceState(request, atoi(code), slot);
440 }
441}
442//Warren add for plantform 2021_08_11 start
443int get_reg_voice_service_state(int request, int slot)
444{
445 int state = 0;
446 int temp=0;
447 if(reg_voice_service_state[slot]) {
448 //reg_voice_service_state[slot] = atoi(code);
449 temp = reg_voice_service_state[slot];
450 state = reg_Code_To_Service_State(request, temp, slot);
451 }
452 return state;
453}
454//Warren add for plantform 2021_08_11 end
455
456void update_reg_voice_radio_tech(int request, int code, int slot, int32_t token) {
457 if((reg_voice_radio_tech[slot] != code) || ((token&RIL_TOKEN_MARK) == RIL_TOKEN_MARK)){
458 reg_voice_radio_tech[slot] = code;
459 regCodeToRadioTechnology(request, code, slot);
460 }
461}
462
463void update_reg_data_service_state(int request, char *code,int slot, int32_t token)
464{
465 if((reg_data_service_state[slot] != atoi(code)) || ((token&RIL_TOKEN_MARK) == RIL_TOKEN_MARK)) {
466 reg_data_service_state[slot] = atoi(code);
467 regCodeToServiceState(request, atoi(code), slot);
468 }
469}
470
471void update_reg_data_radio_tech(int request, int code, int slot, int32_t token){
472 if((reg_data_radio_tech[slot] != code) || ((token&RIL_TOKEN_MARK) == RIL_TOKEN_MARK)) {
473 reg_data_radio_tech[slot] = code;
474 regCodeToRadioTechnology(request, code, slot);
475 }
476}
477
478void registerRadioOn(RfDesenseTxTest* rf){
479 if(!m_RfDesense) {
480 m_RfDesense = rf;
481 }
482}
483
484void unregisterRadioOn() {
485 if(m_RfDesense) {
486 m_RfDesense == NULL;
487 }
488}
489
490void registerRadioOffOrNotAvailable(RfDesenseTxTest* rf){
491 if(!m_RfDesense) {
492 m_RfDesense = rf;
493 }
494}
495
496void unregisterRadioOffOrNotAvailable() {
497 if(m_RfDesense) {
498 m_RfDesense == NULL;
499 }
500}
501
502void registerOnUnsolOemHookRaw(RfDesenseTxTest* rf){
503 if(!m_RfDesense) {
504 m_RfDesense = rf;
505 }
506}
507
508void unregisterOnUnsolOemHookRaw(){
509 if(m_RfDesense) {
510 m_RfDesense == NULL;
511 }
512}
513
514void register_response_oem_hook_raw(RfDesenseTxTest* rf){
515 if(!m_RfDesense) {
516 m_RfDesense = rf;
517 }
518}
519
520void unregister_response_oem_hook_raw(){
521 if(m_RfDesense) {
522 m_RfDesense == NULL;
523 }
524}
525
526void updateRadioStatus(int newValue ,RIL_SOCKET_ID soc_id)
527{
528 RLOGD("updateRadioStatus oldState: %d, newState: %d", radio_status[soc_id], newValue);
529 bool newOn = (newValue == RADIO_STATE_ON);
530 bool oldOn = (radio_status[soc_id] == RADIO_STATE_ON);
531 bool newAvaiable = (newValue != RADIO_STATE_UNAVAILABLE);
532 bool oldAvaiable = (radio_status[soc_id] != RADIO_STATE_UNAVAILABLE);
533 if (newOn && !oldOn) {
534 RLOGD("RadioStateOn");
535 //printf("[SIM%d] radio on\n",soc_id +1);
536 if(m_RfDesense){
537 m_RfDesense->emRadioStateOn();
538 }
539 }
540
541 if ((!newOn || !newAvaiable) && !((!oldOn || !oldAvaiable))) {
542 RLOGD("RadioStateOfforNotAvailable");
543 //printf("[SIM%d] radio off or not available\n",soc_id +1);
544 if(m_RfDesense){
545 m_RfDesense->emRadioStateOfforNotAvailable();
546 }
547 }
548 if(newValue != radio_status[soc_id]) {
549 radio_status[soc_id] = newValue;
550 }
551}
552
553bool isRadioOn(RIL_SOCKET_ID soc_id)
554{
555 return radio_status[soc_id] == RADIO_STATE_ON;
556}
557
558bool isRadioAvailable(RIL_SOCKET_ID soc_id)
559{
560 return radio_status[soc_id] != RADIO_STATE_UNAVAILABLE;
561}
562//Warren add for plantform 2021_08_11 start
563static int reg_Code_To_Service_State(int request,int code, int slot)
564{
565 RLOGD("[slot%d][LYNQ]reg_Code_To_Service_State %d, request: %s",slot, code, android::requestToString(request));
566 switch (code)
567 {
568 case 0:
569 case 2: // 2 is "searching"
570 case 3: // 3 is "registration denied"
571 case 4: // 4 is "unknown" no vaild in current baseband
572 case 10:// same as 0, but indicates that emergency call is possible.
573 case 12:// same as 2, but indicates that emergency call is possible.
574 case 13:// same as 3, but indicates that emergency call is possible.
575 case 14:// same as 4, but indicates that emergency call is possible.
576 {
577 if(request == RIL_REQUEST_VOICE_REGISTRATION_STATE) {
578 RLOGD("[QUERY][VOICE REG_STATUS][SIM%d] The current service state is OUT OF SERVICE\n", slot);
579 } else {
580 RLOGD("[QUERY][DATA REG_STATUS][SIM%d] The current service state is OUT OF SERVICE\n", slot);
581 }
582 return STATE_OUT_OF_SERVICE;
583 }
584
585 case 1:
586 case 5:
587 {
588 if(request == RIL_REQUEST_VOICE_REGISTRATION_STATE) {
589 RLOGD("[QUERY][VOICE REG_STATUS][SIM%d] The current service state is IN SERVICE\n", slot);
590 } else {
591 RLOGD("[QUERY][DATA REG_STATUS][SIM%d] The current service state is IN SERVICE\n", slot);
592 }
593 return STATE_IN_SERVICE;
594 }
595
596 default:
597 {
598 if(request == RIL_REQUEST_VOICE_REGISTRATION_STATE) {
599 RLOGD("[QUERY][VOICE REG_STATUS][SIM%d] Unexpected service state %d\n", slot, code);
600 } else {
601 RLOGD("[QUERY][DATA REG_STATUS][SIM%d] Unexpected service state %d\n", slot, code);
602 }
603 RLOGW("[SIM%d]regCodeToServiceState: unexpected service state %d", slot, code);
604 return STATE_OUT_OF_SERVICE;
605 }
606 }
607}
608
609//Warren add for plantform 2021_08_11 start end
610static int regCodeToServiceState(int request,int code, int slot)
611{
612 RLOGD("[slot%d]regCodeToServiceState %d, request: %s",slot, code, android::requestToString(request));
613 switch (code)
614 {
615 case 0:
616 case 2: // 2 is "searching"
617 case 3: // 3 is "registration denied"
618 case 4: // 4 is "unknown" no vaild in current baseband
619 case 10:// same as 0, but indicates that emergency call is possible.
620 case 12:// same as 2, but indicates that emergency call is possible.
621 case 13:// same as 3, but indicates that emergency call is possible.
622 case 14:// same as 4, but indicates that emergency call is possible.
623 {
624 if(request == RIL_REQUEST_VOICE_REGISTRATION_STATE) {
625 printf("[QUERY][VOICE REG_STATUS][SIM%d] The current service state is OUT OF SERVICE\n", slot);
626 } else {
627 printf("[QUERY][DATA REG_STATUS][SIM%d] The current service state is OUT OF SERVICE\n", slot);
628 }
629 return STATE_OUT_OF_SERVICE;
630 }
631
632 case 1:
633 case 5:
634 {
635 if(request == RIL_REQUEST_VOICE_REGISTRATION_STATE) {
636 printf("[QUERY][VOICE REG_STATUS][SIM%d] The current service state is IN SERVICE\n", slot);
637 } else {
638 printf("[QUERY][DATA REG_STATUS][SIM%d] The current service state is IN SERVICE\n", slot);
639 }
640 return STATE_IN_SERVICE;
641 }
642
643 default:
644 {
645 if(request == RIL_REQUEST_VOICE_REGISTRATION_STATE) {
646 printf("[QUERY][VOICE REG_STATUS][SIM%d] Unexpected service state %d\n", slot, code);
647 } else {
648 printf("[QUERY][DATA REG_STATUS][SIM%d] Unexpected service state %d\n", slot, code);
649 }
650 RLOGW("[SIM%d]regCodeToServiceState: unexpected service state %d", slot, code);
651 return STATE_OUT_OF_SERVICE;
652 }
653 }
654}
655
656static int regCodeToRadioTechnology(int request, int code, int slot) {
657 RLOGD("[slot%d]regCodeToRadioTechnology %d, request: %s",slot, code, android::requestToString(request));
658 switch(code) {
659 case RADIO_TECH_LTE:
660 {
661 if(request == RIL_REQUEST_VOICE_REGISTRATION_STATE) {
662 printf("[QUERY][VOICE REG_STATUS][SIM%d] The registered radio technology is 4G\n", slot);
663 } else {
664 printf("[QUERY][DATA REG_STATUS][SIM%d] The registered radio technology is 4G\n", slot);
665 }
666 break;
667 }
668 case RADIO_TECH_GSM:
669 case RADIO_TECH_GPRS:
670 case RADIO_TECH_EDGE:
671 case RADIO_TECH_IS95A:
672 case RADIO_TECH_IS95B:
673 case RADIO_TECH_1xRTT:
674 {
675 if(request == RIL_REQUEST_VOICE_REGISTRATION_STATE) {
676 printf("[QUERY][VOICE REG_STATUS][SIM%d] The registered radio technology is 2G\n", slot);
677 } else {
678 printf("[QUERY][DATA REG_STATUS][SIM%d] The registered radio technology is 2G\n", slot);
679 }
680 break;
681 }
682 case RADIO_TECH_UMTS:
683 case RADIO_TECH_HSDPA:
684 case RADIO_TECH_HSUPA:
685 case RADIO_TECH_HSPA:
686 case RADIO_TECH_EHRPD:
687 case RADIO_TECH_HSPAP:
688 case RADIO_TECH_TD_SCDMA:
689 case RADIO_TECH_EVDO_0:
690 case RADIO_TECH_EVDO_A:
691 case RADIO_TECH_EVDO_B:
692 {
693 if(request == RIL_REQUEST_VOICE_REGISTRATION_STATE) {
694 printf("[QUERY][VOICE REG_STATUS][SIM%d] The registered radio technology is 3G\n", slot);
695 } else {
696 printf("[QUERY][DATA REG_STATUS][SIM%d] The registered radio technology is 3G\n", slot);
697 }
698 break;
699 }
700#ifdef TELEMATIC_5G_SUPPORT
701 case RADIO_TECH_NR://5G
702 {
703 if(request == RIL_REQUEST_VOICE_REGISTRATION_STATE) {
704 printf("[QUERY][VOICE REG_STATUS][SIM%d] The registered radio technology is 5G\n", slot);
705 } else {
706 printf("[QUERY][DATA REG_STATUS][SIM%d] The registered radio technology is 5G\n", slot);
707 }
708 break;
709 }
710#endif
711 case RADIO_TECH_UNKNOWN:
712 {
713 if(request == RIL_REQUEST_VOICE_REGISTRATION_STATE) {
714 printf("[QUERY][VOICE REG_STATUS][SIM%d] The registered radio technology is unknown\n", slot);
715 } else {
716 printf("[QUERY][DATA REG_STATUS][SIM%d] The registered radio technology is unknown\n", slot);
717 }
718 break;
719 }
720 default:
721 {
722 if(request == RIL_REQUEST_VOICE_REGISTRATION_STATE) {
723 printf("[QUERY][VOICE REG_STATUS][SIM%d] %d is unexpected value\n",slot, code);
724 } else {
725 printf("[QUERY][DATA REG_STATUS][SIM%d] %d is unexpected value\n",slot, code);
726 }
727 }
728 }
729 return 0;
730}
731
732int get_reg_data_radio_tech(int slot) {
733 return reg_data_radio_tech[slot];
734}
735
736int get_reg_voice_radio_tech(int slot) {
737 return reg_voice_radio_tech[slot];
738}
739
740#ifdef ECALL_SUPPORT
741void ConvertMsd(const char *msdChar, unsigned char *msd) {
742 unsigned int n, x;
743
744 for (n = 0; n < MSD_MAX_LENGTH; n++) {
745 if (sscanf(&msdChar[n<<1], "%2x", &x) == 1) {
746 msd[n] = x;
747 } else {
748 RLOGE("invalid MSD characters");
749 break;
750 }
751 }
752}
753#endif /*ECALL_SUPPORT*/
754
755bool isFinalResponseErrorEx(char* str) {
756 AtLine atline(str, NULL);
757 return (atline.isFinalResponseErrorEx(0) == 1 ? true : false);
758}
759
760int get_atci_sim(){
761 return utils::mtk_property_get_int32(ATCI_SIM, 0);
762}
763
764static char *findNextChar(char *p, char c, int length)
765{
766 char *ptr = p;
767 int i = 0;
768 while (i++ < length)
769 {
770 if (*ptr++ == c)
771 return ptr;
772 }
773 return NULL;
774}
775
776static int getGMTval(char *pdata)
777{
778 char *ptr;
779 ptr = findNextChar(pdata, '+', strlen(pdata));
780 if (ptr == NULL)
781 {
782 ptr = findNextChar(pdata, '-', strlen(pdata));
783 if (ptr == NULL)
784 {
785 return 0;
786 }
787 }
788 return atoi(ptr);
789}
790
791static void adjustGMT2LocalTime(struct tm *src, int dGMTval)
792{
793 time_t t1, t2;
794 struct tm * ptm;
795 char buf[255];
796 int dShiftSec;
797
798 dShiftSec = dGMTval * 15 * 60;
799 t1 = mktime(src);
800 t2 = (time_t)(t1 + dShiftSec);
801 ptm = gmtime(&t2);
802
803 memcpy(src, ptm, sizeof(struct tm));
804}
805
806void updateSystemTime(const void *data, int datalen)
807{
808 char strTime[32];
809 struct tm tm;
810 time_t t;
811 int dGMTval;
812
813 if (data == NULL || datalen <= 0)
814 return;
815
816 memset(strTime, 0, sizeof(strTime));
817 strcat(strTime, "20");
818 strcat(strTime, (const char *)data);
819
820 dGMTval = getGMTval(strTime);
821 memset(&tm, 0, sizeof(struct tm));
822 strptime(strTime, "%Y/%m/%d,%H:%M:%S", &tm);
823
824 adjustGMT2LocalTime(&tm, dGMTval);
825
826 t = mktime(&tm);
827 stime(&t);
828
829 return;
830}
831void notifyDataSignal() {
832 RLOGE("notifyDataSignal()");
833 pthread_mutex_lock(&s_DataMutex);
834 pthread_cond_broadcast(&s_DataCond);
835 pthread_mutex_unlock(&s_DataMutex);
836}
837
838bool mtkItTest(const char* data) {
839 std::string str("");
840 str.append(data);
841 RLOGD("%s, data: %s", __FUNCTION__, str.c_str());
842 std::vector<std::string> all;
843 RequestInfo* pRI = NULL;
844 utils::tokenize(str, ',', all);
845 if(all[0] != std::string("TEST")) {
846 return false;
847 }
848 android::Parcel p;
849 size_t pos = p.dataPosition();
850 for(int i = 1 ; i < all.size(); i++) {
851 std::string str = all[i];
852 RLOGD("%s, all[%d]: %s", __FUNCTION__, i, str.c_str());
853 std::vector<std::string> items;
854 utils::tokenize(str, '=', items);
855 if(items.size() == 2) {
856 if(items[0] == std::string("INT")) {
857 int para = std::stoi(items[1]);
858 p.writeInt32(para);
859 } else if(items[0] == std::string("STR")) {
860 writeStringToParcel(p, items[1].c_str());
861 } else if(items[0] == std::string("REQ")) {
862 int request = std::stoi(items[1]);
863 pRI = creatRILInfoAndInit(request, UDP, (RIL_SOCKET_ID) ((0)));
864 }
865 } else {
866 RLOGD("%s, too many \"=\"");
867 }
868 }
869 if(pRI && pRI->pCI) {
870 p.setDataPosition(pos);
871 pRI->pCI->dispatchFunction(p, pRI);
872 } else {
873 if(pRI) {
874 free(pRI);
875 pRI = NULL;
876 }
877 }
878 return true;
879}