blob: 369bd2f28618675882976b5618711b8017380a9c [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 {
xja1c30b82022-01-25 16:13:48 +0800172 //setEcallAudioPathOn(false);
lh7b0674a2022-01-10 00:34:35 -0800173 ret = get_mixer_ctrl_value_int(g_mixer_name);
174 RLOGD("mixer_set(get_mixer_ctrl_value_int: %s) = %d", g_mixer_name, ret);
xja1c30b82022-01-25 16:13:48 +0800175 if(ret > 0) {
lh7b0674a2022-01-10 00:34:35 -0800176 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);
xja1c30b82022-01-25 16:13:48 +0800223 ret = -1;
lh7b0674a2022-01-10 00:34:35 -0800224 }
225 RLOGD("The ctrl \"%s\" is set to %d ", g_mixer_name, ret);
226 return ret;
227}
228int mixer_set_volume(int value)
229{
230 int ret;
231 if (get_audio_path() == 0) {
232 ret = set_mixer_ctrl_volume_value(g_mixer_name_volume, value);
233 } else {
234 ret = set_mixer_ctrl_volume_value(g_mixer_name_volume_bt, value);
235 }
236 if (ret)
237 RLOGE("set_mixer_ctrl_volume_value_int err: %d", ret);
238 return ret;
239}
240long int mixer_get_volume()
241{
242 long int vol_value;
243 if (get_audio_path() == 0) {
244 vol_value = get_mixer_ctrl_volume_value(g_mixer_name_volume);
245 } else {
246 vol_value = get_mixer_ctrl_volume_value(g_mixer_name_volume_bt);
247 }
248 RLOGD("The ctrl \"%s\" is set to %d", g_mixer_name_volume, vol_value);
249 return vol_value;
250}
251
252GstElement *pipeline_element;
253GstState gst_cur_state = GST_STATE_NULL;
254static int gst_status = 0;
255
256int GSM_Init(char* filepath)
257{
258 GstElement *pipeline, *source, *mux, *encoder, *sink;
259 RLOGD("[GSM]GSM Init Start!");
260 /* Initialisation */
261 gst_init (NULL, NULL);
262
263 pipeline = gst_pipeline_new ("3gppmux-test");
264 source = gst_element_factory_make ("pulsesrc", "file-source");
265 encoder = gst_element_factory_make ("faac", "encoder");
266 mux = gst_element_factory_make ("3gppmux", "muxer");
267 sink = gst_element_factory_make ("filesink", "output");
268
269 g_object_set(mux, "fragment-duration", 100, NULL);
270 g_object_set(sink, "location", filepath, NULL);
271
272 if (!pipeline || !source || !encoder || !mux || !sink) {
273 if(pipeline) {
274 gst_object_unref (GST_OBJECT (pipeline));
275 pipeline = NULL;
276 }
277 if(source) {
278 gst_object_unref (GST_OBJECT (source));
279 source = NULL;
280 }
281 if(encoder) {
282 gst_object_unref (GST_OBJECT (encoder));
283 encoder = NULL;
284 }
285 if(mux) {
286 gst_object_unref (GST_OBJECT (mux));
287 mux = NULL;
288 }
289 if(sink) {
290 gst_object_unref (GST_OBJECT (sink));
291 sink = NULL;
292 }
293 RLOGE ("[GSM]One element could not be created. Exiting");
294 return -1;
295 }
296
297 gst_bin_add_many (GST_BIN (pipeline), source, encoder, mux, sink, NULL);
298 gst_element_link_many (source, encoder, mux, sink, NULL);
299
300 pipeline_element = pipeline;
301 gst_status = 1; //initial done
302 RLOGD("[GSM]GSM Init Done!");
303 return 0;
304}
305
306int GSM_Start(void)
307{
308 RLOGD("[GSM]GSM Start start!");
309 if(gst_status == 2)
310 return 0;
311
312 if(gst_status == 1 || gst_status ==3) {
313 GstStateChangeReturn ret = gst_element_set_state (pipeline_element, GST_STATE_PLAYING);
314
315 RLOGD("[GSM]Running... return: %d", ret);
316 //g_main_loop_run (gst_loop);
317 gst_status = 2; //start done
318 } else {
319 return -1;
320 }
321 RLOGD("[GSM]GSM Start End!");
322 return 0;
323}
324
325int GSM_Stop()
326{
327 RLOGD("[GSM]GSM Stop Start!");
328 if (gst_status == 4)
329 return 0;
330
331 if(gst_status == 2 || gst_status == 3) {
332 /* Out of the main loop, clean up nicely */
333 gboolean isSend = gst_element_send_event (pipeline_element, gst_event_new_eos ());
334 GstStateChangeReturn ret = gst_element_set_state (pipeline_element, GST_STATE_NULL);
335 RLOGD("[GSM]Returned, stopping playback. ret: %d, isSend: %d", ret, isSend);
336 gst_status = 4;
337 } else {
338 return -1;
339 }
340 RLOGD("[GSM]GSM Stop End!");
341 return 0;
342}
343
344int GSM_Close()
345{
346 RLOGD("[GSM]Deleting pipeline");
347 gst_object_unref (GST_OBJECT (pipeline_element));
348 gst_deinit ();
349 gst_status = 0;
350 RLOGD("[GSM]GSM Close Done!");
351 return 0;
352}
353/*cmd:1, address,
354*2, clirMode,
355*3, if present, uusinfo.type
356*4, as above, uusinfo.Dcs
357*5, as above, uusinfo.userdatalength
358*6, as above, uusinfo.UserData
359*/
360//RIL_REQUEST_DIAL
361int dial(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
362{
363 android::Parcel p;
364 size_t pos = p.dataPosition();
365
366 if (argc < 3 || argv[1]==NULL) {
367 //add log msg
368 free(pRI);
369 return -1;
370 }
371 //address;
372 writeStringToParcel(p, (const char *)argv[1]);
373 //clirMode
374 if (argc >=2) {
375 p.writeInt32(atoi(argv[2]));
376
377 if (argc == 7 && argv[3] != NULL
378 && argv[4] != NULL && argv[5] != NULL
379 && argv[6] != NULL ) {
380 p.writeInt32(1); // UUS information is present
381 p.writeInt32(atoi(argv[3]));
382 p.writeInt32(atoi(argv[4]));
383 p.writeByteArray((size_t)atoi(argv[5]),(uint8_t*)argv[6]);
384 } else {
385 p.writeInt32(0); // UUS information is absent
386 }
387 }
388 p.setDataPosition(pos);
389 setEcallAudioPathOn(false);
390 pRI->pCI->dispatchFunction(p, pRI);
391 inCallstatus = CALL_ON;
392 return 0;
393}
394#if 0 //not need user setup
395//RIL_REQUEST_OEM_HOOK_STRINGS
396int invokeOemRilRequestStrings(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
397{
398 android::Parcel p;
399 size_t pos = p.dataPosition();
400 RLOGD("OEM_HOOK_STRINGS: p1->\"%s\",p2->\"%s\"",argv[1],argv[2]);
401 p.writeInt32(2);
402 writeStringToParcel(p, (const char *)argv[1]);
403 writeStringToParcel(p, "\"\"");//(const char *)argv[2]);
404 p.setDataPosition(pos);
405
406 pRI->pCI->dispatchFunction(p, pRI);
407 return 0;
408}
409#endif
410
411extern void ARspRequest (int request,RIL_SOCKET_ID socket_id);
412//RIL_REQUEST_SET_AUDIO_PATH
413/*cmd:1, speech mode,
414*2, bt_has_ecnr
415*3, bt_wbs
416*/
417int setAudioPath(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
418{
419 if (argc < 1) {
420 free(pRI);
421 RLOGE("set bt mode need bt_has_encr and bt_wbs");
422 return -1;
423 }
424
425 int temp_audio_path = atoi(argv[1]);
426 int bt_has_ecnr;
427 int bt_wbs;
428 int current_audio_path = get_audio_path();
429 RLOGD("setAudioPath enter");
430 if ((temp_audio_path != 0) && (temp_audio_path != 1)) {
431 RLOGE("audio path illegal %d, only support 0 and 1", temp_audio_path);
432 return -1;
433 }
434 set_audio_path(temp_audio_path);
435 RLOGD("set audio path to %d, current audio path is %d", temp_audio_path, current_audio_path);
436 if (temp_audio_path == 1) {
437 /* bt speech need BT_HAS_ECNR and BT_WBS */
438 bt_has_ecnr = atoi(argv[2]);
439 bt_wbs = atoi(argv[3]);
440 set_bt_has_ecnr(bt_has_ecnr);
441 set_bt_wbs(bt_wbs);
442 RLOGD("set bt_has_ecnr %d, bt_wbs %d", bt_has_ecnr, bt_wbs);
443 }
444 if ((current_audio_path != temp_audio_path)
445 && (get_call_status() == CALL_ON)) {
446 if (current_audio_path == 0) {
447 if (getSpeechStatus() == NORMAL_SPEECH_ON) {
448 RLOGD("normal speech off then bt speech on");
449 mixer_set(0);
450 setSpeechAndStatus(2);
451 }
452 } else {
453 if (getSpeechStatus() == BT_SPEECH_ON) {
454 RLOGD("bt speech off then normal speech on");
455 bt_mixer_set(0);
456 setSpeechAndStatus(1);
457 }
458 }
459 }
460 if (pRI != NULL) {
461 free(pRI);
462 }
463
464 RLOGD("setAudioPath done");
465 return 0;
466}
467
468
469//RIL_REQUEST_HANGUP
470int hangupConnection(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
471{
472 android::Parcel p;
473 size_t pos = p.dataPosition();
474
475 p.writeInt32(1);
476 p.writeInt32(atoi(argv[1]));
477 p.setDataPosition(pos);
478
479 pRI->pCI->dispatchFunction(p, pRI);
480 return 0;
481}
482
483//RIL_REQUEST_FORCE_RELEASE_CALL
484int forceReleaseCall(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
485{
486 android::Parcel p;
487 size_t pos = p.dataPosition();
488
489 p.writeInt32(1);
490 p.writeInt32(atoi(argv[1]));
491 p.setDataPosition(pos);
492
493 pRI->pCI->dispatchFunction(p, pRI);
494 return 0;
495}
496
497//RIL_REQUEST_SEPARATE_CONNECTION
498int separateConnection(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
499{
500 android::Parcel p;
501 size_t pos = p.dataPosition();
502
503 p.writeInt32(1);
504 p.writeInt32(atoi(argv[1]));
505 p.setDataPosition(pos);
506
507 pRI->pCI->dispatchFunction(p, pRI);
508 return 0;
509}
510//RIL_REQUEST_DTMF
511//RIL_REQUEST_DTMF_START
512int sendDtmf(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
513{
514 android::Parcel p;
515 int number;
516 size_t pos = p.dataPosition();
517 char * c_num = NULL;
518
519 c_num = argv[1];
520 if (c_num == NULL) {
521 free(pRI);
522 return -1;
523 }
524 number = int(c_num[0] - '0');
525 if(number == -6)
526 number = 10;
527 if(number == -13)
528 number = 11;
529 RLOGD("DTMF input number is %s-->%d",c_num,number);
530 if ( number < 0 || number > 15 ) {
531 RLOGE("DTMF input number error");
532 free(pRI);
533 return -1;
534 }
535
536 writeStringToParcel(p, (const char *)argv[1]);
537 p.setDataPosition(pos);
538
539 dtmf_stop(dtmf_handle);
540 gint time_ms = 500;
541 if (pRI->pCI->requestNumber == RIL_REQUEST_DTMF_START) {
542 time_ms = 0;
543 }
544 RLOGD("request: %d, time_ms = %d", pRI->pCI->requestNumber, time_ms);
545 dtmf_handle = dtmf_start(number, time_ms, dtmf_volume, NULL);
546 pRI->pCI->dispatchFunction(p, pRI);
547 if (dtmf_handle == NULL)
548 RLOGE("[DTMF] dtmf_start return NULL!");
549 return 0;
550}
551
552//RIL_REQUEST_UDUB
553int rejectCall(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
554{
555 android::Parcel p;
556
557 pRI->pCI->dispatchFunction(p, pRI);
558 return 0;
559}
560//RIL_REQUEST_ANSWER
561int acceptCall(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
562{
563 android::Parcel p;
564
565 pRI->pCI->dispatchFunction(p, pRI);
566 inCallstatus = CALL_ON;
567 return 0;
568}
569
570//RIL_REQUEST_HANGUP_ALL
571int hangupAll(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
572{
573 android::Parcel p;
574
575 pRI->pCI->dispatchFunction(p, pRI);
576 return 0;
577}
578
579//RIL_REQUEST_CONFERENCE
580int conference(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
581{
582 android::Parcel p;
583
584 pRI->pCI->dispatchFunction(p, pRI);
585 return 0;
586}
587//RIL_REQUEST_HANGUP_WAITING_OR_BACKGROUND
588int hangupWaitingOrBackground(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
589{
590 android::Parcel p;
591
592 pRI->pCI->dispatchFunction(p, pRI);
593 return 0;
594}
595//RIL_REQUEST_SWITCH_WAITING_OR_HOLDING_AND_ACTIVE
596int switchWaitingOrHoldingAndActive(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
597{
598 android::Parcel p;
599
600 pRI->pCI->dispatchFunction(p, pRI);
601 return 0;
602}
603//RIL_REQUEST_HANGUP_FOREGROUND_RESUME_BACKGROUND
604int hangupForegroundResumeBackground(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
605{
606 android::Parcel p;
607
608 pRI->pCI->dispatchFunction(p, pRI);
609 return 0;
610}
611//RIL_REQUEST_EXPLICIT_CALL_TRANSFER
612int explicitCallTransfer(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
613{
614 android::Parcel p;
615
616 pRI->pCI->dispatchFunction(p, pRI);
617 return 0;
618}
619
620//RIL_REQUEST_ADD_IMS_CONFERENCE_CALL_MEMBER
621int addImsConferenceCallMember(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
622{
623 android::Parcel p;
624 size_t pos = p.dataPosition();
625
626 p.writeInt32(3);
627 writeStringToParcel(p, (const char *)argv[1]);//confCallId
628 writeStringToParcel(p, (const char *)argv[2]);//address
629 writeStringToParcel(p, (const char *)argv[3]);//CallIdToAdd
630
631 p.setDataPosition(pos);
632 pRI->pCI->dispatchFunction(p, pRI);
633 return 0;
634}
635//RIL_REQUEST_REMOVE_IMS_CONFERENCE_CALL_MEMBER
636int removeImsConferenceCallMember(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
637{
638 android::Parcel p;
639 size_t pos = p.dataPosition();
640
641 p.writeInt32(3);
642 writeStringToParcel(p, (const char *)argv[1]);//confCallId
643 writeStringToParcel(p, (const char *)argv[2]);//address
644 writeStringToParcel(p, (const char *)argv[3]);//CallIdToRemove
645
646 p.setDataPosition(pos);
647 pRI->pCI->dispatchFunction(p, pRI);
648 return 0;
649}
650//RIL_REQUEST_CONFERENCE_DIAL
651//argv[1]:DialMethod
652//argv[2]:ParticipantsNumber
653//argv[2+ParticipantsNumber]:addresss
654//argv[2+ParticipantsNumber+1]:clir
655int conferenceDial(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
656{
657 android::Parcel p;
658 size_t pos = p.dataPosition();
659 int ParticipantsNumber,i;
660
661 if( argc < 3 ) {
662 free(pRI);
663 RLOGE("Error: conference Dial parameter is error!");
664 return -1;
665 }
666
667 ParticipantsNumber = atoi(argv[2]);
668
669 if( argc < (ParticipantsNumber+3) ) {
670 free(pRI);
671 RLOGE("Error: Dial With SIP URI parameter is error! \
672 argc is %d, and need parameter %d",argc,(ParticipantsNumber+3));
673 return -1;
674 }
675
676 p.writeInt32((ParticipantsNumber+3));
677 writeStringToParcel(p, (const char *)argv[1]); //DialMethod
678 writeStringToParcel(p, (const char *)argv[2]); //ParticipantsNumber
679 for( i=0; i<ParticipantsNumber; i++ ){ //address
680 writeStringToParcel(p, (const char *)argv[3+i]);
681 }
682 writeStringToParcel(p, (const char *)argv[3+ParticipantsNumber]);//clir
683
684 p.setDataPosition(pos);
685 setEcallAudioPathOn(false);
686 pRI->pCI->dispatchFunction(p, pRI);
687 return 0;
688}
689//RIL_REQUEST_DIAL_WITH_SIP_URI
690int dialWithSipUri(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
691{
692 android::Parcel p;
693 size_t pos = p.dataPosition();
694
695 if (argc < 3 || argv[1]==NULL) {
696 free(pRI);
697 return -1;
698 }
699
700 writeStringToParcel(p, (const char *)argv[1]);//address
701 /* for compatibility of test script, still receive clirMode and UUS,
702 but don't send them to libvendor-ril */
703#if 0
704 p.writeInt32(atoi(argv[2]));//clirMode
705 p.writeInt32(0); // UUS information is absent
706#endif
707
708 p.setDataPosition(pos);
709 setEcallAudioPathOn(false);
710 pRI->pCI->dispatchFunction(p, pRI);
711 return 0;
712}
713//RIL_REQUEST_HOLD_CALL
714int holdCall(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
715{
716 android::Parcel p;
717 size_t pos = p.dataPosition();
718
719 if (argc < 2 || argv[1]==NULL) {
720 free(pRI);
721 return -1;
722 }
723
724 //callIDToHold
725 p.writeInt32(1);
726 p.writeInt32(atoi(argv[1]));
727
728 p.setDataPosition(pos);
729
730 pRI->pCI->dispatchFunction(p, pRI);
731 return 0;
732}
733//RIL_REQUEST_RESUME_CALL
734int resumeCall(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
735{
736 android::Parcel p;
737 size_t pos = p.dataPosition();
738
739 if (argc < 2 || argv[1]==NULL) {
740 free(pRI);
741 return -1;
742 }
743
744 //callIDToResume
745 p.writeInt32(1);
746 p.writeInt32(atoi(argv[1]));
747
748 p.setDataPosition(pos);
749
750 pRI->pCI->dispatchFunction(p, pRI);
751 return 0;
752}
753int getCurrentCalls(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
754{
755 android::Parcel p;
756
757 pRI->pCI->dispatchFunction(p, pRI);
758 return 0;
759}
760int autoAnswerCall(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
761{
762 if(argc < 2) {
763 RLOGW("[error],set auto answer call parameter error!");
764 free(pRI);
765 return 0;
766 }
767 //need add lock to pretect.
768 autoAnswerMode = atoi(argv[1]) ? 1 : 0;
769 RLOGD("SetAutoAnserMode is %s",autoAnswerMode ? "On" :"Off");
770 if(pRI) {
771 free(pRI);
772 }
773 return 0;
774}
775
776int inCallRecord(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
777{
778 int recordEnable = 0;
779 char* filepath = NULL;
780 if(inCallstatus == CALL_OFF || speechStatus == SPEECH_OFF) {
781 RLOGW("[warning],not in calling status. Can't do record!");
782 return 0;
783 }
784
785 if(argc < 3) {
786 free(pRI);
787 RLOGW("[error],inCallRecord parameter error!");
788 return 0;
789 }
790
791 recordEnable = atoi(argv[1]) ? 1 : 0;
792 RLOGD("InCall record %s!",recordEnable ? "enable" : "disable");
793 filepath = argv[2];
794 RLOGD("InCall record file path as \'%s\'",filepath);
795
796 if (recordEnable == 1) {//enable record
797 RLOGD("start GSM!");
798 if(-1 != GSM_Init(filepath) && -1 != GSM_Start()) {
799 inCallRecordMode = 1;
800 RLOGW("inCallRecord Start OK!");
801 }else{
802 inCallRecordMode = 0;
803 RLOGW("[error],inCallRecord Start fail!");
804 }
805 } else { //disable record
806 if (inCallRecordMode == 1) {
807 if(!(-1 != GSM_Stop() && -1 != GSM_Close()))
808 RLOGW("[error],inCallRecord fail!");
809
810 inCallRecordMode = 0;
811 }
812 }
813
814 if(pRI != NULL) {
815 free(pRI);
816 }
817 return 0;
818}
819
820int StopRecord()
821{
822 RLOGD("After Handup, stop record! Before Record is %s",inCallRecordMode ? "Enable" : "Disable");
823 if (inCallRecordMode == 1) {
824 if(!(-1 != GSM_Stop() && -1 != GSM_Close()))
825 RLOGW("[error],inCallRecord fail!");
826
827 inCallRecordMode = 0;
828 /*From GSM report stop_record to PulseAudio send record_off need 15ms. so after stop record delay 30ms*/
829 usleep(30*1000);
830 }
831 return 0;
832}
833
834int setSpeechVolume(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
835{
836 int setValue = 0;
837 RLOGD("setSpeechVolume start!");
838
839 if(argc < 2) {
840 free(pRI);
841 RLOGW("Warning: no set volume value!");
842 return -1;
843 }
844
845 setValue = atoi(argv[1]);
846 RLOGD("set Speech Volume value is %d!",setValue);
847 if (get_audio_path() == 0) {
848 if(setValue < MIN_VOLUME || setValue > MAX_VOLUME) {
849 RLOGW("Warning: set volume value is over-range!");
850 return -1;
851 }
852 } else {
853 if(setValue < BT_MIN_VOLUME || setValue > BT_MAX_VOLUME) {
854 RLOGW("Warning: set bt volume value is over-range!");
855 return -1;
856 }
857 }
858 //paramter is from 1 to 7
859 mixer_set_volume(setValue);
860 free(pRI);
861 return 0;
862}
863int setDtmfVolume(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
864{
865 int setValue = 0;
866 Parcel p;
867 RLOGD("setDtmfVolume start!");
868 printf("setDtmfVolume start!\n");
869 if(argc < 2) {
870 RLOGW("Warning: no set volume value!");
871 printf("Warning: no set volume value!\n");
872 free(pRI);
873 return -1;
874 }
875
876 setValue = atoi(argv[1]);
877 RLOGD("set dtmf Volume value is %d!",setValue);
878 printf("set dtmf Volume value is %d!\n",setValue);
879 if(setValue < DTMF_MIN_VOLUME || setValue > DTMF_MAX_VOLUME) {
880 RLOGW("Warning: set volume value is over-range!");
881 printf("set dtmf Volume value is %d!\n",setValue);
882 /*Warren add for t800 ril service 2021/12/23 start*/
883 android::lynqAssemblyParcelheader(p,socket_id,LYNQ_REQUEST_SET_DTMF_VOLUME,0,2);
884 android::LYNQ_RIL_respSocket_sp(p,pRI);
885 /*Warren add for t800 ril service 2021/12/23 end*/
886 free(pRI);
887 return -1;
888 }
889 //paramter is from 0 to 36
890 dtmf_volume = setValue;
891 printf(">>>>set dtmf Volume<<<< success value is %d!\n",setValue);
892 /*Warren add for t800 ril service 2021/12/23 start*/
893 android::lynqAssemblyParcelheader(p,socket_id,LYNQ_REQUEST_SET_DTMF_VOLUME,0,0);
894 printf(">>>>set dtmf 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);
897 free(pRI);
898 return 0;
899}
900
901speech_status getSpeechStatus()
902{
903 return speechStatus;
904}
905
906void setSpeechAndStatus(int value)
907{
908 RLOGD("setSpeechAndStatus value: %d, speechStatus: %d", value, speechStatus);
909 if (value == 1) {
910 speechStatus = NORMAL_SPEECH_ON;
911 mixer_set(1);
912 } else if (value == 2) {
913 speechStatus = BT_SPEECH_ON;
914 bt_mixer_set(1);
915 } else if (value == 0) {
916 speechStatus == BT_SPEECH_ON ? bt_mixer_set(0) : mixer_set(0);
917 speechStatus = SPEECH_OFF;
918 } else {
919 RLOGE("set speech value is invaild!\n");
920 }
921}
922//RIL_REQUEST_EMERGENCY_DIAL
923/*cmd:1, address,
924*2, clirMode,
925*3, if present, uusinfo.type
926*4, as above, uusinfo.Dcs
927*5, as above, uusinfo.userdatalength
928*6, as above, uusinfo.UserData
929*/
930int emergencyDial(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
931{
932 android::Parcel p;
933 size_t pos = p.dataPosition();
934
935 if (argc < 3 || argv[1] == NULL)
936 {
937 //add log msg
938 free(pRI);
939 return -1;
940 }
941 //address;
942 writeStringToParcel(p, (const char *) argv[1]);
943 //clirMode
944 if (argc >= 2)
945 {
946 p.writeInt32(atoi(argv[2]));
947
948 if (argc == 7&& argv[3] != NULL
949 && argv[4] != NULL && argv[5] != NULL
950 && argv[6] != NULL)
951 {
952 p.writeInt32(1); // UUS information is present
953 p.writeInt32(atoi(argv[3]));
954 p.writeInt32(atoi(argv[4]));
955 p.writeByteArray((size_t) atoi(argv[5]), (uint8_t*) argv[6]);
956 } else
957 {
958 p.writeInt32(0); // UUS information is absent
959 }
960 }
961 p.setDataPosition(pos);
962 setEcallAudioPathOn(false);
963 pRI->pCI->dispatchFunction(p, pRI);
964 return 0;
965}
966//RIL_REQUEST_SET_ECC_SERVICE_CATEGORY
967int setEccServiceCategory(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
968{
969 android::Parcel p;
970 size_t pos = p.dataPosition();
971
972 //if ( getSpeechStatus() != 1)
973 // setSpeechAndStatus(1);
974
975 p.writeInt32(1);
976 p.writeInt32(atoi(argv[1]));
977 p.setDataPosition(pos);
978 pRI->pCI->dispatchFunction(p, pRI);
979 return 0;
980}
981//RIL_REQUEST_SET_ECC_LIST
982/* argv[1]: list number
983 argv[2+i]: ECC string
984 argv[3+i]: Categroy
985 argv[4+i]: Conditon
986*/
987int setEccList(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
988{
989 android::Parcel p;
990 size_t pos = p.dataPosition();
991 int num = 0;
992 //if ( getSpeechStatus() != 1)
993 // setSpeechAndStatus(1);
994 if(argc < 3) {
995 RLOGE("%s parameter error!",__func__);
996 free(pRI);
997 return -1;
998 }
999 num = atoi(argv[1]);
1000 RLOGD("list number is %d, argc is %d",num, argc);
1001 if((num == 0) || ((argc-2) < num*3)) {
1002 RLOGE("%s parameter error!",__func__);
1003 free(pRI);
1004 return -1;
1005 }
1006
1007 p.writeInt32(num*3);
1008 for(int i = 0; i < num; i++){
1009 writeStringToParcel(p, (const char *)argv[2+i*3+0]); //ECC
1010 writeStringToParcel(p, (const char *)argv[2+i*3+1]); //Category
1011 writeStringToParcel(p, (const char *)argv[2+i*3+2]); //Condition
1012 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]);
1013 }
1014 p.setDataPosition(pos);
1015 pRI->pCI->dispatchFunction(p, pRI);
1016 return 0;
1017}
1018
1019//RIL_REQUEST_SET_ECC_NUM
1020int setEccNum(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
1021{
1022 android::Parcel p;
1023 size_t pos = p.dataPosition();
1024 int num = 0;
1025
1026 if(argc < 2 || argc > 3) {
1027 RLOGE("%s parameter error!",__func__);
1028 free(pRI);
1029 return -1;
1030 }
1031
1032 num = (argc > 2)?2:1;
1033
1034 p.writeInt32(num);
1035 writeStringToParcel(p, (const char *)argv[1]); //ECC number with card
1036 RLOGD("Set ECC number with card: %s",argv[1]);
1037 if (num>1){
1038 writeStringToParcel(p, (const char *)argv[2]); //ECC number without card
1039 RLOGD("Set ECC number without card: %s",argv[2]);
1040 }
1041 p.setDataPosition(pos);
1042 pRI->pCI->dispatchFunction(p, pRI);
1043 return 0;
1044}
1045
1046//RIL_REQUEST_GET_ECC_NUM
1047int getEccNum(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
1048{
1049 android::Parcel p;
1050 pRI->pCI->dispatchFunction(p, pRI);
1051 return 0;
1052}
1053
1054int handleECCNumResponse(const void *data, int datalen, RIL_SOCKET_ID socket_id){
1055 if (data == NULL || datalen <= 0){
1056 RLOGE("%s parameter error!",__func__);
1057 return -1;
1058 }
1059
1060 printf("[ECC NUM][Slot%d] %s\n", socket_id, (const char*)data);
1061 RLOGD("[ECC NUM][Slot%d] %s\n", socket_id, (const char*)data);
1062 return 0;
1063}
1064
1065
1066//RIL_REQUEST_LAST_CALL_FAIL_CAUSE
1067int getLastCallFailCause(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI) {
1068 if(argc != 1)
1069 {
1070 RLOGD("the peremeters numbers isn't right , so return");
1071 free(pRI);
1072 return -1;
1073 }
1074 RLOGD("getLastCallFailCause %d: " , pRI->pCI->requestNumber);
1075 android::Parcel p;
1076
1077 pRI->pCI->dispatchFunction(p, pRI);
1078 return 0;
1079}
1080
1081//#ifdef C2K_SUPPORT
1082static bool is12Key(char c) {
1083 return (c >= '0' && c <= '9') || c == '*' || c == '#';
1084}
1085
1086//RIL_REQUEST_CDMA_BURST_DTMF
1087int sendBurstDtmf(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI){
1088 if(argc < 4) {
1089 RLOGE("%s parameter error!",__func__);
1090 free(pRI);
1091 return -1;
1092 }
1093 int number;
1094 char * c_num = NULL;
1095
1096 c_num = argv[1];
1097 if (c_num == NULL) {
1098 free(pRI);
1099 return -1;
1100 }
1101 number = int(c_num[0] - '0');
1102 if(number == -6)
1103 number = 10;
1104 if(number == -13)
1105 number = 11;
1106 RLOGD("DTMF input number is %s-->%d",c_num,number);
1107 if ( number < 0 || number > 15 ) {
1108 RLOGE("DTMF input number error");
1109 free(pRI);
1110 return -1;
1111 }
1112 dtmf_stop(dtmf_handle);
1113 dtmf_handle = dtmf_start(number, 500, dtmf_volume, NULL);
1114 android::Parcel p;
1115 size_t pos = p.dataPosition();
1116 p.writeInt32(3);
1117 writeStringToParcel(p, c_num);
1118 writeStringToParcel(p, argv[2]);
1119 writeStringToParcel(p, argv[3]);
1120 p.setDataPosition(pos);
1121 pRI->pCI->dispatchFunction(p, pRI);
1122 if (dtmf_handle == NULL)
1123 RLOGE("[DTMF] dtmf_start return NULL!");
1124 return 0;
1125}
1126
1127//RIL_REQUEST_CDMA_FLASH
1128int sendCDMAFeatureCode(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI){
1129 if(argc > 2)
1130 {
1131 RLOGD("the peremeters numbers isn't right , so return");
1132 free(pRI);
1133 return -1;
1134 }
1135 android::Parcel p;
1136 size_t pos = p.dataPosition();
1137 writeStringToParcel(p, ((argc == 1) ? "" : argv[1]));
1138 p.setDataPosition(pos);
1139 pRI->pCI->dispatchFunction(p, pRI);
1140 return 0;
1141}
1142//#endif /*C2K_SUPPORT*/
1143
1144static int mixer_set_mute(int path, int value)
1145{
1146 RLOGD("mixer_set_mute path: %d , value: %d", path, value);
1147 int ret;
1148 /* DL:0 UL:1 */
1149 if (path == 0) {
1150 ret = set_mixer_ctrl_value_int(g_DL_mute_name, value);
1151 } else {
1152 ret = set_mixer_ctrl_value_int(g_UL_mute_name, value);
1153 }
1154 if (ret) {
1155 RLOGE("set_mixer_ctrl_volume_value_int err: %d", ret);
1156 }
1157 return ret;
1158}
1159
1160static long int mixer_get_mute(int path)
1161{
1162 long int is_mute;
1163
1164 /* DL:0 UL:1 */
1165 if (path == 0) {
1166 is_mute = get_mixer_ctrl_value_int(g_DL_mute_name);
1167 RLOGD("The ctrl \"%s\" is set to %d", g_DL_mute_name, is_mute);
1168 } else {
1169 is_mute = get_mixer_ctrl_value_int(g_UL_mute_name);
1170 RLOGD("The ctrl \"%s\" is set to %d", g_UL_mute_name, is_mute);
1171 }
1172
1173 return is_mute;
1174}
1175
1176static int setCallMute(bool mute) {
1177 RLOGD("setCallMute: %d", mute);
1178 return mixer_set_mute(1, (mute ? 1: 0));
1179}
1180
1181int getCallMute() {
1182 long int cc_mute = mixer_get_mute(1);
1183 RLOGD("getCallMute: %d", cc_mute);
1184 return cc_mute;
1185}
1186
1187void resetMute() {
1188 if (getCallMute() > 0) {
1189 setCallMute(false);
1190 }
1191}
1192
1193void callRing(RIL_SOCKET_ID soc_id)
1194{
1195 resetMute();
1196 if (autoAnswerMode) {
1197 RLOGD("Auto Answer MT Call!");
1198 android::requestAnswer(soc_id);
1199 }
1200 return;
1201}
1202
1203void autoAnswerForCdma(RIL_SOCKET_ID socket_id)
1204{
1205 resetMute();
1206 if (autoAnswerMode) {
1207 RLOGD("Auto Answer MT Call for cdma");
1208 ARspRequest(RIL_REQUEST_CDMA_FLASH, socket_id);
1209 }
1210 return;
1211}
1212
1213//void callStateChange(void)
1214void speechonoff(int callnum)
1215{
1216 static int callIndex = 0;
1217 RLOGD("callnum = %d, Call State Change then judge speech on/off!", callnum);
1218 callIndex = callnum;
1219 if( callIndex == 1 && speechStatus == SPEECH_OFF) { //speech on
1220 //RLOGD("DemoAPP Call shell command (pactl set-card-profile 0 phonecall)");
1221 //system("pactl set-card-profile 0 phonecall");
1222 //RLOGD("DemoAPP Call shell command end");
1223 if (get_audio_path() == 0) {
1224 mixer_set(1);
1225 speechStatus = NORMAL_SPEECH_ON;
1226 } else {
1227 bt_mixer_set(1);
1228 speechStatus = BT_SPEECH_ON;
1229 }
1230 inCallstatus = CALL_ON;
1231 RLOGD("[speech]: set on");
1232 sendCallMsg(true); //for Power Manager test
1233 } else if (callIndex == 0
1234 && (speechStatus == NORMAL_SPEECH_ON
1235 || speechStatus == BT_SPEECH_ON)) { //speech off
1236 StopRecord();
1237 sendCallMsg(false); // for Power Manager test.
1238 dtmf_stop(dtmf_handle);
1239 if (speechStatus == NORMAL_SPEECH_ON) {
1240 mixer_set(0);
1241 } else {
1242 bt_mixer_set(0);
1243 }
1244 //RLOGD("DemoAPP Call shell command (pactl set-card-profile 0 HiFi)");
1245 //system("pactl set-card-profile 0 HiFi");
1246 //RLOGD("DemoAPP Call(pactl set-card-profile 0 HiFi) command end");
1247 speechStatus = SPEECH_OFF;
1248 inCallstatus = CALL_OFF;
1249 resetMute();
1250 RLOGD("[speech]: set off");
1251 } else {
1252 RLOGD("callIndex is %d, speechStatus is %d.",callIndex, speechStatus);
1253 }
1254
1255 return;
1256}
1257
1258//RIL_REQUEST_SET_MUTE
1259int setMute(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
1260{
1261 Parcel p;
1262 printf("WARREN TEST002!!!\n");
1263 if(argc<2)
1264 {
1265 if(pRI)
1266 {
1267 free(pRI);
1268 }
1269 return -1;
1270 }
1271 bool mute = (atoi(argv[1]) > 0) ? true: false;
1272 RLOGD("set mute %s", ((atoi(argv[1]) > 0) ? "on": "off"));
1273 int ret = setCallMute(mute);
1274 if(ret) {
1275 /*Warren add for t800 ril service 2021/12/23 start*/
1276 android::lynqAssemblyParcelheader(p,socket_id,RIL_REQUEST_GET_MUTE,0,2);
1277 /*Warren add for t800 ril service 2021/12/23 start*/
1278 printf("set mute fail, please try agian\n");
1279 } else {
1280 /*Warren add for t800 ril service 2021/12/23 start*/
1281 android::lynqAssemblyParcelheader(p,socket_id,RIL_REQUEST_GET_MUTE,0,0);
1282 /*Warren add for t800 ril service 2021/12/23 start*/
1283 }
1284 /*Warren add for t800 ril service 2021/12/23 start*/
1285 printf("set mute %s\n", ((atoi(argv[1]) > 0) ? "on": "off"));
1286 android::LYNQ_RIL_respSocket(p,(void *)pRI);
1287 /*Warren add for t800 ril service 2021/12/23 start*/
1288 if(pRI) {
1289 free(pRI);
1290 }
1291 return 0;
1292}
1293
1294//RIL_REQUEST_GET_MUTE
1295int getMute(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
1296{
1297
1298 Parcel p;
1299 printf("WARREN TEST001!!!\n");
1300 int mute = getCallMute();
1301 //TBC -200 fail status
1302 if(mute == -200) {
1303 printf("get mute state fail, please check whether does call exsit.\n");
1304 /*Warren add for t800 ril service 2021/12/23 start*/
1305 android::lynqAssemblyParcelheader(p,socket_id,RIL_REQUEST_GET_MUTE,0,2);
1306 /*Warren add for t800 ril service 2021/12/23 end*/
1307 } else {
1308 /*Warren add for t800 ril service 2021/12/23 start*/
1309 android::lynqAssemblyParcelheader(p,socket_id,RIL_REQUEST_GET_MUTE,0,0);
1310 /*Warren add for t800 ril service 2021/12/23 end*/
1311 }
1312 printf("current mute state is%s",((mute == 1) ? "on\n" : "off\n"));
1313 p.writeInt32(mute);
1314 android::LYNQ_RIL_respSocket(p,(void *)pRI);
1315 if(pRI) {
1316 free(pRI);
1317 }
1318 return 0;
1319}
1320
1321//RIL_UNSOL_SIP_CALL_PROGRESS_INDICATOR
1322int handleUnsolSipCallProgressInd(const void *response, size_t responselen) {
1323 if (response == NULL && responselen != 0) {
1324 RLOGE("handleUnsolSipCallProgressInd: invalid response: NULL");
1325 return -1;
1326 }
1327 if (responselen % sizeof(char *) != 0) {
1328 RLOGE("handleUnsolSipCallProgressInd: invalid response length %d expected multiple of %d\n",
1329 (int)responselen, (int)sizeof(char *));
1330 return -1;
1331 }
1332
1333 int numStrings = responselen / sizeof(char *);
1334 RLOGD("handleUnsolSipCallProgressInd: numStrings: %d", numStrings);
1335 if(numStrings < 6) {
1336 RLOGE("handleUnsolSipCallProgressInd: invalid response numbers: NULL");
1337 return -1;
1338 }
1339 char **p_cur = (char **) response;
1340 //<call_id>,<dir>,<SIP_msg_type>,<method>,<response_code>,"<reason_text>"
1341 //if response == <id>, 1, 0, 4, 0, "call completed elsewhere" ,printf "SIP CANCEL:Call completed elsewhere"
1342 //if response == <id>, 1, 0, 4, 0, " declined" ,printf "SIP CANCEL:declined"
1343 std::string call_id(p_cur[0]);
1344 std::string dir(p_cur[1]);
1345 std::string sip_msg_type(p_cur[2]);
1346 std::string method(p_cur[3]);
1347 std::string resp_code(p_cur[4]);
1348 std::string reason_text(p_cur[5]);
1349 RLOGD("%s, call_id=%s, dir=%s, sip_msg_type=%s, method=%s, resp_code=%s, reason_text=%s",
1350 __FUNCTION__, call_id.c_str(),dir.c_str(),sip_msg_type.c_str(),method.c_str(),resp_code.c_str(), reason_text.c_str());
1351 printf("call_id=%s, dir=%s, sip_msg_type=%s, method=%s, resp_code=%s, reason_text=%s\n",
1352 call_id.c_str(),dir.c_str(),sip_msg_type.c_str(),method.c_str(),resp_code.c_str(), reason_text.c_str());
1353
1354 if ((std::stoi(dir) == 1) && (std::stoi(sip_msg_type) == 0)
1355 && (std::stoi(method) == 4) && (std::stoi(resp_code) == 0)) {
1356 std::string msg("SIP CANCEL:");
1357 msg.append(reason_text);
1358 printf("%s", msg.c_str());
1359 }
1360 return 0;
1361}
1362
1363//RIL_UNSOL_CALL_INFO_INDICATION
1364int handleUnsolCallInfoInd(const void *response, size_t responselen, RIL_SOCKET_ID socket_id) {
1365 int numStrings = 0;
1366
1367 if (response == NULL && responselen != 0) {
1368 RLOGE("[slot%d]handleUnsolCallInfoInd, invalid response: NULL", socket_id);
1369 return -1;
1370 }
1371 if (responselen % sizeof(char *) != 0) {
1372 RLOGE("[slot%d]handleUnsolCallInfoInd: invalid response length %d expected multiple of %d\n",socket_id,
1373 (int)responselen, (int)sizeof(char *));
1374 return -1;
1375 }
1376
1377 if (response == NULL) {
1378 RLOGE("[slot%d]handleUnsolCallInfoInd, length and invalid response : NULL", socket_id);
1379 } else {
1380 char **p_cur = (char **) response;
1381
1382 numStrings = responselen / sizeof(char *);
1383 RLOGD("[slot%d]handleUnsolCallInfoInd: numStrings: %d",socket_id, numStrings);
1384 if(numStrings < 9) {
1385 RLOGE("[slot%d]handleUnsolCallInfoInd, invalid numStrings(%d) < 9, no pau value : numStrings", socket_id);
1386 return -1;
1387 } else {
1388 RLOGD("[slot%d]handleUnsolCallInfoInd(): pau: %s", socket_id, p_cur[8]);
1389 printf("[slot%d]handleUnsolCallInfoInd(): pau: %s\n", socket_id, p_cur[8]);
1390 }
1391 }
1392 return 0;
1393}
1394
1395static void playtone(int start) {
1396 RLOGD("playtone(): start: %d, isRingStart %d", start, isRingStart);
1397 char cmd[256];
1398 sprintf(cmd, "aplay %s", RING_PATH);
1399 system(cmd);
1400 isRingStart = false;
1401}
1402
1403//RIL_UNSOL_RINGBACK_TONE
1404int handleRingbackTone(const void *response, size_t responselen, RIL_SOCKET_ID socket_id) {
1405
1406 int numInts = 0;
1407
1408 if (response == NULL && responselen != 0) {
1409 RLOGE("[slot%d]handleRingbackTone, invalid response: NULL", socket_id);
1410 return -1;
1411 }
1412 if (responselen % sizeof(int) != 0) {
1413 RLOGE("[slot%d]handleRingbackTone: invalid response length %d expected multiple of %d\n",socket_id,
1414 (int)responselen, (int)sizeof(char *));
1415 return -1;
1416 }
1417
1418 int *p_int = (int *) response;
1419
1420 numInts = responselen / sizeof(int);
1421 RLOGD("[slot%d]handleRingbackTone: numInts: %d",socket_id, numInts);
1422 if(numInts < 1) {
1423 RLOGE("[slot%d]handleRingbackTone, invalid numStrings(%d) < 1", socket_id);
1424 return -1;
1425 } else {
1426 int start = p_int[0];
1427 RLOGD("[slot%d]handleRingbackTone(): start: %d, isRingStart %d", socket_id, start, isRingStart);
1428 printf("[slot%d]handleRingbackTone(): start: %d, isRingStart %d\n", socket_id, start, isRingStart);
1429#if defined(TARGET_PLATFORM_MT2731)
1430 if(start && (!isRingStart)) {
1431 isRingStart = true;
1432 std::thread t(playtone, start);
1433 t.detach();
1434 } else if((!start) && isRingStart) {
1435 isRingStart = false;
1436 system("kill $(ps aux | grep '[a]play' | awk '{print $2}')");
1437 }
1438#endif
1439 }
1440 return 0;
1441}
1442
1443//RIL_REQUEST_DTMF_STOP
1444int stopDtmf(int argc, char **argv, RIL_SOCKET_ID socket_id, RequestInfo *pRI)
1445{
1446 android::Parcel p;
1447
1448 dtmf_stop(dtmf_handle);
xja1c30b82022-01-25 16:13:48 +08001449 dtmf_handle = NULL;
lh7b0674a2022-01-10 00:34:35 -08001450 pRI->pCI->dispatchFunction(p, pRI);
1451 return 0;
1452}