blob: 28098c2de79e9265fa1670dc58f71170003185ea [file] [log] [blame]
b.liu68a94c92025-05-24 12:53:41 +08001#include <stdio.h>
2#include <stdlib.h>
3#include <stdbool.h>
4#include <dlfcn.h>
5#include <stdint.h>
6#include <string.h>
7#include <pthread.h>
8
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} __attribute__((packed)) mbtk_call_info_t;
59
60typedef enum {
61 MBTK_CLCC = 1,
62 MBTK_CPAS,
63 MBTK_DISCONNECTED,
64} mbtk_call_enum;
65
66typedef enum {
67 MBTK_CALL_RADY, //MT allows commands from TA/TE
68 MBTK_CALL_UNAVAILABLE, //MT does not allow commands from TA/TE
69 MBTK_CALL_UNKNOWN, //MT is not guaranteed to respond to instructions
70 MBTK_CALL_RINGING, //MT is ready for commands from TA/TE, but the ringer is active
71 MBTK_CALL_PROGRESS, //MT is ready for commands from TA/TE, but a call is in progress
72 MBTK_CALL_ASLEEP, //MT is unable to process commands from TA/TE because it is in a low functionality state
73 MBTK_CALL_ACTIVE,
74} mbtk_call_pas_enum;
75
76typedef uint32_t voice_client_handle_type;
77
78
79// GSW includes
80#define GSW_HAL_SUCCESS 0
81#define GSW_HAL_FAIL -1
82#define GSW_HAL_MEM_INVAILD -2
83
84
85typedef int CallHandle;
86typedef enum {
87 GSW_VOICE_CALL_HOLDING = 0,
88 GSW_VOICE_CALL_DIALING,
89 GSW_VOICE_CALL_ALERTING,
90 GSW_VOICE_CALL_CONNECTED,
91 GSW_VOICE_CALL_INCOMING,
92 GSW_VOICE_CALL_WAITING,
93 GSW_VOICE_CALL_END,
94}VoiceCallState;
95
96typedef enum{
97 GSW_AUDIO_MODE_CODEC = 0,
98 GSW_AUDIO_MODE_RTP = 1,
99}AudioMode;
100
101typedef enum {
102 GSW_RTP_CLIENT = 0,
103 GSW_RTP_SERVER,
104}RTPMode;
105
106typedef void (*CallStateInd)(CallHandle, VoiceCallState);
107
108
109int32_t (*gsw_voice_sdk_init)(CallStateInd ind);
110int32_t (*gsw_voice_set_speaker_volume)(int32_t volume);
111int32_t (*gsw_voice_normal_voice_start)(CallHandle *handle, const char *callNumber);
112int32_t (*gsw_voice_answer)(CallHandle handle);
113int32_t (*gsw_voice_hangup)(CallHandle handle);
114int32_t (*gsw_voice_set_auto_answer_mode)(int32_t mode);
115int32_t (*gsw_voice_get_current_call_end_reason)(CallHandle handle);
116/*#############################rtp begin*/
117int32_t (*gsw_voice_set_audio_mode)(AudioMode audioMode);
118int32_t (*gsw_voice_set_remote_rtp_ip)(const char *ip, int32_t len);
119int32_t (*gsw_voice_set_rtp_port)(RTPMode rtpMode, int32_t port);
120int32_t (*gsw_voice_set_rtp_param)(int32_t clockRate, int32_t channel, int32_t latency);
q.huang020cc232025-06-06 19:06:18 +0800121int32_t (*gsw_voice_set_rtp_vlan_info)(const char *interfaceName);
b.liu68a94c92025-05-24 12:53:41 +0800122/*#############################rtp end*/
123
124CallHandle call_handle;
125
126#define lib_gsw_voice_path "/lib/libgsw_lib.so"
127static void *dlHandle_voice = NULL;
128
129void gsw_test_callback(CallHandle handle, VoiceCallState state)
130{
131
132 printf("gsw_test_callback succeess!\n");
133 printf("id = %d, state = %d\n", handle, state);
134
135 call_handle = handle;
136 printf("set call_handle = %d\n", call_handle);
137 printf("call_handle = %d\n", call_handle);
138
139}
140
141static int gsw_rtp_api_import()
142{
143 gsw_voice_set_audio_mode = (int32_t (*)(AudioMode audioMode))dlsym(dlHandle_voice, "gsw_voice_set_audio_mode");
144 if(gsw_voice_set_audio_mode == NULL) {
145 printf("dlsym gsw_voice_set_audio_mode failed: %s\n", dlerror());
146 return -1;
147 }
148
149
150 gsw_voice_set_remote_rtp_ip = (int32_t (*)(const char *ip, int32_t len))dlsym(dlHandle_voice, "gsw_voice_set_remote_rtp_ip");
151 if(gsw_voice_set_remote_rtp_ip == NULL) {
152 printf("dlsym gsw_voice_set_remote_rtp_ip failed: %s\n", dlerror());
153 return -1;
154 }
155
156
157 gsw_voice_set_rtp_port = (int32_t (*)(RTPMode rtpMode, int32_t port))dlsym(dlHandle_voice, "gsw_voice_set_rtp_port");
158 if(gsw_voice_set_rtp_port == NULL) {
159 printf("dlsym gsw_voice_set_rtp_port failed: %s\n", dlerror());
160 return -1;
161 }
162
163
164 gsw_voice_set_rtp_param = (int32_t (*)(int32_t clockRate, int32_t channel, int32_t latency))dlsym(dlHandle_voice, "gsw_voice_set_rtp_param");
165 if(gsw_voice_set_rtp_param == NULL) {
166 printf("dlsym gsw_voice_set_rtp_param failed: %s\n", dlerror());
167 return -1;
168 }
169
q.huang020cc232025-06-06 19:06:18 +0800170 gsw_voice_set_rtp_vlan_info = (int32_t (*)(const char *interfaceName))dlsym(dlHandle_voice, "gsw_voice_set_rtp_vlan_info");
171 if(gsw_voice_set_rtp_vlan_info == NULL) {
172 printf("dlsym gsw_voice_set_rtp_vlan_info failed: %s\n", dlerror());
b.liu68a94c92025-05-24 12:53:41 +0800173 return -1;
174 }
175
176 return 0;
177
178}
179
180
181
182static int gsw_call_api_import()
183{
184 dlHandle_voice = dlopen(lib_gsw_voice_path, RTLD_NOW);
185 if (!dlHandle_voice) {
186 printf("dlopen %s failed: %s\n", lib_gsw_voice_path, dlerror());
187 return -1;
188 }
189
190 gsw_voice_sdk_init = (int32_t (*)(CallStateInd ind))dlsym(dlHandle_voice, "gsw_voice_sdk_init");
191 if(gsw_voice_sdk_init == NULL) {
192 printf("dlsym gsw_voice_sdk_init failed: %s\n", dlerror());
193 return -1;
194 }
195
196 gsw_voice_set_speaker_volume = (int32_t (*)(int32_t volume))dlsym(dlHandle_voice, "gsw_voice_set_speaker_volume");
197 if(gsw_voice_set_speaker_volume == NULL) {
198 printf("dlsym gsw_voice_set_speaker_volume failed: %s\n", dlerror());
199 return -1;
200 }
201
202 gsw_voice_normal_voice_start = (int32_t (*)(CallHandle *, const char *))dlsym(dlHandle_voice, "gsw_voice_normal_voice_start");
203 if(gsw_voice_normal_voice_start == NULL) {
204 printf("dlsym gsw_voice_normal_voice_start failed: %s\n", dlerror());
205 return -1;
206 }
207
208 gsw_voice_answer = (int32_t (*)(CallHandle handle))dlsym(dlHandle_voice, "gsw_voice_answer");
209 if(gsw_voice_answer == NULL) {
210 printf("dlsym gsw_voice_answer failed: %s\n", dlerror());
211 return -1;
212
213 }
214
215 gsw_voice_hangup = (int32_t (*)(CallHandle handle))dlsym(dlHandle_voice, "gsw_voice_hangup");
216 if(gsw_voice_hangup == NULL) {
217 printf("dlsym gsw_voice_hangup failed: %s\n", dlerror());
218 return -1;
219 }
220
221 gsw_voice_set_auto_answer_mode = (int32_t (*)(int32_t mode))dlsym(dlHandle_voice, "gsw_voice_set_auto_answer_mode");
222 if(gsw_voice_set_auto_answer_mode == NULL) {
223 printf("dlsym gsw_voice_set_auto_answer_mode failed: %s\n", dlerror());
224 return -1;
225 }
226
q.huang020cc232025-06-06 19:06:18 +0800227 gsw_voice_get_current_call_end_reason = (int32_t (*)(CallHandle handle))dlsym(dlHandle_voice, "gsw_voice_get_current_call_end_reason");
228 if(gsw_voice_get_current_call_end_reason == NULL) {
229 printf("dlsym gsw_voice_get_current_call_end_reason failed: %s\n", dlerror());
230 return -1;
231 }
232
b.liu68a94c92025-05-24 12:53:41 +0800233 return gsw_rtp_api_import();
234}
235
236int main()
237{
238 char operator[10];
239 int opt;
240 int ret;
241
242 gsw_call_api_import();
243
244 while(1)
245 {
246 printf("=========gsw voice main=========\n"
247 "\t-1 exit\n"
248 "\t1 voice init\n"
249 "\t2 voice dial\n"
250 "\t3 voice hangup\n"
251 "\t4 voice answer\n"
252 "\t5 set auto answer mode\n"
253 "\t6 set speaker volume\n"
254 "\t7 set audio mode (local codec or rtp) \n"
255 "\t8 set remote rtp ip\n"
256 "\t9 set rtp port\n"
257 "\t10 set rtp param\n"
q.huang020cc232025-06-06 19:06:18 +0800258 "\t11 set rtp vlan\n"
259 "\t12 get current call end reason\n"
b.liu68a94c92025-05-24 12:53:41 +0800260 "operator: >> \n");
261
262 memset(operator, 0, sizeof(operator));
263 printf("%s\n",fgets(operator, sizeof(operator), stdin));
264 fflush(stdin);
265 opt = atoi(operator);
266 switch (opt)
267 {
268 case -1:
269 printf("main exit\n");
270 return 0;
271 case 1:
272 {
273 printf(">>>>>voice init\n");
274 ret = gsw_voice_sdk_init(gsw_test_callback);
275 if(ret != 0)
276 {
q.huang50a0d852025-06-11 14:35:15 +0800277 printf("gsw_voice_sdk_init fail, ret is %d\n",ret);
b.liu68a94c92025-05-24 12:53:41 +0800278 }
279 else
280 {
281 printf("gsw_voice_sdk_init success\n");
282 }
283 }
284 break;
285 case 2:
286 {
287 printf(">>>>>Input gsw_voice_normal_voice_start<<<<<\n");
288 char number[16] = {0};
289 printf("Enter call number\n");
290 printf("%d\n",scanf("%15s", number));
291 printf("call number is %s\n", number);
292
293 ret = gsw_voice_normal_voice_start(&call_handle, number);
294 if(ret < 0)
295 {
q.huang50a0d852025-06-11 14:35:15 +0800296 printf("gsw_voice_normal_voice_start fail, ret is %d\n", ret);
b.liu68a94c92025-05-24 12:53:41 +0800297 }
298 else
299 {
300 printf("gsw_voice_normal_voice_start success\n");
301 }
302 }
303 break;
304 case 3:
305 {
306 printf(">>>>>Input gsw_voice_hangup<<<<<\n");
307 printf("call_handle is %d\n", call_handle);
308 ret = gsw_voice_hangup(call_handle);
309 if(ret < 0)
310 {
q.huang50a0d852025-06-11 14:35:15 +0800311 printf("gsw_voice_hangup fail, ret is %d\n",ret);
b.liu68a94c92025-05-24 12:53:41 +0800312 }
313 else
314 {
315 printf("gsw_voice_hangup success\n");
316 }
317 }
318 break;
319 case 4:
320 {
321 printf(">>>>>Input gsw_voice_answer<<<<<\n");
322 printf("call_handle is %d\n", call_handle);
323 ret = gsw_voice_answer(call_handle);
324 if(ret < 0)
325 {
326 printf("gsw_voice_answer fail\n");
327 }
328 else
329 {
330 printf("gsw_voice_answer success\n");
331 }
332 }
333 break;
334 case 5:
335 {
336 printf(">>>>>Input gsw_voice_set_auto_answer_mode<<<<<\n");
337
338 int mode = 0;
339 printf("Enter set mode\n");
340 printf("%d\n",scanf("%d", &mode));
341 fflush(stdin);
342 printf("mode is %d\n", mode);
343
344 printf("start set auto answer mode(0:disable, 1:enable)\n");
345 ret = gsw_voice_set_auto_answer_mode(mode);
346 if(ret < 0)
347 {
q.huang50a0d852025-06-11 14:35:15 +0800348 printf("gsw_voice_set_auto_answer_mode fail, ret is %d\n",ret);
b.liu68a94c92025-05-24 12:53:41 +0800349 }
350 else
351 {
352 printf("gsw_voice_set_auto_answer_mode success\n");
353 }
354 }
355 break;
356 case 6:
357 {
358 printf(">>>>>Input gsw_voice_set_speaker_volume<<<<<\n");
359
360
361 int volume;
362
363 printf("Enter set volume\n");
364 printf("%d\n",scanf("%d", &volume));
365 fflush(stdin);
366 printf("volume is %d\n", volume);
367
368 ret = gsw_voice_set_speaker_volume(volume);
369 if(ret < 0)
370 {
q.huang50a0d852025-06-11 14:35:15 +0800371 printf("gsw_voice_set_speaker_volume fail, ret is %d\n",ret);
b.liu68a94c92025-05-24 12:53:41 +0800372 }
373 else
374 {
375 printf("gsw_voice_set_speaker_volume success\n");
376 }
377 }
378 break;
379 /*#############################rtp begin*/
380 case 7:
381 {
382 printf(">>>>>Input gsw_voice_set_audio_mode<<<<<\n");
383
384 int mode;
385
386 printf("Enter set mode (0: local codec, 1:rtp)\n");
387 printf("%d\n",scanf("%d", &mode));
388 fflush(stdin);
389 printf("mode is %d\n", mode);
390
391 ret = gsw_voice_set_audio_mode(mode);
392 if(ret != 0)
393 {
q.huang50a0d852025-06-11 14:35:15 +0800394 printf("gsw_voice_set_audio_mode fail, ret is %d\n",ret);
b.liu68a94c92025-05-24 12:53:41 +0800395 }
396 else
397 {
398 printf("gsw_voice_set_audio_mode success\n");
399 }
400 }
401 break;
402
403 case 8:
404 {
405 printf(">>>>>Input gsw_voice_set_remote_rtp_ip<<<<<\n");
406
407 char remote_ip_addr[100] = {0};
408
409 printf("Enter set remote rtp ip address (***.***.***.***) \n");
410 printf("%d\n",scanf("%s", remote_ip_addr));
411 fflush(stdin);
412 printf("remote rtp ip address is %s\n", remote_ip_addr);
413
414 ret = gsw_voice_set_remote_rtp_ip(remote_ip_addr,strlen(remote_ip_addr)+1);
415 if(ret != 0)
416 {
q.huang50a0d852025-06-11 14:35:15 +0800417 printf("gsw_voice_set_remote_rtp_ip fail, ret is %d\n",ret);
b.liu68a94c92025-05-24 12:53:41 +0800418 }
419 else
420 {
421 printf("gsw_voice_set_remote_rtp_ip success\n");
422 }
423 }
424 break;
425
426 case 9:
427 {
428 printf(">>>>>Input gsw_voice_set_rtp_port<<<<<\n");
429
430 int mode;
431 int port;
432 printf("Enter set mode (0: server, 1:client)\n");
433 printf("%d\n",scanf("%d", &mode));
434 fflush(stdin);
435 printf("mode is %d\n", mode);
436
437 printf("Enter set port\n");
438 printf("%d\n",scanf("%d", &port));
439 fflush(stdin);
440 printf("port is %d\n", port);
441
442 ret = gsw_voice_set_rtp_port(mode,port);
443 if(ret != 0)
444 {
q.huang50a0d852025-06-11 14:35:15 +0800445 printf("gsw_voice_set_rtp_port fail, ret is %d\n",ret);
b.liu68a94c92025-05-24 12:53:41 +0800446 }
447 else
448 {
449 printf("gsw_voice_set_rtp_port success\n");
450 }
451 }
452 break;
453
454
455 case 10:
456 {
457 printf(">>>>>Input gsw_voice_set_rtp_param<<<<<\n");
458
459 int clockRate;
460 int channel;
461 int latency=400;
462
463 printf("Enter set clockRate (only 8000 and 16000 supoort) \n");
464 printf("%d\n",scanf("%d", &clockRate));
465 fflush(stdin);
466 printf("clockRate is %d\n", clockRate);
467
468 printf("Enter set channel (only 1 support)\n");
469 printf("%d\n",scanf("%d", &channel));
470 fflush(stdin);
471 printf("channel is %d\n", channel);
472
473 ret = gsw_voice_set_rtp_param(clockRate, channel, latency);
474 if(ret != 0)
475 {
q.huang50a0d852025-06-11 14:35:15 +0800476 printf("gsw_voice_set_rtp_param fail, ret is %d\n",ret);
b.liu68a94c92025-05-24 12:53:41 +0800477 }
478 else
479 {
480 printf("gsw_voice_set_rtp_param success\n");
481 }
482 }
483 break;
q.huang020cc232025-06-06 19:06:18 +0800484 case 11:
485 {
486 printf(">>>>>Input gsw_voice_set_rtp_vlan_info<<<<<\n");
487
488 char interface[100] = {0};
489
490 printf("Enter vlan interface info (for example: eth2.4) \n");
491 printf("%d\n",scanf("%s", interface));
492 fflush(stdin);
493 printf("vlan interface is %s\n", interface);
494
495 ret = gsw_voice_set_rtp_vlan_info(interface);
496 if(ret != 0)
497 {
q.huang50a0d852025-06-11 14:35:15 +0800498 printf("gsw_voice_set_rtp_vlan_info fail, ret is %d\n",ret);
q.huang020cc232025-06-06 19:06:18 +0800499 }
500 else
501 {
502 printf("gsw_voice_set_rtp_vlan_info success\n");
503 }
504 }
505 break;
b.liu68a94c92025-05-24 12:53:41 +0800506 /*#############################rtp end*/
507
q.huang020cc232025-06-06 19:06:18 +0800508 case 12:
b.liu68a94c92025-05-24 12:53:41 +0800509 {
510 printf(">>>>gsw_voice_get_current_call_end_reason<<<\n");
511 ret = gsw_voice_get_current_call_end_reason(call_handle);
512 printf("gsw_voice_get_current_call_end_reason = %d\n", ret);
513 break;
514 }
515
516 default:
517 break;
518 }
519
520 }
521
522 return 0;
523
524}