blob: ab384933f4440039f083587a0f7f22c04d81a72f [file] [log] [blame]
hong.liucd370792025-05-28 06:29:19 -07001#include "gsw_voice_interface.h"
b.liu68a94c92025-05-24 12:53:41 +08002#include <dlfcn.h>
3#include <pthread.h>
xy.hecfb7d682025-05-28 21:39:12 +08004#include <stdio.h>
5#include <string.h>
6#include <stdlib.h>
b.liu68a94c92025-05-24 12:53:41 +08007
8// mbtk includes
9
10typedef unsigned int uint32;
11typedef unsigned char uint8;
12typedef unsigned short uint16;
13typedef void (*mbtk_info_callback_func)(const void* data, int data_len);
14
15typedef struct
16{
17 int client_fd;
18 pthread_t read_thread_id;
19 int exit_fd[2];
20 bool is_waitting;
21 pthread_cond_t cond;
22 pthread_mutex_t mutex;
23
24 pthread_mutex_t send_mutex;
25
26 // Temp response data.
27 uint16 info_err;
28 uint16 data_len;
29 void *data;
30
31 //mbtk wyq for server_ready_status add start
32 char server_ready_status;
33 //mbtk wyq for server_ready_status add end
34
35 mbtk_info_callback_func net_state_cb;
36 mbtk_info_callback_func call_state_cb;
37 mbtk_info_callback_func sms_state_cb;
38 mbtk_info_callback_func radio_state_cb;
39 mbtk_info_callback_func sim_state_cb;
40 mbtk_info_callback_func pdp_state_cb;
41 //add signal by xr
42 mbtk_info_callback_func signal_state_cb;
43} mbtk_info_handle_t;
44
45typedef struct
46{
47 uint8 call_wait;
48 uint8 dir1;
49 uint8 dir;
50 uint8 state;
51 uint8 mode;
52 uint8 mpty;
53 char phone_number[100];
54 uint8 type;
55 uint8 pas;
56 uint8 disconnected_id;
57 uint8 end_reason[128];
58} __attribute__((packed)) mbtk_call_info_t;
59
60typedef enum {
61 MBTK_CLCC = 1,
62 MBTK_CPAS,
63 MBTK_DISCONNECTED,
64} mbtk_call_enum;
65
66typedef enum {
67 MBTK_CALL_RADY, //MT allows commands from TA/TE
68 MBTK_CALL_UNAVAILABLE, //MT does not allow commands from TA/TE
69 MBTK_CALL_UNKNOWN, //MT is not guaranteed to respond to instructions
70 MBTK_CALL_RINGING, //MT is ready for commands from TA/TE, but the ringer is active
71 MBTK_CALL_PROGRESS, //MT is ready for commands from TA/TE, but a call is in progress
72 MBTK_CALL_ASLEEP, //MT is unable to process commands from TA/TE because it is in a low functionality state
73 MBTK_CALL_ACTIVE,
74} mbtk_call_pas_enum;
75
76
77//----------------end_reason start------------
78//mbtk end_reason define
79#define MBTK_VOICE_END_REASON_UNKNOWN "0 "
80#define MBTK_VOICE_END_REASON_UNASSIGNED_NUMBER "1 "
81#define MBTK_VOICE_END_REASON_NO_ROUTE_DES "3 "
82#define MBTK_VOICE_END_REASON_CHANNEL_UNACCEPTABLE "6 "
83#define MBTK_VOICE_END_REASON_OPERATOR_DETERMINED_BARRING "8 "
84#define MBTK_VOICE_END_REASON_NORMAL_CALL_CLEARING "16 "
85#define MBTK_VOICE_END_REASON_USER_BUSY "17 "
86#define MBTK_VOICE_END_REASON_NO_USER_RESPONDING "18 "
87#define MBTK_VOICE_END_REASON_USER_ALERTING_NO_ANSWER "19 "
88#define MBTK_VOICE_END_REASON_CALL_REJECTED "21 "
89#define MBTK_VOICE_END_REASON_NUMBER_CHANGED "22 "
90#define MBTK_VOICE_END_REASON_PREEMPTION "25 "
91#define MBTK_VOICE_END_REASON_NON_SELECTED_USER_CLEARING "26 "
92#define MBTK_VOICE_END_REASON_DESTINATION_OUT_OF_ORDER "27 "
93#define MBTK_VOICE_END_REASON_INVALID_NUMBER_FORMAT "28 "
94#define MBTK_VOICE_END_REASON_FACILITY_REJECTED "29 "
95#define MBTK_VOICE_END_REASON_STATUS_ENQUIRY "30 "
96#define MBTK_VOICE_END_REASON_NORMAL_UNSPECIFIED "31 "
97#define MBTK_VOICE_END_REASON_NO_CIRCUIT_AVAILABLE "34 "
98#define MBTK_VOICE_END_REASON_NETWORK_OUT_OF_ORDER "38 "
99#define MBTK_VOICE_END_REASON_TEMPORARY_FAILURE "41 "
100#define MBTK_VOICE_END_REASON_SWITCHING_EQUIPMENT_CONGESTION "42 "
101#define MBTK_VOICE_END_REASON_ACCESS_INFORMATION_DISCARDED "43 "
102#define MBTK_VOICE_END_REASON_REQUESTED_CIRCUIT_UNAVAILABLE "44 "
103#define MBTK_VOICE_END_REASON_RESOURCE_UNAVAILABLE "47 "
104#define MBTK_VOICE_END_REASON_QOS_UNAVAILABLE "49 "
105#define MBTK_VOICE_END_REASON_REQUESTED_FACILITY_NOT_SUBSCRIBED "50 "
106#define MBTK_VOICE_END_REASON_INCOMING_CALLS_BARRED_WITHIN_CUG "55 "
107#define MBTK_VOICE_END_REASON_BEARER_CAPABILITY_NOT_AUTHORIZED "57 "
108#define MBTK_VOICE_END_REASON_BEARER_CAPABILITY_NOT_AVAILABLE "58 "
109#define MBTK_VOICE_END_REASON_SERVICE_NOT_AVAILABLE "63 "
110#define MBTK_VOICE_END_REASON_BEARER_SERVICE_NOT_IMPLEMENTED "65 "
111#define MBTK_VOICE_END_REASON_ACM_MAX_REACHED "68 "
112#define MBTK_VOICE_END_REASON_FACILITY_NOT_IMPLEMENTED "69 "
113#define MBTK_VOICE_END_REASON_ONLY_RDI_BEARER_CAPABILITY_AVAILABLE "70 "
114#define MBTK_VOICE_END_REASON_SERVICE_NOT_IMPLEMENTED "79 "
115#define MBTK_VOICE_END_REASON_INVALID_TRANSACTION_ID "81 "
116#define MBTK_VOICE_END_REASON_USER_NOT_MEMBER_OF_CUG "87 "
117#define MBTK_VOICE_END_REASON_INCOMPATIBLE_DESTINATION "88 "
118#define MBTK_VOICE_END_REASON_INVALID_TRANSIT_NETWORK_SELECTION "91 "
119#define MBTK_VOICE_END_REASON_INCORRECT_MESSAGE "95 "
120#define MBTK_VOICE_END_REASON_INVALID_MANDATORY_INFORMATION "96 "
121#define MBTK_VOICE_END_REASON_MESSAGE_TYPE_NON_EXISTENT "97 "
122#define MBTK_VOICE_END_REASON_MESSAGE_TYPE_WRONG_STATE "98 "
123#define MBTK_VOICE_END_REASON_INFORMATION_ELEMENT_NOT_EXISTENT "99 "
124#define MBTK_VOICE_END_REASON_CONDITIONAL_IE_ERROR "100 "
125#define MBTK_VOICE_END_REASON_MESSAGE_WRONG_STATE "101 "
126#define MBTK_VOICE_END_REASON_RECOVERY_AFTER_TIMER_EXPIRY "102 "
127#define MBTK_VOICE_END_REASON_PROTOCOL_ERROR_UNSPECIFIED "111 "
128#define MBTK_VOICE_END_REASON_INERWORKING_UNSPECIFIED "127 "
129#define MBTK_VOICE_END_REASON_CALL_BARRING "224 "
130#define MBTK_VOICE_END_REASON_FDN_BLOCKED "241 "
131#define MBTK_VOICE_END_REASON_END "end"
132
133typedef enum{
134 GSW_LOCAL_END_NORMAL = 0,
135 GSW_PEER_END_NORMAL,
136 GSW_OTHER_END_NORMAL,
137 GSW_END_ABNORMAL,
138} gsw_call_end_reason_enum;
139
140//mbtk end_reason enum define
141typedef struct {
142 char mbtk_end_reason[128];
143 gsw_call_end_reason_enum end_reason;
144}end_reason_t;
145
146end_reason_t g_end_reason[] = {
147{MBTK_VOICE_END_REASON_UNASSIGNED_NUMBER, GSW_PEER_END_NORMAL},
148{MBTK_VOICE_END_REASON_NO_ROUTE_DES, GSW_END_ABNORMAL},
149{MBTK_VOICE_END_REASON_CHANNEL_UNACCEPTABLE, GSW_END_ABNORMAL},
150{MBTK_VOICE_END_REASON_OPERATOR_DETERMINED_BARRING, GSW_END_ABNORMAL},
151{MBTK_VOICE_END_REASON_NORMAL_CALL_CLEARING, GSW_LOCAL_END_NORMAL},
152{MBTK_VOICE_END_REASON_USER_BUSY, GSW_OTHER_END_NORMAL},
153{MBTK_VOICE_END_REASON_NO_USER_RESPONDING, GSW_OTHER_END_NORMAL},
154{MBTK_VOICE_END_REASON_USER_ALERTING_NO_ANSWER, GSW_LOCAL_END_NORMAL},
155{MBTK_VOICE_END_REASON_CALL_REJECTED, GSW_LOCAL_END_NORMAL},
156{MBTK_VOICE_END_REASON_NUMBER_CHANGED, GSW_OTHER_END_NORMAL},
157{MBTK_VOICE_END_REASON_PREEMPTION, GSW_OTHER_END_NORMAL},
158{MBTK_VOICE_END_REASON_NON_SELECTED_USER_CLEARING, GSW_OTHER_END_NORMAL},
159{MBTK_VOICE_END_REASON_DESTINATION_OUT_OF_ORDER, GSW_OTHER_END_NORMAL},
160{MBTK_VOICE_END_REASON_INVALID_NUMBER_FORMAT, GSW_OTHER_END_NORMAL},
161{MBTK_VOICE_END_REASON_FACILITY_REJECTED, GSW_OTHER_END_NORMAL},
162{MBTK_VOICE_END_REASON_STATUS_ENQUIRY, GSW_OTHER_END_NORMAL},
163{MBTK_VOICE_END_REASON_NORMAL_UNSPECIFIED, GSW_PEER_END_NORMAL},
164{MBTK_VOICE_END_REASON_NO_CIRCUIT_AVAILABLE, GSW_OTHER_END_NORMAL},
165{MBTK_VOICE_END_REASON_NETWORK_OUT_OF_ORDER, GSW_END_ABNORMAL},
166{MBTK_VOICE_END_REASON_TEMPORARY_FAILURE, GSW_END_ABNORMAL},
167{MBTK_VOICE_END_REASON_SWITCHING_EQUIPMENT_CONGESTION, GSW_OTHER_END_NORMAL},
168{MBTK_VOICE_END_REASON_ACCESS_INFORMATION_DISCARDED, GSW_OTHER_END_NORMAL},
169{MBTK_VOICE_END_REASON_REQUESTED_CIRCUIT_UNAVAILABLE, GSW_OTHER_END_NORMAL},
170{MBTK_VOICE_END_REASON_SERVICE_NOT_AVAILABLE, GSW_END_ABNORMAL},
171{MBTK_VOICE_END_REASON_END, GSW_OTHER_END_NORMAL}
172
173};
174
175int gsw_global_end_reason = GSW_OTHER_END_NORMAL;
176
177//----------------end_reason end------------
178
179
180typedef uint32_t voice_client_handle_type;
181
182
183
184static mbtk_info_handle_t* call_info_handle = NULL;
185static int level_call = 0;
186int gsw_voice_init_flag = 0;
187int auto_answer_flag = 0;
188voice_client_handle_type g_call_val = -1;
189CallStateInd gsw_voice_callback = NULL;
190
191
192int state_t = 0;
193char* phone_num_t = NULL;
194char* phone_num_t2 = NULL;
195int call_id_t = 0;
196int call_id_t2 = 0;
197
198#define lib_mbtk_path "/lib/libmbtk_lib.so"
199static void *dlHandle_mbtk;
200
201static mbtk_info_handle_t* (*mbtk_info_handle_get)(void);
202int (*mbtk_call_state_change_cb_reg)(mbtk_info_handle_t* handle, mbtk_info_callback_func cb);
203int (*mbtk_call_start)(mbtk_info_handle_t* handle, char* phone_number);
204int (*mbtk_call_hang)(mbtk_info_handle_t* handle);
205int (*mbtk_a_call_hang)(mbtk_info_handle_t* handle, int phone_id);
206int (*mbtk_call_answer)(mbtk_info_handle_t* handle);
207int (*mbtk_call_reg_get)(mbtk_info_handle_t* handle, mbtk_call_info_t *reg);
208static void (*mbtk_log)(int level, const char *format, ...);
209static void (*mbtk_log_init)(char *path, char *tag);
210
211/*rtp begin*/
212int (*mbtk_rtp_init)();
213int (*mbtk_rtp_deinit)();
214int (*mbtk_rtp_enable)(bool enable);
215int (*mbtk_rtp_remote_ip_set)(const char *ipv4);
216int (*mbtk_rtp_server_port_set)(int port);
217int (*mbtk_rtp_client_port_set)(int port);
218int (*mbtk_rtp_sample_rate_set)(int sample_rate);
219int (*mbtk_rtp_channel_set)(int channel);
q.huang020cc232025-06-06 19:06:18 +0800220int (*mbtk_rtp_vlan_set)(const char *vlan);
b.liu68a94c92025-05-24 12:53:41 +0800221/*rtp end*/
222
223
224#ifndef LOG_ERR_LEVEL
225#define LOG_ERR_LEVEL 3 /* error conditions */
226#endif
227#ifndef LOG_WARN_LEVEL
228#define LOG_WARN_LEVEL 4 /* warning conditions */
229#endif
230#ifndef LOG_INFO_LEVEL
231#define LOG_INFO_LEVEL 6 /* informational */
232#endif
233#ifndef LOG_DEBUG_LEVEL
234#define LOG_DEBUG_LEVEL 7 /* debug-level messages */
235#endif
236#ifndef LOG_VERBOSE_LEVEL
237#define LOG_VERBOSE_LEVEL 8
238#endif
239
l.yang6a42e4d2025-05-28 01:04:20 -0700240#define GSW_VOICE "[HAL][GSW_VOICE]"
241
b.liu68a94c92025-05-24 12:53:41 +0800242#define LOGV(fmt, args ...) \
243 do{ \
244 char *file_ptr_1001 = __FILE__; \
245 char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
246 char line_1001[10] = {0}; \
247 sprintf(line_1001, "%d", __LINE__); \
248 while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
249 if(*ptr_1001 == '/') \
250 break; \
251 ptr_1001--; \
252 } \
l.yang6a42e4d2025-05-28 01:04:20 -0700253 mbtk_log(LOG_VERBOSE_LEVEL, "%s#%s: "GSW_VOICE"" fmt, ptr_1001 + 1, line_1001, ##args); \
b.liu68a94c92025-05-24 12:53:41 +0800254 } while(0)
255
256#define LOGI(fmt, args...) \
257 do{ \
258 char *file_ptr_1001 = __FILE__; \
259 char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
260 char line_1001[10] = {0}; \
261 sprintf(line_1001, "%d", __LINE__); \
262 while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
263 if(*ptr_1001 == '/') \
264 break; \
265 ptr_1001--; \
266 } \
l.yang6a42e4d2025-05-28 01:04:20 -0700267 mbtk_log(LOG_INFO_LEVEL, "%s#%s: "GSW_VOICE"" fmt, ptr_1001 + 1, line_1001, ##args); \
b.liu68a94c92025-05-24 12:53:41 +0800268 } while(0)
269
270#define LOGD(fmt, args...) \
271 do{ \
272 char *file_ptr_1001 = __FILE__; \
273 char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
274 char line_1001[10] = {0}; \
275 sprintf(line_1001, "%d", __LINE__); \
276 while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
277 if(*ptr_1001 == '/') \
278 break; \
279 ptr_1001--; \
280 } \
l.yang6a42e4d2025-05-28 01:04:20 -0700281 mbtk_log(LOG_DEBUG_LEVEL, "%s#%s: "GSW_VOICE"" fmt, ptr_1001 + 1, line_1001, ##args); \
b.liu68a94c92025-05-24 12:53:41 +0800282 } while(0)
283
284#define LOGW(fmt, args...) \
285 do{ \
286 char *file_ptr_1001 = __FILE__; \
287 char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
288 char line_1001[10] = {0}; \
289 sprintf(line_1001, "%d", __LINE__); \
290 while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
291 if(*ptr_1001 == '/') \
292 break; \
293 ptr_1001--; \
294 } \
l.yang6a42e4d2025-05-28 01:04:20 -0700295 mbtk_log(LOG_WARN_LEVEL, "%s#%s: "GSW_VOICE"" fmt, ptr_1001 + 1, line_1001, ##args); \
b.liu68a94c92025-05-24 12:53:41 +0800296 } while(0)
297
298#define LOGE(fmt, args...) \
299 do{ \
300 char *file_ptr_1001 = __FILE__; \
301 char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
302 char line_1001[10] = {0}; \
303 sprintf(line_1001, "%d", __LINE__); \
304 while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
305 if(*ptr_1001 == '/') \
306 break; \
307 ptr_1001--; \
308 } \
l.yang6a42e4d2025-05-28 01:04:20 -0700309 mbtk_log(LOG_ERR_LEVEL, "%s#%s: "GSW_VOICE"" fmt, ptr_1001 + 1, line_1001, ##args); \
b.liu68a94c92025-05-24 12:53:41 +0800310 } while(0)
311
q.huang50a0d852025-06-11 14:35:15 +0800312#define MODULE_INIT_CHECK(init_flag) \
313 if(init_flag == 0) \
314 { \
315 return GSW_HAL_ERROR_GNSS_DATA_CALL_DEINIT; \
316 }
317
318#define VOICE_MODULE_INIT_CHECK() MODULE_INIT_CHECK(gsw_voice_init_flag)
319
320
b.liu68a94c92025-05-24 12:53:41 +0800321static int mbtk_rtp_api_import()
322{
323 mbtk_rtp_init = (int (*)(void))dlsym(dlHandle_mbtk, "mbtk_rtp_init");
324 if (mbtk_rtp_init == NULL)
325 {
326 LOGE("mbtk_rtp_init dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800327 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800328 }
329
330 mbtk_rtp_deinit = (int (*)(void))dlsym(dlHandle_mbtk, "mbtk_rtp_deinit");
331 if (mbtk_rtp_deinit == NULL)
332 {
333 LOGE("mbtk_rtp_deinit dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800334 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800335 }
336
337 mbtk_rtp_enable = (int (*)(bool enable))dlsym(dlHandle_mbtk, "mbtk_rtp_enable");
338 if (mbtk_rtp_enable == NULL)
339 {
340 LOGE("mbtk_rtp_enable dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800341 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800342 }
343
344 mbtk_rtp_remote_ip_set = (int (*)(const char *ipv4))dlsym(dlHandle_mbtk, "mbtk_rtp_remote_ip_set");
345 if (mbtk_rtp_remote_ip_set == NULL)
346 {
347 LOGE("mbtk_rtp_remote_ip_set dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800348 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800349 }
350
351 mbtk_rtp_server_port_set = (int (*)(int port))dlsym(dlHandle_mbtk, "mbtk_rtp_server_port_set");
352 if (mbtk_rtp_server_port_set == NULL)
353 {
354 LOGE("mbtk_rtp_server_port_set dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800355 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800356 }
357
358 mbtk_rtp_client_port_set = (int (*)(int port))dlsym(dlHandle_mbtk, "mbtk_rtp_client_port_set");
359 if (mbtk_rtp_client_port_set == NULL)
360 {
361 LOGE("mbtk_rtp_client_port_set dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800362 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800363 }
364
365 mbtk_rtp_sample_rate_set = (int (*)(int sample_rate))dlsym(dlHandle_mbtk, "mbtk_rtp_sample_rate_set");
366 if (mbtk_rtp_sample_rate_set == NULL)
367 {
368 LOGE("mbtk_rtp_sample_rate_set dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800369 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800370 }
371
372 mbtk_rtp_channel_set = (int (*)(int channel))dlsym(dlHandle_mbtk, "mbtk_rtp_channel_set");
373 if (mbtk_rtp_channel_set == NULL)
374 {
375 LOGE("mbtk_rtp_channel_set dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800376 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800377 }
q.huang020cc232025-06-06 19:06:18 +0800378
379 mbtk_rtp_vlan_set = (int (*)(const char *vlan))dlsym(dlHandle_mbtk, "mbtk_rtp_vlan_set");
380 if (mbtk_rtp_vlan_set == NULL)
381 {
382 LOGE("mbtk_rtp_vlan_set dlsym fail\n");
383 return GSW_HAL_NORMAL_FAIL;
384 }
b.liu68a94c92025-05-24 12:53:41 +0800385
386 return GSW_HAL_SUCCESS;
387}
388
389
390
391static int mbtk_call_api_import()
392{
393 dlHandle_mbtk = dlopen(lib_mbtk_path, RTLD_NOW);
394 if (dlHandle_mbtk == NULL)
395 {
xy.hecfb7d682025-05-28 21:39:12 +0800396 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800397 }
398
399 mbtk_log_init = (void (*)(char *path, char *tag))dlsym(dlHandle_mbtk, "mbtk_log_init");
400 if (mbtk_log_init == NULL)
401 {
xy.hecfb7d682025-05-28 21:39:12 +0800402 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800403 }
404
405 mbtk_log = (void (*)(int level, const char *format, ...))dlsym(dlHandle_mbtk, "mbtk_log");
406 if (mbtk_log == NULL)
407 {
xy.hecfb7d682025-05-28 21:39:12 +0800408 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800409 }
410
411 mbtk_info_handle_get = (mbtk_info_handle_t* (*)(void))dlsym(dlHandle_mbtk, "mbtk_info_handle_get");
412 if (mbtk_info_handle_get == NULL)
413 {
414 LOGE("mbtk_info_handle_get dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800415 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800416 }
417
418 mbtk_call_state_change_cb_reg = (int (*)(mbtk_info_handle_t* handle, mbtk_info_callback_func cb))dlsym(dlHandle_mbtk, "mbtk_call_state_change_cb_reg");
419 if(mbtk_call_state_change_cb_reg == NULL)
420 {
421 LOGE("mbtk_call_state_change_cb_reg dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800422 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800423 }
424
425 mbtk_call_start = (int (*)(mbtk_info_handle_t* handle, char* phone_number))dlsym(dlHandle_mbtk, "mbtk_call_start");
426 if(mbtk_call_start == NULL)
427 {
428 LOGE("mbtk_call_start dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800429 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800430 }
431
432 mbtk_call_answer = (int (*)(mbtk_info_handle_t* handle))dlsym(dlHandle_mbtk, "mbtk_call_answer");
433 if(mbtk_call_answer == NULL)
434 {
435 LOGE("mbtk_call_answer dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800436 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800437 }
438
439 mbtk_call_hang = (int (*)(mbtk_info_handle_t* handle))dlsym(dlHandle_mbtk, "mbtk_call_hang");
440 if(mbtk_call_hang == NULL)
441 {
442 LOGE("mbtk_call_hang dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800443 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800444 }
445
446 mbtk_a_call_hang = (int (*)(mbtk_info_handle_t* handle, int phone_id))dlsym(dlHandle_mbtk, "mbtk_a_call_hang");
447 if(mbtk_a_call_hang == NULL)
448 {
449 LOGE("mbtk_a_call_hang dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800450 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800451 }
452
453 mbtk_call_reg_get = (int (*)(mbtk_info_handle_t* handle, mbtk_call_info_t *reg))dlsym(dlHandle_mbtk, "mbtk_call_reg_get");
454 if(mbtk_call_reg_get == NULL)
455 {
456 LOGE("mbtk_call_reg_get dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800457 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800458 }
459
460 return mbtk_rtp_api_import();
461}
462
463static int end_reason_mbtk_to_gsw(char* mbtk_reason)
464{
465 LOGE("mbtk_reason:%s\n", mbtk_reason);
466 gsw_global_end_reason = GSW_OTHER_END_NORMAL;
467 for(int i = 0; 0 != strncmp(g_end_reason[i].mbtk_end_reason, MBTK_VOICE_END_REASON_END, strlen(MBTK_VOICE_END_REASON_END)); i++)
468 {
469 if(0 == strncmp(mbtk_reason, g_end_reason[i].mbtk_end_reason, strlen(g_end_reason[i].mbtk_end_reason)))
470 {
471 gsw_global_end_reason = g_end_reason[i].end_reason;
472 LOGE("gsw_global_end_reason:%d\n", gsw_global_end_reason);
473 break;
474 }
475 }
476
477 return 0;
478}
479
480void gsw_call_state_change_cb(const void *data, int data_len)
481{
482 mbtk_call_info_t *reg = (mbtk_call_info_t *)data;
483 switch (reg->call_wait)
484 {
485 case MBTK_CLCC:
486 {
487 LOGD("RING : %d, %d, %d, %d, %d, %s, %d, %d, end_reason:%s", reg->dir1, reg->dir, reg->state, reg->mode, reg->mpty, reg->phone_number, reg->type, reg->disconnected_id, reg->end_reason);
488 switch(reg->state)
489 {
490 case 0:
491 state_t = GSW_VOICE_CALL_CONNECTED;
492 break;
493 case 1:
494 state_t = GSW_VOICE_CALL_HOLDING;
495 break;
496 case 2:
497 state_t = GSW_VOICE_CALL_DIALING;
498 break;
499 case 3:
500 state_t = GSW_VOICE_CALL_ALERTING;
501 break;
502 case 4:
503 state_t = GSW_VOICE_CALL_INCOMING;
504 break;
505 case 5:
506 state_t = GSW_VOICE_CALL_WAITING;
507 break;
508 case 6:
509 {
510 state_t = GSW_VOICE_CALL_END;
511 call_id_t = reg->dir1;
512 end_reason_mbtk_to_gsw((char *)reg->end_reason);
513 break;
514 }
515
516 }
517
518 if(gsw_voice_callback)
519 {
520 gsw_voice_callback(reg->dir1, state_t);
521 }
522
523 }
524 break;
525 case MBTK_DISCONNECTED:
526 {
527 LOGD("RING : call dis connected!");
528 LOGD("RING : %d, %d, %d, %d, %d, %s, %d, %d, end_reason:%s", reg->dir1, reg->dir, reg->state, reg->mode, reg->mpty, reg->phone_number, reg->type, reg->disconnected_id, reg->end_reason);
529 state_t = GSW_VOICE_CALL_END;
530 call_id_t = reg->dir1;
531 end_reason_mbtk_to_gsw((char *)reg->end_reason);
532 if(gsw_voice_callback)
533 {
534 gsw_voice_callback(reg->disconnected_id, state_t);
535 }
536 }
537 break;
538 case MBTK_CPAS:
539 LOGD("CALL : Call state = %d", reg->pas);
540 switch (reg->pas)
541 {
542 case MBTK_CALL_RADY:
543 LOGD("CALL: call READY");
544 break;
545 case MBTK_CALL_UNAVAILABLE:
546 LOGD("CALL: call unavaliable");
547 break;
548 case MBTK_CALL_UNKNOWN:
549 LOGD("CALL: call unknown");
550 break;
551 case MBTK_CALL_RINGING:
552 LOGD("CALL: call ringing");
553 break;
554 case MBTK_CALL_PROGRESS:
555 LOGD("CALL: call progress");
556 break;
557 case MBTK_CALL_ASLEEP:
558 LOGD("CALL: call asleep");
559 break;
560 case MBTK_CALL_ACTIVE:
561 LOGD("CALL: call active");
562 break;
563 default:
564 //LOGE("\r\n");
565 break;
566 }
567 break;
568 default:
569 LOGE("RING : None call_wait = %d", reg->call_wait);
570 break;
571 }
572}
573
574
575/**
576* @brief init voice sdk,and register the status indicated callback function
577* @param [in] CallStateInd ind: status indicated callback function
578* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800579* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800580*/
581int32_t gsw_voice_sdk_init(CallStateInd ind)
582{
583 int ret;
584
585 if (gsw_voice_init_flag == 1 && call_info_handle != NULL)
586 {
587 return GSW_HAL_SUCCESS;
588 }
589
590 if(ind == NULL)
591 {
592 LOGE("parameter is null\n");
xy.hecfb7d682025-05-28 21:39:12 +0800593 return GSW_HAL_ARG_INVALID;
b.liu68a94c92025-05-24 12:53:41 +0800594 }
595
596 ret = mbtk_call_api_import();
597 if(ret != 0)
598 {
599 if(mbtk_log != NULL)
600 {
601 LOGE("[gsw_voice_sdk_init]mbtk_call_api_import fail\n");
602 }
xy.hecfb7d682025-05-28 21:39:12 +0800603 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800604 }
605
606 mbtk_log_init("syslog", "MBTK_RIL");
607
608
609 if(ret < 0)
610 {
611 LOGE("mbtk_call_api_import fail,ret = %d\n",ret);
xy.hecfb7d682025-05-28 21:39:12 +0800612 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800613 }
614
615 ret=mbtk_rtp_init();
616
617 if(ret!=0)
618 {
619 LOGE("[gsw_voice_sdk_init]mbtk_rtp_init fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800620 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800621 }
622
623 if(call_info_handle == NULL)
624 {
625 call_info_handle = mbtk_info_handle_get();
626 if(call_info_handle != NULL)
627 {
628 LOGE("create gsw_voice_sdk_init success\n");
629
630 ret = mbtk_call_state_change_cb_reg(call_info_handle, gsw_call_state_change_cb);
631 if(ret)
632 {
633 LOGE("mbtk_call_state_change_cb_reg fail,ret = %d\n",ret);
634 (void) mbtk_rtp_deinit();
xy.hecfb7d682025-05-28 21:39:12 +0800635 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800636 }
637 else
638 {
639 gsw_voice_init_flag = 1;
640 gsw_voice_callback = ind;
641 LOGE("create gsw_voice_sdk_init success\n");
642 return GSW_HAL_SUCCESS;
643 }
644
645 }
646
647 else
648 {
649 (void) mbtk_rtp_deinit();
650 LOGE("create gsw_voice_sdk_init fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800651 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800652 }
653 }
654
655 return GSW_HAL_SUCCESS;
656}
657
658/**
659* @brief set speaker_volume
660* @param [in] int32_t volume:1(Min)-7(Max)
661* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800662* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800663*/
664int32_t gsw_voice_set_speaker_volume(int32_t volume)
665{
666 //UNUSED(volume);
667
q.huang50a0d852025-06-11 14:35:15 +0800668 VOICE_MODULE_INIT_CHECK();
b.liu68a94c92025-05-24 12:53:41 +0800669
670 char cmd[128] = {0};
671 int lv = 0;
672
673 memset(cmd ,0x00, sizeof(cmd));
674
675 if(volume < 1 || volume > 7)
676 {
677 LOGE("Error volume : %d", volume);
xy.hecfb7d682025-05-28 21:39:12 +0800678 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800679 }
680 else
681 {
682 switch(volume)
683 {
684 case 1 :
685 lv = -36;
686 break;
687 case 2 :
688 lv = -36;
689 break;
690 case 3 :
691 lv = -27;
692 break;
693 case 4 :
694 lv = -18;
695 break;
696 case 5 :
697 lv = -9;
698 break;
699 case 6 :
700 lv = 0;
701 break;
702 case 7:
703 lv = 12;
704 break;
705 default:
706 break;
707 }
708 }
709
710 sprintf(cmd, "ubus call audio_if config_dspgain \"{\'type\':%d,\'gain\':%d}\"", 1, lv);
711// sLOGE(cmd, "ubus call audio_if volume_set \'{\"param0\":%d}\'", lv);
712 int err = system(cmd);
713 if ((err != -1) && (err != 127))
714 {
715 LOGE("Set success.");
716 level_call = volume;
717 }
718 else
719 {
720 LOGE("Error : %d", err);
xy.hecfb7d682025-05-28 21:39:12 +0800721 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800722 }
723
724 return GSW_HAL_SUCCESS;
725}
726
727/**
728* @brief start a voice call
729* @param [in] char *callNumber
730* @param [out] CallHandle *handle
xy.hecfb7d682025-05-28 21:39:12 +0800731* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800732*/
733int32_t gsw_voice_normal_voice_start(CallHandle *handle, const char *callNumber)
734{
q.huang50a0d852025-06-11 14:35:15 +0800735 VOICE_MODULE_INIT_CHECK();
b.liu68a94c92025-05-24 12:53:41 +0800736
737 mbtk_call_info_t reg = {0};
738 int ret = -1;
739
740
741 if(handle == NULL)
742 {
743 LOGE("handle is null\n");
xy.hecfb7d682025-05-28 21:39:12 +0800744 return GSW_HAL_ARG_INVALID;
b.liu68a94c92025-05-24 12:53:41 +0800745 }
746
747 if(callNumber == NULL)
748 {
749 LOGE("callNumber is null\n");
xy.hecfb7d682025-05-28 21:39:12 +0800750 return GSW_HAL_ARG_INVALID;
b.liu68a94c92025-05-24 12:53:41 +0800751 }
752
753
754 ret = mbtk_call_start(call_info_handle, (char *)callNumber);
755
756 if(ret != 0)
757 {
758 LOGE("mbtk_call_start fail,ret = %d\n",ret);
xy.hecfb7d682025-05-28 21:39:12 +0800759 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800760 }
761
762 //get call id
763 mbtk_call_reg_get(call_info_handle, &reg);
764 LOGE("call id = %d\n",reg.dir1);
765 *handle = reg.dir1;
766 LOGE("gsw_voice_normal_voice_start id = %d\n", (int)*handle);
767
768
769 return GSW_HAL_SUCCESS;
770
771}
772
773/**
774* @brief answer a voice call
775* @param [in] CallHandle handle
776* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800777* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800778*/
779int32_t gsw_voice_answer(CallHandle handle)
780{
q.huang50a0d852025-06-11 14:35:15 +0800781 VOICE_MODULE_INIT_CHECK();
b.liu68a94c92025-05-24 12:53:41 +0800782
783 int ret = -1;
784
785
786 ret = mbtk_call_answer(call_info_handle);
787
788 if(ret != 0)
789 {
790 LOGE("mbtk_call_answer fail,ret = %d\n", ret);
xy.hecfb7d682025-05-28 21:39:12 +0800791 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800792 }
793 else
794 {
795 LOGE("mbtk_call_answer success\n");
796 }
797
798 return GSW_HAL_SUCCESS;
799}
800
801
802/**
803* @brief hangup a voice call
804* @param [in] CallHandle handle
805* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800806* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800807*/
808int32_t gsw_voice_hangup(CallHandle handle)
809{
q.huang50a0d852025-06-11 14:35:15 +0800810 VOICE_MODULE_INIT_CHECK();
b.liu68a94c92025-05-24 12:53:41 +0800811
812 int ret = -1;
813
814 ret = mbtk_a_call_hang(call_info_handle,handle);
815
816 if(ret != 0)
817 {
818 LOGE("mbtk_a_call_hang fail,ret = %d\n", ret);
xy.hecfb7d682025-05-28 21:39:12 +0800819 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800820 }
821 else
822 {
823 LOGE("mbtk_a_call_hang success\n");
824 }
825
826 return GSW_HAL_SUCCESS;
827}
828
829/**
830* @brief set auto answer mode
831* @param [in] int32_t mode:0-1, 0:NO(close auto answer), 1:YES(auto answer)
832* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800833* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800834*/
835int32_t gsw_voice_set_auto_answer_mode(int32_t mode)
836{
q.huang50a0d852025-06-11 14:35:15 +0800837 VOICE_MODULE_INIT_CHECK();
838
b.liu68a94c92025-05-24 12:53:41 +0800839 if(mode == 1)
840 {
841 int ret = -1;
842
843 ret = mbtk_call_answer(call_info_handle);
844 if(ret != 0)
845 {
846 LOGE("mbtk_call_answer fail,ret = %d\n", ret);
xy.hecfb7d682025-05-28 21:39:12 +0800847 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800848 }
849 else
850 {
851 LOGE("mbtk_call_answer success\n");
852 }
853 }
854
855 return GSW_HAL_SUCCESS;
856}
857
858int32_t gsw_voice_get_current_call_end_reason(CallHandle handle)
859{
q.huang50a0d852025-06-11 14:35:15 +0800860 VOICE_MODULE_INIT_CHECK();
861
b.liu68a94c92025-05-24 12:53:41 +0800862 int reason = gsw_global_end_reason;
863
864 return reason;
865}
866
867
868
869/*##########################################rtp begin*/
870/**
871* @brief set audio mode
872* @param [in] AudioMode audioMode
873* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800874* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800875*/
876int32_t gsw_voice_set_audio_mode(AudioMode audioMode)
877{
q.huang50a0d852025-06-11 14:35:15 +0800878 VOICE_MODULE_INIT_CHECK();
b.liu68a94c92025-05-24 12:53:41 +0800879
880 int ret=mbtk_rtp_enable(audioMode);
881 if(ret !=0 )
882 {
xy.hecfb7d682025-05-28 21:39:12 +0800883 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800884 }
885 return GSW_HAL_SUCCESS;
886}
887
888/**
889* @brief set rtp ip address of remote
890* @param [in] char *ip :ip address
891* @param [in] int32_t len: length
892* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800893* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800894*/
895int32_t gsw_voice_set_remote_rtp_ip(const char *ip, int32_t len)
896{
q.huang50a0d852025-06-11 14:35:15 +0800897 VOICE_MODULE_INIT_CHECK();
b.liu68a94c92025-05-24 12:53:41 +0800898
899 int ret=mbtk_rtp_remote_ip_set(ip);
900 if(ret !=0 )
901 {
xy.hecfb7d682025-05-28 21:39:12 +0800902 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800903 }
904 return GSW_HAL_SUCCESS;
905}
906
907/**
908* @brief set rtp mode and port
909* @param [in] RTPMode rtpMode: rtp mode
910* @param [in] int32_t port:rtp port
911* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800912* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800913*/
914int32_t gsw_voice_set_rtp_port(RTPMode rtpMode, int32_t port)
915{
q.huang50a0d852025-06-11 14:35:15 +0800916 VOICE_MODULE_INIT_CHECK();
b.liu68a94c92025-05-24 12:53:41 +0800917
918 int ret;
919 if(rtpMode==GSW_RTP_CLIENT)
920 {
921 ret = mbtk_rtp_client_port_set(port);
922 }
923 else
924 {
925 ret = mbtk_rtp_server_port_set(port);
926 }
927 if(ret !=0 )
928 {
xy.hecfb7d682025-05-28 21:39:12 +0800929 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800930 }
931 return GSW_HAL_SUCCESS;
932}
933
934/**
935* @brief set rtp mode and port
936* @param [in] int32_t clockRate: clock rate
937* @param [in] int32_t channel:channel
938* @param [in] int32_t latency:latency
939* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800940* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800941*/
942int32_t gsw_voice_set_rtp_param(int32_t clockRate, int32_t channel, int32_t latency)
943{
q.huang50a0d852025-06-11 14:35:15 +0800944 VOICE_MODULE_INIT_CHECK();
b.liu68a94c92025-05-24 12:53:41 +0800945
946 int ret=mbtk_rtp_channel_set(channel);
947 if(ret==0)
948 {
949 ret=mbtk_rtp_sample_rate_set(clockRate);
950 }
951 if(ret !=0 )
952 {
xy.hecfb7d682025-05-28 21:39:12 +0800953 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800954 }
955 return GSW_HAL_SUCCESS;
956}
q.huang020cc232025-06-06 19:06:18 +0800957
958/**
959 * @brief set rtp vlan
960 * @param [in] interfaceName network interface name
961 * @retval 0: success
962 * @retval other: fail
963 */
964int32_t gsw_voice_set_rtp_vlan_info(const char *interfaceName)
965{
q.huang50a0d852025-06-11 14:35:15 +0800966 VOICE_MODULE_INIT_CHECK();
q.huang020cc232025-06-06 19:06:18 +0800967
968 int ret=mbtk_rtp_vlan_set(interfaceName);
969
970 if(ret !=0 )
971 {
972 return GSW_HAL_NORMAL_FAIL;
973 }
974 return GSW_HAL_SUCCESS;
975}
b.liu68a94c92025-05-24 12:53:41 +0800976/*##########################################rtp end*/
977