blob: c81e8df02afbd6b638a2f227cffc6e4dc1f1a863 [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};
b.liu68a94c92025-05-24 12:53:41 +0800144int gsw_global_end_reason = GSW_OTHER_END_NORMAL;
145
146//----------------end_reason end------------
147
148
149typedef uint32_t voice_client_handle_type;
150
151
152
153static mbtk_info_handle_t* call_info_handle = NULL;
154static int level_call = 0;
155int gsw_voice_init_flag = 0;
156int auto_answer_flag = 0;
157voice_client_handle_type g_call_val = -1;
158CallStateInd gsw_voice_callback = NULL;
159
160
161int state_t = 0;
162char* phone_num_t = NULL;
163char* phone_num_t2 = NULL;
164int call_id_t = 0;
165int call_id_t2 = 0;
166
167#define lib_mbtk_path "/lib/libmbtk_lib.so"
168static void *dlHandle_mbtk;
169
170static mbtk_info_handle_t* (*mbtk_info_handle_get)(void);
171int (*mbtk_call_state_change_cb_reg)(mbtk_info_handle_t* handle, mbtk_info_callback_func cb);
172int (*mbtk_call_start)(mbtk_info_handle_t* handle, char* phone_number);
173int (*mbtk_call_hang)(mbtk_info_handle_t* handle);
174int (*mbtk_a_call_hang)(mbtk_info_handle_t* handle, int phone_id);
175int (*mbtk_call_answer)(mbtk_info_handle_t* handle);
176int (*mbtk_call_reg_get)(mbtk_info_handle_t* handle, mbtk_call_info_t *reg);
177static void (*mbtk_log)(int level, const char *format, ...);
178static void (*mbtk_log_init)(char *path, char *tag);
179
180/*rtp begin*/
181int (*mbtk_rtp_init)();
182int (*mbtk_rtp_deinit)();
183int (*mbtk_rtp_enable)(bool enable);
184int (*mbtk_rtp_remote_ip_set)(const char *ipv4);
185int (*mbtk_rtp_server_port_set)(int port);
186int (*mbtk_rtp_client_port_set)(int port);
187int (*mbtk_rtp_sample_rate_set)(int sample_rate);
188int (*mbtk_rtp_channel_set)(int channel);
q.huang020cc232025-06-06 19:06:18 +0800189int (*mbtk_rtp_vlan_set)(const char *vlan);
b.liu68a94c92025-05-24 12:53:41 +0800190/*rtp end*/
191
192
193#ifndef LOG_ERR_LEVEL
194#define LOG_ERR_LEVEL 3 /* error conditions */
195#endif
196#ifndef LOG_WARN_LEVEL
197#define LOG_WARN_LEVEL 4 /* warning conditions */
198#endif
199#ifndef LOG_INFO_LEVEL
200#define LOG_INFO_LEVEL 6 /* informational */
201#endif
202#ifndef LOG_DEBUG_LEVEL
203#define LOG_DEBUG_LEVEL 7 /* debug-level messages */
204#endif
205#ifndef LOG_VERBOSE_LEVEL
206#define LOG_VERBOSE_LEVEL 8
207#endif
208
l.yang6a42e4d2025-05-28 01:04:20 -0700209#define GSW_VOICE "[HAL][GSW_VOICE]"
210
b.liu68a94c92025-05-24 12:53:41 +0800211#define LOGV(fmt, args ...) \
212 do{ \
213 char *file_ptr_1001 = __FILE__; \
214 char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
215 char line_1001[10] = {0}; \
216 sprintf(line_1001, "%d", __LINE__); \
217 while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
218 if(*ptr_1001 == '/') \
219 break; \
220 ptr_1001--; \
221 } \
l.yang6a42e4d2025-05-28 01:04:20 -0700222 mbtk_log(LOG_VERBOSE_LEVEL, "%s#%s: "GSW_VOICE"" fmt, ptr_1001 + 1, line_1001, ##args); \
b.liu68a94c92025-05-24 12:53:41 +0800223 } while(0)
224
225#define LOGI(fmt, args...) \
226 do{ \
227 char *file_ptr_1001 = __FILE__; \
228 char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
229 char line_1001[10] = {0}; \
230 sprintf(line_1001, "%d", __LINE__); \
231 while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
232 if(*ptr_1001 == '/') \
233 break; \
234 ptr_1001--; \
235 } \
l.yang6a42e4d2025-05-28 01:04:20 -0700236 mbtk_log(LOG_INFO_LEVEL, "%s#%s: "GSW_VOICE"" fmt, ptr_1001 + 1, line_1001, ##args); \
b.liu68a94c92025-05-24 12:53:41 +0800237 } while(0)
238
239#define LOGD(fmt, args...) \
240 do{ \
241 char *file_ptr_1001 = __FILE__; \
242 char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
243 char line_1001[10] = {0}; \
244 sprintf(line_1001, "%d", __LINE__); \
245 while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
246 if(*ptr_1001 == '/') \
247 break; \
248 ptr_1001--; \
249 } \
l.yang6a42e4d2025-05-28 01:04:20 -0700250 mbtk_log(LOG_DEBUG_LEVEL, "%s#%s: "GSW_VOICE"" fmt, ptr_1001 + 1, line_1001, ##args); \
b.liu68a94c92025-05-24 12:53:41 +0800251 } while(0)
252
253#define LOGW(fmt, args...) \
254 do{ \
255 char *file_ptr_1001 = __FILE__; \
256 char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
257 char line_1001[10] = {0}; \
258 sprintf(line_1001, "%d", __LINE__); \
259 while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
260 if(*ptr_1001 == '/') \
261 break; \
262 ptr_1001--; \
263 } \
l.yang6a42e4d2025-05-28 01:04:20 -0700264 mbtk_log(LOG_WARN_LEVEL, "%s#%s: "GSW_VOICE"" fmt, ptr_1001 + 1, line_1001, ##args); \
b.liu68a94c92025-05-24 12:53:41 +0800265 } while(0)
266
267#define LOGE(fmt, args...) \
268 do{ \
q.huang5461cfd2025-06-24 19:04:34 +0800269 char *file_ptr_1001 = __FILE__; \
b.liu68a94c92025-05-24 12:53:41 +0800270 char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
271 char line_1001[10] = {0}; \
272 sprintf(line_1001, "%d", __LINE__); \
273 while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
274 if(*ptr_1001 == '/') \
275 break; \
276 ptr_1001--; \
277 } \
l.yang6a42e4d2025-05-28 01:04:20 -0700278 mbtk_log(LOG_ERR_LEVEL, "%s#%s: "GSW_VOICE"" fmt, ptr_1001 + 1, line_1001, ##args); \
b.liu68a94c92025-05-24 12:53:41 +0800279 } while(0)
280
q.huang50a0d852025-06-11 14:35:15 +0800281#define MODULE_INIT_CHECK(init_flag) \
282 if(init_flag == 0) \
283 { \
284 return GSW_HAL_ERROR_GNSS_DATA_CALL_DEINIT; \
285 }
286
287#define VOICE_MODULE_INIT_CHECK() MODULE_INIT_CHECK(gsw_voice_init_flag)
288
289
b.liu68a94c92025-05-24 12:53:41 +0800290static int mbtk_rtp_api_import()
291{
292 mbtk_rtp_init = (int (*)(void))dlsym(dlHandle_mbtk, "mbtk_rtp_init");
293 if (mbtk_rtp_init == NULL)
294 {
295 LOGE("mbtk_rtp_init dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800296 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800297 }
298
299 mbtk_rtp_deinit = (int (*)(void))dlsym(dlHandle_mbtk, "mbtk_rtp_deinit");
300 if (mbtk_rtp_deinit == NULL)
301 {
302 LOGE("mbtk_rtp_deinit dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800303 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800304 }
305
306 mbtk_rtp_enable = (int (*)(bool enable))dlsym(dlHandle_mbtk, "mbtk_rtp_enable");
307 if (mbtk_rtp_enable == NULL)
308 {
309 LOGE("mbtk_rtp_enable dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800310 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800311 }
312
313 mbtk_rtp_remote_ip_set = (int (*)(const char *ipv4))dlsym(dlHandle_mbtk, "mbtk_rtp_remote_ip_set");
314 if (mbtk_rtp_remote_ip_set == NULL)
315 {
316 LOGE("mbtk_rtp_remote_ip_set dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800317 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800318 }
319
320 mbtk_rtp_server_port_set = (int (*)(int port))dlsym(dlHandle_mbtk, "mbtk_rtp_server_port_set");
321 if (mbtk_rtp_server_port_set == NULL)
322 {
323 LOGE("mbtk_rtp_server_port_set dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800324 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800325 }
326
327 mbtk_rtp_client_port_set = (int (*)(int port))dlsym(dlHandle_mbtk, "mbtk_rtp_client_port_set");
328 if (mbtk_rtp_client_port_set == NULL)
329 {
330 LOGE("mbtk_rtp_client_port_set dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800331 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800332 }
333
334 mbtk_rtp_sample_rate_set = (int (*)(int sample_rate))dlsym(dlHandle_mbtk, "mbtk_rtp_sample_rate_set");
335 if (mbtk_rtp_sample_rate_set == NULL)
336 {
337 LOGE("mbtk_rtp_sample_rate_set dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800338 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800339 }
340
341 mbtk_rtp_channel_set = (int (*)(int channel))dlsym(dlHandle_mbtk, "mbtk_rtp_channel_set");
342 if (mbtk_rtp_channel_set == NULL)
343 {
344 LOGE("mbtk_rtp_channel_set dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800345 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800346 }
q.huang020cc232025-06-06 19:06:18 +0800347
348 mbtk_rtp_vlan_set = (int (*)(const char *vlan))dlsym(dlHandle_mbtk, "mbtk_rtp_vlan_set");
349 if (mbtk_rtp_vlan_set == NULL)
350 {
351 LOGE("mbtk_rtp_vlan_set dlsym fail\n");
352 return GSW_HAL_NORMAL_FAIL;
353 }
b.liu68a94c92025-05-24 12:53:41 +0800354
355 return GSW_HAL_SUCCESS;
356}
357
358
359
360static int mbtk_call_api_import()
361{
362 dlHandle_mbtk = dlopen(lib_mbtk_path, RTLD_NOW);
363 if (dlHandle_mbtk == NULL)
364 {
xy.hecfb7d682025-05-28 21:39:12 +0800365 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800366 }
367
368 mbtk_log_init = (void (*)(char *path, char *tag))dlsym(dlHandle_mbtk, "mbtk_log_init");
369 if (mbtk_log_init == NULL)
370 {
xy.hecfb7d682025-05-28 21:39:12 +0800371 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800372 }
373
374 mbtk_log = (void (*)(int level, const char *format, ...))dlsym(dlHandle_mbtk, "mbtk_log");
375 if (mbtk_log == NULL)
376 {
xy.hecfb7d682025-05-28 21:39:12 +0800377 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800378 }
379
380 mbtk_info_handle_get = (mbtk_info_handle_t* (*)(void))dlsym(dlHandle_mbtk, "mbtk_info_handle_get");
381 if (mbtk_info_handle_get == NULL)
382 {
383 LOGE("mbtk_info_handle_get dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800384 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800385 }
386
387 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");
388 if(mbtk_call_state_change_cb_reg == NULL)
389 {
390 LOGE("mbtk_call_state_change_cb_reg dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800391 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800392 }
393
394 mbtk_call_start = (int (*)(mbtk_info_handle_t* handle, char* phone_number))dlsym(dlHandle_mbtk, "mbtk_call_start");
395 if(mbtk_call_start == NULL)
396 {
397 LOGE("mbtk_call_start dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800398 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800399 }
400
401 mbtk_call_answer = (int (*)(mbtk_info_handle_t* handle))dlsym(dlHandle_mbtk, "mbtk_call_answer");
402 if(mbtk_call_answer == NULL)
403 {
404 LOGE("mbtk_call_answer dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800405 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800406 }
407
408 mbtk_call_hang = (int (*)(mbtk_info_handle_t* handle))dlsym(dlHandle_mbtk, "mbtk_call_hang");
409 if(mbtk_call_hang == NULL)
410 {
411 LOGE("mbtk_call_hang dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800412 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800413 }
414
415 mbtk_a_call_hang = (int (*)(mbtk_info_handle_t* handle, int phone_id))dlsym(dlHandle_mbtk, "mbtk_a_call_hang");
416 if(mbtk_a_call_hang == NULL)
417 {
418 LOGE("mbtk_a_call_hang dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800419 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800420 }
421
422 mbtk_call_reg_get = (int (*)(mbtk_info_handle_t* handle, mbtk_call_info_t *reg))dlsym(dlHandle_mbtk, "mbtk_call_reg_get");
423 if(mbtk_call_reg_get == NULL)
424 {
425 LOGE("mbtk_call_reg_get dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800426 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800427 }
428
429 return mbtk_rtp_api_import();
430}
431
q.huang5461cfd2025-06-24 19:04:34 +0800432static void end_reason_mbtk_to_gsw(char* mbtk_reason)
b.liu68a94c92025-05-24 12:53:41 +0800433{
434 LOGE("mbtk_reason:%s\n", mbtk_reason);
q.huang5461cfd2025-06-24 19:04:34 +0800435 gsw_global_end_reason = GSW_END_ABNORMAL;
436 int length=sizeof (g_normal_end_reason)/ sizeof(g_normal_end_reason[0]);
437 for(int i = 0; i<length; i++)
b.liu68a94c92025-05-24 12:53:41 +0800438 {
q.huang5461cfd2025-06-24 19:04:34 +0800439 if(0 == strncmp(mbtk_reason, g_normal_end_reason[i], strlen(g_normal_end_reason[i])))
b.liu68a94c92025-05-24 12:53:41 +0800440 {
q.huang5461cfd2025-06-24 19:04:34 +0800441 gsw_global_end_reason=GSW_OTHER_END_NORMAL;
442 return;
b.liu68a94c92025-05-24 12:53:41 +0800443 }
444 }
445
q.huang5461cfd2025-06-24 19:04:34 +0800446 return;
b.liu68a94c92025-05-24 12:53:41 +0800447}
448
449void gsw_call_state_change_cb(const void *data, int data_len)
450{
451 mbtk_call_info_t *reg = (mbtk_call_info_t *)data;
452 switch (reg->call_wait)
453 {
454 case MBTK_CLCC:
455 {
q.huang5461cfd2025-06-24 19:04:34 +0800456 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);
457 //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 +0800458 switch(reg->state)
459 {
460 case 0:
461 state_t = GSW_VOICE_CALL_CONNECTED;
462 break;
463 case 1:
464 state_t = GSW_VOICE_CALL_HOLDING;
465 break;
466 case 2:
467 state_t = GSW_VOICE_CALL_DIALING;
468 break;
469 case 3:
470 state_t = GSW_VOICE_CALL_ALERTING;
471 break;
472 case 4:
473 state_t = GSW_VOICE_CALL_INCOMING;
474 break;
475 case 5:
476 state_t = GSW_VOICE_CALL_WAITING;
477 break;
478 case 6:
479 {
480 state_t = GSW_VOICE_CALL_END;
481 call_id_t = reg->dir1;
482 end_reason_mbtk_to_gsw((char *)reg->end_reason);
483 break;
484 }
485
486 }
487
488 if(gsw_voice_callback)
489 {
490 gsw_voice_callback(reg->dir1, state_t);
491 }
492
493 }
q.huang5461cfd2025-06-24 19:04:34 +0800494 break;
b.liu68a94c92025-05-24 12:53:41 +0800495 case MBTK_DISCONNECTED:
496 {
q.huang5461cfd2025-06-24 19:04:34 +0800497 LOGD("RING : call dis connected!");
b.liu68a94c92025-05-24 12:53:41 +0800498 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 +0800499 //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);
500 state_t = GSW_VOICE_CALL_END;
b.liu68a94c92025-05-24 12:53:41 +0800501 call_id_t = reg->dir1;
502 end_reason_mbtk_to_gsw((char *)reg->end_reason);
q.huang5461cfd2025-06-24 19:04:34 +0800503 if(gsw_voice_callback)
b.liu68a94c92025-05-24 12:53:41 +0800504 {
505 gsw_voice_callback(reg->disconnected_id, state_t);
506 }
507 }
q.huang5461cfd2025-06-24 19:04:34 +0800508 break;
b.liu68a94c92025-05-24 12:53:41 +0800509 case MBTK_CPAS:
510 LOGD("CALL : Call state = %d", reg->pas);
q.huang5461cfd2025-06-24 19:04:34 +0800511 switch (reg->pas)
512 {
b.liu68a94c92025-05-24 12:53:41 +0800513 case MBTK_CALL_RADY:
514 LOGD("CALL: call READY");
515 break;
516 case MBTK_CALL_UNAVAILABLE:
517 LOGD("CALL: call unavaliable");
518 break;
519 case MBTK_CALL_UNKNOWN:
520 LOGD("CALL: call unknown");
521 break;
522 case MBTK_CALL_RINGING:
523 LOGD("CALL: call ringing");
524 break;
525 case MBTK_CALL_PROGRESS:
526 LOGD("CALL: call progress");
527 break;
528 case MBTK_CALL_ASLEEP:
529 LOGD("CALL: call asleep");
530 break;
531 case MBTK_CALL_ACTIVE:
532 LOGD("CALL: call active");
533 break;
534 default:
535 //LOGE("\r\n");
536 break;
q.huang5461cfd2025-06-24 19:04:34 +0800537 }
b.liu68a94c92025-05-24 12:53:41 +0800538 break;
539 default:
540 LOGE("RING : None call_wait = %d", reg->call_wait);
541 break;
542 }
543}
544
545
546/**
547* @brief init voice sdk,and register the status indicated callback function
548* @param [in] CallStateInd ind: status indicated callback function
549* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800550* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800551*/
552int32_t gsw_voice_sdk_init(CallStateInd ind)
553{
554 int ret;
555
556 if (gsw_voice_init_flag == 1 && call_info_handle != NULL)
557 {
558 return GSW_HAL_SUCCESS;
559 }
560
561 if(ind == NULL)
562 {
563 LOGE("parameter is null\n");
xy.hecfb7d682025-05-28 21:39:12 +0800564 return GSW_HAL_ARG_INVALID;
b.liu68a94c92025-05-24 12:53:41 +0800565 }
566
567 ret = mbtk_call_api_import();
568 if(ret != 0)
569 {
570 if(mbtk_log != NULL)
571 {
572 LOGE("[gsw_voice_sdk_init]mbtk_call_api_import fail\n");
573 }
xy.hecfb7d682025-05-28 21:39:12 +0800574 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800575 }
576
577 mbtk_log_init("syslog", "MBTK_RIL");
578
579
580 if(ret < 0)
581 {
582 LOGE("mbtk_call_api_import fail,ret = %d\n",ret);
xy.hecfb7d682025-05-28 21:39:12 +0800583 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800584 }
585
586 ret=mbtk_rtp_init();
587
588 if(ret!=0)
589 {
590 LOGE("[gsw_voice_sdk_init]mbtk_rtp_init fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800591 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800592 }
593
594 if(call_info_handle == NULL)
595 {
596 call_info_handle = mbtk_info_handle_get();
597 if(call_info_handle != NULL)
598 {
599 LOGE("create gsw_voice_sdk_init success\n");
600
601 ret = mbtk_call_state_change_cb_reg(call_info_handle, gsw_call_state_change_cb);
602 if(ret)
603 {
604 LOGE("mbtk_call_state_change_cb_reg fail,ret = %d\n",ret);
605 (void) mbtk_rtp_deinit();
xy.hecfb7d682025-05-28 21:39:12 +0800606 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800607 }
608 else
609 {
610 gsw_voice_init_flag = 1;
611 gsw_voice_callback = ind;
612 LOGE("create gsw_voice_sdk_init success\n");
613 return GSW_HAL_SUCCESS;
614 }
615
616 }
617
618 else
619 {
620 (void) mbtk_rtp_deinit();
621 LOGE("create gsw_voice_sdk_init fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800622 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800623 }
624 }
625
626 return GSW_HAL_SUCCESS;
627}
628
629/**
630* @brief set speaker_volume
631* @param [in] int32_t volume:1(Min)-7(Max)
632* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800633* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800634*/
635int32_t gsw_voice_set_speaker_volume(int32_t volume)
636{
637 //UNUSED(volume);
638
q.huang50a0d852025-06-11 14:35:15 +0800639 VOICE_MODULE_INIT_CHECK();
b.liu68a94c92025-05-24 12:53:41 +0800640
641 char cmd[128] = {0};
642 int lv = 0;
643
644 memset(cmd ,0x00, sizeof(cmd));
645
646 if(volume < 1 || volume > 7)
647 {
648 LOGE("Error volume : %d", volume);
xy.hecfb7d682025-05-28 21:39:12 +0800649 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800650 }
651 else
652 {
653 switch(volume)
654 {
655 case 1 :
656 lv = -36;
657 break;
658 case 2 :
659 lv = -36;
660 break;
661 case 3 :
662 lv = -27;
663 break;
664 case 4 :
665 lv = -18;
666 break;
667 case 5 :
668 lv = -9;
669 break;
670 case 6 :
671 lv = 0;
672 break;
673 case 7:
674 lv = 12;
675 break;
676 default:
677 break;
678 }
679 }
680
681 sprintf(cmd, "ubus call audio_if config_dspgain \"{\'type\':%d,\'gain\':%d}\"", 1, lv);
682// sLOGE(cmd, "ubus call audio_if volume_set \'{\"param0\":%d}\'", lv);
683 int err = system(cmd);
684 if ((err != -1) && (err != 127))
685 {
686 LOGE("Set success.");
687 level_call = volume;
688 }
689 else
690 {
691 LOGE("Error : %d", err);
xy.hecfb7d682025-05-28 21:39:12 +0800692 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800693 }
694
695 return GSW_HAL_SUCCESS;
696}
697
698/**
699* @brief start a voice call
700* @param [in] char *callNumber
701* @param [out] CallHandle *handle
xy.hecfb7d682025-05-28 21:39:12 +0800702* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800703*/
704int32_t gsw_voice_normal_voice_start(CallHandle *handle, const char *callNumber)
705{
q.huang50a0d852025-06-11 14:35:15 +0800706 VOICE_MODULE_INIT_CHECK();
b.liu68a94c92025-05-24 12:53:41 +0800707
708 mbtk_call_info_t reg = {0};
709 int ret = -1;
710
711
712 if(handle == NULL)
713 {
714 LOGE("handle is null\n");
xy.hecfb7d682025-05-28 21:39:12 +0800715 return GSW_HAL_ARG_INVALID;
b.liu68a94c92025-05-24 12:53:41 +0800716 }
717
718 if(callNumber == NULL)
719 {
720 LOGE("callNumber is null\n");
xy.hecfb7d682025-05-28 21:39:12 +0800721 return GSW_HAL_ARG_INVALID;
b.liu68a94c92025-05-24 12:53:41 +0800722 }
723
724
725 ret = mbtk_call_start(call_info_handle, (char *)callNumber);
726
727 if(ret != 0)
728 {
729 LOGE("mbtk_call_start fail,ret = %d\n",ret);
xy.hecfb7d682025-05-28 21:39:12 +0800730 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800731 }
732
733 //get call id
734 mbtk_call_reg_get(call_info_handle, &reg);
735 LOGE("call id = %d\n",reg.dir1);
736 *handle = reg.dir1;
737 LOGE("gsw_voice_normal_voice_start id = %d\n", (int)*handle);
738
739
740 return GSW_HAL_SUCCESS;
741
742}
743
744/**
745* @brief answer a voice call
746* @param [in] CallHandle handle
747* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800748* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800749*/
750int32_t gsw_voice_answer(CallHandle handle)
751{
q.huang50a0d852025-06-11 14:35:15 +0800752 VOICE_MODULE_INIT_CHECK();
b.liu68a94c92025-05-24 12:53:41 +0800753
754 int ret = -1;
755
756
757 ret = mbtk_call_answer(call_info_handle);
758
759 if(ret != 0)
760 {
761 LOGE("mbtk_call_answer fail,ret = %d\n", ret);
xy.hecfb7d682025-05-28 21:39:12 +0800762 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800763 }
764 else
765 {
766 LOGE("mbtk_call_answer success\n");
767 }
768
769 return GSW_HAL_SUCCESS;
770}
771
772
773/**
774* @brief hangup 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_hangup(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 ret = mbtk_a_call_hang(call_info_handle,handle);
786
787 if(ret != 0)
788 {
789 LOGE("mbtk_a_call_hang fail,ret = %d\n", ret);
xy.hecfb7d682025-05-28 21:39:12 +0800790 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800791 }
792 else
793 {
794 LOGE("mbtk_a_call_hang success\n");
795 }
796
797 return GSW_HAL_SUCCESS;
798}
799
800/**
801* @brief set auto answer mode
802* @param [in] int32_t mode:0-1, 0:NO(close auto answer), 1:YES(auto answer)
803* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800804* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800805*/
806int32_t gsw_voice_set_auto_answer_mode(int32_t mode)
807{
q.huang50a0d852025-06-11 14:35:15 +0800808 VOICE_MODULE_INIT_CHECK();
809
b.liu68a94c92025-05-24 12:53:41 +0800810 if(mode == 1)
811 {
812 int ret = -1;
813
814 ret = mbtk_call_answer(call_info_handle);
815 if(ret != 0)
816 {
817 LOGE("mbtk_call_answer fail,ret = %d\n", ret);
xy.hecfb7d682025-05-28 21:39:12 +0800818 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800819 }
820 else
821 {
822 LOGE("mbtk_call_answer success\n");
823 }
824 }
825
826 return GSW_HAL_SUCCESS;
827}
828
829int32_t gsw_voice_get_current_call_end_reason(CallHandle handle)
830{
q.huang50a0d852025-06-11 14:35:15 +0800831 VOICE_MODULE_INIT_CHECK();
q.huang5461cfd2025-06-24 19:04:34 +0800832
833 return gsw_global_end_reason;
b.liu68a94c92025-05-24 12:53:41 +0800834}
835
836
837
838/*##########################################rtp begin*/
839/**
840* @brief set audio mode
841* @param [in] AudioMode audioMode
842* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800843* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800844*/
845int32_t gsw_voice_set_audio_mode(AudioMode audioMode)
846{
q.huang50a0d852025-06-11 14:35:15 +0800847 VOICE_MODULE_INIT_CHECK();
b.liu68a94c92025-05-24 12:53:41 +0800848
849 int ret=mbtk_rtp_enable(audioMode);
850 if(ret !=0 )
851 {
xy.hecfb7d682025-05-28 21:39:12 +0800852 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800853 }
854 return GSW_HAL_SUCCESS;
855}
856
857/**
858* @brief set rtp ip address of remote
859* @param [in] char *ip :ip address
860* @param [in] int32_t len: length
861* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800862* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800863*/
864int32_t gsw_voice_set_remote_rtp_ip(const char *ip, int32_t len)
865{
q.huang50a0d852025-06-11 14:35:15 +0800866 VOICE_MODULE_INIT_CHECK();
b.liu68a94c92025-05-24 12:53:41 +0800867
868 int ret=mbtk_rtp_remote_ip_set(ip);
869 if(ret !=0 )
870 {
xy.hecfb7d682025-05-28 21:39:12 +0800871 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800872 }
873 return GSW_HAL_SUCCESS;
874}
875
876/**
877* @brief set rtp mode and port
878* @param [in] RTPMode rtpMode: rtp mode
879* @param [in] int32_t port:rtp port
880* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800881* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800882*/
883int32_t gsw_voice_set_rtp_port(RTPMode rtpMode, int32_t port)
884{
q.huang50a0d852025-06-11 14:35:15 +0800885 VOICE_MODULE_INIT_CHECK();
b.liu68a94c92025-05-24 12:53:41 +0800886
887 int ret;
888 if(rtpMode==GSW_RTP_CLIENT)
889 {
890 ret = mbtk_rtp_client_port_set(port);
891 }
892 else
893 {
894 ret = mbtk_rtp_server_port_set(port);
895 }
896 if(ret !=0 )
897 {
xy.hecfb7d682025-05-28 21:39:12 +0800898 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800899 }
900 return GSW_HAL_SUCCESS;
901}
902
903/**
904* @brief set rtp mode and port
905* @param [in] int32_t clockRate: clock rate
906* @param [in] int32_t channel:channel
907* @param [in] int32_t latency:latency
908* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800909* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800910*/
911int32_t gsw_voice_set_rtp_param(int32_t clockRate, int32_t channel, int32_t latency)
912{
q.huang50a0d852025-06-11 14:35:15 +0800913 VOICE_MODULE_INIT_CHECK();
b.liu68a94c92025-05-24 12:53:41 +0800914
915 int ret=mbtk_rtp_channel_set(channel);
916 if(ret==0)
917 {
918 ret=mbtk_rtp_sample_rate_set(clockRate);
919 }
920 if(ret !=0 )
921 {
xy.hecfb7d682025-05-28 21:39:12 +0800922 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800923 }
924 return GSW_HAL_SUCCESS;
925}
q.huang020cc232025-06-06 19:06:18 +0800926
927/**
928 * @brief set rtp vlan
929 * @param [in] interfaceName network interface name
930 * @retval 0: success
931 * @retval other: fail
932 */
933int32_t gsw_voice_set_rtp_vlan_info(const char *interfaceName)
934{
q.huang50a0d852025-06-11 14:35:15 +0800935 VOICE_MODULE_INIT_CHECK();
q.huang020cc232025-06-06 19:06:18 +0800936
937 int ret=mbtk_rtp_vlan_set(interfaceName);
938
939 if(ret !=0 )
940 {
941 return GSW_HAL_NORMAL_FAIL;
942 }
943 return GSW_HAL_SUCCESS;
944}
b.liu68a94c92025-05-24 12:53:41 +0800945/*##########################################rtp end*/
946