b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | /******************************************************************************
|
| 2 | *(C) Copyright 2021 ASR MicroElectronics Ltd.
|
| 3 | * All Rights Reserved
|
| 4 | ******************************************************************************/
|
| 5 | /*--------------------------------------------------------------------------------------------------------------------
|
| 6 | * -------------------------------------------------------------------------------------------------------------------
|
| 7 | *
|
| 8 | * Filename: ecall_daemon.c
|
| 9 | *
|
| 10 | * Description: ecall_daemon
|
| 11 | *
|
| 12 | * History:
|
| 13 | * June 22, 2021 - ZhouTao Creation of file
|
| 14 | *
|
| 15 | * Notes:
|
| 16 | *
|
| 17 | ******************************************************************************/
|
| 18 |
|
| 19 | #ifndef NO_AUDIO
|
| 20 |
|
| 21 | #include <stdlib.h>
|
| 22 | #include <string.h>
|
| 23 | #include <ctype.h>
|
| 24 | #include <libubus.h>
|
| 25 | #include <fcntl.h>
|
| 26 |
|
| 27 | #include "ecall_daemon.h"
|
| 28 | #include "at_tok.h"
|
| 29 | #include "ril.h"
|
| 30 | #include "rilutil.h"
|
| 31 | #include "audio_if_parameter.h"
|
| 32 | #include "ecall_sms.h"
|
| 33 |
|
| 34 | #define ECALL_CLCOK_ALARM CLOCK_BOOTTIME_ALARM
|
| 35 | #define MAX_NUMBER_LEN 40
|
| 36 | #define NG_ECALL_MT_DEFAULT_TEST_NUMBER_URL "default.virtual"
|
| 37 | #define NG_ECALL_MO_DEFAULT_TEST_NUMBER_URL "urn:service:test.sos.ecall"
|
| 38 | #define ECALL_SAVE_ALACK_PATH "./tmp/ecallSaveAlAck"
|
| 39 | #define ECALL_SAVE_ALACK_COUNT_MAX (100)
|
| 40 |
|
| 41 | char testNumber[MAX_NUMBER_LEN] = {'N','U','L','L', 0};
|
| 42 | char reconfigureNumber[MAX_NUMBER_LEN] = {'N','U','L','L', 0};
|
| 43 | char smsMsdNumber[MAX_NUMBER_LEN] = {'1', '1', '2', 0}; //ECALL_SMS_FALLBACK_NUMBER
|
| 44 | char nGMtEcallTestNumUrl[MAX_NUMBER_LEN] = {0};
|
| 45 | char nGMoEcallTestNumUrl[MAX_NUMBER_LEN] = {0};
|
| 46 | char ecall_msd[300] = {0};
|
| 47 | char ecall_msd_hex[150] = {0};
|
| 48 | static char gEcallMsdPath[64] = {0};
|
| 49 | static int gEcallMsdLen = 0;
|
| 50 | static int gEcallMsdSavedFlag = 0;
|
| 51 | static int gEcallCallID = 0;
|
| 52 | static int gPushVal = 0;
|
| 53 | static int gSmsMsd = 0;
|
| 54 | static int gEcallNW = 0;
|
| 55 | static int gEcallType = 0;
|
| 56 | static int gEcallCeer = 16;
|
| 57 | static int gEcallRedial = 0;
|
| 58 | static int gSimEcallOnly = 0;
|
| 59 | static int gSimEcallActive = 0;
|
| 60 | static int gEcallOnlySim = 0;
|
| 61 | static int gEcallOnlySimValid = 0;
|
| 62 | static int gEcallSmsProcess = 1;
|
| 63 | static int gEcallSaveAlAckCnt = 0;
|
| 64 | #ifdef EU
|
| 65 | static int gEcallMode = 0; //default ecall mode is EU
|
| 66 | #elif defined ERA
|
| 67 | static int gEcallMode = 1;
|
| 68 | #endif
|
| 69 |
|
| 70 | static int gEcallDialCnt = 0;
|
| 71 | static int gEcallSmsMsdCnt = 0;
|
| 72 | static int gCurrentHasCallSet = 0;
|
| 73 | static int gEacllUserUpdatedMsd = 0;
|
| 74 | DAEMON_ECALL_STATUS gEcallStatus = DAEMON_ECALL_IDLE;
|
| 75 |
|
| 76 | static int gEcallTimerInitialized = 0;
|
| 77 |
|
| 78 | struct blob_buf send_at_b;
|
| 79 | struct blob_buf ecall_sms_b;
|
| 80 | struct blob_buf ecall_cmgr_b;
|
| 81 |
|
| 82 | extern struct ubus_context *ecall_ctx;
|
| 83 | extern void ecall_sms_parse_pdu(char *smsPdu);
|
| 84 |
|
| 85 | static int gEcallUbusRilId = 0;
|
| 86 | /* ecall global count define */
|
| 87 | static int ECALL_AUTO_DIAL_ATTEMPTS = 10;
|
| 88 | //static int ECALL_MANUAL_DIAL_ATTEMPTS = 10;
|
| 89 | static int ECALL_SMS_MSD_RETRANSMIT_ATTEMPTS = 10; //INT_MEM_TRANSMIT_ATTEMPTS
|
| 90 |
|
| 91 | /* ecall global timer value define */
|
| 92 | static int ECALL_PSAP_CALLBACK_TMR_EU = 60*60; //60min
|
| 93 | static int ECALL_PSAP_CALLBACK_TMR_ERA = 20*60; //20min
|
| 94 | static int ECALL_DIAL_SETUP_TMR_EU = 60; //60s
|
| 95 | static int ECALL_DIAL_SETUP_TMR_ERA = 30; //30s
|
| 96 | static int ECALL_REDIAL_TMR_ERA = 30; //30s for ecall abnormal disconnect
|
| 97 | static int ECALL_REDIAL_HANGUP_TMR_INT = 5; //5s for ivs hangup and redial timer interval
|
| 98 | static int ECALL_DIAL_CLEARDOWN_TMR = 60*60; //60min
|
| 99 | static int ECALL_WAIT_HL_ACK_TMR = 5; //5s--T6
|
| 100 | static int ECALL_SMS_SEND_MSD_TMR = 60*60; //60min
|
| 101 | static int ECALL_WAIT_LL_ACK_TMR = 20; //20s--T7
|
| 102 | static int ECALL_NAD_DEREGISTRATION_TMR_ERA = 2*60*60; //120min--NAD_DEREGISTRATION_TIME
|
| 103 | static int ECALL_NAD_DEREGISTRATION_TMR_EU = 12*60*60; //720min--NAD_DEREGISTRATION_TIME
|
| 104 | static int ECALL_WAIT_T6_T7_TMR = 25;//ECALL_WAIT_HL_ACK_TMR + ECALL_WAIT_LL_ACK_TMR; //25s--T6+T7 timer
|
| 105 |
|
| 106 | static TIMER_t ecall_psap_callback_timer;
|
| 107 | static TIMER_t ecall_dial_cleardown_timer;
|
| 108 | static TIMER_t ecall_dial_setup_timer;
|
| 109 | static TIMER_t ecall_redial_timer;
|
| 110 | static TIMER_t ecall_wait_hl_ack_timer;
|
| 111 | static TIMER_t ecall_sms_retransmit_timer;
|
| 112 | static TIMER_t ecall_saved_sms_retransmit_timer;
|
| 113 | static TIMER_t ecall_deregister_network_timer;
|
| 114 |
|
| 115 | /* ecall timer callback function declared */
|
| 116 | static void ecall_psap_callback_cb(int sigNum, siginfo_t *pInfo, void *p);
|
| 117 | static void ecall_dial_cleardown_cb(int sigNum, siginfo_t *pInfo, void *p);
|
| 118 | static void ecall_smsMsd_retransmit_cb(int sigNum, siginfo_t *pInfo, void *p);
|
| 119 | static void ecall_retransmit_msd_cb(int sigNum, siginfo_t *pInfo, void *p);
|
| 120 | static void ecall_saved_smsMsd_retransmit_cb(int sigNum, siginfo_t *pInfo, void *p);
|
| 121 | static void ecall_deregister_network_cb(int sigNum, siginfo_t *pInfo, void *p);
|
| 122 | static void ecall_setup_cb(int sigNum, siginfo_t *pInfo, void *p);
|
| 123 | static void ecall_redial_setup_cb(int sigNum, siginfo_t *pInfo, void *p);
|
| 124 | static void ecall_hang_up(void);
|
| 125 |
|
| 126 | #define ecall_set_ecall_type(val) (gEcallType = val)
|
| 127 | #define ecall_get_ecall_type() (gEcallType)
|
| 128 |
|
| 129 | #define ecall_set_ecallNetwork(val) (gEcallNW = val)
|
| 130 | #define ecall_get_ecallNetwork() (gEcallNW)
|
| 131 |
|
| 132 | #define ecall_set_redial_flag(val) (gEcallRedial = val)
|
| 133 | #define ecall_get_redial_flag() (gEcallRedial)
|
| 134 |
|
| 135 | #define ecalL_daemon_set_ceerVal(val) (gEcallCeer = val)
|
| 136 | #define ecall_daemon_get_ceerVal() (gEcallCeer)
|
| 137 |
|
| 138 | #define ecall_set_sim_ecallOnly(val) (gSimEcallOnly = val)
|
| 139 | #define ecall_get_sim_ecallOnly() (gSimEcallOnly)
|
| 140 |
|
| 141 | #define ecall_set_sim_ecallActive(val) (gSimEcallActive = val)
|
| 142 | #define ecall_get_sim_ecallActive() (gSimEcallActive)
|
| 143 |
|
| 144 | #define ecall_set_ecallOnlySim(val) (gEcallOnlySim = val)
|
| 145 | #define ecall_get_ecallOnlySim() (gEcallOnlySim)
|
| 146 |
|
| 147 | #define ecall_set_ecallOnlySimValid(val) (gEcallOnlySimValid = val)
|
| 148 | #define ecall_get_ecallOnlySimValid() (gEcallOnlySimValid)
|
| 149 |
|
| 150 | #define ecall_daemon_set_smsProcess(val) (gEcallSmsProcess = val)
|
| 151 | #define ecall_daemon_get_smsProcess() (gEcallSmsProcess)
|
| 152 |
|
| 153 | #define ecall_set_ecall_hangup_redial_timer(val) (ECALL_REDIAL_HANGUP_TMR_INT = val)
|
| 154 | #define ecall_get_ecall_hangup_redial_timer() (ECALL_REDIAL_HANGUP_TMR_INT)
|
| 155 |
|
| 156 | #define ecall_set_smsMsd_send_count(val) (ECALL_SMS_MSD_RETRANSMIT_ATTEMPTS = val)
|
| 157 | #define ecall_get_smsMsd_send_count() (ECALL_SMS_MSD_RETRANSMIT_ATTEMPTS)
|
| 158 |
|
| 159 | #define ecall_set_ecalltimer_initialized(val) (gEcallTimerInitialized = val)
|
| 160 | #define ecall_get_ecalltimer_initialized() (gEcallTimerInitialized)
|
| 161 |
|
| 162 | #define ecall_get_ecall_redial_cnt() (gEcallDialCnt)
|
| 163 | #define ecall_reset_ecall_redial_cnt() (gEcallDialCnt = 0)
|
| 164 |
|
| 165 | #define ecall_get_ecall_status() (gEcallStatus)
|
| 166 | int ecall_set_ecall_status(DAEMON_ECALL_STATUS ecallStatus)
|
| 167 | {
|
| 168 | gEcallStatus = ecallStatus;
|
| 169 | return 0;
|
| 170 | }
|
| 171 |
|
| 172 | #define ecall_daemon_get_ecallPush() (gPushVal)
|
| 173 | int ecall_daemon_set_ecallPush(int val)
|
| 174 | {
|
| 175 | gPushVal = val;
|
| 176 | return 0;
|
| 177 | }
|
| 178 |
|
| 179 | int ecall_daemon_set_mode(int val)
|
| 180 | {
|
| 181 | gEcallMode = val;
|
| 182 |
|
| 183 | return 0;
|
| 184 | }
|
| 185 |
|
| 186 | int ecall_daemon_get_mode(void)
|
| 187 | {
|
| 188 | return gEcallMode;
|
| 189 | }
|
| 190 |
|
| 191 | int ecall_current_is_ecallOnly_mode(void)
|
| 192 | {
|
| 193 | if (((ecall_get_sim_ecallActive() != 5) && (ecall_get_ecallOnlySim() > 0)) //ecallonlysim > 0
|
| 194 | || (ecall_get_sim_ecallActive() == 1) //cs ecall only
|
| 195 | || (ecall_get_sim_ecallActive() == 2) //ng ecall only
|
| 196 | || (ecall_get_sim_ecallActive() == 3)) //es and ng ecall only
|
| 197 | {
|
| 198 | return 1;
|
| 199 | }
|
| 200 | else
|
| 201 | {
|
| 202 | return 0;
|
| 203 | }
|
| 204 | }
|
| 205 |
|
| 206 | unsigned int ecall_get_ubus_ril_id(void)
|
| 207 | {
|
| 208 | int ret = 0;
|
| 209 | unsigned int id = 0;
|
| 210 |
|
| 211 | if (gEcallUbusRilId > 0) {
|
| 212 | return gEcallUbusRilId;
|
| 213 | } else {
|
| 214 | ret = ubus_lookup_id(ecall_ctx, "ril", &id);
|
| 215 | if (ret == 0) {
|
| 216 | gEcallUbusRilId = id;
|
| 217 | } else {
|
| 218 | ECALL_Log("lookup ril object failed\n");
|
| 219 | return 0;
|
| 220 | }
|
| 221 | }
|
| 222 |
|
| 223 | return id;
|
| 224 | }
|
| 225 |
|
| 226 | char *ecall_strsep(char **s, const char *del)
|
| 227 | {
|
| 228 | char *begin = *s;
|
| 229 | char *end = NULL;
|
| 230 |
|
| 231 | if(begin == NULL)
|
| 232 | return NULL;
|
| 233 |
|
| 234 | end = strpbrk(begin, del);
|
| 235 | if(end)
|
| 236 | *end++ = '\0';
|
| 237 |
|
| 238 | *s = end;
|
| 239 | return begin;
|
| 240 | }
|
| 241 |
|
| 242 | char* ecallStrdup(const char* str)
|
| 243 | {
|
| 244 | char *result = NULL;
|
| 245 | int length = 0;
|
| 246 |
|
| 247 | if (str) {
|
| 248 | length = strlen(str);
|
| 249 | result = (char *)malloc(length +1);
|
| 250 | }
|
| 251 |
|
| 252 | if (result) {
|
| 253 | memcpy(result, str, length);
|
| 254 | result[length] = 0;
|
| 255 | }
|
| 256 |
|
| 257 | return result;
|
| 258 | }
|
| 259 |
|
| 260 | int at_tok_start(char **p_cur)
|
| 261 | {
|
| 262 | if (*p_cur == NULL)
|
| 263 | {
|
| 264 | return -1;
|
| 265 | }
|
| 266 |
|
| 267 | // skip prefix
|
| 268 | // consume "^[^:]:"
|
| 269 |
|
| 270 | *p_cur = strchr(*p_cur, ':');
|
| 271 |
|
| 272 | if (*p_cur == NULL)
|
| 273 | {
|
| 274 | return -1;
|
| 275 | }
|
| 276 |
|
| 277 | (*p_cur)++;
|
| 278 |
|
| 279 | return 0;
|
| 280 | }
|
| 281 |
|
| 282 | void skipWhiteSpace(char **p_cur)
|
| 283 | {
|
| 284 | if (*p_cur == NULL) return;
|
| 285 |
|
| 286 | while (**p_cur != '\0' && isspace(**p_cur))
|
| 287 | {
|
| 288 | (*p_cur)++;
|
| 289 | }
|
| 290 | }
|
| 291 |
|
| 292 | void skipNextComma(char **p_cur)
|
| 293 | {
|
| 294 | if (*p_cur == NULL) return;
|
| 295 |
|
| 296 | while (**p_cur != '\0' && **p_cur != ',')
|
| 297 | {
|
| 298 | (*p_cur)++;
|
| 299 | }
|
| 300 |
|
| 301 | if (**p_cur == ',')
|
| 302 | {
|
| 303 | (*p_cur)++;
|
| 304 | }
|
| 305 | }
|
| 306 |
|
| 307 | char * nextTok(char **p_cur)
|
| 308 | {
|
| 309 | char *ret = NULL;
|
| 310 |
|
| 311 | skipWhiteSpace(p_cur);
|
| 312 |
|
| 313 | if (*p_cur == NULL)
|
| 314 | {
|
| 315 | ret = NULL;
|
| 316 | }
|
| 317 | else if (**p_cur == '"')
|
| 318 | {
|
| 319 | (*p_cur)++;
|
| 320 | ret = ecall_strsep(p_cur, "\"");
|
| 321 | skipNextComma(p_cur);
|
| 322 | }
|
| 323 | else
|
| 324 | {
|
| 325 | ret = ecall_strsep(p_cur, ",");
|
| 326 | }
|
| 327 |
|
| 328 | return ret;
|
| 329 | }
|
| 330 |
|
| 331 |
|
| 332 | int at_tok_nextint_base(char **p_cur, int *p_out, int base, int uns)
|
| 333 | {
|
| 334 | char *ret;
|
| 335 |
|
| 336 | if (*p_cur == NULL)
|
| 337 | {
|
| 338 | return -1;
|
| 339 | }
|
| 340 |
|
| 341 | ret = nextTok(p_cur);
|
| 342 |
|
| 343 | if (ret == NULL)
|
| 344 | {
|
| 345 | return -1;
|
| 346 | }
|
| 347 | else
|
| 348 | {
|
| 349 | long l;
|
| 350 | char *end;
|
| 351 |
|
| 352 | if (uns)
|
| 353 | l = strtoul(ret, &end, base);
|
| 354 | else
|
| 355 | l = strtol(ret, &end, base);
|
| 356 |
|
| 357 | *p_out = (int)l;
|
| 358 | }
|
| 359 |
|
| 360 | return 0;
|
| 361 | }
|
| 362 |
|
| 363 |
|
| 364 | int at_tok_nextint(char **p_cur, int *p_out)
|
| 365 | {
|
| 366 | return at_tok_nextint_base(p_cur, p_out, 10, 0);
|
| 367 | }
|
| 368 |
|
| 369 | int at_tok_nextstr(char **p_cur, char **p_out)
|
| 370 | {
|
| 371 | if (*p_cur == NULL)
|
| 372 | {
|
| 373 | return -1;
|
| 374 | }
|
| 375 |
|
| 376 | *p_out = nextTok(p_cur);
|
| 377 |
|
| 378 | return 0;
|
| 379 | }
|
| 380 |
|
| 381 | /** returns 1 on "has more tokens" and 0 if no */
|
| 382 | int at_tok_hasmore(char **p_cur)
|
| 383 | {
|
| 384 | return !(*p_cur == NULL || **p_cur == '\0');
|
| 385 | }
|
| 386 |
|
| 387 | int ecall_invoke_noreply(unsigned int sAtpIndex, const char *service,
|
| 388 | const char *method, struct blob_attr *msg)
|
| 389 | {
|
| 390 | UNUSED(sAtpIndex);
|
| 391 |
|
| 392 | struct ubus_context *ctx;
|
| 393 | int rc;
|
| 394 | uint32_t id;
|
| 395 | struct ubus_request req;
|
| 396 |
|
| 397 | ctx = ubus_connect(NULL);
|
| 398 | if (!ctx)
|
| 399 | return -1;
|
| 400 |
|
| 401 | ubus_add_uloop(ctx);
|
| 402 |
|
| 403 | /* Look up the target object id by the object path */
|
| 404 | rc = ubus_lookup_id(ctx, service, &id);
|
| 405 | if (rc != 0)
|
| 406 | return -1;
|
| 407 |
|
| 408 | rc = ubus_invoke_async(ctx, id, method, msg, &req);
|
| 409 | if (rc != 0)
|
| 410 | return -1;
|
| 411 |
|
| 412 | /* cancel req (on client side) because noreply is needed */
|
| 413 | ubus_abort_request(ctx, &req);
|
| 414 | return 0;
|
| 415 | }
|
| 416 |
|
| 417 | static void ecall_rilrequest_cb(struct ubus_request *req, int type, struct blob_attr *msg)
|
| 418 | {
|
| 419 | UNUSED(type);
|
| 420 | UNUSED(req);
|
| 421 |
|
| 422 | unsigned int rilid = 0;
|
| 423 | unsigned int rilerror = 0;
|
| 424 | void *data = NULL;
|
| 425 | int datalen = 0;
|
| 426 | int ret = 0;
|
| 427 | char *respPtr = NULL;
|
| 428 |
|
| 429 | //ENTER();
|
| 430 | ret = rilutil_parseResponse(msg, &rilid, &rilerror, &data, &datalen);
|
| 431 | if (ret)
|
| 432 | goto end;
|
| 433 |
|
| 434 | ECALL_Log("ecall_rilrequest_cb recv rilid %d, rilerror %d.\n", rilid, rilerror);
|
| 435 |
|
| 436 | switch (rilid) {
|
| 437 | case RIL_REQUEST_SEND_ATCMD:
|
| 438 | {
|
| 439 | if (rilerror) {
|
| 440 | ECALL_Log("Get at response err %d\n", rilerror);
|
| 441 | goto end;
|
| 442 | }
|
| 443 |
|
| 444 | ECALL_Log("Get at response: %s\n", data);
|
| 445 |
|
| 446 | if (data)
|
| 447 | {
|
| 448 | respPtr = data;
|
| 449 | if (strncmp(respPtr, "*ECALLONLY:", strlen("*ECALLONLY:")) == 0)
|
| 450 | {
|
| 451 | ecall_handle_ecallOnly_response(respPtr);
|
| 452 | }
|
| 453 | if (strncmp(respPtr, "*ECALLONLYSIM:", strlen("*ECALLONLYSIM:")) == 0)
|
| 454 | {
|
| 455 | ecall_handle_ecallOnlySim_response(respPtr);
|
| 456 | }
|
| 457 | else if (strncmp(respPtr, "+CEER:", strlen("+CEER:")) == 0)
|
| 458 | {
|
| 459 | ecall_handle_ceer_response(respPtr);
|
| 460 | }
|
| 461 | else if (strncmp(respPtr, "*ECALLMSDGEN:", strlen("*ECALLMSDGEN:")) == 0)
|
| 462 | {
|
| 463 | ecall_handle_msdGen_response(respPtr);
|
| 464 | }
|
| 465 | else
|
| 466 | {
|
| 467 |
|
| 468 | }
|
| 469 | }
|
| 470 | break;
|
| 471 | }
|
| 472 | case RIL_REQUEST_GET_SIM_STATUS:
|
| 473 | {
|
| 474 | if (rilerror) {
|
| 475 | ECALL_Log("Get sim status err %d\n", rilerror);
|
| 476 | goto end;
|
| 477 | }
|
| 478 |
|
| 479 | ECALL_Log("Get sim status: %s\n", data);
|
| 480 | }
|
| 481 | break;
|
| 482 |
|
| 483 | case RIL_REQUEST_SEND_SMS:
|
| 484 | {
|
| 485 | if (rilerror) {
|
| 486 | ECALL_Log("Get send sms status err %d\n", rilerror);
|
| 487 | goto end;
|
| 488 | }
|
| 489 | /* sms send successed. */
|
| 490 | ecallHandleSmsMsdResp();
|
| 491 | ECALL_Log("ecall send sms status: %s\n", data);
|
| 492 | }
|
| 493 | break;
|
| 494 |
|
| 495 | case RIL_REQUEST_GET_NW_DOMAIN:
|
| 496 | if (rilerror) {
|
| 497 | ECALL_Log("Get network status err %d\n", rilerror);
|
| 498 | goto end;
|
| 499 | }
|
| 500 | /* sms send successed. */
|
| 501 | ret = handle_ecallNetwork((char*)data);
|
| 502 | if (ret > 0) {
|
| 503 | ecall_set_ecallNetwork(1);
|
| 504 | } else {
|
| 505 | ecall_set_ecallNetwork(0);
|
| 506 | }
|
| 507 | ECALL_Log("ecall get network status: %d\n", ret);
|
| 508 | break;
|
| 509 |
|
| 510 | case RIL_REQUEST_GET_CMGR:
|
| 511 | if (rilerror) {
|
| 512 | ECALL_Log("Get cmgr err %d\n", rilerror);
|
| 513 | goto end;
|
| 514 | }
|
| 515 | ECALL_Log("ecall get cmgr data: %s\n", (char *)data);
|
| 516 | ecallHandleSmsReceived((const char *)data);
|
| 517 | break;
|
| 518 | default:
|
| 519 | break;
|
| 520 | }
|
| 521 |
|
| 522 | end:
|
| 523 | if (data)
|
| 524 | rilutil_freeResponseData(rilid, data, datalen);
|
| 525 |
|
| 526 | //LEAVE();
|
| 527 | }
|
| 528 |
|
| 529 | unsigned int ecall_ubusSendEcallCmd(unsigned int sAtpIndex, unsigned int op_id, unsigned int param1, char* MSD)
|
| 530 | {
|
| 531 | unsigned int length;
|
| 532 | struct blob_buf outBlob;
|
| 533 | unsigned int ret = 1;
|
| 534 | unsigned int origParserId = sAtpIndex;
|
| 535 |
|
| 536 | memset(&outBlob, 0, sizeof(outBlob));
|
| 537 |
|
| 538 | blob_buf_init(&outBlob, 0);
|
| 539 |
|
| 540 | if(MSD != NULL)
|
| 541 | length = sizeof(op_id) + sizeof(param1) + 140; //ECALL_MSD_BIN_MAX_LEN 140
|
| 542 | else
|
| 543 | length = sizeof(op_id) + sizeof(param1);
|
| 544 |
|
| 545 | //DBGMSG(ubusSendEcallCmd, "%s: length = %d.\n", __FUNCTION__, length);
|
| 546 |
|
| 547 | blobmsg_add_u32(&outBlob, "length", (unsigned int)length);
|
| 548 | blobmsg_add_u32(&outBlob, "op", (unsigned int)op_id);
|
| 549 | blobmsg_add_u32(&outBlob, "param1", (unsigned int)param1);
|
| 550 |
|
| 551 | if(MSD != NULL)
|
| 552 | blobmsg_add_string(&outBlob, "data", MSD);
|
| 553 |
|
| 554 | if (ecall_invoke_noreply(origParserId, "audio_if", AUDIO_IF_UBUS_ECALL_DATA_SET, outBlob.head) == 0) {
|
| 555 | //ret = ATRESP( atHandle, ATCI_RESULT_CODE_OK, 0, NULL);
|
| 556 | ret = 0;
|
| 557 | ECALL_Log("%s: succeed in sending AUDIO_IF_UBUS_ECALL_DATA_SET\n", __FUNCTION__);
|
| 558 | } else {
|
| 559 | //ret = ATRESP( atHandle, ATCI_RESULT_CODE_CME_ERROR, CME_UNKNOWN, NULL);
|
| 560 | ret = 1;
|
| 561 | ECALL_Log("%s: fail to send AUDIO_IF_UBUS_ECALL_DATA_SET\n", __FUNCTION__);
|
| 562 | }
|
| 563 |
|
| 564 | blob_buf_free(&outBlob);
|
| 565 |
|
| 566 | return(ret);
|
| 567 | }
|
| 568 |
|
| 569 | int ecallSendAtCmd(void *data, int sync)
|
| 570 | {
|
| 571 | int ret;
|
| 572 | unsigned int id = 0;
|
| 573 | int len = 0;
|
| 574 | struct ubus_request *req = NULL;
|
| 575 |
|
| 576 | len = strlen(data)+1;
|
| 577 | blob_buf_init(&send_at_b, 0);
|
| 578 | rilutil_makeRequestBlob(&send_at_b, RIL_REQUEST_SEND_ATCMD, data, len);
|
| 579 |
|
| 580 | id = ecall_get_ubus_ril_id();
|
| 581 | if (id == 0)
|
| 582 | return -1;
|
| 583 |
|
| 584 | req = (struct ubus_request *)malloc(sizeof(struct ubus_request));
|
| 585 | if (req == NULL) {
|
| 586 | ECALL_Log("leave ecallSendAtCmd: lack of memory\n");
|
| 587 | return -2;
|
| 588 | }
|
| 589 |
|
| 590 | if (sync)
|
| 591 | ret = ubus_invoke(ecall_ctx, id, "ril_request", send_at_b.head, ecall_rilrequest_cb, NULL, 0);
|
| 592 | else {
|
| 593 | ret = ubus_invoke_async(ecall_ctx, id, "ril_request", send_at_b.head, req);
|
| 594 | req->data_cb = ecall_rilrequest_cb;
|
| 595 | req->priv = data;
|
| 596 | ubus_complete_request_async(ecall_ctx, req);
|
| 597 | }
|
| 598 | return ret;
|
| 599 | }
|
| 600 |
|
| 601 | static void ecall_start_auto_answer(int timeVal)
|
| 602 | {
|
| 603 | char arr[64] = {0};
|
| 604 |
|
| 605 | sprintf(arr, "ATS0=1\r");
|
| 606 | ecallSendAtCmd(arr, 1);
|
| 607 | ecall_disable_timer(ecall_psap_callback_timer);
|
| 608 | ecall_enable_timer(ecall_psap_callback_timer, timeVal);
|
| 609 | ECALL_Log("%s: leave.", __FUNCTION__);
|
| 610 |
|
| 611 | return;
|
| 612 | }
|
| 613 |
|
| 614 | void ecall_stop_auto_answer(void)
|
| 615 | {
|
| 616 | char arr[64] = {0};
|
| 617 | int ret = 0;
|
| 618 |
|
| 619 | sprintf(arr, "ATS0=0\r");
|
| 620 | ret = ecallSendAtCmd(arr, 1);
|
| 621 | ECALL_Log("%s: ret=%d, leave.", __FUNCTION__, ret);
|
| 622 |
|
| 623 | return;
|
| 624 | }
|
| 625 |
|
| 626 | /* ecall timer callback function define */
|
| 627 | static void ecall_psap_callback_cb(int sigNum, siginfo_t *pInfo, void *p)
|
| 628 | {
|
| 629 | UNUSED(sigNum);
|
| 630 | UNUSED(pInfo);
|
| 631 | UNUSED(p);
|
| 632 |
|
| 633 | ECALL_Log("%s: enter, ecall status=%d.\n", __FUNCTION__, gEcallStatus);
|
| 634 | ecall_stop_auto_answer();
|
| 635 |
|
| 636 | return;
|
| 637 | }
|
| 638 |
|
| 639 | static void ecall_dial_cleardown_nomal(void)
|
| 640 | {
|
| 641 | char arr[64] = {0};
|
| 642 | int ret = 0;
|
| 643 |
|
| 644 | sprintf(arr, "ATH\r");
|
| 645 | ret = ecallSendAtCmd((void*)arr, 1);
|
| 646 | sleep(1); //sleep 1s
|
| 647 | ECALL_Log("%s: ecall send hang up at for nomal call, ret=%d.\n", __FUNCTION__, ret);
|
| 648 | return;
|
| 649 | }
|
| 650 |
|
| 651 | static void ecall_dial_cleardown_cb(int sigNum, siginfo_t *pInfo, void *p)
|
| 652 | {
|
| 653 | UNUSED(sigNum);
|
| 654 | UNUSED(pInfo);
|
| 655 | UNUSED(p);
|
| 656 |
|
| 657 | char arr[64] = {0};
|
| 658 | int ret = 0;
|
| 659 |
|
| 660 | sprintf(arr, "AT+CECALLINSIDE=5\r");
|
| 661 | ret = ecallSendAtCmd((void*)arr, 1);
|
| 662 | ECALL_Log("%s: ecall send hang up at ret=%d.\n", __FUNCTION__, ret);
|
| 663 | sleep(2); //sleep 2s
|
| 664 | return;
|
| 665 | }
|
| 666 |
|
| 667 | static void ecall_setup_cb(int sigNum, siginfo_t *pInfo, void *p)
|
| 668 | {
|
| 669 | UNUSED(sigNum);
|
| 670 | UNUSED(pInfo);
|
| 671 | UNUSED(p);
|
| 672 |
|
| 673 | ECALL_Log("%s: enter, gEcallDialCnt=%d, ecall status=%d.\n", __FUNCTION__, gEcallDialCnt, gEcallStatus);
|
| 674 | if (gEcallDialCnt < ECALL_AUTO_DIAL_ATTEMPTS) {
|
| 675 | ecall_hang_up(); //hangup ecall
|
| 676 | }
|
| 677 |
|
| 678 | ecall_disable_timer(ecall_redial_timer);
|
| 679 | ecall_enable_timer(ecall_redial_timer, ecall_get_ecall_hangup_redial_timer());
|
| 680 |
|
| 681 | return;
|
| 682 | }
|
| 683 |
|
| 684 | static void ecall_redial_setup_cb(int sigNum, siginfo_t *pInfo, void *p)
|
| 685 | {
|
| 686 | UNUSED(sigNum);
|
| 687 | UNUSED(pInfo);
|
| 688 | UNUSED(p);
|
| 689 |
|
| 690 | ECALL_Log("%s: enter, gEcallDialCnt=%d, ecall status=%d.\n", __FUNCTION__, gEcallDialCnt, gEcallStatus);
|
| 691 |
|
| 692 | if (ecall_daemon_get_mode() == 1) { //ERA, redial timer=30s, 33464 spec define era redial is retry 10 times within 5mins
|
| 693 | if (gEcallDialCnt < ECALL_AUTO_DIAL_ATTEMPTS) {
|
| 694 | if (ecall_get_ecall_status() < DAEMON_ECALL_MO_SETUP) { //redial and send msd
|
| 695 | ecall_redial_and_send_msd();
|
| 696 | gEcallDialCnt++;
|
| 697 | } else {
|
| 698 | ECALL_Log("%s1: redial failed, gEcallDialCnt=%d, ecall status=%d.\n", __FUNCTION__, gEcallDialCnt, gEcallStatus);
|
| 699 | }
|
| 700 | } else {
|
| 701 | //if (gEcallCallID != 0) { //has ecall dialing and alerting and 30s timeout, hang up it
|
| 702 | // ecall_dial_cleardown_cb(NULL); //hangup ecall
|
| 703 | //}
|
| 704 | ECALL_Log("%s: redial attempts times has exhausted, wait PSAP answer call or network hang up call.\n", __FUNCTION__);
|
| 705 | }
|
| 706 | } else { //EU, redial timer=60s, when call isn't setup or call is ring always but not answer, IVS need redial witnin 2mins
|
| 707 | if (ecall_get_ecall_status() < DAEMON_ECALL_MO_SETUP) { //redial and send msd
|
| 708 | ecall_redial_and_send_msd();
|
| 709 | } else {
|
| 710 | ECALL_Log("%s2: redial failed, gEcallDialCnt=%d, ecall status=%d.\n", __FUNCTION__, gEcallDialCnt, gEcallStatus);
|
| 711 | }
|
| 712 | }
|
| 713 |
|
| 714 | return;
|
| 715 | }
|
| 716 |
|
| 717 | static void ecall_retransmit_msd_cb(int sigNum, siginfo_t *pInfo, void *p)
|
| 718 | {
|
| 719 | UNUSED(sigNum);
|
| 720 | UNUSED(pInfo);
|
| 721 | UNUSED(p);
|
| 722 |
|
| 723 | ECALL_Log("%s: enter, gEcallDialCnt=%d, ecall status=%d.\n", __FUNCTION__, gEcallDialCnt, gEcallStatus);
|
| 724 |
|
| 725 | if (ecall_daemon_get_mode() == 1) { //ERA mode, when msd send failed IVS need use SMS send msd.
|
| 726 | if (ecall_get_ecall_status() == DAEMON_ECALL_MO_MSD || ecall_get_ecall_status() == DAEMON_ECALL_MO_SETUP) {
|
| 727 | if (gEcallCallID != 0) //current ecall isn't hangup, so use sms send msd
|
| 728 | ecall_sms_send_cfg_msd();
|
| 729 | else //current ecall has hangup, ivs need redial and send msd
|
| 730 | ecall_redial_and_send_msd();
|
| 731 | } else {
|
| 732 | ecall_set_ecall_status(DAEMON_ECALL_IDLE);
|
| 733 | }
|
| 734 | } else { //EU mode, when msd send failed and duration timer=2min isn't expiered, IVS need redial and send msd via in-band.
|
| 735 | if (ecall_get_ecall_status() >= DAEMON_ECALL_MO_MSD) {
|
| 736 | //ecallStopTimer(&ecall_wait_hl_ack_timer);
|
| 737 | ecall_disable_timer(ecall_wait_hl_ack_timer);
|
| 738 | ecall_retransmit_send_msd();
|
| 739 | } else {
|
| 740 | ECALL_Log("%s: redial failed, gEcallDialCnt=%d, ecall status=%d.\n", __FUNCTION__, gEcallDialCnt, gEcallStatus);
|
| 741 | return;
|
| 742 | }
|
| 743 | }
|
| 744 |
|
| 745 | return;
|
| 746 | }
|
| 747 |
|
| 748 | static void ecall_smsMsd_retransmit_cb(int sigNum, siginfo_t *pInfo, void *p)
|
| 749 | {
|
| 750 | UNUSED(sigNum);
|
| 751 | UNUSED(pInfo);
|
| 752 | UNUSED(p);
|
| 753 | int ret = 0;
|
| 754 |
|
| 755 | ECALL_Log("%s: enter, gEcallSmsMsdCnt=%d, ecall status=%d.\n", __FUNCTION__, gEcallSmsMsdCnt, gEcallStatus);
|
| 756 | if (ecall_daemon_get_mode() == 1 && gSmsMsd == 1) {
|
| 757 | if (gEcallSmsMsdCnt < ECALL_SMS_MSD_RETRANSMIT_ATTEMPTS) {
|
| 758 | if (ecall_get_ecall_status() == DAEMON_ECALL_SMS) {
|
| 759 | ret = ecall_sms_send_cfg_msd();
|
| 760 | if (ret == 0 || ret == -1) {
|
| 761 | ecall_disable_timer(ecall_sms_retransmit_timer);
|
| 762 | ecall_enable_timer(ecall_sms_retransmit_timer, ECALL_SMS_SEND_MSD_TMR);
|
| 763 | }
|
| 764 | } else {
|
| 765 | ecall_set_ecall_status(DAEMON_ECALL_IDLE);
|
| 766 | }
|
| 767 | } else {
|
| 768 | gEcallSmsMsdCnt = 0;
|
| 769 | ecall_set_ecall_status(DAEMON_ECALL_IDLE);
|
| 770 | }
|
| 771 | } else {
|
| 772 | ecall_msd_saved("/tmp/ecall_msd_sms_send_failed", ecall_msd);
|
| 773 | ECALL_Log("ecall_smsMsd_retransmit_cb: sms send msd failed and gEcallMode %d, gSmsMsd %d.", gEcallMode, gSmsMsd);
|
| 774 | }
|
| 775 |
|
| 776 | return;
|
| 777 | }
|
| 778 |
|
| 779 | static void ecall_saved_smsMsd_retransmit_cb(int sigNum, siginfo_t *pInfo, void *p)
|
| 780 | {
|
| 781 | UNUSED(sigNum);
|
| 782 | UNUSED(pInfo);
|
| 783 | UNUSED(p);
|
| 784 |
|
| 785 | ecall_get_network_status();
|
| 786 | ECALL_Log("%s: enter, gEcallNW=%d, gEcallMode=%d, gEcallMsdSavedFlag=%d.\n", __FUNCTION__, gEcallNW, gEcallMode, gEcallMsdSavedFlag);
|
| 787 |
|
| 788 | if (ecall_get_ecallNetwork() > 0 || (gEcallMsdSavedFlag > 0))
|
| 789 | {
|
| 790 | if ((ecall_daemon_get_mode() == 1) && (gEcallMsdSavedFlag > 0))
|
| 791 | {
|
| 792 | ecall_sms_send_saved_msd();
|
| 793 | }
|
| 794 | }
|
| 795 | else
|
| 796 | {
|
| 797 | //ecallStopTimer(&ecall_saved_sms_retransmit_timer);
|
| 798 | ecall_disable_timer(ecall_saved_sms_retransmit_timer);
|
| 799 | //ecallStartTimer(&ecall_saved_sms_retransmit_timer, ECALL_SMS_SEND_MSD_TMR);
|
| 800 | ecall_enable_timer(ecall_saved_sms_retransmit_timer, ECALL_SMS_SEND_MSD_TMR);
|
| 801 | }
|
| 802 |
|
| 803 | return;
|
| 804 | }
|
| 805 |
|
| 806 | static void ecall_deregister_network_cb(int sigNum, siginfo_t *pInfo, void *p)
|
| 807 | {
|
| 808 | UNUSED(sigNum);
|
| 809 | UNUSED(pInfo);
|
| 810 | UNUSED(p);
|
| 811 |
|
| 812 | char arr[64] = {0};
|
| 813 |
|
| 814 | sprintf(arr, "AT*ECALLREG=0\r");
|
| 815 | ecallSendAtCmd(arr, 1);
|
| 816 |
|
| 817 | ECALL_Log("%s: leave.", __FUNCTION__);
|
| 818 |
|
| 819 | ecall_disable_timer(&ecall_deregister_network_timer);
|
| 820 |
|
| 821 | return;
|
| 822 | }
|
| 823 |
|
| 824 | static void ecall_hang_up(void)
|
| 825 | {
|
| 826 | char arr[64] = {0};
|
| 827 | int ret = 0;
|
| 828 |
|
| 829 | //sprintf(arr, "AT+CECALLINSIDE=5\r");
|
| 830 | sprintf(arr, "ATH\r");
|
| 831 | ret = ecallSendAtCmd((void*)arr, 1);
|
| 832 | ECALL_Log("%s: ecall send hang up at ret=%d.\n", __FUNCTION__, ret);
|
| 833 |
|
| 834 | return;
|
| 835 | }
|
| 836 |
|
| 837 | void ecall_redial_and_send_msd(void)
|
| 838 | {
|
| 839 | int ecallType = 0;
|
| 840 | int pushVal = 0;
|
| 841 | char arr[400] = {0};
|
| 842 | int ret = 0;
|
| 843 |
|
| 844 | ecallType = gEcallType;
|
| 845 | pushVal = ecall_daemon_get_ecallPush();
|
| 846 | ECALL_Log("%s: this is %d redial.", __FUNCTION__, gEcallDialCnt);
|
| 847 | ECALL_Log("%s: ecall type=%d, ecall push=%d.", __FUNCTION__, ecallType, pushVal);
|
| 848 |
|
| 849 | ecall_set_ecall_status(DAEMON_ECALL_IDLE);
|
| 850 | if (0 != strlen(ecall_msd)) {
|
| 851 | /* AT*ECALLMSD=MSD */
|
| 852 | memset(arr, 0, 400);
|
| 853 | sprintf(arr, "AT*ECALLMSD=%s\r", ecall_msd);
|
| 854 | ret = ecallSendAtCmd((void*)arr, 0);
|
| 855 |
|
| 856 | /* AT+CECALL=ecallType */
|
| 857 | memset(arr, 0, 400);
|
| 858 | sprintf(arr, "AT+CECALL=%d\r", ecallType);
|
| 859 | ret = ecallSendAtCmd((void*)arr, 0);
|
| 860 |
|
| 861 | /* AT*ECALLPUSH */
|
| 862 | if (pushVal) {
|
| 863 | memset(arr, 0, 400);
|
| 864 | sprintf(arr, "AT*ECALLPUSH\r");
|
| 865 | ret = ecallSendAtCmd((void*)arr, 0);
|
| 866 | }
|
| 867 |
|
| 868 | ECALL_Log("%s: redial success and ret=%d.", __FUNCTION__, ret);
|
| 869 | } else {
|
| 870 | ECALL_Log("%s: redial failed.", __FUNCTION__);
|
| 871 | }
|
| 872 | }
|
| 873 |
|
| 874 | void ecall_retransmit_send_msd(void)
|
| 875 | {
|
| 876 | int ecallType = 0;
|
| 877 | int pushVal = 0;
|
| 878 | char arr[400] = {0};
|
| 879 | int ret = 0;
|
| 880 |
|
| 881 | ecallType = gEcallType;
|
| 882 | pushVal = ecall_daemon_get_ecallPush();
|
| 883 | ECALL_Log("%s: ecall type=%d, ecall push=%d.", __FUNCTION__, ecallType, pushVal);
|
| 884 |
|
| 885 | ecall_set_ecall_status(DAEMON_ECALL_MO_SETUP);
|
| 886 | if (0 != strlen(ecall_msd)) {
|
| 887 | /* AT*ECALLMSD=MSD */
|
| 888 | memset(arr, 0, 400);
|
| 889 | sprintf(arr, "AT*ECALLMSD=%s\r", ecall_msd);
|
| 890 | ret = ecallSendAtCmd((void*)arr, 0);
|
| 891 |
|
| 892 | /* AT*ECALLPUSH */
|
| 893 | if (pushVal) {
|
| 894 | memset(arr, 0, 400);
|
| 895 | sprintf(arr, "AT*ECALLPUSH\r");
|
| 896 | ret = ecallSendAtCmd((void*)arr, 0);
|
| 897 | }
|
| 898 |
|
| 899 | ECALL_Log("%s: retransmit send msd success and ret=%d.", __FUNCTION__, ret);
|
| 900 | } else {
|
| 901 | ECALL_Log("%s: retransmit send msd failed.", __FUNCTION__);
|
| 902 | }
|
| 903 | }
|
| 904 |
|
| 905 | void ecall_redial_only(void)
|
| 906 | {
|
| 907 | int ecallType = 0;
|
| 908 | char arr[64] = {0};
|
| 909 | int ret = 0;
|
| 910 |
|
| 911 | ecallType = gEcallType;
|
| 912 | //ecall_dial_cleardown_cb(NULL); //hangup ecall
|
| 913 |
|
| 914 | sprintf(arr, "AT+CECALL=%d\r", ecallType);
|
| 915 | ret = ecallSendAtCmd((void*)arr, 1);
|
| 916 | ECALL_Log("ecall_redial_only: redial success and ecallType=%d, ret=%d.", ecallType, ret);
|
| 917 | return;
|
| 918 | }
|
| 919 |
|
| 920 | int RildReady(void)
|
| 921 | {
|
| 922 | unsigned int ril_id;
|
| 923 |
|
| 924 | ril_id = ecall_get_ubus_ril_id();
|
| 925 | if (ril_id > 0)
|
| 926 | return 1;
|
| 927 |
|
| 928 | return 0;
|
| 929 | }
|
| 930 |
|
| 931 | int ecall_subscriber_cb(struct ubus_context *ctx, struct ubus_object *obj,
|
| 932 | struct ubus_request_data *req, const char *method, struct blob_attr *msg)
|
| 933 | {
|
| 934 | UNUSED(ctx);
|
| 935 | UNUSED(obj);
|
| 936 | UNUSED(req);
|
| 937 | UNUSED(method);
|
| 938 |
|
| 939 | unsigned int requestid = 0;
|
| 940 | unsigned int rilerrno = 0;
|
| 941 | void *response = NULL;
|
| 942 | int responselen = 0;
|
| 943 | int ret = 0;
|
| 944 |
|
| 945 | ret = rilutil_parseResponse(msg, &requestid, &rilerrno, &response, &responselen);
|
| 946 | if (ret)
|
| 947 | goto end;
|
| 948 |
|
| 949 | ECALL_Log("ecall_subscriber_cb: rcv %d", requestid);
|
| 950 |
|
| 951 | ecall_handle_ril_ind(ctx, requestid, rilerrno, response, responselen);
|
| 952 |
|
| 953 | end:
|
| 954 | if (response)
|
| 955 | rilutil_freeResponseData(requestid,response,responselen);
|
| 956 |
|
| 957 | return 0;
|
| 958 | }
|
| 959 |
|
| 960 | void ecall_subscriber_remove_cb(struct ubus_context *ctx, struct ubus_subscriber *obj, uint32_t id)
|
| 961 | {
|
| 962 | UNUSED(ctx);
|
| 963 | UNUSED(obj);
|
| 964 | UNUSED(id);
|
| 965 | ECALL_Log("ecall_subscriber_remove_cb");
|
| 966 | }
|
| 967 |
|
| 968 | void ecall_handle_ecallOnly_response(const char *s)
|
| 969 | {
|
| 970 | int err;
|
| 971 | char *line = ecallStrdup((char *)s);
|
| 972 | int ecallActive = 0;
|
| 973 | int simEcall = 0;
|
| 974 | char *pStart = NULL;
|
| 975 |
|
| 976 | ECALL_Log("%s: %s", __FUNCTION__,s);
|
| 977 | pStart = line;
|
| 978 | err = at_tok_start(&line);
|
| 979 | if(err < 0) {
|
| 980 | goto error;
|
| 981 | }
|
| 982 |
|
| 983 | if (at_tok_hasmore(&line))
|
| 984 | {
|
| 985 | err = at_tok_nextint(&line, &ecallActive);
|
| 986 | if(err < 0)
|
| 987 | goto error;
|
| 988 | }
|
| 989 |
|
| 990 | if (at_tok_hasmore(&line))
|
| 991 | {
|
| 992 | err = at_tok_nextint(&line, &simEcall);
|
| 993 | if(err < 0)
|
| 994 | goto error;
|
| 995 | }
|
| 996 |
|
| 997 | ECALL_Log("%s rcv: ecallActive=%d, simEcall=%d", __FUNCTION__, ecallActive, simEcall);
|
| 998 |
|
| 999 | ecall_set_sim_ecallActive(ecallActive);
|
| 1000 | ecall_set_sim_ecallOnly(simEcall);
|
| 1001 |
|
| 1002 | error:
|
| 1003 | if(pStart) {
|
| 1004 | free(pStart);
|
| 1005 | }
|
| 1006 |
|
| 1007 | return;
|
| 1008 | }
|
| 1009 |
|
| 1010 | void ecall_handle_ecallOnlySim_response(const char *s)
|
| 1011 | {
|
| 1012 | int err;
|
| 1013 | char *line = ecallStrdup((char *)s);
|
| 1014 | int ecallOnlySim = 0;
|
| 1015 | char *pStart = NULL;
|
| 1016 |
|
| 1017 | ECALL_Log("%s: %s", __FUNCTION__,s);
|
| 1018 | pStart = line;
|
| 1019 | err = at_tok_start(&line);
|
| 1020 | if(err < 0) {
|
| 1021 | goto error;
|
| 1022 | }
|
| 1023 |
|
| 1024 | if (at_tok_hasmore(&line))
|
| 1025 | {
|
| 1026 | err = at_tok_nextint(&line, &ecallOnlySim);
|
| 1027 | if(err < 0)
|
| 1028 | goto error;
|
| 1029 | }
|
| 1030 |
|
| 1031 | ECALL_Log("%s rcv: ecallOnlySim=%d", __FUNCTION__, ecallOnlySim);
|
| 1032 |
|
| 1033 | ecall_set_ecallOnlySim(ecallOnlySim);
|
| 1034 | ecall_set_ecallOnlySimValid(1);
|
| 1035 |
|
| 1036 | error:
|
| 1037 | if(pStart) {
|
| 1038 | free(pStart);
|
| 1039 | }
|
| 1040 |
|
| 1041 | return;
|
| 1042 | }
|
| 1043 |
|
| 1044 | int ecall_send_getEcallOnly_cmd(void)
|
| 1045 | {
|
| 1046 | int ret = 0;
|
| 1047 |
|
| 1048 | char arr[64] = {0};
|
| 1049 |
|
| 1050 | memset(arr, 0x00, sizeof(arr));
|
| 1051 | snprintf(arr, sizeof(arr), "AT*ECALLONLY?\r");
|
| 1052 |
|
| 1053 | ret = ecallSendAtCmd(arr, 1);
|
| 1054 |
|
| 1055 | ECALL_Log("%s: ret = %d.", __FUNCTION__, ret);
|
| 1056 |
|
| 1057 | return ret;
|
| 1058 | }
|
| 1059 |
|
| 1060 | int ecall_send_getEcallOnlySim_cmd(void)
|
| 1061 | {
|
| 1062 | int ret = 0;
|
| 1063 |
|
| 1064 | char arr[64] = {0};
|
| 1065 |
|
| 1066 | memset(arr, 0x00, sizeof(arr));
|
| 1067 | snprintf(arr, sizeof(arr), "AT*ECALLONLYSIM?\r");
|
| 1068 |
|
| 1069 | ret = ecallSendAtCmd(arr, 1);
|
| 1070 |
|
| 1071 | ECALL_Log("%s: ret = %d.", __FUNCTION__, ret);
|
| 1072 |
|
| 1073 | return ret;
|
| 1074 | }
|
| 1075 |
|
| 1076 | void ecall_set_voice_data(unsigned int cmd_id, unsigned int res_id, unsigned int param)
|
| 1077 | {
|
| 1078 | char arr[64] = {0};
|
| 1079 |
|
| 1080 | memset(arr, 0x00, sizeof(arr));
|
| 1081 | snprintf(arr, sizeof(arr), "AT*ECALLVOICE=%d,%d,%d\r", cmd_id, res_id, param);
|
| 1082 | ecallSendAtCmd(arr, 1);
|
| 1083 |
|
| 1084 | ECALL_Log("%s: leave.", __FUNCTION__);
|
| 1085 |
|
| 1086 | return;
|
| 1087 | }
|
| 1088 |
|
| 1089 | void ecall_reset_msd_timestamp(void)
|
| 1090 | {
|
| 1091 | char arr[64] = {0};
|
| 1092 |
|
| 1093 | memset(arr, 0x00, sizeof(arr));
|
| 1094 | snprintf(arr, sizeof(arr), "AT*ECALLMSDCFG=5,1\r");
|
| 1095 | ecallSendAtCmd(arr, 1);
|
| 1096 |
|
| 1097 | ECALL_Log("%s: leave.", __FUNCTION__);
|
| 1098 |
|
| 1099 | return;
|
| 1100 | }
|
| 1101 |
|
| 1102 | int ecall_msd_saved(char *filePath, char *ecallMsd)
|
| 1103 | {
|
| 1104 | int ecallMsdFd = 0;
|
| 1105 | int ecallMsdLen = 0;
|
| 1106 | int ret = 0;
|
| 1107 |
|
| 1108 | if ((strlen(filePath) > 0) && (strlen(ecallMsd) > 0)) {
|
| 1109 | ecallMsdLen = strlen(ecallMsd);
|
| 1110 | ECALL_Log("%s: ecallMsd file path is %s and length is %d.\n", __FUNCTION__, filePath, ecallMsdLen);
|
| 1111 | } else {
|
| 1112 | ECALL_Log("%s: file path or ecallMsd is NULL.\n", __FUNCTION__);
|
| 1113 | return -1;
|
| 1114 | }
|
| 1115 |
|
| 1116 | ecallMsdFd = open (filePath, O_RDWR|O_CREAT|O_TRUNC, 0666);
|
| 1117 | if (ecallMsdFd < 0) {
|
| 1118 | ECALL_Log("%s: open file failed and ecallMsdFd=%d.\n", __FUNCTION__, ecallMsdFd);
|
| 1119 | return -1;
|
| 1120 | }
|
| 1121 |
|
| 1122 | ret = write(ecallMsdFd, ecallMsd, ecallMsdLen);
|
| 1123 | if (ret < 0) {
|
| 1124 | ECALL_Log("%s: write ecall msd failed.\n", __FUNCTION__);
|
| 1125 | goto error;
|
| 1126 | } else if (ret < ecallMsdLen) {
|
| 1127 | ECALL_Log("%s: wrote less the buffer size and ret=%d.\n", __FUNCTION__, ret);
|
| 1128 | goto error;
|
| 1129 | } else {
|
| 1130 | ECALL_Log("%s: write ecall msd success and ret=%d.\n", __FUNCTION__, ret);
|
| 1131 | }
|
| 1132 |
|
| 1133 | error:
|
| 1134 | if (ecallMsdFd) {
|
| 1135 | ret = close(ecallMsdFd);
|
| 1136 | if (ret < 0) {
|
| 1137 | ECALL_Log("%s: close ecall msd failed.\n", __FUNCTION__);
|
| 1138 | }
|
| 1139 | }
|
| 1140 | return ret;
|
| 1141 | }
|
| 1142 |
|
| 1143 | int ecall_save_alAck(char *aLAckStr)
|
| 1144 | {
|
| 1145 | int ecallAlAckFd = 0;
|
| 1146 | int ecallAlAckLen = 0;
|
| 1147 | int ret = 0;
|
| 1148 |
|
| 1149 | if (gEcallSaveAlAckCnt >= ECALL_SAVE_ALACK_COUNT_MAX) {
|
| 1150 | //remove save alack file
|
| 1151 | remove(ECALL_SAVE_ALACK_PATH);
|
| 1152 | gEcallSaveAlAckCnt = 0;
|
| 1153 | }
|
| 1154 |
|
| 1155 | if (strlen(aLAckStr) > 0) {
|
| 1156 | ecallAlAckLen = strlen(aLAckStr);
|
| 1157 | ECALL_Log("%s: ecallMsd file path is %s and length is %d.\n", __FUNCTION__, ECALL_SAVE_ALACK_PATH, ecallAlAckLen);
|
| 1158 | } else {
|
| 1159 | ECALL_Log("%s: file path or ecallMsd is NULL.\n", __FUNCTION__);
|
| 1160 | return -1;
|
| 1161 | }
|
| 1162 |
|
| 1163 | ecallAlAckFd = open (ECALL_SAVE_ALACK_PATH, O_RDWR|O_CREAT|O_APPEND, 0666);
|
| 1164 | if (ecallAlAckFd < 0) {
|
| 1165 | ECALL_Log("%s: open file failed and ecallMsdFd=%d.\n", __FUNCTION__, ecallAlAckFd);
|
| 1166 | return -1;
|
| 1167 | }
|
| 1168 |
|
| 1169 | ret = write(ecallAlAckFd, aLAckStr, ecallAlAckLen);
|
| 1170 | if (ret < 0) {
|
| 1171 | ECALL_Log("%s: write ecall msd failed.\n", __FUNCTION__);
|
| 1172 | goto error;
|
| 1173 | } else if (ret < ecallAlAckLen) {
|
| 1174 | ECALL_Log("%s: wrote less the buffer size and ret=%d.\n", __FUNCTION__, ret);
|
| 1175 | goto error;
|
| 1176 | } else {
|
| 1177 | ECALL_Log("%s: write ecall msd success and ret=%d.\n", __FUNCTION__, ret);
|
| 1178 | gEcallSaveAlAckCnt++;
|
| 1179 | }
|
| 1180 |
|
| 1181 | error:
|
| 1182 | if (ecallAlAckFd) {
|
| 1183 | ret = close(ecallAlAckFd);
|
| 1184 | if (ret < 0) {
|
| 1185 | ECALL_Log("%s: close ecall msd failed.\n", __FUNCTION__);
|
| 1186 | }
|
| 1187 | }
|
| 1188 | return ret;
|
| 1189 | }
|
| 1190 |
|
| 1191 | char * ecall_get_timestamp(void)
|
| 1192 | {
|
| 1193 | struct timeval log_time;
|
| 1194 | char *timestr = NULL;
|
| 1195 |
|
| 1196 | gettimeofday(&log_time, NULL);
|
| 1197 | timestr = ctime(&(log_time.tv_sec));
|
| 1198 | timestr[strlen(timestr) - 1] = '\0';
|
| 1199 |
|
| 1200 | return timestr;
|
| 1201 | }
|
| 1202 |
|
| 1203 | int ecall_ubus_sms_send(char* smsNum, char* txtData)
|
| 1204 | {
|
| 1205 | int ret = -1;
|
| 1206 | rilutilstrings param;
|
| 1207 | unsigned int id;
|
| 1208 |
|
| 1209 | id = ecall_get_ubus_ril_id();
|
| 1210 | if (id == 0) {
|
| 1211 | ECALL_Log("lookup ril object failed\n");
|
| 1212 | return -1;
|
| 1213 | }
|
| 1214 |
|
| 1215 | if (!txtData) return -2;
|
| 1216 |
|
| 1217 | param.num = 2;
|
| 1218 | char* strs[2] = {NULL, NULL};
|
| 1219 | //strs[0] = smsNum;
|
| 1220 | strs[1] = txtData;
|
| 1221 | param.str = strs;
|
| 1222 |
|
| 1223 | ecall_set_ecall_status(DAEMON_ECALL_SMS);
|
| 1224 |
|
| 1225 | ECALL_Log("ecall_ubus_sms_send: smsNum %s, txtData %s.\n", smsNum, txtData);
|
| 1226 | blob_buf_init(&ecall_sms_b, 0);
|
| 1227 | ret = rilutil_makeRequestBlob(&ecall_sms_b, RIL_REQUEST_SEND_SMS, ¶m, sizeof(rilutilstrings));
|
| 1228 |
|
| 1229 | ret = ubus_invoke(ecall_ctx, id, "ril_request", ecall_sms_b.head, ecall_rilrequest_cb, NULL, 0);
|
| 1230 | ECALL_Log("%s: ret=%d", __FUNCTION__, ret);
|
| 1231 |
|
| 1232 | return ret;
|
| 1233 | }
|
| 1234 |
|
| 1235 | int ecall_ubus_get_cmgr(int index)
|
| 1236 | {
|
| 1237 | int ret = -1;
|
| 1238 | int param = 0;
|
| 1239 | unsigned int id;
|
| 1240 |
|
| 1241 | id = ecall_get_ubus_ril_id();
|
| 1242 | if (id == 0) {
|
| 1243 | ECALL_Log("lookup ril object failed\n");
|
| 1244 | return -1;
|
| 1245 | }
|
| 1246 |
|
| 1247 | param = index;
|
| 1248 | ECALL_Log("ecall_ubus_get_cmgr: param %d.\n", param);
|
| 1249 |
|
| 1250 | blob_buf_init(&ecall_cmgr_b, 0);
|
| 1251 | ret = rilutil_makeRequestBlob(&ecall_cmgr_b, RIL_REQUEST_GET_CMGR, ¶m, sizeof(rilutilstrings));
|
| 1252 |
|
| 1253 | ret = ubus_invoke(ecall_ctx, id, "ril_request", ecall_cmgr_b.head, ecall_rilrequest_cb, NULL, 0);
|
| 1254 | ECALL_Log("%s: ret=%d", __FUNCTION__, ret);
|
| 1255 |
|
| 1256 | return ret;
|
| 1257 | }
|
| 1258 |
|
| 1259 | int ecall_sms_send_cfg_msd(void)
|
| 1260 | {
|
| 1261 | int ret = 0;
|
| 1262 | unsigned char *smsDataTmp = NULL;
|
| 1263 |
|
| 1264 | if (ecall_daemon_get_mode() != 1) {
|
| 1265 | ECALL_Log("%s: sms send failed, ecall mode=%d.", __FUNCTION__, ecall_daemon_get_mode());
|
| 1266 | return -3;
|
| 1267 | }
|
| 1268 |
|
| 1269 | //ecall_send_updateMsd_cmd();
|
| 1270 | smsDataTmp = ecall_sms_msdSMS(ecall_msd, gEcallMsdLen);
|
| 1271 | if (smsDataTmp == NULL)
|
| 1272 | {
|
| 1273 | ECALL_Log("%s: ecall_sms_msdSMS return smsData is NULL.", __FUNCTION__);
|
| 1274 | return -4;
|
| 1275 | }
|
| 1276 | /* use sms send msd */
|
| 1277 | if ((0 != strlen(smsMsdNumber)) && (0 != strlen(ecall_msd))) {
|
| 1278 | ret = ecall_ubus_sms_send(smsMsdNumber, (char *)smsDataTmp);
|
| 1279 | gEcallSmsMsdCnt++;
|
| 1280 | if (0 == ret) {
|
| 1281 | gSmsMsd = 1;
|
| 1282 | //ecallStartTimer(&ecall_sms_retransmit_timer, ECALL_SMS_SEND_MSD_TMR);
|
| 1283 | //ecall_enable_timer(ecall_sms_retransmit_timer, ECALL_SMS_SEND_MSD_TMR);
|
| 1284 | ECALL_Log("%s: sms send done.", __FUNCTION__);
|
| 1285 | } else {
|
| 1286 | ECALL_Log("%s: sms send fail.", __FUNCTION__);
|
| 1287 | ret = -1;
|
| 1288 | }
|
| 1289 | } else {
|
| 1290 | ECALL_Log("%s: no config sms number or msd is NULL.", __FUNCTION__);
|
| 1291 | ret = -2;
|
| 1292 | }
|
| 1293 |
|
| 1294 | if (smsDataTmp) {
|
| 1295 | free(smsDataTmp);
|
| 1296 | smsDataTmp = NULL;
|
| 1297 | }
|
| 1298 | return ret;
|
| 1299 | }
|
| 1300 |
|
| 1301 | int ecall_sms_send_saved_msd(void)
|
| 1302 | {
|
| 1303 | int ret = 0;
|
| 1304 | int smsMsdFd = -1;
|
| 1305 | int i = 0;
|
| 1306 | char smsMsdSavedPath[128] = {0};
|
| 1307 | char smsMsdSaved[300] = {0};
|
| 1308 | unsigned char *smsDataTmp = NULL;
|
| 1309 |
|
| 1310 | ECALL_Log("%s: sms send saved msd, ecall mode=%d, gEcallMsdSavedFlag=%d.", __FUNCTION__, gEcallMode, gEcallMsdSavedFlag);
|
| 1311 | if (ecall_daemon_get_mode() != 1) {
|
| 1312 | return -3;
|
| 1313 | }
|
| 1314 |
|
| 1315 | if (gEcallMsdSavedFlag > 0) {
|
| 1316 | for (i = 0; i < gEcallMsdSavedFlag; i++) {
|
| 1317 | sprintf(smsMsdSavedPath, "./tmp/ecall_msd_saved_%d", i);
|
| 1318 | ECALL_Log("%s: smsMsdSavedPath=%s.", __FUNCTION__, smsMsdSavedPath);
|
| 1319 | if (access(smsMsdSavedPath, F_OK) != 0)
|
| 1320 | {
|
| 1321 | ECALL_Log("%s: %s file isn't exist.", __FUNCTION__, smsMsdSavedPath);
|
| 1322 | continue;
|
| 1323 | }
|
| 1324 |
|
| 1325 | smsMsdFd = open(smsMsdSavedPath, O_RDONLY);
|
| 1326 | if (smsMsdFd < 0) {
|
| 1327 | ECALL_Log("%s: open sms msd saved file path failed.", __FUNCTION__);
|
| 1328 | ret = -1;
|
| 1329 | goto error;
|
| 1330 | } else {
|
| 1331 | memset(smsMsdSaved, 0x00, sizeof(smsMsdSaved));
|
| 1332 | ret = read(smsMsdFd, smsMsdSaved, sizeof(smsMsdSaved));
|
| 1333 | if (ret > 0) {
|
| 1334 | if (0 != strlen(smsMsdNumber)) {
|
| 1335 | smsDataTmp = ecall_sms_msdSMS(smsMsdSaved, strlen(smsMsdSaved));
|
| 1336 | if (smsDataTmp == NULL) {
|
| 1337 | ECALL_Log("%s: ecall_sms_msdSMS return smsData is NULL.", __FUNCTION__);
|
| 1338 | ret = -4;
|
| 1339 | goto error;
|
| 1340 | } else {
|
| 1341 | gSmsMsd = 1;
|
| 1342 | ecall_set_msdPath(smsMsdSavedPath);
|
| 1343 | ret = ecall_ubus_sms_send(smsMsdNumber, (char *)smsDataTmp);
|
| 1344 | //start msdSms retransmit timer
|
| 1345 | //ecallStopTimer(&ecall_saved_sms_retransmit_timer);
|
| 1346 | ecall_disable_timer(ecall_saved_sms_retransmit_timer);
|
| 1347 | //ecallStartTimer(&ecall_saved_sms_retransmit_timer, ECALL_SMS_SEND_MSD_TMR);
|
| 1348 | ecall_enable_timer(ecall_saved_sms_retransmit_timer, ECALL_SMS_SEND_MSD_TMR);
|
| 1349 | if (0 == ret) {
|
| 1350 | ECALL_Log("%s: sms send msd success and i=%d.", __FUNCTION__, i);
|
| 1351 | //remove(smsMsdSavedPath); //remove saved msd
|
| 1352 | ret = 0;
|
| 1353 | goto error;
|
| 1354 | } else {
|
| 1355 | ECALL_Log("%s: sms send msd failed and i=%d.", __FUNCTION__, i);
|
| 1356 | ret = -4;
|
| 1357 | goto error;
|
| 1358 | }
|
| 1359 | }
|
| 1360 | } else {
|
| 1361 | ECALL_Log("%s: sms number not config.", __FUNCTION__);
|
| 1362 | ret = -3;
|
| 1363 | goto error;
|
| 1364 | }
|
| 1365 | } else {
|
| 1366 | ECALL_Log("%s: read saved msd failed.", __FUNCTION__);
|
| 1367 | ret = -2;
|
| 1368 | goto error;
|
| 1369 | }
|
| 1370 | }
|
| 1371 | sleep(5); //sleep 1s after send sms
|
| 1372 | }
|
| 1373 | //gEcallMsdSavedFlag = 0;
|
| 1374 | }
|
| 1375 |
|
| 1376 | error:
|
| 1377 | if (smsDataTmp) {
|
| 1378 | free(smsDataTmp);
|
| 1379 | smsDataTmp = NULL;
|
| 1380 | }
|
| 1381 |
|
| 1382 | if (smsMsdFd > 0) {
|
| 1383 | close(smsMsdFd);
|
| 1384 | smsMsdFd = -1;
|
| 1385 | }
|
| 1386 |
|
| 1387 | return ret;
|
| 1388 | }
|
| 1389 |
|
| 1390 | int ecall_sms_send_smsFailed_msd(void)
|
| 1391 | {
|
| 1392 | int ret = 0;
|
| 1393 | int fd = 0;
|
| 1394 | char smsSendFailedMsd[300] = {0};
|
| 1395 |
|
| 1396 | if (ecall_daemon_get_mode() != 1) {
|
| 1397 | ECALL_Log("%s: sms send failed, ecall mode=%d.", __FUNCTION__, ecall_daemon_get_mode());
|
| 1398 | return -5;
|
| 1399 | }
|
| 1400 | /* use sms send msd */
|
| 1401 | if (0 != strlen(smsMsdNumber)) {
|
| 1402 | fd = open("/tmp/ecall_msd_sms_send_failed", O_RDONLY);
|
| 1403 | if (fd < 0) {
|
| 1404 | ECALL_Log("%s: open file failed.", __FUNCTION__);
|
| 1405 | return -1;
|
| 1406 | } else {
|
| 1407 | ret = read(fd, smsSendFailedMsd, sizeof(smsSendFailedMsd));
|
| 1408 | if (ret <= 0) {
|
| 1409 | ECALL_Log("%s: read file failed.", __FUNCTION__);
|
| 1410 | return -2;
|
| 1411 | } else {
|
| 1412 | ret = ecall_ubus_sms_send(smsMsdNumber, smsSendFailedMsd);
|
| 1413 | if (0 != ret) {
|
| 1414 | ECALL_Log("%s: sms send failed.", __FUNCTION__);
|
| 1415 | ret = -3;
|
| 1416 | } else {
|
| 1417 | close(fd);
|
| 1418 | fd = -1;
|
| 1419 | remove("/ecall_msd_sms_send_failed"); //remove msd of sms send failed
|
| 1420 | }
|
| 1421 | }
|
| 1422 | }
|
| 1423 | } else {
|
| 1424 | ECALL_Log("%s: sms number not config.", __FUNCTION__);
|
| 1425 | return -4;
|
| 1426 | }
|
| 1427 |
|
| 1428 | return ret;
|
| 1429 | }
|
| 1430 |
|
| 1431 | void ecall_get_network_status(void)
|
| 1432 | {
|
| 1433 | unsigned int id;
|
| 1434 |
|
| 1435 | id = ecall_get_ubus_ril_id();
|
| 1436 | if (id == 0) {
|
| 1437 | ECALL_Log("lookup ril object failed\n");
|
| 1438 | return;
|
| 1439 | }
|
| 1440 |
|
| 1441 | blob_buf_init(&ecall_sms_b, 0);
|
| 1442 | rilutil_makeRequestBlob(&ecall_sms_b, RIL_REQUEST_GET_NW_DOMAIN, NULL, 0);
|
| 1443 | ubus_invoke(ecall_ctx, id, "ril_request", ecall_sms_b.head, ecall_rilrequest_cb, 0, 0);
|
| 1444 |
|
| 1445 | ECALL_Log("%s: send ril request.", __FUNCTION__);
|
| 1446 | return;
|
| 1447 | }
|
| 1448 |
|
| 1449 | void ecall_timer_init(void)
|
| 1450 | {
|
| 1451 | if (ecall_get_ecalltimer_initialized() == 0)
|
| 1452 | {
|
| 1453 | ecall_start_timer(&ecall_psap_callback_timer, SIG_ECALL_PSAP_CALLBACK, ecall_psap_callback_cb);
|
| 1454 | ecall_start_timer(&ecall_dial_cleardown_timer, SIG_ECALL_PSAP_CLEARDOWN, ecall_dial_cleardown_cb);
|
| 1455 | ecall_start_timer(&ecall_dial_setup_timer, SIG_ECALL_DIAL_SETUP, ecall_setup_cb);
|
| 1456 | ecall_start_timer(&ecall_redial_timer, SIG_ECALL_REDIAL_SETUP, ecall_redial_setup_cb);
|
| 1457 | ecall_start_timer(&ecall_wait_hl_ack_timer, SIG_ECALL_WAIT_HL_ACK, ecall_retransmit_msd_cb);
|
| 1458 | ecall_start_timer(&ecall_sms_retransmit_timer, SIG_ECALL_SMS_RETRANSMIT, ecall_smsMsd_retransmit_cb);
|
| 1459 | ecall_start_timer(&ecall_saved_sms_retransmit_timer, SIG_ECALL_SAVED_SMS_RETRANSMIT, ecall_saved_smsMsd_retransmit_cb);
|
| 1460 | ecall_start_timer(&ecall_deregister_network_timer, SIG_ECALL_DEREG_NETWORK, ecall_deregister_network_cb);
|
| 1461 |
|
| 1462 | ecall_set_ecalltimer_initialized(1);
|
| 1463 | }
|
| 1464 | ECALL_Log("%s: leave", __FUNCTION__);
|
| 1465 |
|
| 1466 | return;
|
| 1467 | }
|
| 1468 |
|
| 1469 | int ecall_start_timer(TIMER_t *timerid, int signum, SIG_HANDLER timeout_handler)
|
| 1470 | {
|
| 1471 | struct sigevent sev;
|
| 1472 | struct sigaction sa;
|
| 1473 | int ret = 0;
|
| 1474 |
|
| 1475 | memset(&sev, 0x00, sizeof(struct sigevent));
|
| 1476 | memset(&sa, 0x00, sizeof(struct sigaction));
|
| 1477 |
|
| 1478 | sa.sa_flags = SA_SIGINFO;
|
| 1479 | sa.sa_sigaction = timeout_handler;
|
| 1480 | sigemptyset(&sa.sa_mask);
|
| 1481 |
|
| 1482 | if(sigaction(signum, &sa, NULL) == -1)
|
| 1483 | ECALL_Log("sigaction");
|
| 1484 |
|
| 1485 | sev.sigev_notify = SIGEV_SIGNAL;
|
| 1486 | sev.sigev_signo = signum;
|
| 1487 | sev.sigev_value.sival_ptr = timerid;
|
| 1488 | ret = timer_create(ECALL_CLCOK_ALARM, &sev, timerid);
|
| 1489 | ECALL_Log("ecall_start_timer return[%d], timerid[%x]", ret, *timerid);
|
| 1490 |
|
| 1491 | return ret;
|
| 1492 | }
|
| 1493 |
|
| 1494 | int ecall_enable_timer(TIMER_t timerid, long secs)
|
| 1495 | { |
| 1496 | struct itimerspec its;
|
| 1497 | int ret = 0;
|
| 1498 |
|
| 1499 | if (secs < 0)
|
| 1500 | return -1;
|
| 1501 |
|
| 1502 | //how long to run the first time
|
| 1503 | its.it_value.tv_sec = secs;
|
| 1504 | its.it_value.tv_nsec = 0;
|
| 1505 | //after first time, how long to run next time
|
| 1506 | its.it_interval.tv_sec = 0;
|
| 1507 | its.it_interval.tv_nsec = 0;
|
| 1508 | ret = timer_settime(timerid, 0, &its, NULL);
|
| 1509 | ECALL_Log("ecall_enable_timer return[%d], timerid[%x], secs[%ld]", ret, timerid, secs);
|
| 1510 |
|
| 1511 | return ret;
|
| 1512 | }
|
| 1513 |
|
| 1514 | int ecall_disable_timer(TIMER_t timerid)
|
| 1515 | { |
| 1516 | struct itimerspec its;
|
| 1517 |
|
| 1518 | its.it_value.tv_sec = 0;
|
| 1519 | its.it_value.tv_nsec = 0;
|
| 1520 | its.it_interval.tv_sec = 0;
|
| 1521 | its.it_interval.tv_nsec = 0;
|
| 1522 |
|
| 1523 | ECALL_Log("%s: timerid[%x]", __FUNCTION__, timerid);
|
| 1524 |
|
| 1525 | return timer_settime(timerid, 0, &its, NULL);
|
| 1526 | }
|
| 1527 |
|
| 1528 | int ecall_delete_timer(TIMER_t timerid)
|
| 1529 | { |
| 1530 | return timer_delete(timerid);
|
| 1531 | }
|
| 1532 |
|
| 1533 | #if 0
|
| 1534 | void ecallStartTimer(struct uloop_timeout *timeout, int timeVal)
|
| 1535 | {
|
| 1536 | //UNUSED(timeout);
|
| 1537 | ECALL_Log("%s: timeVal=%lu.", __FUNCTION__, timeVal);
|
| 1538 | if (timeVal > 0)
|
| 1539 | uloop_timeout_set(timeout, timeVal);
|
| 1540 | return;
|
| 1541 | }
|
| 1542 |
|
| 1543 | void ecallStopTimer(struct uloop_timeout *timeout)
|
| 1544 | {
|
| 1545 | //UNUSED(timeout);
|
| 1546 | if (timeout)
|
| 1547 | uloop_timeout_cancel(timeout);
|
| 1548 | return;
|
| 1549 | }
|
| 1550 | #endif
|
| 1551 | void ecall_sms_deReg(void)
|
| 1552 | {
|
| 1553 | char arr[64] = {0};
|
| 1554 |
|
| 1555 | sprintf(arr, "AT*ECALLREG=0\r");
|
| 1556 | ecallSendAtCmd(arr, 1);
|
| 1557 |
|
| 1558 | ECALL_Log("%s: leave.", __FUNCTION__);
|
| 1559 |
|
| 1560 | return;
|
| 1561 | }
|
| 1562 |
|
| 1563 | static void ecall_get_ecalldata_t6_timer(void)
|
| 1564 | {
|
| 1565 | char arr[64] = {0};
|
| 1566 |
|
| 1567 | sprintf(arr, "AT*ECALLDATA=5,2\r");
|
| 1568 | ecallSendAtCmd(arr, 1);
|
| 1569 |
|
| 1570 | ECALL_Log("%s: leave.", __FUNCTION__);
|
| 1571 |
|
| 1572 | return;
|
| 1573 | }
|
| 1574 |
|
| 1575 | static void ecall_get_ecalldata_t7_timer(void)
|
| 1576 | {
|
| 1577 | char arr[64] = {0};
|
| 1578 |
|
| 1579 | sprintf(arr, "AT*ECALLDATA=5,3\r");
|
| 1580 | ecallSendAtCmd(arr, 1);
|
| 1581 |
|
| 1582 | ECALL_Log("%s: leave.", __FUNCTION__);
|
| 1583 |
|
| 1584 | return;
|
| 1585 | }
|
| 1586 |
|
| 1587 | void ecall_start_manual_ecall(void)
|
| 1588 | {
|
| 1589 | char arr[64] = {0};
|
| 1590 |
|
| 1591 | memset(arr, 0, sizeof(arr));
|
| 1592 | sprintf(arr, "AT*ECALLMSDGEN\r");
|
| 1593 | ecallSendAtCmd(arr, 1);
|
| 1594 |
|
| 1595 | memset(arr, 0, sizeof(arr));
|
| 1596 | sprintf(arr, "AT+CECALL=2\r");
|
| 1597 | ecallSendAtCmd(arr, 1);
|
| 1598 |
|
| 1599 | memset(arr, 0, sizeof(arr));
|
| 1600 | sprintf(arr, "AT*ECALLPUSH\r");
|
| 1601 | ecallSendAtCmd(arr, 1);
|
| 1602 |
|
| 1603 | ECALL_Log("%s: leave.", __FUNCTION__);
|
| 1604 |
|
| 1605 | return;
|
| 1606 | }
|
| 1607 |
|
| 1608 | void ecall_start_auto_ecall(void)
|
| 1609 | {
|
| 1610 | char arr[64] = {0};
|
| 1611 |
|
| 1612 | memset(arr, 0, sizeof(arr));
|
| 1613 | sprintf(arr, "AT*ECALLMSDGEN\r");
|
| 1614 | ecallSendAtCmd(arr, 1);
|
| 1615 |
|
| 1616 | memset(arr, 0, sizeof(arr));
|
| 1617 | sprintf(arr, "AT+CECALL=3\r");
|
| 1618 | ecallSendAtCmd(arr, 1);
|
| 1619 |
|
| 1620 | memset(arr, 0, sizeof(arr));
|
| 1621 | sprintf(arr, "AT*ECALLPUSH\r");
|
| 1622 | ecallSendAtCmd(arr, 1);
|
| 1623 |
|
| 1624 | ECALL_Log("%s: leave.", __FUNCTION__);
|
| 1625 |
|
| 1626 | return;
|
| 1627 | }
|
| 1628 |
|
| 1629 | int handle_ecallNetwork(void *data)
|
| 1630 | {
|
| 1631 | int err = 0;
|
| 1632 | rilutilstrings *resp = NULL;
|
| 1633 |
|
| 1634 | if (data) {
|
| 1635 | resp = (rilutilstrings *)data;
|
| 1636 |
|
| 1637 | if ((resp->num != 2) || (0 == memcmp(resp->str[0], "No Service", strlen("No Service")))) {
|
| 1638 | ECALL_Log("handle_ecallNetwork recv no service.\n");
|
| 1639 | return -1;
|
| 1640 | }
|
| 1641 |
|
| 1642 | ECALL_Log("handle_ecallNetwork data->num=%d.\n", resp->num);
|
| 1643 | ECALL_Log("handle_ecallNetwork: resp->str[0]=%s.\n", resp->str[0]);
|
| 1644 | //ECALL_Log("handle_ecallNetwork: resp->str[1]=%s.\n", resp->str[1]);
|
| 1645 |
|
| 1646 | if (0 == memcmp(resp->str[1], "CS_ONLY", strlen("CS_ONLY"))) {
|
| 1647 | err = 1;
|
| 1648 | } else if (0 == memcmp(resp->str[1], "PS_ONLY", strlen("PS_ONLY"))) {
|
| 1649 | err = 2;
|
| 1650 | } else if (0 == memcmp(resp->str[1], "CS_PS", strlen("CS_PS"))) {
|
| 1651 | err = 3;
|
| 1652 | } else if (0 == memcmp(resp->str[1], "CAMPED", strlen("CAMPED"))) {
|
| 1653 | err = 4;
|
| 1654 | //if (ecall_daemon_get_mode() == 0)
|
| 1655 | // err = 4;
|
| 1656 | //else if (ecall_daemon_get_mode() == 1)
|
| 1657 | // err = -2;
|
| 1658 | //else
|
| 1659 | // err = -3;
|
| 1660 | } else if (0 == memcmp(resp->str[1], "ECALLONLY", strlen("ECALLONLY"))) {
|
| 1661 | err = 5;
|
| 1662 | } else {
|
| 1663 | err = 0;
|
| 1664 | }
|
| 1665 | } else {
|
| 1666 | ECALL_Log("handle_ecallNetwork data is NULL.\n");
|
| 1667 | return -1;
|
| 1668 | }
|
| 1669 |
|
| 1670 | return err;
|
| 1671 | }
|
| 1672 |
|
| 1673 | int ecall_daemon_set_ecallSmsNum(char *ecallSmsNum)
|
| 1674 | {
|
| 1675 | if ((ecallSmsNum != NULL) && (strlen(ecallSmsNum) > 0))
|
| 1676 | {
|
| 1677 | memset(smsMsdNumber, '\0', sizeof(smsMsdNumber));
|
| 1678 | memcpy(smsMsdNumber, ecallSmsNum, strlen(ecallSmsNum));
|
| 1679 |
|
| 1680 | ECALL_Log("%s: strlen(ecallSmsNum)=%d, ecallSmsNum=%s", __FUNCTION__, strlen(ecallSmsNum), ecallSmsNum);
|
| 1681 |
|
| 1682 | return 0;
|
| 1683 | }
|
| 1684 | else
|
| 1685 | {
|
| 1686 | ECALL_Log("%s: recv ecall msd is invalid", __FUNCTION__);
|
| 1687 |
|
| 1688 | return -1;
|
| 1689 | }
|
| 1690 | }
|
| 1691 |
|
| 1692 | char * ecall_daemon_get_ecallSmsNum(void)
|
| 1693 | {
|
| 1694 | if (strlen(smsMsdNumber) > 0)
|
| 1695 | {
|
| 1696 | return smsMsdNumber;
|
| 1697 | }
|
| 1698 | else
|
| 1699 | {
|
| 1700 | return NULL;
|
| 1701 | }
|
| 1702 | }
|
| 1703 |
|
| 1704 | int ecall_daemon_set_ecallMsd(char *ecallMsd)
|
| 1705 | {
|
| 1706 | if ((ecallMsd != NULL) && (strlen(ecallMsd) > 0))
|
| 1707 | {
|
| 1708 | gEcallMsdLen = strlen(ecallMsd);
|
| 1709 | memset(ecall_msd, '\0', sizeof(ecall_msd));
|
| 1710 | memcpy(ecall_msd, ecallMsd, gEcallMsdLen);
|
| 1711 |
|
| 1712 | ECALL_Log("%s: gEcallMsdLen=%d, ecall_msd=%s", __FUNCTION__, gEcallMsdLen, ecall_msd);
|
| 1713 |
|
| 1714 | if (1 == ecall_daemon_get_mode())
|
| 1715 | {
|
| 1716 | ecall_save_curMsd();
|
| 1717 | }
|
| 1718 |
|
| 1719 | return 0;
|
| 1720 | }
|
| 1721 | else
|
| 1722 | {
|
| 1723 | ECALL_Log("%s: recv ecall msd is invalid", __FUNCTION__);
|
| 1724 |
|
| 1725 | return -1;
|
| 1726 | }
|
| 1727 | }
|
| 1728 |
|
| 1729 | char * ecall_daemon_get_ecallMsd(void)
|
| 1730 | {
|
| 1731 | if (strlen(ecall_msd) > 0)
|
| 1732 | {
|
| 1733 | return ecall_msd;
|
| 1734 | }
|
| 1735 | else
|
| 1736 | {
|
| 1737 | return NULL;
|
| 1738 | }
|
| 1739 | }
|
| 1740 |
|
| 1741 | int ecall_daemon_send_ceer_cmd(void)
|
| 1742 | {
|
| 1743 | int ret = 0;
|
| 1744 |
|
| 1745 | char arr[64] = {0};
|
| 1746 |
|
| 1747 | memset(arr, 0x00, sizeof(arr));
|
| 1748 | snprintf(arr, sizeof(arr), "AT+CEER\r");
|
| 1749 |
|
| 1750 | ret = ecallSendAtCmd(arr, 1);
|
| 1751 |
|
| 1752 | ECALL_Log("%s: ret = %d.", __FUNCTION__, ret);
|
| 1753 |
|
| 1754 | return ret;
|
| 1755 |
|
| 1756 | }
|
| 1757 |
|
| 1758 | void ecall_handle_ceer_response(const char *s)
|
| 1759 | {
|
| 1760 | int err, ceerVal = 0;
|
| 1761 | char *line = ecallStrdup((char *)s);
|
| 1762 | char *ceerStr = NULL;
|
| 1763 | char *pStart = NULL;
|
| 1764 | char data[3] = {0};
|
| 1765 |
|
| 1766 | ECALL_Log("%s: %s", __FUNCTION__, s);
|
| 1767 | pStart = line;
|
| 1768 | err = at_tok_start(&line);
|
| 1769 | if(err < 0) {
|
| 1770 | goto error;
|
| 1771 | }
|
| 1772 |
|
| 1773 | err = at_tok_nextstr(&line, &ceerStr);
|
| 1774 | if(err < 0) {
|
| 1775 | goto error;
|
| 1776 | }
|
| 1777 | ECALL_Log("%s: %s", __FUNCTION__, ceerStr);
|
| 1778 |
|
| 1779 | data[0] = ceerStr[0];
|
| 1780 | if (data[0] >= '0' && data[0] <= '9')
|
| 1781 | ceerVal = data[0] - '0';
|
| 1782 |
|
| 1783 | data[1] = ceerStr[1];
|
| 1784 | if (data[1] >= '0' && data[1] <= '9')
|
| 1785 | ceerVal = ceerVal * 10 + (data[1] - '0');
|
| 1786 |
|
| 1787 | data[2] = ceerStr[2];
|
| 1788 | if (data[2] >= '0' && data[2] <= '9')
|
| 1789 | ceerVal = ceerVal * 10 + (data[2] - '0');
|
| 1790 |
|
| 1791 | ECALL_Log("%s: ceerVal=%d", __FUNCTION__, ceerVal);
|
| 1792 | ecalL_daemon_set_ceerVal(ceerVal);
|
| 1793 |
|
| 1794 | error:
|
| 1795 | if(pStart) {
|
| 1796 | free(pStart);
|
| 1797 | }
|
| 1798 |
|
| 1799 | return;
|
| 1800 | }
|
| 1801 |
|
| 1802 | int ecall_send_updateMsd_cmd(void)
|
| 1803 | {
|
| 1804 | int ret = 0;
|
| 1805 |
|
| 1806 | char arr[64] = {0};
|
| 1807 |
|
| 1808 | memset(arr, 0x00, sizeof(arr));
|
| 1809 | snprintf(arr, sizeof(arr), "AT*ECALLMSDGEN\r");
|
| 1810 |
|
| 1811 | ret = ecallSendAtCmd(arr, 1);
|
| 1812 |
|
| 1813 | ECALL_Log("%s: ret = %d.", __FUNCTION__, ret);
|
| 1814 |
|
| 1815 | return ret;
|
| 1816 |
|
| 1817 | }
|
| 1818 |
|
| 1819 | void ecall_handle_msdGen_response(const char *s)
|
| 1820 | {
|
| 1821 | int err;
|
| 1822 | char *line = ecallStrdup((char *)s);
|
| 1823 | char *msd = NULL;
|
| 1824 | char *pStart = NULL;
|
| 1825 |
|
| 1826 | ECALL_Log("%s: %s", __FUNCTION__,s);
|
| 1827 | pStart = line;
|
| 1828 | err = at_tok_start(&line);
|
| 1829 | if(err < 0) {
|
| 1830 | goto error;
|
| 1831 | }
|
| 1832 |
|
| 1833 | err = at_tok_nextstr(&line, &msd);
|
| 1834 | if(err < 0) {
|
| 1835 | goto error;
|
| 1836 | }
|
| 1837 |
|
| 1838 | if (msd != NULL)
|
| 1839 | {
|
| 1840 | ecall_daemon_set_ecallMsd(msd);
|
| 1841 | }
|
| 1842 | else
|
| 1843 | {
|
| 1844 | goto error;
|
| 1845 | }
|
| 1846 |
|
| 1847 | ecall_daemon_str2hex(gEcallMsdLen, ecall_msd, ecall_msd_hex, sizeof(ecall_msd_hex)); // update to gMSDStr_HEX
|
| 1848 |
|
| 1849 | //gEcallMsdHexLen = gEcallMsdLen/2;
|
| 1850 | //ecall_msd_saved("/tmp/ecall_msd_sms_send_failed", ecall_msd);
|
| 1851 | ECALL_Log("%s rcv: ecall msd %s, ecall msd length %d.", __FUNCTION__, ecall_msd, gEcallMsdLen);
|
| 1852 |
|
| 1853 | error:
|
| 1854 | if(pStart) {
|
| 1855 | free(pStart);
|
| 1856 | }
|
| 1857 |
|
| 1858 | return;
|
| 1859 | }
|
| 1860 |
|
| 1861 | void ecall_daemon_get_ecallParams(char *respBuff, int buffLen)
|
| 1862 | {
|
| 1863 | int len = 0;
|
| 1864 |
|
| 1865 | if (ecall_daemon_get_mode() == 1)
|
| 1866 | {
|
| 1867 | len += snprintf(respBuff + len, buffLen - len, "ERA mode, callback timer: %ds, ", ECALL_PSAP_CALLBACK_TMR_ERA);
|
| 1868 | len += snprintf(respBuff + len, buffLen - len, "dial setup timer: %ds, ", ECALL_DIAL_SETUP_TMR_ERA);
|
| 1869 | len += snprintf(respBuff + len, buffLen - len, "NAD deregister timer: %ds, ", ECALL_NAD_DEREGISTRATION_TMR_ERA);
|
| 1870 | len += snprintf(respBuff + len, buffLen - len, "cleardown timer: %ds, ", ECALL_DIAL_CLEARDOWN_TMR);
|
| 1871 | len += snprintf(respBuff + len, buffLen - len, "redial attempts count: %d, ", ECALL_AUTO_DIAL_ATTEMPTS);
|
| 1872 | len += snprintf(respBuff + len, buffLen - len, "redial wait timer: %ds, ", ECALL_REDIAL_TMR_ERA);
|
| 1873 | len += snprintf(respBuff + len, buffLen - len, "smsprocess: %d, ", ecall_daemon_get_smsProcess());
|
| 1874 | len += snprintf(respBuff + len, buffLen - len, "SMS resend timer: %ds, ", ECALL_SMS_SEND_MSD_TMR);
|
| 1875 | len += snprintf(respBuff + len, buffLen - len, "sms msd send count: %d.", ecall_get_smsMsd_send_count());
|
| 1876 | }
|
| 1877 | else
|
| 1878 | {
|
| 1879 | len += snprintf(respBuff + len, buffLen - len, "EU mode, callback timer: %ds, ", ECALL_PSAP_CALLBACK_TMR_EU);
|
| 1880 | len += snprintf(respBuff + len, buffLen - len, "dial setup timer: %ds, ", ECALL_DIAL_SETUP_TMR_EU);
|
| 1881 | len += snprintf(respBuff + len, buffLen - len, "NAD deregister timer: %ds, ", ECALL_NAD_DEREGISTRATION_TMR_EU);
|
| 1882 | len += snprintf(respBuff + len, buffLen - len, "cleardown timer: %ds.", ECALL_DIAL_CLEARDOWN_TMR);
|
| 1883 | }
|
| 1884 |
|
| 1885 | return;
|
| 1886 | }
|
| 1887 |
|
| 1888 | void ecallClearTimer(void)
|
| 1889 | {
|
| 1890 | //stop ecall dial setup timer
|
| 1891 | //ecallStopTimer(&ecall_dial_setup_timer);
|
| 1892 | ecall_disable_timer(ecall_dial_setup_timer);
|
| 1893 | //stop ecall clear down timer
|
| 1894 | //ecallStopTimer(&ecall_dial_cleardown_timer);
|
| 1895 | ecall_disable_timer(ecall_dial_cleardown_timer);
|
| 1896 | //ecallStopTimer(&ecall_wait_hl_ack_timer);
|
| 1897 | ecall_disable_timer(ecall_wait_hl_ack_timer);
|
| 1898 | //ecallStopTimer(&ecall_psap_callback_timer);
|
| 1899 | ecall_disable_timer(ecall_psap_callback_timer);
|
| 1900 | //ecallStopTimer(&ecall_deregister_network_timer);
|
| 1901 | ecall_disable_timer(ecall_deregister_network_timer);
|
| 1902 | return;
|
| 1903 | }
|
| 1904 |
|
| 1905 | void ecall_clear_status(void)
|
| 1906 | {
|
| 1907 | ecallClearTimer();
|
| 1908 | ecall_clear_allSavedMsd();
|
| 1909 | ecall_set_ecall_status(DAEMON_ECALL_IDLE);
|
| 1910 | gEcallMsdSavedFlag = 0;
|
| 1911 | gEcallCallID = 0;
|
| 1912 | gPushVal = 0;
|
| 1913 | gSmsMsd = 0;
|
| 1914 | gEcallNW = 0;
|
| 1915 | gEcallType = 0;
|
| 1916 | gEcallCeer = 16;
|
| 1917 | gEcallRedial = 0;
|
| 1918 | gSimEcallOnly = 0;
|
| 1919 | gSimEcallActive = 0;
|
| 1920 | gEcallDialCnt = 0;
|
| 1921 | gEcallSmsMsdCnt = 0;
|
| 1922 | gCurrentHasCallSet = 0;
|
| 1923 | gEacllUserUpdatedMsd = 0;
|
| 1924 | }
|
| 1925 |
|
| 1926 | int ecall_check_msd_hasMore(void)
|
| 1927 | {
|
| 1928 | int i = 0, count = 0;
|
| 1929 | char savedMsdPath[64] = {0};
|
| 1930 |
|
| 1931 | for (i = 0; i < gEcallMsdSavedFlag; i++)
|
| 1932 | {
|
| 1933 | memset(savedMsdPath, 0x00, sizeof(savedMsdPath));
|
| 1934 | sprintf(savedMsdPath, "./tmp/ecall_msd_saved_%d", i);
|
| 1935 | if (access(savedMsdPath, F_OK) != 0)
|
| 1936 | {
|
| 1937 | ECALL_Log("%s: savedMsdPath=%s file isn't exist.", __FUNCTION__, savedMsdPath);
|
| 1938 | continue;
|
| 1939 | }
|
| 1940 | count++;
|
| 1941 | ECALL_Log("%s: savedMsdPath=%s file is exist, count=%d.", __FUNCTION__, savedMsdPath, count);
|
| 1942 | }
|
| 1943 |
|
| 1944 | return count;
|
| 1945 | }
|
| 1946 |
|
| 1947 | int ecall_set_msdPath(char *msdPath)
|
| 1948 | {
|
| 1949 | if ((msdPath != NULL) && (strlen(msdPath) > 0))
|
| 1950 | {
|
| 1951 | memset(gEcallMsdPath, 0x0, sizeof(gEcallMsdPath));
|
| 1952 | memcpy(gEcallMsdPath, msdPath, strlen(msdPath));
|
| 1953 | ECALL_Log("%s: gEcallMsdPath=%s", __FUNCTION__, gEcallMsdPath);
|
| 1954 | }
|
| 1955 | else
|
| 1956 | {
|
| 1957 | ECALL_Log("%s: msdPath=%s file is nivalid.", __FUNCTION__, msdPath);
|
| 1958 | return -1;
|
| 1959 | }
|
| 1960 |
|
| 1961 | return 0;
|
| 1962 | }
|
| 1963 |
|
| 1964 | char * ecall_get_msdPath(void)
|
| 1965 | {
|
| 1966 | if (strlen(gEcallMsdPath) > 0)
|
| 1967 | {
|
| 1968 | return gEcallMsdPath;
|
| 1969 | }
|
| 1970 | else
|
| 1971 | {
|
| 1972 | return NULL;
|
| 1973 | }
|
| 1974 | }
|
| 1975 |
|
| 1976 | int ecall_clear_allSavedMsd(void)
|
| 1977 | {
|
| 1978 | int i = 0;
|
| 1979 | char savedMsdPath[64] = {0};
|
| 1980 |
|
| 1981 | for (i = 0; i < 100; i++)
|
| 1982 | {
|
| 1983 | memset(savedMsdPath, 0x00, sizeof(savedMsdPath));
|
| 1984 | sprintf(savedMsdPath, "./tmp/ecall_msd_saved_%d", i);
|
| 1985 | if (access(savedMsdPath, F_OK) != 0)
|
| 1986 | {
|
| 1987 | //ECALL_Log("%s: savedMsdPath=%s file isn't exist.", __FUNCTION__, savedMsdPath);
|
| 1988 | continue;
|
| 1989 | }
|
| 1990 | else
|
| 1991 | {
|
| 1992 | ECALL_Log("%s: removed savedMsdPath=%s file.", __FUNCTION__, savedMsdPath);
|
| 1993 | remove(savedMsdPath);
|
| 1994 | }
|
| 1995 | }
|
| 1996 |
|
| 1997 | gEcallMsdSavedFlag = 0;
|
| 1998 |
|
| 1999 | return 0;
|
| 2000 | }
|
| 2001 |
|
| 2002 | int ecall_clear_curMsd(void)
|
| 2003 | {
|
| 2004 | int ret = 0;
|
| 2005 | int i = 0, savedMsdFd = -1;
|
| 2006 | char savedMsd[300] = {0};
|
| 2007 | char savedMsdPath[64] = {0};
|
| 2008 |
|
| 2009 | ECALL_Log("%s: gEcallMsdSavedFlag=%d, strlen(ecall_msd)=%d.", __FUNCTION__, gEcallMsdSavedFlag, strlen(ecall_msd));
|
| 2010 |
|
| 2011 | if (strlen(ecall_msd) > 0)
|
| 2012 | {
|
| 2013 | if (gEcallMsdSavedFlag > 0)
|
| 2014 | {
|
| 2015 | for (i = 0; i < gEcallMsdSavedFlag; i++)
|
| 2016 | {
|
| 2017 | memset(savedMsdPath, 0x00, sizeof(savedMsdPath));
|
| 2018 | sprintf(savedMsdPath, "./tmp/ecall_msd_saved_%d", i);
|
| 2019 | if (access(savedMsdPath, F_OK) != 0)
|
| 2020 | {
|
| 2021 | ECALL_Log("%s: savedMsdPath=%s file isn't exist.", __FUNCTION__, savedMsdPath);
|
| 2022 | continue;
|
| 2023 | }
|
| 2024 |
|
| 2025 | savedMsdFd = open(savedMsdPath, O_RDONLY);
|
| 2026 | if (savedMsdFd < 0)
|
| 2027 | {
|
| 2028 | ECALL_Log("%s: open sms msd saved file path failed.", __FUNCTION__);
|
| 2029 | continue;
|
| 2030 | }
|
| 2031 | else
|
| 2032 | {
|
| 2033 | memset(savedMsd, 0x00, sizeof(savedMsd));
|
| 2034 | ret = read(savedMsdFd, savedMsd, sizeof(savedMsd));
|
| 2035 | ECALL_Log("%s: read saved msd ret=%d, path=%s, msd=%s.", __FUNCTION__, ret, savedMsdPath, savedMsd);
|
| 2036 | if (ret > 0) {
|
| 2037 | if (0 == strncmp(savedMsd, ecall_msd, strlen(ecall_msd)))
|
| 2038 | {
|
| 2039 | remove(savedMsdPath);
|
| 2040 | ECALL_Log("%s: find current sent msd and remove him in file system.", __FUNCTION__);
|
| 2041 |
|
| 2042 | ret = ecall_check_msd_hasMore();
|
| 2043 | if (ret == 0)
|
| 2044 | {
|
| 2045 | ECALL_Log("%s: file system not exist msd.", __FUNCTION__);
|
| 2046 | gEcallMsdSavedFlag = 0;
|
| 2047 | }
|
| 2048 |
|
| 2049 | break;
|
| 2050 | }
|
| 2051 | }
|
| 2052 | else
|
| 2053 | {
|
| 2054 | ECALL_Log("%s: read saved msd failed.", __FUNCTION__);
|
| 2055 | if (savedMsdFd > 0)
|
| 2056 | {
|
| 2057 | close(savedMsdFd);
|
| 2058 | savedMsdFd = -1;
|
| 2059 | }
|
| 2060 | continue;
|
| 2061 | }
|
| 2062 | }
|
| 2063 | }
|
| 2064 | }
|
| 2065 | else
|
| 2066 | {
|
| 2067 | ECALL_Log("%s: gEcallMsdSavedFlag is invalid.", __FUNCTION__);
|
| 2068 | return -1;
|
| 2069 | }
|
| 2070 | }
|
| 2071 | else
|
| 2072 | {
|
| 2073 | ECALL_Log("%s: current msd is invalid.", __FUNCTION__);
|
| 2074 | return -2;
|
| 2075 | }
|
| 2076 |
|
| 2077 | if (savedMsdFd > 0)
|
| 2078 | {
|
| 2079 | close(savedMsdFd);
|
| 2080 | savedMsdFd = -1;
|
| 2081 | }
|
| 2082 |
|
| 2083 | return 0;
|
| 2084 | }
|
| 2085 |
|
| 2086 | int ecall_save_curMsd(void)
|
| 2087 | {
|
| 2088 | int ret = 0;
|
| 2089 | int i = 0, savedMsdFd = -1;
|
| 2090 | char savedMsd[300] = {0};
|
| 2091 | char savedMsdPath[64] = {0};
|
| 2092 |
|
| 2093 | ECALL_Log("%s: gEcallMsdSavedFlag=%d, strlen(ecall_msd)=%d.", __FUNCTION__, gEcallMsdSavedFlag, strlen(ecall_msd));
|
| 2094 |
|
| 2095 | if (strlen(ecall_msd) != 0)
|
| 2096 | {
|
| 2097 | if (gEcallMsdSavedFlag > 100)
|
| 2098 | {
|
| 2099 | ECALL_Log("%s: msd saved failed and gEcallMsdSavedFlag=%d.", __FUNCTION__, gEcallMsdSavedFlag);
|
| 2100 | return -2;
|
| 2101 | }
|
| 2102 | else if (gEcallMsdSavedFlag >= 0 && gEcallMsdSavedFlag <= 100)
|
| 2103 | {
|
| 2104 | for(i = 0; i < gEcallMsdSavedFlag; i++)
|
| 2105 | {
|
| 2106 | memset(savedMsdPath, 0x00, sizeof(savedMsdPath));
|
| 2107 | sprintf(savedMsdPath, "./tmp/ecall_msd_saved_%d", i);
|
| 2108 | if (access(savedMsdPath, F_OK) != 0)
|
| 2109 | {
|
| 2110 | ECALL_Log("%s: savedMsdPath=%s file isn't exist.", __FUNCTION__, savedMsdPath);
|
| 2111 | continue;
|
| 2112 | }
|
| 2113 |
|
| 2114 | savedMsdFd = open(savedMsdPath, O_RDONLY);
|
| 2115 | if (savedMsdFd < 0)
|
| 2116 | {
|
| 2117 | ECALL_Log("%s: open sms msd saved file path failed.", __FUNCTION__);
|
| 2118 | continue;
|
| 2119 | }
|
| 2120 | else
|
| 2121 | {
|
| 2122 | memset(savedMsd, 0x00, sizeof(savedMsd));
|
| 2123 | ret = read(savedMsdFd, savedMsd, sizeof(savedMsd));
|
| 2124 | ECALL_Log("%s: read saved msd ret=%d, path=%s, msd=%s.", __FUNCTION__, ret, savedMsdPath, savedMsd);
|
| 2125 | if (ret > 0)
|
| 2126 | {
|
| 2127 | if (0 == strncmp(savedMsd, ecall_msd, strlen(ecall_msd)))
|
| 2128 | {
|
| 2129 | ECALL_Log("%s: find current sent msd has saved in file system.", __FUNCTION__);
|
| 2130 | goto exit;
|
| 2131 | }
|
| 2132 | else
|
| 2133 | {
|
| 2134 | ECALL_Log("%s: current sent msd isn't equal %s.", __FUNCTION__, savedMsdPath);
|
| 2135 | if (savedMsdFd > 0)
|
| 2136 | {
|
| 2137 | close(savedMsdFd);
|
| 2138 | savedMsdFd = -1;
|
| 2139 | }
|
| 2140 | continue;
|
| 2141 | }
|
| 2142 | }
|
| 2143 | else
|
| 2144 | {
|
| 2145 | ECALL_Log("%s: read saved msd failed.", __FUNCTION__);
|
| 2146 | if (savedMsdFd > 0)
|
| 2147 | {
|
| 2148 | close(savedMsdFd);
|
| 2149 | savedMsdFd = -1;
|
| 2150 | }
|
| 2151 | continue;
|
| 2152 | }
|
| 2153 | }
|
| 2154 | }
|
| 2155 |
|
| 2156 | memset(savedMsdPath, 0x00, sizeof(savedMsdPath));
|
| 2157 | sprintf(savedMsdPath, "/tmp/ecall_msd_saved_%d", gEcallMsdSavedFlag);
|
| 2158 | ret = ecall_msd_saved(savedMsdPath, ecall_msd);
|
| 2159 | if (ret >= 0)
|
| 2160 | {
|
| 2161 | gEcallMsdSavedFlag++;
|
| 2162 | ECALL_Log("%s: ecall msd has saved and gEcallMsdSavedFlag=%d.", __FUNCTION__, gEcallMsdSavedFlag);
|
| 2163 | }
|
| 2164 | else
|
| 2165 | {
|
| 2166 | ECALL_Log("%s: ecall msd saved failed and gEcallMsdSavedFlag=%d.", __FUNCTION__, gEcallMsdSavedFlag);
|
| 2167 | return -1;
|
| 2168 | }
|
| 2169 | }
|
| 2170 | else
|
| 2171 | {
|
| 2172 | ECALL_Log("%s: %d is invalid.", __FUNCTION__, gEcallMsdSavedFlag);
|
| 2173 | return -3;
|
| 2174 | }
|
| 2175 | }
|
| 2176 |
|
| 2177 | exit:
|
| 2178 | //ecall_reset_msd_timestamp();
|
| 2179 | if (savedMsdFd > 0)
|
| 2180 | {
|
| 2181 | close(savedMsdFd);
|
| 2182 | savedMsdFd = -1;
|
| 2183 | }
|
| 2184 |
|
| 2185 | return 0;
|
| 2186 | }
|
| 2187 |
|
| 2188 | void ecallHandleEcallType(const char *s)
|
| 2189 | {
|
| 2190 | int err;
|
| 2191 | char arr[64] = {0};
|
| 2192 | char *line = ecallStrdup((char *)s);
|
| 2193 | int ecallType = 0;
|
| 2194 | char *pStart = NULL;
|
| 2195 |
|
| 2196 | ecall_get_network_status();
|
| 2197 |
|
| 2198 | ecall_set_voice_data(4, 0, 1);
|
| 2199 |
|
| 2200 | pStart = line;
|
| 2201 | ECALL_Log("%s: %s", __FUNCTION__,s);
|
| 2202 | err = at_tok_start(&line);
|
| 2203 | if(err < 0)
|
| 2204 | goto error;
|
| 2205 |
|
| 2206 | err = at_tok_nextint(&line, &ecallType);
|
| 2207 | if(err < 0) {
|
| 2208 | goto error;
|
| 2209 | }
|
| 2210 |
|
| 2211 | gEcallType = ecallType;
|
| 2212 | ECALL_Log("%s rcv: ecallType %d, ecall nw %d", __FUNCTION__, gEcallType, ecall_get_ecallNetwork());
|
| 2213 |
|
| 2214 | ECALL_Log("%s: gCurrentHasCallSet %d, gEcallCallID %d.", __FUNCTION__, gCurrentHasCallSet, gEcallCallID);
|
| 2215 | if (gCurrentHasCallSet == 1) //has a call is setup,need to hangup when a new call want to setup
|
| 2216 | {
|
| 2217 | if (0 == gEcallCallID) //it is current has a normal call is processing, need hangup it.
|
| 2218 | {
|
| 2219 | ecall_dial_cleardown_nomal(); //hangup call
|
| 2220 | }
|
| 2221 | else //it is current has a ecall is processing, don't setup ecall again.
|
| 2222 | {
|
| 2223 | if (5 != ecallType)
|
| 2224 | {
|
| 2225 | if(pStart)
|
| 2226 | free(pStart);
|
| 2227 | return;
|
| 2228 | }
|
| 2229 | }
|
| 2230 | }
|
| 2231 |
|
| 2232 | ecallClearTimer(); //clear ecall timer
|
| 2233 | if (gEcallType == 5) //for user hang up ecall
|
| 2234 | goto hang_up_ecall;
|
| 2235 |
|
| 2236 | if (ecall_daemon_get_mode() == 1)
|
| 2237 | {
|
| 2238 | if (ecall_get_ecallNetwork() <= 0) //network not ready, msd need saved
|
| 2239 | {
|
| 2240 | #if 0
|
| 2241 | if (strlen(ecall_msd) != 0) {
|
| 2242 | if (gEcallMsdSavedFlag > 100) {
|
| 2243 | ECALL_Log("%s: msd saved failed and gEcallMsdSavedFlag=%d.", __FUNCTION__, gEcallMsdSavedFlag);
|
| 2244 | } else {
|
| 2245 | char ecallMsdPath[128] = {0};
|
| 2246 | sprintf(ecallMsdPath, "/tmp/ecall_msd_saved_%d", gEcallMsdSavedFlag);
|
| 2247 | err = ecall_msd_saved(ecallMsdPath, ecall_msd);
|
| 2248 | if (err >= 0) {
|
| 2249 | gEcallMsdSavedFlag++;
|
| 2250 | ECALL_Log("%s: ecall network not ready, msd has saved and gEcallMsdSavedFlag=%d.", __FUNCTION__, gEcallMsdSavedFlag);
|
| 2251 | //ecallStopTimer(&ecall_saved_sms_retransmit_timer);
|
| 2252 | //ecallStartTimer(&ecall_saved_sms_retransmit_timer, ECALL_SMS_SEND_MSD_TMR);
|
| 2253 | } else {
|
| 2254 | ECALL_Log("%s: ecall msd saved failed", __FUNCTION__);
|
| 2255 | }
|
| 2256 | }
|
| 2257 | }
|
| 2258 | ecall_reset_msd_timestamp();
|
| 2259 | #endif
|
| 2260 | ECALL_Log("%s: ecall network not ready, need saved msd and return", __FUNCTION__);
|
| 2261 | ecall_set_redial_flag(1);
|
| 2262 | return;
|
| 2263 | }
|
| 2264 | }
|
| 2265 |
|
| 2266 | ecall_get_ecalldata_t6_timer(); //update T6 timer
|
| 2267 | ecall_get_ecalldata_t7_timer(); //update T7 timer
|
| 2268 | ecall_send_getEcallOnly_cmd(); // get ecallonly value
|
| 2269 | if (ecall_get_ecallOnlySimValid() == 0) { //only once get ecallonlysim value
|
| 2270 | ecall_send_getEcallOnlySim_cmd();
|
| 2271 | }
|
| 2272 |
|
| 2273 | //set ecall status
|
| 2274 | ecall_set_ecall_status(DAEMON_ECALL_MO);
|
| 2275 | sprintf(arr, "AT+CECALLINSIDE=%d\r", ecallType);
|
| 2276 | ecallSendAtCmd((void*)arr, 1);
|
| 2277 |
|
| 2278 | //stop dial setup timer
|
| 2279 | //ecallStopTimer(&ecall_dial_setup_timer);
|
| 2280 | ecall_disable_timer(ecall_dial_setup_timer);
|
| 2281 | //start dial setup timer
|
| 2282 | if (ecall_daemon_get_mode() == 0) { //EU
|
| 2283 | //ecallStartTimer(&ecall_dial_setup_timer, ECALL_DIAL_SETUP_TMR_EU);
|
| 2284 | ecall_enable_timer(ecall_dial_setup_timer, ECALL_DIAL_SETUP_TMR_EU);
|
| 2285 | } else {
|
| 2286 | //ecallStartTimer(&ecall_dial_setup_timer, ECALL_DIAL_SETUP_TMR_ERA);
|
| 2287 | ecall_enable_timer(ecall_dial_setup_timer, ECALL_DIAL_SETUP_TMR_ERA);
|
| 2288 | }
|
| 2289 |
|
| 2290 | hang_up_ecall:
|
| 2291 | if (gEcallType == 5)
|
| 2292 | {
|
| 2293 | ecall_clear_status();
|
| 2294 | sprintf(arr, "AT+CECALLINSIDE=%d\r", ecallType);
|
| 2295 | ecallSendAtCmd((void*)arr, 1);
|
| 2296 | }
|
| 2297 |
|
| 2298 | error:
|
| 2299 | if(pStart) {
|
| 2300 | free(pStart);
|
| 2301 | }
|
| 2302 |
|
| 2303 | return;
|
| 2304 | }
|
| 2305 |
|
| 2306 | int ecall_daemon_set_ecallTimer(char *timerName, int timerValue)
|
| 2307 | {
|
| 2308 | if ((timerName != NULL) && (strlen(timerName) > 0))
|
| 2309 | {
|
| 2310 | if ((0 == strncmp(timerName, "callback", strlen("callback"))) || (0 == strncmp(timerName, "CALLBACK", strlen("CALLBACK")))) {
|
| 2311 | if (0 == ecall_daemon_get_mode()) {
|
| 2312 | ECALL_PSAP_CALLBACK_TMR_EU = timerValue;
|
| 2313 | } else {
|
| 2314 | ECALL_PSAP_CALLBACK_TMR_ERA = timerValue;
|
| 2315 | }
|
| 2316 | } else if ((0 == strncmp(timerName, "cleardown", strlen("cleardown"))) || (0 == strncmp(timerName, "CLEARDOWN", strlen("CLEARDOWN")))) {
|
| 2317 | ECALL_DIAL_CLEARDOWN_TMR = timerValue;
|
| 2318 | } else if ((0 == strncmp(timerName, "dial", strlen("dial"))) || (0 == strncmp(timerName, "DIAL", strlen("DIAL")))) {
|
| 2319 | if (0 == ecall_daemon_get_mode()) {
|
| 2320 | ECALL_DIAL_SETUP_TMR_EU = timerValue;
|
| 2321 | } else {
|
| 2322 | ECALL_DIAL_SETUP_TMR_ERA = timerValue;
|
| 2323 | }
|
| 2324 | } else if ((0 == strcmp(timerName, "sms")) || (0 == strcmp(timerName, "SMS"))) {
|
| 2325 | ECALL_SMS_SEND_MSD_TMR = timerValue;
|
| 2326 | } else if ((0 == strncmp(timerName, "dereg", strlen("dereg"))) || (0 == strncmp(timerName, "DEREG", strlen("DEREG")))) {
|
| 2327 | if (ecall_daemon_get_mode() == 0) { //EU mode
|
| 2328 | ECALL_NAD_DEREGISTRATION_TMR_EU = timerValue;
|
| 2329 | }
|
| 2330 | else {
|
| 2331 | ECALL_NAD_DEREGISTRATION_TMR_ERA = timerValue;
|
| 2332 | }
|
| 2333 | } else if ((0 == strncmp(timerName, "redialcnt", strlen("redialcnt"))) || (0 == strncmp(timerName, "REDIALCNT", strlen("REDIALCNT")))) {
|
| 2334 | ECALL_AUTO_DIAL_ATTEMPTS = timerValue;
|
| 2335 | } else if ((0 == strncmp(timerName, "redialtmr", strlen("redialtmr"))) || (0 == strncmp(timerName, "REDIALTMR", strlen("REDIALTMR")))) {
|
| 2336 | if (ecall_daemon_get_mode() == 1) //ERA mode
|
| 2337 | ECALL_REDIAL_TMR_ERA = timerValue;
|
| 2338 | } else if ((0 == strcmp(timerName, "smsprocess")) || (0 == strcmp(timerName, "SMSPROCESS"))) {
|
| 2339 | ecall_daemon_set_smsProcess(timerValue);
|
| 2340 | } else if ((0 == strcmp(timerName, "smsmsdcnt")) || (0 == strcmp(timerName, "SMSMSDCNT"))) {
|
| 2341 | ecall_set_smsMsd_send_count(timerValue);
|
| 2342 | } else if ((0 == strcmp(timerName, "hangup_redial_tmr")) || (0 == strcmp(timerName, "HANGUP_REDIAL_TMR"))) {
|
| 2343 | ecall_set_ecall_hangup_redial_timer(timerValue);
|
| 2344 | } else {
|
| 2345 | ECALL_Log("%s rcv ecall timer name is invalid.", __FUNCTION__);
|
| 2346 |
|
| 2347 | return -1;
|
| 2348 | }
|
| 2349 | ECALL_Log("%s: timerValue=%d, timerName=%s", __FUNCTION__, timerValue, timerName);
|
| 2350 |
|
| 2351 | return 0;
|
| 2352 | }
|
| 2353 | else
|
| 2354 | {
|
| 2355 | ECALL_Log("%s: set ecall timer name is invalid", __FUNCTION__);
|
| 2356 |
|
| 2357 | return -2;
|
| 2358 | }
|
| 2359 | }
|
| 2360 |
|
| 2361 | int ecall_daemon_get_ecallTimerValue(char *timerName)
|
| 2362 | {
|
| 2363 | int timerValue = 0;
|
| 2364 |
|
| 2365 | if ((timerName != NULL) && (strlen(timerName) > 0))
|
| 2366 | {
|
| 2367 | if ((0 == strncmp(timerName, "callback", strlen("callback"))) || (0 == strncmp(timerName, "CALLBACK", strlen("CALLBACK"))))
|
| 2368 | {
|
| 2369 | if (0 == ecall_daemon_get_mode()) {
|
| 2370 | timerValue = ECALL_PSAP_CALLBACK_TMR_EU;
|
| 2371 | } else {
|
| 2372 | timerValue = ECALL_PSAP_CALLBACK_TMR_ERA;
|
| 2373 | }
|
| 2374 | }
|
| 2375 | else if ((0 == strncmp(timerName, "cleardown", strlen("cleardown"))) || (0 == strncmp(timerName, "CLEARDOWN", strlen("CLEARDOWN"))))
|
| 2376 | {
|
| 2377 | timerValue = ECALL_DIAL_CLEARDOWN_TMR;
|
| 2378 | }
|
| 2379 | else if ((0 == strncmp(timerName, "dial", strlen("dial"))) || (0 == strncmp(timerName, "DIAL", strlen("DIAL"))))
|
| 2380 | {
|
| 2381 | if (0 == ecall_daemon_get_mode()) {
|
| 2382 | timerValue = ECALL_DIAL_SETUP_TMR_EU;
|
| 2383 | } else {
|
| 2384 | timerValue = ECALL_DIAL_SETUP_TMR_ERA;
|
| 2385 | }
|
| 2386 | }
|
| 2387 | else if ((0 == strcmp(timerName, "sms")) || (0 == strcmp(timerName, "SMS")))
|
| 2388 | {
|
| 2389 | timerValue = ECALL_SMS_SEND_MSD_TMR;
|
| 2390 | }
|
| 2391 | else if ((0 == strncmp(timerName, "dereg", strlen("dereg"))) || (0 == strncmp(timerName, "DEREG", strlen("DEREG")))) {
|
| 2392 | if (ecall_daemon_get_mode() == 0) { //EU mode
|
| 2393 | timerValue = ECALL_NAD_DEREGISTRATION_TMR_EU;
|
| 2394 | }
|
| 2395 | else {
|
| 2396 | timerValue = ECALL_NAD_DEREGISTRATION_TMR_ERA;
|
| 2397 | }
|
| 2398 | }
|
| 2399 | else if ((0 == strncmp(timerName, "redialcnt", strlen("redialcnt"))) || (0 == strncmp(timerName, "REDIALCNT", strlen("REDIALCNT"))))
|
| 2400 | {
|
| 2401 | timerValue = ECALL_AUTO_DIAL_ATTEMPTS;
|
| 2402 | }
|
| 2403 | else if ((0 == strncmp(timerName, "redialtmr", strlen("redialtmr"))) || (0 == strncmp(timerName, "REDIALTMR", strlen("REDIALTMR"))))
|
| 2404 | {
|
| 2405 | timerValue = ECALL_REDIAL_TMR_ERA;
|
| 2406 | }
|
| 2407 | else if ((0 == strcmp(timerName, "smsprocess")) || (0 == strcmp(timerName, "SMSPROCESS")))
|
| 2408 | {
|
| 2409 | timerValue = ecall_daemon_get_smsProcess();
|
| 2410 | }
|
| 2411 | else if ((0 == strcmp(timerName, "smsmsdcnt")) || (0 == strcmp(timerName, "SMSMSDCNT")))
|
| 2412 | {
|
| 2413 | timerValue = ecall_get_smsMsd_send_count();
|
| 2414 | }
|
| 2415 | else if ((0 == strcmp(timerName, "hangup_redial_tmr")) || (0 == strcmp(timerName, "HANGUP_REDIAL_TMR")))
|
| 2416 | {
|
| 2417 | timerValue = ecall_get_ecall_hangup_redial_timer();
|
| 2418 | }
|
| 2419 | else
|
| 2420 | {
|
| 2421 | ECALL_Log("%s rcv ecall timer name is invalid.", __FUNCTION__);
|
| 2422 |
|
| 2423 | return -1;
|
| 2424 | }
|
| 2425 | ECALL_Log("%s get ecall timerName[%s], timerValue[%d].", __FUNCTION__, timerName, timerValue);
|
| 2426 |
|
| 2427 | return timerValue;
|
| 2428 | }
|
| 2429 | else
|
| 2430 | {
|
| 2431 | ECALL_Log("%s get ecall timer value is invalid.", __FUNCTION__);
|
| 2432 |
|
| 2433 | return -2;
|
| 2434 | }
|
| 2435 | }
|
| 2436 |
|
| 2437 | int ecall_daemon_handle_setMode(char *ecallMode)
|
| 2438 | {
|
| 2439 | if ((ecallMode != NULL) && (strlen(ecallMode) > 0))
|
| 2440 | {
|
| 2441 | if ((0 == strncmp(ecallMode, "EU", strlen("EU"))) || (0 == strncmp(ecallMode, "eu", strlen("eu"))))
|
| 2442 | {
|
| 2443 | ecall_daemon_set_mode(0);
|
| 2444 | }
|
| 2445 | else if ((0 == strncmp(ecallMode, "ERA", strlen("ERA"))) || (0 == strncmp(ecallMode, "era", strlen("era"))))
|
| 2446 | {
|
| 2447 | ecall_daemon_set_mode(1);
|
| 2448 | }
|
| 2449 | else
|
| 2450 | {
|
| 2451 | ecall_daemon_set_mode(0);
|
| 2452 | }
|
| 2453 |
|
| 2454 | return 0;
|
| 2455 | }
|
| 2456 | else
|
| 2457 | {
|
| 2458 | ECALL_Log("%s: recv ecallMode[%s] is invalid", __FUNCTION__, ecallMode);
|
| 2459 |
|
| 2460 | return -1;
|
| 2461 | }
|
| 2462 | }
|
| 2463 |
|
| 2464 | void ecallHandleSmsMsdResp(void)
|
| 2465 | {
|
| 2466 | char *msdPath = NULL;
|
| 2467 | int ret = 0;
|
| 2468 |
|
| 2469 | ECALL_Log("%s: gEcallMode %d, gSmsMsd %d, gEcallStatus %d, gEcallDialCnt %d.", __FUNCTION__, gEcallMode, gSmsMsd, gEcallStatus, gEcallDialCnt);
|
| 2470 |
|
| 2471 | if (ecall_daemon_get_mode() == 1 && gSmsMsd == 1)
|
| 2472 | {
|
| 2473 | gEcallDialCnt = 0;
|
| 2474 | ecall_set_redial_flag(0);
|
| 2475 | msdPath = ecall_get_msdPath();
|
| 2476 | if (msdPath != NULL)
|
| 2477 | {
|
| 2478 | if (access(msdPath, F_OK) == 0)
|
| 2479 | {
|
| 2480 | remove(msdPath);
|
| 2481 | ECALL_Log("%s: msdPath=%s is removed.", __FUNCTION__, msdPath);
|
| 2482 | }
|
| 2483 | else
|
| 2484 | {
|
| 2485 | ECALL_Log("%s: msdPath isn't exist.", __FUNCTION__);
|
| 2486 | }
|
| 2487 |
|
| 2488 | ret = ecall_check_msd_hasMore();
|
| 2489 | if (ret == 0)
|
| 2490 | {
|
| 2491 | gEcallMsdSavedFlag = 0;
|
| 2492 | //ecallStopTimer(&ecall_saved_sms_retransmit_timer);
|
| 2493 | ecall_disable_timer(ecall_saved_sms_retransmit_timer);
|
| 2494 | }
|
| 2495 | else
|
| 2496 | {
|
| 2497 | //ecallStopTimer(&ecall_saved_sms_retransmit_timer);
|
| 2498 | ecall_disable_timer(ecall_saved_sms_retransmit_timer);
|
| 2499 | //ecallStartTimer(&ecall_saved_sms_retransmit_timer, ECALL_SMS_SEND_MSD_TMR);
|
| 2500 | ecall_enable_timer(ecall_saved_sms_retransmit_timer, ECALL_SMS_SEND_MSD_TMR);
|
| 2501 | }
|
| 2502 | gSmsMsd = 0;
|
| 2503 | }
|
| 2504 | else
|
| 2505 | //if (ecall_get_ecall_status() == DAEMON_ECALL_SMS)
|
| 2506 | {
|
| 2507 | ECALL_Log("%s: config msd sms is send success.", __FUNCTION__);
|
| 2508 | ecall_clear_curMsd();
|
| 2509 | //ecallStopTimer(&ecall_sms_retransmit_timer);
|
| 2510 | ecall_disable_timer(ecall_sms_retransmit_timer);
|
| 2511 | ecall_set_ecall_status(DAEMON_ECALL_IDLE);
|
| 2512 | gSmsMsd = 0;
|
| 2513 | gEcallSmsMsdCnt = 0;
|
| 2514 | }
|
| 2515 | }
|
| 2516 |
|
| 2517 | return;
|
| 2518 | }
|
| 2519 |
|
| 2520 | int ecall_daemon_send_msdSms(int smsSendMsdFlag)
|
| 2521 | {
|
| 2522 | int ret = 0;
|
| 2523 |
|
| 2524 | ECALL_Log("%s: smsSendMsdFlag=%d", __FUNCTION__, smsSendMsdFlag);
|
| 2525 |
|
| 2526 | if (0 == smsSendMsdFlag) {
|
| 2527 | ret = ecall_sms_send_cfg_msd();
|
| 2528 | } else if (1 == smsSendMsdFlag) {
|
| 2529 | ret = ecall_sms_send_saved_msd();
|
| 2530 | } else if (2 == smsSendMsdFlag) {
|
| 2531 | ret = ecall_sms_send_smsFailed_msd();
|
| 2532 | } else {
|
| 2533 | ECALL_Log("%s recv smsFlag is invalid.", __FUNCTION__);
|
| 2534 |
|
| 2535 | ret = -1;
|
| 2536 | }
|
| 2537 |
|
| 2538 | return ret;
|
| 2539 | }
|
| 2540 |
|
| 2541 | int ecall_daemon_set_ecallTestNum(char *ecallTestNum, char *ecallReconfigNum)
|
| 2542 | {
|
| 2543 | if ((ecallTestNum != NULL) && (strlen(ecallTestNum) > 0))
|
| 2544 | {
|
| 2545 | memset(testNumber, '\0', sizeof(testNumber));
|
| 2546 | memcpy(testNumber, ecallTestNum, strlen(ecallTestNum));
|
| 2547 |
|
| 2548 | ECALL_Log("%s: testNumber=%s", __FUNCTION__, testNumber);
|
| 2549 | }
|
| 2550 |
|
| 2551 | if ((ecallReconfigNum != NULL) && (strlen(ecallReconfigNum) > 0))
|
| 2552 | {
|
| 2553 | memset(reconfigureNumber, '\0', sizeof(reconfigureNumber));
|
| 2554 | memcpy(reconfigureNumber, ecallReconfigNum, strlen(ecallReconfigNum));
|
| 2555 |
|
| 2556 | ECALL_Log("%s: reconfigureNumber=%s", __FUNCTION__, reconfigureNumber);
|
| 2557 | }
|
| 2558 |
|
| 2559 | return 0;
|
| 2560 | }
|
| 2561 |
|
| 2562 | void ecallHandleClcc(const char *s)
|
| 2563 | {
|
| 2564 | char *callMumber;
|
| 2565 | int direction=0;
|
| 2566 | RIL_Call *ril_call_status;
|
| 2567 | RIL_CallState callStat = 0;
|
| 2568 | int callID = 0;
|
| 2569 |
|
| 2570 | if (strlen(nGMtEcallTestNumUrl) == 0) {
|
| 2571 | memset(nGMtEcallTestNumUrl, 0x00, sizeof(nGMtEcallTestNumUrl));
|
| 2572 | strncpy(nGMtEcallTestNumUrl, NG_ECALL_MT_DEFAULT_TEST_NUMBER_URL, sizeof(nGMtEcallTestNumUrl)-1);
|
| 2573 | }
|
| 2574 | if (strlen(nGMoEcallTestNumUrl) == 0) {
|
| 2575 | memset(nGMoEcallTestNumUrl, 0x00, sizeof(nGMoEcallTestNumUrl));
|
| 2576 | strncpy(nGMoEcallTestNumUrl, NG_ECALL_MO_DEFAULT_TEST_NUMBER_URL, sizeof(nGMoEcallTestNumUrl)-1);
|
| 2577 | }
|
| 2578 |
|
| 2579 | ril_call_status = (RIL_Call*)s;
|
| 2580 | if(ril_call_status->number == NULL)
|
| 2581 | {
|
| 2582 | ECALL_Log("%s: received call number is NULL", __FUNCTION__);
|
| 2583 | return;
|
| 2584 | }
|
| 2585 | ECALL_Log("%s: %s", __FUNCTION__,ril_call_status->number);
|
| 2586 |
|
| 2587 | callMumber = ril_call_status->number;
|
| 2588 | direction = ril_call_status->isMT;
|
| 2589 | callStat = ril_call_status->state;
|
| 2590 | callID = ril_call_status->index;
|
| 2591 |
|
| 2592 | ECALL_Log("%s: callStat %d, callMumber %s, direction %d, callID %d", __FUNCTION__, callStat, callMumber, direction, callID);
|
| 2593 | ECALL_Log("%s: testNumber=%s, reconfigureNumber=%s", __FUNCTION__, testNumber, reconfigureNumber);
|
| 2594 | ECALL_Log("%s: nGMtEcallTestNumUrl=%s, nGMoEcallTestNumUrl=%s", __FUNCTION__, nGMtEcallTestNumUrl, nGMoEcallTestNumUrl);
|
| 2595 |
|
| 2596 | if (ecall_current_is_ecallOnly_mode() == 1)
|
| 2597 | {
|
| 2598 | ECALL_Log("%s: ecall only mode, don't care ecall number!", __FUNCTION__);
|
| 2599 | }
|
| 2600 | else if(strcmp(callMumber, "112") && strcmp(callMumber, "119") && (strstr(callMumber, testNumber) == NULL) && (strstr(callMumber, reconfigureNumber) == NULL))
|
| 2601 | {
|
| 2602 | if ((strstr(callMumber, nGMoEcallTestNumUrl) == NULL) && (strstr(callMumber, nGMtEcallTestNumUrl) == NULL)) {
|
| 2603 | if ((!direction) && (0 == callStat)) //has a normal call is answer
|
| 2604 | gCurrentHasCallSet = 1;
|
| 2605 | ECALL_Log("%s: it's not a ecall, just return", __FUNCTION__);
|
| 2606 | return;
|
| 2607 | }
|
| 2608 | }
|
| 2609 | else
|
| 2610 | {
|
| 2611 | ECALL_Log("%s: callMumber %s, testNumber %s, reconfigureNumber %s", __FUNCTION__, callMumber, testNumber, reconfigureNumber);
|
| 2612 | }
|
| 2613 |
|
| 2614 | ECALL_WAIT_T6_T7_TMR = ECALL_WAIT_HL_ACK_TMR + ECALL_WAIT_LL_ACK_TMR; //update T6 + T7 timer
|
| 2615 | ECALL_Log("%s: T6 + T7 timer %d", __FUNCTION__,ECALL_WAIT_T6_T7_TMR);
|
| 2616 |
|
| 2617 | if(!direction) { //MO call
|
| 2618 | //rcord current call is a ecall
|
| 2619 | gEcallCallID = callID;
|
| 2620 | if (0 == callStat) {
|
| 2621 | ecall_set_redial_flag(0);
|
| 2622 | if ((ecall_get_ecall_status() == DAEMON_ECALL_MO) || (ecall_get_ecall_status() == DAEMON_ECALL_MO_MSD_SENT)) {
|
| 2623 | //stop dial setup timer
|
| 2624 | //ecallStopTimer(&ecall_dial_setup_timer);
|
| 2625 | ecall_disable_timer(ecall_dial_setup_timer);
|
| 2626 | if (ecall_get_ecall_status() == DAEMON_ECALL_MO) {
|
| 2627 | //set ecall status
|
| 2628 | ecall_set_ecall_status(DAEMON_ECALL_MO_SETUP);
|
| 2629 | }
|
| 2630 | //start ecall clear down timer
|
| 2631 | //ecallStartTimer(&ecall_dial_cleardown_timer, ECALL_DIAL_CLEARDOWN_TMR);
|
| 2632 | ecall_enable_timer(ecall_dial_cleardown_timer, ECALL_DIAL_CLEARDOWN_TMR);
|
| 2633 | }
|
| 2634 | }else if (2 == callStat) {
|
| 2635 | if (ecall_get_ecall_status() == DAEMON_ECALL_MO) {
|
| 2636 | }
|
| 2637 | } else {
|
| 2638 | ECALL_Log("%s: callMumber %s, callStat %d", __FUNCTION__,callMumber, callStat);
|
| 2639 | }
|
| 2640 | } else { //MT Call
|
| 2641 | if (0 == callStat) { /* only MT call status is active to send voice data */
|
| 2642 | ECALL_Log("%s: callMumber %s, call audio API", __FUNCTION__,callMumber);
|
| 2643 | ecall_ubusSendEcallCmd(0, 1, 0, NULL); //TEL_AT_CMD_ATP_0
|
| 2644 | ecall_set_voice_data(4, 0, 1);
|
| 2645 | }
|
| 2646 | }
|
| 2647 |
|
| 2648 | if (ecall_get_ecall_redial_cnt() == ECALL_AUTO_DIAL_ATTEMPTS) //ecall redial count is ECALL_AUTO_DIAL_ATTEMPTS, but new MO/MT ecall has setup successful, so redialcnt need to reset;
|
| 2649 | {
|
| 2650 | ecall_reset_ecall_redial_cnt();
|
| 2651 | }
|
| 2652 |
|
| 2653 | return;
|
| 2654 | }
|
| 2655 |
|
| 2656 | static char hexToNum(char ch)
|
| 2657 | {
|
| 2658 | ch = toupper(ch);
|
| 2659 |
|
| 2660 | if (isdigit(ch)) {
|
| 2661 | ch -= '0';
|
| 2662 | } else if (isxdigit(ch)) {
|
| 2663 | ch -= 'A';
|
| 2664 | ch += 0x0A;
|
| 2665 | }
|
| 2666 |
|
| 2667 | return ch;
|
| 2668 | }
|
| 2669 |
|
| 2670 | void ecall_daemon_str2hex(int src_len, char *psrc, char *pdest, int dest_len)
|
| 2671 | {
|
| 2672 | int i = 0;
|
| 2673 | char highpart =0;
|
| 2674 | char lowpart = 0;
|
| 2675 | char result = 0;
|
| 2676 |
|
| 2677 | ECALL_Log("%s: src_len %d, dest_len %d", __func__,src_len, dest_len);
|
| 2678 |
|
| 2679 | if((psrc == NULL) || (pdest == NULL))
|
| 2680 | return;
|
| 2681 |
|
| 2682 | if(src_len > dest_len<<1)
|
| 2683 | return;
|
| 2684 |
|
| 2685 | for (i = 0; i < src_len; i++)
|
| 2686 | {
|
| 2687 | highpart = hexToNum(*psrc++);
|
| 2688 | //ECALL_Log(str_to_Hex5, "%s: result[%d]: highpart %X\n", __FUNCTION__, i>>1, highpart);
|
| 2689 |
|
| 2690 | lowpart = hexToNum(*psrc++);
|
| 2691 | //ECALL_Log(str_to_Hex6, "%s: result[%d]: lowpart %X\n", __FUNCTION__, i>>1, highpart);
|
| 2692 |
|
| 2693 | result = (highpart<<4) | lowpart;
|
| 2694 | *pdest++ = result;
|
| 2695 | i++;
|
| 2696 | //ECALL_Log(str_to_Hex7, "%s: result[%d]: %X, highpart %d, lowpart %d\n", __FUNCTION__, i>>1, result, highpart, lowpart);
|
| 2697 | }
|
| 2698 |
|
| 2699 | return;
|
| 2700 | }
|
| 2701 |
|
| 2702 | void ecallHandleSmsReceived(const char *s)
|
| 2703 | {
|
| 2704 | char *line = ecallStrdup((char *)s);
|
| 2705 | char *data = NULL;
|
| 2706 | char *pStart = NULL;
|
| 2707 | char hexData[128] = {0};
|
| 2708 |
|
| 2709 | ECALL_Log("%s: %s, msg len=%d.", __FUNCTION__, s, strlen(s));
|
| 2710 | if (line)
|
| 2711 | {
|
| 2712 | data = line;
|
| 2713 | pStart = line;
|
| 2714 | }
|
| 2715 |
|
| 2716 | ecall_daemon_str2hex(strlen(data), data, hexData, sizeof(hexData));
|
| 2717 |
|
| 2718 | #if 0
|
| 2719 | hexDataLen = strlen(data)/2;
|
| 2720 |
|
| 2721 | if ( hexDataLen > 0 )
|
| 2722 | {
|
| 2723 | for (i = 0; i < hexDataLen; i++)
|
| 2724 | {
|
| 2725 | ECALL_Log(ecallHandleSmsReceived1, "%s: hexData[%d]=%x", __FUNCTION__, i, hexData[i]);
|
| 2726 | }
|
| 2727 | }
|
| 2728 | #endif
|
| 2729 | ecall_sms_parse_pdu(hexData);
|
| 2730 |
|
| 2731 | if(pStart)
|
| 2732 | free(pStart);
|
| 2733 | }
|
| 2734 |
|
| 2735 | void ecallHandleSmsIdxRecvExt(void *data)
|
| 2736 | {
|
| 2737 | int err = 0;
|
| 2738 | int *resp = NULL;
|
| 2739 | int index = 0;
|
| 2740 |
|
| 2741 | if (data) {
|
| 2742 | resp = (int *)data;
|
| 2743 | ECALL_Log("%s: value[0]=%d, value[1]=%d", __FUNCTION__, resp[0], resp[1]);
|
| 2744 | index = resp[1];
|
| 2745 |
|
| 2746 | ECALL_Log("%s: index=%d", __FUNCTION__, index);
|
| 2747 | if (index >= 0) {
|
| 2748 | err = ecall_ubus_get_cmgr(index);
|
| 2749 | ECALL_Log("%s: err=%d", __FUNCTION__, err);
|
| 2750 | }
|
| 2751 | }
|
| 2752 |
|
| 2753 | return;
|
| 2754 | }
|
| 2755 |
|
| 2756 | void ecallHandleNetworkChanged(void *data)
|
| 2757 | {
|
| 2758 | UNUSED(data);
|
| 2759 |
|
| 2760 | ECALL_Log("%s: enter!!!", __FUNCTION__);
|
| 2761 |
|
| 2762 | ecall_get_network_status();
|
| 2763 |
|
| 2764 | if (0 == ecall_get_redial_flag() || ecall_get_ecallNetwork() <= 0)
|
| 2765 | {
|
| 2766 | ECALL_Log("%s: network flag is 0 or network not ready, just return!!!", __FUNCTION__);
|
| 2767 | return;
|
| 2768 | }
|
| 2769 |
|
| 2770 | ECALL_Log("%s: gEcallNW=%d, gEcallMsdSavedFlag=%d, gEcallRedial=%d.", __FUNCTION__, gEcallNW, gEcallMsdSavedFlag, gEcallRedial);
|
| 2771 |
|
| 2772 | if ((ecall_daemon_get_mode() == 1))
|
| 2773 | {
|
| 2774 | if ((gEcallMsdSavedFlag > 0) && (gEcallDialCnt == ECALL_AUTO_DIAL_ATTEMPTS))
|
| 2775 | {
|
| 2776 | ecall_sms_send_saved_msd();
|
| 2777 | if (ecall_get_ecall_status() == DAEMON_ECALL_SMS)
|
| 2778 | {
|
| 2779 | ecall_set_ecall_status(DAEMON_ECALL_IDLE);
|
| 2780 | }
|
| 2781 | }
|
| 2782 |
|
| 2783 | if ((ecall_get_redial_flag()) == 1 && (gEcallDialCnt < ECALL_AUTO_DIAL_ATTEMPTS))
|
| 2784 | ecall_redial_only();
|
| 2785 | }
|
| 2786 |
|
| 2787 | return;
|
| 2788 | }
|
| 2789 |
|
| 2790 | void ecallHandleSmsIdxRecvONSim(void *data)
|
| 2791 | {
|
| 2792 | int err = 0;
|
| 2793 | int *resp = NULL;
|
| 2794 | int index = 0;
|
| 2795 |
|
| 2796 | if (data) {
|
| 2797 | resp = (int *)data;
|
| 2798 | ECALL_Log("%s: index=%d", __FUNCTION__, *resp);
|
| 2799 | index = *resp;
|
| 2800 |
|
| 2801 | ECALL_Log("%s: index=%d", __FUNCTION__, index);
|
| 2802 | if (index >= 0) {
|
| 2803 | err = ecall_ubus_get_cmgr(index);
|
| 2804 | ECALL_Log("%s: err=%d", __FUNCTION__, err);
|
| 2805 | }
|
| 2806 | }
|
| 2807 |
|
| 2808 | return;
|
| 2809 | }
|
| 2810 |
|
| 2811 | void ecallHandleEcalldata(const char *s)
|
| 2812 | {
|
| 2813 | int urc_id = -1, urc_data = -1, timer = 0;
|
| 2814 | int *arr_p;
|
| 2815 | arr_p = (int*)s;
|
| 2816 | urc_id = *arr_p;
|
| 2817 | urc_data = *((int *)(arr_p + 1));
|
| 2818 | timer = *((int *)(arr_p + 2));
|
| 2819 | char alAckStr[128] = {0};
|
| 2820 | char *timeStr = NULL;
|
| 2821 | ECALL_Log("%s: urc_id %d, urc_data %d, timer %d", __FUNCTION__, urc_id, urc_data, timer);
|
| 2822 |
|
| 2823 | if (urc_id == 5) {
|
| 2824 | if (urc_data == 2) { //get T6 timer 1 frame = 20ms
|
| 2825 | ECALL_WAIT_HL_ACK_TMR = timer * 20;
|
| 2826 | } else if (urc_data == 3) {
|
| 2827 | ECALL_WAIT_LL_ACK_TMR = timer * 20;
|
| 2828 | } else {
|
| 2829 | ECALL_Log("%s: recv no used urc data.", __FUNCTION__);
|
| 2830 | return;
|
| 2831 | }
|
| 2832 | } else if (urc_id == 24 || urc_id == 25) { //T5 or T6 expiry
|
| 2833 | //stop ecall_wait_hl_ack_timer and send msd via sms when ecall mode is ERA
|
| 2834 | //stop wait HL_ACK timer
|
| 2835 | //ecallStopTimer(&ecall_wait_hl_ack_timer);
|
| 2836 | ecall_disable_timer(ecall_wait_hl_ack_timer);
|
| 2837 | ecall_retransmit_msd_cb(0, NULL, NULL);
|
| 2838 | } else if (urc_id == 26) { //T7 expiry
|
| 2839 | //stop ecall_wait_hl_ack_timer and send msd via sms when ecall mode is ERA
|
| 2840 | //stop wait HL_ACK timer
|
| 2841 | //ecallStopTimer(&ecall_wait_hl_ack_timer);
|
| 2842 | ecall_disable_timer(ecall_wait_hl_ack_timer);
|
| 2843 | if (gEacllUserUpdatedMsd == 0 || gEacllUserUpdatedMsd == 2) { //gEacllUserUpdatedMsd == 1 is user don't update msd, so send old msd via sms is not must.
|
| 2844 | ecall_retransmit_msd_cb(0, NULL, NULL);
|
| 2845 | }
|
| 2846 | gEacllUserUpdatedMsd = 0;
|
| 2847 | } else if (urc_id == 9) { //pull mode, user need update msd
|
| 2848 | gEacllUserUpdatedMsd = 1;
|
| 2849 | } else if (urc_id == 21) { //user has updated msd
|
| 2850 | if (gEacllUserUpdatedMsd == 1) //gEacllUserUpdatedMsd value update when pull mode and received urcid=9
|
| 2851 | gEacllUserUpdatedMsd = 2;
|
| 2852 | } else if(urc_id == 17) { //HL-ACK received
|
| 2853 | //stop wait HL_ACK timer
|
| 2854 | //ecallStopTimer(&ecall_wait_hl_ack_timer);
|
| 2855 | ecall_disable_timer(ecall_wait_hl_ack_timer);
|
| 2856 | //set ecall status
|
| 2857 | ecall_set_ecall_status(DAEMON_ECALL_MO_MSD_SENT);
|
| 2858 | if (1 == ecall_daemon_get_mode())
|
| 2859 | {
|
| 2860 | //ecall_clear_curMsd();
|
| 2861 | ecall_clear_allSavedMsd();
|
| 2862 | }
|
| 2863 | gEcallDialCnt = 0;
|
| 2864 | ecall_daemon_set_ecallPush(0);
|
| 2865 | gEacllUserUpdatedMsd = 0;
|
| 2866 | }
|
| 2867 | else if(urc_id == 12) { //SEND MSD request received
|
| 2868 | //start wait HL_ACK timer
|
| 2869 | //ecallStopTimer(&ecall_wait_hl_ack_timer);
|
| 2870 | ecall_disable_timer(ecall_wait_hl_ack_timer);
|
| 2871 | //ecallStartTimer(&ecall_wait_hl_ack_timer, ECALL_WAIT_T6_T7_TMR);
|
| 2872 | ecall_enable_timer(ecall_wait_hl_ack_timer, ECALL_WAIT_T6_T7_TMR);
|
| 2873 | //set ecall status
|
| 2874 | ecall_set_ecall_status(DAEMON_ECALL_MO_MSD);
|
| 2875 | } else if (urc_id == 0) {
|
| 2876 | ecall_daemon_set_ecallPush(0);
|
| 2877 | if ((urc_data & 0x02) == 0) { //receice eIM completes sending MSD
|
| 2878 | //stop wait HL_ACK timer
|
| 2879 | //ecallStopTimer(&ecall_wait_hl_ack_timer);
|
| 2880 | ecall_disable_timer(ecall_wait_hl_ack_timer);
|
| 2881 | //set ecall status
|
| 2882 | ecall_set_ecall_status(DAEMON_ECALL_MO_MSD_SENT);
|
| 2883 | if (1 == ecall_daemon_get_mode())
|
| 2884 | {
|
| 2885 | //ecall_clear_curMsd();
|
| 2886 | ecall_clear_allSavedMsd();
|
| 2887 | }
|
| 2888 | gEcallDialCnt = 0;
|
| 2889 | gEacllUserUpdatedMsd = 0;
|
| 2890 | //save received al-ack and it's timestamp
|
| 2891 | timeStr = ecall_get_timestamp();
|
| 2892 | if (strlen(timeStr) > 0) {
|
| 2893 | memset(alAckStr, 0x00, sizeof(alAckStr));
|
| 2894 | snprintf(alAckStr, sizeof(alAckStr), "IVS received AL-ACK on %s\n", timeStr);
|
| 2895 | if (strlen(alAckStr) > 0) {
|
| 2896 | ecall_save_alAck(alAckStr);
|
| 2897 | }
|
| 2898 | } else {
|
| 2899 | ECALL_Log("%s: ecall get time string fail.", __FUNCTION__);
|
| 2900 | }
|
| 2901 | } else if ((urc_data & 0x02) == 2) { //Clear down received
|
| 2902 | if (ecall_get_ecall_status() <= DAEMON_ECALL_MO_MSD_SENT) { //normol clear down
|
| 2903 | //stop wait HL_ACK timer
|
| 2904 | //ecallStopTimer(&ecall_wait_hl_ack_timer);
|
| 2905 | ecall_disable_timer(ecall_wait_hl_ack_timer);
|
| 2906 | //stop clear down timer
|
| 2907 | //ecallStopTimer(&ecall_dial_cleardown_timer);
|
| 2908 | ecall_disable_timer(ecall_dial_cleardown_timer);
|
| 2909 | //set ecall status
|
| 2910 | ecall_set_ecall_status(DAEMON_ECALL_MO_MSD_SENT);
|
| 2911 | //hang up call
|
| 2912 | ecall_hang_up();
|
| 2913 | //set ecall status
|
| 2914 | ecall_set_ecall_status(DAEMON_ECALL_IDLE);
|
| 2915 | //set psap callback timer
|
| 2916 | if (ecall_daemon_get_mode() == 0) { //EU Mode
|
| 2917 | ecall_start_auto_answer(ECALL_PSAP_CALLBACK_TMR_EU);
|
| 2918 | } else {
|
| 2919 | ecall_start_auto_answer(ECALL_PSAP_CALLBACK_TMR_ERA);
|
| 2920 | }
|
| 2921 | } else {
|
| 2922 | ECALL_Log("%s: error1 urc_id %d, urc_data %0x, ecall status %d.", __FUNCTION__, urc_id, urc_data, gEcallStatus);
|
| 2923 | }
|
| 2924 | } else {
|
| 2925 | ECALL_Log("%s: error2 urc_id %d, urc_data %0x.", __FUNCTION__, urc_id, urc_data);
|
| 2926 | }
|
| 2927 | } else {
|
| 2928 | ECALL_Log("%s: urc_id %d unused.", __FUNCTION__, urc_id);
|
| 2929 | }
|
| 2930 |
|
| 2931 | return;
|
| 2932 | }
|
| 2933 |
|
| 2934 | void ecallHandlePsapHangUp(void)
|
| 2935 | {
|
| 2936 | ECALL_Log("%s: recv 'NO CARRIER'", __FUNCTION__);
|
| 2937 | ECALL_Log("%s: gCurrentHasCallSet[%d], gEcallCallID[%d], gEcallMode[%d], gEcallType[%d]", __FUNCTION__, gCurrentHasCallSet, gEcallCallID, gEcallMode, gEcallType);
|
| 2938 | ECALL_Log("%s: ecall_get_ecall_status[%d]", __FUNCTION__, ecall_get_ecall_status());
|
| 2939 | ECALL_Log("%s: gEcallDialCnt[%d]", __FUNCTION__, gEcallDialCnt);
|
| 2940 |
|
| 2941 | if (gEcallType == 5) //for user hang up ecall
|
| 2942 | {
|
| 2943 | ecall_clear_status();
|
| 2944 | return;
|
| 2945 | }
|
| 2946 | if (ecall_daemon_send_ceer_cmd() != 0)
|
| 2947 | {
|
| 2948 | ECALL_Log("%s: get ceer falied", __FUNCTION__);
|
| 2949 | return;
|
| 2950 | }
|
| 2951 | ECALL_Log("%s: gEcallCeer[%d]", __FUNCTION__, ecall_daemon_get_ceerVal());
|
| 2952 |
|
| 2953 | gCurrentHasCallSet = 0;
|
| 2954 |
|
| 2955 | if(gEcallCallID != 0) //current call is ecall
|
| 2956 | {
|
| 2957 | gEcallCallID = 0;
|
| 2958 | if (ecall_daemon_get_ceerVal() != 16) //gEcallNormalHangup=0 is not user use AT+CECALL=5 or psap send clear down command
|
| 2959 | {
|
| 2960 | //when ecall hangup and ivs not received AL-ACK and msd is transmitting, ivs need redial and send msd
|
| 2961 | if (ecall_get_ecall_status() == DAEMON_ECALL_MO)
|
| 2962 | {
|
| 2963 | //clear ecall timer
|
| 2964 | ecallClearTimer();
|
| 2965 | if (ecall_daemon_get_mode() == 1)
|
| 2966 | {
|
| 2967 | if (gEcallDialCnt < ECALL_AUTO_DIAL_ATTEMPTS)
|
| 2968 | {
|
| 2969 | //ecall_redial_and_send_msd();
|
| 2970 | //gEcallDialCnt++;
|
| 2971 | //ecallStartTimer(&ecall_dial_setup_timer, ECALL_REDIAL_TMR_ERA);
|
| 2972 | ecall_enable_timer(ecall_redial_timer, ECALL_REDIAL_TMR_ERA);
|
| 2973 | }
|
| 2974 | else
|
| 2975 | {
|
| 2976 | if (gEcallMsdSavedFlag > 0)
|
| 2977 | {
|
| 2978 | ecall_sms_send_saved_msd();
|
| 2979 | }
|
| 2980 | }
|
| 2981 | }
|
| 2982 | else //EU mode, redial timers has confused
|
| 2983 | {
|
| 2984 | //to be do
|
| 2985 | }
|
| 2986 | }
|
| 2987 | else if (ecall_get_ecall_status() == DAEMON_ECALL_MO_SETUP)
|
| 2988 | {
|
| 2989 | //clear ecall timer
|
| 2990 | ecallClearTimer();
|
| 2991 | ecall_redial_and_send_msd();
|
| 2992 | ECALL_Log("%s: ecall_redial_and_send_msd", __FUNCTION__);
|
| 2993 | }
|
| 2994 | else if (ecall_get_ecall_status() == DAEMON_ECALL_MO_MSD)
|
| 2995 | {
|
| 2996 | //clear ecall timer
|
| 2997 | ecallClearTimer();
|
| 2998 | ecall_redial_and_send_msd();
|
| 2999 | ECALL_Log("%s: ecall_redial_and_send_msd", __FUNCTION__);
|
| 3000 | }
|
| 3001 | else if (ecall_get_ecall_status() == DAEMON_ECALL_MO_MSD_SENT)
|
| 3002 | {
|
| 3003 | //clear ecall timer
|
| 3004 | ecallClearTimer();
|
| 3005 | ecall_set_redial_flag(1);
|
| 3006 | ECALL_Log("%s: ecall should redial only", __FUNCTION__);
|
| 3007 | }
|
| 3008 | else
|
| 3009 | {
|
| 3010 | ECALL_Log("%s: recv normal disconnet the ivs", __FUNCTION__);
|
| 3011 | }
|
| 3012 | //return; //ecall daemon need set auto answer when abnormal call disconnect.
|
| 3013 | }
|
| 3014 | else
|
| 3015 | {
|
| 3016 | //ecallStopTimer(&ecall_dial_setup_timer);
|
| 3017 | ecall_disable_timer(ecall_dial_setup_timer);
|
| 3018 | ecall_set_ecall_status(DAEMON_ECALL_IDLE);
|
| 3019 | }
|
| 3020 | }
|
| 3021 | else
|
| 3022 | {
|
| 3023 | ECALL_Log("%s: current call isn't a ecall.", __FUNCTION__);
|
| 3024 | return;
|
| 3025 | }
|
| 3026 |
|
| 3027 | //set auto answer and start psap callback timer
|
| 3028 | if (ecall_daemon_get_mode() == 0) { //EU mode
|
| 3029 | ecall_start_auto_answer(ECALL_PSAP_CALLBACK_TMR_EU);
|
| 3030 | } else if (ecall_daemon_get_mode() == 1) {
|
| 3031 | ecall_start_auto_answer(ECALL_PSAP_CALLBACK_TMR_ERA);
|
| 3032 | } else {
|
| 3033 | ECALL_Log("%s: set psap callback timer failed, gEcallMode=%d.", __FUNCTION__, ecall_daemon_get_mode());
|
| 3034 | }
|
| 3035 |
|
| 3036 | if (ecall_send_getEcallOnly_cmd() == 0)
|
| 3037 | {
|
| 3038 | if (ecall_current_is_ecallOnly_mode() == 1)
|
| 3039 | {
|
| 3040 | //ecallStopTimer(&ecall_deregister_network_timer);
|
| 3041 | ecall_disable_timer(ecall_deregister_network_timer);
|
| 3042 | if (ecall_daemon_get_mode() == 0) { //EU mode
|
| 3043 | //ecallStartTimer(&ecall_deregister_network_timer, ECALL_NAD_DEREGISTRATION_TMR_EU);
|
| 3044 | ecall_enable_timer(ecall_deregister_network_timer, ECALL_NAD_DEREGISTRATION_TMR_EU);
|
| 3045 | }
|
| 3046 | else {
|
| 3047 | //ecallStartTimer(&ecall_deregister_network_timer, ECALL_NAD_DEREGISTRATION_TMR_ERA);
|
| 3048 | ecall_enable_timer(ecall_deregister_network_timer, ECALL_NAD_DEREGISTRATION_TMR_ERA);
|
| 3049 | }
|
| 3050 | }
|
| 3051 | }
|
| 3052 |
|
| 3053 | //set ecall status
|
| 3054 | ecall_set_ecall_status(DAEMON_ECALL_IDLE);
|
| 3055 |
|
| 3056 | return;
|
| 3057 | }
|
| 3058 |
|
| 3059 | int ecall_handle_ril_ind(struct ubus_context *ctx, unsigned int rilid, unsigned int rilerror, char *data, int data_len)
|
| 3060 | {
|
| 3061 | UNUSED(data_len);
|
| 3062 | UNUSED(ctx);
|
| 3063 |
|
| 3064 | int ret = 0;
|
| 3065 |
|
| 3066 | if (rilerror)
|
| 3067 | return -1;
|
| 3068 |
|
| 3069 | ECALL_Log("ecall_handle_ril_ind: ecall status: %d, ecall mode: %d, ecall type: %d, ecall nw: %d", gEcallStatus, gEcallMode, gEcallType, gEcallNW);
|
| 3070 |
|
| 3071 | switch(rilid)
|
| 3072 | {
|
| 3073 | case RIL_UNSOL_RESPONSE_CALL_STATE_CHANGED_EXT: //+clcc
|
| 3074 | ecallHandleClcc(data);
|
| 3075 | break;
|
| 3076 |
|
| 3077 | case RIL_UNSOL_ECALLDATA: //+ecalldata
|
| 3078 | ecallHandleEcalldata(data);
|
| 3079 | break;
|
| 3080 |
|
| 3081 | case RIL_UNSOL_CALL_NO_CARRIER_EXT: //PSAP hang up ecall
|
| 3082 | ecallHandlePsapHangUp();
|
| 3083 | break;
|
| 3084 |
|
| 3085 | case RIL_UNSOL_ECALL_TYPE:
|
| 3086 | ecallHandleEcallType(data);
|
| 3087 | break;
|
| 3088 |
|
| 3089 | case RIL_UNSOL_RESPONSE_SMS_SENT:
|
| 3090 | //ecallHandleSmsMsdResp();
|
| 3091 | break;
|
| 3092 |
|
| 3093 | case RIL_UNSOL_RESPONSE_NEW_SMS: /* +CMT */
|
| 3094 | if (ecall_daemon_get_smsProcess() == 1 && ecall_daemon_get_mode() == 1)
|
| 3095 | ecallHandleSmsReceived(data);
|
| 3096 | break;
|
| 3097 |
|
| 3098 | case RIL_UNSOL_RESPONSE_NEW_SMS_ON_SIM: /* +CMTI */
|
| 3099 | if (ecall_daemon_get_smsProcess() == 1 && ecall_daemon_get_mode() == 1)
|
| 3100 | ecallHandleSmsIdxRecvONSim(data);
|
| 3101 | break;
|
| 3102 |
|
| 3103 | case RIL_UNSOL_NEW_SMS_EXT: /* +CMTI */
|
| 3104 | if (ecall_daemon_get_smsProcess() == 1 && ecall_daemon_get_mode() == 1)
|
| 3105 | ecallHandleSmsIdxRecvExt(data);
|
| 3106 | break;
|
| 3107 |
|
| 3108 | case RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED: /* network is changed */
|
| 3109 | ecallHandleNetworkChanged(data);
|
| 3110 | break;
|
| 3111 |
|
| 3112 | default:
|
| 3113 | break;
|
| 3114 | }
|
| 3115 |
|
| 3116 | return ret;
|
| 3117 | }
|
| 3118 |
|
| 3119 | #endif
|