blob: a283bf9d2b7703f480fbb09674dfe15ee999216f [file] [log] [blame]
lhb07f4e12022-02-17 22:08:54 -08001//SPDX-License-Identifier: MediaTekProprietary
lh7b0674a2022-01-10 00:34:35 -08002/* Copyright Statement:
3 *
4 * This software/firmware and related documentation ("MediaTek Software") are
5 * protected under relevant copyright laws. The information contained herein
6 * is confidential and proprietary to MediaTek Inc. and/or its licensors.
7 * Without the prior written permission of MediaTek inc. and/or its licensors,
8 * any reproduction, modification, use or disclosure of MediaTek Software,
9 * and information contained herein, in whole or in part, shall be strictly prohibited.
10 */
11/* MediaTek Inc. (C) 2010. All rights reserved.
12 *
13 * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
14 * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
15 * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
16 * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
19 * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
20 * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
21 * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
22 * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
23 * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
24 * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
25 * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
26 * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
27 * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
28 * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
29 * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
30 * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
31 *
32 * The following software/firmware and/or related documentation ("MediaTek Software")
33 * have been modified by MediaTek Inc. All revisions are subject to any receiver's
34 * applicable license agreements with MediaTek Inc.
35 */
36#include "cc.h"
37#include <alloca.h>
38#include <stdlib.h>
39#include <stdio.h>
40#include <cutils/jstring.h>
41#include <stdbool.h>
42#include <glib.h>
43#include <string.h>
44#include <string>
45#include <thread>
46#include "eCall.h"
47/*Warren add for t800 ril servie 2021/12/23 start*/
48#include "lynq_interface.h"
49#include <binder/Parcel.h>
q.huang1c03f752023-12-14 14:11:58 +080050#include "call_rtp.h"
you.chen297fc092023-12-21 17:11:20 +080051#include "liblynq-codec/lynq_codec.h"
lh7b0674a2022-01-10 00:34:35 -080052using android::Parcel;
53/*Warren add for t800 ril servie 2021/12/23 end*/
54
55static int dtmf_volume = 0;
56void *dtmf_handle = NULL;
57
58extern "C" {
59 #include <dtmf.h>
60 #include "mixer_ctrl.h"
61}
62#undef LOG_TAG
63#define LOG_TAG "LYNQ_RIL_CC"
64
65static speech_status speechStatus = SPEECH_OFF;
66static int autoAnswerMode = 0;
67static int inCallRecordMode = 0;
68static call_status inCallstatus = CALL_OFF;
69//int callIndex = 0;
70const char g_card_name[] = "mtk_phonecall";
71/*for speech on*/
72const char g_mixer_name[] = "Speech_on";
73const char g_mixer_name_ecall[] = "Speech_on_ecall";
74const char g_mixer_reset_name[] = "Modem_reset_notify";
75const char g_mixer_name_bt[] = "Speech_on_bt";
76const char g_bt_has_ecnr_name[] = "BT_HAS_ECNR";
77const char g_bt_wbs_name[] = "BT_WBS";
78int g_audio_path = 0; // 0: normal, 1: bt
79int g_bt_has_ecnr_value = 0; // 0: ecnr, 1, no ecnr
80int g_bt_wbs_value = 0; // 0: 8000, 1, 16000
81/*for DL call volume*/
82const char g_mixer_name_volume[] = "DL Call";
83const char g_mixer_name_volume_bt[] = "DL BT";
84
85const char g_DL_mute_name[] = "Speech_DL_mute";
86const char g_UL_mute_name[] = "Speech_UL_mute";
87
88const char *RING_PATH = "/system/etc/tele/ring/ring.wav";
89static bool isRingStart = false;
90
91#if defined(TARGET_PLATFORM_MT2731)||defined(TARGET_PLATFORM_MT2735)
92#define MAX_VOLUME (7)
93#define MIN_VOLUME (1)
94#endif
95
96#ifdef TARGET_PLATFORM_MT2635
97#define MAX_VOLUME (17)
98#define MIN_VOLUME (-23)
99#endif
100
101#define BT_MAX_VOLUME (15)
102#define BT_MIN_VOLUME (0)
103#define DTMF_MAX_VOLUME (36)
104#define DTMF_MIN_VOLUME (0)
105
106int get_call_status(void)
107{
108 return inCallstatus;
109}
110
111void set_audio_path(int path)
112{
113 if ((path != 0) && (path != 1)) {
114 RLOGE("set_audio_path() illegal value %d, we support 0: normal, 1: bt", path);
115 return;
116 }
117
118 g_audio_path = path;
119}
120
121int get_audio_path(void)
122{
123 return g_audio_path;
124}
125
126void set_bt_has_ecnr(int ecnr)
127{
128 if ((ecnr != 0) && (ecnr != 1)) {
129 RLOGE("set_bt_has_ecnr() illegal value %d, we support 0: do ecnr, 1: no ecnr", ecnr);
130 return;
131 }
132
133 g_bt_has_ecnr_value = ecnr;
134}
135
136int get_bt_has_ecnr(void)
137{
138 return g_bt_has_ecnr_value;
139}
140
141void set_bt_wbs(int wbs)
142{
143 if ((wbs < 0) || (wbs > 15)) {
144 RLOGE("set_bt_wbs() illegal value %d, we support 0~15", wbs);
145 return;
146 }
147
148 g_bt_wbs_value = wbs;
149}
150
151int get_bt_wbs(void)
152{
153 return g_bt_wbs_value;
154}
155
156int mixer_init()
157{
158 RLOGD("set_card_name: %s", g_card_name);
159 int ret;
160
161 // only need to set card name once
162 ret = set_card_name(g_card_name);
163 RLOGD("mixer_init(%s) = %d", g_card_name, ret);
164 return ret;
165}
166int mixer_set(int value )
167{
168 int ret;
169
170 //set mixer ctl to om:1 or off:0
171 if(value){
q.huang1c03f752023-12-14 14:11:58 +0800172 //ret = set_mixer_ctrl_value_int(isEcallAudioPath() ? g_mixer_name_ecall: g_mixer_name, value);
173 if(isEcallAudioPath())
174 {
175 exe_set_voice_audio_mode(AUDIO_MODE_CODEC);
176 }
177 else
178 {
179 exe_set_voice_audio_mode(AUDIO_MODE_RTP);
180 }
181 // RLOGD("mixer_set(%s) = %d, ret: %d", (isEcallAudioPath() ? g_mixer_name_ecall: g_mixer_name), value, ret);
182 } else {
183 exe_set_voice_audio_mode(AUDIO_MODE_ALL_CLOSE);
184/*
lh7b0674a2022-01-10 00:34:35 -0800185 ret = get_mixer_ctrl_value_int(g_mixer_name);
186 RLOGD("mixer_set(get_mixer_ctrl_value_int: %s) = %d", g_mixer_name, ret);
xja1c30b82022-01-25 16:13:48 +0800187 if(ret > 0) {
lh7b0674a2022-01-10 00:34:35 -0800188 ret = set_mixer_ctrl_value_int(g_mixer_name, value);
189 RLOGD("mixer_set(%s) = %d", g_mixer_name, ret);
190 } else {
191 ret = set_mixer_ctrl_value_int(g_mixer_name_ecall, value);
192 RLOGD("mixer_set(%s) = %d", g_mixer_name_ecall, ret);
193 }
q.huang1c03f752023-12-14 14:11:58 +0800194*/
lh7b0674a2022-01-10 00:34:35 -0800195 }
196
197
198 return ret;
199}
200int mixer_reset_set(int value )
201{
202 int ret;
203
204 // set mixer to reset:1
205 ret = set_mixer_ctrl_value_int(g_mixer_reset_name, value);
206 RLOGD("mixer_reset_set(%s) = %d", g_mixer_reset_name, ret);
207 return ret;
208}
209int bt_mixer_set(int value)
210{
211 int ret;
212
213 //set mixer ctrl to on:1 or off:0
214 // bt speech
215 int bt_has_ecnr = get_bt_has_ecnr();
216 int bt_wbs = get_bt_wbs();
217 ret = set_mixer_ctrl_value_int(g_bt_has_ecnr_name, bt_has_ecnr);
218 ret = set_mixer_ctrl_value_int(g_bt_wbs_name, bt_wbs);
219 ret = set_mixer_ctrl_value_int(g_mixer_name_bt, value);
220
221 if (ret)
222 RLOGE("set_mixer_ctrl_value_int err: %d", ret);
223 return ret;
224}
225
226int mixer_check(int mix)
227{
228 int ret;
229
230 if (mix == 0) {
231 ret = get_mixer_ctrl_value_int(g_mixer_name);
232 } else if (mix == 1){
233 ret = get_mixer_ctrl_value_int(g_mixer_name_bt);
234 } else {
235 RLOGE("mixer_check wrong mix %d", mix);
xja1c30b82022-01-25 16:13:48 +0800236 ret = -1;
lh7b0674a2022-01-10 00:34:35 -0800237 }
238 RLOGD("The ctrl \"%s\" is set to %d ", g_mixer_name, ret);
239 return ret;
240}
241int mixer_set_volume(int value)
242{
243 int ret;
244 if (get_audio_path() == 0) {
245 ret = set_mixer_ctrl_volume_value(g_mixer_name_volume, value);
246 } else {
247 ret = set_mixer_ctrl_volume_value(g_mixer_name_volume_bt, value);
248 }
249 if (ret)
250 RLOGE("set_mixer_ctrl_volume_value_int err: %d", ret);
251 return ret;
252}
253long int mixer_get_volume()
254{
255 long int vol_value;
256 if (get_audio_path() == 0) {
257 vol_value = get_mixer_ctrl_volume_value(g_mixer_name_volume);
258 } else {
259 vol_value = get_mixer_ctrl_volume_value(g_mixer_name_volume_bt);
260 }
lhb07f4e12022-02-17 22:08:54 -0800261 RLOGD("The ctrl \"%s\" is set to %ld", g_mixer_name_volume, vol_value);
lh7b0674a2022-01-10 00:34:35 -0800262 return vol_value;
263}
264
265GstElement *pipeline_element;
266GstState gst_cur_state = GST_STATE_NULL;
267static int gst_status = 0;
268
269int GSM_Init(char* filepath)
270{
271 GstElement *pipeline, *source, *mux, *encoder, *sink;
272 RLOGD("[GSM]GSM Init Start!");
273 /* Initialisation */
274 gst_init (NULL, NULL);
275
276 pipeline = gst_pipeline_new ("3gppmux-test");
277 source = gst_element_factory_make ("pulsesrc", "file-source");
278 encoder = gst_element_factory_make ("faac", "encoder");
279 mux = gst_element_factory_make ("3gppmux", "muxer");
280 sink = gst_element_factory_make ("filesink", "output");
281
282 g_object_set(mux, "fragment-duration", 100, NULL);
283 g_object_set(sink, "location", filepath, NULL);
284
285 if (!pipeline || !source || !encoder || !mux || !sink) {
286 if(pipeline) {
287 gst_object_unref (GST_OBJECT (pipeline));
288 pipeline = NULL;
289 }
290 if(source) {
291 gst_object_unref (GST_OBJECT (source));
292 source = NULL;
293 }
294 if(encoder) {
295 gst_object_unref (GST_OBJECT (encoder));
296 encoder = NULL;
297 }
298 if(mux) {
299 gst_object_unref (GST_OBJECT (mux));
300 mux = NULL;
301 }
302 if(sink) {
303 gst_object_unref (GST_OBJECT (sink));
304 sink = NULL;
305 }
306 RLOGE ("[GSM]One element could not be created. Exiting");
307 return -1;
308 }
309
310 gst_bin_add_many (GST_BIN (pipeline), source, encoder, mux, sink, NULL);
311 gst_element_link_many (source, encoder, mux, sink, NULL);
312
313 pipeline_element = pipeline;
314 gst_status = 1; //initial done
315 RLOGD("[GSM]GSM Init Done!");
316 return 0;
317}
318
319int GSM_Start(void)
320{
321 RLOGD("[GSM]GSM Start start!");
322 if(gst_status == 2)
323 return 0;
324
325 if(gst_status == 1 || gst_status ==3) {
326 GstStateChangeReturn ret = gst_element_set_state (pipeline_element, GST_STATE_PLAYING);
327
328 RLOGD("[GSM]Running... return: %d", ret);
329 //g_main_loop_run (gst_loop);
330 gst_status = 2; //start done
331 } else {
332 return -1;
333 }
334 RLOGD("[GSM]GSM Start End!");
335 return 0;
336}
337
338int GSM_Stop()
339{
340 RLOGD("[GSM]GSM Stop Start!");
341 if (gst_status == 4)
342 return 0;
343
344 if(gst_status == 2 || gst_status == 3) {
345 /* Out of the main loop, clean up nicely */
346 gboolean isSend = gst_element_send_event (pipeline_element, gst_event_new_eos ());
347 GstStateChangeReturn ret = gst_element_set_state (pipeline_element, GST_STATE_NULL);
348 RLOGD("[GSM]Returned, stopping playback. ret: %d, isSend: %d", ret, isSend);
349 gst_status = 4;
350 } else {
351 return -1;
352 }
353 RLOGD("[GSM]GSM Stop End!");
354 return 0;
355}
356
357int GSM_Close()
358{
359 RLOGD("[GSM]Deleting pipeline");
360 gst_object_unref (GST_OBJECT (pipeline_element));
361 gst_deinit ();
362 gst_status = 0;
363 RLOGD("[GSM]GSM Close Done!");
364 return 0;
365}
366/*cmd:1, address,
367*2, clirMode,
368*3, if present, uusinfo.type
369*4, as above, uusinfo.Dcs
370*5, as above, uusinfo.userdatalength
371*6, as above, uusinfo.UserData
372*/
373//RIL_REQUEST_DIAL
374int dial(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
375{
376 android::Parcel p;
377 size_t pos = p.dataPosition();
378
379 if (argc < 3 || argv[1]==NULL) {
380 //add log msg
381 free(pRI);
382 return -1;
383 }
384 //address;
385 writeStringToParcel(p, (const char *)argv[1]);
386 //clirMode
387 if (argc >=2) {
388 p.writeInt32(atoi(argv[2]));
389
390 if (argc == 7 && argv[3] != NULL
391 && argv[4] != NULL && argv[5] != NULL
392 && argv[6] != NULL ) {
393 p.writeInt32(1); // UUS information is present
394 p.writeInt32(atoi(argv[3]));
395 p.writeInt32(atoi(argv[4]));
396 p.writeByteArray((size_t)atoi(argv[5]),(uint8_t*)argv[6]);
397 } else {
398 p.writeInt32(0); // UUS information is absent
399 }
400 }
401 p.setDataPosition(pos);
q.huang1c03f752023-12-14 14:11:58 +0800402// setEcallAudioPathOn(false);
lh7b0674a2022-01-10 00:34:35 -0800403 pRI->pCI->dispatchFunction(p, pRI);
404 inCallstatus = CALL_ON;
405 return 0;
406}
407#if 0 //not need user setup
408//RIL_REQUEST_OEM_HOOK_STRINGS
409int invokeOemRilRequestStrings(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
410{
411 android::Parcel p;
412 size_t pos = p.dataPosition();
413 RLOGD("OEM_HOOK_STRINGS: p1->\"%s\",p2->\"%s\"",argv[1],argv[2]);
414 p.writeInt32(2);
415 writeStringToParcel(p, (const char *)argv[1]);
416 writeStringToParcel(p, "\"\"");//(const char *)argv[2]);
417 p.setDataPosition(pos);
418
419 pRI->pCI->dispatchFunction(p, pRI);
420 return 0;
421}
422#endif
423
424extern void ARspRequest (int request,RIL_SOCKET_ID socket_id);
425//RIL_REQUEST_SET_AUDIO_PATH
426/*cmd:1, speech mode,
427*2, bt_has_ecnr
428*3, bt_wbs
429*/
430int setAudioPath(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
431{
432 if (argc < 1) {
433 free(pRI);
434 RLOGE("set bt mode need bt_has_encr and bt_wbs");
435 return -1;
436 }
437
438 int temp_audio_path = atoi(argv[1]);
439 int bt_has_ecnr;
440 int bt_wbs;
441 int current_audio_path = get_audio_path();
442 RLOGD("setAudioPath enter");
443 if ((temp_audio_path != 0) && (temp_audio_path != 1)) {
444 RLOGE("audio path illegal %d, only support 0 and 1", temp_audio_path);
445 return -1;
446 }
447 set_audio_path(temp_audio_path);
448 RLOGD("set audio path to %d, current audio path is %d", temp_audio_path, current_audio_path);
449 if (temp_audio_path == 1) {
450 /* bt speech need BT_HAS_ECNR and BT_WBS */
451 bt_has_ecnr = atoi(argv[2]);
452 bt_wbs = atoi(argv[3]);
453 set_bt_has_ecnr(bt_has_ecnr);
454 set_bt_wbs(bt_wbs);
455 RLOGD("set bt_has_ecnr %d, bt_wbs %d", bt_has_ecnr, bt_wbs);
456 }
457 if ((current_audio_path != temp_audio_path)
458 && (get_call_status() == CALL_ON)) {
459 if (current_audio_path == 0) {
460 if (getSpeechStatus() == NORMAL_SPEECH_ON) {
461 RLOGD("normal speech off then bt speech on");
462 mixer_set(0);
463 setSpeechAndStatus(2);
464 }
465 } else {
466 if (getSpeechStatus() == BT_SPEECH_ON) {
467 RLOGD("bt speech off then normal speech on");
468 bt_mixer_set(0);
469 setSpeechAndStatus(1);
470 }
471 }
472 }
473 if (pRI != NULL) {
474 free(pRI);
475 }
476
477 RLOGD("setAudioPath done");
478 return 0;
479}
480
481
482//RIL_REQUEST_HANGUP
483int hangupConnection(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
484{
485 android::Parcel p;
486 size_t pos = p.dataPosition();
487
488 p.writeInt32(1);
489 p.writeInt32(atoi(argv[1]));
490 p.setDataPosition(pos);
491
492 pRI->pCI->dispatchFunction(p, pRI);
493 return 0;
494}
495
496//RIL_REQUEST_FORCE_RELEASE_CALL
497int forceReleaseCall(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
498{
499 android::Parcel p;
500 size_t pos = p.dataPosition();
501
502 p.writeInt32(1);
503 p.writeInt32(atoi(argv[1]));
504 p.setDataPosition(pos);
505
506 pRI->pCI->dispatchFunction(p, pRI);
507 return 0;
508}
509
510//RIL_REQUEST_SEPARATE_CONNECTION
511int separateConnection(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
512{
513 android::Parcel p;
514 size_t pos = p.dataPosition();
515
516 p.writeInt32(1);
517 p.writeInt32(atoi(argv[1]));
518 p.setDataPosition(pos);
519
520 pRI->pCI->dispatchFunction(p, pRI);
521 return 0;
522}
523//RIL_REQUEST_DTMF
524//RIL_REQUEST_DTMF_START
525int sendDtmf(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
526{
527 android::Parcel p;
528 int number;
529 size_t pos = p.dataPosition();
530 char * c_num = NULL;
531
532 c_num = argv[1];
533 if (c_num == NULL) {
534 free(pRI);
535 return -1;
536 }
537 number = int(c_num[0] - '0');
538 if(number == -6)
539 number = 10;
540 if(number == -13)
541 number = 11;
542 RLOGD("DTMF input number is %s-->%d",c_num,number);
543 if ( number < 0 || number > 15 ) {
544 RLOGE("DTMF input number error");
545 free(pRI);
546 return -1;
547 }
548
549 writeStringToParcel(p, (const char *)argv[1]);
550 p.setDataPosition(pos);
551
552 dtmf_stop(dtmf_handle);
553 gint time_ms = 500;
554 if (pRI->pCI->requestNumber == RIL_REQUEST_DTMF_START) {
555 time_ms = 0;
556 }
557 RLOGD("request: %d, time_ms = %d", pRI->pCI->requestNumber, time_ms);
558 dtmf_handle = dtmf_start(number, time_ms, dtmf_volume, NULL);
559 pRI->pCI->dispatchFunction(p, pRI);
560 if (dtmf_handle == NULL)
561 RLOGE("[DTMF] dtmf_start return NULL!");
562 return 0;
563}
564
565//RIL_REQUEST_UDUB
566int rejectCall(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
567{
568 android::Parcel p;
569
570 pRI->pCI->dispatchFunction(p, pRI);
571 return 0;
572}
573//RIL_REQUEST_ANSWER
574int acceptCall(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
575{
576 android::Parcel p;
577
578 pRI->pCI->dispatchFunction(p, pRI);
579 inCallstatus = CALL_ON;
580 return 0;
581}
582
583//RIL_REQUEST_HANGUP_ALL
584int hangupAll(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
585{
586 android::Parcel p;
587
588 pRI->pCI->dispatchFunction(p, pRI);
589 return 0;
590}
591
592//RIL_REQUEST_CONFERENCE
593int conference(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
594{
595 android::Parcel p;
596
597 pRI->pCI->dispatchFunction(p, pRI);
598 return 0;
599}
600//RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND
601int hangupWaitingOrBackground(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
602{
603 android::Parcel p;
604
605 pRI->pCI->dispatchFunction(p, pRI);
606 return 0;
607}
608//RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE
609int switchWaitingOrHoldingAndActive(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
610{
611 android::Parcel p;
612
613 pRI->pCI->dispatchFunction(p, pRI);
614 return 0;
615}
616//RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND
617int hangupForegroundResumeBackground(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
618{
619 android::Parcel p;
620
621 pRI->pCI->dispatchFunction(p, pRI);
622 return 0;
623}
624//RIL_REQUEST_EXPLICIT_CALL_TRANSFER
625int explicitCallTransfer(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
626{
627 android::Parcel p;
628
629 pRI->pCI->dispatchFunction(p, pRI);
630 return 0;
631}
632
633//RIL_REQUEST_ADD_IMS_CONFERENCE_CALL_MEMBER
634int addImsConferenceCallMember(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
635{
636 android::Parcel p;
637 size_t pos = p.dataPosition();
638
639 p.writeInt32(3);
640 writeStringToParcel(p, (const char *)argv[1]);//confCallId
641 writeStringToParcel(p, (const char *)argv[2]);//address
642 writeStringToParcel(p, (const char *)argv[3]);//CallIdToAdd
643
644 p.setDataPosition(pos);
645 pRI->pCI->dispatchFunction(p, pRI);
646 return 0;
647}
648//RIL_REQUEST_REMOVE_IMS_CONFERENCE_CALL_MEMBER
649int removeImsConferenceCallMember(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
650{
651 android::Parcel p;
652 size_t pos = p.dataPosition();
653
654 p.writeInt32(3);
655 writeStringToParcel(p, (const char *)argv[1]);//confCallId
656 writeStringToParcel(p, (const char *)argv[2]);//address
657 writeStringToParcel(p, (const char *)argv[3]);//CallIdToRemove
658
659 p.setDataPosition(pos);
660 pRI->pCI->dispatchFunction(p, pRI);
661 return 0;
662}
663//RIL_REQUEST_CONFERENCE_DIAL
664//argv[1]:DialMethod
665//argv[2]:ParticipantsNumber
666//argv[2+ParticipantsNumber]:addresss
667//argv[2+ParticipantsNumber+1]:clir
668int conferenceDial(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
669{
670 android::Parcel p;
671 size_t pos = p.dataPosition();
672 int ParticipantsNumber,i;
673
674 if( argc < 3 ) {
675 free(pRI);
676 RLOGE("Error: conference Dial parameter is error!");
677 return -1;
678 }
679
680 ParticipantsNumber = atoi(argv[2]);
681
682 if( argc < (ParticipantsNumber+3) ) {
683 free(pRI);
684 RLOGE("Error: Dial With SIP URI parameter is error! \
685 argc is %d, and need parameter %d",argc,(ParticipantsNumber+3));
686 return -1;
687 }
688
689 p.writeInt32((ParticipantsNumber+3));
690 writeStringToParcel(p, (const char *)argv[1]); //DialMethod
691 writeStringToParcel(p, (const char *)argv[2]); //ParticipantsNumber
692 for( i=0; i<ParticipantsNumber; i++ ){ //address
693 writeStringToParcel(p, (const char *)argv[3+i]);
694 }
695 writeStringToParcel(p, (const char *)argv[3+ParticipantsNumber]);//clir
696
697 p.setDataPosition(pos);
698 setEcallAudioPathOn(false);
699 pRI->pCI->dispatchFunction(p, pRI);
700 return 0;
701}
702//RIL_REQUEST_DIAL_WITH_SIP_URI
703int dialWithSipUri(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
704{
705 android::Parcel p;
706 size_t pos = p.dataPosition();
707
708 if (argc < 3 || argv[1]==NULL) {
709 free(pRI);
710 return -1;
711 }
712
713 writeStringToParcel(p, (const char *)argv[1]);//address
714 /* for compatibility of test script, still receive clirMode and UUS,
715 but don't send them to libvendor-ril */
716#if 0
717 p.writeInt32(atoi(argv[2]));//clirMode
718 p.writeInt32(0); // UUS information is absent
719#endif
720
721 p.setDataPosition(pos);
q.huang1c03f752023-12-14 14:11:58 +0800722// setEcallAudioPathOn(false);
lh7b0674a2022-01-10 00:34:35 -0800723 pRI->pCI->dispatchFunction(p, pRI);
724 return 0;
725}
726//RIL_REQUEST_HOLD_CALL
727int holdCall(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
728{
729 android::Parcel p;
730 size_t pos = p.dataPosition();
731
732 if (argc < 2 || argv[1]==NULL) {
733 free(pRI);
734 return -1;
735 }
736
737 //callIDToHold
738 p.writeInt32(1);
739 p.writeInt32(atoi(argv[1]));
740
741 p.setDataPosition(pos);
742
743 pRI->pCI->dispatchFunction(p, pRI);
744 return 0;
745}
746//RIL_REQUEST_RESUME_CALL
747int resumeCall(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
748{
749 android::Parcel p;
750 size_t pos = p.dataPosition();
751
752 if (argc < 2 || argv[1]==NULL) {
753 free(pRI);
754 return -1;
755 }
756
757 //callIDToResume
758 p.writeInt32(1);
759 p.writeInt32(atoi(argv[1]));
760
761 p.setDataPosition(pos);
762
763 pRI->pCI->dispatchFunction(p, pRI);
764 return 0;
765}
766int getCurrentCalls(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
767{
768 android::Parcel p;
769
770 pRI->pCI->dispatchFunction(p, pRI);
771 return 0;
772}
773int autoAnswerCall(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
774{
775 if(argc < 2) {
776 RLOGW("[error],set auto answer call parameter error!");
777 free(pRI);
778 return 0;
779 }
780 //need add lock to pretect.
781 autoAnswerMode = atoi(argv[1]) ? 1 : 0;
782 RLOGD("SetAutoAnserMode is %s",autoAnswerMode ? "On" :"Off");
783 if(pRI) {
784 free(pRI);
785 }
786 return 0;
787}
788
789int inCallRecord(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
790{
q.huangec88da92022-03-29 04:17:32 -0400791 android::Parcel p;
lh7b0674a2022-01-10 00:34:35 -0800792 int recordEnable = 0;
793 char* filepath = NULL;
794 if(inCallstatus == CALL_OFF || speechStatus == SPEECH_OFF) {
795 RLOGW("[warning],not in calling status. Can't do record!");
q.huangec88da92022-03-29 04:17:32 -0400796 goto FAIL_RETURN;
lh7b0674a2022-01-10 00:34:35 -0800797 }
798
q.huangec88da92022-03-29 04:17:32 -0400799 if(argc < 3) {
lh7b0674a2022-01-10 00:34:35 -0800800 RLOGW("[error],inCallRecord parameter error!");
q.huangec88da92022-03-29 04:17:32 -0400801 goto FAIL_RETURN;
lh7b0674a2022-01-10 00:34:35 -0800802 }
803
804 recordEnable = atoi(argv[1]) ? 1 : 0;
805 RLOGD("InCall record %s!",recordEnable ? "enable" : "disable");
806 filepath = argv[2];
807 RLOGD("InCall record file path as \'%s\'",filepath);
808
809 if (recordEnable == 1) {//enable record
810 RLOGD("start GSM!");
811 if(-1 != GSM_Init(filepath) && -1 != GSM_Start()) {
812 inCallRecordMode = 1;
813 RLOGW("inCallRecord Start OK!");
814 }else{
815 inCallRecordMode = 0;
816 RLOGW("[error],inCallRecord Start fail!");
q.huangec88da92022-03-29 04:17:32 -0400817 goto FAIL_RETURN;
lh7b0674a2022-01-10 00:34:35 -0800818 }
819 } else { //disable record
820 if (inCallRecordMode == 1) {
lh7b0674a2022-01-10 00:34:35 -0800821 inCallRecordMode = 0;
q.huangec88da92022-03-29 04:17:32 -0400822 if(!(-1 != GSM_Stop() && -1 != GSM_Close()))
823 {
824 RLOGW("[error],inCallRecord fail!");
825 goto FAIL_RETURN;
826 }
lh7b0674a2022-01-10 00:34:35 -0800827 }
828 }
q.huangec88da92022-03-29 04:17:32 -0400829 if(pRI != NULL) {
q.huangadbad2f2022-09-15 16:28:02 +0800830 android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,LYNQ_REQUEST_RECORD,0,0);
q.huangec88da92022-03-29 04:17:32 -0400831 android::LYNQ_RIL_respSocket_sp(p,pRI);
lh7b0674a2022-01-10 00:34:35 -0800832 free(pRI);
q.huangec88da92022-03-29 04:17:32 -0400833 }
lh7b0674a2022-01-10 00:34:35 -0800834 return 0;
q.huangec88da92022-03-29 04:17:32 -0400835FAIL_RETURN:
836 if(pRI != NULL) {
q.huangadbad2f2022-09-15 16:28:02 +0800837 android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,LYNQ_REQUEST_RECORD,0,2);
q.huangec88da92022-03-29 04:17:32 -0400838 android::LYNQ_RIL_respSocket_sp(p,pRI);
839 free(pRI);
840 }
841 return -1;
lh7b0674a2022-01-10 00:34:35 -0800842}
843
844int StopRecord()
845{
846 RLOGD("After Handup, stop record! Before Record is %s",inCallRecordMode ? "Enable" : "Disable");
847 if (inCallRecordMode == 1) {
848 if(!(-1 != GSM_Stop() && -1 != GSM_Close()))
849 RLOGW("[error],inCallRecord fail!");
850
851 inCallRecordMode = 0;
852 /*From GSM report stop_record to PulseAudio send record_off need 15ms. so after stop record delay 30ms*/
853 usleep(30*1000);
854 }
855 return 0;
856}
857
858int setSpeechVolume(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
859{
q.huangec88da92022-03-29 04:17:32 -0400860 android::Parcel p;
lh7b0674a2022-01-10 00:34:35 -0800861 int setValue = 0;
862 RLOGD("setSpeechVolume start!");
863
864 if(argc < 2) {
q.huangadbad2f2022-09-15 16:28:02 +0800865 android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,LYNQ_REQUEST_SET_SPEECH_VOLUME,0,2);
q.huangec88da92022-03-29 04:17:32 -0400866 android::LYNQ_RIL_respSocket_sp(p,pRI);
lh7b0674a2022-01-10 00:34:35 -0800867 free(pRI);
868 RLOGW("Warning: no set volume value!");
869 return -1;
870 }
871
872 setValue = atoi(argv[1]);
873 RLOGD("set Speech Volume value is %d!",setValue);
874 if (get_audio_path() == 0) {
875 if(setValue < MIN_VOLUME || setValue > MAX_VOLUME) {
876 RLOGW("Warning: set volume value is over-range!");
q.huangadbad2f2022-09-15 16:28:02 +0800877 android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,LYNQ_REQUEST_SET_SPEECH_VOLUME,0,2);
q.huangec88da92022-03-29 04:17:32 -0400878 android::LYNQ_RIL_respSocket_sp(p,pRI);
879 free(pRI);
lh7b0674a2022-01-10 00:34:35 -0800880 return -1;
881 }
882 } else {
883 if(setValue < BT_MIN_VOLUME || setValue > BT_MAX_VOLUME) {
884 RLOGW("Warning: set bt volume value is over-range!");
q.huangadbad2f2022-09-15 16:28:02 +0800885 android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,LYNQ_REQUEST_SET_SPEECH_VOLUME,0,2);
q.huangec88da92022-03-29 04:17:32 -0400886 android::LYNQ_RIL_respSocket_sp(p,pRI);
887 free(pRI);
lh7b0674a2022-01-10 00:34:35 -0800888 return -1;
889 }
890 }
891 //paramter is from 1 to 7
892 mixer_set_volume(setValue);
q.huangadbad2f2022-09-15 16:28:02 +0800893 android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,LYNQ_REQUEST_SET_SPEECH_VOLUME,0,0);
q.huangec88da92022-03-29 04:17:32 -0400894 printf(">>>>set speech Volume<<<< success value is %d!\n",setValue);
895 /*Warren add for t800 ril service 2021/12/23 end*/
896 android::LYNQ_RIL_respSocket_sp(p,pRI);
lh7b0674a2022-01-10 00:34:35 -0800897 free(pRI);
898 return 0;
899}
q.huangec88da92022-03-29 04:17:32 -0400900int getSpeechVolume(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
901{
902 android::Parcel p;
903 printf("WARREN TEST001!!!\n");
904 int volumn = mixer_get_volume();
905 //TBC -200 fail status
906 if(volumn <0) {
907 printf("get speech volumn fail, please check whether does call exsit.\n");
908 /*Warren add for t800 ril service 2021/12/23 start*/
q.huangadbad2f2022-09-15 16:28:02 +0800909 android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,LYNQ_REQUEST_GET_SPEECH_VOLUME,0,2);
q.huangec88da92022-03-29 04:17:32 -0400910 /*Warren add for t800 ril service 2021/12/23 end*/
911 } else {
912 /*Warren add for t800 ril service 2021/12/23 start*/
q.huangadbad2f2022-09-15 16:28:02 +0800913 android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,LYNQ_REQUEST_GET_SPEECH_VOLUME,0,0);
q.huangec88da92022-03-29 04:17:32 -0400914 /*Warren add for t800 ril service 2021/12/23 end*/
915 }
916 printf("current Speech Volume is%d",volumn);
917 p.writeInt32(volumn);
918 android::LYNQ_RIL_respSocket(p,(void *)pRI);
919 if(pRI) {
920 free(pRI);
921 }
922 return 0;
923}
lh7b0674a2022-01-10 00:34:35 -0800924int setDtmfVolume(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
925{
q.huangec88da92022-03-29 04:17:32 -0400926 android::Parcel p;
lh7b0674a2022-01-10 00:34:35 -0800927 int setValue = 0;
lh7b0674a2022-01-10 00:34:35 -0800928 RLOGD("setDtmfVolume start!");
929 printf("setDtmfVolume start!\n");
930 if(argc < 2) {
931 RLOGW("Warning: no set volume value!");
932 printf("Warning: no set volume value!\n");
q.huangadbad2f2022-09-15 16:28:02 +0800933 android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,LYNQ_REQUEST_SET_DTMF_VOLUME,0,2);
q.huangec88da92022-03-29 04:17:32 -0400934 android::LYNQ_RIL_respSocket_sp(p,pRI);
lh7b0674a2022-01-10 00:34:35 -0800935 free(pRI);
936 return -1;
937 }
938
939 setValue = atoi(argv[1]);
940 RLOGD("set dtmf Volume value is %d!",setValue);
941 printf("set dtmf Volume value is %d!\n",setValue);
942 if(setValue < DTMF_MIN_VOLUME || setValue > DTMF_MAX_VOLUME) {
943 RLOGW("Warning: set volume value is over-range!");
944 printf("set dtmf Volume value is %d!\n",setValue);
945 /*Warren add for t800 ril service 2021/12/23 start*/
q.huangadbad2f2022-09-15 16:28:02 +0800946 android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,LYNQ_REQUEST_SET_DTMF_VOLUME,0,2);
lh7b0674a2022-01-10 00:34:35 -0800947 android::LYNQ_RIL_respSocket_sp(p,pRI);
948 /*Warren add for t800 ril service 2021/12/23 end*/
949 free(pRI);
950 return -1;
951 }
952 //paramter is from 0 to 36
953 dtmf_volume = setValue;
954 printf(">>>>set dtmf Volume<<<< success value is %d!\n",setValue);
955 /*Warren add for t800 ril service 2021/12/23 start*/
q.huangadbad2f2022-09-15 16:28:02 +0800956 android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,LYNQ_REQUEST_SET_DTMF_VOLUME,0,0);
lh7b0674a2022-01-10 00:34:35 -0800957 printf(">>>>set dtmf Volume<<<< success value is %d!\n",setValue);
958 /*Warren add for t800 ril service 2021/12/23 end*/
959 android::LYNQ_RIL_respSocket_sp(p,pRI);
960 free(pRI);
961 return 0;
962}
963
964speech_status getSpeechStatus()
965{
966 return speechStatus;
967}
968
969void setSpeechAndStatus(int value)
970{
971 RLOGD("setSpeechAndStatus value: %d, speechStatus: %d", value, speechStatus);
972 if (value == 1) {
973 speechStatus = NORMAL_SPEECH_ON;
974 mixer_set(1);
975 } else if (value == 2) {
976 speechStatus = BT_SPEECH_ON;
977 bt_mixer_set(1);
978 } else if (value == 0) {
979 speechStatus == BT_SPEECH_ON ? bt_mixer_set(0) : mixer_set(0);
980 speechStatus = SPEECH_OFF;
981 } else {
982 RLOGE("set speech value is invaild!\n");
983 }
984}
985//RIL_REQUEST_EMERGENCY_DIAL
986/*cmd:1, address,
987*2, clirMode,
988*3, if present, uusinfo.type
989*4, as above, uusinfo.Dcs
990*5, as above, uusinfo.userdatalength
991*6, as above, uusinfo.UserData
992*/
993int emergencyDial(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
994{
995 android::Parcel p;
996 size_t pos = p.dataPosition();
997
998 if (argc < 3 || argv[1] == NULL)
999 {
1000 //add log msg
1001 free(pRI);
1002 return -1;
1003 }
1004 //address;
1005 writeStringToParcel(p, (const char *) argv[1]);
1006 //clirMode
1007 if (argc >= 2)
1008 {
1009 p.writeInt32(atoi(argv[2]));
1010
1011 if (argc == 7&& argv[3] != NULL
1012 && argv[4] != NULL && argv[5] != NULL
1013 && argv[6] != NULL)
1014 {
1015 p.writeInt32(1); // UUS information is present
1016 p.writeInt32(atoi(argv[3]));
1017 p.writeInt32(atoi(argv[4]));
1018 p.writeByteArray((size_t) atoi(argv[5]), (uint8_t*) argv[6]);
1019 } else
1020 {
1021 p.writeInt32(0); // UUS information is absent
1022 }
1023 }
1024 p.setDataPosition(pos);
q.huang1c03f752023-12-14 14:11:58 +08001025//setEcallAudioPathOn(false);
lh7b0674a2022-01-10 00:34:35 -08001026 pRI->pCI->dispatchFunction(p, pRI);
1027 return 0;
1028}
1029//RIL_REQUEST_SET_ECC_SERVICE_CATEGORY
1030int setEccServiceCategory(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
1031{
1032 android::Parcel p;
1033 size_t pos = p.dataPosition();
1034
1035 //if ( getSpeechStatus() != 1)
1036 // setSpeechAndStatus(1);
1037
1038 p.writeInt32(1);
1039 p.writeInt32(atoi(argv[1]));
1040 p.setDataPosition(pos);
1041 pRI->pCI->dispatchFunction(p, pRI);
1042 return 0;
1043}
1044//RIL_REQUEST_SET_ECC_LIST
1045/* argv[1]: list number
1046 argv[2+i]: ECC string
1047 argv[3+i]: Categroy
1048 argv[4+i]: Conditon
1049*/
1050int setEccList(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
1051{
1052 android::Parcel p;
1053 size_t pos = p.dataPosition();
1054 int num = 0;
1055 //if ( getSpeechStatus() != 1)
1056 // setSpeechAndStatus(1);
1057 if(argc < 3) {
1058 RLOGE("%s parameter error!",__func__);
1059 free(pRI);
1060 return -1;
1061 }
1062 num = atoi(argv[1]);
1063 RLOGD("list number is %d, argc is %d",num, argc);
1064 if((num == 0) || ((argc-2) < num*3)) {
1065 RLOGE("%s parameter error!",__func__);
1066 free(pRI);
1067 return -1;
1068 }
1069
1070 p.writeInt32(num*3);
1071 for(int i = 0; i < num; i++){
1072 writeStringToParcel(p, (const char *)argv[2+i*3+0]); //ECC
1073 writeStringToParcel(p, (const char *)argv[2+i*3+1]); //Category
1074 writeStringToParcel(p, (const char *)argv[2+i*3+2]); //Condition
1075 RLOGD("list[%d],ECC is %s, Category is %s, Condition is %s!",i+1,argv[2+i*3+0],argv[2+i*3+1],argv[2+i*3+2]);
1076 }
1077 p.setDataPosition(pos);
1078 pRI->pCI->dispatchFunction(p, pRI);
1079 return 0;
1080}
1081
1082//RIL_REQUEST_SET_ECC_NUM
1083int setEccNum(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
1084{
1085 android::Parcel p;
1086 size_t pos = p.dataPosition();
1087 int num = 0;
1088
1089 if(argc < 2 || argc > 3) {
1090 RLOGE("%s parameter error!",__func__);
1091 free(pRI);
1092 return -1;
1093 }
1094
1095 num = (argc > 2)?2:1;
1096
1097 p.writeInt32(num);
1098 writeStringToParcel(p, (const char *)argv[1]); //ECC number with card
1099 RLOGD("Set ECC number with card: %s",argv[1]);
1100 if (num>1){
1101 writeStringToParcel(p, (const char *)argv[2]); //ECC number without card
1102 RLOGD("Set ECC number without card: %s",argv[2]);
1103 }
1104 p.setDataPosition(pos);
1105 pRI->pCI->dispatchFunction(p, pRI);
1106 return 0;
1107}
1108
1109//RIL_REQUEST_GET_ECC_NUM
1110int getEccNum(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
1111{
1112 android::Parcel p;
1113 pRI->pCI->dispatchFunction(p, pRI);
1114 return 0;
1115}
1116
1117int handleECCNumResponse(const void *data, int datalen, RIL_SOCKET_ID socket_id){
1118 if (data == NULL || datalen <= 0){
1119 RLOGE("%s parameter error!",__func__);
1120 return -1;
1121 }
1122
1123 printf("[ECC NUM][Slot%d] %s\n", socket_id, (const char*)data);
1124 RLOGD("[ECC NUM][Slot%d] %s\n", socket_id, (const char*)data);
1125 return 0;
1126}
1127
1128
1129//RIL_REQUEST_LAST_CALL_FAIL_CAUSE
1130int getLastCallFailCause(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI) {
1131 if(argc != 1)
1132 {
1133 RLOGD("the peremeters numbers isn't right , so return");
1134 free(pRI);
1135 return -1;
1136 }
1137 RLOGD("getLastCallFailCause %d: " , pRI->pCI->requestNumber);
1138 android::Parcel p;
1139
1140 pRI->pCI->dispatchFunction(p, pRI);
1141 return 0;
1142}
1143
1144//#ifdef C2K_SUPPORT
1145static bool is12Key(char c) {
1146 return (c >= '0' && c <= '9') || c == '*' || c == '#';
1147}
1148
1149//RIL_REQUEST_CDMA_BURST_DTMF
1150int sendBurstDtmf(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI){
1151 if(argc < 4) {
1152 RLOGE("%s parameter error!",__func__);
1153 free(pRI);
1154 return -1;
1155 }
1156 int number;
1157 char * c_num = NULL;
1158
1159 c_num = argv[1];
1160 if (c_num == NULL) {
1161 free(pRI);
1162 return -1;
1163 }
1164 number = int(c_num[0] - '0');
1165 if(number == -6)
1166 number = 10;
1167 if(number == -13)
1168 number = 11;
1169 RLOGD("DTMF input number is %s-->%d",c_num,number);
1170 if ( number < 0 || number > 15 ) {
1171 RLOGE("DTMF input number error");
1172 free(pRI);
1173 return -1;
1174 }
1175 dtmf_stop(dtmf_handle);
1176 dtmf_handle = dtmf_start(number, 500, dtmf_volume, NULL);
1177 android::Parcel p;
1178 size_t pos = p.dataPosition();
1179 p.writeInt32(3);
1180 writeStringToParcel(p, c_num);
1181 writeStringToParcel(p, argv[2]);
1182 writeStringToParcel(p, argv[3]);
1183 p.setDataPosition(pos);
1184 pRI->pCI->dispatchFunction(p, pRI);
1185 if (dtmf_handle == NULL)
1186 RLOGE("[DTMF] dtmf_start return NULL!");
1187 return 0;
1188}
1189
1190//RIL_REQUEST_CDMA_FLASH
1191int sendCDMAFeatureCode(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI){
1192 if(argc > 2)
1193 {
1194 RLOGD("the peremeters numbers isn't right , so return");
1195 free(pRI);
1196 return -1;
1197 }
1198 android::Parcel p;
1199 size_t pos = p.dataPosition();
1200 writeStringToParcel(p, ((argc == 1) ? "" : argv[1]));
1201 p.setDataPosition(pos);
1202 pRI->pCI->dispatchFunction(p, pRI);
1203 return 0;
1204}
1205//#endif /*C2K_SUPPORT*/
1206
1207static int mixer_set_mute(int path, int value)
1208{
1209 RLOGD("mixer_set_mute path: %d , value: %d", path, value);
1210 int ret;
1211 /* DL:0 UL:1 */
1212 if (path == 0) {
1213 ret = set_mixer_ctrl_value_int(g_DL_mute_name, value);
1214 } else {
1215 ret = set_mixer_ctrl_value_int(g_UL_mute_name, value);
1216 }
1217 if (ret) {
1218 RLOGE("set_mixer_ctrl_volume_value_int err: %d", ret);
1219 }
1220 return ret;
1221}
1222
1223static long int mixer_get_mute(int path)
1224{
1225 long int is_mute;
1226
1227 /* DL:0 UL:1 */
1228 if (path == 0) {
1229 is_mute = get_mixer_ctrl_value_int(g_DL_mute_name);
lhb07f4e12022-02-17 22:08:54 -08001230 RLOGD("The ctrl \"%s\" is set to %ld", g_DL_mute_name, is_mute);
lh7b0674a2022-01-10 00:34:35 -08001231 } else {
1232 is_mute = get_mixer_ctrl_value_int(g_UL_mute_name);
lhb07f4e12022-02-17 22:08:54 -08001233 RLOGD("The ctrl \"%s\" is set to %ld", g_UL_mute_name, is_mute);
lh7b0674a2022-01-10 00:34:35 -08001234 }
1235
1236 return is_mute;
1237}
1238
1239static int setCallMute(bool mute) {
1240 RLOGD("setCallMute: %d", mute);
1241 return mixer_set_mute(1, (mute ? 1: 0));
1242}
1243
1244int getCallMute() {
1245 long int cc_mute = mixer_get_mute(1);
lhb07f4e12022-02-17 22:08:54 -08001246 RLOGD("getCallMute: %ld", cc_mute);
lh7b0674a2022-01-10 00:34:35 -08001247 return cc_mute;
1248}
1249
1250void resetMute() {
1251 if (getCallMute() > 0) {
1252 setCallMute(false);
1253 }
1254}
1255
1256void callRing(RIL_SOCKET_ID soc_id)
1257{
lh7b0674a2022-01-10 00:34:35 -08001258 if (autoAnswerMode) {
1259 RLOGD("Auto Answer MT Call!");
1260 android::requestAnswer(soc_id);
1261 }
1262 return;
1263}
1264
1265void autoAnswerForCdma(RIL_SOCKET_ID socket_id)
1266{
1267 resetMute();
1268 if (autoAnswerMode) {
1269 RLOGD("Auto Answer MT Call for cdma");
1270 ARspRequest(RIL_REQUEST_CDMA_FLASH, socket_id);
1271 }
1272 return;
1273}
1274
1275//void callStateChange(void)
1276void speechonoff(int callnum)
1277{
1278 static int callIndex = 0;
1279 RLOGD("callnum = %d, Call State Change then judge speech on/off!", callnum);
1280 callIndex = callnum;
q.huang1c03f752023-12-14 14:11:58 +08001281 lock_rtp_audio_mtx();
1282 if( callIndex > 0 && speechStatus == SPEECH_OFF) { //speech on
lh7b0674a2022-01-10 00:34:35 -08001283 //RLOGD("DemoAPP Call shell command (pactl set-card-profile 0 phonecall)");
1284 //system("pactl set-card-profile 0 phonecall");
1285 //RLOGD("DemoAPP Call shell command end");
you.chen297fc092023-12-21 17:11:20 +08001286 set_codec(LYNQ_CALL, CODEC_CLOSE); //hqing add for Geely demand on 11/07/2022, init cs call, open codec
lh7b0674a2022-01-10 00:34:35 -08001287 if (get_audio_path() == 0) {
1288 mixer_set(1);
1289 speechStatus = NORMAL_SPEECH_ON;
1290 } else {
1291 bt_mixer_set(1);
1292 speechStatus = BT_SPEECH_ON;
1293 }
1294 inCallstatus = CALL_ON;
q.huang1c03f752023-12-14 14:11:58 +08001295 unlock_rtp_audio_mtx();
lh7b0674a2022-01-10 00:34:35 -08001296 RLOGD("[speech]: set on");
1297 sendCallMsg(true); //for Power Manager test
1298 } else if (callIndex == 0
1299 && (speechStatus == NORMAL_SPEECH_ON
1300 || speechStatus == BT_SPEECH_ON)) { //speech off
1301 StopRecord();
1302 sendCallMsg(false); // for Power Manager test.
1303 dtmf_stop(dtmf_handle);
lhb07f4e12022-02-17 22:08:54 -08001304 dtmf_handle = NULL;
lh7b0674a2022-01-10 00:34:35 -08001305 if (speechStatus == NORMAL_SPEECH_ON) {
1306 mixer_set(0);
1307 } else {
1308 bt_mixer_set(0);
1309 }
1310 //RLOGD("DemoAPP Call shell command (pactl set-card-profile 0 HiFi)");
1311 //system("pactl set-card-profile 0 HiFi");
1312 //RLOGD("DemoAPP Call(pactl set-card-profile 0 HiFi) command end");
1313 speechStatus = SPEECH_OFF;
1314 inCallstatus = CALL_OFF;
1315 resetMute();
q.huang1c03f752023-12-14 14:11:58 +08001316 unlock_rtp_audio_mtx();
you.chen297fc092023-12-21 17:11:20 +08001317 set_codec(LYNQ_CALL, CODEC_OPEN); //hqing add for Geely demand on 11/07/2022, after cs call, close codec for power Manager
lh7b0674a2022-01-10 00:34:35 -08001318 RLOGD("[speech]: set off");
1319 } else {
q.huang1c03f752023-12-14 14:11:58 +08001320 unlock_rtp_audio_mtx();
lh7b0674a2022-01-10 00:34:35 -08001321 RLOGD("callIndex is %d, speechStatus is %d.",callIndex, speechStatus);
1322 }
1323
1324 return;
1325}
1326
1327//RIL_REQUEST_SET_MUTE
1328int setMute(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
1329{
q.huangec88da92022-03-29 04:17:32 -04001330 android::Parcel p;
lh7b0674a2022-01-10 00:34:35 -08001331 printf("WARREN TEST002!!!\n");
1332 if(argc<2)
1333 {
1334 if(pRI)
1335 {
1336 free(pRI);
1337 }
1338 return -1;
1339 }
1340 bool mute = (atoi(argv[1]) > 0) ? true: false;
1341 RLOGD("set mute %s", ((atoi(argv[1]) > 0) ? "on": "off"));
1342 int ret = setCallMute(mute);
1343 if(ret) {
1344 /*Warren add for t800 ril service 2021/12/23 start*/
q.huangadbad2f2022-09-15 16:28:02 +08001345 android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,RIL_REQUEST_SET_MUTE,0,2);
lh7b0674a2022-01-10 00:34:35 -08001346 /*Warren add for t800 ril service 2021/12/23 start*/
1347 printf("set mute fail, please try agian\n");
1348 } else {
1349 /*Warren add for t800 ril service 2021/12/23 start*/
q.huangadbad2f2022-09-15 16:28:02 +08001350 android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,RIL_REQUEST_SET_MUTE,0,0);
lh7b0674a2022-01-10 00:34:35 -08001351 /*Warren add for t800 ril service 2021/12/23 start*/
1352 }
1353 /*Warren add for t800 ril service 2021/12/23 start*/
1354 printf("set mute %s\n", ((atoi(argv[1]) > 0) ? "on": "off"));
1355 android::LYNQ_RIL_respSocket(p,(void *)pRI);
1356 /*Warren add for t800 ril service 2021/12/23 start*/
1357 if(pRI) {
1358 free(pRI);
1359 }
1360 return 0;
1361}
1362
1363//RIL_REQUEST_GET_MUTE
1364int getMute(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
1365{
1366
q.huangec88da92022-03-29 04:17:32 -04001367 android::Parcel p;
lh7b0674a2022-01-10 00:34:35 -08001368 printf("WARREN TEST001!!!\n");
1369 int mute = getCallMute();
1370 //TBC -200 fail status
q.huangec88da92022-03-29 04:17:32 -04001371 if(mute < 0) {
lh7b0674a2022-01-10 00:34:35 -08001372 printf("get mute state fail, please check whether does call exsit.\n");
1373 /*Warren add for t800 ril service 2021/12/23 start*/
q.huangadbad2f2022-09-15 16:28:02 +08001374 android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,RIL_REQUEST_GET_MUTE,0,2);
lh7b0674a2022-01-10 00:34:35 -08001375 /*Warren add for t800 ril service 2021/12/23 end*/
1376 } else {
1377 /*Warren add for t800 ril service 2021/12/23 start*/
q.huangadbad2f2022-09-15 16:28:02 +08001378 android::lynqAssemblyParcelheader(p,socket_id,pRI->uToken,RIL_REQUEST_GET_MUTE,0,0);
lh7b0674a2022-01-10 00:34:35 -08001379 /*Warren add for t800 ril service 2021/12/23 end*/
1380 }
1381 printf("current mute state is%s",((mute == 1) ? "on\n" : "off\n"));
1382 p.writeInt32(mute);
lh7b0674a2022-01-10 00:34:35 -08001383 if(pRI) {
q.huangec88da92022-03-29 04:17:32 -04001384 android::LYNQ_RIL_respSocket(p,(void *)pRI);
lh7b0674a2022-01-10 00:34:35 -08001385 free(pRI);
1386 }
1387 return 0;
1388}
1389
1390//RIL_UNSOL_SIP_CALL_PROGRESS_INDICATOR
1391int handleUnsolSipCallProgressInd(const void *response, size_t responselen) {
1392 if (response == NULL && responselen != 0) {
1393 RLOGE("handleUnsolSipCallProgressInd: invalid response: NULL");
1394 return -1;
1395 }
1396 if (responselen % sizeof(char *) != 0) {
1397 RLOGE("handleUnsolSipCallProgressInd: invalid response length %d expected multiple of %d\n",
1398 (int)responselen, (int)sizeof(char *));
1399 return -1;
1400 }
1401
1402 int numStrings = responselen / sizeof(char *);
1403 RLOGD("handleUnsolSipCallProgressInd: numStrings: %d", numStrings);
1404 if(numStrings < 6) {
1405 RLOGE("handleUnsolSipCallProgressInd: invalid response numbers: NULL");
1406 return -1;
1407 }
1408 char **p_cur = (char **) response;
1409 //<call_id>,<dir>,<SIP_msg_type>,<method>,<response_code>,"<reason_text>"
1410 //if response == <id>, 1, 0, 4, 0, "call completed elsewhere" ,printf "SIP CANCEL:Call completed elsewhere"
1411 //if response == <id>, 1, 0, 4, 0, " declined" ,printf "SIP CANCEL:declined"
1412 std::string call_id(p_cur[0]);
1413 std::string dir(p_cur[1]);
1414 std::string sip_msg_type(p_cur[2]);
1415 std::string method(p_cur[3]);
1416 std::string resp_code(p_cur[4]);
1417 std::string reason_text(p_cur[5]);
1418 RLOGD("%s, call_id=%s, dir=%s, sip_msg_type=%s, method=%s, resp_code=%s, reason_text=%s",
1419 __FUNCTION__, call_id.c_str(),dir.c_str(),sip_msg_type.c_str(),method.c_str(),resp_code.c_str(), reason_text.c_str());
1420 printf("call_id=%s, dir=%s, sip_msg_type=%s, method=%s, resp_code=%s, reason_text=%s\n",
1421 call_id.c_str(),dir.c_str(),sip_msg_type.c_str(),method.c_str(),resp_code.c_str(), reason_text.c_str());
1422
1423 if ((std::stoi(dir) == 1) && (std::stoi(sip_msg_type) == 0)
1424 && (std::stoi(method) == 4) && (std::stoi(resp_code) == 0)) {
lhb07f4e12022-02-17 22:08:54 -08001425 std::string msg("SIP CANCEL:");
lh7b0674a2022-01-10 00:34:35 -08001426 msg.append(reason_text);
1427 printf("%s", msg.c_str());
1428 }
1429 return 0;
1430}
1431
1432//RIL_UNSOL_CALL_INFO_INDICATION
1433int handleUnsolCallInfoInd(const void *response, size_t responselen, RIL_SOCKET_ID socket_id) {
1434 int numStrings = 0;
1435
1436 if (response == NULL && responselen != 0) {
1437 RLOGE("[slot%d]handleUnsolCallInfoInd, invalid response: NULL", socket_id);
1438 return -1;
1439 }
1440 if (responselen % sizeof(char *) != 0) {
1441 RLOGE("[slot%d]handleUnsolCallInfoInd: invalid response length %d expected multiple of %d\n",socket_id,
1442 (int)responselen, (int)sizeof(char *));
1443 return -1;
1444 }
1445
1446 if (response == NULL) {
1447 RLOGE("[slot%d]handleUnsolCallInfoInd, length and invalid response : NULL", socket_id);
1448 } else {
1449 char **p_cur = (char **) response;
1450
1451 numStrings = responselen / sizeof(char *);
1452 RLOGD("[slot%d]handleUnsolCallInfoInd: numStrings: %d",socket_id, numStrings);
1453 if(numStrings < 9) {
lhb07f4e12022-02-17 22:08:54 -08001454 RLOGE("[slot%d]handleUnsolCallInfoInd, invalid numStrings < 9, no pau value : numStrings", socket_id);
lh7b0674a2022-01-10 00:34:35 -08001455 return -1;
1456 } else {
1457 RLOGD("[slot%d]handleUnsolCallInfoInd(): pau: %s", socket_id, p_cur[8]);
1458 printf("[slot%d]handleUnsolCallInfoInd(): pau: %s\n", socket_id, p_cur[8]);
1459 }
1460 }
1461 return 0;
1462}
1463
1464static void playtone(int start) {
1465 RLOGD("playtone(): start: %d, isRingStart %d", start, isRingStart);
1466 char cmd[256];
1467 sprintf(cmd, "aplay %s", RING_PATH);
1468 system(cmd);
1469 isRingStart = false;
1470}
1471
1472//RIL_UNSOL_RINGBACK_TONE
1473int handleRingbackTone(const void *response, size_t responselen, RIL_SOCKET_ID socket_id) {
1474
1475 int numInts = 0;
1476
1477 if (response == NULL && responselen != 0) {
1478 RLOGE("[slot%d]handleRingbackTone, invalid response: NULL", socket_id);
1479 return -1;
1480 }
1481 if (responselen % sizeof(int) != 0) {
1482 RLOGE("[slot%d]handleRingbackTone: invalid response length %d expected multiple of %d\n",socket_id,
1483 (int)responselen, (int)sizeof(char *));
1484 return -1;
1485 }
1486
1487 int *p_int = (int *) response;
1488
1489 numInts = responselen / sizeof(int);
1490 RLOGD("[slot%d]handleRingbackTone: numInts: %d",socket_id, numInts);
1491 if(numInts < 1) {
lhb07f4e12022-02-17 22:08:54 -08001492 RLOGE("[slot%d]handleRingbackTone, invalid numStrings < 1", socket_id);
lh7b0674a2022-01-10 00:34:35 -08001493 return -1;
1494 } else {
1495 int start = p_int[0];
1496 RLOGD("[slot%d]handleRingbackTone(): start: %d, isRingStart %d", socket_id, start, isRingStart);
1497 printf("[slot%d]handleRingbackTone(): start: %d, isRingStart %d\n", socket_id, start, isRingStart);
1498#if defined(TARGET_PLATFORM_MT2731)
1499 if(start && (!isRingStart)) {
1500 isRingStart = true;
1501 std::thread t(playtone, start);
1502 t.detach();
1503 } else if((!start) && isRingStart) {
1504 isRingStart = false;
1505 system("kill $(ps aux | grep '[a]play' | awk '{print $2}')");
1506 }
1507#endif
1508 }
1509 return 0;
1510}
1511
1512//RIL_REQUEST_DTMF_STOP
1513int stopDtmf(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
1514{
1515 android::Parcel p;
1516
1517 dtmf_stop(dtmf_handle);
xja1c30b82022-01-25 16:13:48 +08001518 dtmf_handle = NULL;
lh7b0674a2022-01-10 00:34:35 -08001519 pRI->pCI->dispatchFunction(p, pRI);
1520 return 0;
1521}