blob: 1063c79134e5bf564067e7b1e29a5e8b1deea4a0 [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);
220/*rtp end*/
221
222
223#ifndef LOG_ERR_LEVEL
224#define LOG_ERR_LEVEL 3 /* error conditions */
225#endif
226#ifndef LOG_WARN_LEVEL
227#define LOG_WARN_LEVEL 4 /* warning conditions */
228#endif
229#ifndef LOG_INFO_LEVEL
230#define LOG_INFO_LEVEL 6 /* informational */
231#endif
232#ifndef LOG_DEBUG_LEVEL
233#define LOG_DEBUG_LEVEL 7 /* debug-level messages */
234#endif
235#ifndef LOG_VERBOSE_LEVEL
236#define LOG_VERBOSE_LEVEL 8
237#endif
238
l.yang6a42e4d2025-05-28 01:04:20 -0700239#define GSW_VOICE "[HAL][GSW_VOICE]"
240
b.liu68a94c92025-05-24 12:53:41 +0800241#define LOGV(fmt, args ...) \
242 do{ \
243 char *file_ptr_1001 = __FILE__; \
244 char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
245 char line_1001[10] = {0}; \
246 sprintf(line_1001, "%d", __LINE__); \
247 while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
248 if(*ptr_1001 == '/') \
249 break; \
250 ptr_1001--; \
251 } \
l.yang6a42e4d2025-05-28 01:04:20 -0700252 mbtk_log(LOG_VERBOSE_LEVEL, "%s#%s: "GSW_VOICE"" fmt, ptr_1001 + 1, line_1001, ##args); \
b.liu68a94c92025-05-24 12:53:41 +0800253 } while(0)
254
255#define LOGI(fmt, args...) \
256 do{ \
257 char *file_ptr_1001 = __FILE__; \
258 char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
259 char line_1001[10] = {0}; \
260 sprintf(line_1001, "%d", __LINE__); \
261 while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
262 if(*ptr_1001 == '/') \
263 break; \
264 ptr_1001--; \
265 } \
l.yang6a42e4d2025-05-28 01:04:20 -0700266 mbtk_log(LOG_INFO_LEVEL, "%s#%s: "GSW_VOICE"" fmt, ptr_1001 + 1, line_1001, ##args); \
b.liu68a94c92025-05-24 12:53:41 +0800267 } while(0)
268
269#define LOGD(fmt, args...) \
270 do{ \
271 char *file_ptr_1001 = __FILE__; \
272 char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
273 char line_1001[10] = {0}; \
274 sprintf(line_1001, "%d", __LINE__); \
275 while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
276 if(*ptr_1001 == '/') \
277 break; \
278 ptr_1001--; \
279 } \
l.yang6a42e4d2025-05-28 01:04:20 -0700280 mbtk_log(LOG_DEBUG_LEVEL, "%s#%s: "GSW_VOICE"" fmt, ptr_1001 + 1, line_1001, ##args); \
b.liu68a94c92025-05-24 12:53:41 +0800281 } while(0)
282
283#define LOGW(fmt, args...) \
284 do{ \
285 char *file_ptr_1001 = __FILE__; \
286 char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
287 char line_1001[10] = {0}; \
288 sprintf(line_1001, "%d", __LINE__); \
289 while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
290 if(*ptr_1001 == '/') \
291 break; \
292 ptr_1001--; \
293 } \
l.yang6a42e4d2025-05-28 01:04:20 -0700294 mbtk_log(LOG_WARN_LEVEL, "%s#%s: "GSW_VOICE"" fmt, ptr_1001 + 1, line_1001, ##args); \
b.liu68a94c92025-05-24 12:53:41 +0800295 } while(0)
296
297#define LOGE(fmt, args...) \
298 do{ \
299 char *file_ptr_1001 = __FILE__; \
300 char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
301 char line_1001[10] = {0}; \
302 sprintf(line_1001, "%d", __LINE__); \
303 while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
304 if(*ptr_1001 == '/') \
305 break; \
306 ptr_1001--; \
307 } \
l.yang6a42e4d2025-05-28 01:04:20 -0700308 mbtk_log(LOG_ERR_LEVEL, "%s#%s: "GSW_VOICE"" fmt, ptr_1001 + 1, line_1001, ##args); \
b.liu68a94c92025-05-24 12:53:41 +0800309 } while(0)
310
311static int mbtk_rtp_api_import()
312{
313 mbtk_rtp_init = (int (*)(void))dlsym(dlHandle_mbtk, "mbtk_rtp_init");
314 if (mbtk_rtp_init == NULL)
315 {
316 LOGE("mbtk_rtp_init 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_deinit = (int (*)(void))dlsym(dlHandle_mbtk, "mbtk_rtp_deinit");
321 if (mbtk_rtp_deinit == NULL)
322 {
323 LOGE("mbtk_rtp_deinit 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_enable = (int (*)(bool enable))dlsym(dlHandle_mbtk, "mbtk_rtp_enable");
328 if (mbtk_rtp_enable == NULL)
329 {
330 LOGE("mbtk_rtp_enable 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_remote_ip_set = (int (*)(const char *ipv4))dlsym(dlHandle_mbtk, "mbtk_rtp_remote_ip_set");
335 if (mbtk_rtp_remote_ip_set == NULL)
336 {
337 LOGE("mbtk_rtp_remote_ip_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_server_port_set = (int (*)(int port))dlsym(dlHandle_mbtk, "mbtk_rtp_server_port_set");
342 if (mbtk_rtp_server_port_set == NULL)
343 {
344 LOGE("mbtk_rtp_server_port_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 }
347
348 mbtk_rtp_client_port_set = (int (*)(int port))dlsym(dlHandle_mbtk, "mbtk_rtp_client_port_set");
349 if (mbtk_rtp_client_port_set == NULL)
350 {
351 LOGE("mbtk_rtp_client_port_set dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800352 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800353 }
354
355 mbtk_rtp_sample_rate_set = (int (*)(int sample_rate))dlsym(dlHandle_mbtk, "mbtk_rtp_sample_rate_set");
356 if (mbtk_rtp_sample_rate_set == NULL)
357 {
358 LOGE("mbtk_rtp_sample_rate_set dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800359 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800360 }
361
362 mbtk_rtp_channel_set = (int (*)(int channel))dlsym(dlHandle_mbtk, "mbtk_rtp_channel_set");
363 if (mbtk_rtp_channel_set == NULL)
364 {
365 LOGE("mbtk_rtp_channel_set dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800366 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800367 }
368
369 return GSW_HAL_SUCCESS;
370}
371
372
373
374static int mbtk_call_api_import()
375{
376 dlHandle_mbtk = dlopen(lib_mbtk_path, RTLD_NOW);
377 if (dlHandle_mbtk == NULL)
378 {
xy.hecfb7d682025-05-28 21:39:12 +0800379 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800380 }
381
382 mbtk_log_init = (void (*)(char *path, char *tag))dlsym(dlHandle_mbtk, "mbtk_log_init");
383 if (mbtk_log_init == NULL)
384 {
xy.hecfb7d682025-05-28 21:39:12 +0800385 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800386 }
387
388 mbtk_log = (void (*)(int level, const char *format, ...))dlsym(dlHandle_mbtk, "mbtk_log");
389 if (mbtk_log == NULL)
390 {
xy.hecfb7d682025-05-28 21:39:12 +0800391 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800392 }
393
394 mbtk_info_handle_get = (mbtk_info_handle_t* (*)(void))dlsym(dlHandle_mbtk, "mbtk_info_handle_get");
395 if (mbtk_info_handle_get == NULL)
396 {
397 LOGE("mbtk_info_handle_get 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_state_change_cb_reg = (int (*)(mbtk_info_handle_t* handle, mbtk_info_callback_func cb))dlsym(dlHandle_mbtk, "mbtk_call_state_change_cb_reg");
402 if(mbtk_call_state_change_cb_reg == NULL)
403 {
404 LOGE("mbtk_call_state_change_cb_reg 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_start = (int (*)(mbtk_info_handle_t* handle, char* phone_number))dlsym(dlHandle_mbtk, "mbtk_call_start");
409 if(mbtk_call_start == NULL)
410 {
411 LOGE("mbtk_call_start 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_call_answer = (int (*)(mbtk_info_handle_t* handle))dlsym(dlHandle_mbtk, "mbtk_call_answer");
416 if(mbtk_call_answer == NULL)
417 {
418 LOGE("mbtk_call_answer 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_hang = (int (*)(mbtk_info_handle_t* handle))dlsym(dlHandle_mbtk, "mbtk_call_hang");
423 if(mbtk_call_hang == NULL)
424 {
425 LOGE("mbtk_call_hang 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 mbtk_a_call_hang = (int (*)(mbtk_info_handle_t* handle, int phone_id))dlsym(dlHandle_mbtk, "mbtk_a_call_hang");
430 if(mbtk_a_call_hang == NULL)
431 {
432 LOGE("mbtk_a_call_hang dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800433 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800434 }
435
436 mbtk_call_reg_get = (int (*)(mbtk_info_handle_t* handle, mbtk_call_info_t *reg))dlsym(dlHandle_mbtk, "mbtk_call_reg_get");
437 if(mbtk_call_reg_get == NULL)
438 {
439 LOGE("mbtk_call_reg_get dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800440 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800441 }
442
443 return mbtk_rtp_api_import();
444}
445
446static int end_reason_mbtk_to_gsw(char* mbtk_reason)
447{
448 LOGE("mbtk_reason:%s\n", mbtk_reason);
449 gsw_global_end_reason = GSW_OTHER_END_NORMAL;
450 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++)
451 {
452 if(0 == strncmp(mbtk_reason, g_end_reason[i].mbtk_end_reason, strlen(g_end_reason[i].mbtk_end_reason)))
453 {
454 gsw_global_end_reason = g_end_reason[i].end_reason;
455 LOGE("gsw_global_end_reason:%d\n", gsw_global_end_reason);
456 break;
457 }
458 }
459
460 return 0;
461}
462
463void gsw_call_state_change_cb(const void *data, int data_len)
464{
465 mbtk_call_info_t *reg = (mbtk_call_info_t *)data;
466 switch (reg->call_wait)
467 {
468 case MBTK_CLCC:
469 {
470 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);
471 switch(reg->state)
472 {
473 case 0:
474 state_t = GSW_VOICE_CALL_CONNECTED;
475 break;
476 case 1:
477 state_t = GSW_VOICE_CALL_HOLDING;
478 break;
479 case 2:
480 state_t = GSW_VOICE_CALL_DIALING;
481 break;
482 case 3:
483 state_t = GSW_VOICE_CALL_ALERTING;
484 break;
485 case 4:
486 state_t = GSW_VOICE_CALL_INCOMING;
487 break;
488 case 5:
489 state_t = GSW_VOICE_CALL_WAITING;
490 break;
491 case 6:
492 {
493 state_t = GSW_VOICE_CALL_END;
494 call_id_t = reg->dir1;
495 end_reason_mbtk_to_gsw((char *)reg->end_reason);
496 break;
497 }
498
499 }
500
501 if(gsw_voice_callback)
502 {
503 gsw_voice_callback(reg->dir1, state_t);
504 }
505
506 }
507 break;
508 case MBTK_DISCONNECTED:
509 {
510 LOGD("RING : call dis connected!");
511 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);
512 state_t = GSW_VOICE_CALL_END;
513 call_id_t = reg->dir1;
514 end_reason_mbtk_to_gsw((char *)reg->end_reason);
515 if(gsw_voice_callback)
516 {
517 gsw_voice_callback(reg->disconnected_id, state_t);
518 }
519 }
520 break;
521 case MBTK_CPAS:
522 LOGD("CALL : Call state = %d", reg->pas);
523 switch (reg->pas)
524 {
525 case MBTK_CALL_RADY:
526 LOGD("CALL: call READY");
527 break;
528 case MBTK_CALL_UNAVAILABLE:
529 LOGD("CALL: call unavaliable");
530 break;
531 case MBTK_CALL_UNKNOWN:
532 LOGD("CALL: call unknown");
533 break;
534 case MBTK_CALL_RINGING:
535 LOGD("CALL: call ringing");
536 break;
537 case MBTK_CALL_PROGRESS:
538 LOGD("CALL: call progress");
539 break;
540 case MBTK_CALL_ASLEEP:
541 LOGD("CALL: call asleep");
542 break;
543 case MBTK_CALL_ACTIVE:
544 LOGD("CALL: call active");
545 break;
546 default:
547 //LOGE("\r\n");
548 break;
549 }
550 break;
551 default:
552 LOGE("RING : None call_wait = %d", reg->call_wait);
553 break;
554 }
555}
556
557
558/**
559* @brief init voice sdk,and register the status indicated callback function
560* @param [in] CallStateInd ind: status indicated callback function
561* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800562* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800563*/
564int32_t gsw_voice_sdk_init(CallStateInd ind)
565{
566 int ret;
567
568 if (gsw_voice_init_flag == 1 && call_info_handle != NULL)
569 {
570 return GSW_HAL_SUCCESS;
571 }
572
573 if(ind == NULL)
574 {
575 LOGE("parameter is null\n");
xy.hecfb7d682025-05-28 21:39:12 +0800576 return GSW_HAL_ARG_INVALID;
b.liu68a94c92025-05-24 12:53:41 +0800577 }
578
579 ret = mbtk_call_api_import();
580 if(ret != 0)
581 {
582 if(mbtk_log != NULL)
583 {
584 LOGE("[gsw_voice_sdk_init]mbtk_call_api_import fail\n");
585 }
xy.hecfb7d682025-05-28 21:39:12 +0800586 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800587 }
588
589 mbtk_log_init("syslog", "MBTK_RIL");
590
591
592 if(ret < 0)
593 {
594 LOGE("mbtk_call_api_import fail,ret = %d\n",ret);
xy.hecfb7d682025-05-28 21:39:12 +0800595 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800596 }
597
598 ret=mbtk_rtp_init();
599
600 if(ret!=0)
601 {
602 LOGE("[gsw_voice_sdk_init]mbtk_rtp_init fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800603 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800604 }
605
606 if(call_info_handle == NULL)
607 {
608 call_info_handle = mbtk_info_handle_get();
609 if(call_info_handle != NULL)
610 {
611 LOGE("create gsw_voice_sdk_init success\n");
612
613 ret = mbtk_call_state_change_cb_reg(call_info_handle, gsw_call_state_change_cb);
614 if(ret)
615 {
616 LOGE("mbtk_call_state_change_cb_reg fail,ret = %d\n",ret);
617 (void) mbtk_rtp_deinit();
xy.hecfb7d682025-05-28 21:39:12 +0800618 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800619 }
620 else
621 {
622 gsw_voice_init_flag = 1;
623 gsw_voice_callback = ind;
624 LOGE("create gsw_voice_sdk_init success\n");
625 return GSW_HAL_SUCCESS;
626 }
627
628 }
629
630 else
631 {
632 (void) mbtk_rtp_deinit();
633 LOGE("create gsw_voice_sdk_init fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800634 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800635 }
636 }
637
638 return GSW_HAL_SUCCESS;
639}
640
641/**
642* @brief set speaker_volume
643* @param [in] int32_t volume:1(Min)-7(Max)
644* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800645* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800646*/
647int32_t gsw_voice_set_speaker_volume(int32_t volume)
648{
649 //UNUSED(volume);
650
651#if 0
652
653 if(volume < 0 || volume > 5)
654 {
655 level_call = 0;
656 }
657 else
658 {
659 //支持-36~12
660 switch(volume)
661 {
662 case 0 :
663 level_call = -20;
664 break;
665 case 1 :
666 level_call = -14;
667 break;
668 case 2 :
669 level_call = -8;
670 break;
671 case 3 :
672 level_call = 0;
673 break;
674 case 4 :
675 level_call = 5;
676 break;
677 case 5 :
678 level_call = 12;
679 break;
680 default:
681 break;
682 }
683 }
684
685 mbtk_audio_dsp_set(1, level_call);
686 if(err)
687 {
688 LOGE("Error : %d\n", err);
689 return -1;
690 }
691 else
692 {
693 LOGE("Set success.\n");
694 }
695#endif
696
697 char cmd[128] = {0};
698 int lv = 0;
699
700 memset(cmd ,0x00, sizeof(cmd));
701
702 if(volume < 1 || volume > 7)
703 {
704 LOGE("Error volume : %d", volume);
xy.hecfb7d682025-05-28 21:39:12 +0800705 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800706 }
707 else
708 {
709 switch(volume)
710 {
711 case 1 :
712 lv = -36;
713 break;
714 case 2 :
715 lv = -36;
716 break;
717 case 3 :
718 lv = -27;
719 break;
720 case 4 :
721 lv = -18;
722 break;
723 case 5 :
724 lv = -9;
725 break;
726 case 6 :
727 lv = 0;
728 break;
729 case 7:
730 lv = 12;
731 break;
732 default:
733 break;
734 }
735 }
736
737 sprintf(cmd, "ubus call audio_if config_dspgain \"{\'type\':%d,\'gain\':%d}\"", 1, lv);
738// sLOGE(cmd, "ubus call audio_if volume_set \'{\"param0\":%d}\'", lv);
739 int err = system(cmd);
740 if ((err != -1) && (err != 127))
741 {
742 LOGE("Set success.");
743 level_call = volume;
744 }
745 else
746 {
747 LOGE("Error : %d", err);
xy.hecfb7d682025-05-28 21:39:12 +0800748 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800749 }
750
751 return GSW_HAL_SUCCESS;
752}
753
754/**
755* @brief start a voice call
756* @param [in] char *callNumber
757* @param [out] CallHandle *handle
xy.hecfb7d682025-05-28 21:39:12 +0800758* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800759*/
760int32_t gsw_voice_normal_voice_start(CallHandle *handle, const char *callNumber)
761{
762 if(gsw_voice_init_flag == 0)
763 {
xy.hecfb7d682025-05-28 21:39:12 +0800764 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800765 }
766
767 mbtk_call_info_t reg = {0};
768 int ret = -1;
769
770
771 if(handle == NULL)
772 {
773 LOGE("handle is null\n");
xy.hecfb7d682025-05-28 21:39:12 +0800774 return GSW_HAL_ARG_INVALID;
b.liu68a94c92025-05-24 12:53:41 +0800775 }
776
777 if(callNumber == NULL)
778 {
779 LOGE("callNumber is null\n");
xy.hecfb7d682025-05-28 21:39:12 +0800780 return GSW_HAL_ARG_INVALID;
b.liu68a94c92025-05-24 12:53:41 +0800781 }
782
783
784 ret = mbtk_call_start(call_info_handle, (char *)callNumber);
785
786 if(ret != 0)
787 {
788 LOGE("mbtk_call_start fail,ret = %d\n",ret);
xy.hecfb7d682025-05-28 21:39:12 +0800789 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800790 }
791
792 //get call id
793 mbtk_call_reg_get(call_info_handle, &reg);
794 LOGE("call id = %d\n",reg.dir1);
795 *handle = reg.dir1;
796 LOGE("gsw_voice_normal_voice_start id = %d\n", (int)*handle);
797
798
799 return GSW_HAL_SUCCESS;
800
801}
802
803/**
804* @brief answer a voice call
805* @param [in] CallHandle handle
806* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800807* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800808*/
809int32_t gsw_voice_answer(CallHandle handle)
810{
811 if(gsw_voice_init_flag == 0)
812 {
xy.hecfb7d682025-05-28 21:39:12 +0800813 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800814 }
815
816 int ret = -1;
817
818
819 ret = mbtk_call_answer(call_info_handle);
820
821 if(ret != 0)
822 {
823 LOGE("mbtk_call_answer fail,ret = %d\n", ret);
xy.hecfb7d682025-05-28 21:39:12 +0800824 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800825 }
826 else
827 {
828 LOGE("mbtk_call_answer success\n");
829 }
830
831 return GSW_HAL_SUCCESS;
832}
833
834
835/**
836* @brief hangup a voice call
837* @param [in] CallHandle handle
838* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800839* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800840*/
841int32_t gsw_voice_hangup(CallHandle handle)
842{
843 if(gsw_voice_init_flag == 0)
844 {
xy.hecfb7d682025-05-28 21:39:12 +0800845 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800846 }
847
848 int ret = -1;
849
850 ret = mbtk_a_call_hang(call_info_handle,handle);
851
852 if(ret != 0)
853 {
854 LOGE("mbtk_a_call_hang fail,ret = %d\n", ret);
xy.hecfb7d682025-05-28 21:39:12 +0800855 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800856 }
857 else
858 {
859 LOGE("mbtk_a_call_hang success\n");
860 }
861
862 return GSW_HAL_SUCCESS;
863}
864
865/**
866* @brief set auto answer mode
867* @param [in] int32_t mode:0-1, 0:NO(close auto answer), 1:YES(auto answer)
868* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800869* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800870*/
871int32_t gsw_voice_set_auto_answer_mode(int32_t mode)
872{
873 if(gsw_voice_init_flag == 0)
874 {
xy.hecfb7d682025-05-28 21:39:12 +0800875 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800876 }
877
878 if(mode == 1)
879 {
880 int ret = -1;
881
882 ret = mbtk_call_answer(call_info_handle);
883 if(ret != 0)
884 {
885 LOGE("mbtk_call_answer fail,ret = %d\n", ret);
xy.hecfb7d682025-05-28 21:39:12 +0800886 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800887 }
888 else
889 {
890 LOGE("mbtk_call_answer success\n");
891 }
892 }
893
894 return GSW_HAL_SUCCESS;
895}
896
897int32_t gsw_voice_get_current_call_end_reason(CallHandle handle)
898{
899 if(gsw_voice_init_flag == 0 || call_info_handle == NULL)
900 {
xy.hecfb7d682025-05-28 21:39:12 +0800901 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800902 }
903
904 int reason = gsw_global_end_reason;
905
906 return reason;
907}
908
909
910
911/*##########################################rtp begin*/
912/**
913* @brief set audio mode
914* @param [in] AudioMode audioMode
915* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800916* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800917*/
918int32_t gsw_voice_set_audio_mode(AudioMode audioMode)
919{
920 if(gsw_voice_init_flag == 0)
921 {
xy.hecfb7d682025-05-28 21:39:12 +0800922 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800923 }
924
925 int ret=mbtk_rtp_enable(audioMode);
926 if(ret !=0 )
927 {
xy.hecfb7d682025-05-28 21:39:12 +0800928 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800929 }
930 return GSW_HAL_SUCCESS;
931}
932
933/**
934* @brief set rtp ip address of remote
935* @param [in] char *ip :ip address
936* @param [in] int32_t len: length
937* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800938* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800939*/
940int32_t gsw_voice_set_remote_rtp_ip(const char *ip, int32_t len)
941{
942 if(gsw_voice_init_flag == 0)
943 {
xy.hecfb7d682025-05-28 21:39:12 +0800944 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800945 }
946
947 int ret=mbtk_rtp_remote_ip_set(ip);
948 if(ret !=0 )
949 {
xy.hecfb7d682025-05-28 21:39:12 +0800950 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800951 }
952 return GSW_HAL_SUCCESS;
953}
954
955/**
956* @brief set rtp mode and port
957* @param [in] RTPMode rtpMode: rtp mode
958* @param [in] int32_t port:rtp port
959* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800960* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800961*/
962int32_t gsw_voice_set_rtp_port(RTPMode rtpMode, int32_t port)
963{
964 if(gsw_voice_init_flag == 0)
965 {
xy.hecfb7d682025-05-28 21:39:12 +0800966 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800967 }
968
969 int ret;
970 if(rtpMode==GSW_RTP_CLIENT)
971 {
972 ret = mbtk_rtp_client_port_set(port);
973 }
974 else
975 {
976 ret = mbtk_rtp_server_port_set(port);
977 }
978 if(ret !=0 )
979 {
xy.hecfb7d682025-05-28 21:39:12 +0800980 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800981 }
982 return GSW_HAL_SUCCESS;
983}
984
985/**
986* @brief set rtp mode and port
987* @param [in] int32_t clockRate: clock rate
988* @param [in] int32_t channel:channel
989* @param [in] int32_t latency:latency
990* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800991* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800992*/
993int32_t gsw_voice_set_rtp_param(int32_t clockRate, int32_t channel, int32_t latency)
994{
995 if(gsw_voice_init_flag == 0)
996 {
xy.hecfb7d682025-05-28 21:39:12 +0800997 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800998 }
999
1000 int ret=mbtk_rtp_channel_set(channel);
1001 if(ret==0)
1002 {
1003 ret=mbtk_rtp_sample_rate_set(clockRate);
1004 }
1005 if(ret !=0 )
1006 {
xy.hecfb7d682025-05-28 21:39:12 +08001007 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +08001008 }
1009 return GSW_HAL_SUCCESS;
1010}
1011/*##########################################rtp end*/
1012