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