blob: 4ce0151de5ca917cdfe7ac780261b1996143a843 [file] [log] [blame]
b.liud440f9f2025-04-18 10:44:31 +08001/*-----------------------------------------------------------------------------------------------*/
2/**
3 @file ql_voice.h
4 @brief Voice service API.
5*/
6/*-----------------------------------------------------------------------------------------------*/
7
8/*-------------------------------------------------------------------------------------------------
9 Copyright (c) 2019 Quectel Wireless Solution, Co., Ltd. All Rights Reserved.
10 Quectel Wireless Solution Proprietary and Confidential.
11-------------------------------------------------------------------------------------------------*/
12
13/*-------------------------------------------------------------------------------------------------
14 EDIT HISTORY
15 This section contains comments describing changes made to the file.
16 Notice that changes are listed in reverse chronological order.
17 $Header: $
18 when who what, where, why
19 -------- --- ----------------------------------------------------------
20 20210622 Rambo.shan Added Voice DSDA API.
21 20210203 Rambo.shan Added Voice bind API for DSDA.
22 20210104 Rambo.shan Added DTMF event indication.
23 20200928 Rambo.shan Added eCall set option of T3.
24 20200907 Rambo.shan Added SETUP voice state.
25 20200622 Rambo.shan Add eCall auto answer function
26 20191225 solomon.cui Modify fucntion description.
27 20191111 solomon.cui Add eCall APIs.
28 20190815 solomon.cui Add service type for sending message.
29 20190625 solomon.cui Created.
30-------------------------------------------------------------------------------------------------*/
31#include "mbtk_type.h"
32#include "mbtk_ril_api.h"
33#include "mbtk_log.h"
34#include "ql_voice.h"
35#include "ql_type.h"
36
37#include <stdint.h>
38#include <stdio.h>
39#include <stdlib.h>
40#include <sys/epoll.h>
41#include <unistd.h>
42#include <errno.h>
43#include <pthread.h>
44#include <string.h>
45#include <fcntl.h>
46#include <time.h>
47
48#define MBTK_ERR_OK 0
49
50typedef struct {
51 mbtk_ril_handle* handle;
52 int state_t;
53 ql_voice_record_array_t record_array;
54 ql_voice_call_cb_f call_cb;
55 ql_voice_service_error_cb_f server_cb;
56}ql_voice_info_handle_t;
57
58
59static ql_voice_info_handle_t* voice_handle = NULL;
60
61
62typedef struct {
63 mbtk_voice_end_reason_enum mbtk_end_reason;
64 QL_VOICE_END_REASON_E ql_end_reason;
65}end_reason_t;
66
67
68
69end_reason_t g_end_reason[] = {
70{MBTK_VOICE_END_REASON_UNASSIGNED_NUMBER, QL_VOICE_END_REASON_UNASSIGNED_NUMBER},
71{MBTK_VOICE_END_REASON_NO_ROUTE_DES, QL_VOICE_END_REASON_NO_ROUTE_TO_DESTINATION},
72{MBTK_VOICE_END_REASON_CHANNEL_UNACCEPTABLE, QL_VOICE_END_REASON_CHANNEL_UNACCEPTABLE},
73{MBTK_VOICE_END_REASON_OPERATOR_DETERMINED_BARRING, QL_VOICE_END_REASON_OPERATOR_DETERMINED_BARRING},
74{MBTK_VOICE_END_REASON_NORMAL_CALL_CLEARING, QL_VOICE_END_REASON_NORMAL_CALL_CLEARING},
75{MBTK_VOICE_END_REASON_USER_BUSY, QL_VOICE_END_REASON_USER_BUSY},
76
77{MBTK_VOICE_END_REASON_NO_USER_RESPONDING, QL_VOICE_END_REASON_NO_USER_RESPONDING},
78{MBTK_VOICE_END_REASON_USER_ALERTING_NO_ANSWER, QL_VOICE_END_REASON_USER_ALERTING_NO_ANSWER},
79{MBTK_VOICE_END_REASON_CALL_REJECTED, QL_VOICE_END_REASON_CALL_REJECTED},
80{MBTK_VOICE_END_REASON_NUMBER_CHANGED, QL_VOICE_END_REASON_NUMBER_CHANGED},
81{MBTK_VOICE_END_REASON_PREEMPTION, QL_VOICE_END_REASON_PREEMPTION},
82{MBTK_VOICE_END_REASON_NON_SELECTED_USER_CLEARING, QL_VOICE_END_REASON_NONE},
83{MBTK_VOICE_END_REASON_DESTINATION_OUT_OF_ORDER, QL_VOICE_END_REASON_DESTINATION_OUT_OF_ORDER},
84{MBTK_VOICE_END_REASON_INVALID_NUMBER_FORMAT, QL_VOICE_END_REASON_INVALID_NUMBER_FORMAT},
85{MBTK_VOICE_END_REASON_FACILITY_REJECTED, QL_VOICE_END_REASON_FACILITY_REJECTED},
86{MBTK_VOICE_END_REASON_STATUS_ENQUIRY, QL_VOICE_END_REASON_RESP_TO_STATUS_ENQUIRY},
87{MBTK_VOICE_END_REASON_NORMAL_UNSPECIFIED, QL_VOICE_END_REASON_NORMAL_UNSPECIFIED},
88{MBTK_VOICE_END_REASON_NO_CIRCUIT_AVAILABLE, QL_VOICE_END_REASON_NO_CIRCUIT_OR_CHANNEL_AVAILABLE},
89{MBTK_VOICE_END_REASON_NETWORK_OUT_OF_ORDER, QL_VOICE_END_REASON_NETWORK_OUT_OF_ORDER},
90{MBTK_VOICE_END_REASON_TEMPORARY_FAILURE, QL_VOICE_END_REASON_TEMPORARY_FAILURE},
91{MBTK_VOICE_END_REASON_SWITCHING_EQUIPMENT_CONGESTION, QL_VOICE_END_REASON_SWITCHING_EQUIPMENT_CONGESTION},
92{MBTK_VOICE_END_REASON_ACCESS_INFORMATION_DISCARDED, QL_VOICE_END_REASON_ACCESS_INFORMATION_DISCARDED},
93{MBTK_VOICE_END_REASON_REQUESTED_CIRCUIT_UNAVAILABLE, QL_VOICE_END_REASON_REQUESTED_CIRCUIT_OR_CHANNEL_NOT_AVAILABLE},
94
95{MBTK_VOICE_END_REASON_SERVICE_NOT_AVAILABLE, QL_VOICE_END_REASON_SERVICE_OPTION_NOT_AVAILABLE},
96
97{MBTK_VOICE_END_REASON_END, QL_VOICE_END_REASON_NONE}
98
99};
100
101
l.yange4f94f42025-04-29 18:08:39 -0700102/*
b.liud440f9f2025-04-18 10:44:31 +0800103 static int end_reason_mbtk_to_ql(char* mbtk_reason, int* ql_reason)
104{
105 int bufefer_i = 0;
106 *ql_reason = QL_VOICE_END_REASON_NONE;
107
108 bufefer_i = atoi(mbtk_reason);
109
110 for(int i = 0; g_end_reason[i].mbtk_end_reason != MBTK_VOICE_END_REASON_END; i++)
111 {
112 if(bufefer_i == g_end_reason[i].mbtk_end_reason)
113 {
114 *ql_reason = g_end_reason[i].ql_end_reason;
115 break;
116 }
117 }
118
119 return 0;
120}
l.yange4f94f42025-04-29 18:08:39 -0700121*/
b.liud440f9f2025-04-18 10:44:31 +0800122
l.yange4f94f42025-04-29 18:08:39 -0700123static mbtk_sim_type_enum s_voice_slot = MBTK_SIM_1;
124
125static bool check_slot_valid(QL_SIM_SLOT_E slot)
126{
127 if (slot !=QL_SIM_SLOT_1 && slot != QL_SIM_SLOT_2)
128 {
129 LOG("bad slot: %d, slot should be 1 or 2", slot);
130 return false;
131 }
132
133 return true;
134}
135
136static void ql_slot_convert_to_mbtk(QL_SIM_SLOT_E ql_slot,mbtk_sim_type_enum *mbtk_slot)
137{
138 if(ql_slot == QL_SIM_SLOT_1)
139 {
140 *mbtk_slot = MBTK_SIM_1;
141 }
142
143 if(ql_slot == QL_SIM_SLOT_2)
144 {
145 *mbtk_slot = MBTK_SIM_2;
146 }
147 return;
148
149}
150
151int ql_set_voice_slot(QL_SIM_SLOT_E log_slot)
152{
153 if(!check_slot_valid(log_slot))
154 {
155 LOG("[%s] check_slot_valid failed.", __func__);
156 return QL_ERR_INVALID_ARG;
157 }
158 ql_slot_convert_to_mbtk(log_slot,&s_voice_slot);
159 LOG("s_net_slot is %d",s_voice_slot);
160 return QL_ERR_OK;
161}
b.liud440f9f2025-04-18 10:44:31 +0800162
163static void ql_voice_state_change_cb(const void* data, int data_len)
164{
165 if(NULL == data)
166 {
167 LOGE("[ql_voice_state_change_cb] data is null.");
168 return;
169 }
170
171 if(voice_handle->call_cb == NULL) {
172 LOGW("voice_state_change_cb not set.");
173 return;
174 }
175
l.yange4f94f42025-04-29 18:08:39 -0700176 mbtk_ril_call_state_info_t *reg = (mbtk_ril_call_state_info_t *)data;
b.liud440f9f2025-04-18 10:44:31 +0800177
178 int ql_reason = 0;
l.yange4f94f42025-04-29 18:08:39 -0700179 //end_reason_mbtk_to_ql((char*)reg->end_reason, &ql_reason);
b.liud440f9f2025-04-18 10:44:31 +0800180 LOG("ql_voice_state_change_cb ql_reason:%d", ql_reason);
181
182
183 if(MBTK_RIL_CALL_STATE_DISCONNECT != reg->state)
184 {
l.yange4f94f42025-04-29 18:08:39 -0700185 LOG("ql_voice_state_change_cb : %d, %d, %d, %d, %s", reg->call_id, reg->dir, reg->state, reg->num_type, reg->call_number);
b.liud440f9f2025-04-18 10:44:31 +0800186
187 switch(reg->state)
188 {
189 case 0:
190 voice_handle->state_t = QL_VOICE_STATE_ACTIVE;
191 break;
192 case 1:
193 voice_handle->state_t = QL_VOICE_STATE_HOLDING;
194 break;
195 case 2:
196 voice_handle->state_t = QL_VOICE_STATE_DIALING;
197 break;
198 case 3:
199 voice_handle->state_t = QL_VOICE_STATE_ALERTING;
200 break;
201 case 4:
202 voice_handle->state_t = QL_VOICE_STATE_INCOMING;
203 break;
204 case 5:
205 voice_handle->state_t = QL_VOICE_STATE_WAITING;
206 break;
207 case 7:
208 voice_handle->state_t = QL_VOICE_STATE_END;
209 break;
l.yange4f94f42025-04-29 18:08:39 -0700210 default:
211 break;
b.liud440f9f2025-04-18 10:44:31 +0800212 }
213
l.yange4f94f42025-04-29 18:08:39 -0700214 if (voice_handle->record_array.records[0].id == 0 || voice_handle->record_array.records[0].id == reg->call_id)
b.liud440f9f2025-04-18 10:44:31 +0800215 {
216 voice_handle->record_array.len = 1;
l.yange4f94f42025-04-29 18:08:39 -0700217 voice_handle->record_array.records[0].id = reg->call_id;
b.liud440f9f2025-04-18 10:44:31 +0800218 voice_handle->record_array.records[0].tech = 1;
219 voice_handle->record_array.records[0].dir = reg->dir;
220 voice_handle->record_array.records[0].end_reason = ql_reason;
221 voice_handle->record_array.records[0].state = voice_handle->state_t;
l.yange4f94f42025-04-29 18:08:39 -0700222 memcpy(voice_handle->record_array.records[0].number, reg->call_number, strlen((char *)reg->call_number));
b.liud440f9f2025-04-18 10:44:31 +0800223 }
l.yange4f94f42025-04-29 18:08:39 -0700224 else if (voice_handle->record_array.records[0].id != reg->call_id)
b.liud440f9f2025-04-18 10:44:31 +0800225 {
226 voice_handle->record_array.len = 2;
l.yange4f94f42025-04-29 18:08:39 -0700227 voice_handle->record_array.records[1].id = reg->call_id;
b.liud440f9f2025-04-18 10:44:31 +0800228 voice_handle->record_array.records[1].tech = 1;
229 voice_handle->record_array.records[1].dir = reg->dir;
230 voice_handle->record_array.records[1].end_reason = ql_reason;
231 voice_handle->record_array.records[1].state = voice_handle->state_t;
l.yange4f94f42025-04-29 18:08:39 -0700232 memcpy(voice_handle->record_array.records[1].number, reg->call_number, strlen((char *)reg->call_number));
b.liud440f9f2025-04-18 10:44:31 +0800233 }
234
235 voice_handle->call_cb(&voice_handle->record_array);
236 }
237 else
238 {
239 LOGI("RING : call dis connected!");
240 voice_handle->record_array.records[0].end_reason = ql_reason;
241 voice_handle->record_array.records[1].end_reason = ql_reason;
l.yange4f94f42025-04-29 18:08:39 -0700242 if(voice_handle->record_array.records[0].id == reg->call_id)
b.liud440f9f2025-04-18 10:44:31 +0800243 {
244 voice_handle->record_array.records[0].state = QL_VOICE_STATE_END;
245 voice_handle->record_array.records[0].id = 0;
246 }
l.yange4f94f42025-04-29 18:08:39 -0700247 if(voice_handle->record_array.records[1].id == reg->call_id)
b.liud440f9f2025-04-18 10:44:31 +0800248 {
249 voice_handle->record_array.records[1].state = QL_VOICE_STATE_END;
250 voice_handle->record_array.records[1].id = 0;
251 voice_handle->record_array.len = 1;
252 }
l.yange4f94f42025-04-29 18:08:39 -0700253 if (reg->call_id == voice_handle->record_array.records[1].id)
b.liud440f9f2025-04-18 10:44:31 +0800254 voice_handle->call_cb(&voice_handle->record_array);
255 else
256 voice_handle->call_cb(&voice_handle->record_array);
257 }
258
259}
260
261static void ql_voice_server_change_cb(const void* data, int data_len)
262{
l.yange4f94f42025-04-29 18:08:39 -0700263 if(data)
b.liud440f9f2025-04-18 10:44:31 +0800264 {
l.yange4f94f42025-04-29 18:08:39 -0700265 mbtk_ril_ser_state_enum server_state = *(mbtk_ril_ser_state_enum *)data;
266 if(voice_handle->server_cb && server_state == MBTK_RIL_SER_STATE_EXIT)
b.liud440f9f2025-04-18 10:44:31 +0800267 {
268 voice_handle->server_cb(QL_ERR_ABORTED);
269 }
270 }
271}
272
273
274/*-----------------------------------------------------------------------------------------------*/
275/**
276 @brief Initializes voice service.
277 @return Whether the voice service was initialized successfully.
278 @retval QL_ERR_OK successful.
279 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
280 @retval Other error code defined by ql_type.h.
281 */
282/*-----------------------------------------------------------------------------------------------*/
283int ql_voice_init(void)
284{
285 if(NULL == voice_handle)
286 {
287 voice_handle = (ql_voice_info_handle_t*)malloc(sizeof(ql_voice_info_handle_t));
288 memset(voice_handle, 0, sizeof(ql_voice_info_handle_t));
289 voice_handle->record_array.records[0].id = 0;
290 if(NULL == voice_handle)
291 {
292 LOGE("[ql_voice_init] voice handle malloc fail.");
293 return QL_ERR_FAILED;
294 }
295
l.yange4f94f42025-04-29 18:08:39 -0700296 voice_handle->handle = mbtk_ril_open(MBTK_AT_PORT_VOICE);
b.liud440f9f2025-04-18 10:44:31 +0800297 if(NULL == voice_handle->handle)
298 {
299 LOGE("[ql_voice_init] mbtk handle init fail.");
300 if(voice_handle)
301 {
302 free(voice_handle);
303 voice_handle = NULL;
304 return QL_ERR_FAILED;
305 }
306 }
307
l.yange4f94f42025-04-29 18:08:39 -0700308 int ret = mbtk_ds_call_state_change_cb_reg(MBTK_SIM_1,ql_voice_state_change_cb);
b.liud440f9f2025-04-18 10:44:31 +0800309 if(ret != MBTK_ERR_OK)
310 {
311 LOGE("[ql_voice_init] set voice state cb fail.[%d]", ret);
312 if(voice_handle->handle)
313 {
l.yange4f94f42025-04-29 18:08:39 -0700314 mbtk_ril_close(MBTK_AT_PORT_VOICE);
315 voice_handle->handle = NULL;
316 return QL_ERR_FAILED;
317 }
318 }
319 ret = mbtk_ds_call_state_change_cb_reg(MBTK_SIM_2,ql_voice_state_change_cb);
320 if(ret != MBTK_ERR_OK)
321 {
322 LOGE("[ql_voice_init] set voice state cb fail.[%d]", ret);
323 if(voice_handle->handle)
324 {
325 mbtk_ril_close(MBTK_AT_PORT_VOICE);
b.liud440f9f2025-04-18 10:44:31 +0800326 voice_handle->handle = NULL;
327 return QL_ERR_FAILED;
328 }
329 }
330
331 ret = mbtk_ril_ser_state_change_cb_reg(ql_voice_server_change_cb);
332 if(ret != MBTK_ERR_OK)
333 {
334 LOGE("[ql_sim_init] set sim server cb fail.[%d]", ret);
335 if(voice_handle->handle)
336 {
l.yange4f94f42025-04-29 18:08:39 -0700337 mbtk_ril_close(MBTK_AT_PORT_VOICE);
b.liud440f9f2025-04-18 10:44:31 +0800338 voice_handle->handle = NULL;
339 return QL_ERR_FAILED;
340 }
341 }
342
343 voice_handle->call_cb = NULL;
344 voice_handle->server_cb = NULL;
345 }
346 return QL_ERR_OK;
347}
348
349/*-----------------------------------------------------------------------------------------------*/
350/**
351 @brief Deinitializes voice service.
352 @return Whether the voice service was deinitialized successfully.
353 @retval QL_ERR_OK successful.
354 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
355 @retval Other error code defined by ql_type.h.
356 */
357/*-----------------------------------------------------------------------------------------------*/
358int ql_voice_deinit(void)
359{
360 if(NULL == voice_handle)
361 {
362 LOGE("[ql_voice_deinit] voice handle not init.");
363 return QL_ERR_NOT_INIT;
364 }
365
366 int ret = 0;
367 voice_handle->server_cb = NULL;
368 voice_handle->call_cb = NULL;
369
370 if(NULL != voice_handle->handle)
371 {
l.yange4f94f42025-04-29 18:08:39 -0700372 ret = mbtk_ril_close(MBTK_AT_PORT_VOICE);
b.liud440f9f2025-04-18 10:44:31 +0800373 if(ret != MBTK_ERR_OK)
374 {
375 LOGE("[ql_voice_deinit] mbtk handle deinit fail.[%d]", ret);
376 return QL_ERR_FAILED;
377 }
378 voice_handle->handle = NULL;
379 }
380
381 if(ret != QL_ERR_OK)
382 {
383 LOGE("[ql_voice_deinit] cb thread free deinit fail.");
384 return QL_ERR_FAILED;
385 }
386
387 free(voice_handle);
388 voice_handle = NULL;
389 return QL_ERR_OK;
390}
391
392/*-----------------------------------------------------------------------------------------------*/
393/**
394 @brief Dials a call.
395 @param[in] num phone number to dial.
396 @param[in] len length of phone number, should be less than
397 or euqnal to QL_VOICE_MAX_PHONE_NUMBER.
398 @param[out] id call id.
399 @return Whether a voice call was successfully dialed.
400 @retval QL_ERR_OK successful.
401 @retval QL_ERR_INVALID_ARG invalid argument.
402 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
403 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
404 @retval Other error code defined by ql_type.h.
405 */
406/*-----------------------------------------------------------------------------------------------*/
407int ql_voice_dial(char *num, int len, uint32_t *id)
408{
409 char* phone_num_t = NULL;
410 mbtk_call_info_t reg = {0};
411 int err;
412
413 if(voice_handle->handle == NULL)
414 {
415 LOGE("ql_voice_call_start call_info_handle NULL");
416 return QL_ERR_FAILED;
417 }
418
419 if (num == NULL)
420 {
421 LOGE("ql_voice_call_start phone_number NULL");
422 return QL_ERR_FAILED;
423
424 }
425
426 phone_num_t = num;
427
l.yange4f94f42025-04-29 18:08:39 -0700428 err = mbtk_ds_call_start(voice_handle->handle, s_voice_slot,phone_num_t);
b.liud440f9f2025-04-18 10:44:31 +0800429 if(err)
430 {
431 LOGE("Error : %d\n", err);
432 return QL_ERR_FAILED;
433 }
434 else
435 {
436 LOGI("Call success.");
437 }
438
l.yange4f94f42025-04-29 18:08:39 -0700439 mbtk_ds_call_reg_get(voice_handle->handle, s_voice_slot,&reg);
b.liud440f9f2025-04-18 10:44:31 +0800440 *id = reg.dir1;
441 LOG("ql_voice_dial call_id: %d\n", reg.dir1, *id);
442
443 return QL_ERR_OK;
444}
445
446/*-----------------------------------------------------------------------------------------------*/
447/**
448 @brief Cancels dialing with given id.
449 @param[in] id call id returned from dial.
450 @return Whether the voice call was successfully cancelled.
451 @retval QL_ERR_OK successful.
452 @retval QL_ERR_INVALID_ARG invalid argument.
453 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
454 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
455 @retval Other error code defined by ql_type.h.
456 */
457/*-----------------------------------------------------------------------------------------------*/
458int ql_voice_cancel_dial(uint32_t id);
459
460/*-----------------------------------------------------------------------------------------------*/
461/**
462 @brief hangup all dialing.
463 @return Whether all voice call were successfully hangup.
464 @retval QL_ERR_OK successful.
465 @retval QL_ERR_INVALID_ARG invalid argument.
466 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
467 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
468 @retval Other error code defined by ql_type.h.
469 */
470/*-----------------------------------------------------------------------------------------------*/
471int ql_voice_hangup_all(void)
472{
473 int err;
474
475 if(voice_handle->handle == NULL)
476 {
477 LOGE("ql_voice_call_end call_info_handle NULL");
478 return QL_ERR_FAILED;
479 }
480
481 err = mbtk_call_hang(voice_handle->handle);
482 if(err)
483 {
484 LOGE("Error : %d", err);
485 return QL_ERR_FAILED;
486 }
487 else
488 {
489 LOGI("Call hang up a all.");
490 }
491 return QL_ERR_OK;
492}
493
494/*-----------------------------------------------------------------------------------------------*/
495/**
496 @brief Answers the call.
497 @param[in] id call id returned from dial.
498 @return Whether the voice call was successfully answered.
499 @retval QL_ERR_OK successful.
500 @retval QL_ERR_INVALID_ARG invalid argument.
501 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
502 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
503 @retval Other error code defined by ql_type.h.
504 */
505/*-----------------------------------------------------------------------------------------------*/
506int ql_voice_answer(uint32_t id)
507{
508 int err;
509
510 if(voice_handle->handle == NULL)
511 {
512 LOGE("ql_voice_call_anser call_info_handle NULL");
513 return QL_ERR_FAILED;
514 }
515
516 err = mbtk_call_answer(voice_handle->handle);
517 if(err)
518 {
519 LOGE("Error : %d", err);
520 return QL_ERR_FAILED;
521 }
522 else
523 {
524 LOGI("Answer success.");
525 }
526 return QL_ERR_OK;
527}
528
529/*-----------------------------------------------------------------------------------------------*/
530/**
531 @brief Hangs up the call.
532 @param[in] id call id returned from dial.
533 @return Whether the voice call was successfully hung up.
534 @retval QL_ERR_OK successful.
535 @retval QL_ERR_INVALID_ARG invalid argument.
536 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
537 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
538 @retval Other error code defined by ql_type.h.
539 */
540/*-----------------------------------------------------------------------------------------------*/
541int ql_voice_hangup(uint32_t id);
542
543/*-----------------------------------------------------------------------------------------------*/
544/**
545 @brief Holds the call when mutil calls is activated.
546 @param[in] id call id returned from dial.
547 @return Whether the voice call was successfully held.
548 @retval QL_ERR_OK successful.
549 @retval QL_ERR_INVALID_ARG invalid argument.
550 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
551 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
552 @retval Other error code defined by ql_type.h.
553 */
554/*-----------------------------------------------------------------------------------------------*/
555int ql_voice_hold(uint32_t id);
556
557/*-----------------------------------------------------------------------------------------------*/
558/**
559 @brief Releases the call from hold when mutil calls is activated.
560 @param[in] id call id returned from dial.
561 @return Whether the voice call was successfully unheld.
562 @retval QL_ERR_OK successful.
563 @retval QL_ERR_INVALID_ARG invalid argument.
564 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
565 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
566 @retval Other error code defined by ql_type.h.
567 */
568/*-----------------------------------------------------------------------------------------------*/
569int ql_voice_unhold(uint32_t id);
570
571/*-----------------------------------------------------------------------------------------------*/
572/**
573 @brief Gets call records.
574 @param[in] p_arr pointer to ql_voice_record_array_t.
575 @return Whether the call records were successfully obtained.
576 @retval QL_ERR_OK successful.
577 @retval QL_ERR_INVALID_ARG invalid argument.
578 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
579 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
580 @retval Other error code defined by ql_type.h.
581 */
582/*-----------------------------------------------------------------------------------------------*/
583int ql_voice_get_records(ql_voice_record_array_t *p_arr)
584{
585 if(NULL == p_arr)
586 {
587 LOGE("ql_voice_get_records p_arr NULL");
588 return QL_ERR_FAILED;
589 }
590 memcpy(p_arr, &voice_handle->record_array, sizeof(voice_handle->record_array));
591
592 return QL_ERR_OK;
593}
594
595/*-----------------------------------------------------------------------------------------------*/
596/**
597 @brief Registers or Unregisters forwarding.
598 @param[in] reg 0 - unregister, 1 - register.
599 @param[in] cond forwarding condition.
600 @param[in] num phone number.
601 @param[in] len length of phone numebr.
602 @return Whether the voice call forward was registered or unregistered successfully.
603 @retval QL_ERR_OK successful.
604 @retval QL_ERR_INVALID_ARG invalid argument.
605 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
606 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
607 @retval Other error code defined by ql_type.h.
608 */
609/*-----------------------------------------------------------------------------------------------*/
610int ql_voice_forwarding(int reg, QL_VOICE_FW_COND_E cond, char *num, int len);
611
612/*-----------------------------------------------------------------------------------------------*/
613/**
614 @brief Gets forwarding status.
615 @param[in] cond forwarding condition.
616 @param[out] p_status pointer to ql_voice_fw_status_t.
617 @return Whether the voice call forward status was successfully obtained.
618 @retval QL_ERR_OK successful.
619 @retval QL_ERR_INVALID_ARG invalid argument.
620 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
621 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
622 @retval Other error code defined by ql_type.h.
623 */
624/*-----------------------------------------------------------------------------------------------*/
625int ql_voice_get_forwarding_status(QL_VOICE_FW_COND_E cond, ql_voice_fw_status_t *p_status);
626
627/*-----------------------------------------------------------------------------------------------*/
628/**
629 @brief Enables or disables call waiting.
630 @param[in] enable 0 - disable, other - enable.
631 @return Whether the voice call waiting was enabled or disabled successfully.
632 @retval QL_ERR_OK successful.
633 @retval QL_ERR_INVALID_ARG invalid argument.
634 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
635 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
636 @retval Other error code defined by ql_type.h.
637 */
638/*-----------------------------------------------------------------------------------------------*/
639int ql_voice_waiting(int enable);
640
641/*-----------------------------------------------------------------------------------------------*/
642/**
643 @brief Gets call waiting status.
644 @param[out] enabled 0 - waiting is disabled, 1 - waiting is enabled.
645 @return Whether the voice call waiting status was successfully obtained.
646 @retval QL_ERR_OK successful.
647 @retval QL_ERR_INVALID_ARG invalid argument.
648 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
649 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
650 @retval Other error code defined by ql_type.h.
651 */
652/*-----------------------------------------------------------------------------------------------*/
653int ql_voice_get_waiting_status(int *enabled);
654
655/*-----------------------------------------------------------------------------------------------*/
656/**
657 @brief Enables or disables auto answer.
658 @param[in] enable 0 - disable, other - enable.
659 @param[in] sec wait this `sec' seconds before auto answer.
660 @return Whether the voice call autoanswer was enabled or disabled successfully.
661 @retval QL_ERR_OK successful.
662 @retval QL_ERR_INVALID_ARG invalid argument.
663 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
664 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
665 @retval Other error code defined by ql_type.h.
666 */
667/*-----------------------------------------------------------------------------------------------*/
668int ql_voice_autoanswer(int enable, uint32_t sec);
669
670/*-----------------------------------------------------------------------------------------------*/
671/**
672 @brief Sends a DTMF(Dual Tone Multi Frequency) character over the call ID.
673 @param[in] id call id returned from dial.
674 @param[in] c DTMF character to be sent. Valid DTMF characters are 0-9, A-D, '*', '#'.
675 @return Whether a DTMF character was successfully sent.
676 @retval QL_ERR_OK successful.
677 @retval QL_ERR_INVALID_ARG invalid argument.
678 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
679 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
680 @retval Other error code defined by ql_type.h.
681 */
682/*-----------------------------------------------------------------------------------------------*/
683int ql_voice_send_dtmf_char(uint32_t id, char c)
684{
685 int ret = 0;
686 int tmp;
687 char callnum_c;
688 mbtk_call_dtmf_info_t *dtmf = NULL;
689
690 if(voice_handle->handle == NULL)
691 {
692 LOGE("ql_voice_set_dtmf call_info_handle NULL");
693 return QL_ERR_FAILED;
694 }
695
696 dtmf = (mbtk_call_dtmf_info_t*)malloc(sizeof(mbtk_call_dtmf_info_t));
697 memset(dtmf,0x00, sizeof(mbtk_call_dtmf_info_t));
698
699 tmp = (int)c;
700
701 callnum_c = c;
702
703 if ((tmp >= 48 && tmp <= 57) || (tmp >= 65 && tmp <= 68) || (tmp == 42) || (tmp == 35))
704 {
705 dtmf->duration = 300;
706 dtmf->character = callnum_c;
707
l.yange4f94f42025-04-29 18:08:39 -0700708 ret = mbtk_ds_dtmf_send(voice_handle->handle,s_voice_slot, dtmf);
b.liud440f9f2025-04-18 10:44:31 +0800709 if (ret)
710 {
711 LOGE("mbtk_dtmf_send Error : %d", ret);
712 ret = QL_ERR_FAILED;
713 goto err;
714 }
715 }
716 else
717 {
718 LOGE("ql_voice_set_dtmf callnum demand ERR");
719 ret = QL_ERR_FAILED;
720 goto err;
721 }
722
723err:
724 free(dtmf);
725 return ret;
726
727}
728
729/*-----------------------------------------------------------------------------------------------*/
730/**
731 @brief Sets voice call callback handler.
732 @param[in] cb call back handler.
733 @return Whether the voice call callback handler was successfully set.
734 @retval QL_ERR_OK successful.
735 @retval QL_ERR_INVALID_ARG invalid argument.
736 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
737 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
738 @retval Other error code defined by ql_type.h.
739 */
740/*-----------------------------------------------------------------------------------------------*/
741int ql_voice_set_call_cb(ql_voice_call_cb_f cb)
742{
743 if(NULL == voice_handle)
744 {
745 LOGE("[ql_voice_set_msg_recv_cb] voice handle not init.");
746 return QL_ERR_NOT_INIT;
747 }
748
749 voice_handle->call_cb = cb;
750
751 return QL_ERR_OK;
752}
753
754/*-----------------------------------------------------------------------------------------------*/
755/**
756 @brief Sets voice dtmf callback handler.
757 @param[in] cb call back handler.
758 @return Whether the voice call DTMF repcetion callback handler was successfully set.
759 @retval QL_ERR_OK successful.
760 @retval QL_ERR_INVALID_ARG invalid argument.
761 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
762 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
763 @retval Other error code defined by ql_type.h.
764 */
765/*-----------------------------------------------------------------------------------------------*/
766int ql_voice_set_dtmf_cb(ql_voice_dtmf_cb_f cb);
767
768/*-----------------------------------------------------------------------------------------------*/
769/**
770 @brief Dials eCall.
771 @param[in] p_info eCall info.
772 @return Whether a eCall was successfully dialed.
773 @retval QL_ERR_OK successful.
774 @retval QL_ERR_INVALID_ARG invalid argument.
775 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
776 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
777 @retval Other error code defined by ql_type.h.
778 */
779/*-----------------------------------------------------------------------------------------------*/
780int ql_voice_ecall_dial(ql_voice_ecall_info_t *p_info);
781
782/*-----------------------------------------------------------------------------------------------*/
783/**
784 @brief Hangs up eCall.
785 @return Whether the eCall was successfully hung up.
786 @retval QL_ERR_OK successful.
787 @retval QL_ERR_INVALID_ARG invalid argument.
788 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
789 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
790 @retval Other error code defined by ql_type.h.
791 */
792/*-----------------------------------------------------------------------------------------------*/
793int ql_voice_ecall_hangup(void);
794
795/*-----------------------------------------------------------------------------------------------*/
796/**
797 @brief Updates eCall MSD.
798 @param[in] msd Minimum Set of Data.
799 @param[in] msd_len Length of Minimum Set of Data.
800 @return Whether the eCall MSD was successfully updated.
801 @retval QL_ERR_OK successful.
802 @retval QL_ERR_INVALID_ARG invalid argument.
803 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
804 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
805 @retval Other error code defined by ql_type.h.
806 */
807/*-----------------------------------------------------------------------------------------------*/
808int ql_voice_ecall_update_msd(const uint8_t *msd, uint32_t msd_len);
809
810/*-----------------------------------------------------------------------------------------------*/
811/**
812 @brief Pushes eCall MSD.
813 @param[out] state eCall state.
814 @return Whether the eCall MSD was successfully pushed.
815 @retval QL_ERR_OK successful.
816 @retval QL_ERR_INVALID_ARG invalid argument.
817 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
818 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
819 @retval Other error code defined by ql_type.h.
820 */
821/*-----------------------------------------------------------------------------------------------*/
822int ql_voice_ecall_push_msd(QL_VOICE_ECALL_STATE_E *state);
823
824/*-----------------------------------------------------------------------------------------------*/
825/**
826 @brief Gets eCall config.
827 @param[in] p_config eCall config.
828 @return Whether the eCall config was successfully obtained.
829 @retval QL_ERR_OK successful.
830 @retval QL_ERR_INVALID_ARG invalid argument.
831 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
832 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
833 @retval Other error code defined by ql_type.h.
834 */
835/*-----------------------------------------------------------------------------------------------*/
836int ql_voice_ecall_get_config(ql_voice_ecall_config_t *p_config);
837
838/*-----------------------------------------------------------------------------------------------*/
839/**
840 @brief Sets eCall config.
841 @param[in] item Items to set.
842 @param[in] p_config eCall config.
843 @return Whether the eCall config was successfully set.
844 @retval QL_ERR_OK successful.
845 @retval QL_ERR_INVALID_ARG invalid argument.
846 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
847 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
848 @retval Other error code defined by ql_type.h.
849 */
850/*-----------------------------------------------------------------------------------------------*/
851int ql_voice_ecall_set_config(int item, ql_voice_ecall_config_t *p_config);
852
853/*-----------------------------------------------------------------------------------------------*/
854/**
855 @brief Sets eCall event callback handler.
856 @param[in] cb call back handler.
857 @return Whether the eCall event callback handler was successfully set.
858 @retval QL_ERR_OK successful.
859 @retval QL_ERR_INVALID_ARG invalid argument.
860 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
861 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
862 @retval Other error code defined by ql_type.h.
863 */
864/*-----------------------------------------------------------------------------------------------*/
865int ql_voice_ecall_set_event_cb(ql_voice_ecall_event_cb_f cb);
866
867/*-----------------------------------------------------------------------------------------------*/
868/**
869 @brief Sets eCall status callback handler.
870 @param[in] cb call back handler.
871 @return Whether the eCall status callback handler was successfully set.
872 @retval QL_ERR_OK successful.
873 @retval QL_ERR_INVALID_ARG invalid argument.
874 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
875 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
876 @retval Other error code defined by ql_type.h.
877 */
878/*-----------------------------------------------------------------------------------------------*/
879int ql_voice_ecall_set_status_cb(ql_voice_ecall_status_cb_f cb);
880
881/*-----------------------------------------------------------------------------------------------*/
882/**
883 @brief Registration server error callback. Currently, only if the server exits abnormally,
884 the callback function will be executed, and the error code is QL_ERR_ABORTED;
885 @param[in] cb Callback function
886 @return
887 QL_ERR_OK - successful
888 Other - error code defined by ql_type.h
889 */
890/*-----------------------------------------------------------------------------------------------*/
891int ql_voice_set_service_error_cb(ql_voice_service_error_cb_f cb)
892{
893 if(NULL == voice_handle)
894 {
895 LOGE("[ql_voice_set_service_error_cb] voice handle not init.");
896 return QL_ERR_NOT_INIT;
897 }
898
899 voice_handle->server_cb = cb;
900
901 return QL_ERR_OK;
902}
903
904/*-----------------------------------------------------------------------------------------------*/
905/**
906 @brief Binds the current control point to a specific subscription.
907 @param[in] sub Subscription type.
908 @return Whether the subscription was successfully bound.
909 @retval QL_ERR_OK successful.
910 @retval QL_ERR_INVALID_ARG invalid argument.
911 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
912 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
913 @retval Other error code defined by ql_type.h.
914 */
915/*-----------------------------------------------------------------------------------------------*/
916//int ql_voice_bind_subscription(QL_VOICE_SUBSCRIPTION_E sub);
917
918