Fix mbtk from v1265 GSW

Change-Id: I5d8d395616f284bc74c8b9448cfa347164b5a668
diff --git a/mbtk/test/libgsw_lib/gsw_voice_test.c b/mbtk/test/libgsw_lib/gsw_voice_test.c
new file mode 100755
index 0000000..894ac86
--- /dev/null
+++ b/mbtk/test/libgsw_lib/gsw_voice_test.c
@@ -0,0 +1,494 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <dlfcn.h>
+#include <stdint.h>
+#include <string.h>
+#include <pthread.h>
+
+// mbtk includes
+
+typedef unsigned int uint32;
+typedef unsigned char uint8;
+typedef unsigned short uint16;
+typedef void (*mbtk_info_callback_func)(const void* data, int data_len);
+
+typedef struct
+{
+    int client_fd;
+    pthread_t read_thread_id;
+    int exit_fd[2];
+    bool is_waitting;
+    pthread_cond_t cond;
+    pthread_mutex_t mutex;
+
+    pthread_mutex_t send_mutex;
+
+    // Temp response data.
+    uint16 info_err;
+    uint16 data_len;
+    void *data;
+
+    //mbtk wyq for server_ready_status add start
+    char server_ready_status;
+    //mbtk wyq for server_ready_status add end
+
+    mbtk_info_callback_func net_state_cb;
+    mbtk_info_callback_func call_state_cb;
+    mbtk_info_callback_func sms_state_cb;
+    mbtk_info_callback_func radio_state_cb;
+    mbtk_info_callback_func sim_state_cb;
+    mbtk_info_callback_func pdp_state_cb;
+    //add signal by xr
+    mbtk_info_callback_func signal_state_cb;
+} mbtk_info_handle_t;
+
+typedef struct
+{
+    uint8 call_wait;
+    uint8 dir1;
+    uint8 dir;
+    uint8 state;
+    uint8 mode;
+    uint8 mpty;
+    char phone_number[100];
+    uint8 type;
+    uint8 pas;
+    uint8 disconnected_id;
+} __attribute__((packed)) mbtk_call_info_t;
+
+typedef enum {
+    MBTK_CLCC = 1,
+    MBTK_CPAS,
+    MBTK_DISCONNECTED,
+} mbtk_call_enum;
+
+typedef enum {
+    MBTK_CALL_RADY,                 //MT allows commands from TA/TE
+    MBTK_CALL_UNAVAILABLE,          //MT does not allow commands from TA/TE
+    MBTK_CALL_UNKNOWN,              //MT is not guaranteed to respond to instructions
+    MBTK_CALL_RINGING,              //MT is ready for commands from TA/TE, but the ringer is active
+    MBTK_CALL_PROGRESS,             //MT is ready for commands from TA/TE, but a call is in progress
+    MBTK_CALL_ASLEEP,               //MT is unable to process commands from TA/TE because it is in a low functionality state
+    MBTK_CALL_ACTIVE,
+} mbtk_call_pas_enum;
+
+typedef uint32_t voice_client_handle_type;
+
+
+// GSW includes
+#define GSW_HAL_SUCCESS 0
+#define GSW_HAL_FAIL -1
+#define GSW_HAL_MEM_INVAILD -2
+
+
+typedef int CallHandle;
+typedef enum {
+    GSW_VOICE_CALL_HOLDING = 0,
+    GSW_VOICE_CALL_DIALING,
+    GSW_VOICE_CALL_ALERTING,
+    GSW_VOICE_CALL_CONNECTED,
+    GSW_VOICE_CALL_INCOMING,
+    GSW_VOICE_CALL_WAITING,
+    GSW_VOICE_CALL_END,
+}VoiceCallState;
+
+typedef enum{
+    GSW_AUDIO_MODE_CODEC = 0,
+    GSW_AUDIO_MODE_RTP = 1,
+}AudioMode;
+
+typedef enum {
+    GSW_RTP_CLIENT = 0,
+    GSW_RTP_SERVER,
+}RTPMode;
+
+typedef void (*CallStateInd)(CallHandle, VoiceCallState);
+
+
+int32_t (*gsw_voice_sdk_init)(CallStateInd ind);
+int32_t (*gsw_voice_set_speaker_volume)(int32_t volume);
+int32_t (*gsw_voice_normal_voice_start)(CallHandle *handle, const char *callNumber);
+int32_t (*gsw_voice_answer)(CallHandle handle);
+int32_t (*gsw_voice_hangup)(CallHandle handle);
+int32_t (*gsw_voice_set_auto_answer_mode)(int32_t mode);
+int32_t (*gsw_voice_get_current_call_end_reason)(CallHandle handle);
+/*#############################rtp begin*/
+int32_t (*gsw_voice_set_audio_mode)(AudioMode audioMode);
+int32_t (*gsw_voice_set_remote_rtp_ip)(const char *ip, int32_t len);
+int32_t (*gsw_voice_set_rtp_port)(RTPMode rtpMode, int32_t port);
+int32_t (*gsw_voice_set_rtp_param)(int32_t clockRate, int32_t channel, int32_t latency);
+/*#############################rtp end*/
+
+CallHandle call_handle;
+
+#define lib_gsw_voice_path "/lib/libgsw_lib.so"
+static void *dlHandle_voice = NULL;
+
+void gsw_test_callback(CallHandle handle, VoiceCallState state)
+{
+
+    printf("gsw_test_callback succeess!\n");
+    printf("id = %d, state = %d\n", handle, state);
+
+    call_handle = handle;
+    printf("set call_handle = %d\n", call_handle);
+    printf("call_handle = %d\n", call_handle);
+
+}
+
+static int gsw_rtp_api_import()
+{
+   gsw_voice_set_audio_mode = (int32_t (*)(AudioMode audioMode))dlsym(dlHandle_voice, "gsw_voice_set_audio_mode");
+   if(gsw_voice_set_audio_mode == NULL) {
+       printf("dlsym gsw_voice_set_audio_mode failed: %s\n", dlerror());
+       return -1;
+   }
+
+
+   gsw_voice_set_remote_rtp_ip = (int32_t (*)(const char *ip, int32_t len))dlsym(dlHandle_voice, "gsw_voice_set_remote_rtp_ip");
+   if(gsw_voice_set_remote_rtp_ip == NULL) {
+       printf("dlsym gsw_voice_set_remote_rtp_ip failed: %s\n", dlerror());
+       return -1;
+   }
+
+       
+   gsw_voice_set_rtp_port = (int32_t (*)(RTPMode rtpMode, int32_t port))dlsym(dlHandle_voice, "gsw_voice_set_rtp_port");
+   if(gsw_voice_set_rtp_port == NULL) {
+       printf("dlsym gsw_voice_set_rtp_port failed: %s\n", dlerror());
+       return -1;
+   }
+
+   
+   gsw_voice_set_rtp_param = (int32_t (*)(int32_t clockRate, int32_t channel, int32_t latency))dlsym(dlHandle_voice, "gsw_voice_set_rtp_param");
+   if(gsw_voice_set_rtp_param == NULL) {
+       printf("dlsym gsw_voice_set_rtp_param failed: %s\n", dlerror());
+       return -1;
+   }
+
+   gsw_voice_get_current_call_end_reason = (int32_t (*)(CallHandle handle))dlsym(dlHandle_voice, "gsw_voice_get_current_call_end_reason");
+   if(gsw_voice_get_current_call_end_reason == NULL) {
+       printf("dlsym gsw_voice_get_current_call_end_reason failed: %s\n", dlerror());
+       return -1;
+   }
+   
+   return 0;
+
+}
+
+
+
+static int gsw_call_api_import()
+{
+    dlHandle_voice = dlopen(lib_gsw_voice_path, RTLD_NOW);
+    if (!dlHandle_voice) {
+        printf("dlopen %s failed: %s\n", lib_gsw_voice_path, dlerror());
+        return -1;
+    }
+
+    gsw_voice_sdk_init = (int32_t (*)(CallStateInd ind))dlsym(dlHandle_voice, "gsw_voice_sdk_init");
+    if(gsw_voice_sdk_init == NULL) {
+        printf("dlsym gsw_voice_sdk_init failed: %s\n", dlerror());
+        return -1;
+    }
+
+    gsw_voice_set_speaker_volume = (int32_t (*)(int32_t volume))dlsym(dlHandle_voice, "gsw_voice_set_speaker_volume");
+    if(gsw_voice_set_speaker_volume == NULL) {
+        printf("dlsym gsw_voice_set_speaker_volume failed: %s\n", dlerror());
+        return -1;
+    }
+    
+    gsw_voice_normal_voice_start = (int32_t (*)(CallHandle *, const char *))dlsym(dlHandle_voice, "gsw_voice_normal_voice_start");
+    if(gsw_voice_normal_voice_start == NULL) {
+        printf("dlsym gsw_voice_normal_voice_start failed: %s\n", dlerror());
+        return -1;
+    }
+
+    gsw_voice_answer = (int32_t (*)(CallHandle handle))dlsym(dlHandle_voice, "gsw_voice_answer");
+    if(gsw_voice_answer == NULL) {
+        printf("dlsym gsw_voice_answer failed: %s\n", dlerror());
+        return -1;
+
+    }
+
+    gsw_voice_hangup = (int32_t (*)(CallHandle handle))dlsym(dlHandle_voice, "gsw_voice_hangup");
+    if(gsw_voice_hangup == NULL) {
+        printf("dlsym gsw_voice_hangup failed: %s\n", dlerror());
+        return -1;
+    }
+
+    gsw_voice_set_auto_answer_mode = (int32_t (*)(int32_t mode))dlsym(dlHandle_voice, "gsw_voice_set_auto_answer_mode");
+    if(gsw_voice_set_auto_answer_mode == NULL) {
+        printf("dlsym gsw_voice_set_auto_answer_mode failed: %s\n", dlerror());
+        return -1;
+    }
+
+    return gsw_rtp_api_import();
+}
+
+int main() 
+{
+    char operator[10];
+    int opt;
+    int ret;
+
+    gsw_call_api_import();
+
+    while(1)
+    {
+        printf("=========gsw voice main=========\n"
+        "\t-1 exit\n"
+        "\t1 voice init\n"
+        "\t2 voice dial\n"
+        "\t3 voice hangup\n"
+        "\t4 voice answer\n"
+        "\t5 set auto answer mode\n"
+        "\t6 set speaker volume\n"        
+        "\t7 set audio mode (local codec or rtp) \n"
+        "\t8 set remote rtp ip\n"
+        "\t9 set rtp port\n"
+        "\t10 set rtp param\n"
+        "\t11 get current call end reason\n"
+        "operator: >> \n");
+
+		memset(operator, 0, sizeof(operator));
+        printf("%s\n",fgets(operator, sizeof(operator), stdin));
+        fflush(stdin);
+        opt = atoi(operator);
+        switch (opt)
+        {
+        case -1:
+            printf("main exit\n");
+            return 0;
+        case 1:
+            {
+                printf(">>>>>voice init\n");
+				ret = gsw_voice_sdk_init(gsw_test_callback);
+				if(ret != 0)
+				{
+					printf("gsw_voice_sdk_init fail\n");
+				}
+				else
+				{
+					printf("gsw_voice_sdk_init success\n");
+				}
+            }
+            break;
+        case 2:
+            {
+                printf(">>>>>Input gsw_voice_normal_voice_start<<<<<\n");
+                char number[16] = {0};
+                printf("Enter call number\n");
+                printf("%d\n",scanf("%15s", number));
+                printf("call number is %s\n", number);
+
+                ret = gsw_voice_normal_voice_start(&call_handle, number);
+				if(ret < 0)
+				{
+					printf("gsw_voice_normal_voice_start fail\n");
+				}
+				else
+				{
+					printf("gsw_voice_normal_voice_start success\n");
+				}
+            }
+            break;
+        case 3:
+            {
+                printf(">>>>>Input gsw_voice_hangup<<<<<\n");
+                printf("call_handle is %d\n", call_handle);
+                ret = gsw_voice_hangup(call_handle);
+                if(ret < 0)
+                {
+                    printf("gsw_voice_hangup fail\n");
+                }
+                else
+                {
+                    printf("gsw_voice_hangup success\n");
+                }
+            }
+            break;
+        case 4:
+            {
+                printf(">>>>>Input gsw_voice_answer<<<<<\n");
+                printf("call_handle is %d\n", call_handle);
+                ret = gsw_voice_answer(call_handle);
+				if(ret < 0)
+				{
+					printf("gsw_voice_answer fail\n");
+				}
+				else
+				{
+					printf("gsw_voice_answer success\n");
+				}
+            }
+            break;
+        case 5:
+            {
+                printf(">>>>>Input gsw_voice_set_auto_answer_mode<<<<<\n");
+
+                int mode = 0;
+                printf("Enter set mode\n");
+                printf("%d\n",scanf("%d", &mode));
+                fflush(stdin);
+                printf("mode is %d\n", mode);
+
+                printf("start set auto answer mode(0:disable, 1:enable)\n");
+                ret = gsw_voice_set_auto_answer_mode(mode);
+				if(ret < 0)
+				{
+					printf("gsw_voice_set_auto_answer_mode fail\n");
+				}
+				else
+				{
+					printf("gsw_voice_set_auto_answer_mode success\n");
+				}
+            }
+            break;
+         case 6:
+            {
+                printf(">>>>>Input gsw_voice_set_speaker_volume<<<<<\n");
+
+
+                int volume;
+                
+                printf("Enter set volume\n");
+                printf("%d\n",scanf("%d", &volume));
+                fflush(stdin);
+                printf("volume is %d\n", volume);
+                
+                ret = gsw_voice_set_speaker_volume(volume);
+				if(ret < 0)
+				{
+					printf("gsw_voice_set_speaker_volume fail\n");
+				}
+				else
+				{
+					printf("gsw_voice_set_speaker_volume success\n");
+				}
+            }
+            break;
+        /*#############################rtp begin*/         
+        case 7:
+            {
+                printf(">>>>>Input gsw_voice_set_audio_mode<<<<<\n");
+
+                int mode;    
+
+                printf("Enter set mode (0: local codec, 1:rtp)\n");                
+                printf("%d\n",scanf("%d", &mode));
+                fflush(stdin);
+                printf("mode is %d\n", mode);               
+                                
+                ret = gsw_voice_set_audio_mode(mode);
+				if(ret != 0)
+				{
+					printf("gsw_voice_set_audio_mode fail\n");
+				}
+				else
+				{
+					printf("gsw_voice_set_audio_mode success\n");
+				}
+            }
+            break;
+
+        case 8:
+            {
+                printf(">>>>>Input gsw_voice_set_remote_rtp_ip<<<<<\n");
+
+                char remote_ip_addr[100] = {0};
+                
+                printf("Enter set remote rtp ip address (***.***.***.***) \n");
+                printf("%d\n",scanf("%s", remote_ip_addr));
+                fflush(stdin);
+                printf("remote rtp ip address is %s\n", remote_ip_addr);              
+                              
+                ret = gsw_voice_set_remote_rtp_ip(remote_ip_addr,strlen(remote_ip_addr)+1);
+                if(ret != 0)
+                {
+                    printf("gsw_voice_set_remote_rtp_ip fail\n");
+                }
+                else
+                {
+                    printf("gsw_voice_set_remote_rtp_ip success\n");
+                }
+            }
+            break;
+
+        case 9:
+            {
+                printf(">>>>>Input gsw_voice_set_rtp_port<<<<<\n");
+
+                int mode;    
+                int port;               
+                printf("Enter set mode (0: server, 1:client)\n");
+                printf("%d\n",scanf("%d", &mode));
+                fflush(stdin);
+                printf("mode is %d\n", mode);
+                
+                printf("Enter set port\n");
+                printf("%d\n",scanf("%d", &port));
+                fflush(stdin);
+                printf("port is %d\n", port);
+                
+                ret = gsw_voice_set_rtp_port(mode,port);
+				if(ret != 0)
+				{
+					printf("gsw_voice_set_rtp_port fail\n");
+				}
+				else
+				{
+					printf("gsw_voice_set_rtp_port success\n");
+				}
+            }
+            break;
+
+            
+        case 10:
+            {
+                printf(">>>>>Input gsw_voice_set_rtp_param<<<<<\n");
+
+                int clockRate;
+                int channel;
+                int latency=400;
+                
+                printf("Enter set clockRate (only 8000 and 16000 supoort) \n");
+                printf("%d\n",scanf("%d", &clockRate));
+                fflush(stdin);
+                printf("clockRate is %d\n", clockRate);
+                
+                printf("Enter set channel (only 1 support)\n");
+                printf("%d\n",scanf("%d", &channel));
+                fflush(stdin);
+                printf("channel is %d\n", channel);
+                
+                ret = gsw_voice_set_rtp_param(clockRate, channel, latency);
+                if(ret != 0)
+                {
+                    printf("gsw_voice_set_rtp_param fail\n");
+                }
+                else
+                {
+                    printf("gsw_voice_set_rtp_param success\n");
+                }
+            }
+            break;          
+        /*#############################rtp end*/
+
+        case 11:
+        {
+            printf(">>>>gsw_voice_get_current_call_end_reason<<<\n");
+            ret = gsw_voice_get_current_call_end_reason(call_handle);
+            printf("gsw_voice_get_current_call_end_reason = %d\n", ret);
+            break;
+        }
+ 
+        default:
+            break;
+        }
+
+    }
+	
+    return 0;
+
+}