blob: 3a13b6134fda66cea68a1c681b1b9ca967795bf6 [file] [log] [blame]
b.liufd87baf2024-11-15 15:30:38 +08001/*
2* ril_ecall.c
3*
4* Implementation of ecall related functions.
5*
6* The general structure is as follows:
7* API --- mbtk_rild --- atcmdsrv --- modem
8* |
9 |
10* ecall_daemon
11*
12*/
13/******************************************************************************
14
15 EDIT HISTORY FOR FILE
16
17 WHEN WHO WHAT,WHERE,WHY
18-------- -------- -------------------------------------------------------
192024/11/04 LiuBin Initial version
20
21******************************************************************************/
b.liu15f456b2024-10-31 20:16:06 +080022#include <stdio.h>
23#include <stdlib.h>
24#include <unistd.h>
25#include <errno.h>
26#include <sys/socket.h>
27#include <sys/un.h>
28#include <netinet/in.h>
29#include <pthread.h>
30#include <sys/epoll.h>
31#include <fcntl.h>
32#include <signal.h>
33
34#include "mbtk_type.h"
35#include "mbtk_ril.h"
36#include "atchannel.h"
37#include "at_tok.h"
38#include "mbtk_utils.h"
39#include "ril_info.h"
40
41static mbtk_ecall_mode_type_enum ecall_mode = MBTK_ECALL_MODE_TYPE_EU;
42
b.liu7ca612c2025-04-25 09:23:36 +080043void ril_rsp_pack_send(mbtk_sim_type_enum sim_id, ATPortType_enum port, int fd, int ril_id, int msg_index, const void* data, int data_len);
44ATPortId_enum portType_2_portId(mbtk_sim_type_enum sim_id, ATPortType_enum port);
b.liu15f456b2024-10-31 20:16:06 +080045
b.liu7ca612c2025-04-25 09:23:36 +080046
47static int cfg_ecalldata_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_ecall_cfg_item_enum type, uint32 *value, int *cme_err)
b.liueea595d2024-11-05 19:52:10 +080048{
49 ATResponse *response = NULL;
b.liu62240ee2024-11-07 17:52:45 +080050// char *tmp_ptr = NULL;
b.liueea595d2024-11-05 19:52:10 +080051 int tmp_int;
52 char cmd[100] = {0};
53 int err = 0;
54
55 snprintf(cmd, sizeof(cmd), "AT*ECALLDATA=5,%d", type);
b.liu7ca612c2025-04-25 09:23:36 +080056 err = at_send_command_singleline(portType_2_portId(sim_id, port), cmd, "*ECALLDATA:", &response);
b.liueea595d2024-11-05 19:52:10 +080057
58 if (err < 0 || response->success == 0 || !response->p_intermediates){
59 *cme_err = at_get_cme_error(response);
60 goto exit;
61 }
62
63 char *line = response->p_intermediates->line;
64 err = at_tok_start(&line);
65 if (err < 0)
66 {
67 goto exit;
68 }
69
70 err = at_tok_nextint(&line, &tmp_int);
71 if (err < 0)
72 {
73 goto exit;
74 }
75
76 err = at_tok_nextint(&line, &tmp_int);
77 if (err < 0)
78 {
79 goto exit;
80 }
81
82 err = at_tok_nextint(&line, &tmp_int);
83 if (err < 0)
84 {
85 goto exit;
86 }
87
88 *value = (uint32)(tmp_int * 20); // ms
89
90 goto exit;
91exit:
92 at_response_free(response);
93 return err;
94}
95
b.liu7ca612c2025-04-25 09:23:36 +080096static int cfg_ecalldata_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_ecall_cfg_item_enum type, uint32 value, int *cme_err)
b.liueea595d2024-11-05 19:52:10 +080097{
98 ATResponse *response = NULL;
99 char cmd[100] = {0};
100 int err = 0;
101
102 snprintf(cmd, sizeof(cmd), "AT*ECALLDATA=5,%d,%d", type, value / 20);
b.liu7ca612c2025-04-25 09:23:36 +0800103 err = at_send_command(portType_2_portId(sim_id, port), cmd, &response);
b.liueea595d2024-11-05 19:52:10 +0800104 if (err < 0 || response->success == 0){
105 *cme_err = at_get_cme_error(response);
106 goto exit;
107 }
108
109 goto exit;
110exit:
111 at_response_free(response);
112 return err;
113}
114
b.liu7ca612c2025-04-25 09:23:36 +0800115static int cfg_ecalltimer_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, const char* type, uint32 value, int *cme_err)
b.liueea595d2024-11-05 19:52:10 +0800116{
117 ATResponse *response = NULL;
118 char cmd[100] = {0};
119 int err = 0;
120
121 snprintf(cmd, sizeof(cmd), "AT*ECALLTIMER=%s,%d", type, value);
b.liu7ca612c2025-04-25 09:23:36 +0800122 err = at_send_command(portType_2_portId(sim_id, port), cmd, &response);
b.liueea595d2024-11-05 19:52:10 +0800123 if (err < 0 || response->success == 0){
124 *cme_err = at_get_cme_error(response);
125 goto exit;
126 }
127
128 goto exit;
129exit:
130 at_response_free(response);
131 return err;
132}
133
b.liu7ca612c2025-04-25 09:23:36 +0800134static int req_ecall_msdcfg(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_ecall_msd_cfg_info_t *cfg_info, int *cme_err)
b.liu15f456b2024-10-31 20:16:06 +0800135{
136 ATResponse *response = NULL;
137 char cmd[1024] = {0};
138 sprintf(cmd, "AT*ECALLMSDCFG=%d,\"%s\",0", cfg_info->item_type, cfg_info->data);
b.liu7ca612c2025-04-25 09:23:36 +0800139 int err = at_send_command(portType_2_portId(sim_id, port), cmd, &response);
b.liu15f456b2024-10-31 20:16:06 +0800140 if (err < 0 || response->success == 0){
141 *cme_err = at_get_cme_error(response);
142 goto exit;
143 }
144
145exit:
146 at_response_free(response);
147 return err;
148}
149
b.liu7ca612c2025-04-25 09:23:36 +0800150static int req_ecall_msdgen(mbtk_sim_type_enum sim_id, ATPortType_enum port, int *cme_err)
b.liu15f456b2024-10-31 20:16:06 +0800151{
152 ATResponse *response = NULL;
b.liu7ca612c2025-04-25 09:23:36 +0800153 int err = at_send_command(portType_2_portId(sim_id, port), "AT*ECALLMSDGEN", &response);
b.liu15f456b2024-10-31 20:16:06 +0800154 if (err < 0 || response->success == 0){
155 *cme_err = at_get_cme_error(response);
156 goto exit;
157 }
158
159exit:
160 at_response_free(response);
161 return err;
162}
163
b.liu7ca612c2025-04-25 09:23:36 +0800164static int req_ecall_msd_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, const uint8 *msd, int *cme_err)
b.liu15f456b2024-10-31 20:16:06 +0800165{
166 ATResponse *response = NULL;
167 char cmd[1024] = {0};
168 sprintf(cmd, "AT*ECALLMSD=\"%s\"", msd);
b.liu7ca612c2025-04-25 09:23:36 +0800169 int err = at_send_command(portType_2_portId(sim_id, port), cmd, &response);
b.liu15f456b2024-10-31 20:16:06 +0800170 if (err < 0 || response->success == 0){
171 *cme_err = at_get_cme_error(response);
172 goto exit;
173 }
174
175exit:
176 at_response_free(response);
177 return err;
178}
179
b.liu7ca612c2025-04-25 09:23:36 +0800180static int req_ecall_msd_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, uint8 *msd, int *cme_err)
b.liu15f456b2024-10-31 20:16:06 +0800181{
182 ATResponse *response = NULL;
183 char *tmp_ptr = NULL;
b.liu7ca612c2025-04-25 09:23:36 +0800184 int err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT*ECALLMSD?", "*ECALLMSD:", &response);
b.liu15f456b2024-10-31 20:16:06 +0800185
186 if (err < 0 || response->success == 0 || !response->p_intermediates){
187 *cme_err = at_get_cme_error(response);
188 goto exit;
189 }
190
191 char *line = response->p_intermediates->line;
192 err = at_tok_start(&line);
193 if (err < 0)
194 {
195 goto exit;
196 }
197
198 err = at_tok_nextstr(&line, &tmp_ptr);
199 if (err < 0)
200 {
201 goto exit;
202 }
203
204 if(tmp_ptr && strlen(tmp_ptr) > 0) {
205 memcpy(msd, tmp_ptr, strlen(tmp_ptr));
206 }
207
208 goto exit;
209exit:
210 at_response_free(response);
211 return err;
212}
213
b.liu7ca612c2025-04-25 09:23:36 +0800214static int req_ecall_push(mbtk_sim_type_enum sim_id, ATPortType_enum port, int *cme_err)
b.liu15f456b2024-10-31 20:16:06 +0800215{
216 ATResponse *response = NULL;
b.liu7ca612c2025-04-25 09:23:36 +0800217 int err = at_send_command(portType_2_portId(sim_id, port), "AT*ECALLPUSH", &response);
b.liu15f456b2024-10-31 20:16:06 +0800218 if (err < 0 || response->success == 0){
219 *cme_err = at_get_cme_error(response);
220 goto exit;
221 }
222
223exit:
224 at_response_free(response);
225 return err;
226}
227
228/*
229AT*ECALLONLY?
230*ECALLONLY: 0,0,18981911691,18981911691
231
232OK
233
234*/
b.liu7ca612c2025-04-25 09:23:36 +0800235static int req_ecall_only_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_ecall_only_info_t *only_info, int *cme_err)
b.liu15f456b2024-10-31 20:16:06 +0800236{
237 ATResponse *response = NULL;
238 char *tmp_ptr = NULL;
239 int tmp_int;
b.liu7ca612c2025-04-25 09:23:36 +0800240 int err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT*ECALLONLY?", "*ECALLONLY:", &response);
b.liu15f456b2024-10-31 20:16:06 +0800241
242 if (err < 0 || response->success == 0 || !response->p_intermediates){
243 *cme_err = at_get_cme_error(response);
244 goto exit;
245 }
246
247 char *line = response->p_intermediates->line;
248 err = at_tok_start(&line);
249 if (err < 0)
250 {
251 goto exit;
252 }
253
254 err = at_tok_nextint(&line, &tmp_int);
255 if (err < 0)
256 {
257 goto exit;
258 }
259 only_info->active = (mbtk_ecall_only_type_enum)tmp_int;
260
261 err = at_tok_nextint(&line, &tmp_int);
262 if (err < 0)
263 {
264 goto exit;
265 }
266 only_info->sim_type = (mbtk_ecall_sim_type_enum)tmp_int;
267
268 err = at_tok_nextstr(&line, &tmp_ptr);
269 if (err < 0)
270 {
271 goto exit;
272 }
273
274 if(tmp_ptr && strlen(tmp_ptr) > 0) {
275 memcpy(only_info->test_num, tmp_ptr, strlen(tmp_ptr));
276 }
277
278 err = at_tok_nextstr(&line, &tmp_ptr);
279 if (err < 0)
280 {
281 goto exit;
282 }
283
284 if(tmp_ptr && strlen(tmp_ptr) > 0) {
285 memcpy(only_info->reconfig_num, tmp_ptr, strlen(tmp_ptr));
286 }
287
288 goto exit;
289exit:
290 at_response_free(response);
291 return err;
292}
293
294/*
295AT*ECALLONLY?
296*ECALLONLY: 0,0,18981911691,18981911691
297
298OK
299
300*/
b.liu7ca612c2025-04-25 09:23:36 +0800301static int req_ecall_only_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, const mbtk_ecall_only_info_t *only_info, int *cme_err)
b.liu15f456b2024-10-31 20:16:06 +0800302{
303 ATResponse *response = NULL;
304 char cmd[1024] = {0};
305 sprintf(cmd, "AT*ECALLONLY=%d,%s,%s", only_info->active,only_info->test_num,only_info->reconfig_num);
b.liu7ca612c2025-04-25 09:23:36 +0800306 int err = at_send_command(portType_2_portId(sim_id, port), cmd, &response);
b.liu15f456b2024-10-31 20:16:06 +0800307 if (err < 0 || response->success == 0){
308 *cme_err = at_get_cme_error(response);
309 goto exit;
310 }
311
312exit:
313 at_response_free(response);
314 return err;
315}
316
317/*
318AT*ECALLREG=0/1
319
320*/
b.liu7ca612c2025-04-25 09:23:36 +0800321static int req_ecall_reg_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, uint8 reg, int *cme_err)
b.liu15f456b2024-10-31 20:16:06 +0800322{
323 ATResponse *response = NULL;
324 char cmd[30] = {0};
325 sprintf(cmd, "AT*ECALLREG=%d", reg);
b.liu7ca612c2025-04-25 09:23:36 +0800326 int err = at_send_command(portType_2_portId(sim_id, port), cmd, &response);
b.liu15f456b2024-10-31 20:16:06 +0800327 if (err < 0 || response->success == 0){
328 *cme_err = at_get_cme_error(response);
329 goto exit;
330 }
331
332exit:
333 at_response_free(response);
334 return err;
335}
336
337/*
338AT+CECALL?
339+CECALL: 4
340
341OK
342
343*/
b.liu7ca612c2025-04-25 09:23:36 +0800344static int req_ecall_dial_state_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_ecall_dial_type_enum *type, int *cme_err)
b.liu15f456b2024-10-31 20:16:06 +0800345{
346 ATResponse *response = NULL;
347 int tmp_int;
b.liu7ca612c2025-04-25 09:23:36 +0800348 int err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT+CECALL?", "+CECALL:", &response);
b.liu15f456b2024-10-31 20:16:06 +0800349
350 if (err < 0 || response->success == 0 || !response->p_intermediates){
351 *cme_err = at_get_cme_error(response);
352 goto exit;
353 }
354
355 char *line = response->p_intermediates->line;
356 err = at_tok_start(&line);
357 if (err < 0)
358 {
359 goto exit;
360 }
361
362 err = at_tok_nextint(&line, &tmp_int);
363 if (err < 0)
364 {
365 goto exit;
366 }
367 *type = (mbtk_ecall_dial_type_enum)tmp_int;
368
369 goto exit;
370exit:
371 at_response_free(response);
372 return err;
373}
374
375/*
376AT+CECALL=<ecalltype>
377OK
378*/
b.liu7ca612c2025-04-25 09:23:36 +0800379static int req_ecall_dial_start(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_ecall_dial_type_enum type, int *cme_err)
b.liu15f456b2024-10-31 20:16:06 +0800380{
381 ATResponse *response = NULL;
382 char cmd[1024] = {0};
383 sprintf(cmd, "AT+CECALL=%d", type);
b.liu7ca612c2025-04-25 09:23:36 +0800384 int err = at_send_command(portType_2_portId(sim_id, port), cmd, &response);
b.liu15f456b2024-10-31 20:16:06 +0800385 if (err < 0 || response->success == 0){
386 *cme_err = at_get_cme_error(response);
387 goto exit;
388 }
389
390exit:
391 at_response_free(response);
392 return err;
393}
394
395
396/*
397AT*ECALLMODE?
398*ECALLMODE: "ERA"
399
400OK
401
402*/
b.liu7ca612c2025-04-25 09:23:36 +0800403static int req_ecall_mode_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_ecall_mode_type_enum *mode, int *cme_err)
b.liu15f456b2024-10-31 20:16:06 +0800404{
405 ATResponse *response = NULL;
406 char *tmp_ptr = NULL;
b.liu7ca612c2025-04-25 09:23:36 +0800407 int err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT*ECALLMODE?", "*ECALLMODE:", &response);
b.liu15f456b2024-10-31 20:16:06 +0800408
409 if (err < 0 || response->success == 0 || !response->p_intermediates){
410 *cme_err = at_get_cme_error(response);
411 goto exit;
412 }
413
414 char *line = response->p_intermediates->line;
415 err = at_tok_start(&line);
416 if (err < 0)
417 {
418 goto exit;
419 }
420
421 err = at_tok_nextstr(&line, &tmp_ptr);
422 if (err < 0)
423 {
424 goto exit;
425 }
426
427 if(tmp_ptr && strlen(tmp_ptr) > 0) {
428 if(strcmp(tmp_ptr, "ERA") == 0) {
429 *mode = MBTK_ECALL_MODE_TYPE_ERA;
430 } else {
431 *mode = MBTK_ECALL_MODE_TYPE_EU;
432 }
433
434 ecall_mode = *mode;
435 } else {
436 err = -1;
437 }
438
439 goto exit;
440exit:
441 at_response_free(response);
442 return err;
443}
444
445/*
446AT*ECALLMODE="ERA"
447OK
448
449*/
b.liu7ca612c2025-04-25 09:23:36 +0800450static int req_ecall_mode_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_ecall_mode_type_enum mode, int *cme_err)
b.liu15f456b2024-10-31 20:16:06 +0800451{
452 ATResponse *response = NULL;
453 char cmd[1024] = {0};
454 if(mode == MBTK_ECALL_MODE_TYPE_EU) {
455 sprintf(cmd, "AT*ECALLMODE=\"EU\"");
456 } else {
457 sprintf(cmd, "AT*ECALLMODE=\"ERA\"");
458 }
b.liu7ca612c2025-04-25 09:23:36 +0800459 int err = at_send_command(portType_2_portId(sim_id, port), cmd, &response);
b.liu15f456b2024-10-31 20:16:06 +0800460 if (err < 0 || response->success == 0){
461 *cme_err = at_get_cme_error(response);
462 goto exit;
463 }
464
465 ecall_mode = mode;
466
467exit:
468 at_response_free(response);
469 return err;
470}
471
472/*
473AT*ECALLDATA=5,2
474*ECALLDATA: 5,2,250
475
476OK
477
478AT*ECALLTIMER?
479*ECALLTIMER: ERA mode, callback timer: 1200s, dial setup timer: 30s, NAD deregister timer: 7200s, cleardown timer: 3600s, redial attempts count: 10, redial wait timer: 30s, smsprocess: 1, SMS resend timer: 3600s, sms msd send count: 10.
480
481OK
482
483*/
b.liu7ca612c2025-04-25 09:23:36 +0800484static int req_ecall_cfg_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, uint32 type, mbtk_ecall_cfg_info_t *cfg, int *cme_err)
b.liu15f456b2024-10-31 20:16:06 +0800485{
486 ATResponse *response = NULL;
487 char *tmp_ptr = NULL;
b.liu62240ee2024-11-07 17:52:45 +0800488// int tmp_int;
b.liu15f456b2024-10-31 20:16:06 +0800489 int err = 0;
490
491 cfg->type = type;
b.liu15f456b2024-10-31 20:16:06 +0800492
b.liueea595d2024-11-05 19:52:10 +0800493 if(type & MBTK_ECALL_CFG_T3) {
b.liu7ca612c2025-04-25 09:23:36 +0800494 if(cfg_ecalldata_get(sim_id, port, MBTK_ECALL_CFG_ITEM_T3, &(cfg->data[MBTK_ECALL_CFG_ITEM_T3]), cme_err)
b.liueea595d2024-11-05 19:52:10 +0800495 || *cme_err != MBTK_RIL_ERR_CME_NON)
496 {
497 goto exit;
498 }
b.liu9d0a70f2024-11-06 11:26:17 +0800499 cfg->data_valid[MBTK_ECALL_CFG_ITEM_T3] = (uint8)1;
b.liu15f456b2024-10-31 20:16:06 +0800500 }
501
b.liueea595d2024-11-05 19:52:10 +0800502 if(type & MBTK_ECALL_CFG_T5) {
b.liu7ca612c2025-04-25 09:23:36 +0800503 if(cfg_ecalldata_get(sim_id, port, MBTK_ECALL_CFG_ITEM_T5, &(cfg->data[MBTK_ECALL_CFG_ITEM_T5]), cme_err)
b.liueea595d2024-11-05 19:52:10 +0800504 || *cme_err != MBTK_RIL_ERR_CME_NON)
505 {
506 goto exit;
507 }
b.liu9d0a70f2024-11-06 11:26:17 +0800508 cfg->data_valid[MBTK_ECALL_CFG_ITEM_T5] = (uint8)1;
b.liu15f456b2024-10-31 20:16:06 +0800509 }
510
b.liueea595d2024-11-05 19:52:10 +0800511 if(type & MBTK_ECALL_CFG_T6) {
b.liu7ca612c2025-04-25 09:23:36 +0800512 if(cfg_ecalldata_get(sim_id, port, MBTK_ECALL_CFG_ITEM_T6, &(cfg->data[MBTK_ECALL_CFG_ITEM_T6]), cme_err)
b.liueea595d2024-11-05 19:52:10 +0800513 || *cme_err != MBTK_RIL_ERR_CME_NON)
514 {
515 goto exit;
516 }
b.liu9d0a70f2024-11-06 11:26:17 +0800517 cfg->data_valid[MBTK_ECALL_CFG_ITEM_T6] = (uint8)1;
b.liu15f456b2024-10-31 20:16:06 +0800518 }
519
b.liueea595d2024-11-05 19:52:10 +0800520 if(type & MBTK_ECALL_CFG_T7) {
b.liu7ca612c2025-04-25 09:23:36 +0800521 if(cfg_ecalldata_get(sim_id, port, MBTK_ECALL_CFG_ITEM_T7, &(cfg->data[MBTK_ECALL_CFG_ITEM_T7]), cme_err)
b.liueea595d2024-11-05 19:52:10 +0800522 || *cme_err != MBTK_RIL_ERR_CME_NON)
523 {
524 goto exit;
525 }
b.liu9d0a70f2024-11-06 11:26:17 +0800526 cfg->data_valid[MBTK_ECALL_CFG_ITEM_T7] = (uint8)1;
b.liueea595d2024-11-05 19:52:10 +0800527 }
528
529 if(type & MBTK_ECALL_CFG_TH) {
b.liu7ca612c2025-04-25 09:23:36 +0800530 if(cfg_ecalldata_get(sim_id, port, MBTK_ECALL_CFG_ITEM_TH, &(cfg->data[MBTK_ECALL_CFG_ITEM_TH]), cme_err)
b.liueea595d2024-11-05 19:52:10 +0800531 || *cme_err != MBTK_RIL_ERR_CME_NON)
532 {
533 goto exit;
534 }
b.liu9d0a70f2024-11-06 11:26:17 +0800535 cfg->data_valid[MBTK_ECALL_CFG_ITEM_TH] = (uint8)1;
b.liueea595d2024-11-05 19:52:10 +0800536 }
537
538 if(type & (MBTK_ECALL_CFG_TIMER_CALLBACK | MBTK_ECALL_CFG_TIMER_CLEARDOWN | MBTK_ECALL_CFG_TIMER_DEREG
539 | MBTK_ECALL_CFG_TIMER_DIAL | MBTK_ECALL_CFG_TIMER_REDIAL | MBTK_ECALL_CFG_TIMER_SMS
540 | MBTK_ECALL_CFG_REDIALCNT | MBTK_ECALL_CFG_SMSPROCESS | MBTK_ECALL_CFG_SMSMSDCNT)) {
b.liu7ca612c2025-04-25 09:23:36 +0800541 err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT*ECALLTIMER?", "*ECALLTIMER:", &response);
b.liueea595d2024-11-05 19:52:10 +0800542 if (err < 0 || response->success == 0 || !response->p_intermediates){
543 *cme_err = at_get_cme_error(response);
544 goto exit;
545 }
546
547 char *line = response->p_intermediates->line;
548 err = at_tok_start(&line);
b.liu15f456b2024-10-31 20:16:06 +0800549 if (err < 0)
550 {
551 goto exit;
552 }
553
b.liu15f456b2024-10-31 20:16:06 +0800554 // *ECALLTIMER: ERA mode, callback timer: 1200s,
555 // dial setup timer: 30s, NAD deregister timer: 7200s,
556 // cleardown timer: 3600s, redial attempts count: 10,
557 // redial wait timer: 30s, smsprocess: 1, SMS resend timer: 3600s,
558 // sms msd send count: 10.
559
560 if(strstr(line, "ERA mode") != NULL) {
561 ecall_mode = MBTK_ECALL_MODE_TYPE_ERA;
562 } else {
563 ecall_mode = MBTK_ECALL_MODE_TYPE_EU;
564 }
565
b.liueea595d2024-11-05 19:52:10 +0800566 if(type & MBTK_ECALL_CFG_TIMER_CALLBACK)
b.liu15f456b2024-10-31 20:16:06 +0800567 {
b.liueea595d2024-11-05 19:52:10 +0800568 if((tmp_ptr = strstr(line, "callback timer: ")) != NULL) {
569 cfg->data[MBTK_ECALL_CFG_ITEM_TIMER_CALLBACK] = (uint32)atoi(tmp_ptr + 16); // s
570 cfg->data[MBTK_ECALL_CFG_ITEM_TIMER_CALLBACK] *= 1000; // s -> ms
b.liu9d0a70f2024-11-06 11:26:17 +0800571 cfg->data_valid[MBTK_ECALL_CFG_ITEM_TIMER_CALLBACK] = (uint8)1;
b.liu15f456b2024-10-31 20:16:06 +0800572 }
b.liueea595d2024-11-05 19:52:10 +0800573 }
574
575 if(type & MBTK_ECALL_CFG_TIMER_CLEARDOWN)
576 {
577 if((tmp_ptr = strstr(line, "cleardown timer: ")) != NULL) {
578 cfg->data[MBTK_ECALL_CFG_ITEM_TIMER_CLEARDOWN] = (uint32)atoi(tmp_ptr + 17); // s
579 cfg->data[MBTK_ECALL_CFG_ITEM_TIMER_CLEARDOWN] *= 1000; // s -> ms
b.liu9d0a70f2024-11-06 11:26:17 +0800580 cfg->data_valid[MBTK_ECALL_CFG_ITEM_TIMER_CLEARDOWN] = (uint8)1;
b.liu15f456b2024-10-31 20:16:06 +0800581 }
b.liueea595d2024-11-05 19:52:10 +0800582 }
583
584 if(type & MBTK_ECALL_CFG_TIMER_DEREG)
585 {
586 if((tmp_ptr = strstr(line, "deregister timer: ")) != NULL) {
587 cfg->data[MBTK_ECALL_CFG_ITEM_TIMER_DEREG] = (uint32)atoi(tmp_ptr + 18); // s
588 cfg->data[MBTK_ECALL_CFG_ITEM_TIMER_DEREG] *= 1000; // s -> ms
b.liu9d0a70f2024-11-06 11:26:17 +0800589 cfg->data_valid[MBTK_ECALL_CFG_ITEM_TIMER_DEREG] = (uint8)1;
b.liu15f456b2024-10-31 20:16:06 +0800590 }
b.liueea595d2024-11-05 19:52:10 +0800591 }
592
593 if(type & MBTK_ECALL_CFG_TIMER_DIAL)
594 {
595 if((tmp_ptr = strstr(line, "dial setup timer: ")) != NULL) {
596 cfg->data[MBTK_ECALL_CFG_ITEM_TIMER_DIAL] = (uint32)atoi(tmp_ptr + 18); // s
597 cfg->data[MBTK_ECALL_CFG_ITEM_TIMER_DIAL] *= 1000; // s -> ms
b.liu9d0a70f2024-11-06 11:26:17 +0800598 cfg->data_valid[MBTK_ECALL_CFG_ITEM_TIMER_DIAL] = (uint8)1;
b.liu15f456b2024-10-31 20:16:06 +0800599 }
b.liueea595d2024-11-05 19:52:10 +0800600 }
601
602 if(type & MBTK_ECALL_CFG_TIMER_REDIAL)
603 {
604 if((tmp_ptr = strstr(line, "redial wait timer: ")) != NULL) {
605 cfg->data[MBTK_ECALL_CFG_ITEM_TIMER_REDIAL] = (uint32)atoi(tmp_ptr + 19); // s
606 cfg->data[MBTK_ECALL_CFG_ITEM_TIMER_REDIAL] *= 1000; // s -> ms
b.liu9d0a70f2024-11-06 11:26:17 +0800607 cfg->data_valid[MBTK_ECALL_CFG_ITEM_TIMER_REDIAL] = (uint8)1;
b.liu15f456b2024-10-31 20:16:06 +0800608 }
b.liueea595d2024-11-05 19:52:10 +0800609 }
610
611 if(type & MBTK_ECALL_CFG_TIMER_SMS)
612 {
613 if((tmp_ptr = strstr(line, "SMS resend timer: ")) != NULL) {
614 cfg->data[MBTK_ECALL_CFG_ITEM_TIMER_SMS] = (uint32)atoi(tmp_ptr + 18);
615 cfg->data[MBTK_ECALL_CFG_ITEM_TIMER_SMS] *= 1000; // s -> ms
b.liu9d0a70f2024-11-06 11:26:17 +0800616 cfg->data_valid[MBTK_ECALL_CFG_ITEM_TIMER_SMS] = (uint8)1;
b.liu15f456b2024-10-31 20:16:06 +0800617 }
b.liueea595d2024-11-05 19:52:10 +0800618 }
619
620 if(type & MBTK_ECALL_CFG_REDIALCNT)
621 {
622 if((tmp_ptr = strstr(line, "redial attempts count: ")) != NULL) {
623 cfg->data[MBTK_ECALL_CFG_ITEM_REDIALCNT] = (uint32)atoi(tmp_ptr + 23);
b.liu9d0a70f2024-11-06 11:26:17 +0800624 cfg->data_valid[MBTK_ECALL_CFG_ITEM_REDIALCNT] = (uint8)1;
b.liu15f456b2024-10-31 20:16:06 +0800625 }
b.liueea595d2024-11-05 19:52:10 +0800626 }
627
628 if(type & MBTK_ECALL_CFG_SMSPROCESS)
629 {
630 if((tmp_ptr = strstr(line, "smsprocess: ")) != NULL) {
631 cfg->data[MBTK_ECALL_CFG_ITEM_SMSPROCESS] = (uint32)atoi(tmp_ptr + 12);
b.liu9d0a70f2024-11-06 11:26:17 +0800632 cfg->data_valid[MBTK_ECALL_CFG_ITEM_SMSPROCESS] = (uint8)1;
b.liu15f456b2024-10-31 20:16:06 +0800633 }
b.liueea595d2024-11-05 19:52:10 +0800634 }
635
636 if(type & MBTK_ECALL_CFG_SMSMSDCNT)
637 {
638 if((tmp_ptr = strstr(line, "sms msd send count: ")) != NULL) {
639 cfg->data[MBTK_ECALL_CFG_ITEM_SMSMSDCNT] = (uint32)atoi(tmp_ptr + 20);
b.liu9d0a70f2024-11-06 11:26:17 +0800640 cfg->data_valid[MBTK_ECALL_CFG_ITEM_SMSMSDCNT] = (uint8)1;
b.liu15f456b2024-10-31 20:16:06 +0800641 }
b.liu15f456b2024-10-31 20:16:06 +0800642 }
643 }
644
645 goto exit;
646exit:
647 at_response_free(response);
648 return err;
649}
650
651/*
652AT*ECALLDATA=5,2,250
653OK
654
655AT*ECALLTIMER=dereg,300
656OK
657*/
b.liu7ca612c2025-04-25 09:23:36 +0800658static int req_ecall_cfg_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, const mbtk_ecall_cfg_info_t *cfg_info, int *cme_err)
b.liu15f456b2024-10-31 20:16:06 +0800659{
b.liu15f456b2024-10-31 20:16:06 +0800660 int err = 0;
b.liu15f456b2024-10-31 20:16:06 +0800661 if(ecall_mode == MBTK_ECALL_MODE_TYPE_EU) {
b.liueea595d2024-11-05 19:52:10 +0800662 if((cfg_info->type & MBTK_ECALL_CFG_TIMER_REDIAL)
663 || (cfg_info->type & MBTK_ECALL_CFG_TIMER_SMS)
664 || (cfg_info->type & MBTK_ECALL_CFG_REDIALCNT)
665 || (cfg_info->type & MBTK_ECALL_CFG_SMSPROCESS)
666 || (cfg_info->type & MBTK_ECALL_CFG_SMSMSDCNT)){
b.liu15f456b2024-10-31 20:16:06 +0800667 LOGW("No support for EU.");
668 return -1;
669 }
670 }
671
b.liueea595d2024-11-05 19:52:10 +0800672 if(cfg_info->type & MBTK_ECALL_CFG_T3) {
b.liu7ca612c2025-04-25 09:23:36 +0800673 if(cfg_ecalldata_set(sim_id, port, MBTK_ECALL_CFG_ITEM_T3, cfg_info->data[MBTK_ECALL_CFG_ITEM_T3], cme_err)
b.liueea595d2024-11-05 19:52:10 +0800674 || *cme_err != MBTK_RIL_ERR_CME_NON)
b.liu15f456b2024-10-31 20:16:06 +0800675 {
b.liu15f456b2024-10-31 20:16:06 +0800676 goto exit;
b.liueea595d2024-11-05 19:52:10 +0800677 }
b.liu15f456b2024-10-31 20:16:06 +0800678 }
679
b.liueea595d2024-11-05 19:52:10 +0800680 if(cfg_info->type & MBTK_ECALL_CFG_T5) {
b.liu7ca612c2025-04-25 09:23:36 +0800681 if(cfg_ecalldata_set(sim_id, port, MBTK_ECALL_CFG_ITEM_T5, cfg_info->data[MBTK_ECALL_CFG_ITEM_T5], cme_err)
b.liueea595d2024-11-05 19:52:10 +0800682 || *cme_err != MBTK_RIL_ERR_CME_NON)
683 {
684 goto exit;
685 }
686 }
687
688 if(cfg_info->type & MBTK_ECALL_CFG_T6) {
b.liu7ca612c2025-04-25 09:23:36 +0800689 if(cfg_ecalldata_set(sim_id, port, MBTK_ECALL_CFG_ITEM_T6, cfg_info->data[MBTK_ECALL_CFG_ITEM_T6], cme_err)
b.liueea595d2024-11-05 19:52:10 +0800690 || *cme_err != MBTK_RIL_ERR_CME_NON)
691 {
692 goto exit;
693 }
694 }
695
696 if(cfg_info->type & MBTK_ECALL_CFG_T7) {
b.liu7ca612c2025-04-25 09:23:36 +0800697 if(cfg_ecalldata_set(sim_id, port, MBTK_ECALL_CFG_ITEM_T7, cfg_info->data[MBTK_ECALL_CFG_ITEM_T7], cme_err)
b.liueea595d2024-11-05 19:52:10 +0800698 || *cme_err != MBTK_RIL_ERR_CME_NON)
699 {
700 goto exit;
701 }
702 }
703
704 if(cfg_info->type & MBTK_ECALL_CFG_TH) {
b.liu7ca612c2025-04-25 09:23:36 +0800705 if(cfg_ecalldata_set(sim_id, port, MBTK_ECALL_CFG_ITEM_TH, cfg_info->data[MBTK_ECALL_CFG_ITEM_TH], cme_err)
b.liueea595d2024-11-05 19:52:10 +0800706 || *cme_err != MBTK_RIL_ERR_CME_NON)
707 {
708 goto exit;
709 }
710 }
711
712 if(cfg_info->type & MBTK_ECALL_CFG_TIMER_CALLBACK)
713 {
b.liu7ca612c2025-04-25 09:23:36 +0800714 if(cfg_ecalltimer_set(sim_id, port, "callback", cfg_info->data[MBTK_ECALL_CFG_ITEM_TIMER_CALLBACK] / 1000, cme_err)
b.liueea595d2024-11-05 19:52:10 +0800715 || *cme_err != MBTK_RIL_ERR_CME_NON) {
716 goto exit;
717 }
718 }
719 if(cfg_info->type & MBTK_ECALL_CFG_TIMER_CLEARDOWN)
720 {
b.liu7ca612c2025-04-25 09:23:36 +0800721 if(cfg_ecalltimer_set(sim_id, port, "cleardown", cfg_info->data[MBTK_ECALL_CFG_ITEM_TIMER_CLEARDOWN] / 1000, cme_err)
b.liueea595d2024-11-05 19:52:10 +0800722 || *cme_err != MBTK_RIL_ERR_CME_NON) {
723 goto exit;
724 }
725 }
b.liu942ef782025-02-07 13:24:30 +0800726
727 if(cfg_info->type & MBTK_ECALL_CFG_TIMER_DEREG)
b.liueea595d2024-11-05 19:52:10 +0800728 {
b.liu7ca612c2025-04-25 09:23:36 +0800729 if(cfg_ecalltimer_set(sim_id, port, "dereg", cfg_info->data[MBTK_ECALL_CFG_ITEM_TIMER_DEREG] / 1000, cme_err)
b.liueea595d2024-11-05 19:52:10 +0800730 || *cme_err != MBTK_RIL_ERR_CME_NON) {
731 goto exit;
732 }
733 }
b.liu942ef782025-02-07 13:24:30 +0800734 if(cfg_info->type & MBTK_ECALL_CFG_TIMER_DIAL)
b.liueea595d2024-11-05 19:52:10 +0800735 {
b.liu7ca612c2025-04-25 09:23:36 +0800736 if(cfg_ecalltimer_set(sim_id, port, "dial", cfg_info->data[MBTK_ECALL_CFG_ITEM_TIMER_DIAL] / 1000, cme_err)
b.liueea595d2024-11-05 19:52:10 +0800737 || *cme_err != MBTK_RIL_ERR_CME_NON) {
738 goto exit;
739 }
740 }
b.liu942ef782025-02-07 13:24:30 +0800741 if(cfg_info->type & MBTK_ECALL_CFG_TIMER_REDIAL)
b.liueea595d2024-11-05 19:52:10 +0800742 {
b.liu7ca612c2025-04-25 09:23:36 +0800743 if(cfg_ecalltimer_set(sim_id, port, "redialtmr", cfg_info->data[MBTK_ECALL_CFG_ITEM_TIMER_REDIAL] / 1000, cme_err)
b.liueea595d2024-11-05 19:52:10 +0800744 || *cme_err != MBTK_RIL_ERR_CME_NON) {
745 goto exit;
746 }
747 }
b.liu942ef782025-02-07 13:24:30 +0800748 if(cfg_info->type & MBTK_ECALL_CFG_TIMER_SMS)
b.liueea595d2024-11-05 19:52:10 +0800749 {
b.liu7ca612c2025-04-25 09:23:36 +0800750 if(cfg_ecalltimer_set(sim_id, port, "sms", cfg_info->data[MBTK_ECALL_CFG_ITEM_TIMER_SMS] / 1000, cme_err)
b.liueea595d2024-11-05 19:52:10 +0800751 || *cme_err != MBTK_RIL_ERR_CME_NON) {
752 goto exit;
753 }
754 }
b.liu942ef782025-02-07 13:24:30 +0800755 if(cfg_info->type & MBTK_ECALL_CFG_REDIALCNT)
b.liueea595d2024-11-05 19:52:10 +0800756 {
b.liu7ca612c2025-04-25 09:23:36 +0800757 if(cfg_ecalltimer_set(sim_id, port, "redialcnt", cfg_info->data[MBTK_ECALL_CFG_ITEM_REDIALCNT], cme_err)
b.liueea595d2024-11-05 19:52:10 +0800758 || *cme_err != MBTK_RIL_ERR_CME_NON) {
759 goto exit;
760 }
761 }
b.liu942ef782025-02-07 13:24:30 +0800762 if(cfg_info->type & MBTK_ECALL_CFG_SMSPROCESS)
b.liueea595d2024-11-05 19:52:10 +0800763 {
b.liu7ca612c2025-04-25 09:23:36 +0800764 if(cfg_ecalltimer_set(sim_id, port, "smsprocess", cfg_info->data[MBTK_ECALL_CFG_ITEM_SMSPROCESS], cme_err)
b.liueea595d2024-11-05 19:52:10 +0800765 || *cme_err != MBTK_RIL_ERR_CME_NON) {
766 goto exit;
767 }
768 }
b.liu942ef782025-02-07 13:24:30 +0800769 if(cfg_info->type & MBTK_ECALL_CFG_SMSMSDCNT)
b.liueea595d2024-11-05 19:52:10 +0800770 {
b.liu7ca612c2025-04-25 09:23:36 +0800771 if(cfg_ecalltimer_set(sim_id, port, "smsmsdcnt", cfg_info->data[MBTK_ECALL_CFG_ITEM_SMSMSDCNT], cme_err)
b.liueea595d2024-11-05 19:52:10 +0800772 || *cme_err != MBTK_RIL_ERR_CME_NON) {
773 goto exit;
774 }
b.liu15f456b2024-10-31 20:16:06 +0800775 }
776
777exit:
b.liu15f456b2024-10-31 20:16:06 +0800778 return err;
779}
780
781/*
782AT*ECALLMUTESPK=1
783OK
784
785*/
b.liu7ca612c2025-04-25 09:23:36 +0800786static int req_ecall_spkmute_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, int mute, int *cme_err)
b.liu15f456b2024-10-31 20:16:06 +0800787{
788 ATResponse *response = NULL;
789 char cmd[100] = {0};
790 sprintf(cmd, "AT*ECALLMUTESPK=%d", mute);
b.liu7ca612c2025-04-25 09:23:36 +0800791 int err = at_send_command(portType_2_portId(sim_id, port), cmd, &response);
b.liu15f456b2024-10-31 20:16:06 +0800792 if (err < 0 || response->success == 0){
793 *cme_err = at_get_cme_error(response);
794 goto exit;
795 }
796
797exit:
798 at_response_free(response);
799 return err;
800}
801
802
803/*
804AT*ECALLSMSNUM?
805*ECALLSMSNUM: "18981991452"
806
807OK
808
809*/
b.liu7ca612c2025-04-25 09:23:36 +0800810static int req_ecall_sms_num_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, uint8 *number, int *cme_err)
b.liu15f456b2024-10-31 20:16:06 +0800811{
812 ATResponse *response = NULL;
813 char *tmp_ptr = NULL;
b.liu7ca612c2025-04-25 09:23:36 +0800814 int err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT*ECALLSMSNUM?", "*ECALLSMSNUM:", &response);
b.liu15f456b2024-10-31 20:16:06 +0800815
816 if (err < 0 || response->success == 0 || !response->p_intermediates){
817 *cme_err = at_get_cme_error(response);
818 goto exit;
819 }
820
821 char *line = response->p_intermediates->line;
822 err = at_tok_start(&line);
823 if (err < 0)
824 {
825 goto exit;
826 }
827
828 err = at_tok_nextstr(&line, &tmp_ptr);
829 if (err < 0)
830 {
831 goto exit;
832 }
833
834 if(tmp_ptr && strlen(tmp_ptr) > 0) {
835 memcpy(number, tmp_ptr, strlen(tmp_ptr));
836 }
837
838 goto exit;
839exit:
840 at_response_free(response);
841 return err;
842}
843
844/*
845AT*ECALLSMSNUM=18981991452
846OK
847
848*/
b.liu7ca612c2025-04-25 09:23:36 +0800849static int req_ecall_sms_num_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, const uint8 *number, int *cme_err)
b.liu15f456b2024-10-31 20:16:06 +0800850{
851 ATResponse *response = NULL;
852 char cmd[100] = {0};
853 sprintf(cmd, "AT*ECALLSMSNUM=%s", number);
b.liu7ca612c2025-04-25 09:23:36 +0800854 int err = at_send_command(portType_2_portId(sim_id, port), cmd, &response);
b.liu15f456b2024-10-31 20:16:06 +0800855 if (err < 0 || response->success == 0){
856 *cme_err = at_get_cme_error(response);
857 goto exit;
858 }
859
860exit:
861 at_response_free(response);
862 return err;
863}
864
865/*
866AT*AUDGAIN=8,1 // Set Rx voice gain = 8dB
867OK
868
869*/
b.liu7ca612c2025-04-25 09:23:36 +0800870static int req_ecall_gain_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_ecall_gain_info_t *gain, int *cme_err)
b.liu15f456b2024-10-31 20:16:06 +0800871{
872 ATResponse *response = NULL;
873 char cmd[100] = {0};
874 sprintf(cmd, "AT*AUDGAIN=%d,%d", gain->gain, gain->mode);
b.liu7ca612c2025-04-25 09:23:36 +0800875 int err = at_send_command(portType_2_portId(sim_id, port), cmd, &response);
b.liu15f456b2024-10-31 20:16:06 +0800876 if (err < 0 || response->success == 0){
877 *cme_err = at_get_cme_error(response);
878 goto exit;
879 }
880
881exit:
882 at_response_free(response);
883 return err;
884}
885
886//void net_list_free(void *data);
887// Return MBTK_INFO_ERR_SUCCESS,will call pack_error_send() to send RSP.
888// Otherwise, do not call pack_error_send().
889mbtk_ril_err_enum ecall_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack)
890{
891 mbtk_ril_err_enum err = MBTK_RIL_ERR_SUCCESS;
892 int cme_err = MBTK_RIL_ERR_CME_NON;
893 switch(pack->msg_id)
894 {
895 case RIL_MSG_ID_ECALL_MSDCFG: // mbtk_ecall_msd_cfg_info_t
896 {
897 if(pack->data_len == 0 || pack->data == NULL)
898 {
899 err = MBTK_RIL_ERR_UNSUPPORTED;
900 }
901 else // Set
902 {
903 mbtk_ecall_msd_cfg_info_t *cfg_info = (mbtk_ecall_msd_cfg_info_t*)(pack->data);
b.liu7ca612c2025-04-25 09:23:36 +0800904 if(req_ecall_msdcfg(cli_info->sim_id, cli_info->port, cfg_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu15f456b2024-10-31 20:16:06 +0800905 {
906 if(cme_err != MBTK_RIL_ERR_CME_NON) {
907 err = MBTK_RIL_ERR_CME + cme_err;
908 } else {
909 err = MBTK_RIL_ERR_UNKNOWN;
910 }
911 LOG("AT*ECALLMSDCFG fail.");
912 }
913 else
914 {
b.liu7ca612c2025-04-25 09:23:36 +0800915 ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
b.liu15f456b2024-10-31 20:16:06 +0800916 }
917 }
918 break;
919 }
920 case RIL_MSG_ID_ECALL_MSDGEN:
921 {
922 if(pack->data_len == 0 || pack->data == NULL)
923 {
b.liu7ca612c2025-04-25 09:23:36 +0800924 if(req_ecall_msdgen(cli_info->sim_id, cli_info->port, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu15f456b2024-10-31 20:16:06 +0800925 {
926 if(cme_err != MBTK_RIL_ERR_CME_NON) {
927 err = MBTK_RIL_ERR_CME + cme_err;
928 } else {
929 err = MBTK_RIL_ERR_UNKNOWN;
930 }
931 LOG("AT*ECALLMSDGEN fail.");
932 }
933 else
934 {
b.liu7ca612c2025-04-25 09:23:36 +0800935 ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
b.liu15f456b2024-10-31 20:16:06 +0800936 }
937 }
938 else // Set
939 {
940 err = MBTK_RIL_ERR_UNSUPPORTED;
941 }
942 break;
943 }
944 case RIL_MSG_ID_ECALL_MSD: // uint8[]
945 {
946 uint8 msd[MBTK_ECALL_MSD_LEN_MAX];
947 memset(msd, 0, sizeof(msd));
948 if(pack->data_len == 0 || pack->data == NULL)
949 {
b.liu7ca612c2025-04-25 09:23:36 +0800950 if(req_ecall_msd_get(cli_info->sim_id, cli_info->port, msd, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu15f456b2024-10-31 20:16:06 +0800951 {
952 if(cme_err != MBTK_RIL_ERR_CME_NON) {
953 err = MBTK_RIL_ERR_CME + cme_err;
954 } else {
955 err = MBTK_RIL_ERR_UNKNOWN;
956 }
957 LOG("Get MSD fail.");
958 }
959 else
960 {
b.liu7ca612c2025-04-25 09:23:36 +0800961 ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, msd, strlen((char*)msd));
b.liu15f456b2024-10-31 20:16:06 +0800962 }
963 }
964 else // Set
965 {
966 memcpy(msd, pack->data, pack->data_len);
b.liu7ca612c2025-04-25 09:23:36 +0800967 if(req_ecall_msd_set(cli_info->sim_id, cli_info->port, msd, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu15f456b2024-10-31 20:16:06 +0800968 {
969 if(cme_err != MBTK_RIL_ERR_CME_NON) {
970 err = MBTK_RIL_ERR_CME + cme_err;
971 } else {
972 err = MBTK_RIL_ERR_UNKNOWN;
973 }
974 LOG("AT*ECALLMSD fail.");
975 }
976 else
977 {
b.liu7ca612c2025-04-25 09:23:36 +0800978 ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
b.liu15f456b2024-10-31 20:16:06 +0800979 }
980 }
981 break;
982 }
983 case RIL_MSG_ID_ECALL_PUSH:
984 {
985 if(pack->data_len == 0 || pack->data == NULL)
986 {
b.liu7ca612c2025-04-25 09:23:36 +0800987 if(req_ecall_push(cli_info->sim_id, cli_info->port, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu15f456b2024-10-31 20:16:06 +0800988 {
989 if(cme_err != MBTK_RIL_ERR_CME_NON) {
990 err = MBTK_RIL_ERR_CME + cme_err;
991 } else {
992 err = MBTK_RIL_ERR_UNKNOWN;
993 }
994 LOG("AT*ECALLPUSH fail.");
995 }
996 else
997 {
b.liu7ca612c2025-04-25 09:23:36 +0800998 ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
b.liu15f456b2024-10-31 20:16:06 +0800999 }
1000 }
1001 else // Set
1002 {
1003 err = MBTK_RIL_ERR_UNSUPPORTED;
1004 }
1005 break;
1006 }
1007 case RIL_MSG_ID_ECALL_ONLY: // mbtk_ecall_only_info_t
1008 {
1009 if(pack->data_len == 0 || pack->data == NULL)
1010 {
1011 mbtk_ecall_only_info_t only_info;
1012 memset(&only_info, 0, sizeof(mbtk_ecall_only_info_t));
b.liu7ca612c2025-04-25 09:23:36 +08001013 if(req_ecall_only_get(cli_info->sim_id, cli_info->port, &only_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu15f456b2024-10-31 20:16:06 +08001014 {
1015 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1016 err = MBTK_RIL_ERR_CME + cme_err;
1017 } else {
1018 err = MBTK_RIL_ERR_UNKNOWN;
1019 }
1020 LOG("Get ecall only mode fail.");
1021 }
1022 else
1023 {
b.liu7ca612c2025-04-25 09:23:36 +08001024 ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &only_info, sizeof(mbtk_ecall_only_info_t));
b.liu15f456b2024-10-31 20:16:06 +08001025 }
1026 }
1027 else // Set
1028 {
1029 mbtk_ecall_only_info_t *only_info = (mbtk_ecall_only_info_t*)(pack->data);
b.liu7ca612c2025-04-25 09:23:36 +08001030 if(req_ecall_only_set(cli_info->sim_id, cli_info->port, only_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu15f456b2024-10-31 20:16:06 +08001031 {
1032 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1033 err = MBTK_RIL_ERR_CME + cme_err;
1034 } else {
1035 err = MBTK_RIL_ERR_UNKNOWN;
1036 }
1037 LOG("AT*ECALLONLY fail.");
1038 }
1039 else
1040 {
b.liu7ca612c2025-04-25 09:23:36 +08001041 ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
b.liu15f456b2024-10-31 20:16:06 +08001042 }
1043 }
1044 break;
1045 }
1046 case RIL_MSG_ID_ECALL_REG: // reg <uint8>
1047 {
1048 if(pack->data_len == 0 || pack->data == NULL)
1049 {
1050 err = MBTK_RIL_ERR_UNSUPPORTED;
1051 }
1052 else
1053 {
1054 uint8 reg = pack->data[0];
b.liu7ca612c2025-04-25 09:23:36 +08001055 if(req_ecall_reg_set(cli_info->sim_id, cli_info->port, reg, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu15f456b2024-10-31 20:16:06 +08001056 {
1057 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1058 err = MBTK_RIL_ERR_CME + cme_err;
1059 } else {
1060 err = MBTK_RIL_ERR_UNKNOWN;
1061 }
1062 LOG("ecall reg(%d) fail.", reg);
1063 }
1064 else
1065 {
b.liu7ca612c2025-04-25 09:23:36 +08001066 ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
b.liu15f456b2024-10-31 20:16:06 +08001067 }
1068 }
1069 break;
1070 }
1071 case RIL_MSG_ID_ECALL_DIAL: // mbtk_ecall_dial_type_enum
1072 {
1073 if(pack->data_len == 0 || pack->data == NULL)
1074 {
1075 mbtk_ecall_dial_type_enum type;
b.liu7ca612c2025-04-25 09:23:36 +08001076 if(req_ecall_dial_state_get(cli_info->sim_id, cli_info->port, &type, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu15f456b2024-10-31 20:16:06 +08001077 {
1078 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1079 err = MBTK_RIL_ERR_CME + cme_err;
1080 } else {
1081 err = MBTK_RIL_ERR_UNKNOWN;
1082 }
1083 LOG("Get ecall type fail.");
1084 }
1085 else
1086 {
b.liu7ca612c2025-04-25 09:23:36 +08001087 ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &type, sizeof(uint8));
b.liu15f456b2024-10-31 20:16:06 +08001088 }
1089 }
1090 else
1091 {
1092 mbtk_ecall_dial_type_enum type = (mbtk_ecall_dial_type_enum)pack->data[0];
b.liu7ca612c2025-04-25 09:23:36 +08001093 if(req_ecall_dial_start(cli_info->sim_id, cli_info->port, type, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu15f456b2024-10-31 20:16:06 +08001094 {
1095 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1096 err = MBTK_RIL_ERR_CME + cme_err;
1097 } else {
1098 err = MBTK_RIL_ERR_UNKNOWN;
1099 }
1100 LOG("Start ecall %d fail.", type);
1101 }
1102 else
1103 {
b.liu7ca612c2025-04-25 09:23:36 +08001104 ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
b.liu15f456b2024-10-31 20:16:06 +08001105 }
1106 }
1107 break;
1108 }
1109 case RIL_MSG_ID_ECALL_MODE: // mbtk_ecall_cfg_item_enum / mbtk_ecall_cfg_info_t
1110 {
1111 if(pack->data_len == 0 || pack->data == NULL)
1112 {
1113 mbtk_ecall_mode_type_enum mode;
b.liu7ca612c2025-04-25 09:23:36 +08001114 if(req_ecall_mode_get(cli_info->sim_id, cli_info->port, &mode, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu15f456b2024-10-31 20:16:06 +08001115 {
1116 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1117 err = MBTK_RIL_ERR_CME + cme_err;
1118 } else {
1119 err = MBTK_RIL_ERR_UNKNOWN;
1120 }
1121 LOG("Get ecall mode fail.");
1122 }
1123 else
1124 {
b.liu7ca612c2025-04-25 09:23:36 +08001125 ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &mode, sizeof(uint8));
b.liu15f456b2024-10-31 20:16:06 +08001126 }
1127 }
1128 else
1129 {
1130 mbtk_ecall_mode_type_enum mode = (mbtk_ecall_mode_type_enum)pack->data[0];
b.liu7ca612c2025-04-25 09:23:36 +08001131 if(req_ecall_mode_set(cli_info->sim_id, cli_info->port, mode, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu15f456b2024-10-31 20:16:06 +08001132 {
1133 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1134 err = MBTK_RIL_ERR_CME + cme_err;
1135 } else {
1136 err = MBTK_RIL_ERR_UNKNOWN;
1137 }
1138 LOG("Set ecall mode %d fail.", mode);
1139 }
1140 else
1141 {
b.liu7ca612c2025-04-25 09:23:36 +08001142 ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
b.liu15f456b2024-10-31 20:16:06 +08001143 }
1144 }
1145 break;
1146 }
1147 case RIL_MSG_ID_ECALL_CFG: // mbtk_ecall_cfg_item_enum / mbtk_ecall_cfg_info_t
1148 {
1149 if(pack->data_len == 0 || pack->data == NULL)
1150 {
1151 err = MBTK_RIL_ERR_UNSUPPORTED;
1152 }
1153 else
1154 {
1155 if(pack->data_len == sizeof(mbtk_ecall_cfg_info_t)) { // Set
1156 mbtk_ecall_cfg_info_t *cfg_info = (mbtk_ecall_cfg_info_t*)pack->data;
b.liu7ca612c2025-04-25 09:23:36 +08001157 if(req_ecall_cfg_set(cli_info->sim_id, cli_info->port, cfg_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu15f456b2024-10-31 20:16:06 +08001158 {
1159 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1160 err = MBTK_RIL_ERR_CME + cme_err;
1161 } else {
1162 err = MBTK_RIL_ERR_UNKNOWN;
1163 }
b.liueea595d2024-11-05 19:52:10 +08001164 LOG("Set ecall config[%x] fail.", cfg_info->type);
b.liu15f456b2024-10-31 20:16:06 +08001165 }
1166 else
1167 {
b.liu7ca612c2025-04-25 09:23:36 +08001168 ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
b.liu15f456b2024-10-31 20:16:06 +08001169 }
1170 } else { // Get
1171 mbtk_ecall_cfg_info_t cfg_info;
1172 memset(&cfg_info, 0, sizeof(mbtk_ecall_cfg_info_t));
b.liueea595d2024-11-05 19:52:10 +08001173 uint32 *type = (uint32*)(pack->data);
b.liu7ca612c2025-04-25 09:23:36 +08001174 if(req_ecall_cfg_get(cli_info->sim_id, cli_info->port, *type, &cfg_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu15f456b2024-10-31 20:16:06 +08001175 {
1176 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1177 err = MBTK_RIL_ERR_CME + cme_err;
1178 } else {
1179 err = MBTK_RIL_ERR_UNKNOWN;
1180 }
b.liueea595d2024-11-05 19:52:10 +08001181 LOG("Get ecall config[%x] fail.", *type);
b.liu15f456b2024-10-31 20:16:06 +08001182 }
1183 else
1184 {
b.liu7ca612c2025-04-25 09:23:36 +08001185 ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &cfg_info, sizeof(mbtk_ecall_cfg_info_t));
b.liu15f456b2024-10-31 20:16:06 +08001186 }
1187 }
1188 }
1189 break;
1190 }
1191 case RIL_MSG_ID_ECALL_SMS_NUM: // uint8[]
1192 {
1193 uint8 number[RIL_MAX_NUMBER_LEN];
1194 memset(number, 0, sizeof(number));
1195 if(pack->data_len == 0 || pack->data == NULL)
1196 {
b.liu7ca612c2025-04-25 09:23:36 +08001197 if(req_ecall_sms_num_get(cli_info->sim_id, cli_info->port, number, &cme_err) || strlen((char*)number) == 0 || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu15f456b2024-10-31 20:16:06 +08001198 {
1199 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1200 err = MBTK_RIL_ERR_CME + cme_err;
1201 } else {
1202 err = MBTK_RIL_ERR_UNKNOWN;
1203 }
1204 LOG("Get ecall sms number fail.");
1205 }
1206 else
1207 {
b.liu7ca612c2025-04-25 09:23:36 +08001208 ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, number, strlen((char*)number));
b.liu15f456b2024-10-31 20:16:06 +08001209 }
1210 }
1211 else // Set
1212 {
1213 memcpy(number, pack->data, pack->data_len);
b.liu7ca612c2025-04-25 09:23:36 +08001214 if(req_ecall_sms_num_set(cli_info->sim_id, cli_info->port, number, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu15f456b2024-10-31 20:16:06 +08001215 {
1216 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1217 err = MBTK_RIL_ERR_CME + cme_err;
1218 } else {
1219 err = MBTK_RIL_ERR_UNKNOWN;
1220 }
1221 LOG("Set ecall sms number fail.");
1222 }
1223 else
1224 {
b.liu7ca612c2025-04-25 09:23:36 +08001225 ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
b.liu15f456b2024-10-31 20:16:06 +08001226 }
1227 }
1228 break;
1229 }
1230 case RIL_MSG_ID_ECALL_MUTESPK:
1231 {
1232 if(pack->data_len == 0 || pack->data == NULL)
1233 {
1234 err = MBTK_RIL_ERR_UNSUPPORTED;
1235 }
1236 else // Set mute state.
1237 {
1238 uint8 mute = pack->data[0];
1239 if(pack->data_len != sizeof(uint8) || (mute != 0 && mute != 1))
1240 {
1241 err = MBTK_RIL_ERR_REQ_PARAMETER;
1242 LOG("Set spk mute parameter error.");
1243 break;
1244 }
1245
b.liu7ca612c2025-04-25 09:23:36 +08001246 if(req_ecall_spkmute_set(cli_info->sim_id, cli_info->port, mute, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu15f456b2024-10-31 20:16:06 +08001247 {
1248 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1249 err = MBTK_RIL_ERR_CME + cme_err;
1250 } else {
1251 err = MBTK_RIL_ERR_UNKNOWN;
1252 }
1253 LOG("Set spk mute state fail.");
1254 }
1255 else
1256 {
b.liu7ca612c2025-04-25 09:23:36 +08001257 ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
b.liu15f456b2024-10-31 20:16:06 +08001258 }
1259 }
1260 break;
1261 }
1262 case RIL_MSG_ID_ECALL_DSP_GAIN: // mbtk_ecall_gain_info_t
1263 {
1264 if(pack->data_len == 0 || pack->data == NULL)
1265 {
1266 err = MBTK_RIL_ERR_UNSUPPORTED;
1267 }
1268 else // Set
1269 {
1270 mbtk_ecall_gain_info_t *gain_info = (mbtk_ecall_gain_info_t *)pack->data;
b.liu7ca612c2025-04-25 09:23:36 +08001271 if(req_ecall_gain_set(cli_info->sim_id, cli_info->port, gain_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu15f456b2024-10-31 20:16:06 +08001272 {
1273 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1274 err = MBTK_RIL_ERR_CME + cme_err;
1275 } else {
1276 err = MBTK_RIL_ERR_UNKNOWN;
1277 }
1278 LOGE("Set ecall gain fail.");
1279 }
1280 else
1281 {
b.liu7ca612c2025-04-25 09:23:36 +08001282 ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
b.liu15f456b2024-10-31 20:16:06 +08001283 }
1284 }
1285 break;
1286 }
1287 default:
1288 {
1289 err = MBTK_RIL_ERR_REQ_UNKNOWN;
1290 LOG("Unknown request : %s", id2str(pack->msg_id));
1291 break;
1292 }
1293 }
1294
1295 return err;
1296}
1297
1298
1299