blob: 367753d831a75279f6476a988dda1cd2ede73e7f [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
102
103 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}
121
122
123static void ql_voice_state_change_cb(const void* data, int data_len)
124{
125 if(NULL == data)
126 {
127 LOGE("[ql_voice_state_change_cb] data is null.");
128 return;
129 }
130
131 if(voice_handle->call_cb == NULL) {
132 LOGW("voice_state_change_cb not set.");
133 return;
134 }
135
136 mbtk_call_info_t *reg = (mbtk_call_info_t *)data;
137
138 int ql_reason = 0;
139 end_reason_mbtk_to_ql((char*)reg->end_reason, &ql_reason);
140 LOG("ql_voice_state_change_cb ql_reason:%d", ql_reason);
141
142
143 if(MBTK_RIL_CALL_STATE_DISCONNECT != reg->state)
144 {
145 LOG("ql_voice_state_change_cb : %d, %d, %d, %d, %d, %s, %d, %s", reg->dir1, reg->dir, reg->state, reg->mode, reg->mpty, reg->phone_number, reg->type, reg->end_reason);
146
147 switch(reg->state)
148 {
149 case 0:
150 voice_handle->state_t = QL_VOICE_STATE_ACTIVE;
151 break;
152 case 1:
153 voice_handle->state_t = QL_VOICE_STATE_HOLDING;
154 break;
155 case 2:
156 voice_handle->state_t = QL_VOICE_STATE_DIALING;
157 break;
158 case 3:
159 voice_handle->state_t = QL_VOICE_STATE_ALERTING;
160 break;
161 case 4:
162 voice_handle->state_t = QL_VOICE_STATE_INCOMING;
163 break;
164 case 5:
165 voice_handle->state_t = QL_VOICE_STATE_WAITING;
166 break;
167 case 7:
168 voice_handle->state_t = QL_VOICE_STATE_END;
169 break;
170 }
171
172 if (voice_handle->record_array.records[0].id == 0 || voice_handle->record_array.records[0].id == reg->dir1)
173 {
174 voice_handle->record_array.len = 1;
175 voice_handle->record_array.records[0].id = reg->dir1;
176 voice_handle->record_array.records[0].tech = 1;
177 voice_handle->record_array.records[0].dir = reg->dir;
178 voice_handle->record_array.records[0].end_reason = ql_reason;
179 voice_handle->record_array.records[0].state = voice_handle->state_t;
180 memcpy(voice_handle->record_array.records[0].number, reg->phone_number, strlen(reg->phone_number));
181 }
182 else if (voice_handle->record_array.records[0].id != reg->dir1)
183 {
184 voice_handle->record_array.len = 2;
185 voice_handle->record_array.records[1].id = reg->dir1;
186 voice_handle->record_array.records[1].tech = 1;
187 voice_handle->record_array.records[1].dir = reg->dir;
188 voice_handle->record_array.records[1].end_reason = ql_reason;
189 voice_handle->record_array.records[1].state = voice_handle->state_t;
190 memcpy(voice_handle->record_array.records[1].number, reg->phone_number, strlen(reg->phone_number));
191 }
192
193 voice_handle->call_cb(&voice_handle->record_array);
194 }
195 else
196 {
197 LOGI("RING : call dis connected!");
198 voice_handle->record_array.records[0].end_reason = ql_reason;
199 voice_handle->record_array.records[1].end_reason = ql_reason;
200 if(voice_handle->record_array.records[0].id == reg->dir1)
201 {
202 voice_handle->record_array.records[0].state = QL_VOICE_STATE_END;
203 voice_handle->record_array.records[0].id = 0;
204 }
205 if(voice_handle->record_array.records[1].id == reg->dir1)
206 {
207 voice_handle->record_array.records[1].state = QL_VOICE_STATE_END;
208 voice_handle->record_array.records[1].id = 0;
209 voice_handle->record_array.len = 1;
210 }
211 if (reg->disconnected_id == voice_handle->record_array.records[1].id)
212 voice_handle->call_cb(&voice_handle->record_array);
213 else
214 voice_handle->call_cb(&voice_handle->record_array);
215 }
216
217}
218
219static void ql_voice_server_change_cb(const void* data, int data_len)
220{
221 if(data_len != sizeof(int))
222 {
223 LOGE("[ql_voice_server_change_cb] data_len[%d] than int[%d] fail. ", data_len, sizeof(int));
224 }
225 else
226 {
227 int server_state = *(int *)data;
228 if(server_state == 1 && voice_handle->server_cb)
229 {
230 voice_handle->server_cb(QL_ERR_ABORTED);
231 }
232 }
233}
234
235
236/*-----------------------------------------------------------------------------------------------*/
237/**
238 @brief Initializes voice service.
239 @return Whether the voice service was initialized successfully.
240 @retval QL_ERR_OK successful.
241 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
242 @retval Other error code defined by ql_type.h.
243 */
244/*-----------------------------------------------------------------------------------------------*/
245int ql_voice_init(void)
246{
247 if(NULL == voice_handle)
248 {
249 voice_handle = (ql_voice_info_handle_t*)malloc(sizeof(ql_voice_info_handle_t));
250 memset(voice_handle, 0, sizeof(ql_voice_info_handle_t));
251 voice_handle->record_array.records[0].id = 0;
252 if(NULL == voice_handle)
253 {
254 LOGE("[ql_voice_init] voice handle malloc fail.");
255 return QL_ERR_FAILED;
256 }
257
258 voice_handle->handle = mbtk_ril_open(MBTK_AT_PORT_DEF);
259 if(NULL == voice_handle->handle)
260 {
261 LOGE("[ql_voice_init] mbtk handle init fail.");
262 if(voice_handle)
263 {
264 free(voice_handle);
265 voice_handle = NULL;
266 return QL_ERR_FAILED;
267 }
268 }
269
270 int ret = mbtk_call_state_change_cb_reg( ql_voice_state_change_cb);
271 if(ret != MBTK_ERR_OK)
272 {
273 LOGE("[ql_voice_init] set voice state cb fail.[%d]", ret);
274 if(voice_handle->handle)
275 {
276 mbtk_ril_close(MBTK_AT_PORT_DEF);
277 voice_handle->handle = NULL;
278 return QL_ERR_FAILED;
279 }
280 }
281
282 ret = mbtk_ril_ser_state_change_cb_reg(ql_voice_server_change_cb);
283 if(ret != MBTK_ERR_OK)
284 {
285 LOGE("[ql_sim_init] set sim server cb fail.[%d]", ret);
286 if(voice_handle->handle)
287 {
288 mbtk_ril_close(MBTK_AT_PORT_DEF);
289 voice_handle->handle = NULL;
290 return QL_ERR_FAILED;
291 }
292 }
293
294 voice_handle->call_cb = NULL;
295 voice_handle->server_cb = NULL;
296 }
297 return QL_ERR_OK;
298}
299
300/*-----------------------------------------------------------------------------------------------*/
301/**
302 @brief Deinitializes voice service.
303 @return Whether the voice service was deinitialized successfully.
304 @retval QL_ERR_OK successful.
305 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
306 @retval Other error code defined by ql_type.h.
307 */
308/*-----------------------------------------------------------------------------------------------*/
309int ql_voice_deinit(void)
310{
311 if(NULL == voice_handle)
312 {
313 LOGE("[ql_voice_deinit] voice handle not init.");
314 return QL_ERR_NOT_INIT;
315 }
316
317 int ret = 0;
318 voice_handle->server_cb = NULL;
319 voice_handle->call_cb = NULL;
320
321 if(NULL != voice_handle->handle)
322 {
323 ret = mbtk_ril_close(MBTK_AT_PORT_DEF);
324 if(ret != MBTK_ERR_OK)
325 {
326 LOGE("[ql_voice_deinit] mbtk handle deinit fail.[%d]", ret);
327 return QL_ERR_FAILED;
328 }
329 voice_handle->handle = NULL;
330 }
331
332 if(ret != QL_ERR_OK)
333 {
334 LOGE("[ql_voice_deinit] cb thread free deinit fail.");
335 return QL_ERR_FAILED;
336 }
337
338 free(voice_handle);
339 voice_handle = NULL;
340 return QL_ERR_OK;
341}
342
343/*-----------------------------------------------------------------------------------------------*/
344/**
345 @brief Dials a call.
346 @param[in] num phone number to dial.
347 @param[in] len length of phone number, should be less than
348 or euqnal to QL_VOICE_MAX_PHONE_NUMBER.
349 @param[out] id call id.
350 @return Whether a voice call was successfully dialed.
351 @retval QL_ERR_OK successful.
352 @retval QL_ERR_INVALID_ARG invalid argument.
353 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
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_dial(char *num, int len, uint32_t *id)
359{
360 char* phone_num_t = NULL;
361 mbtk_call_info_t reg = {0};
362 int err;
363
364 if(voice_handle->handle == NULL)
365 {
366 LOGE("ql_voice_call_start call_info_handle NULL");
367 return QL_ERR_FAILED;
368 }
369
370 if (num == NULL)
371 {
372 LOGE("ql_voice_call_start phone_number NULL");
373 return QL_ERR_FAILED;
374
375 }
376
377 phone_num_t = num;
378
379 err = mbtk_call_start(voice_handle->handle, phone_num_t);
380 if(err)
381 {
382 LOGE("Error : %d\n", err);
383 return QL_ERR_FAILED;
384 }
385 else
386 {
387 LOGI("Call success.");
388 }
389
390 mbtk_call_reg_get(voice_handle->handle, &reg);
391 *id = reg.dir1;
392 LOG("ql_voice_dial call_id: %d\n", reg.dir1, *id);
393
394 return QL_ERR_OK;
395}
396
397/*-----------------------------------------------------------------------------------------------*/
398/**
399 @brief Cancels dialing with given id.
400 @param[in] id call id returned from dial.
401 @return Whether the voice call was successfully cancelled.
402 @retval QL_ERR_OK successful.
403 @retval QL_ERR_INVALID_ARG invalid argument.
404 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
405 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
406 @retval Other error code defined by ql_type.h.
407 */
408/*-----------------------------------------------------------------------------------------------*/
409int ql_voice_cancel_dial(uint32_t id);
410
411/*-----------------------------------------------------------------------------------------------*/
412/**
413 @brief hangup all dialing.
414 @return Whether all voice call were successfully hangup.
415 @retval QL_ERR_OK successful.
416 @retval QL_ERR_INVALID_ARG invalid argument.
417 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
418 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
419 @retval Other error code defined by ql_type.h.
420 */
421/*-----------------------------------------------------------------------------------------------*/
422int ql_voice_hangup_all(void)
423{
424 int err;
425
426 if(voice_handle->handle == NULL)
427 {
428 LOGE("ql_voice_call_end call_info_handle NULL");
429 return QL_ERR_FAILED;
430 }
431
432 err = mbtk_call_hang(voice_handle->handle);
433 if(err)
434 {
435 LOGE("Error : %d", err);
436 return QL_ERR_FAILED;
437 }
438 else
439 {
440 LOGI("Call hang up a all.");
441 }
442 return QL_ERR_OK;
443}
444
445/*-----------------------------------------------------------------------------------------------*/
446/**
447 @brief Answers the call.
448 @param[in] id call id returned from dial.
449 @return Whether the voice call was successfully answered.
450 @retval QL_ERR_OK successful.
451 @retval QL_ERR_INVALID_ARG invalid argument.
452 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
453 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
454 @retval Other error code defined by ql_type.h.
455 */
456/*-----------------------------------------------------------------------------------------------*/
457int ql_voice_answer(uint32_t id)
458{
459 int err;
460
461 if(voice_handle->handle == NULL)
462 {
463 LOGE("ql_voice_call_anser call_info_handle NULL");
464 return QL_ERR_FAILED;
465 }
466
467 err = mbtk_call_answer(voice_handle->handle);
468 if(err)
469 {
470 LOGE("Error : %d", err);
471 return QL_ERR_FAILED;
472 }
473 else
474 {
475 LOGI("Answer success.");
476 }
477 return QL_ERR_OK;
478}
479
480/*-----------------------------------------------------------------------------------------------*/
481/**
482 @brief Hangs up the call.
483 @param[in] id call id returned from dial.
484 @return Whether the voice call was successfully hung up.
485 @retval QL_ERR_OK successful.
486 @retval QL_ERR_INVALID_ARG invalid argument.
487 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
488 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
489 @retval Other error code defined by ql_type.h.
490 */
491/*-----------------------------------------------------------------------------------------------*/
492int ql_voice_hangup(uint32_t id);
493
494/*-----------------------------------------------------------------------------------------------*/
495/**
496 @brief Holds the call when mutil calls is activated.
497 @param[in] id call id returned from dial.
498 @return Whether the voice call was successfully held.
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_hold(uint32_t id);
507
508/*-----------------------------------------------------------------------------------------------*/
509/**
510 @brief Releases the call from hold when mutil calls is activated.
511 @param[in] id call id returned from dial.
512 @return Whether the voice call was successfully unheld.
513 @retval QL_ERR_OK successful.
514 @retval QL_ERR_INVALID_ARG invalid argument.
515 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
516 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
517 @retval Other error code defined by ql_type.h.
518 */
519/*-----------------------------------------------------------------------------------------------*/
520int ql_voice_unhold(uint32_t id);
521
522/*-----------------------------------------------------------------------------------------------*/
523/**
524 @brief Gets call records.
525 @param[in] p_arr pointer to ql_voice_record_array_t.
526 @return Whether the call records were successfully obtained.
527 @retval QL_ERR_OK successful.
528 @retval QL_ERR_INVALID_ARG invalid argument.
529 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
530 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
531 @retval Other error code defined by ql_type.h.
532 */
533/*-----------------------------------------------------------------------------------------------*/
534int ql_voice_get_records(ql_voice_record_array_t *p_arr)
535{
536 if(NULL == p_arr)
537 {
538 LOGE("ql_voice_get_records p_arr NULL");
539 return QL_ERR_FAILED;
540 }
541 memcpy(p_arr, &voice_handle->record_array, sizeof(voice_handle->record_array));
542
543 return QL_ERR_OK;
544}
545
546/*-----------------------------------------------------------------------------------------------*/
547/**
548 @brief Registers or Unregisters forwarding.
549 @param[in] reg 0 - unregister, 1 - register.
550 @param[in] cond forwarding condition.
551 @param[in] num phone number.
552 @param[in] len length of phone numebr.
553 @return Whether the voice call forward was registered or unregistered successfully.
554 @retval QL_ERR_OK successful.
555 @retval QL_ERR_INVALID_ARG invalid argument.
556 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
557 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
558 @retval Other error code defined by ql_type.h.
559 */
560/*-----------------------------------------------------------------------------------------------*/
561int ql_voice_forwarding(int reg, QL_VOICE_FW_COND_E cond, char *num, int len);
562
563/*-----------------------------------------------------------------------------------------------*/
564/**
565 @brief Gets forwarding status.
566 @param[in] cond forwarding condition.
567 @param[out] p_status pointer to ql_voice_fw_status_t.
568 @return Whether the voice call forward status was successfully obtained.
569 @retval QL_ERR_OK successful.
570 @retval QL_ERR_INVALID_ARG invalid argument.
571 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
572 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
573 @retval Other error code defined by ql_type.h.
574 */
575/*-----------------------------------------------------------------------------------------------*/
576int ql_voice_get_forwarding_status(QL_VOICE_FW_COND_E cond, ql_voice_fw_status_t *p_status);
577
578/*-----------------------------------------------------------------------------------------------*/
579/**
580 @brief Enables or disables call waiting.
581 @param[in] enable 0 - disable, other - enable.
582 @return Whether the voice call waiting was enabled or disabled successfully.
583 @retval QL_ERR_OK successful.
584 @retval QL_ERR_INVALID_ARG invalid argument.
585 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
586 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
587 @retval Other error code defined by ql_type.h.
588 */
589/*-----------------------------------------------------------------------------------------------*/
590int ql_voice_waiting(int enable);
591
592/*-----------------------------------------------------------------------------------------------*/
593/**
594 @brief Gets call waiting status.
595 @param[out] enabled 0 - waiting is disabled, 1 - waiting is enabled.
596 @return Whether the voice call waiting status was successfully obtained.
597 @retval QL_ERR_OK successful.
598 @retval QL_ERR_INVALID_ARG invalid argument.
599 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
600 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
601 @retval Other error code defined by ql_type.h.
602 */
603/*-----------------------------------------------------------------------------------------------*/
604int ql_voice_get_waiting_status(int *enabled);
605
606/*-----------------------------------------------------------------------------------------------*/
607/**
608 @brief Enables or disables auto answer.
609 @param[in] enable 0 - disable, other - enable.
610 @param[in] sec wait this `sec' seconds before auto answer.
611 @return Whether the voice call autoanswer was enabled or disabled successfully.
612 @retval QL_ERR_OK successful.
613 @retval QL_ERR_INVALID_ARG invalid argument.
614 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
615 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
616 @retval Other error code defined by ql_type.h.
617 */
618/*-----------------------------------------------------------------------------------------------*/
619int ql_voice_autoanswer(int enable, uint32_t sec);
620
621/*-----------------------------------------------------------------------------------------------*/
622/**
623 @brief Sends a DTMF(Dual Tone Multi Frequency) character over the call ID.
624 @param[in] id call id returned from dial.
625 @param[in] c DTMF character to be sent. Valid DTMF characters are 0-9, A-D, '*', '#'.
626 @return Whether a DTMF character was successfully sent.
627 @retval QL_ERR_OK successful.
628 @retval QL_ERR_INVALID_ARG invalid argument.
629 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
630 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
631 @retval Other error code defined by ql_type.h.
632 */
633/*-----------------------------------------------------------------------------------------------*/
634int ql_voice_send_dtmf_char(uint32_t id, char c)
635{
636 int ret = 0;
637 int tmp;
638 char callnum_c;
639 mbtk_call_dtmf_info_t *dtmf = NULL;
640
641 if(voice_handle->handle == NULL)
642 {
643 LOGE("ql_voice_set_dtmf call_info_handle NULL");
644 return QL_ERR_FAILED;
645 }
646
647 dtmf = (mbtk_call_dtmf_info_t*)malloc(sizeof(mbtk_call_dtmf_info_t));
648 memset(dtmf,0x00, sizeof(mbtk_call_dtmf_info_t));
649
650 tmp = (int)c;
651
652 callnum_c = c;
653
654 if ((tmp >= 48 && tmp <= 57) || (tmp >= 65 && tmp <= 68) || (tmp == 42) || (tmp == 35))
655 {
656 dtmf->duration = 300;
657 dtmf->character = callnum_c;
658
659 ret = mbtk_dtmf_send(voice_handle->handle, dtmf);
660 if (ret)
661 {
662 LOGE("mbtk_dtmf_send Error : %d", ret);
663 ret = QL_ERR_FAILED;
664 goto err;
665 }
666 }
667 else
668 {
669 LOGE("ql_voice_set_dtmf callnum demand ERR");
670 ret = QL_ERR_FAILED;
671 goto err;
672 }
673
674err:
675 free(dtmf);
676 return ret;
677
678}
679
680/*-----------------------------------------------------------------------------------------------*/
681/**
682 @brief Sets voice call callback handler.
683 @param[in] cb call back handler.
684 @return Whether the voice call callback handler was successfully set.
685 @retval QL_ERR_OK successful.
686 @retval QL_ERR_INVALID_ARG invalid argument.
687 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
688 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
689 @retval Other error code defined by ql_type.h.
690 */
691/*-----------------------------------------------------------------------------------------------*/
692int ql_voice_set_call_cb(ql_voice_call_cb_f cb)
693{
694 if(NULL == voice_handle)
695 {
696 LOGE("[ql_voice_set_msg_recv_cb] voice handle not init.");
697 return QL_ERR_NOT_INIT;
698 }
699
700 voice_handle->call_cb = cb;
701
702 return QL_ERR_OK;
703}
704
705/*-----------------------------------------------------------------------------------------------*/
706/**
707 @brief Sets voice dtmf callback handler.
708 @param[in] cb call back handler.
709 @return Whether the voice call DTMF repcetion callback handler was successfully set.
710 @retval QL_ERR_OK successful.
711 @retval QL_ERR_INVALID_ARG invalid argument.
712 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
713 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
714 @retval Other error code defined by ql_type.h.
715 */
716/*-----------------------------------------------------------------------------------------------*/
717int ql_voice_set_dtmf_cb(ql_voice_dtmf_cb_f cb);
718
719/*-----------------------------------------------------------------------------------------------*/
720/**
721 @brief Dials eCall.
722 @param[in] p_info eCall info.
723 @return Whether a eCall was successfully dialed.
724 @retval QL_ERR_OK successful.
725 @retval QL_ERR_INVALID_ARG invalid argument.
726 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
727 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
728 @retval Other error code defined by ql_type.h.
729 */
730/*-----------------------------------------------------------------------------------------------*/
731int ql_voice_ecall_dial(ql_voice_ecall_info_t *p_info);
732
733/*-----------------------------------------------------------------------------------------------*/
734/**
735 @brief Hangs up eCall.
736 @return Whether the eCall was successfully hung up.
737 @retval QL_ERR_OK successful.
738 @retval QL_ERR_INVALID_ARG invalid argument.
739 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
740 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
741 @retval Other error code defined by ql_type.h.
742 */
743/*-----------------------------------------------------------------------------------------------*/
744int ql_voice_ecall_hangup(void);
745
746/*-----------------------------------------------------------------------------------------------*/
747/**
748 @brief Updates eCall MSD.
749 @param[in] msd Minimum Set of Data.
750 @param[in] msd_len Length of Minimum Set of Data.
751 @return Whether the eCall MSD was successfully updated.
752 @retval QL_ERR_OK successful.
753 @retval QL_ERR_INVALID_ARG invalid argument.
754 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
755 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
756 @retval Other error code defined by ql_type.h.
757 */
758/*-----------------------------------------------------------------------------------------------*/
759int ql_voice_ecall_update_msd(const uint8_t *msd, uint32_t msd_len);
760
761/*-----------------------------------------------------------------------------------------------*/
762/**
763 @brief Pushes eCall MSD.
764 @param[out] state eCall state.
765 @return Whether the eCall MSD was successfully pushed.
766 @retval QL_ERR_OK successful.
767 @retval QL_ERR_INVALID_ARG invalid argument.
768 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
769 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
770 @retval Other error code defined by ql_type.h.
771 */
772/*-----------------------------------------------------------------------------------------------*/
773int ql_voice_ecall_push_msd(QL_VOICE_ECALL_STATE_E *state);
774
775/*-----------------------------------------------------------------------------------------------*/
776/**
777 @brief Gets eCall config.
778 @param[in] p_config eCall config.
779 @return Whether the eCall config was successfully obtained.
780 @retval QL_ERR_OK successful.
781 @retval QL_ERR_INVALID_ARG invalid argument.
782 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
783 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
784 @retval Other error code defined by ql_type.h.
785 */
786/*-----------------------------------------------------------------------------------------------*/
787int ql_voice_ecall_get_config(ql_voice_ecall_config_t *p_config);
788
789/*-----------------------------------------------------------------------------------------------*/
790/**
791 @brief Sets eCall config.
792 @param[in] item Items to set.
793 @param[in] p_config eCall config.
794 @return Whether the eCall config was successfully set.
795 @retval QL_ERR_OK successful.
796 @retval QL_ERR_INVALID_ARG invalid argument.
797 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
798 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
799 @retval Other error code defined by ql_type.h.
800 */
801/*-----------------------------------------------------------------------------------------------*/
802int ql_voice_ecall_set_config(int item, ql_voice_ecall_config_t *p_config);
803
804/*-----------------------------------------------------------------------------------------------*/
805/**
806 @brief Sets eCall event callback handler.
807 @param[in] cb call back handler.
808 @return Whether the eCall event callback handler was successfully set.
809 @retval QL_ERR_OK successful.
810 @retval QL_ERR_INVALID_ARG invalid argument.
811 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
812 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
813 @retval Other error code defined by ql_type.h.
814 */
815/*-----------------------------------------------------------------------------------------------*/
816int ql_voice_ecall_set_event_cb(ql_voice_ecall_event_cb_f cb);
817
818/*-----------------------------------------------------------------------------------------------*/
819/**
820 @brief Sets eCall status callback handler.
821 @param[in] cb call back handler.
822 @return Whether the eCall status callback handler was successfully set.
823 @retval QL_ERR_OK successful.
824 @retval QL_ERR_INVALID_ARG invalid argument.
825 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
826 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
827 @retval Other error code defined by ql_type.h.
828 */
829/*-----------------------------------------------------------------------------------------------*/
830int ql_voice_ecall_set_status_cb(ql_voice_ecall_status_cb_f cb);
831
832/*-----------------------------------------------------------------------------------------------*/
833/**
834 @brief Registration server error callback. Currently, only if the server exits abnormally,
835 the callback function will be executed, and the error code is QL_ERR_ABORTED;
836 @param[in] cb Callback function
837 @return
838 QL_ERR_OK - successful
839 Other - error code defined by ql_type.h
840 */
841/*-----------------------------------------------------------------------------------------------*/
842int ql_voice_set_service_error_cb(ql_voice_service_error_cb_f cb)
843{
844 if(NULL == voice_handle)
845 {
846 LOGE("[ql_voice_set_service_error_cb] voice handle not init.");
847 return QL_ERR_NOT_INIT;
848 }
849
850 voice_handle->server_cb = cb;
851
852 return QL_ERR_OK;
853}
854
855/*-----------------------------------------------------------------------------------------------*/
856/**
857 @brief Binds the current control point to a specific subscription.
858 @param[in] sub Subscription type.
859 @return Whether the subscription was successfully bound.
860 @retval QL_ERR_OK successful.
861 @retval QL_ERR_INVALID_ARG invalid argument.
862 @retval QL_ERR_UNKNOWN unknown error, failed to connect to service.
863 @retval QL_ERR_SERVICE_NOT_READY service is not ready, need to retry.
864 @retval Other error code defined by ql_type.h.
865 */
866/*-----------------------------------------------------------------------------------------------*/
867//int ql_voice_bind_subscription(QL_VOICE_SUBSCRIPTION_E sub);
868
869