blob: c95251b872170d8a5242e35cdcc11ee704e770c3 [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
q.huang5f210842025-09-01 19:53:43 +0800146end_reason_map_t g_end_reason_map[6] = {
q.huangd934b6d2025-07-29 20:17:00 +0800147{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},
q.huang5f210842025-09-01 19:53:43 +0800151{MBTK_VOICE_END_REASON_USER_BUSY, GSW_PEER_END_NORMAL},
152{MBTK_VOICE_END_REASON_NO_USER_RESPONDING, GSW_PEER_END_NORMAL},
b.liu68a94c92025-05-24 12:53:41 +0800153};
q.huangd934b6d2025-07-29 20:17:00 +0800154
b.liu68a94c92025-05-24 12:53:41 +0800155int gsw_global_end_reason = GSW_OTHER_END_NORMAL;
156
157//----------------end_reason end------------
158
159
160typedef uint32_t voice_client_handle_type;
161
b.liu68a94c92025-05-24 12:53:41 +0800162static mbtk_info_handle_t* call_info_handle = NULL;
163static int level_call = 0;
164int gsw_voice_init_flag = 0;
165int auto_answer_flag = 0;
166voice_client_handle_type g_call_val = -1;
167CallStateInd gsw_voice_callback = NULL;
168
169
170int state_t = 0;
171char* phone_num_t = NULL;
172char* phone_num_t2 = NULL;
173int call_id_t = 0;
174int call_id_t2 = 0;
175
176#define lib_mbtk_path "/lib/libmbtk_lib.so"
177static void *dlHandle_mbtk;
178
179static mbtk_info_handle_t* (*mbtk_info_handle_get)(void);
180int (*mbtk_call_state_change_cb_reg)(mbtk_info_handle_t* handle, mbtk_info_callback_func cb);
181int (*mbtk_call_start)(mbtk_info_handle_t* handle, char* phone_number);
182int (*mbtk_call_hang)(mbtk_info_handle_t* handle);
183int (*mbtk_a_call_hang)(mbtk_info_handle_t* handle, int phone_id);
184int (*mbtk_call_answer)(mbtk_info_handle_t* handle);
185int (*mbtk_call_reg_get)(mbtk_info_handle_t* handle, mbtk_call_info_t *reg);
b.liu68a94c92025-05-24 12:53:41 +0800186
187/*rtp begin*/
188int (*mbtk_rtp_init)();
189int (*mbtk_rtp_deinit)();
190int (*mbtk_rtp_enable)(bool enable);
191int (*mbtk_rtp_remote_ip_set)(const char *ipv4);
192int (*mbtk_rtp_server_port_set)(int port);
193int (*mbtk_rtp_client_port_set)(int port);
194int (*mbtk_rtp_sample_rate_set)(int sample_rate);
195int (*mbtk_rtp_channel_set)(int channel);
q.huang020cc232025-06-06 19:06:18 +0800196int (*mbtk_rtp_vlan_set)(const char *vlan);
b.liu68a94c92025-05-24 12:53:41 +0800197/*rtp end*/
198
199
l.yang6a42e4d2025-05-28 01:04:20 -0700200#define GSW_VOICE "[HAL][GSW_VOICE]"
201
q.huang50a0d852025-06-11 14:35:15 +0800202#define MODULE_INIT_CHECK(init_flag) \
203 if(init_flag == 0) \
204 { \
205 return GSW_HAL_ERROR_GNSS_DATA_CALL_DEINIT; \
206 }
207
208#define VOICE_MODULE_INIT_CHECK() MODULE_INIT_CHECK(gsw_voice_init_flag)
209
210
b.liu68a94c92025-05-24 12:53:41 +0800211static int mbtk_rtp_api_import()
212{
213 mbtk_rtp_init = (int (*)(void))dlsym(dlHandle_mbtk, "mbtk_rtp_init");
214 if (mbtk_rtp_init == NULL)
215 {
q.huang6e4f4732025-07-22 18:46:32 +0800216 LOGE(GSW_VOICE,"mbtk_rtp_init dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800217 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800218 }
219
220 mbtk_rtp_deinit = (int (*)(void))dlsym(dlHandle_mbtk, "mbtk_rtp_deinit");
221 if (mbtk_rtp_deinit == NULL)
222 {
q.huang6e4f4732025-07-22 18:46:32 +0800223 LOGE(GSW_VOICE,"mbtk_rtp_deinit dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800224 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800225 }
226
227 mbtk_rtp_enable = (int (*)(bool enable))dlsym(dlHandle_mbtk, "mbtk_rtp_enable");
228 if (mbtk_rtp_enable == NULL)
229 {
q.huang6e4f4732025-07-22 18:46:32 +0800230 LOGE(GSW_VOICE,"mbtk_rtp_enable dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800231 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800232 }
233
234 mbtk_rtp_remote_ip_set = (int (*)(const char *ipv4))dlsym(dlHandle_mbtk, "mbtk_rtp_remote_ip_set");
235 if (mbtk_rtp_remote_ip_set == NULL)
236 {
q.huang6e4f4732025-07-22 18:46:32 +0800237 LOGE(GSW_VOICE,"mbtk_rtp_remote_ip_set dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800238 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800239 }
240
241 mbtk_rtp_server_port_set = (int (*)(int port))dlsym(dlHandle_mbtk, "mbtk_rtp_server_port_set");
242 if (mbtk_rtp_server_port_set == NULL)
243 {
q.huang6e4f4732025-07-22 18:46:32 +0800244 LOGE(GSW_VOICE,"mbtk_rtp_server_port_set dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800245 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800246 }
247
248 mbtk_rtp_client_port_set = (int (*)(int port))dlsym(dlHandle_mbtk, "mbtk_rtp_client_port_set");
249 if (mbtk_rtp_client_port_set == NULL)
250 {
q.huang6e4f4732025-07-22 18:46:32 +0800251 LOGE(GSW_VOICE,"mbtk_rtp_client_port_set dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800252 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800253 }
254
255 mbtk_rtp_sample_rate_set = (int (*)(int sample_rate))dlsym(dlHandle_mbtk, "mbtk_rtp_sample_rate_set");
256 if (mbtk_rtp_sample_rate_set == NULL)
257 {
q.huang6e4f4732025-07-22 18:46:32 +0800258 LOGE(GSW_VOICE,"mbtk_rtp_sample_rate_set dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800259 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800260 }
261
262 mbtk_rtp_channel_set = (int (*)(int channel))dlsym(dlHandle_mbtk, "mbtk_rtp_channel_set");
263 if (mbtk_rtp_channel_set == NULL)
264 {
q.huang6e4f4732025-07-22 18:46:32 +0800265 LOGE(GSW_VOICE,"mbtk_rtp_channel_set dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800266 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800267 }
q.huang020cc232025-06-06 19:06:18 +0800268
269 mbtk_rtp_vlan_set = (int (*)(const char *vlan))dlsym(dlHandle_mbtk, "mbtk_rtp_vlan_set");
270 if (mbtk_rtp_vlan_set == NULL)
271 {
q.huang6e4f4732025-07-22 18:46:32 +0800272 LOGE(GSW_VOICE,"mbtk_rtp_vlan_set dlsym fail\n");
q.huang020cc232025-06-06 19:06:18 +0800273 return GSW_HAL_NORMAL_FAIL;
274 }
b.liu68a94c92025-05-24 12:53:41 +0800275
276 return GSW_HAL_SUCCESS;
277}
278
279
280
281static int mbtk_call_api_import()
282{
283 dlHandle_mbtk = dlopen(lib_mbtk_path, RTLD_NOW);
284 if (dlHandle_mbtk == NULL)
285 {
xy.hecfb7d682025-05-28 21:39:12 +0800286 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800287 }
288
b.liu68a94c92025-05-24 12:53:41 +0800289 mbtk_info_handle_get = (mbtk_info_handle_t* (*)(void))dlsym(dlHandle_mbtk, "mbtk_info_handle_get");
290 if (mbtk_info_handle_get == NULL)
291 {
q.huang6e4f4732025-07-22 18:46:32 +0800292 LOGE(GSW_VOICE,"mbtk_info_handle_get dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800293 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800294 }
295
296 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");
297 if(mbtk_call_state_change_cb_reg == NULL)
298 {
q.huang6e4f4732025-07-22 18:46:32 +0800299 LOGE(GSW_VOICE,"mbtk_call_state_change_cb_reg dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800300 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800301 }
302
303 mbtk_call_start = (int (*)(mbtk_info_handle_t* handle, char* phone_number))dlsym(dlHandle_mbtk, "mbtk_call_start");
304 if(mbtk_call_start == NULL)
305 {
q.huang6e4f4732025-07-22 18:46:32 +0800306 LOGE(GSW_VOICE,"mbtk_call_start dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800307 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800308 }
309
310 mbtk_call_answer = (int (*)(mbtk_info_handle_t* handle))dlsym(dlHandle_mbtk, "mbtk_call_answer");
311 if(mbtk_call_answer == NULL)
312 {
q.huang6e4f4732025-07-22 18:46:32 +0800313 LOGE(GSW_VOICE,"mbtk_call_answer dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800314 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800315 }
316
317 mbtk_call_hang = (int (*)(mbtk_info_handle_t* handle))dlsym(dlHandle_mbtk, "mbtk_call_hang");
318 if(mbtk_call_hang == NULL)
319 {
q.huang6e4f4732025-07-22 18:46:32 +0800320 LOGE(GSW_VOICE,"mbtk_call_hang dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800321 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800322 }
323
324 mbtk_a_call_hang = (int (*)(mbtk_info_handle_t* handle, int phone_id))dlsym(dlHandle_mbtk, "mbtk_a_call_hang");
325 if(mbtk_a_call_hang == NULL)
326 {
q.huang6e4f4732025-07-22 18:46:32 +0800327 LOGE(GSW_VOICE,"mbtk_a_call_hang dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800328 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800329 }
330
331 mbtk_call_reg_get = (int (*)(mbtk_info_handle_t* handle, mbtk_call_info_t *reg))dlsym(dlHandle_mbtk, "mbtk_call_reg_get");
332 if(mbtk_call_reg_get == NULL)
333 {
q.huang6e4f4732025-07-22 18:46:32 +0800334 LOGE(GSW_VOICE,"mbtk_call_reg_get dlsym fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800335 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800336 }
337
338 return mbtk_rtp_api_import();
339}
340
q.huang5461cfd2025-06-24 19:04:34 +0800341static void end_reason_mbtk_to_gsw(char* mbtk_reason)
b.liu68a94c92025-05-24 12:53:41 +0800342{
q.huang6e4f4732025-07-22 18:46:32 +0800343 LOGE(GSW_VOICE,"mbtk_reason:%s\n", mbtk_reason);
q.huang5461cfd2025-06-24 19:04:34 +0800344 gsw_global_end_reason = GSW_END_ABNORMAL;
q.huangd934b6d2025-07-29 20:17:00 +0800345
346 int length=sizeof (g_end_reason_map)/ sizeof(g_end_reason_map[0]);
q.huang5461cfd2025-06-24 19:04:34 +0800347 for(int i = 0; i<length; i++)
b.liu68a94c92025-05-24 12:53:41 +0800348 {
q.huangd934b6d2025-07-29 20:17:00 +0800349 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 +0800350 {
q.huangd934b6d2025-07-29 20:17:00 +0800351 gsw_global_end_reason = g_end_reason_map[i].end_reason;
352 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 +0800353 return;
b.liu68a94c92025-05-24 12:53:41 +0800354 }
355 }
b.liu68a94c92025-05-24 12:53:41 +0800356}
357
358void gsw_call_state_change_cb(const void *data, int data_len)
359{
360 mbtk_call_info_t *reg = (mbtk_call_info_t *)data;
361 switch (reg->call_wait)
362 {
363 case MBTK_CLCC:
364 {
q.huang6e4f4732025-07-22 18:46:32 +0800365 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);
366 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 +0800367 switch(reg->state)
368 {
369 case 0:
370 state_t = GSW_VOICE_CALL_CONNECTED;
371 break;
372 case 1:
373 state_t = GSW_VOICE_CALL_HOLDING;
374 break;
375 case 2:
376 state_t = GSW_VOICE_CALL_DIALING;
377 break;
378 case 3:
379 state_t = GSW_VOICE_CALL_ALERTING;
380 break;
381 case 4:
382 state_t = GSW_VOICE_CALL_INCOMING;
383 break;
384 case 5:
385 state_t = GSW_VOICE_CALL_WAITING;
386 break;
387 case 6:
388 {
389 state_t = GSW_VOICE_CALL_END;
390 call_id_t = reg->dir1;
391 end_reason_mbtk_to_gsw((char *)reg->end_reason);
392 break;
393 }
394
395 }
396
397 if(gsw_voice_callback)
398 {
399 gsw_voice_callback(reg->dir1, state_t);
400 }
401
402 }
q.huang5461cfd2025-06-24 19:04:34 +0800403 break;
b.liu68a94c92025-05-24 12:53:41 +0800404 case MBTK_DISCONNECTED:
405 {
q.huang6e4f4732025-07-22 18:46:32 +0800406 LOGD(GSW_VOICE,"RING : call dis connected!");
407 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);
408 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 +0800409 state_t = GSW_VOICE_CALL_END;
b.liu68a94c92025-05-24 12:53:41 +0800410 call_id_t = reg->dir1;
411 end_reason_mbtk_to_gsw((char *)reg->end_reason);
q.huang5461cfd2025-06-24 19:04:34 +0800412 if(gsw_voice_callback)
b.liu68a94c92025-05-24 12:53:41 +0800413 {
414 gsw_voice_callback(reg->disconnected_id, state_t);
415 }
416 }
q.huang5461cfd2025-06-24 19:04:34 +0800417 break;
b.liu68a94c92025-05-24 12:53:41 +0800418 case MBTK_CPAS:
q.huang6e4f4732025-07-22 18:46:32 +0800419 LOGD(GSW_VOICE,"CALL : Call state = %d", reg->pas);
q.huang5461cfd2025-06-24 19:04:34 +0800420 switch (reg->pas)
421 {
b.liu68a94c92025-05-24 12:53:41 +0800422 case MBTK_CALL_RADY:
q.huang6e4f4732025-07-22 18:46:32 +0800423 LOGD(GSW_VOICE,"CALL: call READY");
b.liu68a94c92025-05-24 12:53:41 +0800424 break;
425 case MBTK_CALL_UNAVAILABLE:
q.huang6e4f4732025-07-22 18:46:32 +0800426 LOGD(GSW_VOICE,"CALL: call unavaliable");
b.liu68a94c92025-05-24 12:53:41 +0800427 break;
428 case MBTK_CALL_UNKNOWN:
q.huang6e4f4732025-07-22 18:46:32 +0800429 LOGD(GSW_VOICE,"CALL: call unknown");
b.liu68a94c92025-05-24 12:53:41 +0800430 break;
431 case MBTK_CALL_RINGING:
q.huang6e4f4732025-07-22 18:46:32 +0800432 LOGD(GSW_VOICE,"CALL: call ringing");
b.liu68a94c92025-05-24 12:53:41 +0800433 break;
434 case MBTK_CALL_PROGRESS:
q.huang6e4f4732025-07-22 18:46:32 +0800435 LOGD(GSW_VOICE,"CALL: call progress");
b.liu68a94c92025-05-24 12:53:41 +0800436 break;
437 case MBTK_CALL_ASLEEP:
q.huang6e4f4732025-07-22 18:46:32 +0800438 LOGD(GSW_VOICE,"CALL: call asleep");
b.liu68a94c92025-05-24 12:53:41 +0800439 break;
440 case MBTK_CALL_ACTIVE:
q.huang6e4f4732025-07-22 18:46:32 +0800441 LOGD(GSW_VOICE,"CALL: call active");
b.liu68a94c92025-05-24 12:53:41 +0800442 break;
443 default:
q.huang6e4f4732025-07-22 18:46:32 +0800444 //LOGE(GSW_VOICE,"\r\n");
b.liu68a94c92025-05-24 12:53:41 +0800445 break;
q.huang5461cfd2025-06-24 19:04:34 +0800446 }
b.liu68a94c92025-05-24 12:53:41 +0800447 break;
448 default:
q.huang6e4f4732025-07-22 18:46:32 +0800449 LOGE(GSW_VOICE,"RING : None call_wait = %d", reg->call_wait);
b.liu68a94c92025-05-24 12:53:41 +0800450 break;
451 }
452}
453
b.liu68a94c92025-05-24 12:53:41 +0800454/**
455* @brief init voice sdk,and register the status indicated callback function
456* @param [in] CallStateInd ind: status indicated callback function
457* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800458* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800459*/
460int32_t gsw_voice_sdk_init(CallStateInd ind)
461{
b.liu68a94c92025-05-24 12:53:41 +0800462 if (gsw_voice_init_flag == 1 && call_info_handle != NULL)
463 {
464 return GSW_HAL_SUCCESS;
465 }
466
467 if(ind == NULL)
468 {
q.huang6e4f4732025-07-22 18:46:32 +0800469 LOGE(GSW_VOICE,"parameter is null\n");
xy.hecfb7d682025-05-28 21:39:12 +0800470 return GSW_HAL_ARG_INVALID;
b.liu68a94c92025-05-24 12:53:41 +0800471 }
472
q.huangd934b6d2025-07-29 20:17:00 +0800473 int ret = mbtk_call_api_import();
b.liu68a94c92025-05-24 12:53:41 +0800474 if(ret != 0)
475 {
q.huang6e4f4732025-07-22 18:46:32 +0800476 LOGE(GSW_VOICE,"[gsw_voice_sdk_init]mbtk_call_api_import fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800477 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800478 }
479
q.huangd934b6d2025-07-29 20:17:00 +0800480
481
b.liu68a94c92025-05-24 12:53:41 +0800482 if(call_info_handle == NULL)
483 {
484 call_info_handle = mbtk_info_handle_get();
485 if(call_info_handle != NULL)
486 {
q.huang6e4f4732025-07-22 18:46:32 +0800487 LOGE(GSW_VOICE,"create gsw_voice_sdk_init success\n");
b.liu68a94c92025-05-24 12:53:41 +0800488
489 ret = mbtk_call_state_change_cb_reg(call_info_handle, gsw_call_state_change_cb);
490 if(ret)
491 {
q.huang6e4f4732025-07-22 18:46:32 +0800492 LOGE(GSW_VOICE,"mbtk_call_state_change_cb_reg fail,ret = %d\n",ret);
xy.hecfb7d682025-05-28 21:39:12 +0800493 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800494 }
495 else
496 {
497 gsw_voice_init_flag = 1;
498 gsw_voice_callback = ind;
q.huang6e4f4732025-07-22 18:46:32 +0800499 LOGE(GSW_VOICE,"create gsw_voice_sdk_init success\n");
b.liu68a94c92025-05-24 12:53:41 +0800500 return GSW_HAL_SUCCESS;
501 }
502
503 }
504
505 else
506 {
q.huang6e4f4732025-07-22 18:46:32 +0800507 LOGE(GSW_VOICE,"create gsw_voice_sdk_init fail\n");
xy.hecfb7d682025-05-28 21:39:12 +0800508 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800509 }
510 }
511
512 return GSW_HAL_SUCCESS;
513}
514
515/**
516* @brief set speaker_volume
517* @param [in] int32_t volume:1(Min)-7(Max)
518* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800519* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800520*/
521int32_t gsw_voice_set_speaker_volume(int32_t volume)
522{
523 //UNUSED(volume);
524
q.huang50a0d852025-06-11 14:35:15 +0800525 VOICE_MODULE_INIT_CHECK();
b.liu68a94c92025-05-24 12:53:41 +0800526
527 char cmd[128] = {0};
528 int lv = 0;
529
530 memset(cmd ,0x00, sizeof(cmd));
531
532 if(volume < 1 || volume > 7)
533 {
q.huang6e4f4732025-07-22 18:46:32 +0800534 LOGE(GSW_VOICE,"Error volume : %d", volume);
xy.hecfb7d682025-05-28 21:39:12 +0800535 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800536 }
537 else
538 {
539 switch(volume)
540 {
541 case 1 :
542 lv = -36;
543 break;
544 case 2 :
545 lv = -36;
546 break;
547 case 3 :
548 lv = -27;
549 break;
550 case 4 :
551 lv = -18;
552 break;
553 case 5 :
554 lv = -9;
555 break;
556 case 6 :
557 lv = 0;
558 break;
559 case 7:
560 lv = 12;
561 break;
562 default:
563 break;
564 }
565 }
566
567 sprintf(cmd, "ubus call audio_if config_dspgain \"{\'type\':%d,\'gain\':%d}\"", 1, lv);
568// sLOGE(cmd, "ubus call audio_if volume_set \'{\"param0\":%d}\'", lv);
569 int err = system(cmd);
570 if ((err != -1) && (err != 127))
571 {
q.huang6e4f4732025-07-22 18:46:32 +0800572 LOGE(GSW_VOICE,"Set success.");
b.liu68a94c92025-05-24 12:53:41 +0800573 level_call = volume;
574 }
575 else
576 {
q.huang6e4f4732025-07-22 18:46:32 +0800577 LOGE(GSW_VOICE,"Error : %d", err);
xy.hecfb7d682025-05-28 21:39:12 +0800578 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800579 }
580
581 return GSW_HAL_SUCCESS;
582}
583
584/**
585* @brief start a voice call
586* @param [in] char *callNumber
587* @param [out] CallHandle *handle
xy.hecfb7d682025-05-28 21:39:12 +0800588* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800589*/
590int32_t gsw_voice_normal_voice_start(CallHandle *handle, const char *callNumber)
591{
q.huang50a0d852025-06-11 14:35:15 +0800592 VOICE_MODULE_INIT_CHECK();
b.liu68a94c92025-05-24 12:53:41 +0800593
594 mbtk_call_info_t reg = {0};
595 int ret = -1;
596
597
598 if(handle == NULL)
599 {
q.huang6e4f4732025-07-22 18:46:32 +0800600 LOGE(GSW_VOICE,"handle is null\n");
xy.hecfb7d682025-05-28 21:39:12 +0800601 return GSW_HAL_ARG_INVALID;
b.liu68a94c92025-05-24 12:53:41 +0800602 }
603
604 if(callNumber == NULL)
605 {
q.huang6e4f4732025-07-22 18:46:32 +0800606 LOGE(GSW_VOICE,"callNumber is null\n");
xy.hecfb7d682025-05-28 21:39:12 +0800607 return GSW_HAL_ARG_INVALID;
b.liu68a94c92025-05-24 12:53:41 +0800608 }
609
610
611 ret = mbtk_call_start(call_info_handle, (char *)callNumber);
612
613 if(ret != 0)
614 {
q.huang6e4f4732025-07-22 18:46:32 +0800615 LOGE(GSW_VOICE,"mbtk_call_start fail,ret = %d\n",ret);
xy.hecfb7d682025-05-28 21:39:12 +0800616 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800617 }
618
619 //get call id
620 mbtk_call_reg_get(call_info_handle, &reg);
q.huang6e4f4732025-07-22 18:46:32 +0800621 LOGE(GSW_VOICE,"call id = %d\n",reg.dir1);
b.liu68a94c92025-05-24 12:53:41 +0800622 *handle = reg.dir1;
q.huang6e4f4732025-07-22 18:46:32 +0800623 LOGE(GSW_VOICE,"gsw_voice_normal_voice_start id = %d\n", (int)*handle);
b.liu68a94c92025-05-24 12:53:41 +0800624
625
626 return GSW_HAL_SUCCESS;
627
628}
629
630/**
631* @brief answer a voice call
632* @param [in] CallHandle handle
633* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800634* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800635*/
636int32_t gsw_voice_answer(CallHandle handle)
637{
q.huang50a0d852025-06-11 14:35:15 +0800638 VOICE_MODULE_INIT_CHECK();
b.liu68a94c92025-05-24 12:53:41 +0800639
640 int ret = -1;
641
642
643 ret = mbtk_call_answer(call_info_handle);
644
645 if(ret != 0)
646 {
q.huang6e4f4732025-07-22 18:46:32 +0800647 LOGE(GSW_VOICE,"mbtk_call_answer fail,ret = %d\n", ret);
xy.hecfb7d682025-05-28 21:39:12 +0800648 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800649 }
650 else
651 {
q.huang6e4f4732025-07-22 18:46:32 +0800652 LOGE(GSW_VOICE,"mbtk_call_answer success\n");
b.liu68a94c92025-05-24 12:53:41 +0800653 }
654
655 return GSW_HAL_SUCCESS;
656}
657
658
659/**
660* @brief hangup a voice call
661* @param [in] CallHandle handle
662* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800663* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800664*/
665int32_t gsw_voice_hangup(CallHandle handle)
666{
q.huang50a0d852025-06-11 14:35:15 +0800667 VOICE_MODULE_INIT_CHECK();
b.liu68a94c92025-05-24 12:53:41 +0800668
669 int ret = -1;
670
671 ret = mbtk_a_call_hang(call_info_handle,handle);
672
673 if(ret != 0)
674 {
q.huang6e4f4732025-07-22 18:46:32 +0800675 LOGE(GSW_VOICE,"mbtk_a_call_hang fail,ret = %d\n", ret);
xy.hecfb7d682025-05-28 21:39:12 +0800676 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800677 }
678 else
679 {
q.huang6e4f4732025-07-22 18:46:32 +0800680 LOGE(GSW_VOICE,"mbtk_a_call_hang success\n");
b.liu68a94c92025-05-24 12:53:41 +0800681 }
682
683 return GSW_HAL_SUCCESS;
684}
685
686/**
687* @brief set auto answer mode
688* @param [in] int32_t mode:0-1, 0:NO(close auto answer), 1:YES(auto answer)
689* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800690* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800691*/
692int32_t gsw_voice_set_auto_answer_mode(int32_t mode)
693{
q.huang50a0d852025-06-11 14:35:15 +0800694 VOICE_MODULE_INIT_CHECK();
695
b.liu68a94c92025-05-24 12:53:41 +0800696 if(mode == 1)
697 {
698 int ret = -1;
699
700 ret = mbtk_call_answer(call_info_handle);
701 if(ret != 0)
702 {
q.huang6e4f4732025-07-22 18:46:32 +0800703 LOGE(GSW_VOICE,"mbtk_call_answer fail,ret = %d\n", ret);
xy.hecfb7d682025-05-28 21:39:12 +0800704 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800705 }
706 else
707 {
q.huang6e4f4732025-07-22 18:46:32 +0800708 LOGE(GSW_VOICE,"mbtk_call_answer success\n");
b.liu68a94c92025-05-24 12:53:41 +0800709 }
710 }
711
712 return GSW_HAL_SUCCESS;
713}
714
715int32_t gsw_voice_get_current_call_end_reason(CallHandle handle)
716{
q.huang50a0d852025-06-11 14:35:15 +0800717 VOICE_MODULE_INIT_CHECK();
q.huang5461cfd2025-06-24 19:04:34 +0800718
719 return gsw_global_end_reason;
b.liu68a94c92025-05-24 12:53:41 +0800720}
721
722
723
724/*##########################################rtp begin*/
725/**
726* @brief set audio mode
727* @param [in] AudioMode audioMode
728* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800729* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800730*/
731int32_t gsw_voice_set_audio_mode(AudioMode audioMode)
732{
q.huang50a0d852025-06-11 14:35:15 +0800733 VOICE_MODULE_INIT_CHECK();
b.liu68a94c92025-05-24 12:53:41 +0800734
735 int ret=mbtk_rtp_enable(audioMode);
736 if(ret !=0 )
737 {
xy.hecfb7d682025-05-28 21:39:12 +0800738 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800739 }
740 return GSW_HAL_SUCCESS;
741}
742
743/**
744* @brief set rtp ip address of remote
745* @param [in] char *ip :ip address
746* @param [in] int32_t len: length
747* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800748* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800749*/
750int32_t gsw_voice_set_remote_rtp_ip(const char *ip, int32_t len)
751{
q.huang50a0d852025-06-11 14:35:15 +0800752 VOICE_MODULE_INIT_CHECK();
b.liu68a94c92025-05-24 12:53:41 +0800753
754 int ret=mbtk_rtp_remote_ip_set(ip);
755 if(ret !=0 )
756 {
xy.hecfb7d682025-05-28 21:39:12 +0800757 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800758 }
759 return GSW_HAL_SUCCESS;
760}
761
762/**
763* @brief set rtp mode and port
764* @param [in] RTPMode rtpMode: rtp mode
765* @param [in] int32_t port:rtp port
766* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800767* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800768*/
769int32_t gsw_voice_set_rtp_port(RTPMode rtpMode, int32_t port)
770{
q.huang50a0d852025-06-11 14:35:15 +0800771 VOICE_MODULE_INIT_CHECK();
b.liu68a94c92025-05-24 12:53:41 +0800772
773 int ret;
774 if(rtpMode==GSW_RTP_CLIENT)
775 {
776 ret = mbtk_rtp_client_port_set(port);
777 }
778 else
779 {
780 ret = mbtk_rtp_server_port_set(port);
781 }
782 if(ret !=0 )
783 {
xy.hecfb7d682025-05-28 21:39:12 +0800784 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800785 }
786 return GSW_HAL_SUCCESS;
787}
788
789/**
790* @brief set rtp mode and port
791* @param [in] int32_t clockRate: clock rate
792* @param [in] int32_t channel:channel
793* @param [in] int32_t latency:latency
794* @param [out] None
xy.hecfb7d682025-05-28 21:39:12 +0800795* @retval GSW_HAL_SUCCESS\GSW_HAL_NORMAL_FAIL
b.liu68a94c92025-05-24 12:53:41 +0800796*/
797int32_t gsw_voice_set_rtp_param(int32_t clockRate, int32_t channel, int32_t latency)
798{
q.huang50a0d852025-06-11 14:35:15 +0800799 VOICE_MODULE_INIT_CHECK();
b.liu68a94c92025-05-24 12:53:41 +0800800
801 int ret=mbtk_rtp_channel_set(channel);
802 if(ret==0)
803 {
804 ret=mbtk_rtp_sample_rate_set(clockRate);
805 }
806 if(ret !=0 )
807 {
xy.hecfb7d682025-05-28 21:39:12 +0800808 return GSW_HAL_NORMAL_FAIL;
b.liu68a94c92025-05-24 12:53:41 +0800809 }
810 return GSW_HAL_SUCCESS;
811}
q.huang020cc232025-06-06 19:06:18 +0800812
813/**
814 * @brief set rtp vlan
815 * @param [in] interfaceName network interface name
816 * @retval 0: success
817 * @retval other: fail
818 */
819int32_t gsw_voice_set_rtp_vlan_info(const char *interfaceName)
820{
q.huang50a0d852025-06-11 14:35:15 +0800821 VOICE_MODULE_INIT_CHECK();
q.huang020cc232025-06-06 19:06:18 +0800822
823 int ret=mbtk_rtp_vlan_set(interfaceName);
824
825 if(ret !=0 )
826 {
827 return GSW_HAL_NORMAL_FAIL;
828 }
829 return GSW_HAL_SUCCESS;
830}
b.liu68a94c92025-05-24 12:53:41 +0800831/*##########################################rtp end*/
832