blob: e1dae087ecbcdd8d49cd8fd1b26d07ab390fcb8c [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
q.huang5461cfd2025-06-24 19:04:34 +0800140const char* g_normal_end_reason[] = {
141MBTK_VOICE_END_REASON_NORMAL_CALL_CLEARING,
142MBTK_VOICE_END_REASON_NORMAL_UNSPECIFIED,
b.liu68a94c92025-05-24 12:53:41 +0800143};
hong.liud2417072025-06-27 07:10:37 -0700144
b.liu68a94c92025-05-24 12:53:41 +0800145int gsw_global_end_reason = GSW_OTHER_END_NORMAL;
146
147//----------------end_reason end------------
148
149
150typedef uint32_t voice_client_handle_type;
151
152
153
154static mbtk_info_handle_t* call_info_handle = NULL;
155static int level_call = 0;
156int gsw_voice_init_flag = 0;
157int auto_answer_flag = 0;
158voice_client_handle_type g_call_val = -1;
159CallStateInd gsw_voice_callback = NULL;
160
161
162int state_t = 0;
163char* phone_num_t = NULL;
164char* phone_num_t2 = NULL;
165int call_id_t = 0;
166int call_id_t2 = 0;
167
168#define lib_mbtk_path "/lib/libmbtk_lib.so"
169static void *dlHandle_mbtk;
170
171static mbtk_info_handle_t* (*mbtk_info_handle_get)(void);
172int (*mbtk_call_state_change_cb_reg)(mbtk_info_handle_t* handle, mbtk_info_callback_func cb);
173int (*mbtk_call_start)(mbtk_info_handle_t* handle, char* phone_number);
174int (*mbtk_call_hang)(mbtk_info_handle_t* handle);
175int (*mbtk_a_call_hang)(mbtk_info_handle_t* handle, int phone_id);
176int (*mbtk_call_answer)(mbtk_info_handle_t* handle);
177int (*mbtk_call_reg_get)(mbtk_info_handle_t* handle, mbtk_call_info_t *reg);
178static void (*mbtk_log)(int level, const char *format, ...);
179static void (*mbtk_log_init)(char *path, char *tag);
180
181/*rtp begin*/
182int (*mbtk_rtp_init)();
183int (*mbtk_rtp_deinit)();
184int (*mbtk_rtp_enable)(bool enable);
185int (*mbtk_rtp_remote_ip_set)(const char *ipv4);
186int (*mbtk_rtp_server_port_set)(int port);
187int (*mbtk_rtp_client_port_set)(int port);
188int (*mbtk_rtp_sample_rate_set)(int sample_rate);
189int (*mbtk_rtp_channel_set)(int channel);
q.huang020cc232025-06-06 19:06:18 +0800190int (*mbtk_rtp_vlan_set)(const char *vlan);
b.liu68a94c92025-05-24 12:53:41 +0800191/*rtp end*/
192
193
194#ifndef LOG_ERR_LEVEL
195#define LOG_ERR_LEVEL 3 /* error conditions */
196#endif
197#ifndef LOG_WARN_LEVEL
198#define LOG_WARN_LEVEL 4 /* warning conditions */
199#endif
200#ifndef LOG_INFO_LEVEL
201#define LOG_INFO_LEVEL 6 /* informational */
202#endif
203#ifndef LOG_DEBUG_LEVEL
204#define LOG_DEBUG_LEVEL 7 /* debug-level messages */
205#endif
206#ifndef LOG_VERBOSE_LEVEL
207#define LOG_VERBOSE_LEVEL 8
208#endif
209
l.yang6a42e4d2025-05-28 01:04:20 -0700210#define GSW_VOICE "[HAL][GSW_VOICE]"
211
b.liu68a94c92025-05-24 12:53:41 +0800212#define LOGV(fmt, args ...) \
213 do{ \
214 char *file_ptr_1001 = __FILE__; \
215 char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
216 char line_1001[10] = {0}; \
217 sprintf(line_1001, "%d", __LINE__); \
218 while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
219 if(*ptr_1001 == '/') \
220 break; \
221 ptr_1001--; \
222 } \
l.yang6a42e4d2025-05-28 01:04:20 -0700223 mbtk_log(LOG_VERBOSE_LEVEL, "%s#%s: "GSW_VOICE"" fmt, ptr_1001 + 1, line_1001, ##args); \
b.liu68a94c92025-05-24 12:53:41 +0800224 } while(0)
225
226#define LOGI(fmt, args...) \
227 do{ \
228 char *file_ptr_1001 = __FILE__; \
229 char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
230 char line_1001[10] = {0}; \
231 sprintf(line_1001, "%d", __LINE__); \
232 while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
233 if(*ptr_1001 == '/') \
234 break; \
235 ptr_1001--; \
236 } \
l.yang6a42e4d2025-05-28 01:04:20 -0700237 mbtk_log(LOG_INFO_LEVEL, "%s#%s: "GSW_VOICE"" fmt, ptr_1001 + 1, line_1001, ##args); \
b.liu68a94c92025-05-24 12:53:41 +0800238 } while(0)
239
240#define LOGD(fmt, args...) \
241 do{ \
242 char *file_ptr_1001 = __FILE__; \
243 char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
244 char line_1001[10] = {0}; \
245 sprintf(line_1001, "%d", __LINE__); \
246 while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
247 if(*ptr_1001 == '/') \
248 break; \
249 ptr_1001--; \
250 } \
l.yang6a42e4d2025-05-28 01:04:20 -0700251 mbtk_log(LOG_DEBUG_LEVEL, "%s#%s: "GSW_VOICE"" fmt, ptr_1001 + 1, line_1001, ##args); \
b.liu68a94c92025-05-24 12:53:41 +0800252 } while(0)
253
254#define LOGW(fmt, args...) \
255 do{ \
256 char *file_ptr_1001 = __FILE__; \
257 char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
258 char line_1001[10] = {0}; \
259 sprintf(line_1001, "%d", __LINE__); \
260 while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
261 if(*ptr_1001 == '/') \
262 break; \
263 ptr_1001--; \
264 } \
l.yang6a42e4d2025-05-28 01:04:20 -0700265 mbtk_log(LOG_WARN_LEVEL, "%s#%s: "GSW_VOICE"" fmt, ptr_1001 + 1, line_1001, ##args); \
b.liu68a94c92025-05-24 12:53:41 +0800266 } while(0)
267
268#define LOGE(fmt, args...) \
269 do{ \
q.huang5461cfd2025-06-24 19:04:34 +0800270 char *file_ptr_1001 = __FILE__; \
b.liu68a94c92025-05-24 12:53:41 +0800271 char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
272 char line_1001[10] = {0}; \
273 sprintf(line_1001, "%d", __LINE__); \
274 while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
275 if(*ptr_1001 == '/') \
276 break; \
277 ptr_1001--; \
278 } \
l.yang6a42e4d2025-05-28 01:04:20 -0700279 mbtk_log(LOG_ERR_LEVEL, "%s#%s: "GSW_VOICE"" fmt, ptr_1001 + 1, line_1001, ##args); \
b.liu68a94c92025-05-24 12:53:41 +0800280 } while(0)
281
q.huang50a0d852025-06-11 14:35:15 +0800282#define MODULE_INIT_CHECK(init_flag) \
283 if(init_flag == 0) \
284 { \
285 return GSW_HAL_ERROR_GNSS_DATA_CALL_DEINIT; \
286 }
287
288#define VOICE_MODULE_INIT_CHECK() MODULE_INIT_CHECK(gsw_voice_init_flag)
289
290
b.liu68a94c92025-05-24 12:53:41 +0800291static int mbtk_rtp_api_import()
292{
293 mbtk_rtp_init = (int (*)(void))dlsym(dlHandle_mbtk, "mbtk_rtp_init");
294 if (mbtk_rtp_init == NULL)
295 {
296 LOGE("mbtk_rtp_init dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800297 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800298 }
299
300 mbtk_rtp_deinit = (int (*)(void))dlsym(dlHandle_mbtk, "mbtk_rtp_deinit");
301 if (mbtk_rtp_deinit == NULL)
302 {
303 LOGE("mbtk_rtp_deinit dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800304 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800305 }
306
307 mbtk_rtp_enable = (int (*)(bool enable))dlsym(dlHandle_mbtk, "mbtk_rtp_enable");
308 if (mbtk_rtp_enable == NULL)
309 {
310 LOGE("mbtk_rtp_enable dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800311 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800312 }
313
314 mbtk_rtp_remote_ip_set = (int (*)(const char *ipv4))dlsym(dlHandle_mbtk, "mbtk_rtp_remote_ip_set");
315 if (mbtk_rtp_remote_ip_set == NULL)
316 {
317 LOGE("mbtk_rtp_remote_ip_set dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800318 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800319 }
320
321 mbtk_rtp_server_port_set = (int (*)(int port))dlsym(dlHandle_mbtk, "mbtk_rtp_server_port_set");
322 if (mbtk_rtp_server_port_set == NULL)
323 {
324 LOGE("mbtk_rtp_server_port_set dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800325 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800326 }
327
328 mbtk_rtp_client_port_set = (int (*)(int port))dlsym(dlHandle_mbtk, "mbtk_rtp_client_port_set");
329 if (mbtk_rtp_client_port_set == NULL)
330 {
331 LOGE("mbtk_rtp_client_port_set dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800332 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800333 }
334
335 mbtk_rtp_sample_rate_set = (int (*)(int sample_rate))dlsym(dlHandle_mbtk, "mbtk_rtp_sample_rate_set");
336 if (mbtk_rtp_sample_rate_set == NULL)
337 {
338 LOGE("mbtk_rtp_sample_rate_set dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800339 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800340 }
341
342 mbtk_rtp_channel_set = (int (*)(int channel))dlsym(dlHandle_mbtk, "mbtk_rtp_channel_set");
343 if (mbtk_rtp_channel_set == NULL)
344 {
345 LOGE("mbtk_rtp_channel_set dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800346 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800347 }
q.huang020cc232025-06-06 19:06:18 +0800348
349 mbtk_rtp_vlan_set = (int (*)(const char *vlan))dlsym(dlHandle_mbtk, "mbtk_rtp_vlan_set");
350 if (mbtk_rtp_vlan_set == NULL)
351 {
352 LOGE("mbtk_rtp_vlan_set dlsym fail\n");
353 return GSW_HAL_NORMAL_FAIL;
354 }
b.liu68a94c92025-05-24 12:53:41 +0800355
356 return GSW_HAL_SUCCESS;
357}
358
359
360
361static int mbtk_call_api_import()
362{
363 dlHandle_mbtk = dlopen(lib_mbtk_path, RTLD_NOW);
364 if (dlHandle_mbtk == NULL)
365 {
xy.hecfb7d682025-05-28 21:39:12 +0800366 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800367 }
368
369 mbtk_log_init = (void (*)(char *path, char *tag))dlsym(dlHandle_mbtk, "mbtk_log_init");
370 if (mbtk_log_init == NULL)
371 {
xy.hecfb7d682025-05-28 21:39:12 +0800372 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800373 }
374
375 mbtk_log = (void (*)(int level, const char *format, ...))dlsym(dlHandle_mbtk, "mbtk_log");
376 if (mbtk_log == NULL)
377 {
xy.hecfb7d682025-05-28 21:39:12 +0800378 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800379 }
380
381 mbtk_info_handle_get = (mbtk_info_handle_t* (*)(void))dlsym(dlHandle_mbtk, "mbtk_info_handle_get");
382 if (mbtk_info_handle_get == NULL)
383 {
384 LOGE("mbtk_info_handle_get dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800385 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800386 }
387
388 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");
389 if(mbtk_call_state_change_cb_reg == NULL)
390 {
391 LOGE("mbtk_call_state_change_cb_reg dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800392 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800393 }
394
395 mbtk_call_start = (int (*)(mbtk_info_handle_t* handle, char* phone_number))dlsym(dlHandle_mbtk, "mbtk_call_start");
396 if(mbtk_call_start == NULL)
397 {
398 LOGE("mbtk_call_start dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800399 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800400 }
401
402 mbtk_call_answer = (int (*)(mbtk_info_handle_t* handle))dlsym(dlHandle_mbtk, "mbtk_call_answer");
403 if(mbtk_call_answer == NULL)
404 {
405 LOGE("mbtk_call_answer dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800406 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800407 }
408
409 mbtk_call_hang = (int (*)(mbtk_info_handle_t* handle))dlsym(dlHandle_mbtk, "mbtk_call_hang");
410 if(mbtk_call_hang == NULL)
411 {
412 LOGE("mbtk_call_hang dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800413 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800414 }
415
416 mbtk_a_call_hang = (int (*)(mbtk_info_handle_t* handle, int phone_id))dlsym(dlHandle_mbtk, "mbtk_a_call_hang");
417 if(mbtk_a_call_hang == NULL)
418 {
419 LOGE("mbtk_a_call_hang dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800420 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800421 }
422
423 mbtk_call_reg_get = (int (*)(mbtk_info_handle_t* handle, mbtk_call_info_t *reg))dlsym(dlHandle_mbtk, "mbtk_call_reg_get");
424 if(mbtk_call_reg_get == NULL)
425 {
426 LOGE("mbtk_call_reg_get dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800427 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800428 }
429
430 return mbtk_rtp_api_import();
431}
432
q.huang5461cfd2025-06-24 19:04:34 +0800433static void end_reason_mbtk_to_gsw(char* mbtk_reason)
b.liu68a94c92025-05-24 12:53:41 +0800434{
435 LOGE("mbtk_reason:%s\n", mbtk_reason);
q.huang5461cfd2025-06-24 19:04:34 +0800436 gsw_global_end_reason = GSW_END_ABNORMAL;
437 int length=sizeof (g_normal_end_reason)/ sizeof(g_normal_end_reason[0]);
438 for(int i = 0; i<length; i++)
b.liu68a94c92025-05-24 12:53:41 +0800439 {
q.huang5461cfd2025-06-24 19:04:34 +0800440 if(0 == strncmp(mbtk_reason, g_normal_end_reason[i], strlen(g_normal_end_reason[i])))
b.liu68a94c92025-05-24 12:53:41 +0800441 {
q.huang5461cfd2025-06-24 19:04:34 +0800442 gsw_global_end_reason=GSW_OTHER_END_NORMAL;
443 return;
b.liu68a94c92025-05-24 12:53:41 +0800444 }
445 }
446
q.huang5461cfd2025-06-24 19:04:34 +0800447 return;
b.liu68a94c92025-05-24 12:53:41 +0800448}
449
450void gsw_call_state_change_cb(const void *data, int data_len)
451{
452 mbtk_call_info_t *reg = (mbtk_call_info_t *)data;
453 switch (reg->call_wait)
454 {
455 case MBTK_CLCC:
456 {
q.huang5461cfd2025-06-24 19:04:34 +0800457 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);
458 //printf("RING : %d, %d, %d, %d, %d, %s, %d, %d, end_reason:%s\n", reg->dir1, reg->dir, reg->state, reg->mode, reg->mpty, reg->phone_number, reg->type, reg->disconnected_id, reg->end_reason);
b.liu68a94c92025-05-24 12:53:41 +0800459 switch(reg->state)
460 {
461 case 0:
462 state_t = GSW_VOICE_CALL_CONNECTED;
463 break;
464 case 1:
465 state_t = GSW_VOICE_CALL_HOLDING;
466 break;
467 case 2:
468 state_t = GSW_VOICE_CALL_DIALING;
469 break;
470 case 3:
471 state_t = GSW_VOICE_CALL_ALERTING;
472 break;
473 case 4:
474 state_t = GSW_VOICE_CALL_INCOMING;
475 break;
476 case 5:
477 state_t = GSW_VOICE_CALL_WAITING;
478 break;
479 case 6:
480 {
481 state_t = GSW_VOICE_CALL_END;
482 call_id_t = reg->dir1;
483 end_reason_mbtk_to_gsw((char *)reg->end_reason);
484 break;
485 }
486
487 }
488
489 if(gsw_voice_callback)
490 {
491 gsw_voice_callback(reg->dir1, state_t);
492 }
493
494 }
q.huang5461cfd2025-06-24 19:04:34 +0800495 break;
b.liu68a94c92025-05-24 12:53:41 +0800496 case MBTK_DISCONNECTED:
497 {
q.huang5461cfd2025-06-24 19:04:34 +0800498 LOGD("RING : call dis connected!");
b.liu68a94c92025-05-24 12:53:41 +0800499 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);
q.huang5461cfd2025-06-24 19:04:34 +0800500 //printf("RING : %d, %d, %d, %d, %d, %s, %d, %d, end_reason:%s\n", reg->dir1, reg->dir, reg->state, reg->mode, reg->mpty, reg->phone_number, reg->type, reg->disconnected_id, reg->end_reason);
501 state_t = GSW_VOICE_CALL_END;
b.liu68a94c92025-05-24 12:53:41 +0800502 call_id_t = reg->dir1;
503 end_reason_mbtk_to_gsw((char *)reg->end_reason);
q.huang5461cfd2025-06-24 19:04:34 +0800504 if(gsw_voice_callback)
b.liu68a94c92025-05-24 12:53:41 +0800505 {
506 gsw_voice_callback(reg->disconnected_id, state_t);
507 }
508 }
q.huang5461cfd2025-06-24 19:04:34 +0800509 break;
b.liu68a94c92025-05-24 12:53:41 +0800510 case MBTK_CPAS:
511 LOGD("CALL : Call state = %d", reg->pas);
q.huang5461cfd2025-06-24 19:04:34 +0800512 switch (reg->pas)
513 {
b.liu68a94c92025-05-24 12:53:41 +0800514 case MBTK_CALL_RADY:
515 LOGD("CALL: call READY");
516 break;
517 case MBTK_CALL_UNAVAILABLE:
518 LOGD("CALL: call unavaliable");
519 break;
520 case MBTK_CALL_UNKNOWN:
521 LOGD("CALL: call unknown");
522 break;
523 case MBTK_CALL_RINGING:
524 LOGD("CALL: call ringing");
525 break;
526 case MBTK_CALL_PROGRESS:
527 LOGD("CALL: call progress");
528 break;
529 case MBTK_CALL_ASLEEP:
530 LOGD("CALL: call asleep");
531 break;
532 case MBTK_CALL_ACTIVE:
533 LOGD("CALL: call active");
534 break;
535 default:
536 //LOGE("\r\n");
537 break;
q.huang5461cfd2025-06-24 19:04:34 +0800538 }
b.liu68a94c92025-05-24 12:53:41 +0800539 break;
540 default:
541 LOGE("RING : None call_wait = %d", reg->call_wait);
542 break;
543 }
544}
545
546
547/**
548* @brief init voice sdk,and register the status indicated callback function
549* @param [in] CallStateInd ind: status indicated callback function
550* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800551* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800552*/
553int32_t gsw_voice_sdk_init(CallStateInd ind)
554{
555 int ret;
556
557 if (gsw_voice_init_flag == 1 && call_info_handle != NULL)
558 {
559 return GSW_HAL_SUCCESS;
560 }
561
562 if(ind == NULL)
563 {
564 LOGE("parameter is null\n");
xy.hecfb7d682025-05-28 21:39:12 +0800565 return GSW_HAL_ARG_INVALID;
b.liu68a94c92025-05-24 12:53:41 +0800566 }
567
568 ret = mbtk_call_api_import();
569 if(ret != 0)
570 {
571 if(mbtk_log != NULL)
572 {
573 LOGE("[gsw_voice_sdk_init]mbtk_call_api_import fail\n");
574 }
xy.hecfb7d682025-05-28 21:39:12 +0800575 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800576 }
577
578 mbtk_log_init("syslog", "MBTK_RIL");
579
580
581 if(ret < 0)
582 {
583 LOGE("mbtk_call_api_import fail,ret = %d\n",ret);
xy.hecfb7d682025-05-28 21:39:12 +0800584 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800585 }
586
587 ret=mbtk_rtp_init();
588
589 if(ret!=0)
590 {
591 LOGE("[gsw_voice_sdk_init]mbtk_rtp_init fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800592 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800593 }
594
595 if(call_info_handle == NULL)
596 {
597 call_info_handle = mbtk_info_handle_get();
598 if(call_info_handle != NULL)
599 {
600 LOGE("create gsw_voice_sdk_init success\n");
601
602 ret = mbtk_call_state_change_cb_reg(call_info_handle, gsw_call_state_change_cb);
603 if(ret)
604 {
605 LOGE("mbtk_call_state_change_cb_reg fail,ret = %d\n",ret);
606 (void) mbtk_rtp_deinit();
xy.hecfb7d682025-05-28 21:39:12 +0800607 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800608 }
609 else
610 {
611 gsw_voice_init_flag = 1;
612 gsw_voice_callback = ind;
613 LOGE("create gsw_voice_sdk_init success\n");
614 return GSW_HAL_SUCCESS;
615 }
616
617 }
618
619 else
620 {
621 (void) mbtk_rtp_deinit();
622 LOGE("create gsw_voice_sdk_init fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800623 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800624 }
625 }
626
627 return GSW_HAL_SUCCESS;
628}
629
630/**
631* @brief set speaker_volume
632* @param [in] int32_t volume:1(Min)-7(Max)
633* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800634* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800635*/
636int32_t gsw_voice_set_speaker_volume(int32_t volume)
637{
638 //UNUSED(volume);
639
q.huang50a0d852025-06-11 14:35:15 +0800640 VOICE_MODULE_INIT_CHECK();
b.liu68a94c92025-05-24 12:53:41 +0800641
642 char cmd[128] = {0};
643 int lv = 0;
644
645 memset(cmd ,0x00, sizeof(cmd));
646
647 if(volume < 1 || volume > 7)
648 {
649 LOGE("Error volume : %d", volume);
xy.hecfb7d682025-05-28 21:39:12 +0800650 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800651 }
652 else
653 {
654 switch(volume)
655 {
656 case 1 :
657 lv = -36;
658 break;
659 case 2 :
660 lv = -36;
661 break;
662 case 3 :
663 lv = -27;
664 break;
665 case 4 :
666 lv = -18;
667 break;
668 case 5 :
669 lv = -9;
670 break;
671 case 6 :
672 lv = 0;
673 break;
674 case 7:
675 lv = 12;
676 break;
677 default:
678 break;
679 }
680 }
681
682 sprintf(cmd, "ubus call audio_if config_dspgain \"{\'type\':%d,\'gain\':%d}\"", 1, lv);
683// sLOGE(cmd, "ubus call audio_if volume_set \'{\"param0\":%d}\'", lv);
684 int err = system(cmd);
685 if ((err != -1) && (err != 127))
686 {
687 LOGE("Set success.");
688 level_call = volume;
689 }
690 else
691 {
692 LOGE("Error : %d", err);
xy.hecfb7d682025-05-28 21:39:12 +0800693 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800694 }
695
696 return GSW_HAL_SUCCESS;
697}
698
699/**
700* @brief start a voice call
701* @param [in] char *callNumber
702* @param [out] CallHandle *handle
xy.hecfb7d682025-05-28 21:39:12 +0800703* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800704*/
705int32_t gsw_voice_normal_voice_start(CallHandle *handle, const char *callNumber)
706{
q.huang50a0d852025-06-11 14:35:15 +0800707 VOICE_MODULE_INIT_CHECK();
b.liu68a94c92025-05-24 12:53:41 +0800708
709 mbtk_call_info_t reg = {0};
710 int ret = -1;
711
712
713 if(handle == NULL)
714 {
715 LOGE("handle is null\n");
xy.hecfb7d682025-05-28 21:39:12 +0800716 return GSW_HAL_ARG_INVALID;
b.liu68a94c92025-05-24 12:53:41 +0800717 }
718
719 if(callNumber == NULL)
720 {
721 LOGE("callNumber is null\n");
xy.hecfb7d682025-05-28 21:39:12 +0800722 return GSW_HAL_ARG_INVALID;
b.liu68a94c92025-05-24 12:53:41 +0800723 }
724
725
726 ret = mbtk_call_start(call_info_handle, (char *)callNumber);
727
728 if(ret != 0)
729 {
730 LOGE("mbtk_call_start fail,ret = %d\n",ret);
xy.hecfb7d682025-05-28 21:39:12 +0800731 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800732 }
733
734 //get call id
735 mbtk_call_reg_get(call_info_handle, &reg);
736 LOGE("call id = %d\n",reg.dir1);
737 *handle = reg.dir1;
738 LOGE("gsw_voice_normal_voice_start id = %d\n", (int)*handle);
739
740
741 return GSW_HAL_SUCCESS;
742
743}
744
745/**
746* @brief answer a voice call
747* @param [in] CallHandle handle
748* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800749* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800750*/
751int32_t gsw_voice_answer(CallHandle handle)
752{
q.huang50a0d852025-06-11 14:35:15 +0800753 VOICE_MODULE_INIT_CHECK();
b.liu68a94c92025-05-24 12:53:41 +0800754
755 int ret = -1;
756
757
758 ret = mbtk_call_answer(call_info_handle);
759
760 if(ret != 0)
761 {
762 LOGE("mbtk_call_answer fail,ret = %d\n", ret);
xy.hecfb7d682025-05-28 21:39:12 +0800763 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800764 }
765 else
766 {
767 LOGE("mbtk_call_answer success\n");
768 }
769
770 return GSW_HAL_SUCCESS;
771}
772
773
774/**
775* @brief hangup a voice call
776* @param [in] CallHandle handle
777* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800778* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800779*/
780int32_t gsw_voice_hangup(CallHandle handle)
781{
q.huang50a0d852025-06-11 14:35:15 +0800782 VOICE_MODULE_INIT_CHECK();
b.liu68a94c92025-05-24 12:53:41 +0800783
784 int ret = -1;
785
786 ret = mbtk_a_call_hang(call_info_handle,handle);
787
788 if(ret != 0)
789 {
790 LOGE("mbtk_a_call_hang 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_a_call_hang success\n");
796 }
797
798 return GSW_HAL_SUCCESS;
799}
800
801/**
802* @brief set auto answer mode
803* @param [in] int32_t mode:0-1, 0:NO(close auto answer), 1:YES(auto answer)
804* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800805* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800806*/
807int32_t gsw_voice_set_auto_answer_mode(int32_t mode)
808{
q.huang50a0d852025-06-11 14:35:15 +0800809 VOICE_MODULE_INIT_CHECK();
810
b.liu68a94c92025-05-24 12:53:41 +0800811 if(mode == 1)
812 {
813 int ret = -1;
814
815 ret = mbtk_call_answer(call_info_handle);
816 if(ret != 0)
817 {
818 LOGE("mbtk_call_answer 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_call_answer success\n");
824 }
825 }
826
827 return GSW_HAL_SUCCESS;
828}
829
830int32_t gsw_voice_get_current_call_end_reason(CallHandle handle)
831{
q.huang50a0d852025-06-11 14:35:15 +0800832 VOICE_MODULE_INIT_CHECK();
q.huang5461cfd2025-06-24 19:04:34 +0800833
834 return gsw_global_end_reason;
b.liu68a94c92025-05-24 12:53:41 +0800835}
836
837
838
839/*##########################################rtp begin*/
840/**
841* @brief set audio mode
842* @param [in] AudioMode audioMode
843* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800844* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800845*/
846int32_t gsw_voice_set_audio_mode(AudioMode audioMode)
847{
q.huang50a0d852025-06-11 14:35:15 +0800848 VOICE_MODULE_INIT_CHECK();
b.liu68a94c92025-05-24 12:53:41 +0800849
850 int ret=mbtk_rtp_enable(audioMode);
851 if(ret !=0 )
852 {
xy.hecfb7d682025-05-28 21:39:12 +0800853 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800854 }
855 return GSW_HAL_SUCCESS;
856}
857
858/**
859* @brief set rtp ip address of remote
860* @param [in] char *ip :ip address
861* @param [in] int32_t len: length
862* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800863* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800864*/
865int32_t gsw_voice_set_remote_rtp_ip(const char *ip, int32_t len)
866{
q.huang50a0d852025-06-11 14:35:15 +0800867 VOICE_MODULE_INIT_CHECK();
b.liu68a94c92025-05-24 12:53:41 +0800868
869 int ret=mbtk_rtp_remote_ip_set(ip);
870 if(ret !=0 )
871 {
xy.hecfb7d682025-05-28 21:39:12 +0800872 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800873 }
874 return GSW_HAL_SUCCESS;
875}
876
877/**
878* @brief set rtp mode and port
879* @param [in] RTPMode rtpMode: rtp mode
880* @param [in] int32_t port:rtp port
881* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800882* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800883*/
884int32_t gsw_voice_set_rtp_port(RTPMode rtpMode, int32_t port)
885{
q.huang50a0d852025-06-11 14:35:15 +0800886 VOICE_MODULE_INIT_CHECK();
b.liu68a94c92025-05-24 12:53:41 +0800887
888 int ret;
889 if(rtpMode==GSW_RTP_CLIENT)
890 {
891 ret = mbtk_rtp_client_port_set(port);
892 }
893 else
894 {
895 ret = mbtk_rtp_server_port_set(port);
896 }
897 if(ret !=0 )
898 {
xy.hecfb7d682025-05-28 21:39:12 +0800899 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800900 }
901 return GSW_HAL_SUCCESS;
902}
903
904/**
905* @brief set rtp mode and port
906* @param [in] int32_t clockRate: clock rate
907* @param [in] int32_t channel:channel
908* @param [in] int32_t latency:latency
909* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800910* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800911*/
912int32_t gsw_voice_set_rtp_param(int32_t clockRate, int32_t channel, int32_t latency)
913{
q.huang50a0d852025-06-11 14:35:15 +0800914 VOICE_MODULE_INIT_CHECK();
b.liu68a94c92025-05-24 12:53:41 +0800915
916 int ret=mbtk_rtp_channel_set(channel);
917 if(ret==0)
918 {
919 ret=mbtk_rtp_sample_rate_set(clockRate);
920 }
921 if(ret !=0 )
922 {
xy.hecfb7d682025-05-28 21:39:12 +0800923 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800924 }
925 return GSW_HAL_SUCCESS;
926}
q.huang020cc232025-06-06 19:06:18 +0800927
928/**
929 * @brief set rtp vlan
930 * @param [in] interfaceName network interface name
931 * @retval 0: success
932 * @retval other: fail
933 */
934int32_t gsw_voice_set_rtp_vlan_info(const char *interfaceName)
935{
q.huang50a0d852025-06-11 14:35:15 +0800936 VOICE_MODULE_INIT_CHECK();
q.huang020cc232025-06-06 19:06:18 +0800937
938 int ret=mbtk_rtp_vlan_set(interfaceName);
939
940 if(ret !=0 )
941 {
942 return GSW_HAL_NORMAL_FAIL;
943 }
944 return GSW_HAL_SUCCESS;
945}
b.liu68a94c92025-05-24 12:53:41 +0800946/*##########################################rtp end*/
947