blob: 499ada1dc83c63fcdb36da053d8b405b26d3d293 [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.huang5461cfd2025-06-24 19:04:34 +0800141const char* g_normal_end_reason[] = {
142MBTK_VOICE_END_REASON_NORMAL_CALL_CLEARING,
143MBTK_VOICE_END_REASON_NORMAL_UNSPECIFIED,
b.liu68a94c92025-05-24 12:53:41 +0800144};
b.liu68a94c92025-05-24 12:53:41 +0800145int gsw_global_end_reason = GSW_OTHER_END_NORMAL;
146
147//----------------end_reason end------------
148
149
150typedef uint32_t voice_client_handle_type;
151
152
153
154static mbtk_info_handle_t* call_info_handle = NULL;
155static int level_call = 0;
156int gsw_voice_init_flag = 0;
157int auto_answer_flag = 0;
158voice_client_handle_type g_call_val = -1;
159CallStateInd gsw_voice_callback = NULL;
160
161
162int state_t = 0;
163char* phone_num_t = NULL;
164char* phone_num_t2 = NULL;
165int call_id_t = 0;
166int call_id_t2 = 0;
167
168#define lib_mbtk_path "/lib/libmbtk_lib.so"
169static void *dlHandle_mbtk;
170
171static mbtk_info_handle_t* (*mbtk_info_handle_get)(void);
172int (*mbtk_call_state_change_cb_reg)(mbtk_info_handle_t* handle, mbtk_info_callback_func cb);
173int (*mbtk_call_start)(mbtk_info_handle_t* handle, char* phone_number);
174int (*mbtk_call_hang)(mbtk_info_handle_t* handle);
175int (*mbtk_a_call_hang)(mbtk_info_handle_t* handle, int phone_id);
176int (*mbtk_call_answer)(mbtk_info_handle_t* handle);
177int (*mbtk_call_reg_get)(mbtk_info_handle_t* handle, mbtk_call_info_t *reg);
b.liu68a94c92025-05-24 12:53:41 +0800178
179/*rtp begin*/
180int (*mbtk_rtp_init)();
181int (*mbtk_rtp_deinit)();
182int (*mbtk_rtp_enable)(bool enable);
183int (*mbtk_rtp_remote_ip_set)(const char *ipv4);
184int (*mbtk_rtp_server_port_set)(int port);
185int (*mbtk_rtp_client_port_set)(int port);
186int (*mbtk_rtp_sample_rate_set)(int sample_rate);
187int (*mbtk_rtp_channel_set)(int channel);
q.huang020cc232025-06-06 19:06:18 +0800188int (*mbtk_rtp_vlan_set)(const char *vlan);
b.liu68a94c92025-05-24 12:53:41 +0800189/*rtp end*/
190
191
l.yang6a42e4d2025-05-28 01:04:20 -0700192#define GSW_VOICE "[HAL][GSW_VOICE]"
193
q.huang50a0d852025-06-11 14:35:15 +0800194#define MODULE_INIT_CHECK(init_flag) \
195 if(init_flag == 0) \
196 { \
197 return GSW_HAL_ERROR_GNSS_DATA_CALL_DEINIT; \
198 }
199
200#define VOICE_MODULE_INIT_CHECK() MODULE_INIT_CHECK(gsw_voice_init_flag)
201
202
b.liu68a94c92025-05-24 12:53:41 +0800203static int mbtk_rtp_api_import()
204{
205 mbtk_rtp_init = (int (*)(void))dlsym(dlHandle_mbtk, "mbtk_rtp_init");
206 if (mbtk_rtp_init == NULL)
207 {
q.huang6e4f4732025-07-22 18:46:32 +0800208 LOGE(GSW_VOICE,"mbtk_rtp_init dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800209 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800210 }
211
212 mbtk_rtp_deinit = (int (*)(void))dlsym(dlHandle_mbtk, "mbtk_rtp_deinit");
213 if (mbtk_rtp_deinit == NULL)
214 {
q.huang6e4f4732025-07-22 18:46:32 +0800215 LOGE(GSW_VOICE,"mbtk_rtp_deinit dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800216 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800217 }
218
219 mbtk_rtp_enable = (int (*)(bool enable))dlsym(dlHandle_mbtk, "mbtk_rtp_enable");
220 if (mbtk_rtp_enable == NULL)
221 {
q.huang6e4f4732025-07-22 18:46:32 +0800222 LOGE(GSW_VOICE,"mbtk_rtp_enable dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800223 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800224 }
225
226 mbtk_rtp_remote_ip_set = (int (*)(const char *ipv4))dlsym(dlHandle_mbtk, "mbtk_rtp_remote_ip_set");
227 if (mbtk_rtp_remote_ip_set == NULL)
228 {
q.huang6e4f4732025-07-22 18:46:32 +0800229 LOGE(GSW_VOICE,"mbtk_rtp_remote_ip_set dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800230 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800231 }
232
233 mbtk_rtp_server_port_set = (int (*)(int port))dlsym(dlHandle_mbtk, "mbtk_rtp_server_port_set");
234 if (mbtk_rtp_server_port_set == NULL)
235 {
q.huang6e4f4732025-07-22 18:46:32 +0800236 LOGE(GSW_VOICE,"mbtk_rtp_server_port_set dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800237 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800238 }
239
240 mbtk_rtp_client_port_set = (int (*)(int port))dlsym(dlHandle_mbtk, "mbtk_rtp_client_port_set");
241 if (mbtk_rtp_client_port_set == NULL)
242 {
q.huang6e4f4732025-07-22 18:46:32 +0800243 LOGE(GSW_VOICE,"mbtk_rtp_client_port_set dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800244 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800245 }
246
247 mbtk_rtp_sample_rate_set = (int (*)(int sample_rate))dlsym(dlHandle_mbtk, "mbtk_rtp_sample_rate_set");
248 if (mbtk_rtp_sample_rate_set == NULL)
249 {
q.huang6e4f4732025-07-22 18:46:32 +0800250 LOGE(GSW_VOICE,"mbtk_rtp_sample_rate_set dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800251 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800252 }
253
254 mbtk_rtp_channel_set = (int (*)(int channel))dlsym(dlHandle_mbtk, "mbtk_rtp_channel_set");
255 if (mbtk_rtp_channel_set == NULL)
256 {
q.huang6e4f4732025-07-22 18:46:32 +0800257 LOGE(GSW_VOICE,"mbtk_rtp_channel_set dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800258 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800259 }
q.huang020cc232025-06-06 19:06:18 +0800260
261 mbtk_rtp_vlan_set = (int (*)(const char *vlan))dlsym(dlHandle_mbtk, "mbtk_rtp_vlan_set");
262 if (mbtk_rtp_vlan_set == NULL)
263 {
q.huang6e4f4732025-07-22 18:46:32 +0800264 LOGE(GSW_VOICE,"mbtk_rtp_vlan_set dlsym fail\n");
q.huang020cc232025-06-06 19:06:18 +0800265 return GSW_HAL_NORMAL_FAIL;
266 }
b.liu68a94c92025-05-24 12:53:41 +0800267
268 return GSW_HAL_SUCCESS;
269}
270
271
272
273static int mbtk_call_api_import()
274{
275 dlHandle_mbtk = dlopen(lib_mbtk_path, RTLD_NOW);
276 if (dlHandle_mbtk == NULL)
277 {
xy.hecfb7d682025-05-28 21:39:12 +0800278 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800279 }
280
b.liu68a94c92025-05-24 12:53:41 +0800281 mbtk_info_handle_get = (mbtk_info_handle_t* (*)(void))dlsym(dlHandle_mbtk, "mbtk_info_handle_get");
282 if (mbtk_info_handle_get == NULL)
283 {
q.huang6e4f4732025-07-22 18:46:32 +0800284 LOGE(GSW_VOICE,"mbtk_info_handle_get dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800285 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800286 }
287
288 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");
289 if(mbtk_call_state_change_cb_reg == NULL)
290 {
q.huang6e4f4732025-07-22 18:46:32 +0800291 LOGE(GSW_VOICE,"mbtk_call_state_change_cb_reg dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800292 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800293 }
294
295 mbtk_call_start = (int (*)(mbtk_info_handle_t* handle, char* phone_number))dlsym(dlHandle_mbtk, "mbtk_call_start");
296 if(mbtk_call_start == NULL)
297 {
q.huang6e4f4732025-07-22 18:46:32 +0800298 LOGE(GSW_VOICE,"mbtk_call_start dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800299 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800300 }
301
302 mbtk_call_answer = (int (*)(mbtk_info_handle_t* handle))dlsym(dlHandle_mbtk, "mbtk_call_answer");
303 if(mbtk_call_answer == NULL)
304 {
q.huang6e4f4732025-07-22 18:46:32 +0800305 LOGE(GSW_VOICE,"mbtk_call_answer dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800306 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800307 }
308
309 mbtk_call_hang = (int (*)(mbtk_info_handle_t* handle))dlsym(dlHandle_mbtk, "mbtk_call_hang");
310 if(mbtk_call_hang == NULL)
311 {
q.huang6e4f4732025-07-22 18:46:32 +0800312 LOGE(GSW_VOICE,"mbtk_call_hang dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800313 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800314 }
315
316 mbtk_a_call_hang = (int (*)(mbtk_info_handle_t* handle, int phone_id))dlsym(dlHandle_mbtk, "mbtk_a_call_hang");
317 if(mbtk_a_call_hang == NULL)
318 {
q.huang6e4f4732025-07-22 18:46:32 +0800319 LOGE(GSW_VOICE,"mbtk_a_call_hang dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800320 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800321 }
322
323 mbtk_call_reg_get = (int (*)(mbtk_info_handle_t* handle, mbtk_call_info_t *reg))dlsym(dlHandle_mbtk, "mbtk_call_reg_get");
324 if(mbtk_call_reg_get == NULL)
325 {
q.huang6e4f4732025-07-22 18:46:32 +0800326 LOGE(GSW_VOICE,"mbtk_call_reg_get dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800327 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800328 }
329
330 return mbtk_rtp_api_import();
331}
332
q.huang5461cfd2025-06-24 19:04:34 +0800333static void end_reason_mbtk_to_gsw(char* mbtk_reason)
b.liu68a94c92025-05-24 12:53:41 +0800334{
q.huang6e4f4732025-07-22 18:46:32 +0800335 LOGE(GSW_VOICE,"mbtk_reason:%s\n", mbtk_reason);
q.huang5461cfd2025-06-24 19:04:34 +0800336 gsw_global_end_reason = GSW_END_ABNORMAL;
337 int length=sizeof (g_normal_end_reason)/ sizeof(g_normal_end_reason[0]);
338 for(int i = 0; i<length; i++)
b.liu68a94c92025-05-24 12:53:41 +0800339 {
q.huang5461cfd2025-06-24 19:04:34 +0800340 if(0 == strncmp(mbtk_reason, g_normal_end_reason[i], strlen(g_normal_end_reason[i])))
b.liu68a94c92025-05-24 12:53:41 +0800341 {
q.huang5461cfd2025-06-24 19:04:34 +0800342 gsw_global_end_reason=GSW_OTHER_END_NORMAL;
343 return;
b.liu68a94c92025-05-24 12:53:41 +0800344 }
345 }
346
q.huang5461cfd2025-06-24 19:04:34 +0800347 return;
b.liu68a94c92025-05-24 12:53:41 +0800348}
349
350void gsw_call_state_change_cb(const void *data, int data_len)
351{
352 mbtk_call_info_t *reg = (mbtk_call_info_t *)data;
353 switch (reg->call_wait)
354 {
355 case MBTK_CLCC:
356 {
q.huang6e4f4732025-07-22 18:46:32 +0800357 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);
358 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 +0800359 switch(reg->state)
360 {
361 case 0:
362 state_t = GSW_VOICE_CALL_CONNECTED;
363 break;
364 case 1:
365 state_t = GSW_VOICE_CALL_HOLDING;
366 break;
367 case 2:
368 state_t = GSW_VOICE_CALL_DIALING;
369 break;
370 case 3:
371 state_t = GSW_VOICE_CALL_ALERTING;
372 break;
373 case 4:
374 state_t = GSW_VOICE_CALL_INCOMING;
375 break;
376 case 5:
377 state_t = GSW_VOICE_CALL_WAITING;
378 break;
379 case 6:
380 {
381 state_t = GSW_VOICE_CALL_END;
382 call_id_t = reg->dir1;
383 end_reason_mbtk_to_gsw((char *)reg->end_reason);
384 break;
385 }
386
387 }
388
389 if(gsw_voice_callback)
390 {
391 gsw_voice_callback(reg->dir1, state_t);
392 }
393
394 }
q.huang5461cfd2025-06-24 19:04:34 +0800395 break;
b.liu68a94c92025-05-24 12:53:41 +0800396 case MBTK_DISCONNECTED:
397 {
q.huang6e4f4732025-07-22 18:46:32 +0800398 LOGD(GSW_VOICE,"RING : call dis connected!");
399 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);
400 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 +0800401 state_t = GSW_VOICE_CALL_END;
b.liu68a94c92025-05-24 12:53:41 +0800402 call_id_t = reg->dir1;
403 end_reason_mbtk_to_gsw((char *)reg->end_reason);
q.huang5461cfd2025-06-24 19:04:34 +0800404 if(gsw_voice_callback)
b.liu68a94c92025-05-24 12:53:41 +0800405 {
406 gsw_voice_callback(reg->disconnected_id, state_t);
407 }
408 }
q.huang5461cfd2025-06-24 19:04:34 +0800409 break;
b.liu68a94c92025-05-24 12:53:41 +0800410 case MBTK_CPAS:
q.huang6e4f4732025-07-22 18:46:32 +0800411 LOGD(GSW_VOICE,"CALL : Call state = %d", reg->pas);
q.huang5461cfd2025-06-24 19:04:34 +0800412 switch (reg->pas)
413 {
b.liu68a94c92025-05-24 12:53:41 +0800414 case MBTK_CALL_RADY:
q.huang6e4f4732025-07-22 18:46:32 +0800415 LOGD(GSW_VOICE,"CALL: call READY");
b.liu68a94c92025-05-24 12:53:41 +0800416 break;
417 case MBTK_CALL_UNAVAILABLE:
q.huang6e4f4732025-07-22 18:46:32 +0800418 LOGD(GSW_VOICE,"CALL: call unavaliable");
b.liu68a94c92025-05-24 12:53:41 +0800419 break;
420 case MBTK_CALL_UNKNOWN:
q.huang6e4f4732025-07-22 18:46:32 +0800421 LOGD(GSW_VOICE,"CALL: call unknown");
b.liu68a94c92025-05-24 12:53:41 +0800422 break;
423 case MBTK_CALL_RINGING:
q.huang6e4f4732025-07-22 18:46:32 +0800424 LOGD(GSW_VOICE,"CALL: call ringing");
b.liu68a94c92025-05-24 12:53:41 +0800425 break;
426 case MBTK_CALL_PROGRESS:
q.huang6e4f4732025-07-22 18:46:32 +0800427 LOGD(GSW_VOICE,"CALL: call progress");
b.liu68a94c92025-05-24 12:53:41 +0800428 break;
429 case MBTK_CALL_ASLEEP:
q.huang6e4f4732025-07-22 18:46:32 +0800430 LOGD(GSW_VOICE,"CALL: call asleep");
b.liu68a94c92025-05-24 12:53:41 +0800431 break;
432 case MBTK_CALL_ACTIVE:
q.huang6e4f4732025-07-22 18:46:32 +0800433 LOGD(GSW_VOICE,"CALL: call active");
b.liu68a94c92025-05-24 12:53:41 +0800434 break;
435 default:
q.huang6e4f4732025-07-22 18:46:32 +0800436 //LOGE(GSW_VOICE,"\r\n");
b.liu68a94c92025-05-24 12:53:41 +0800437 break;
q.huang5461cfd2025-06-24 19:04:34 +0800438 }
b.liu68a94c92025-05-24 12:53:41 +0800439 break;
440 default:
q.huang6e4f4732025-07-22 18:46:32 +0800441 LOGE(GSW_VOICE,"RING : None call_wait = %d", reg->call_wait);
b.liu68a94c92025-05-24 12:53:41 +0800442 break;
443 }
444}
445
446
447/**
448* @brief init voice sdk,and register the status indicated callback function
449* @param [in] CallStateInd ind: status indicated callback function
450* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800451* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800452*/
453int32_t gsw_voice_sdk_init(CallStateInd ind)
454{
455 int ret;
456
457 if (gsw_voice_init_flag == 1 && call_info_handle != NULL)
458 {
459 return GSW_HAL_SUCCESS;
460 }
461
462 if(ind == NULL)
463 {
q.huang6e4f4732025-07-22 18:46:32 +0800464 LOGE(GSW_VOICE,"parameter is null\n");
xy.hecfb7d682025-05-28 21:39:12 +0800465 return GSW_HAL_ARG_INVALID;
b.liu68a94c92025-05-24 12:53:41 +0800466 }
467
468 ret = mbtk_call_api_import();
469 if(ret != 0)
470 {
q.huang6e4f4732025-07-22 18:46:32 +0800471 LOGE(GSW_VOICE,"[gsw_voice_sdk_init]mbtk_call_api_import fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800472 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800473 }
474
b.liu68a94c92025-05-24 12:53:41 +0800475 if(ret < 0)
476 {
q.huang6e4f4732025-07-22 18:46:32 +0800477 LOGE(GSW_VOICE,"mbtk_call_api_import fail,ret = %d\n",ret);
xy.hecfb7d682025-05-28 21:39:12 +0800478 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800479 }
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