blob: ce4fd2fb5ad09f134dc94b54c15a88ecf97f64c8 [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>
q.huang6e4f4732025-07-22 18:46:32 +08007#include "gsw_log_interface.h"
b.liu68a94c92025-05-24 12:53:41 +08008
9// mbtk includes
10
11typedef unsigned int uint32;
12typedef unsigned char uint8;
13typedef unsigned short uint16;
14typedef void (*mbtk_info_callback_func)(const void* data, int data_len);
15
16typedef struct
17{
18 int client_fd;
19 pthread_t read_thread_id;
20 int exit_fd[2];
21 bool is_waitting;
22 pthread_cond_t cond;
23 pthread_mutex_t mutex;
24
25 pthread_mutex_t send_mutex;
26
27 // Temp response data.
28 uint16 info_err;
29 uint16 data_len;
30 void *data;
31
32 //mbtk wyq for server_ready_status add start
33 char server_ready_status;
34 //mbtk wyq for server_ready_status add end
35
36 mbtk_info_callback_func net_state_cb;
37 mbtk_info_callback_func call_state_cb;
38 mbtk_info_callback_func sms_state_cb;
39 mbtk_info_callback_func radio_state_cb;
40 mbtk_info_callback_func sim_state_cb;
41 mbtk_info_callback_func pdp_state_cb;
42 //add signal by xr
43 mbtk_info_callback_func signal_state_cb;
44} mbtk_info_handle_t;
45
46typedef struct
47{
48 uint8 call_wait;
49 uint8 dir1;
50 uint8 dir;
51 uint8 state;
52 uint8 mode;
53 uint8 mpty;
54 char phone_number[100];
55 uint8 type;
56 uint8 pas;
57 uint8 disconnected_id;
58 uint8 end_reason[128];
59} __attribute__((packed)) mbtk_call_info_t;
60
61typedef enum {
62 MBTK_CLCC = 1,
63 MBTK_CPAS,
64 MBTK_DISCONNECTED,
65} mbtk_call_enum;
66
67typedef enum {
68 MBTK_CALL_RADY, //MT allows commands from TA/TE
69 MBTK_CALL_UNAVAILABLE, //MT does not allow commands from TA/TE
70 MBTK_CALL_UNKNOWN, //MT is not guaranteed to respond to instructions
71 MBTK_CALL_RINGING, //MT is ready for commands from TA/TE, but the ringer is active
72 MBTK_CALL_PROGRESS, //MT is ready for commands from TA/TE, but a call is in progress
73 MBTK_CALL_ASLEEP, //MT is unable to process commands from TA/TE because it is in a low functionality state
74 MBTK_CALL_ACTIVE,
75} mbtk_call_pas_enum;
76
77
78//----------------end_reason start------------
79//mbtk end_reason define
80#define MBTK_VOICE_END_REASON_UNKNOWN "0 "
81#define MBTK_VOICE_END_REASON_UNASSIGNED_NUMBER "1 "
82#define MBTK_VOICE_END_REASON_NO_ROUTE_DES "3 "
83#define MBTK_VOICE_END_REASON_CHANNEL_UNACCEPTABLE "6 "
84#define MBTK_VOICE_END_REASON_OPERATOR_DETERMINED_BARRING "8 "
85#define MBTK_VOICE_END_REASON_NORMAL_CALL_CLEARING "16 "
86#define MBTK_VOICE_END_REASON_USER_BUSY "17 "
87#define MBTK_VOICE_END_REASON_NO_USER_RESPONDING "18 "
88#define MBTK_VOICE_END_REASON_USER_ALERTING_NO_ANSWER "19 "
89#define MBTK_VOICE_END_REASON_CALL_REJECTED "21 "
90#define MBTK_VOICE_END_REASON_NUMBER_CHANGED "22 "
91#define MBTK_VOICE_END_REASON_PREEMPTION "25 "
92#define MBTK_VOICE_END_REASON_NON_SELECTED_USER_CLEARING "26 "
93#define MBTK_VOICE_END_REASON_DESTINATION_OUT_OF_ORDER "27 "
94#define MBTK_VOICE_END_REASON_INVALID_NUMBER_FORMAT "28 "
95#define MBTK_VOICE_END_REASON_FACILITY_REJECTED "29 "
96#define MBTK_VOICE_END_REASON_STATUS_ENQUIRY "30 "
97#define MBTK_VOICE_END_REASON_NORMAL_UNSPECIFIED "31 "
98#define MBTK_VOICE_END_REASON_NO_CIRCUIT_AVAILABLE "34 "
99#define MBTK_VOICE_END_REASON_NETWORK_OUT_OF_ORDER "38 "
100#define MBTK_VOICE_END_REASON_TEMPORARY_FAILURE "41 "
101#define MBTK_VOICE_END_REASON_SWITCHING_EQUIPMENT_CONGESTION "42 "
102#define MBTK_VOICE_END_REASON_ACCESS_INFORMATION_DISCARDED "43 "
103#define MBTK_VOICE_END_REASON_REQUESTED_CIRCUIT_UNAVAILABLE "44 "
104#define MBTK_VOICE_END_REASON_RESOURCE_UNAVAILABLE "47 "
105#define MBTK_VOICE_END_REASON_QOS_UNAVAILABLE "49 "
106#define MBTK_VOICE_END_REASON_REQUESTED_FACILITY_NOT_SUBSCRIBED "50 "
107#define MBTK_VOICE_END_REASON_INCOMING_CALLS_BARRED_WITHIN_CUG "55 "
108#define MBTK_VOICE_END_REASON_BEARER_CAPABILITY_NOT_AUTHORIZED "57 "
109#define MBTK_VOICE_END_REASON_BEARER_CAPABILITY_NOT_AVAILABLE "58 "
110#define MBTK_VOICE_END_REASON_SERVICE_NOT_AVAILABLE "63 "
111#define MBTK_VOICE_END_REASON_BEARER_SERVICE_NOT_IMPLEMENTED "65 "
112#define MBTK_VOICE_END_REASON_ACM_MAX_REACHED "68 "
113#define MBTK_VOICE_END_REASON_FACILITY_NOT_IMPLEMENTED "69 "
114#define MBTK_VOICE_END_REASON_ONLY_RDI_BEARER_CAPABILITY_AVAILABLE "70 "
115#define MBTK_VOICE_END_REASON_SERVICE_NOT_IMPLEMENTED "79 "
116#define MBTK_VOICE_END_REASON_INVALID_TRANSACTION_ID "81 "
117#define MBTK_VOICE_END_REASON_USER_NOT_MEMBER_OF_CUG "87 "
118#define MBTK_VOICE_END_REASON_INCOMPATIBLE_DESTINATION "88 "
119#define MBTK_VOICE_END_REASON_INVALID_TRANSIT_NETWORK_SELECTION "91 "
120#define MBTK_VOICE_END_REASON_INCORRECT_MESSAGE "95 "
121#define MBTK_VOICE_END_REASON_INVALID_MANDATORY_INFORMATION "96 "
122#define MBTK_VOICE_END_REASON_MESSAGE_TYPE_NON_EXISTENT "97 "
123#define MBTK_VOICE_END_REASON_MESSAGE_TYPE_WRONG_STATE "98 "
124#define MBTK_VOICE_END_REASON_INFORMATION_ELEMENT_NOT_EXISTENT "99 "
125#define MBTK_VOICE_END_REASON_CONDITIONAL_IE_ERROR "100 "
126#define MBTK_VOICE_END_REASON_MESSAGE_WRONG_STATE "101 "
127#define MBTK_VOICE_END_REASON_RECOVERY_AFTER_TIMER_EXPIRY "102 "
128#define MBTK_VOICE_END_REASON_PROTOCOL_ERROR_UNSPECIFIED "111 "
129#define MBTK_VOICE_END_REASON_INERWORKING_UNSPECIFIED "127 "
130#define MBTK_VOICE_END_REASON_CALL_BARRING "224 "
131#define MBTK_VOICE_END_REASON_FDN_BLOCKED "241 "
132#define MBTK_VOICE_END_REASON_END "end"
133
134typedef enum{
135 GSW_LOCAL_END_NORMAL = 0,
136 GSW_PEER_END_NORMAL,
137 GSW_OTHER_END_NORMAL,
138 GSW_END_ABNORMAL,
139} gsw_call_end_reason_enum;
140
q.huangd934b6d2025-07-29 20:17:00 +0800141typedef struct {
142 char mbtk_end_reason[64];
143 gsw_call_end_reason_enum end_reason;
144}end_reason_map_t;
145
146end_reason_map_t g_end_reason_map[4] = {
147{MBTK_VOICE_END_REASON_NORMAL_CALL_CLEARING, GSW_OTHER_END_NORMAL},
148{MBTK_VOICE_END_REASON_NORMAL_UNSPECIFIED, GSW_OTHER_END_NORMAL},
149{MBTK_VOICE_END_REASON_USER_ALERTING_NO_ANSWER, GSW_PEER_END_NORMAL},
150{MBTK_VOICE_END_REASON_CALL_REJECTED, GSW_PEER_END_NORMAL},
b.liu68a94c92025-05-24 12:53:41 +0800151};
q.huangd934b6d2025-07-29 20:17:00 +0800152
b.liu68a94c92025-05-24 12:53:41 +0800153int gsw_global_end_reason = GSW_OTHER_END_NORMAL;
154
155//----------------end_reason end------------
156
157
158typedef uint32_t voice_client_handle_type;
159
b.liu68a94c92025-05-24 12:53:41 +0800160static mbtk_info_handle_t* call_info_handle = NULL;
161static int level_call = 0;
162int gsw_voice_init_flag = 0;
163int auto_answer_flag = 0;
164voice_client_handle_type g_call_val = -1;
165CallStateInd gsw_voice_callback = NULL;
166
167
168int state_t = 0;
169char* phone_num_t = NULL;
170char* phone_num_t2 = NULL;
171int call_id_t = 0;
172int call_id_t2 = 0;
173
174#define lib_mbtk_path "/lib/libmbtk_lib.so"
175static void *dlHandle_mbtk;
176
177static mbtk_info_handle_t* (*mbtk_info_handle_get)(void);
178int (*mbtk_call_state_change_cb_reg)(mbtk_info_handle_t* handle, mbtk_info_callback_func cb);
179int (*mbtk_call_start)(mbtk_info_handle_t* handle, char* phone_number);
180int (*mbtk_call_hang)(mbtk_info_handle_t* handle);
181int (*mbtk_a_call_hang)(mbtk_info_handle_t* handle, int phone_id);
182int (*mbtk_call_answer)(mbtk_info_handle_t* handle);
183int (*mbtk_call_reg_get)(mbtk_info_handle_t* handle, mbtk_call_info_t *reg);
b.liu68a94c92025-05-24 12:53:41 +0800184
185/*rtp begin*/
186int (*mbtk_rtp_init)();
187int (*mbtk_rtp_deinit)();
188int (*mbtk_rtp_enable)(bool enable);
189int (*mbtk_rtp_remote_ip_set)(const char *ipv4);
190int (*mbtk_rtp_server_port_set)(int port);
191int (*mbtk_rtp_client_port_set)(int port);
192int (*mbtk_rtp_sample_rate_set)(int sample_rate);
193int (*mbtk_rtp_channel_set)(int channel);
q.huang020cc232025-06-06 19:06:18 +0800194int (*mbtk_rtp_vlan_set)(const char *vlan);
b.liu68a94c92025-05-24 12:53:41 +0800195/*rtp end*/
196
197
l.yang6a42e4d2025-05-28 01:04:20 -0700198#define GSW_VOICE "[HAL][GSW_VOICE]"
199
q.huang50a0d852025-06-11 14:35:15 +0800200#define MODULE_INIT_CHECK(init_flag) \
201 if(init_flag == 0) \
202 { \
203 return GSW_HAL_ERROR_GNSS_DATA_CALL_DEINIT; \
204 }
205
206#define VOICE_MODULE_INIT_CHECK() MODULE_INIT_CHECK(gsw_voice_init_flag)
207
208
b.liu68a94c92025-05-24 12:53:41 +0800209static int mbtk_rtp_api_import()
210{
211 mbtk_rtp_init = (int (*)(void))dlsym(dlHandle_mbtk, "mbtk_rtp_init");
212 if (mbtk_rtp_init == NULL)
213 {
q.huang6e4f4732025-07-22 18:46:32 +0800214 LOGE(GSW_VOICE,"mbtk_rtp_init dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800215 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800216 }
217
218 mbtk_rtp_deinit = (int (*)(void))dlsym(dlHandle_mbtk, "mbtk_rtp_deinit");
219 if (mbtk_rtp_deinit == NULL)
220 {
q.huang6e4f4732025-07-22 18:46:32 +0800221 LOGE(GSW_VOICE,"mbtk_rtp_deinit dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800222 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800223 }
224
225 mbtk_rtp_enable = (int (*)(bool enable))dlsym(dlHandle_mbtk, "mbtk_rtp_enable");
226 if (mbtk_rtp_enable == NULL)
227 {
q.huang6e4f4732025-07-22 18:46:32 +0800228 LOGE(GSW_VOICE,"mbtk_rtp_enable dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800229 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800230 }
231
232 mbtk_rtp_remote_ip_set = (int (*)(const char *ipv4))dlsym(dlHandle_mbtk, "mbtk_rtp_remote_ip_set");
233 if (mbtk_rtp_remote_ip_set == NULL)
234 {
q.huang6e4f4732025-07-22 18:46:32 +0800235 LOGE(GSW_VOICE,"mbtk_rtp_remote_ip_set dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800236 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800237 }
238
239 mbtk_rtp_server_port_set = (int (*)(int port))dlsym(dlHandle_mbtk, "mbtk_rtp_server_port_set");
240 if (mbtk_rtp_server_port_set == NULL)
241 {
q.huang6e4f4732025-07-22 18:46:32 +0800242 LOGE(GSW_VOICE,"mbtk_rtp_server_port_set dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800243 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800244 }
245
246 mbtk_rtp_client_port_set = (int (*)(int port))dlsym(dlHandle_mbtk, "mbtk_rtp_client_port_set");
247 if (mbtk_rtp_client_port_set == NULL)
248 {
q.huang6e4f4732025-07-22 18:46:32 +0800249 LOGE(GSW_VOICE,"mbtk_rtp_client_port_set dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800250 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800251 }
252
253 mbtk_rtp_sample_rate_set = (int (*)(int sample_rate))dlsym(dlHandle_mbtk, "mbtk_rtp_sample_rate_set");
254 if (mbtk_rtp_sample_rate_set == NULL)
255 {
q.huang6e4f4732025-07-22 18:46:32 +0800256 LOGE(GSW_VOICE,"mbtk_rtp_sample_rate_set dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800257 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800258 }
259
260 mbtk_rtp_channel_set = (int (*)(int channel))dlsym(dlHandle_mbtk, "mbtk_rtp_channel_set");
261 if (mbtk_rtp_channel_set == NULL)
262 {
q.huang6e4f4732025-07-22 18:46:32 +0800263 LOGE(GSW_VOICE,"mbtk_rtp_channel_set dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800264 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800265 }
q.huang020cc232025-06-06 19:06:18 +0800266
267 mbtk_rtp_vlan_set = (int (*)(const char *vlan))dlsym(dlHandle_mbtk, "mbtk_rtp_vlan_set");
268 if (mbtk_rtp_vlan_set == NULL)
269 {
q.huang6e4f4732025-07-22 18:46:32 +0800270 LOGE(GSW_VOICE,"mbtk_rtp_vlan_set dlsym fail\n");
q.huang020cc232025-06-06 19:06:18 +0800271 return GSW_HAL_NORMAL_FAIL;
272 }
b.liu68a94c92025-05-24 12:53:41 +0800273
274 return GSW_HAL_SUCCESS;
275}
276
277
278
279static int mbtk_call_api_import()
280{
281 dlHandle_mbtk = dlopen(lib_mbtk_path, RTLD_NOW);
282 if (dlHandle_mbtk == NULL)
283 {
xy.hecfb7d682025-05-28 21:39:12 +0800284 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800285 }
286
b.liu68a94c92025-05-24 12:53:41 +0800287 mbtk_info_handle_get = (mbtk_info_handle_t* (*)(void))dlsym(dlHandle_mbtk, "mbtk_info_handle_get");
288 if (mbtk_info_handle_get == NULL)
289 {
q.huang6e4f4732025-07-22 18:46:32 +0800290 LOGE(GSW_VOICE,"mbtk_info_handle_get dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800291 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800292 }
293
294 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");
295 if(mbtk_call_state_change_cb_reg == NULL)
296 {
q.huang6e4f4732025-07-22 18:46:32 +0800297 LOGE(GSW_VOICE,"mbtk_call_state_change_cb_reg dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800298 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800299 }
300
301 mbtk_call_start = (int (*)(mbtk_info_handle_t* handle, char* phone_number))dlsym(dlHandle_mbtk, "mbtk_call_start");
302 if(mbtk_call_start == NULL)
303 {
q.huang6e4f4732025-07-22 18:46:32 +0800304 LOGE(GSW_VOICE,"mbtk_call_start dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800305 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800306 }
307
308 mbtk_call_answer = (int (*)(mbtk_info_handle_t* handle))dlsym(dlHandle_mbtk, "mbtk_call_answer");
309 if(mbtk_call_answer == NULL)
310 {
q.huang6e4f4732025-07-22 18:46:32 +0800311 LOGE(GSW_VOICE,"mbtk_call_answer dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800312 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800313 }
314
315 mbtk_call_hang = (int (*)(mbtk_info_handle_t* handle))dlsym(dlHandle_mbtk, "mbtk_call_hang");
316 if(mbtk_call_hang == NULL)
317 {
q.huang6e4f4732025-07-22 18:46:32 +0800318 LOGE(GSW_VOICE,"mbtk_call_hang dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800319 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800320 }
321
322 mbtk_a_call_hang = (int (*)(mbtk_info_handle_t* handle, int phone_id))dlsym(dlHandle_mbtk, "mbtk_a_call_hang");
323 if(mbtk_a_call_hang == NULL)
324 {
q.huang6e4f4732025-07-22 18:46:32 +0800325 LOGE(GSW_VOICE,"mbtk_a_call_hang dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800326 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800327 }
328
329 mbtk_call_reg_get = (int (*)(mbtk_info_handle_t* handle, mbtk_call_info_t *reg))dlsym(dlHandle_mbtk, "mbtk_call_reg_get");
330 if(mbtk_call_reg_get == NULL)
331 {
q.huang6e4f4732025-07-22 18:46:32 +0800332 LOGE(GSW_VOICE,"mbtk_call_reg_get dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800333 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800334 }
335
336 return mbtk_rtp_api_import();
337}
338
q.huang5461cfd2025-06-24 19:04:34 +0800339static void end_reason_mbtk_to_gsw(char* mbtk_reason)
b.liu68a94c92025-05-24 12:53:41 +0800340{
q.huang6e4f4732025-07-22 18:46:32 +0800341 LOGE(GSW_VOICE,"mbtk_reason:%s\n", mbtk_reason);
q.huang5461cfd2025-06-24 19:04:34 +0800342 gsw_global_end_reason = GSW_END_ABNORMAL;
q.huangd934b6d2025-07-29 20:17:00 +0800343
344 int length=sizeof (g_end_reason_map)/ sizeof(g_end_reason_map[0]);
q.huang5461cfd2025-06-24 19:04:34 +0800345 for(int i = 0; i<length; i++)
b.liu68a94c92025-05-24 12:53:41 +0800346 {
q.huangd934b6d2025-07-29 20:17:00 +0800347 if(0 == strncmp(mbtk_reason, g_end_reason_map[i].mbtk_end_reason, strlen(g_end_reason_map[i].mbtk_end_reason)))
b.liu68a94c92025-05-24 12:53:41 +0800348 {
q.huangd934b6d2025-07-29 20:17:00 +0800349 gsw_global_end_reason = g_end_reason_map[i].end_reason;
350 LOGE(GSW_VOICE,"mbtk call end reason %s gsw reason:%d\n", mbtk_reason,gsw_global_end_reason);
q.huang5461cfd2025-06-24 19:04:34 +0800351 return;
b.liu68a94c92025-05-24 12:53:41 +0800352 }
353 }
b.liu68a94c92025-05-24 12:53:41 +0800354}
355
356void gsw_call_state_change_cb(const void *data, int data_len)
357{
358 mbtk_call_info_t *reg = (mbtk_call_info_t *)data;
359 switch (reg->call_wait)
360 {
361 case MBTK_CLCC:
362 {
q.huang6e4f4732025-07-22 18:46:32 +0800363 LOGD(GSW_VOICE,"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);
364 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 +0800365 switch(reg->state)
366 {
367 case 0:
368 state_t = GSW_VOICE_CALL_CONNECTED;
369 break;
370 case 1:
371 state_t = GSW_VOICE_CALL_HOLDING;
372 break;
373 case 2:
374 state_t = GSW_VOICE_CALL_DIALING;
375 break;
376 case 3:
377 state_t = GSW_VOICE_CALL_ALERTING;
378 break;
379 case 4:
380 state_t = GSW_VOICE_CALL_INCOMING;
381 break;
382 case 5:
383 state_t = GSW_VOICE_CALL_WAITING;
384 break;
385 case 6:
386 {
387 state_t = GSW_VOICE_CALL_END;
388 call_id_t = reg->dir1;
389 end_reason_mbtk_to_gsw((char *)reg->end_reason);
390 break;
391 }
392
393 }
394
395 if(gsw_voice_callback)
396 {
397 gsw_voice_callback(reg->dir1, state_t);
398 }
399
400 }
q.huang5461cfd2025-06-24 19:04:34 +0800401 break;
b.liu68a94c92025-05-24 12:53:41 +0800402 case MBTK_DISCONNECTED:
403 {
q.huang6e4f4732025-07-22 18:46:32 +0800404 LOGD(GSW_VOICE,"RING : call dis connected!");
405 LOGD(GSW_VOICE,"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);
406 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);
q.huang5461cfd2025-06-24 19:04:34 +0800407 state_t = GSW_VOICE_CALL_END;
b.liu68a94c92025-05-24 12:53:41 +0800408 call_id_t = reg->dir1;
409 end_reason_mbtk_to_gsw((char *)reg->end_reason);
q.huang5461cfd2025-06-24 19:04:34 +0800410 if(gsw_voice_callback)
b.liu68a94c92025-05-24 12:53:41 +0800411 {
412 gsw_voice_callback(reg->disconnected_id, state_t);
413 }
414 }
q.huang5461cfd2025-06-24 19:04:34 +0800415 break;
b.liu68a94c92025-05-24 12:53:41 +0800416 case MBTK_CPAS:
q.huang6e4f4732025-07-22 18:46:32 +0800417 LOGD(GSW_VOICE,"CALL : Call state = %d", reg->pas);
q.huang5461cfd2025-06-24 19:04:34 +0800418 switch (reg->pas)
419 {
b.liu68a94c92025-05-24 12:53:41 +0800420 case MBTK_CALL_RADY:
q.huang6e4f4732025-07-22 18:46:32 +0800421 LOGD(GSW_VOICE,"CALL: call READY");
b.liu68a94c92025-05-24 12:53:41 +0800422 break;
423 case MBTK_CALL_UNAVAILABLE:
q.huang6e4f4732025-07-22 18:46:32 +0800424 LOGD(GSW_VOICE,"CALL: call unavaliable");
b.liu68a94c92025-05-24 12:53:41 +0800425 break;
426 case MBTK_CALL_UNKNOWN:
q.huang6e4f4732025-07-22 18:46:32 +0800427 LOGD(GSW_VOICE,"CALL: call unknown");
b.liu68a94c92025-05-24 12:53:41 +0800428 break;
429 case MBTK_CALL_RINGING:
q.huang6e4f4732025-07-22 18:46:32 +0800430 LOGD(GSW_VOICE,"CALL: call ringing");
b.liu68a94c92025-05-24 12:53:41 +0800431 break;
432 case MBTK_CALL_PROGRESS:
q.huang6e4f4732025-07-22 18:46:32 +0800433 LOGD(GSW_VOICE,"CALL: call progress");
b.liu68a94c92025-05-24 12:53:41 +0800434 break;
435 case MBTK_CALL_ASLEEP:
q.huang6e4f4732025-07-22 18:46:32 +0800436 LOGD(GSW_VOICE,"CALL: call asleep");
b.liu68a94c92025-05-24 12:53:41 +0800437 break;
438 case MBTK_CALL_ACTIVE:
q.huang6e4f4732025-07-22 18:46:32 +0800439 LOGD(GSW_VOICE,"CALL: call active");
b.liu68a94c92025-05-24 12:53:41 +0800440 break;
441 default:
q.huang6e4f4732025-07-22 18:46:32 +0800442 //LOGE(GSW_VOICE,"\r\n");
b.liu68a94c92025-05-24 12:53:41 +0800443 break;
q.huang5461cfd2025-06-24 19:04:34 +0800444 }
b.liu68a94c92025-05-24 12:53:41 +0800445 break;
446 default:
q.huang6e4f4732025-07-22 18:46:32 +0800447 LOGE(GSW_VOICE,"RING : None call_wait = %d", reg->call_wait);
b.liu68a94c92025-05-24 12:53:41 +0800448 break;
449 }
450}
451
b.liu68a94c92025-05-24 12:53:41 +0800452/**
453* @brief init voice sdk,and register the status indicated callback function
454* @param [in] CallStateInd ind: status indicated callback function
455* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800456* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800457*/
458int32_t gsw_voice_sdk_init(CallStateInd ind)
459{
b.liu68a94c92025-05-24 12:53:41 +0800460 if (gsw_voice_init_flag == 1 && call_info_handle != NULL)
461 {
462 return GSW_HAL_SUCCESS;
463 }
464
465 if(ind == NULL)
466 {
q.huang6e4f4732025-07-22 18:46:32 +0800467 LOGE(GSW_VOICE,"parameter is null\n");
xy.hecfb7d682025-05-28 21:39:12 +0800468 return GSW_HAL_ARG_INVALID;
b.liu68a94c92025-05-24 12:53:41 +0800469 }
470
q.huangd934b6d2025-07-29 20:17:00 +0800471 int ret = mbtk_call_api_import();
b.liu68a94c92025-05-24 12:53:41 +0800472 if(ret != 0)
473 {
q.huang6e4f4732025-07-22 18:46:32 +0800474 LOGE(GSW_VOICE,"[gsw_voice_sdk_init]mbtk_call_api_import fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800475 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800476 }
477
q.huangd934b6d2025-07-29 20:17:00 +0800478
479
b.liu68a94c92025-05-24 12:53:41 +0800480 if(call_info_handle == NULL)
481 {
482 call_info_handle = mbtk_info_handle_get();
483 if(call_info_handle != NULL)
484 {
q.huang6e4f4732025-07-22 18:46:32 +0800485 LOGE(GSW_VOICE,"create gsw_voice_sdk_init success\n");
b.liu68a94c92025-05-24 12:53:41 +0800486
487 ret = mbtk_call_state_change_cb_reg(call_info_handle, gsw_call_state_change_cb);
488 if(ret)
489 {
q.huang6e4f4732025-07-22 18:46:32 +0800490 LOGE(GSW_VOICE,"mbtk_call_state_change_cb_reg fail,ret = %d\n",ret);
xy.hecfb7d682025-05-28 21:39:12 +0800491 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800492 }
493 else
494 {
495 gsw_voice_init_flag = 1;
496 gsw_voice_callback = ind;
q.huang6e4f4732025-07-22 18:46:32 +0800497 LOGE(GSW_VOICE,"create gsw_voice_sdk_init success\n");
b.liu68a94c92025-05-24 12:53:41 +0800498 return GSW_HAL_SUCCESS;
499 }
500
501 }
502
503 else
504 {
q.huang6e4f4732025-07-22 18:46:32 +0800505 LOGE(GSW_VOICE,"create gsw_voice_sdk_init fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800506 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800507 }
508 }
509
510 return GSW_HAL_SUCCESS;
511}
512
513/**
514* @brief set speaker_volume
515* @param [in] int32_t volume:1(Min)-7(Max)
516* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800517* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800518*/
519int32_t gsw_voice_set_speaker_volume(int32_t volume)
520{
521 //UNUSED(volume);
522
q.huang50a0d852025-06-11 14:35:15 +0800523 VOICE_MODULE_INIT_CHECK();
b.liu68a94c92025-05-24 12:53:41 +0800524
525 char cmd[128] = {0};
526 int lv = 0;
527
528 memset(cmd ,0x00, sizeof(cmd));
529
530 if(volume < 1 || volume > 7)
531 {
q.huang6e4f4732025-07-22 18:46:32 +0800532 LOGE(GSW_VOICE,"Error volume : %d", volume);
xy.hecfb7d682025-05-28 21:39:12 +0800533 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800534 }
535 else
536 {
537 switch(volume)
538 {
539 case 1 :
540 lv = -36;
541 break;
542 case 2 :
543 lv = -36;
544 break;
545 case 3 :
546 lv = -27;
547 break;
548 case 4 :
549 lv = -18;
550 break;
551 case 5 :
552 lv = -9;
553 break;
554 case 6 :
555 lv = 0;
556 break;
557 case 7:
558 lv = 12;
559 break;
560 default:
561 break;
562 }
563 }
564
565 sprintf(cmd, "ubus call audio_if config_dspgain \"{\'type\':%d,\'gain\':%d}\"", 1, lv);
566// sLOGE(cmd, "ubus call audio_if volume_set \'{\"param0\":%d}\'", lv);
567 int err = system(cmd);
568 if ((err != -1) && (err != 127))
569 {
q.huang6e4f4732025-07-22 18:46:32 +0800570 LOGE(GSW_VOICE,"Set success.");
b.liu68a94c92025-05-24 12:53:41 +0800571 level_call = volume;
572 }
573 else
574 {
q.huang6e4f4732025-07-22 18:46:32 +0800575 LOGE(GSW_VOICE,"Error : %d", err);
xy.hecfb7d682025-05-28 21:39:12 +0800576 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800577 }
578
579 return GSW_HAL_SUCCESS;
580}
581
582/**
583* @brief start a voice call
584* @param [in] char *callNumber
585* @param [out] CallHandle *handle
xy.hecfb7d682025-05-28 21:39:12 +0800586* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800587*/
588int32_t gsw_voice_normal_voice_start(CallHandle *handle, const char *callNumber)
589{
q.huang50a0d852025-06-11 14:35:15 +0800590 VOICE_MODULE_INIT_CHECK();
b.liu68a94c92025-05-24 12:53:41 +0800591
592 mbtk_call_info_t reg = {0};
593 int ret = -1;
594
595
596 if(handle == NULL)
597 {
q.huang6e4f4732025-07-22 18:46:32 +0800598 LOGE(GSW_VOICE,"handle is null\n");
xy.hecfb7d682025-05-28 21:39:12 +0800599 return GSW_HAL_ARG_INVALID;
b.liu68a94c92025-05-24 12:53:41 +0800600 }
601
602 if(callNumber == NULL)
603 {
q.huang6e4f4732025-07-22 18:46:32 +0800604 LOGE(GSW_VOICE,"callNumber is null\n");
xy.hecfb7d682025-05-28 21:39:12 +0800605 return GSW_HAL_ARG_INVALID;
b.liu68a94c92025-05-24 12:53:41 +0800606 }
607
608
609 ret = mbtk_call_start(call_info_handle, (char *)callNumber);
610
611 if(ret != 0)
612 {
q.huang6e4f4732025-07-22 18:46:32 +0800613 LOGE(GSW_VOICE,"mbtk_call_start fail,ret = %d\n",ret);
xy.hecfb7d682025-05-28 21:39:12 +0800614 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800615 }
616
617 //get call id
618 mbtk_call_reg_get(call_info_handle, &reg);
q.huang6e4f4732025-07-22 18:46:32 +0800619 LOGE(GSW_VOICE,"call id = %d\n",reg.dir1);
b.liu68a94c92025-05-24 12:53:41 +0800620 *handle = reg.dir1;
q.huang6e4f4732025-07-22 18:46:32 +0800621 LOGE(GSW_VOICE,"gsw_voice_normal_voice_start id = %d\n", (int)*handle);
b.liu68a94c92025-05-24 12:53:41 +0800622
623
624 return GSW_HAL_SUCCESS;
625
626}
627
628/**
629* @brief answer a voice call
630* @param [in] CallHandle handle
631* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800632* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800633*/
634int32_t gsw_voice_answer(CallHandle handle)
635{
q.huang50a0d852025-06-11 14:35:15 +0800636 VOICE_MODULE_INIT_CHECK();
b.liu68a94c92025-05-24 12:53:41 +0800637
638 int ret = -1;
639
640
641 ret = mbtk_call_answer(call_info_handle);
642
643 if(ret != 0)
644 {
q.huang6e4f4732025-07-22 18:46:32 +0800645 LOGE(GSW_VOICE,"mbtk_call_answer fail,ret = %d\n", ret);
xy.hecfb7d682025-05-28 21:39:12 +0800646 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800647 }
648 else
649 {
q.huang6e4f4732025-07-22 18:46:32 +0800650 LOGE(GSW_VOICE,"mbtk_call_answer success\n");
b.liu68a94c92025-05-24 12:53:41 +0800651 }
652
653 return GSW_HAL_SUCCESS;
654}
655
656
657/**
658* @brief hangup a voice call
659* @param [in] CallHandle handle
660* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800661* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800662*/
663int32_t gsw_voice_hangup(CallHandle handle)
664{
q.huang50a0d852025-06-11 14:35:15 +0800665 VOICE_MODULE_INIT_CHECK();
b.liu68a94c92025-05-24 12:53:41 +0800666
667 int ret = -1;
668
669 ret = mbtk_a_call_hang(call_info_handle,handle);
670
671 if(ret != 0)
672 {
q.huang6e4f4732025-07-22 18:46:32 +0800673 LOGE(GSW_VOICE,"mbtk_a_call_hang fail,ret = %d\n", ret);
xy.hecfb7d682025-05-28 21:39:12 +0800674 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800675 }
676 else
677 {
q.huang6e4f4732025-07-22 18:46:32 +0800678 LOGE(GSW_VOICE,"mbtk_a_call_hang success\n");
b.liu68a94c92025-05-24 12:53:41 +0800679 }
680
681 return GSW_HAL_SUCCESS;
682}
683
684/**
685* @brief set auto answer mode
686* @param [in] int32_t mode:0-1, 0:NO(close auto answer), 1:YES(auto answer)
687* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800688* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800689*/
690int32_t gsw_voice_set_auto_answer_mode(int32_t mode)
691{
q.huang50a0d852025-06-11 14:35:15 +0800692 VOICE_MODULE_INIT_CHECK();
693
b.liu68a94c92025-05-24 12:53:41 +0800694 if(mode == 1)
695 {
696 int ret = -1;
697
698 ret = mbtk_call_answer(call_info_handle);
699 if(ret != 0)
700 {
q.huang6e4f4732025-07-22 18:46:32 +0800701 LOGE(GSW_VOICE,"mbtk_call_answer fail,ret = %d\n", ret);
xy.hecfb7d682025-05-28 21:39:12 +0800702 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800703 }
704 else
705 {
q.huang6e4f4732025-07-22 18:46:32 +0800706 LOGE(GSW_VOICE,"mbtk_call_answer success\n");
b.liu68a94c92025-05-24 12:53:41 +0800707 }
708 }
709
710 return GSW_HAL_SUCCESS;
711}
712
713int32_t gsw_voice_get_current_call_end_reason(CallHandle handle)
714{
q.huang50a0d852025-06-11 14:35:15 +0800715 VOICE_MODULE_INIT_CHECK();
q.huang5461cfd2025-06-24 19:04:34 +0800716
717 return gsw_global_end_reason;
b.liu68a94c92025-05-24 12:53:41 +0800718}
719
720
721
722/*##########################################rtp begin*/
723/**
724* @brief set audio mode
725* @param [in] AudioMode audioMode
726* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800727* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800728*/
729int32_t gsw_voice_set_audio_mode(AudioMode audioMode)
730{
q.huang50a0d852025-06-11 14:35:15 +0800731 VOICE_MODULE_INIT_CHECK();
b.liu68a94c92025-05-24 12:53:41 +0800732
733 int ret=mbtk_rtp_enable(audioMode);
734 if(ret !=0 )
735 {
xy.hecfb7d682025-05-28 21:39:12 +0800736 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800737 }
738 return GSW_HAL_SUCCESS;
739}
740
741/**
742* @brief set rtp ip address of remote
743* @param [in] char *ip :ip address
744* @param [in] int32_t len: length
745* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800746* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800747*/
748int32_t gsw_voice_set_remote_rtp_ip(const char *ip, int32_t len)
749{
q.huang50a0d852025-06-11 14:35:15 +0800750 VOICE_MODULE_INIT_CHECK();
b.liu68a94c92025-05-24 12:53:41 +0800751
752 int ret=mbtk_rtp_remote_ip_set(ip);
753 if(ret !=0 )
754 {
xy.hecfb7d682025-05-28 21:39:12 +0800755 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800756 }
757 return GSW_HAL_SUCCESS;
758}
759
760/**
761* @brief set rtp mode and port
762* @param [in] RTPMode rtpMode: rtp mode
763* @param [in] int32_t port:rtp port
764* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800765* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800766*/
767int32_t gsw_voice_set_rtp_port(RTPMode rtpMode, int32_t port)
768{
q.huang50a0d852025-06-11 14:35:15 +0800769 VOICE_MODULE_INIT_CHECK();
b.liu68a94c92025-05-24 12:53:41 +0800770
771 int ret;
772 if(rtpMode==GSW_RTP_CLIENT)
773 {
774 ret = mbtk_rtp_client_port_set(port);
775 }
776 else
777 {
778 ret = mbtk_rtp_server_port_set(port);
779 }
780 if(ret !=0 )
781 {
xy.hecfb7d682025-05-28 21:39:12 +0800782 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800783 }
784 return GSW_HAL_SUCCESS;
785}
786
787/**
788* @brief set rtp mode and port
789* @param [in] int32_t clockRate: clock rate
790* @param [in] int32_t channel:channel
791* @param [in] int32_t latency:latency
792* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800793* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800794*/
795int32_t gsw_voice_set_rtp_param(int32_t clockRate, int32_t channel, int32_t latency)
796{
q.huang50a0d852025-06-11 14:35:15 +0800797 VOICE_MODULE_INIT_CHECK();
b.liu68a94c92025-05-24 12:53:41 +0800798
799 int ret=mbtk_rtp_channel_set(channel);
800 if(ret==0)
801 {
802 ret=mbtk_rtp_sample_rate_set(clockRate);
803 }
804 if(ret !=0 )
805 {
xy.hecfb7d682025-05-28 21:39:12 +0800806 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800807 }
808 return GSW_HAL_SUCCESS;
809}
q.huang020cc232025-06-06 19:06:18 +0800810
811/**
812 * @brief set rtp vlan
813 * @param [in] interfaceName network interface name
814 * @retval 0: success
815 * @retval other: fail
816 */
817int32_t gsw_voice_set_rtp_vlan_info(const char *interfaceName)
818{
q.huang50a0d852025-06-11 14:35:15 +0800819 VOICE_MODULE_INIT_CHECK();
q.huang020cc232025-06-06 19:06:18 +0800820
821 int ret=mbtk_rtp_vlan_set(interfaceName);
822
823 if(ret !=0 )
824 {
825 return GSW_HAL_NORMAL_FAIL;
826 }
827 return GSW_HAL_SUCCESS;
828}
b.liu68a94c92025-05-24 12:53:41 +0800829/*##########################################rtp end*/
830