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