blob: dfb4acedeaf7222c536428715b3c3e8f4f769b19 [file] [log] [blame]
b.liu15f456b2024-10-31 20:16:06 +08001#include <stdio.h>
2#include <stdlib.h>
3#include <unistd.h>
4#include <errno.h>
5#include <sys/socket.h>
6#include <sys/un.h>
7#include <netinet/in.h>
8#include <pthread.h>
9#include <sys/epoll.h>
10#include <fcntl.h>
11#include <signal.h>
12
13#include "mbtk_type.h"
14#include "mbtk_ril.h"
15#include "atchannel.h"
16#include "at_tok.h"
17#include "mbtk_utils.h"
18#include "ril_info.h"
19
20static mbtk_ecall_mode_type_enum ecall_mode = MBTK_ECALL_MODE_TYPE_EU;
21
22void ril_rsp_pack_send(int fd, int ril_id, int msg_index, const void* data, int data_len);
23
24static int req_ecall_msdcfg(mbtk_ecall_msd_cfg_info_t *cfg_info, int *cme_err)
25{
26 ATResponse *response = NULL;
27 char cmd[1024] = {0};
28 sprintf(cmd, "AT*ECALLMSDCFG=%d,\"%s\",0", cfg_info->item_type, cfg_info->data);
29 int err = at_send_command(cmd, &response);
30 if (err < 0 || response->success == 0){
31 *cme_err = at_get_cme_error(response);
32 goto exit;
33 }
34
35exit:
36 at_response_free(response);
37 return err;
38}
39
40static int req_ecall_msdgen(int *cme_err)
41{
42 ATResponse *response = NULL;
43 int err = at_send_command("AT*ECALLMSDGEN", &response);
44 if (err < 0 || response->success == 0){
45 *cme_err = at_get_cme_error(response);
46 goto exit;
47 }
48
49exit:
50 at_response_free(response);
51 return err;
52}
53
54static int req_ecall_msd_set(const uint8 *msd, int *cme_err)
55{
56 ATResponse *response = NULL;
57 char cmd[1024] = {0};
58 sprintf(cmd, "AT*ECALLMSD=\"%s\"", msd);
59 int err = at_send_command(cmd, &response);
60 if (err < 0 || response->success == 0){
61 *cme_err = at_get_cme_error(response);
62 goto exit;
63 }
64
65exit:
66 at_response_free(response);
67 return err;
68}
69
70static int req_ecall_msd_get(uint8 *msd, int *cme_err)
71{
72 ATResponse *response = NULL;
73 char *tmp_ptr = NULL;
74 int err = at_send_command_singleline("AT*ECALLMSD?", "*ECALLMSD:", &response);
75
76 if (err < 0 || response->success == 0 || !response->p_intermediates){
77 *cme_err = at_get_cme_error(response);
78 goto exit;
79 }
80
81 char *line = response->p_intermediates->line;
82 err = at_tok_start(&line);
83 if (err < 0)
84 {
85 goto exit;
86 }
87
88 err = at_tok_nextstr(&line, &tmp_ptr);
89 if (err < 0)
90 {
91 goto exit;
92 }
93
94 if(tmp_ptr && strlen(tmp_ptr) > 0) {
95 memcpy(msd, tmp_ptr, strlen(tmp_ptr));
96 }
97
98 goto exit;
99exit:
100 at_response_free(response);
101 return err;
102}
103
104static int req_ecall_push(int *cme_err)
105{
106 ATResponse *response = NULL;
107 int err = at_send_command("AT*ECALLPUSH", &response);
108 if (err < 0 || response->success == 0){
109 *cme_err = at_get_cme_error(response);
110 goto exit;
111 }
112
113exit:
114 at_response_free(response);
115 return err;
116}
117
118/*
119AT*ECALLONLY?
120*ECALLONLY: 0,0,18981911691,18981911691
121
122OK
123
124*/
125static int req_ecall_only_get(mbtk_ecall_only_info_t *only_info, int *cme_err)
126{
127 ATResponse *response = NULL;
128 char *tmp_ptr = NULL;
129 int tmp_int;
130 int err = at_send_command_singleline("AT*ECALLONLY?", "*ECALLONLY:", &response);
131
132 if (err < 0 || response->success == 0 || !response->p_intermediates){
133 *cme_err = at_get_cme_error(response);
134 goto exit;
135 }
136
137 char *line = response->p_intermediates->line;
138 err = at_tok_start(&line);
139 if (err < 0)
140 {
141 goto exit;
142 }
143
144 err = at_tok_nextint(&line, &tmp_int);
145 if (err < 0)
146 {
147 goto exit;
148 }
149 only_info->active = (mbtk_ecall_only_type_enum)tmp_int;
150
151 err = at_tok_nextint(&line, &tmp_int);
152 if (err < 0)
153 {
154 goto exit;
155 }
156 only_info->sim_type = (mbtk_ecall_sim_type_enum)tmp_int;
157
158 err = at_tok_nextstr(&line, &tmp_ptr);
159 if (err < 0)
160 {
161 goto exit;
162 }
163
164 if(tmp_ptr && strlen(tmp_ptr) > 0) {
165 memcpy(only_info->test_num, tmp_ptr, strlen(tmp_ptr));
166 }
167
168 err = at_tok_nextstr(&line, &tmp_ptr);
169 if (err < 0)
170 {
171 goto exit;
172 }
173
174 if(tmp_ptr && strlen(tmp_ptr) > 0) {
175 memcpy(only_info->reconfig_num, tmp_ptr, strlen(tmp_ptr));
176 }
177
178 goto exit;
179exit:
180 at_response_free(response);
181 return err;
182}
183
184/*
185AT*ECALLONLY?
186*ECALLONLY: 0,0,18981911691,18981911691
187
188OK
189
190*/
191static int req_ecall_only_set(const mbtk_ecall_only_info_t *only_info, int *cme_err)
192{
193 ATResponse *response = NULL;
194 char cmd[1024] = {0};
195 sprintf(cmd, "AT*ECALLONLY=%d,%s,%s", only_info->active,only_info->test_num,only_info->reconfig_num);
196 int err = at_send_command(cmd, &response);
197 if (err < 0 || response->success == 0){
198 *cme_err = at_get_cme_error(response);
199 goto exit;
200 }
201
202exit:
203 at_response_free(response);
204 return err;
205}
206
207/*
208AT*ECALLREG=0/1
209
210*/
211static int req_ecall_reg_set(uint8 reg, int *cme_err)
212{
213 ATResponse *response = NULL;
214 char cmd[30] = {0};
215 sprintf(cmd, "AT*ECALLREG=%d", reg);
216 int err = at_send_command(cmd, &response);
217 if (err < 0 || response->success == 0){
218 *cme_err = at_get_cme_error(response);
219 goto exit;
220 }
221
222exit:
223 at_response_free(response);
224 return err;
225}
226
227/*
228AT+CECALL?
229+CECALL: 4
230
231OK
232
233*/
234static int req_ecall_dial_state_get(mbtk_ecall_dial_type_enum *type, int *cme_err)
235{
236 ATResponse *response = NULL;
237 int tmp_int;
238 int err = at_send_command_singleline("AT+CECALL?", "+CECALL:", &response);
239
240 if (err < 0 || response->success == 0 || !response->p_intermediates){
241 *cme_err = at_get_cme_error(response);
242 goto exit;
243 }
244
245 char *line = response->p_intermediates->line;
246 err = at_tok_start(&line);
247 if (err < 0)
248 {
249 goto exit;
250 }
251
252 err = at_tok_nextint(&line, &tmp_int);
253 if (err < 0)
254 {
255 goto exit;
256 }
257 *type = (mbtk_ecall_dial_type_enum)tmp_int;
258
259 goto exit;
260exit:
261 at_response_free(response);
262 return err;
263}
264
265/*
266AT+CECALL=<ecalltype>
267OK
268*/
269static int req_ecall_dial_start(mbtk_ecall_dial_type_enum type, int *cme_err)
270{
271 ATResponse *response = NULL;
272 char cmd[1024] = {0};
273 sprintf(cmd, "AT+CECALL=%d", type);
274 int err = at_send_command(cmd, &response);
275 if (err < 0 || response->success == 0){
276 *cme_err = at_get_cme_error(response);
277 goto exit;
278 }
279
280exit:
281 at_response_free(response);
282 return err;
283}
284
285
286/*
287AT*ECALLMODE?
288*ECALLMODE: "ERA"
289
290OK
291
292*/
293static int req_ecall_mode_get(mbtk_ecall_mode_type_enum *mode, int *cme_err)
294{
295 ATResponse *response = NULL;
296 char *tmp_ptr = NULL;
297 int err = at_send_command_singleline("AT*ECALLMODE?", "*ECALLMODE:", &response);
298
299 if (err < 0 || response->success == 0 || !response->p_intermediates){
300 *cme_err = at_get_cme_error(response);
301 goto exit;
302 }
303
304 char *line = response->p_intermediates->line;
305 err = at_tok_start(&line);
306 if (err < 0)
307 {
308 goto exit;
309 }
310
311 err = at_tok_nextstr(&line, &tmp_ptr);
312 if (err < 0)
313 {
314 goto exit;
315 }
316
317 if(tmp_ptr && strlen(tmp_ptr) > 0) {
318 if(strcmp(tmp_ptr, "ERA") == 0) {
319 *mode = MBTK_ECALL_MODE_TYPE_ERA;
320 } else {
321 *mode = MBTK_ECALL_MODE_TYPE_EU;
322 }
323
324 ecall_mode = *mode;
325 } else {
326 err = -1;
327 }
328
329 goto exit;
330exit:
331 at_response_free(response);
332 return err;
333}
334
335/*
336AT*ECALLMODE="ERA"
337OK
338
339*/
340static int req_ecall_mode_set(mbtk_ecall_mode_type_enum mode, int *cme_err)
341{
342 ATResponse *response = NULL;
343 char cmd[1024] = {0};
344 if(mode == MBTK_ECALL_MODE_TYPE_EU) {
345 sprintf(cmd, "AT*ECALLMODE=\"EU\"");
346 } else {
347 sprintf(cmd, "AT*ECALLMODE=\"ERA\"");
348 }
349 int err = at_send_command(cmd, &response);
350 if (err < 0 || response->success == 0){
351 *cme_err = at_get_cme_error(response);
352 goto exit;
353 }
354
355 ecall_mode = mode;
356
357exit:
358 at_response_free(response);
359 return err;
360}
361
362/*
363AT*ECALLDATA=5,2
364*ECALLDATA: 5,2,250
365
366OK
367
368AT*ECALLTIMER?
369*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.
370
371OK
372
373*/
374static int req_ecall_cfg_get(mbtk_ecall_cfg_item_enum type, mbtk_ecall_cfg_info_t *cfg, int *cme_err)
375{
376 ATResponse *response = NULL;
377 char *tmp_ptr = NULL;
378 int tmp_int;
379 char cmd[1024] = {0};
380 int err = 0;
381
382 cfg->type = type;
383 switch(type)
384 {
385 case MBTK_ECALL_CFG_ITEM_T3:
386 case MBTK_ECALL_CFG_ITEM_T5:
387 case MBTK_ECALL_CFG_ITEM_T6:
388 case MBTK_ECALL_CFG_ITEM_T7:
389 case MBTK_ECALL_CFG_ITEM_TH:
390 snprintf(cmd, sizeof(cmd), "AT*ECALLDATA=5,%d", type);
391
392 err = at_send_command_singleline(cmd, "*ECALLDATA:", &response);
393 break;
394 default:
395 snprintf(cmd, sizeof(cmd), "AT*ECALLTIMER?");
396
397 err = at_send_command_singleline(cmd, "*ECALLTIMER:", &response);
398 break;
399 }
400
401 if (err < 0 || response->success == 0 || !response->p_intermediates){
402 *cme_err = at_get_cme_error(response);
403 goto exit;
404 }
405
406 char *line = response->p_intermediates->line;
407 err = at_tok_start(&line);
408 if (err < 0)
409 {
410 goto exit;
411 }
412
413 if(strstr(cmd, "AT*ECALLDATA")) {
414 err = at_tok_nextint(&line, &tmp_int);
415 if (err < 0)
416 {
417 goto exit;
418 }
419
420 err = at_tok_nextint(&line, &tmp_int);
421 if (err < 0)
422 {
423 goto exit;
424 }
425
426 err = at_tok_nextint(&line, &tmp_int);
427 if (err < 0)
428 {
429 goto exit;
430 }
431
432 cfg->data = (uint32)(tmp_int * 20); // ms
433 } else {
434 // *ECALLTIMER: ERA mode, callback timer: 1200s,
435 // dial setup timer: 30s, NAD deregister timer: 7200s,
436 // cleardown timer: 3600s, redial attempts count: 10,
437 // redial wait timer: 30s, smsprocess: 1, SMS resend timer: 3600s,
438 // sms msd send count: 10.
439
440 if(strstr(line, "ERA mode") != NULL) {
441 ecall_mode = MBTK_ECALL_MODE_TYPE_ERA;
442 } else {
443 ecall_mode = MBTK_ECALL_MODE_TYPE_EU;
444 }
445
446 switch(type)
447 {
448 case MBTK_ECALL_CFG_ITEM_TIMER_CALLBACK:
449 {
450 if((tmp_ptr = strstr(line, "callback timer: ")) != NULL) {
451 cfg->data = (uint32)atoi(tmp_ptr + 16); // s
452 cfg->data *= 1000; // s -> ms
453 }
454 break;
455 }
456 case MBTK_ECALL_CFG_ITEM_TIMER_CLEARDOWN:
457 {
458 if((tmp_ptr = strstr(line, "cleardown timer: ")) != NULL) {
459 cfg->data = (uint32)atoi(tmp_ptr + 17); // s
460 cfg->data *= 1000; // s -> ms
461 }
462 break;
463 }
464 case MBTK_ECALL_CFG_ITEM_TIMER_DEREG:
465 {
466 if((tmp_ptr = strstr(line, "deregister timer: ")) != NULL) {
467 cfg->data = (uint32)atoi(tmp_ptr + 18); // s
468 cfg->data *= 1000; // s -> ms
469 }
470 break;
471 }
472 case MBTK_ECALL_CFG_ITEM_TIMER_DIAL:
473 {
474 if((tmp_ptr = strstr(line, "dial setup timer: ")) != NULL) {
475 cfg->data = (uint32)atoi(tmp_ptr + 18); // s
476 }
477 break;
478 }
479 case MBTK_ECALL_CFG_ITEM_TIMER_REDIAL:
480 {
481 if((tmp_ptr = strstr(line, "redial wait timer: ")) != NULL) {
482 cfg->data = (uint32)atoi(tmp_ptr + 19); // s
483 cfg->data *= 1000; // s -> ms
484 }
485 break;
486 }
487 case MBTK_ECALL_CFG_ITEM_TIMER_SMS:
488 {
489 if((tmp_ptr = strstr(line, "SMS resend timer: ")) != NULL) {
490 cfg->data = (uint32)atoi(tmp_ptr + 18);
491 cfg->data *= 1000; // s -> ms
492 }
493 break;
494 }
495 case MBTK_ECALL_CFG_ITEM_REDIALCNT:
496 {
497 if((tmp_ptr = strstr(line, "redial attempts count: ")) != NULL) {
498 cfg->data = (uint32)atoi(tmp_ptr + 23);
499 }
500 break;
501 }
502 case MBTK_ECALL_CFG_ITEM_SMSPROCESS:
503 {
504 if((tmp_ptr = strstr(line, "smsprocess: ")) != NULL) {
505 cfg->data = (uint32)atoi(tmp_ptr + 12);
506 }
507 break;
508 }
509 case MBTK_ECALL_CFG_ITEM_SMSMSDCNT:
510 {
511 if((tmp_ptr = strstr(line, "sms msd send count: ")) != NULL) {
512 cfg->data = (uint32)atoi(tmp_ptr + 20);
513 }
514 break;
515 }
516 default:
517 LOGE("Unknown config item : %d", type);
518 err = -1;
519 break;
520 }
521 }
522
523 goto exit;
524exit:
525 at_response_free(response);
526 return err;
527}
528
529/*
530AT*ECALLDATA=5,2,250
531OK
532
533AT*ECALLTIMER=dereg,300
534OK
535*/
536static int req_ecall_cfg_set(const mbtk_ecall_cfg_info_t *cfg_info, int *cme_err)
537{
538 ATResponse *response = NULL;
539 char cmd[1024] = {0};
540 int err = 0;
541
542 if(ecall_mode == MBTK_ECALL_MODE_TYPE_EU) {
543 if(cfg_info->type != MBTK_ECALL_CFG_ITEM_TIMER_CALLBACK
544 && cfg_info->type != MBTK_ECALL_CFG_ITEM_TIMER_DIAL
545 && cfg_info->type != MBTK_ECALL_CFG_ITEM_TIMER_DEREG
546 && cfg_info->type != MBTK_ECALL_CFG_ITEM_TIMER_CLEARDOWN){
547 LOGW("No support for EU.");
548 return -1;
549 }
550 }
551
552 switch(cfg_info->type)
553 {
554 case MBTK_ECALL_CFG_ITEM_T3:
555 case MBTK_ECALL_CFG_ITEM_T5:
556 case MBTK_ECALL_CFG_ITEM_T6:
557 case MBTK_ECALL_CFG_ITEM_T7:
558 case MBTK_ECALL_CFG_ITEM_TH:
559 snprintf(cmd, sizeof(cmd), "AT*ECALLDATA=5,%d,%d", cfg_info->type, cfg_info->data / 20);
560 break;
561 case MBTK_ECALL_CFG_ITEM_TIMER_CALLBACK:
562 {
563 snprintf(cmd, sizeof(cmd), "AT*ECALLTIMER=callback,%d", cfg_info->data / 1000);
564 break;
565 }
566 case MBTK_ECALL_CFG_ITEM_TIMER_CLEARDOWN:
567 {
568 snprintf(cmd, sizeof(cmd), "AT*ECALLTIMER=cleardown,%d", cfg_info->data / 1000);
569 break;
570 }
571 case MBTK_ECALL_CFG_ITEM_TIMER_DEREG:
572 {
573 snprintf(cmd, sizeof(cmd), "AT*ECALLTIMER=dereg,%d", cfg_info->data / 1000);
574 break;
575 }
576 case MBTK_ECALL_CFG_ITEM_TIMER_DIAL:
577 {
578 snprintf(cmd, sizeof(cmd), "AT*ECALLTIMER=dial,%d", cfg_info->data / 1000);
579 break;
580 }
581 case MBTK_ECALL_CFG_ITEM_TIMER_REDIAL:
582 {
583 snprintf(cmd, sizeof(cmd), "AT*ECALLTIMER=redialtmr,%d", cfg_info->data / 1000);
584 break;
585 }
586 case MBTK_ECALL_CFG_ITEM_TIMER_SMS:
587 {
588 snprintf(cmd, sizeof(cmd), "AT*ECALLTIMER=sms,%d", cfg_info->data / 1000);
589 break;
590 }
591 case MBTK_ECALL_CFG_ITEM_REDIALCNT:
592 {
593 snprintf(cmd, sizeof(cmd), "AT*ECALLTIMER=redialcnt,%d", cfg_info->data);
594 break;
595 }
596 case MBTK_ECALL_CFG_ITEM_SMSPROCESS:
597 {
598 snprintf(cmd, sizeof(cmd), "AT*ECALLTIMER=smsprocess,%d", cfg_info->data);
599 break;
600 }
601 case MBTK_ECALL_CFG_ITEM_SMSMSDCNT:
602 {
603 snprintf(cmd, sizeof(cmd), "AT*ECALLTIMER=smsmsdcnt,%d", cfg_info->data);
604 break;
605 }
606 default:
607 LOGE("Unknown config item : %d", cfg_info->type);
608 err = -1;
609 goto exit;
610 }
611
612 err = at_send_command(cmd, &response);
613 if (err < 0 || response->success == 0){
614 *cme_err = at_get_cme_error(response);
615 goto exit;
616 }
617
618exit:
619 at_response_free(response);
620 return err;
621}
622
623/*
624AT*ECALLMUTESPK=1
625OK
626
627*/
628static int req_ecall_spkmute_set(int mute, int *cme_err)
629{
630 ATResponse *response = NULL;
631 char cmd[100] = {0};
632 sprintf(cmd, "AT*ECALLMUTESPK=%d", mute);
633 int err = at_send_command(cmd, &response);
634 if (err < 0 || response->success == 0){
635 *cme_err = at_get_cme_error(response);
636 goto exit;
637 }
638
639exit:
640 at_response_free(response);
641 return err;
642}
643
644
645/*
646AT*ECALLSMSNUM?
647*ECALLSMSNUM: "18981991452"
648
649OK
650
651*/
652static int req_ecall_sms_num_get(uint8 *number, int *cme_err)
653{
654 ATResponse *response = NULL;
655 char *tmp_ptr = NULL;
656 int err = at_send_command_singleline("AT*ECALLSMSNUM?", "*ECALLSMSNUM:", &response);
657
658 if (err < 0 || response->success == 0 || !response->p_intermediates){
659 *cme_err = at_get_cme_error(response);
660 goto exit;
661 }
662
663 char *line = response->p_intermediates->line;
664 err = at_tok_start(&line);
665 if (err < 0)
666 {
667 goto exit;
668 }
669
670 err = at_tok_nextstr(&line, &tmp_ptr);
671 if (err < 0)
672 {
673 goto exit;
674 }
675
676 if(tmp_ptr && strlen(tmp_ptr) > 0) {
677 memcpy(number, tmp_ptr, strlen(tmp_ptr));
678 }
679
680 goto exit;
681exit:
682 at_response_free(response);
683 return err;
684}
685
686/*
687AT*ECALLSMSNUM=18981991452
688OK
689
690*/
691static int req_ecall_sms_num_set(const uint8 *number, int *cme_err)
692{
693 ATResponse *response = NULL;
694 char cmd[100] = {0};
695 sprintf(cmd, "AT*ECALLSMSNUM=%s", number);
696 int err = at_send_command(cmd, &response);
697 if (err < 0 || response->success == 0){
698 *cme_err = at_get_cme_error(response);
699 goto exit;
700 }
701
702exit:
703 at_response_free(response);
704 return err;
705}
706
707/*
708AT*AUDGAIN=8,1 // Set Rx voice gain = 8dB
709OK
710
711*/
712static int req_ecall_gain_set(mbtk_ecall_gain_info_t *gain, int *cme_err)
713{
714 ATResponse *response = NULL;
715 char cmd[100] = {0};
716 sprintf(cmd, "AT*AUDGAIN=%d,%d", gain->gain, gain->mode);
717 int err = at_send_command(cmd, &response);
718 if (err < 0 || response->success == 0){
719 *cme_err = at_get_cme_error(response);
720 goto exit;
721 }
722
723exit:
724 at_response_free(response);
725 return err;
726}
727
728//void net_list_free(void *data);
729// Return MBTK_INFO_ERR_SUCCESS,will call pack_error_send() to send RSP.
730// Otherwise, do not call pack_error_send().
731mbtk_ril_err_enum ecall_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack)
732{
733 mbtk_ril_err_enum err = MBTK_RIL_ERR_SUCCESS;
734 int cme_err = MBTK_RIL_ERR_CME_NON;
735 switch(pack->msg_id)
736 {
737 case RIL_MSG_ID_ECALL_MSDCFG: // mbtk_ecall_msd_cfg_info_t
738 {
739 if(pack->data_len == 0 || pack->data == NULL)
740 {
741 err = MBTK_RIL_ERR_UNSUPPORTED;
742 }
743 else // Set
744 {
745 mbtk_ecall_msd_cfg_info_t *cfg_info = (mbtk_ecall_msd_cfg_info_t*)(pack->data);
746 if(req_ecall_msdcfg(cfg_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
747 {
748 if(cme_err != MBTK_RIL_ERR_CME_NON) {
749 err = MBTK_RIL_ERR_CME + cme_err;
750 } else {
751 err = MBTK_RIL_ERR_UNKNOWN;
752 }
753 LOG("AT*ECALLMSDCFG fail.");
754 }
755 else
756 {
757 ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
758 }
759 }
760 break;
761 }
762 case RIL_MSG_ID_ECALL_MSDGEN:
763 {
764 if(pack->data_len == 0 || pack->data == NULL)
765 {
766 if(req_ecall_msdgen(&cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
767 {
768 if(cme_err != MBTK_RIL_ERR_CME_NON) {
769 err = MBTK_RIL_ERR_CME + cme_err;
770 } else {
771 err = MBTK_RIL_ERR_UNKNOWN;
772 }
773 LOG("AT*ECALLMSDGEN fail.");
774 }
775 else
776 {
777 ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
778 }
779 }
780 else // Set
781 {
782 err = MBTK_RIL_ERR_UNSUPPORTED;
783 }
784 break;
785 }
786 case RIL_MSG_ID_ECALL_MSD: // uint8[]
787 {
788 uint8 msd[MBTK_ECALL_MSD_LEN_MAX];
789 memset(msd, 0, sizeof(msd));
790 if(pack->data_len == 0 || pack->data == NULL)
791 {
792 if(req_ecall_msd_get(msd, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
793 {
794 if(cme_err != MBTK_RIL_ERR_CME_NON) {
795 err = MBTK_RIL_ERR_CME + cme_err;
796 } else {
797 err = MBTK_RIL_ERR_UNKNOWN;
798 }
799 LOG("Get MSD fail.");
800 }
801 else
802 {
803 ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, msd, strlen(msd));
804 }
805 }
806 else // Set
807 {
808 memcpy(msd, pack->data, pack->data_len);
809 if(req_ecall_msd_set(msd, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
810 {
811 if(cme_err != MBTK_RIL_ERR_CME_NON) {
812 err = MBTK_RIL_ERR_CME + cme_err;
813 } else {
814 err = MBTK_RIL_ERR_UNKNOWN;
815 }
816 LOG("AT*ECALLMSD fail.");
817 }
818 else
819 {
820 ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
821 }
822 }
823 break;
824 }
825 case RIL_MSG_ID_ECALL_PUSH:
826 {
827 if(pack->data_len == 0 || pack->data == NULL)
828 {
829 if(req_ecall_push(&cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
830 {
831 if(cme_err != MBTK_RIL_ERR_CME_NON) {
832 err = MBTK_RIL_ERR_CME + cme_err;
833 } else {
834 err = MBTK_RIL_ERR_UNKNOWN;
835 }
836 LOG("AT*ECALLPUSH fail.");
837 }
838 else
839 {
840 ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
841 }
842 }
843 else // Set
844 {
845 err = MBTK_RIL_ERR_UNSUPPORTED;
846 }
847 break;
848 }
849 case RIL_MSG_ID_ECALL_ONLY: // mbtk_ecall_only_info_t
850 {
851 if(pack->data_len == 0 || pack->data == NULL)
852 {
853 mbtk_ecall_only_info_t only_info;
854 memset(&only_info, 0, sizeof(mbtk_ecall_only_info_t));
855 if(req_ecall_only_get(&only_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
856 {
857 if(cme_err != MBTK_RIL_ERR_CME_NON) {
858 err = MBTK_RIL_ERR_CME + cme_err;
859 } else {
860 err = MBTK_RIL_ERR_UNKNOWN;
861 }
862 LOG("Get ecall only mode fail.");
863 }
864 else
865 {
866 ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &only_info, sizeof(mbtk_ecall_only_info_t));
867 }
868 }
869 else // Set
870 {
871 mbtk_ecall_only_info_t *only_info = (mbtk_ecall_only_info_t*)(pack->data);
872 if(req_ecall_only_set(only_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
873 {
874 if(cme_err != MBTK_RIL_ERR_CME_NON) {
875 err = MBTK_RIL_ERR_CME + cme_err;
876 } else {
877 err = MBTK_RIL_ERR_UNKNOWN;
878 }
879 LOG("AT*ECALLONLY fail.");
880 }
881 else
882 {
883 ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
884 }
885 }
886 break;
887 }
888 case RIL_MSG_ID_ECALL_REG: // reg <uint8>
889 {
890 if(pack->data_len == 0 || pack->data == NULL)
891 {
892 err = MBTK_RIL_ERR_UNSUPPORTED;
893 }
894 else
895 {
896 uint8 reg = pack->data[0];
897 if(req_ecall_reg_set(reg, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
898 {
899 if(cme_err != MBTK_RIL_ERR_CME_NON) {
900 err = MBTK_RIL_ERR_CME + cme_err;
901 } else {
902 err = MBTK_RIL_ERR_UNKNOWN;
903 }
904 LOG("ecall reg(%d) fail.", reg);
905 }
906 else
907 {
908 ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
909 }
910 }
911 break;
912 }
913 case RIL_MSG_ID_ECALL_DIAL: // mbtk_ecall_dial_type_enum
914 {
915 if(pack->data_len == 0 || pack->data == NULL)
916 {
917 mbtk_ecall_dial_type_enum type;
918 if(req_ecall_dial_state_get(&type, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
919 {
920 if(cme_err != MBTK_RIL_ERR_CME_NON) {
921 err = MBTK_RIL_ERR_CME + cme_err;
922 } else {
923 err = MBTK_RIL_ERR_UNKNOWN;
924 }
925 LOG("Get ecall type fail.");
926 }
927 else
928 {
929 ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &type, sizeof(uint8));
930 }
931 }
932 else
933 {
934 mbtk_ecall_dial_type_enum type = (mbtk_ecall_dial_type_enum)pack->data[0];
935 if(req_ecall_dial_start(type, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
936 {
937 if(cme_err != MBTK_RIL_ERR_CME_NON) {
938 err = MBTK_RIL_ERR_CME + cme_err;
939 } else {
940 err = MBTK_RIL_ERR_UNKNOWN;
941 }
942 LOG("Start ecall %d fail.", type);
943 }
944 else
945 {
946 ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
947 }
948 }
949 break;
950 }
951 case RIL_MSG_ID_ECALL_MODE: // mbtk_ecall_cfg_item_enum / mbtk_ecall_cfg_info_t
952 {
953 if(pack->data_len == 0 || pack->data == NULL)
954 {
955 mbtk_ecall_mode_type_enum mode;
956 if(req_ecall_mode_get(&mode, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
957 {
958 if(cme_err != MBTK_RIL_ERR_CME_NON) {
959 err = MBTK_RIL_ERR_CME + cme_err;
960 } else {
961 err = MBTK_RIL_ERR_UNKNOWN;
962 }
963 LOG("Get ecall mode fail.");
964 }
965 else
966 {
967 ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &mode, sizeof(uint8));
968 }
969 }
970 else
971 {
972 mbtk_ecall_mode_type_enum mode = (mbtk_ecall_mode_type_enum)pack->data[0];
973 if(req_ecall_mode_set(mode, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
974 {
975 if(cme_err != MBTK_RIL_ERR_CME_NON) {
976 err = MBTK_RIL_ERR_CME + cme_err;
977 } else {
978 err = MBTK_RIL_ERR_UNKNOWN;
979 }
980 LOG("Set ecall mode %d fail.", mode);
981 }
982 else
983 {
984 ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
985 }
986 }
987 break;
988 }
989 case RIL_MSG_ID_ECALL_CFG: // mbtk_ecall_cfg_item_enum / mbtk_ecall_cfg_info_t
990 {
991 if(pack->data_len == 0 || pack->data == NULL)
992 {
993 err = MBTK_RIL_ERR_UNSUPPORTED;
994 }
995 else
996 {
997 if(pack->data_len == sizeof(mbtk_ecall_cfg_info_t)) { // Set
998 mbtk_ecall_cfg_info_t *cfg_info = (mbtk_ecall_cfg_info_t*)pack->data;
999 if(req_ecall_cfg_set(cfg_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
1000 {
1001 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1002 err = MBTK_RIL_ERR_CME + cme_err;
1003 } else {
1004 err = MBTK_RIL_ERR_UNKNOWN;
1005 }
1006 LOG("Set ecall config[%d] fail.", cfg_info->type);
1007 }
1008 else
1009 {
1010 ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
1011 }
1012 } else { // Get
1013 mbtk_ecall_cfg_info_t cfg_info;
1014 memset(&cfg_info, 0, sizeof(mbtk_ecall_cfg_info_t));
1015 mbtk_ecall_cfg_item_enum type = (mbtk_ecall_cfg_item_enum)pack->data[0];
1016 if(req_ecall_cfg_get(type, &cfg_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
1017 {
1018 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1019 err = MBTK_RIL_ERR_CME + cme_err;
1020 } else {
1021 err = MBTK_RIL_ERR_UNKNOWN;
1022 }
1023 LOG("Get ecall config[%d] fail.", type);
1024 }
1025 else
1026 {
1027 ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &cfg_info, sizeof(mbtk_ecall_cfg_info_t));
1028 }
1029 }
1030 }
1031 break;
1032 }
1033 case RIL_MSG_ID_ECALL_SMS_NUM: // uint8[]
1034 {
1035 uint8 number[RIL_MAX_NUMBER_LEN];
1036 memset(number, 0, sizeof(number));
1037 if(pack->data_len == 0 || pack->data == NULL)
1038 {
1039 if(req_ecall_sms_num_get(number, &cme_err) || strlen(number) == 0 || cme_err != MBTK_RIL_ERR_CME_NON)
1040 {
1041 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1042 err = MBTK_RIL_ERR_CME + cme_err;
1043 } else {
1044 err = MBTK_RIL_ERR_UNKNOWN;
1045 }
1046 LOG("Get ecall sms number fail.");
1047 }
1048 else
1049 {
1050 ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, number, strlen(number));
1051 }
1052 }
1053 else // Set
1054 {
1055 memcpy(number, pack->data, pack->data_len);
1056 if(req_ecall_sms_num_set(number, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
1057 {
1058 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1059 err = MBTK_RIL_ERR_CME + cme_err;
1060 } else {
1061 err = MBTK_RIL_ERR_UNKNOWN;
1062 }
1063 LOG("Set ecall sms number fail.");
1064 }
1065 else
1066 {
1067 ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
1068 }
1069 }
1070 break;
1071 }
1072 case RIL_MSG_ID_ECALL_MUTESPK:
1073 {
1074 if(pack->data_len == 0 || pack->data == NULL)
1075 {
1076 err = MBTK_RIL_ERR_UNSUPPORTED;
1077 }
1078 else // Set mute state.
1079 {
1080 uint8 mute = pack->data[0];
1081 if(pack->data_len != sizeof(uint8) || (mute != 0 && mute != 1))
1082 {
1083 err = MBTK_RIL_ERR_REQ_PARAMETER;
1084 LOG("Set spk mute parameter error.");
1085 break;
1086 }
1087
1088 if(req_ecall_spkmute_set(mute, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
1089 {
1090 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1091 err = MBTK_RIL_ERR_CME + cme_err;
1092 } else {
1093 err = MBTK_RIL_ERR_UNKNOWN;
1094 }
1095 LOG("Set spk mute state fail.");
1096 }
1097 else
1098 {
1099 ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
1100 }
1101 }
1102 break;
1103 }
1104 case RIL_MSG_ID_ECALL_DSP_GAIN: // mbtk_ecall_gain_info_t
1105 {
1106 if(pack->data_len == 0 || pack->data == NULL)
1107 {
1108 err = MBTK_RIL_ERR_UNSUPPORTED;
1109 }
1110 else // Set
1111 {
1112 mbtk_ecall_gain_info_t *gain_info = (mbtk_ecall_gain_info_t *)pack->data;
1113 if(req_ecall_gain_set(gain_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
1114 {
1115 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1116 err = MBTK_RIL_ERR_CME + cme_err;
1117 } else {
1118 err = MBTK_RIL_ERR_UNKNOWN;
1119 }
1120 LOGE("Set ecall gain fail.");
1121 }
1122 else
1123 {
1124 ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
1125 }
1126 }
1127 break;
1128 }
1129 default:
1130 {
1131 err = MBTK_RIL_ERR_REQ_UNKNOWN;
1132 LOG("Unknown request : %s", id2str(pack->msg_id));
1133 break;
1134 }
1135 }
1136
1137 return err;
1138}
1139
1140
1141