Fix warning as error for V2

Change-Id: I70cfd971fda629011ba1be84fef15afea196d393
diff --git a/mbtk/include/mbtk/mbtk_ril_api.h b/mbtk/include/mbtk/mbtk_ril_api.h
index ec3cef6..f5a8d6b 100755
--- a/mbtk/include/mbtk/mbtk_ril_api.h
+++ b/mbtk/include/mbtk/mbtk_ril_api.h
@@ -795,6 +795,10 @@
 
 ////////////////////////////////////////////////////
 
+char* apn2str(mbtk_ip_type_enum type);
+
+int ipv6_2_str(const void *ipv6, void *ipv6_str);
+
 mbtk_ril_err_enum mbtk_ril_init();
 
 mbtk_ril_err_enum mbtk_ril_deinit();
@@ -1215,6 +1219,12 @@
 mbtk_ril_err_enum mbtk_mute_state_set(int mute_state);
 
 /*
+* Set DTMF character.
+*
+*/
+mbtk_ril_err_enum mbtk_dtmf_send(mbtk_call_dtmf_info_t *dtmf_character);
+
+/*
 * Set msd item.
 *
 */
diff --git a/mbtk/libmbtk_lib_v2/Makefile b/mbtk/libmbtk_lib_v2/Makefile
index 2883152..9bbc7d8 100755
--- a/mbtk/libmbtk_lib_v2/Makefile
+++ b/mbtk/libmbtk_lib_v2/Makefile
@@ -17,6 +17,7 @@
 	-I$(LOCAL_PATH)/net \
 	-I$(LOCAL_PATH)/tcpip \
 	-I$(LOCAL_PATH)/ril \
+	-I$(LOCAL_PATH)/sleep \
 	-I$(LOCAL_PATH)/wifi
 
 LIB_DIR +=
@@ -136,7 +137,12 @@
 # tcpip
 LOCAL_SRC_FILES += \
     tcpip/mbtk_tcpip_at.c
-    
+
+# sleep
+LOCAL_SRC_FILES += \
+    sleep/mbtk_sleep.c \
+    sleep/mbtk_lpm.c
+
 #wifi
 LOCAL_SRC_FILES += \
     wifi/sta_cli.c \
diff --git a/mbtk/libmbtk_lib_v2/audio/mbtk_pcm_stream.c b/mbtk/libmbtk_lib_v2/audio/mbtk_pcm_stream.c
index e178b56..cb855c2 100755
--- a/mbtk/libmbtk_lib_v2/audio/mbtk_pcm_stream.c
+++ b/mbtk/libmbtk_lib_v2/audio/mbtk_pcm_stream.c
@@ -3,6 +3,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <errno.h>
+#include <cutils/str_parms.h>
 
 #include "mbtk_log.h"
 #include "mbtk_audio_internal.h"
@@ -74,7 +75,7 @@
 
 static void audio_recorder_thread(void *arg)
 {
-    int rc, len, frames = 0;
+    int len, frames = 0;
     char buff[MBTK_PCM_WB_BUF_SIZE];
 
     audio_info->info.recorder.state = AUDIO_RECORDER_STATE_RUNNING;
@@ -207,7 +208,7 @@
     //printf("Direction is %d, Type is %d, Src_Dst is %d, Priority is %d, Dest is %d. \n",data[0], data[1], data[2], data[3], data[4]);
 
     if (update_vcm) {
-        configure_vcm(data);   /*TODO check if all inputs got all values successfully*/
+        configure_vcm((unsigned int*)data);   /*TODO check if all inputs got all values successfully*/
     }
 
     return 0;
@@ -587,7 +588,7 @@
 };
 
 static struct mopen_audio_t *internal_hdl = NULL;
-typedef int (*_play_callback)(int hdl, int result);
+typedef int (*_play_callback)(void *hdl, int result);
 
 
 static int config_parameters_new(int in_out, int NBWB)
@@ -649,7 +650,7 @@
     //printf("Direction is %d, Type is %d, Src_Dst is %d, Priority is %d, Dest is %d. \n",data[0], data[1], data[2], data[3], data[4]);
 
     if (update_vcm) {
-        configure_vcm(data);   /*TODO check if all inputs got all values successfully*/
+        configure_vcm((unsigned int*)data);   /*TODO check if all inputs got all values successfully*/
     }
 
     return 0;
@@ -677,6 +678,8 @@
     } else if ((16000 == rate) && (1 == num_channels)) {
         nb_wb = 1;//WB
         pcxt->pcm_packet_size = 640;
+    } else {
+        return -1;
     }
 
     //config playback parameters.
@@ -689,7 +692,7 @@
 {
     struct mopen_audio_t *pcxt = (struct mopen_audio_t *)hdl;
     if (NULL == hdl || NULL == internal_hdl)
-        return 0;
+        return;
     pthread_mutex_lock(&pcxt->_cond_mutex);
     pcxt->state = _status;
     pthread_mutex_unlock(&pcxt->_cond_mutex);
@@ -698,7 +701,6 @@
 mbtk_audio_handle mbtk_audio_open_new(mbtk_audio_dev_enum dev, int flag, int rate, void *usrData)
 {
 
-    int value = 1;
     struct mopen_audio_t *aud_hdl = NULL;
     int ret;
 
@@ -750,11 +752,27 @@
     return (void *)aud_hdl;
 
 error:
-    value = 0;
     free(aud_hdl);
     return NULL;
 }
 
+int mbtk_audio_playback_set_block_flag(mbtk_audio_handle handle, int flags)
+{
+    if (handle == NULL) {
+        LOGE("Invalid handle: NULL");
+        return -1;
+    }
+
+    if (flags < 0) {
+        LOGE("Invalid flags: %d", flags);
+        return -1;
+    }
+
+    LOGD("Setting block flag: %d", flags);
+
+    return 0;
+}
+
 int mbtk_audio_play_file_new(void *dev_hdl, int file_fd, int offset)
 {
     unsigned bufsize = 0;
@@ -764,11 +782,6 @@
     int res = 0;
     int ret;
 
-    char cmd[128] = {0};
-    bool flay_flag = TRUE;
-    int i = 0;
-
-
     struct mopen_audio_t *pcxt = (struct mopen_audio_t *)dev_hdl;
     _play_callback audio_play_cb = (_play_callback)pcxt->usrData;
     if (NULL == dev_hdl || NULL == internal_hdl)
@@ -853,7 +866,6 @@
     unsigned bufsize = 0;
     char *data = NULL;
     int first_set = 0;
-    int res = 0;
     int ret = 0;
     int read_size = 0;
     char *p = (char *)pData;
@@ -930,10 +942,11 @@
             if(flay_flag && gain != 50)
             {
                 sprintf(cmd, "ubus call audio_if config_dspgain \"{\'type\':1, \'gain\':%d}\"", gain);
-                system(cmd);
-
-                flay_flag = FALSE;
-                usleep(80000);
+                ret = system(cmd);
+                if(ret != -1 && ret != 127) {
+                    flay_flag = FALSE;
+                    usleep(80000);
+                }
             }
         }
 
@@ -951,7 +964,6 @@
 int mbtk_audio_close_new(void *dev_hdl)
 {
     LOGD("mbtk_audio_close()\n");
-    int value = 0;
     struct mopen_audio_t *_hdl = (struct mopen_audio_t *)dev_hdl;
 
     if (NULL == _hdl || NULL == internal_hdl )
diff --git a/mbtk/libmbtk_lib_v2/audio/mbtk_wav.c b/mbtk/libmbtk_lib_v2/audio/mbtk_wav.c
index f2e104c..403db74 100755
--- a/mbtk/libmbtk_lib_v2/audio/mbtk_wav.c
+++ b/mbtk/libmbtk_lib_v2/audio/mbtk_wav.c
@@ -3,6 +3,7 @@
 #include <stdio.h>
 #include <fcntl.h>
 #include <errno.h>
+#include <stdlib.h>
 
 #include "mbtk_log.h"
 #include "mbtk_audio_internal.h"
@@ -26,6 +27,10 @@
 
 static audio_buff_t audio_buff;
 
+static int current_loopback_state = 0;
+static int current_loopback_device = -1;
+static mbtk_audio_service_error_cb_f service_error_cb = NULL;
+
 static void audio_play_thread(void *arg)
 {
     int rc, len, frames = 0;
@@ -118,13 +123,27 @@
         recorder_header.data_sz = recorver_data_count;
         recorder_header.riff_sz = recorder_header.data_sz + sizeof(recorder_header) - 8;
         lseek(wav_recorder_fd, 0, SEEK_SET);
-        write(wav_recorder_fd, &recorder_header, sizeof(struct wav_header));
+
+        if(sizeof(struct wav_header) == write(wav_recorder_fd, &recorder_header, sizeof(struct wav_header))) {
+            // Do nothting.
+        }
 
         close(wav_recorder_fd);
         wav_recorder_fd = -1;
     }
 }
 
+int mbtk_register_error_callback(mbtk_audio_service_error_cb_f cb)
+{
+    if (cb == NULL) {
+        LOGE("Error: Callback function is NULL.");
+        return -1;
+    }
+    service_error_cb = cb;
+    LOGD("Callback function registered successfully.");
+    return 0;
+}
+
 int mbtk_audio_wav_init()
 {
     //mbtk_log_init("radio", "MBTK_AUDIO");
@@ -162,7 +181,11 @@
         return -1;
     }
 
-    read(wav_play_fd, &riff_wave_header, sizeof(riff_wave_header));
+    if(sizeof(riff_wave_header) != read(wav_play_fd, &riff_wave_header, sizeof(riff_wave_header))) {
+        LOGE("%s: read riff_wave_header fail.", __FUNCTION__);
+        return -1;
+    }
+
     if ((riff_wave_header.riff_id != ID_RIFF) || (riff_wave_header.wave_id != ID_WAVE)) {
         LOGE("Error: '%s' is not a riff/wave file", path);
         close(wav_play_fd);
@@ -170,11 +193,17 @@
     }
 
     do {
-        read(wav_play_fd, &chunk_header, sizeof(chunk_header));
+        if(sizeof(chunk_header) != read(wav_play_fd, &chunk_header, sizeof(chunk_header))) {
+            LOGE("%s: read chunk_header fail.", __FUNCTION__);
+            return -1;
+        }
 
         switch (chunk_header.id) {
             case ID_FMT:
-                read(wav_play_fd, &chunk_fmt, sizeof(chunk_fmt));
+                if(sizeof(chunk_fmt) != read(wav_play_fd, &chunk_fmt, sizeof(chunk_fmt))) {
+                    LOGE("%s: read chunk_fmt fail.", __FUNCTION__);
+                    return -1;
+                }
                 /* If the format header is larger, skip the rest */
                 if (chunk_header.sz > sizeof(chunk_fmt))
                     lseek(wav_play_fd, chunk_header.sz - sizeof(chunk_fmt), SEEK_CUR);
@@ -338,7 +367,6 @@
 
 int mbtk_audio_wav_recorder_start(const void *wav_file, mbtk_audio_sample_rate_enum sample_rate)
 {
-    int rc;
     const char *path = (const char *)wav_file;
 
     LOGD("wav_file is %s.", path);
@@ -407,3 +435,49 @@
     return mbtk_audio_pcm_deinit();
 }
 
+int mbtk_audio_set_loopback_enable_state(int device, int enable_state)
+{
+    char command[128];
+
+    if (device < 0 || device > 2 || (enable_state != 0 && enable_state != 1)) {
+        LOGE("Invalid device or enable_state");
+        return -1;
+    }
+
+    snprintf(command, sizeof(command), "ubus call audio_if audio_mode_set '{\"param0\":0}'");
+    if (system(command) != 0) {
+        LOGE("Failed to set audio mode");
+        return -1;
+    }
+
+    if (enable_state == 1) {
+        snprintf(command, sizeof(command), "ubus call audio_if loopback_enable '{\"param0\":%d}'", device);
+        if (system(command) != 0) {
+            LOGE("Failed to enable loopback");
+            return -1;
+        }
+    } else {
+        if (system("ubus call audio_if loopback_disable") != 0) {
+            LOGE("Failed to disable loopback");
+            return -1;
+        }
+    }
+
+    current_loopback_device = device;
+    current_loopback_state = enable_state;
+
+    return 0;
+}
+
+int mbtk_audio_get_loopback_enable_state(int *device, int *enable_state)
+{
+    if (device == NULL || enable_state == NULL) {
+        LOGE("Null pointer provided for device or enable_state");
+        return -1;
+    }
+
+    *device = current_loopback_device;
+    *enable_state = current_loopback_state;
+
+    return 0;
+}
diff --git a/mbtk/libmbtk_lib_v2/coap/mbtk_coap.c b/mbtk/libmbtk_lib_v2/coap/mbtk_coap.c
index 226fd5c..2fd96a8 100755
--- a/mbtk/libmbtk_lib_v2/coap/mbtk_coap.c
+++ b/mbtk/libmbtk_lib_v2/coap/mbtk_coap.c
@@ -59,26 +59,29 @@
 static mbtk_ecoap_state_e mbtk_ecoap_state = MBTK_ECOAP_STATE_NON;

 

 //static uint16 mbtk_ecoap_curr_coap_id = 0;

-static char mbtk_ecoap_host[MBTK_ECOAP_NEW_MAX+1] = {'\0'};

+//static char mbtk_ecoap_host[MBTK_ECOAP_NEW_MAX+1] = {'\0'};

 

-static int mbtk_ecoap_port;

-static int mbtk_ecoap_is_dtls;

+//static int mbtk_ecoap_port;

+//static int mbtk_ecoap_is_dtls;

 static mbtk_ecoap_opt_2 mbtk_ecoap_option_2;

 static mbtk_ecoap_opt_3 mbtk_ecoap_option_3;

 static int mbtk_ecoap_recv = -1;

-static int mbtk_ecoap_cur_time =0;

+//static int mbtk_ecoap_cur_time =0;

 

 /*func------------------------*/

 void mbtk_ecoap_option_add(mbtk_ecoap_option_s *option);

 int mbtk_ecoap_list_del(uint16 message_id,int optDel);

-

+int mbtk_ecoap_get_message_type(void);

+void mbtk_ecoap_get_code(char *ptr);

 

 #define HEXCHAR(x) ((x >= '0' && x <= '9') || (x >= 'a' && x <= 'f') || (x >= 'A' && x <= 'F'))

 

 

 #if 1

 

+#ifndef toupper

 #define toupper(a)  ((((a) >= 'a') && ((a) <= 'z')) ? ((a) - 'a' + 'A') : (a))

+#endif

 

 void HexToStr(byte *pbDest, byte *pbSrc, int nLen)

 {

@@ -339,7 +342,7 @@
 	}

 }

 

-

+#if 0

 static int

 mbtk_ecoap_is_open()

 {

@@ -400,7 +403,7 @@
 {

 

 }

-

+#endif

 

 

 

@@ -638,7 +641,7 @@
                 break;

             }

             default:

-                printf("No such type:%s\n",option->type);

+                printf("No such type:%d\n",option->type);

                 break;

         }

     }

@@ -731,7 +734,7 @@
                 break;

             }

             default:

-                printf("No such type:%s\n",type);

+                printf("No such type:%d\n",type);

                 break;

         }

     }

@@ -919,8 +922,6 @@
 			type,

 			code,

 			mesageId);

-

-	return 0;

 }

 

 

@@ -947,8 +948,8 @@
         memcpy(token,coapGetRecvTokenPointer(),token_len);

         LOGE("token[%d]:%s\n",token_len,token);

 

-        uint16 playload_len = coapGetRecvPayloadLength();

-        uint8 *playload = coapGetRecvPayloadPointer();

+//        uint16 playload_len = coapGetRecvPayloadLength();

+//        uint8 *playload = coapGetRecvPayloadPointer();

 //        printf("----------------payload-----------------\n");

 //        coap_log(0,(char*)playload,playload_len);

 //        printf("--------------payload end----------------\n");

@@ -974,7 +975,7 @@
             mbtk_ecoap_package_s * coap_send = mbtk_ecoap_get_by_msg_id(message_id);

             if(coap_send != NULL)

             {

-                int number;

+                uint32_t number;

                 uint8_t more_flag;

                 uint8_t size;

                 LOGE("Get message(%d) ack.\n",message_id);

@@ -1055,7 +1056,7 @@
 

 }

 

-static int mbtk_ecoap_open(int open);

+//static int mbtk_ecoap_open(int open);

 

 

 

@@ -1098,7 +1099,7 @@
 )

 {

     int result = 0;

-	int rx_mod = mode;

+//	int rx_mod = mode;

 

     return result;

 }

@@ -1109,7 +1110,7 @@
 )

 {

     int result = 0;

-	uint16 ecoappr = format;

+//	uint16 ecoappr = format;

     return result;

 }

 

@@ -1119,7 +1120,7 @@
 )

 {

     int result = 0;

-	int get_len = len;

+//	int get_len = len;

 

     return result;

 

diff --git a/mbtk/libmbtk_lib_v2/coap/mbtk_coap_api.cpp b/mbtk/libmbtk_lib_v2/coap/mbtk_coap_api.cpp
index 0a6dc19..c864fe0 100755
--- a/mbtk/libmbtk_lib_v2/coap/mbtk_coap_api.cpp
+++ b/mbtk/libmbtk_lib_v2/coap/mbtk_coap_api.cpp
@@ -280,7 +280,7 @@
             strcpy(type, "Reset");

             break;

     }

-    char code[30];

+    char code[40];

     switch(g_CoapRecvPointer->getCode())

     {

         case COAP_EMPTY:

@@ -383,28 +383,28 @@
     uint8_t *tokenPointer = g_CoapRecvPointer->getPDUPointer()+COAP_HDR_SIZE;

     if(tokenLength==0)

     {

-        sprintf(outBuffer,"%sNo token\r\n",outBuffer);

+        sprintf(outBuffer + strlen(outBuffer),"No token\r\n");

     }

     else

     {

-        sprintf(outBuffer,"%sToken of %d bytes.\r\n"

+        sprintf(outBuffer + strlen(outBuffer),"Token of %d bytes.\r\n"

                 "Value: %s\r\n",

-                outBuffer,tokenLength, (char*)tokenPointer);

+                tokenLength, (char*)tokenPointer);

         for(int j=0; j<tokenLength; j++)

         {

-            sprintf(outBuffer,"%s%.2x",outBuffer, tokenPointer[j]);

+            sprintf(outBuffer + strlen(outBuffer),"%.2x", tokenPointer[j]);

         }

     }

     // print options

     CoapPDU::CoapOption* options = g_CoapRecvPointer->getOptions();

     if(options==NULL)

     {

-        sprintf(outBuffer,"\r\n%sNO options\r\n", outBuffer);

+        sprintf(outBuffer + strlen(outBuffer),"\r\nNO options\r\n");

     }

 

     for(int i=0; i<g_CoapRecvPointer->getNumOptions(); i++)

     {

-        char optionNumberBuffer[20];

+        char optionNumberBuffer[40];

         switch(options[i].optionNumber)

         {

             case COAP_OPTION_IF_MATCH:

@@ -479,12 +479,11 @@
             }

         }

         sprintf(optionValue,"%s\"\r\n",optionValue);*/

-        sprintf(outBuffer,"\r\n%sOPTION (%d/%d)\r\n"

+        sprintf(outBuffer + strlen(outBuffer),"\r\nOPTION (%d/%d)\r\n"

                 "Option number (delta): %hu (%hu)\r\n"

                 "Name: %s\r\n"

                 "Value length: %u\r\n"

                 "Value: \"%s",

-                outBuffer,

                 i + 1,g_CoapRecvPointer->getNumOptions(),

                 options[i].optionNumber,options[i].optionDelta,

                 optionNumberBuffer,

@@ -497,12 +496,12 @@
     // print payload

     if(g_CoapRecvPointer->getPayloadLength() == 0)

     {

-        sprintf(outBuffer,"%sNo payload\r\n", outBuffer);

+        sprintf(outBuffer + strlen(outBuffer),"No payload\r\n");

     }

     else

     {

-        sprintf(outBuffer, "%sPayload of %d bytes\r\n"

-                "Value: \"%s\"\r\n", outBuffer,

+        sprintf(outBuffer + strlen(outBuffer), "Payload of %d bytes\r\n"

+                "Value: \"%s\"\r\n",

                 g_CoapRecvPointer->getPayloadLength(),

                 (char *)g_CoapRecvPointer->getPayloadPointer());

         /*sprintf(outBuffer,"%sPayload of %d bytes\r\n", outBuffer,g_CoapRecvPointer->getPayloadLength());

@@ -867,12 +866,12 @@
     else

     {

         uint8_t* payloadPointer = g_CoapRecvPointer->getPayloadPointer();

-        sprintf(out,"%s:%d\r\n",out, payloadLength*2);

+        sprintf(out + strlen(out),":%d\r\n",payloadLength*2);

         for(int j=0; j<payloadLength; j++)

         {

-            sprintf(out,"%s%.2X",out,payloadPointer[j]);

+            sprintf(out + strlen(out),"%.2X", payloadPointer[j]);

         }

-        sprintf(out,"%s\r\n",out);

+        sprintf(out + strlen(out),"\r\n");

         return 1;

     }

 }

diff --git a/mbtk/libmbtk_lib_v2/common/mbtk_adc.c b/mbtk/libmbtk_lib_v2/common/mbtk_adc.c
index 55cce7c..601d9b0 100755
--- a/mbtk/libmbtk_lib_v2/common/mbtk_adc.c
+++ b/mbtk/libmbtk_lib_v2/common/mbtk_adc.c
@@ -16,6 +16,9 @@
 #include <sys/stat.h>
 #include <sys/statfs.h>
 #include <sys/types.h>
+#include <unistd.h>
+#include <stdlib.h>
+
 #include "mbtk_log.h"
 #include "mbtk_type.h"
 #include "mbtk_adc.h"
diff --git a/mbtk/libmbtk_lib_v2/common/mbtk_at.c b/mbtk/libmbtk_lib_v2/common/mbtk_at.c
index 8721a52..8262756 100755
--- a/mbtk/libmbtk_lib_v2/common/mbtk_at.c
+++ b/mbtk/libmbtk_lib_v2/common/mbtk_at.c
@@ -15,12 +15,15 @@
 #include "mbtk_log.h"
 
 #define MBTK_AT_SOCK "/tmp/atcmd_at"
+
+#ifndef TEMP_FAILURE_RETRY
 #define TEMP_FAILURE_RETRY(exp) ({         \
     typeof (exp) _rc;                      \
     do {                                   \
         _rc = (exp);                       \
     } while (_rc == -1 && errno == EINTR); \
     _rc; })
+#endif
 
 static char *at_rsp_complete_tag[] = {
         "OK",
diff --git a/mbtk/libmbtk_lib_v2/common/mbtk_bs_position.c b/mbtk/libmbtk_lib_v2/common/mbtk_bs_position.c
index 0119ae5..0b1d6e3 100755
--- a/mbtk/libmbtk_lib_v2/common/mbtk_bs_position.c
+++ b/mbtk/libmbtk_lib_v2/common/mbtk_bs_position.c
@@ -245,7 +245,6 @@
 
 struct mbtk_bs_ubus_t *bs_ril_init(struct mbtk_bs_ubus_t *bs)
 {
-	int ret;
 
 	mbtk_bs_ubus = malloc(sizeof(struct mbtk_bs_ubus_t));
 	if (!mbtk_bs_ubus) {
diff --git a/mbtk/libmbtk_lib_v2/common/mbtk_debug.c b/mbtk/libmbtk_lib_v2/common/mbtk_debug.c
index e9280c9..23e8431 100755
--- a/mbtk/libmbtk_lib_v2/common/mbtk_debug.c
+++ b/mbtk/libmbtk_lib_v2/common/mbtk_debug.c
@@ -28,6 +28,8 @@
 #include <time.h>
 #include <sys/time.h>
 #include <stdarg.h>
+#include <execinfo.h>
+#include <cutils/properties.h>
 
 #include "mbtk_type.h"
 #include "mbtk_log.h"
@@ -57,7 +59,7 @@
 
 
 static char proc_name[100];
-static char proc_dump_name[100];
+static char proc_dump_name[100 * 2];
 static int proc_dump_fd = -1;
 
 #ifdef HAS_ULSLIB
@@ -85,7 +87,9 @@
         tmp++;
         *tmp = '\n';
 
-        write(proc_dump_fd, buf, strlen(buf));
+        if(write(proc_dump_fd, buf, strlen(buf)) != strlen(buf)) {
+            // Do nothing.
+        }
 
         va_end(ap);
     }
@@ -264,7 +268,7 @@
 
 #if 1
 #define BACKTRACE_SIZE 32
-void sigsegv_handler_with_thread(int signo) {
+void sigsegv_handler_with_thread(int signo,siginfo_t *info, void *context) {
     struct timeval log_time;
     char tmp[50] = {0};
     gettimeofday(&log_time, NULL);
diff --git a/mbtk/libmbtk_lib_v2/common/mbtk_gpio.c b/mbtk/libmbtk_lib_v2/common/mbtk_gpio.c
index d80b014..d861e3e 100755
--- a/mbtk/libmbtk_lib_v2/common/mbtk_gpio.c
+++ b/mbtk/libmbtk_lib_v2/common/mbtk_gpio.c
@@ -12,7 +12,7 @@
 #include "mbtk_gpio.h"
 
 
-int gpio_export(int gpio)
+int mbtk_gpio_export(int gpio)
 {
     int fd = -1;
     char buffer[50];
@@ -44,7 +44,7 @@
     return 0;
 }
 
-int gpio_unexport(int gpio)
+int mbtk_gpio_unexport(int gpio)
 {
     int fd = -1;
     char buffer[50];
@@ -115,7 +115,7 @@
     int fd = -1;
     int ret = 0;
 
-    if(gpio_export(gpio)) {
+    if(mbtk_gpio_export(gpio)) {
         return -1;
     }
 
@@ -161,6 +161,7 @@
         return -1;
     }
 
+    memset(buffer, 0, sizeof(buffer));
     if(read(fd, buffer, sizeof(buffer)) <= 0)
     {
         LOGE("Get gpio[%d] value fail", gpio);
@@ -178,7 +179,7 @@
     int fd = -1;
     int ret =-1;
 
-    if(gpio_export(gpio)) {
+    if(mbtk_gpio_export(gpio)) {
         return -1;
     }
 
@@ -210,3 +211,34 @@
     }
 }
 
+int mbtk_gpio_value_set_2(int gpio, int value)
+{
+    char buffer[50]= {0};
+    int file =-1;
+    int result =-1;
+
+    memset(buffer,0,50);
+    sprintf(buffer,"/sys/class/gpio/gpio%d/value", gpio);
+    file = open(buffer,O_WRONLY);
+    if(file == -1)
+    {
+        LOGE("Open gpio[%d] value fail.", gpio);
+        return -1;
+    }
+    if(value == 0) {
+        result = write(file,"0",1);
+    } else {
+        result = write(file,"1",1);
+    }
+    if(result != 1)
+    {
+        LOGE("Set gpio[%d] value fail err =%d.", gpio, errno);
+        close(file);
+        return -1;
+    }
+    close(file);
+
+    return 0;
+}
+
+
diff --git a/mbtk/libmbtk_lib_v2/common/mbtk_log.c b/mbtk/libmbtk_lib_v2/common/mbtk_log.c
index fcdf0b1..ab599b4 100755
--- a/mbtk/libmbtk_lib_v2/common/mbtk_log.c
+++ b/mbtk/libmbtk_lib_v2/common/mbtk_log.c
@@ -21,6 +21,8 @@
 #include "mbtk_log.h"
 #include "mbtk_str.h"
 
+// extern char *__progname;
+
 typedef enum {
     LOG_ID_MAIN = 0,
     LOG_ID_RADIO = 1,
@@ -35,11 +37,13 @@
 static int tlog_fd = -1;
 // Default for radio log.
 static int syslog_radio_enable = 2;
-static FILE* logfile = NULL;
+//static FILE* logfile = NULL;
 static int signal_fd = -1;
 
 static bool log_level_printed = FALSE;
 
+static bool log_init = FALSE;
+
 /**
  * @brief      mbtk_log_init
  *
@@ -60,6 +64,12 @@
  */
 void mbtk_log_init(char* path, char* tag)
 {
+    if(log_init) {
+        return;
+    } else {
+        log_init = TRUE;
+    }
+
     if (str_empty(path)) {
         tlog_fd = STDOUT_FILENO;
     } else if (0 == memcmp(path, "syslog", 6)) {
@@ -88,6 +98,31 @@
     va_list ap;
     struct timeval log_time;
     int length = 0;
+    int ret = 0;
+
+    if(!log_init) {
+        char filename[64] = {0};
+        int fd = open("/proc/self/comm", O_RDONLY);
+        if(fd > 0) {
+            if(read(fd, filename, sizeof(filename)) > 0) {
+                // Delete last '\r' / '\n' / ' '
+                char *ptr = filename + strlen(filename) - 1;
+                while(ptr >= filename && (*ptr == '\r' || *ptr == '\n' || *ptr == ' '))
+                {
+                    *ptr-- = '\0';
+                }
+
+                mbtk_log_init("radio", filename);
+            } else {
+                mbtk_log_init("radio", "MBTK");
+            }
+            close(fd);
+        } else {
+            mbtk_log_init("radio", "MBTK");
+        }
+
+        //mbtk_log_init("radio", __progname);
+    }
 
     va_start(ap, format);
     length = vsnprintf(buf, sizeof(buf), format, ap);
@@ -111,10 +146,13 @@
         struct tm* tm_t = localtime(&(log_time.tv_sec));
         strftime(tmp, 50, "%F %T", tm_t);
         snprintf(tmp + strlen(tmp), sizeof(tmp) - strlen(tmp), " %d<%d>:", (int)(log_time.tv_usec / 1000), level);
-        write(tlog_fd, tmp, strlen(tmp));
-        write(tlog_fd, buf, length);
+        ret = write(tlog_fd, tmp, strlen(tmp));
+        ret = write(tlog_fd, buf, length);
         if (buf[length - 1] != '\n') {
-            write(tlog_fd, "\n", 1);
+            ret = write(tlog_fd, "\n", 1);
+            if(ret) {
+                // Donothing.
+            }
         }
         if (tlog_fd > 2) {
             fsync(tlog_fd);
@@ -164,7 +202,6 @@
     char buff[256];
     int size = 0;
     int ret = 0;
-    int i = 0;
     static struct sockaddr_un srv_addr;
 
     if(signal_fd < 0) {
diff --git a/mbtk/libmbtk_lib_v2/common/mbtk_ntp.c b/mbtk/libmbtk_lib_v2/common/mbtk_ntp.c
index 5b23e37..704643a 100755
--- a/mbtk/libmbtk_lib_v2/common/mbtk_ntp.c
+++ b/mbtk/libmbtk_lib_v2/common/mbtk_ntp.c
@@ -72,14 +72,12 @@
 {
     char version = 1;
     long tmp_wrd;
-    int port;
     time_t timer;
     strcpy(protocol, NTPV4);
     /*判断协议版本*/
     if(!strcmp(protocol, NTPV1)||!strcmp(protocol, NTPV2)||!strcmp(protocol, NTPV3)||!strcmp(protocol, NTPV4))
     {
         memset(packet, 0, NTP_PCK_LEN);
-        port = NTP_PORT;
         /*设置 16 字节的包头*/
         version = protocol[5] - 0x30;
         tmp_wrd = htonl((LI << 30)|(version << 27) \
@@ -102,7 +100,6 @@
     }
     else if (!strcmp(protocol, TIME))/* "TIME/UDP" */
     {
-        port = TIME_PORT;
         memset(packet, 0, 4);
         return 4;
     }
@@ -117,7 +114,7 @@
     struct timeval block_time;
     char data[NTP_PCK_LEN * 8];
     socklen_t data_len = addr->ai_addrlen;
-    int packet_len, count = 0, result, i,re;
+    int packet_len, count = 0, result;
 
     /* 组织请求报文 */
     if (!(packet_len = construct_packet(data)))
diff --git a/mbtk/libmbtk_lib_v2/common/mbtk_utils.c b/mbtk/libmbtk_lib_v2/common/mbtk_utils.c
index fe4d716..afade99 100755
--- a/mbtk/libmbtk_lib_v2/common/mbtk_utils.c
+++ b/mbtk/libmbtk_lib_v2/common/mbtk_utils.c
@@ -561,9 +561,56 @@
         }
     }
 
-    ftruncate(fd, 0);
+    if(ftruncate(fd, 0)) {
+        LOGE("ftruncate(0) fail.");
+        return -1;
+    }
+
     sprintf(buff, "%ld", (long)getpid());
-    write(fd, buff, strlen(buff) + 1);
-    return 0;
+    if(write(fd, buff, strlen(buff) + 1) == strlen(buff) + 1) {
+        return 0;
+    } else {
+        return -1;
+    }
+}
+
+void mbtk_system(const void* cmd)
+{
+    if(cmd) {
+        int ret = system(cmd);
+        if(ret == -1 || ret == 127) {
+            LOGD("system(%s) fail.", cmd);
+        }
+    }
+}
+
+void mbtk_write(int fd,const void *buf, size_t len)
+{
+    if(fd >= 0 && buf) {
+        int ret = write(fd, buf, len);
+        if(ret < 0) {
+            LOGD("write() fail:%d", errno);
+        }
+    }
+}
+
+void mbtk_read(int fd,void *buf, size_t len)
+{
+    if(fd >= 0 && buf) {
+        int ret = read(fd, buf, len);
+        if(ret < 0) {
+            LOGD("read() fail:%d", errno);
+        }
+    }
+}
+
+void mbtk_close(int fd)
+{
+    if(fd >= 0) {
+        int ret = close(fd);
+        if(ret < 0) {
+            LOGD("close() fail:%d", errno);
+        }
+    }
 }
 
diff --git a/mbtk/libmbtk_lib_v2/fota/mbtk_fota.c b/mbtk/libmbtk_lib_v2/fota/mbtk_fota.c
index 68e2ba0..6d5d3e8 100755
--- a/mbtk/libmbtk_lib_v2/fota/mbtk_fota.c
+++ b/mbtk/libmbtk_lib_v2/fota/mbtk_fota.c
@@ -8,12 +8,23 @@
 #include <pthread.h>

 #include <libubox/blobmsg_json.h>

 #include "libubus.h"

-#include "mbtk_fota.h"

+

 #include <semaphore.h>

 #include <cutils/properties.h>

+#include <libubox/blob.h>

+#include <libubox/uloop.h>

+#include <libubox/usock.h>

+#include <libubox/list.h>

+#include <libubus.h>

+#include <uci.h>

 

+#include <sys/ioctl.h>

+#include <mtd/mtd-user.h>

+

+#include "mbtk_fota.h"

 #include "mbtk_log.h"

-

+#include "mbtk_utils.h"

+#include "mbtk_type.h"

 

 #ifdef DEBUG

     #define fota_log(...)                    printf(__VA_ARGS__)

@@ -21,7 +32,6 @@
     #define fota_log(...)

 #endif

 

-#define UNUSEDPARAM(param) (void)param;

 #define OTA_MAX_STRING_LEN	128

 

 static struct ubus_context    *fota_ubus_ctx = NULL;

@@ -154,7 +164,7 @@
     if(!access("/sys/power/wake_lock", W_OK))

     {

         sprintf(cmd, "echo %s > /sys/power/wake_lock", "ota_lock");

-        system(cmd);

+        mbtk_system(cmd);

         LOGE("/sys/power/wake_lock success\n");

     }

     else

@@ -192,7 +202,7 @@
     {

         char cmd[128]={0};

         sprintf(cmd, "echo %s > /sys/power/wake_unlock", "ota_lock");

-        system(cmd);

+        mbtk_system(cmd);

         LOGE("/sys/power/wake_unlock success\n");

     }

     else

@@ -236,7 +246,7 @@
     if(!access("/sys/power/wake_lock", W_OK))

     {

         sprintf(cmd, "echo %s > /sys/power/wake_lock", "ota_lock");

-        system(cmd);

+        mbtk_system(cmd);

         LOGE("/sys/power/wake_lock success\n");

     }

     else

@@ -275,7 +285,7 @@
     {

         char cmd[128]={0};

         sprintf(cmd, "echo %s > /sys/power/wake_unlock", "ota_lock");

-        system(cmd);

+        mbtk_system(cmd);

         LOGE("/sys/power/wake_unlock success\n");

     }

     else

@@ -325,8 +335,8 @@
     fota_cb = NULL;

 

     if (is_reboot) {

-        system("sync");

-        system("reboot");

+        mbtk_system("sync");

+        mbtk_system("reboot");

     }

     return 0;

 

@@ -335,15 +345,15 @@
 int mbtk_fota_done1(int is_reboot)

 {

     if (is_reboot) {

-        system("sync");

-        system("reboot");

+        mbtk_system("sync");

+        mbtk_system("reboot");

     }

     return 0;

 }

 

 void* mbtk_fota_thread(void* argc)

 {

-    int ret, retries = 0;

+    int ret;

     UNUSEDPARAM(argc);

 

     printf("mbtk_fota_thread() start\n");

@@ -368,7 +378,6 @@
 

 int mbtk_fota_init(fota_callback cb)

 {

-    int id;

     int retries = 0;

 

     /*create ubus loop to listen to RIL event*/

@@ -425,3 +434,73 @@
     MBTK_SOURCE_INFO_PRINT("mbtk_fota_lib");

 }

 

+int mbtk_fota_get_active_absys_type(void)

+{

+    int type = 0;

+    char tmp_type[] ={0};

+

+    property_get("persist.mbtk.absys_active", tmp_type, "0");

+    type = atoi(tmp_type);

+    if (type == 97)

+    {

+        type = mbtk_sys_A;

+    }

+    else if (type == 98)

+    {

+        type = mbtk_sys_B;

+    }

+    else

+    {

+        LOGE("get_active_absys_type %s fail",tmp_type);

+        type = -1;

+    }

+

+    return type;

+}

+

+int mbtk_fota_get_tmp_absys_type(void)

+{

+    int type = 0;

+    char tmp_type[] ={0};

+

+    property_get("persist.mbtk.absys_tmp", tmp_type, "0");

+    type = atoi(tmp_type);

+    if (type == 97)

+    {

+        type = mbtk_sys_A;

+    }

+    else if (type == 98)

+    {

+        type = mbtk_sys_B;

+    }

+    else

+    {

+        LOGE("get_tmp_absys_type %s fail",tmp_type);

+        type = -1;

+    }

+

+    return type;

+}

+

+int mbtk_fota_get_sync_absys_type(void)

+{

+    int type = 0;

+    char tmp_type[] ={0};

+

+    property_get("persist.mbtk.absys_sync", tmp_type, "0");

+    type = atoi(tmp_type);

+

+    return type;

+}

+

+int mbtk_fota_get_mtd_check_type(void)

+{

+    int type = 0;

+    char tmp_type[] ={0};

+

+    property_get("persist.mbtk.mtd_check", tmp_type, "0");

+    type = atoi(tmp_type);

+

+    return type;

+}

+

diff --git a/mbtk/libmbtk_lib_v2/ftp/mbtk_ftp.c b/mbtk/libmbtk_lib_v2/ftp/mbtk_ftp.c
index f485ec7..69208d6 100755
--- a/mbtk/libmbtk_lib_v2/ftp/mbtk_ftp.c
+++ b/mbtk/libmbtk_lib_v2/ftp/mbtk_ftp.c
@@ -6,12 +6,14 @@
  Date:
  2020/10/28 11:49:08
  *************************************************************/
+#include <ctype.h>
+
 #include "mbtk_ftp.h"
 #include "mbtk_list.h"
 #include "mbtk_sock.h"
 #include "mbtk_str.h"
 #include "mbtk_sock2.h"
-#include<linux/msg.h>
+#include <linux/msg.h>
 
 /*************************************************************
  Constants and Macros
@@ -105,12 +107,12 @@
     return ptr;
 }
 
-static int ftp_cmd_handle(mbtk_ftp_info_s *info, const void *cmd, void *rsp,
+static int ftp_cmd_handle(mbtk_ftp_info_s *info, void *cmd, void *rsp,
                           uint32 *rsp_len)
 {
     int err;
     int rsp_code;
-    int len = strlen((char*) cmd);
+    unsigned int len = strlen((char*) cmd);
     // Write cmd
     if(info->auth_type != 0)
     {
@@ -144,13 +146,13 @@
             {
                 printf("\n mbtk_sock_read error:%d \n",err);
             }
-            rsp_code = atoi(mbtk_ftp_ssl_read_buf);
+            rsp_code = atoi((char*)mbtk_ftp_ssl_read_buf);
             printf("%s -> Code:%d; RSP:%s\n", (char*)cmd, rsp_code, (char* )mbtk_ftp_ssl_read_buf);
             if (rsp_code == 0)
             {
                 goto read_angin_1;
             }
-            memcpy((char* )rsp, mbtk_ftp_ssl_read_buf, strlen(mbtk_ftp_ssl_read_buf));
+            memcpy((char* )rsp, mbtk_ftp_ssl_read_buf, strlen((char*)mbtk_ftp_ssl_read_buf));
             //printf("\nrsp = %s\n",(char* )rsp);
             return rsp_code;
         }
@@ -182,7 +184,7 @@
         memset(buff, 0x0, 1024);
         if(info->auth_type != 0)
         {
-            unsigned char mbtk_ftp_ssl_read_buf[16384 + 1];
+            char mbtk_ftp_ssl_read_buf[16384 + 1];
             len = mbtk_sock_read(info->ftp_ssl_handle,info->session,mbtk_ftp_ssl_read_buf,sizeof(mbtk_ftp_ssl_read_buf),FTP_TIMEOUT,&err);
             if(err != 0)
             {
@@ -190,9 +192,8 @@
             }
             rsp_code = atoi(mbtk_ftp_ssl_read_buf);
             printf("%s -> Code:%d; RSP:%s\n", (char*)cmd, rsp_code, (char* )mbtk_ftp_ssl_read_buf);
-            char *mbtk_ftp_ssl_read_buf_p = NULL;
-            mbtk_ftp_ssl_read_buf_p = strstr(mbtk_ftp_ssl_read_buf,"\n");
-            if(mbtk_ftp_ssl_read_buf_p!=NULL);
+            char *mbtk_ftp_ssl_read_buf_p = strstr(mbtk_ftp_ssl_read_buf,"\n");
+            if(mbtk_ftp_ssl_read_buf_p!=NULL)
             {
                 if(strlen(mbtk_ftp_ssl_read_buf_p)>1)
                 {
@@ -374,7 +375,7 @@
     }
 
     // Get IPv4 and port
-    uint8 *ptr = rsp + 4;
+    char *ptr = (char*)rsp + 4;
     while (*ptr)
     {
         if (isdigit(*ptr))
@@ -383,7 +384,7 @@
     }
     // ptr point to first digit.
     memcpy(sock->host, ptr, strlen((char*) ptr));
-    ptr = sock->host;
+    ptr = (char*)(sock->host);
     int count = 0;
     while (*ptr)
     {
@@ -601,7 +602,7 @@
             if (strlen(name) > 0)
             {
                 LOGV("Name:%s",name);
-                memset(file_ptr.name,0,strlen(file_ptr.name)+1);
+                memset(file_ptr.name,0,strlen((char*)(file_ptr.name))+1);
                 memcpy(file_ptr.name, name, strlen(name));
                 char *temp = (char*) file_ptr.name
                              + strlen((char*) file_ptr.name) - 1;
@@ -682,7 +683,7 @@
             if (strlen(name) > 0)
             {
                 LOGV("Name:%s",name);
-                memset(file_ptr.name,0,strlen(file_ptr.name)+1);
+                memset(file_ptr.name,0,strlen((char*)file_ptr.name)+1);
                 memcpy(file_ptr.name, name, strlen(name));
                 char *temp = (char*) file_ptr.name
                              + strlen((char*) file_ptr.name) - 1;
@@ -930,8 +931,8 @@
             info->ftp_sock_ssl_info_data->ftp_ssl_support=1;
             info->ftp_sock_ssl_info_data->port = sock.port;
             info->ftp_sock_ssl_info_data->type = MBTK_SOCK_TCP;
-            info->ftp_sock_ssl_info_data->ingnore_cert = ~(info->sock_info[FTP_SOCK_CTRL].use_cert);
-            memcpy(info->ftp_sock_ssl_info_data->address, sock.host, strlen(sock.host));
+            info->ftp_sock_ssl_info_data->ingnore_cert = !(info->sock_info[FTP_SOCK_CTRL].use_cert);
+            memcpy(info->ftp_sock_ssl_info_data->address, sock.host, strlen((char*)sock.host));
             if(info->ftp_sock_ssl_info_data->is_support_ssl != 0)
             {
                 info->ftp_sock_ssl_info_data->is_support_ssl = 0;
@@ -1015,12 +1016,12 @@
 
     if (cmd == FTP_CMD_GET)   // Is download
     {
-        char cmd[100];
+        char cmd[200];
         if (info->file_trans.size_send > 0)   // Resume transmission
         {
             // REST size
-            memset(cmd, 0x0, 100);
-            snprintf(cmd, 100, "REST %ld\r\n", info->file_trans.size_send);
+            memset(cmd, 0x0, sizeof(cmd));
+            snprintf(cmd, sizeof(cmd), "REST %d\r\n", info->file_trans.size_send);
             code = ftp_cmd_handle(info, cmd, NULL, NULL);
             if (code != 350)
             {
@@ -1030,8 +1031,8 @@
             }
         }
 
-        memset(cmd, 0x0, 100);
-        snprintf(cmd, 100, "RETR %s\r\n", info->file_trans.remote_name);
+        memset(cmd, 0x0, sizeof(cmd));
+        snprintf(cmd, sizeof(cmd), "RETR %s\r\n", info->file_trans.remote_name);
         code = ftp_cmd_handle(info, cmd, NULL, NULL);
         if (code != 125 && code != 150)
         {
@@ -1072,9 +1073,9 @@
         if(info->auth_type != 0)
         {
                 int mbtk_errno;
-                char cmd[100];
-                memset(cmd, 0x0, 100);
-                snprintf(cmd, 100, "STOR %s\r\n", info->file_trans.remote_name);
+                char cmd[200];
+                memset(cmd, 0x0, sizeof(cmd));
+                snprintf(cmd, sizeof(cmd), "STOR %s\r\n", info->file_trans.remote_name);
         		LOGE("STOR %s .name:%s ", cmd, info->file_trans.remote_name);
                 code = ftp_cmd_handle(info, cmd, NULL, NULL);
                 if (code != 125 && code != 150)
@@ -1106,9 +1107,9 @@
         }
         else
         {
-            char cmd[100];
-            memset(cmd, 0x0, 100);
-            snprintf(cmd, 100, "STOR %s\r\n", info->file_trans.remote_name);
+            char cmd[200];
+            memset(cmd, 0x0, sizeof(cmd));
+            snprintf(cmd, sizeof(cmd), "STOR %s\r\n", info->file_trans.remote_name);
     		LOGE("STOR %s .name:%s ", cmd, info->file_trans.remote_name);
             code = ftp_cmd_handle(info, cmd, NULL, NULL);
             if (code != 125 && code != 150)
@@ -1827,7 +1828,7 @@
     info->file_trans.size_count = 0;
     info->file_trans.size_send = 0;
 
-    char line_buf[1024];
+//    char line_buf[1024];
     if(info->auth_type != 0)
         len = mbtk_sock_read(info->ftp_ssl_handle,info->session,buff,sizeof(buff),FTP_TIMEOUT,&err);
     else
@@ -2212,7 +2213,7 @@
                 unsigned char mbtk_ftp_ssl_read_buf[16384 + 1];
                 char cmd[50];
                 memset(cmd,0,50);
-                int len_ssl;
+//                int len_ssl;
 
 
                 memset(cmd,0,50);
@@ -2272,7 +2273,7 @@
                             &mbtk_errno);
                 printf("\nmbtk_sock_read PASS:\n%s\n",mbtk_ftp_ssl_read_buf);
                 char *ptr = NULL;
-                if((ptr = strstr(mbtk_ftp_ssl_read_buf,"220 ")) || (ptr = strstr(mbtk_ftp_ssl_read_buf,"230 "))) {
+                if((ptr = strstr((char*)mbtk_ftp_ssl_read_buf,"220 ")) || (ptr = strstr((char*)mbtk_ftp_ssl_read_buf,"230 "))) {
                     LOGI("RSP:%s",ptr);
                     printf("RSP:%s\n",ptr);
                 }
@@ -2375,16 +2376,16 @@
                                     int *port,int iptype)
 {
     char psz_port_cmd[128];
-    int i=0;
+//    int i=0;
 
     *port = rand() % (60000 - 50000 + 1) + 50000;
     sprintf(psz_port_cmd, "netstat -an | grep :%d > /dev/null", *port);
 
-        char ipBuf[32] = "";
+        char ipBuf[1024] = {0};
         FILE *fstream=NULL;
 
-        char buff[1024];
-        char iptype_str[8];
+        char buff[1024] = {0};
+//        char iptype_str[8];
         memset(buff,0,sizeof(buff));
         /*eth0可以换成eth1、docker0、em1、lo等*/
         if(iptype == MBTK_ADDR_IPV6)
@@ -2396,7 +2397,7 @@
             }
             if(NULL!=fgets(buff, sizeof(buff), fstream))
             {
-                snprintf(ipBuf, 39, "%s",buff);
+                snprintf(ipBuf, sizeof(buff), "%s",buff);
             }
             else
             {
@@ -2412,7 +2413,7 @@
             }
             if(NULL!=fgets(buff, sizeof(buff), fstream))
             {
-                snprintf(ipBuf, 18, "%s",buff);
+                snprintf(ipBuf, sizeof(ipBuf), "%s",buff);
             }
             else
             {
diff --git a/mbtk/libmbtk_lib_v2/ftp/mbtk_ftp_at.c b/mbtk/libmbtk_lib_v2/ftp/mbtk_ftp_at.c
index 3541e2b..958b0d0 100755
--- a/mbtk/libmbtk_lib_v2/ftp/mbtk_ftp_at.c
+++ b/mbtk/libmbtk_lib_v2/ftp/mbtk_ftp_at.c
@@ -11,7 +11,7 @@
 #include "mbtk_sock.h"
 #include "mbtk_str.h"
 #include "mbtk_sock2.h"
-#include<linux/msg.h>
+#include <sys/msg.h>
 
 /*************************************************************
  typedef struct:local at
@@ -38,7 +38,7 @@
 /*************************************************************
  Variables:local
  *************************************************************/
-static list_node_t *ftp_client_list = NULL;
+// static list_node_t *ftp_client_list = NULL;
 
 /*************************************************************
  Variables:public
@@ -328,7 +328,7 @@
 void mbtk_at_ftp_data_cb(void *data, uint32 data_len)
 {
     char resp_buf[2150];
-    printf("\n=====data_cb data[%s]=====\n=====data_cb data_len[%d]=====\n",data, data_len);
+    printf("\n=====data_cb data[%s]=====\n=====data_cb data_len[%d]=====\n",(char*)data, data_len);
 
     memset(resp_buf,0,2150);
     sprintf(resp_buf, "+CFTPGET:");
@@ -370,7 +370,7 @@
 {
 
     int at_ftp_ret=-1;
-    int len_size;
+//    int len_size;
 
     mbtk_at_ftp_par_at.at_ftp_handle = mbtk_ftp_init(mbtk_at_ftp_par_at.host, mbtk_at_ftp_par_at.port, mbtk_at_ftp_par_at.auth_type,
                                     0, mbtk_at_ftp_par_at.use_cert);
@@ -399,7 +399,7 @@
     uint32 len;
     int download_time = 0;
     char resp_buf[1024];
-    int ret;
+//    int ret;
 
     uint32 file_size = mbtk_ftp_file_size(mbtk_at_ftp_par_at.at_ftp_handle, remote_path);
     if(file_size > 0)
@@ -510,7 +510,7 @@
 
 void ftp_ls_at_cb_func(void *file_list_cb)
 {
-    int ret;
+//    int ret;
     char resp_buf[1024 + 1];
     printf("+CFTPLIST:\r\n%s\n", ((mbtk_ftp_file_info_s *)file_list_cb)->name);
     sprintf(resp_buf, "%s",((mbtk_ftp_file_info_s *)file_list_cb)->name);
@@ -522,7 +522,7 @@
 int mbtk_at_ftp_list(char *ftp_path)
 {
     int at_ftp_ret=-1;
-    int len_size;
+//    int len_size;
     char resp_buf[1024];
 
     mbtk_at_ftp_par_at.at_ftp_handle = mbtk_ftp_init(mbtk_at_ftp_par_at.host, mbtk_at_ftp_par_at.port, mbtk_at_ftp_par_at.auth_type,
diff --git a/mbtk/libmbtk_lib_v2/gnss/mbtk_gnss.c b/mbtk/libmbtk_lib_v2/gnss/mbtk_gnss.c
index cf9af27..707b9de 100755
--- a/mbtk/libmbtk_lib_v2/gnss/mbtk_gnss.c
+++ b/mbtk/libmbtk_lib_v2/gnss/mbtk_gnss.c
@@ -46,7 +46,7 @@
 extern long timezone;
 #endif
 
-static int sock_read(int fd, uint8 *msg, int data_len)
+static int sock_read(int fd, void *msg, int data_len)
 {
     memset(msg, 0, data_len);
     int len = 0;
@@ -89,7 +89,7 @@
     }
 }
 
-static int sock_write(int fd, uint8 *msg, int data_len)
+static int sock_write(int fd, void *msg, int data_len)
 {
     int len = 0;
     int write_len = 0;
@@ -161,6 +161,7 @@
     return 0;
 }
 
+#if 0
 static int str2int( const char* head, const char* end )
 {
     int result = 0;
@@ -185,6 +186,7 @@
 Fail:
     return -1;
 }
+#endif
 
 static double str2float( const char* head, const char* end )
 {
@@ -366,7 +368,6 @@
 
 static int nmea_update_latlong(mbtk_gnss_location_info_t* locl_info, mbtk_token         latitude, mbtk_token longitude)
 {
-    double   lat, lon;
     mbtk_token    tok;
     tok = latitude;
     if (tok.head + 6 > tok.end)
@@ -517,7 +518,7 @@
 #if MBTK_GNSS_LOG_ENABLED
                     LOGD("gnss_cb: [%p], locl_info.flags [%d]", gnss_cb, locl_info.flags);
 #endif
-                    if(locl_info.flags == GNSS_LOCATION_HAS_ALL) {
+                    if(ret == 0 && locl_info.flags == GNSS_LOCATION_HAS_ALL) {
                         gnss_cb(MBTK_GNSS_IND_LOCATION, &locl_info, sizeof(mbtk_gnss_location_info_t));
                         locl_info.flags = 0;
                     }
@@ -712,7 +713,9 @@
     }
 
     if(exit_fd[1] > 0) {
-        write(exit_fd[1], "EXIT", 4);
+        if(4 != write(exit_fd[1], "EXIT", 4)) {
+            LOGE("write EXIT fail.");
+        }
     }
 
     int ret = pthread_join(read_thread_id, NULL);
diff --git a/mbtk/libmbtk_lib_v2/http/mbtk_http_base.c b/mbtk/libmbtk_lib_v2/http/mbtk_http_base.c
index 6fbf898..ab4b0ef 100755
--- a/mbtk/libmbtk_lib_v2/http/mbtk_http_base.c
+++ b/mbtk/libmbtk_lib_v2/http/mbtk_http_base.c
@@ -4,8 +4,6 @@
 #include "mbtk_log.h"
 #include "mbtk_http_base.h"
 
-static void http_sock_cb_func(mbtk_sock_handle handle, mbtk_sock_cb_info_s *sock_info);
-
 static bool http_sock_inited = FALSE;
 static mbtk_sock_handle http_handle = -1;
 static mbtk_sock_session http_fd = -1;
@@ -23,6 +21,7 @@
     }
 }
 
+
 int mbtk_http_init()
 {
     if(http_sock_inited) {
diff --git a/mbtk/libmbtk_lib_v2/mqtt/MQTTClient.c b/mbtk/libmbtk_lib_v2/mqtt/MQTTClient.c
index 4a349a7..b197a85 100755
--- a/mbtk/libmbtk_lib_v2/mqtt/MQTTClient.c
+++ b/mbtk/libmbtk_lib_v2/mqtt/MQTTClient.c
@@ -79,7 +79,7 @@
 
 void mbtk_ali_auth_regnwl_sava(MQTTMessage msg)
 {
-    printf("pub, payload: %d,%s\n", msg.payloadlen, msg.payload);
+    printf("pub, payload: %d,%s\n", msg.payloadlen, (char*)msg.payload);
     int32_t res = SUCCESS;
 
     char *client_key = "clientId",*deviceToken_key="deviceToken";
@@ -118,9 +118,9 @@
 
 int sendPacket(Client* c, int length, Timer* timer)
 {
-    int rc = FAILURE, 
+    int rc = FAILURE,
         sent = 0;
-    
+
     while (sent < length && !expired(timer))
     {
         rc = c->ipstack->mqttwrite(c->ipstack, &c->buf[sent], length, left_ms(timer));
@@ -131,7 +131,7 @@
     printf("rc ----%d,sent----%d,length----%d\n",rc,sent,length);
     if (sent == length)
     {
-        countdown(&c->ping_timer, c->keepAliveInterval); // record the fact that we have successfully sent the packet    
+        countdown(&c->ping_timer, c->keepAliveInterval); // record the fact that we have successfully sent the packet
         rc = SUCCESS;
     }
     else
@@ -144,7 +144,7 @@
 {
     int i;
     c->ipstack = network;
-    
+
     for (i = 0; i < MAX_MESSAGE_HANDLERS; ++i)
         c->messageHandlers[i].topicFilter = 0;
     c->command_timeout_ms = command_timeout_ms;
@@ -187,7 +187,7 @@
 }
 
 
-int readPacket(Client* c, Timer* timer) 
+int readPacket(Client* c, Timer* timer)
 {
     int rc = FAILURE;
     MQTTHeader header = {0};
@@ -223,7 +223,7 @@
     char* curf = topicFilter;
     char* curn = topicName->lenstring.data;
     char* curn_end = curn + topicName->lenstring.len;
-    
+
     while (*curf && curn < curn_end)
     {
         if (*curn == '/' && *curf != '/')
@@ -241,7 +241,7 @@
         curf++;
         curn++;
     };
-    
+
     return (curn == curn_end) && (*curf == '\0');
 }
 
@@ -266,15 +266,15 @@
             }
         }
     }
-    
-    if (rc == FAILURE && c->defaultMessageHandler != NULL) 
+
+    if (rc == FAILURE && c->defaultMessageHandler != NULL)
     {
         MessageData md;
         NewMessageData(&md, topicName, message);
         c->defaultMessageHandler(&md);
         rc = SUCCESS;
-    }   
-    
+    }
+
     return rc;
 }
 
@@ -287,7 +287,7 @@
         rc = SUCCESS;
         goto exit;
     }
-    
+
     if (expired(&c->ping_timer))
     {
         if (!c->ping_outstanding)
@@ -303,7 +303,7 @@
         }
     	else
     	{
-    	    printf("fail_count-------------\n",c->fail_count);
+    	    printf("fail_count:%d-------------\n",c->fail_count);
             ++(c->fail_count);
             if (c->fail_count >= MAX_FAIL_ALLOWED)
             {
@@ -334,7 +334,7 @@
 		rc =  DISCONNECTED;
 		goto exit;
 	}
-    
+
     switch (packet_type)
     {
         case CONNACK:
@@ -412,9 +412,9 @@
     int rc = SUCCESS;
     Timer timer;
 
-    InitTimer(&timer);    
+    InitTimer(&timer);
     countdown_ms(&timer, timeout_ms);
-    static int i = 0;
+//    static int i = 0;
     if (c->isconnected)
     		rc = keepalive(c);
     if(rc < 0)
@@ -435,10 +435,10 @@
 */
     do
     {
-            if (expired(&timer)) 
+            if (expired(&timer))
             break; // we timed out
     }
-    while ((rc = cycle(c, &timer)) != PUBLISH);  
+    while ((rc = cycle(c, &timer)) != PUBLISH);
     rc = SUCCESS;
     return rc;
 }
@@ -450,11 +450,11 @@
     int rc = FAILURE;
     do
     {
-            if (expired(timer)) 
+            if (expired(timer))
             break; // we timed out
     }
-    while ((rc = cycle(c, timer)) != packet_type &&  (rc = cycle(c, timer)) != DISCONNECTED);  
-    
+    while ((rc = cycle(c, timer)) != packet_type &&  (rc = cycle(c, timer)) != DISCONNECTED);
+
     return rc;
 }
 
@@ -473,7 +473,7 @@
 
     if (options == 0)
         options = &default_options; // set default options if none were supplied
-    
+
     c->keepAliveInterval = options->keepAliveInterval;
     countdown(&c->ping_timer, c->keepAliveInterval);
     printf("[%s]c->keepAliveInterval = %d", __FUNCTION__,c->keepAliveInterval);
@@ -481,7 +481,7 @@
         goto exit;
     if ((rc = sendPacket(c, len, &connect_timer)) != SUCCESS)  // send the connect packet
         goto exit; // there was a problem
-    
+
     // this will be a blocking call, wait for the connack
     if (waitfor(c, CONNACK, &connect_timer) == CONNACK)
     {
@@ -494,7 +494,7 @@
     }
     else
         rc = FAILURE;
-    
+
 exit:
     if (rc == SUCCESS)
         c->isconnected = 1;
@@ -503,31 +503,31 @@
 
 
 int MQTTSubscribe(Client* c, const char* topicFilter, enum QoS qos, messageHandler messageHandler)
-{ 
-    int rc = FAILURE;  
+{
+    int rc = FAILURE;
     Timer timer;
     int len = 0;
     MQTTString topic = MQTTString_initializer;
     topic.cstring = (char *)topicFilter;
-    
+
     InitTimer(&timer);
     countdown_ms(&timer, c->command_timeout_ms);
 
     if (!c->isconnected)
         goto exit;
-    
+
     len = MQTTSerialize_subscribe(c->buf, c->buf_size, 0, getNextPacketId(c), 1, &topic, (int*)&qos);
     if (len <= 0)
         goto exit;
     if ((rc = sendPacket(c, len, &timer)) != SUCCESS) // send the subscribe packet
         goto exit;             // there was a problem
-    
-    if (waitfor(c, SUBACK, &timer) == SUBACK)      // wait for suback 
+
+    if (waitfor(c, SUBACK, &timer) == SUBACK)      // wait for suback
     {
         int count = 0, grantedQoS = -1;
         unsigned short mypacketid;
         if (MQTTDeserialize_suback(&mypacketid, 1, &count, &grantedQoS, c->readbuf, c->readbuf_size) == 1)
-            rc = grantedQoS; // 0, 1, 2 or 0x80 
+            rc = grantedQoS; // 0, 1, 2 or 0x80
         if (rc != 0x80)
         {
             int i;
@@ -543,9 +543,9 @@
             }
         }
     }
-    else 
+    else
         rc = FAILURE;
-        
+
 exit:
     return rc;
 }
@@ -565,16 +565,16 @@
 }
 
 int MQTTUnsubscribe(Client* c, const char* topicFilter)
-{   
+{
     int rc = FAILURE;
-    Timer timer;    
+    Timer timer;
     MQTTString topic = MQTTString_initializer;
     topic.cstring = (char *)topicFilter;
     int len = 0;
 
     InitTimer(&timer);
     countdown_ms(&timer, c->command_timeout_ms);
-    
+
     if (!c->isconnected)
         goto exit;
     if(messageHandlersFindIndex(c,topicFilter) < 0)
@@ -598,14 +598,14 @@
                 && (strcmp(c->messageHandlers[i].topicFilter, topicFilter) == 0))
                 {
                     c->messageHandlers[i].topicFilter=NULL;
-                    rc = 0; 
+                    rc = 0;
                 }
             }
         }
     }
     else
         rc = FAILURE;
-    
+
 exit:
     return rc;
 }
@@ -614,20 +614,20 @@
 int MQTTPublish(Client* c, const char* topicName, MQTTMessage* message)
 {
     int rc = FAILURE;
-    Timer timer;   
+    Timer timer;
     MQTTString topic = MQTTString_initializer;
     topic.cstring = (char *)topicName;
     int len = 0;
 
     InitTimer(&timer);
     countdown_ms(&timer, c->command_timeout_ms);
-    
+
     if (!c->isconnected)
         goto exit;
     if (message->qos == QOS1 || message->qos == QOS2)
         message->id = getNextPacketId(c);
-    
-    len = MQTTSerialize_publish(c->buf, c->buf_size, 0, message->qos, message->retained, message->id, 
+
+    len = MQTTSerialize_publish(c->buf, c->buf_size, 0, message->qos, message->retained, message->id,
               topic, (unsigned char*)message->payload, message->payloadlen);
 
     if (len <= 0)
@@ -659,14 +659,14 @@
         else
             rc = FAILURE;
     }
-    
+
 exit:
     return rc;
 }
 
 
 int MQTTDisconnect(Client* c ,Network * n)
-{  
+{
     int rc = FAILURE;
     Timer timer;     // we might wait for incomplete incoming publishes to complete
     int len = MQTTSerialize_disconnect(c->buf, c->buf_size);
@@ -676,7 +676,7 @@
 
     if (len > 0)
         rc = sendPacket(c, len, &timer);            // send the disconnect packet
-        
+
     c->isconnected = 0;
     n->disconnect(n);
     return rc;
diff --git a/mbtk/libmbtk_lib_v2/mqtt/MQTTPacket/MQTTFormat.c b/mbtk/libmbtk_lib_v2/mqtt/MQTTPacket/MQTTFormat.c
index 3015a0e..9878492 100755
--- a/mbtk/libmbtk_lib_v2/mqtt/MQTTPacket/MQTTFormat.c
+++ b/mbtk/libmbtk_lib_v2/mqtt/MQTTPacket/MQTTFormat.c
@@ -119,7 +119,7 @@
 	int index = 0;

 	int rem_length = 0;

 	MQTTHeader header = {0};

-	int strindex = 0;

+//	int strindex = 0;

 

 	header.byte = buf[index++];

 	index += MQTTPacket_decodeBuf(&buf[index], &rem_length);

@@ -130,7 +130,7 @@
 	{

 		unsigned char sessionPresent, connack_rc;

 		if (MQTTDeserialize_connack(&sessionPresent, &connack_rc, buf, buflen) == 1)

-			strindex = MQTTStringFormat_connack(strbuf, strbuflen, connack_rc, sessionPresent);

+			MQTTStringFormat_connack(strbuf, strbuflen, connack_rc, sessionPresent);

 	}

 	break;

 	case PUBLISH:

@@ -141,7 +141,7 @@
 		MQTTString topicName = MQTTString_initializer;

 		if (MQTTDeserialize_publish(&dup, &qos, &retained, &packetid, &topicName,

 				&payload, &payloadlen, buf, buflen) == 1)

-			strindex = MQTTStringFormat_publish(strbuf, strbuflen, dup, qos, retained, packetid,

+			MQTTStringFormat_publish(strbuf, strbuflen, dup, qos, retained, packetid,

 					topicName, payload, payloadlen);

 	}

 	break;

@@ -153,7 +153,7 @@
 		unsigned char packettype, dup;

 		unsigned short packetid;

 		if (MQTTDeserialize_ack(&packettype, &dup, &packetid, buf, buflen) == 1)

-			strindex = MQTTStringFormat_ack(strbuf, strbuflen, packettype, dup, packetid);

+			MQTTStringFormat_ack(strbuf, strbuflen, packettype, dup, packetid);

 	}

 	break;

 	case SUBACK:

@@ -162,20 +162,20 @@
 		int maxcount = 1, count = 0;

 		int grantedQoSs[1];

 		if (MQTTDeserialize_suback(&packetid, maxcount, &count, grantedQoSs, buf, buflen) == 1)

-			strindex = MQTTStringFormat_suback(strbuf, strbuflen, packetid, count, grantedQoSs);

+			MQTTStringFormat_suback(strbuf, strbuflen, packetid, count, grantedQoSs);

 	}

 	break;

 	case UNSUBACK:

 	{

 		unsigned short packetid;

 		if (MQTTDeserialize_unsuback(&packetid, buf, buflen) == 1)

-			strindex = MQTTStringFormat_ack(strbuf, strbuflen, UNSUBACK, 0, packetid);

+			MQTTStringFormat_ack(strbuf, strbuflen, UNSUBACK, 0, packetid);

 	}

 	break;

 	case PINGREQ:

 	case PINGRESP:

 	case DISCONNECT:

-		strindex = snprintf(strbuf, strbuflen, "%s", MQTTPacket_names[header.bits.type]);

+		snprintf(strbuf, strbuflen, "%s", MQTTPacket_names[header.bits.type]);

 		break;

 	}

 	return strbuf;

@@ -187,7 +187,7 @@
 	int index = 0;

 	int rem_length = 0;

 	MQTTHeader header = {0};

-	int strindex = 0;

+//	int strindex = 0;

 

 	header.byte = buf[index++];

 	index += MQTTPacket_decodeBuf(&buf[index], &rem_length);

@@ -199,7 +199,7 @@
 		MQTTPacket_connectData data;

 		int rc;

 		if ((rc = MQTTDeserialize_connect(&data, buf, buflen)) == 1)

-			strindex = MQTTStringFormat_connect(strbuf, strbuflen, &data);

+			MQTTStringFormat_connect(strbuf, strbuflen, &data);

 	}

 	break;

 	case PUBLISH:

@@ -210,7 +210,7 @@
 		MQTTString topicName = MQTTString_initializer;

 		if (MQTTDeserialize_publish(&dup, &qos, &retained, &packetid, &topicName,

 				&payload, &payloadlen, buf, buflen) == 1)

-			strindex = MQTTStringFormat_publish(strbuf, strbuflen, dup, qos, retained, packetid,

+			MQTTStringFormat_publish(strbuf, strbuflen, dup, qos, retained, packetid,

 					topicName, payload, payloadlen);

 	}

 	break;

@@ -222,7 +222,7 @@
 		unsigned char packettype, dup;

 		unsigned short packetid;

 		if (MQTTDeserialize_ack(&packettype, &dup, &packetid, buf, buflen) == 1)

-			strindex = MQTTStringFormat_ack(strbuf, strbuflen, packettype, dup, packetid);

+			MQTTStringFormat_ack(strbuf, strbuflen, packettype, dup, packetid);

 	}

 	break;

 	case SUBSCRIBE:

@@ -234,7 +234,7 @@
 		int requestedQoSs[1];

 		if (MQTTDeserialize_subscribe(&dup, &packetid, maxcount, &count,

 				topicFilters, requestedQoSs, buf, buflen) == 1)

-			strindex = MQTTStringFormat_subscribe(strbuf, strbuflen, dup, packetid, count, topicFilters, requestedQoSs);;

+			MQTTStringFormat_subscribe(strbuf, strbuflen, dup, packetid, count, topicFilters, requestedQoSs);;

 	}

 	break;

 	case UNSUBSCRIBE:

@@ -244,13 +244,13 @@
 		int maxcount = 1, count = 0;

 		MQTTString topicFilters[1];

 		if (MQTTDeserialize_unsubscribe(&dup, &packetid, maxcount, &count, topicFilters, buf, buflen) == 1)

-			strindex =  MQTTStringFormat_unsubscribe(strbuf, strbuflen, dup, packetid, count, topicFilters);

+			MQTTStringFormat_unsubscribe(strbuf, strbuflen, dup, packetid, count, topicFilters);

 	}

 	break;

 	case PINGREQ:

 	case PINGRESP:

 	case DISCONNECT:

-		strindex = snprintf(strbuf, strbuflen, "%s", MQTTPacket_names[header.bits.type]);

+		snprintf(strbuf, strbuflen, "%s", MQTTPacket_names[header.bits.type]);

 		break;

 	}

 	strbuf[strbuflen] = '\0';

diff --git a/mbtk/libmbtk_lib_v2/mqtt/mbtk_mqtt.c b/mbtk/libmbtk_lib_v2/mqtt/mbtk_mqtt.c
index 3b78429..40bd5e5 100755
--- a/mbtk/libmbtk_lib_v2/mqtt/mbtk_mqtt.c
+++ b/mbtk/libmbtk_lib_v2/mqtt/mbtk_mqtt.c
@@ -19,6 +19,9 @@
 #include "arpa/inet.h"
 #include "fcntl.h"
 #include "mbtk_sock2.h"
+#include "MQTTPacket/core_sha256.h"
+#include "MQTTPacket/core_sha1.h"
+
 
 #include "mbtk_type.h"
 #include "mbtk_http.h"
@@ -111,17 +114,17 @@
     printf("product_secret: %s\n", product_secret);
     printf("device_name: %s\n", device_name);
 
-    int32_t res = 0, content_len = 0;
+//    int32_t content_len = 0;
     char content[255] = {0};
     char random[15+1]={0};;
     char  sign[65] = {0};
-    int dynamic_register_request_len = 0;
+//    int dynamic_register_request_len = 0;
 //    char *content_fmt = "productKey=%s&deviceName=%s&random=%s&sign=%s&signMethod=%s";
-    char *signMethod = MBTK_MQTT_HTTP_SIGN_METHOD_HMACSHA256;
+//    char *signMethod = MBTK_MQTT_HTTP_SIGN_METHOD_HMACSHA256;
 
 
     memcpy(random, "8Ygb7ULYh53B6OA", strlen("8Ygb7ULYh53B6OA"));
-    char *content_src[] = { product_key, device_name, random,sign,signMethod};
+//    char *content_src[] = { product_key, device_name, random,sign,signMethod};
     mbtk_imqtt_http_dynreg_sign(product_key,product_secret,device_name,random,sign);
 
     sprintf(content, "productKey=%s&deviceName=%s&random=%s&sign=%s&signMethod=%s",
@@ -145,7 +148,7 @@
     {
         char* ptr_start = NULL;
         char* ptr_end = NULL;
-        char fac[64] = {'\0'};
+//        char fac[64] = {'\0'};
         ptr_start = strstr(data, "deviceSecret");
         if(ptr_start != NULL)
         {
@@ -217,9 +220,10 @@
     const mbtk_http_session_t* session = mbtk_http_session_get(http_handle, http_session);
     printf("HTTP:%d,%s,%d,%s\n",session->option,session->host,session->port,session->uri);
 
+#if 0
     char *header = "Accept: text/xml,text/javascript,text/html,application/json\r\n" \
                           "Content-Type: application/x-www-form-urlencoded\r\n";
-
+#endif
 
     mbtk_http_session_head_add(http_handle, http_session, "Accept", "text/xml,text/javascript,text/html,application/json");
 
@@ -260,7 +264,7 @@
 void mbtk_aliyun_mqtt_get_connect_para(char *password,char *cliendid,char *username, mbtk_mqtt_device_session_t *mbtk_mqtt_device_t)
 {
   /*********password.mqttClientId.user_name *************/
-    char content[MBTK_IMQTT_PASSWORD_LEN] = {0};
+    char content[1024] = {0};
 
     printf("mbtk_mqtt_device_t->device_name: %s\n", mbtk_mqtt_device_t->device_name);
     printf("mbtk_mqtt_device_t->product_key: %s\n", mbtk_mqtt_device_t->product_key);
@@ -272,15 +276,15 @@
 
 //    snprintf((char *)cliendid,MBTK_IMQTT_CLIENT_ID_LEN,"%s|securemode=-2,authType=regnwl,random=123,signmethod=hmacsha1,instanceId=%s|",mbtk_mqtt_device_t->device_name,"iot-06z00ag5qidat54");
 
-    snprintf((char *)cliendid,MBTK_IMQTT_CLIENT_ID_LEN,"%s|securemode=-2,authType=regnwl,random=123,signmethod=hmacsha1|",mbtk_mqtt_device_t->device_name);
-    snprintf((char *)username,MBTK_IMQTT_USER_NAME_LEN,"%s&%s",mbtk_mqtt_device_t->device_name,mbtk_mqtt_device_t->product_key);
+    snprintf((char *)cliendid,sizeof(content),"%s|securemode=-2,authType=regnwl,random=123,signmethod=hmacsha1|",mbtk_mqtt_device_t->device_name);
+    snprintf((char *)username,sizeof(content),"%s&%s",mbtk_mqtt_device_t->device_name,mbtk_mqtt_device_t->product_key);
 }
 
 
 void mbtk_imqtt_auth_hostname(char *dest, char *product_key, int host)
 {
 //  char *host = "&product_key.iot-as-mqtt.cn-shanghai.aliyuncs.com";
-    int8_t      public_instance = 1;
+//    int8_t      public_instance = 1;
 
     snprintf(dest, 100, "%s.%s", product_key, mqtt_url[host]);
 }
@@ -507,7 +511,7 @@
         ret = -101;
         goto __END;
     }
-    MQTTClient(&piot_mqtt->Client, piot_mqtt->network, 1000*30, piot_mqtt->mqtt_buffer, MQTT_BUF_SIZE, piot_mqtt->mqtt_read_buffer, MQTT_BUF_SIZE);
+    MQTTClient(&piot_mqtt->Client, piot_mqtt->network, 1000*30, (unsigned char*)piot_mqtt->mqtt_buffer, MQTT_BUF_SIZE, (unsigned char*)piot_mqtt->mqtt_read_buffer, MQTT_BUF_SIZE);
     MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
 
     data.MQTTVersion = piot_mqtt->mqtt_version;
@@ -549,7 +553,7 @@
         ret = -101;
         goto __END;
     }
-    MQTTClient(&piot_mqtt->Client, piot_mqtt->network, 1000, piot_mqtt->mqtt_buffer, MQTT_BUF_SIZE, piot_mqtt->mqtt_read_buffer, MQTT_BUF_SIZE);
+    MQTTClient(&piot_mqtt->Client, piot_mqtt->network, 1000, (unsigned char*)piot_mqtt->mqtt_buffer, MQTT_BUF_SIZE, (unsigned char*)piot_mqtt->mqtt_read_buffer, MQTT_BUF_SIZE);
     MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
 
     if (piot_mqtt->willFlag) {
diff --git a/mbtk/libmbtk_lib_v2/net/mbtk_ifc.c b/mbtk/libmbtk_lib_v2/net/mbtk_ifc.c
index 51267f5..3a7b24b 100755
--- a/mbtk/libmbtk_lib_v2/net/mbtk_ifc.c
+++ b/mbtk/libmbtk_lib_v2/net/mbtk_ifc.c
@@ -152,6 +152,7 @@
     return ret;
 }
 
+#if 0
 /* deprecated - v4 only */
 static int ifc_create_default_route2(const char *name, const char *gw)
 {
@@ -175,6 +176,7 @@
     LOGD("ifc_create_default_route(%s) = %d", name, ret);
     return ret;
 }
+#endif
 
 int mbtk_ifc_open(void)
 {
@@ -572,6 +574,6 @@
 
     LOGD("Set IPv6 : %s success.", ipv6);
 exit:
-    close(socket);
+    mbtk_close(sockfd);
     return err;
 }
diff --git a/mbtk/libmbtk_lib_v2/net/mbtk_net_control.c b/mbtk/libmbtk_lib_v2/net/mbtk_net_control.c
index 722efda..458f940 100755
--- a/mbtk/libmbtk_lib_v2/net/mbtk_net_control.c
+++ b/mbtk/libmbtk_lib_v2/net/mbtk_net_control.c
@@ -298,7 +298,7 @@
     struct timeval timeout;
     int select_r;
     int read_r;
-    struct sockaddr_nl sa;
+//    struct sockaddr_nl sa;
     struct nlmsghdr *nh;
     char buff[NET_CONTROL_BUF_SIZE];
 
diff --git a/mbtk/libmbtk_lib_v2/net/mbtk_sock.c b/mbtk/libmbtk_lib_v2/net/mbtk_sock.c
index d52abdb..ccd872f 100755
--- a/mbtk/libmbtk_lib_v2/net/mbtk_sock.c
+++ b/mbtk/libmbtk_lib_v2/net/mbtk_sock.c
@@ -33,13 +33,13 @@
     if(sock_info->addr_family == MBTK_ADDR_IPV6) { // Only IPv6
         family = AF_INET6;
     }
-    if(sock_info->sock_type == MBTK_SOCK_UDP) { // UDP
+    if(sock_info->sock_type == MBTK_SOCK_UDP_COM) { // UDP
         // socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
         if((sock_info->fd = socket(family, SOCK_DGRAM, IPPROTO_UDP)) < 0){
             LOGE("socket() fail.[%d]",errno);
             goto result_fail;
         }
-    } else if(sock_info->sock_type == MBTK_SOCK_TCP){ // TCP
+    } else if(sock_info->sock_type == MBTK_SOCK_TCP_COM){ // TCP
         if((sock_info->fd = socket(family, SOCK_STREAM, IPPROTO_TCP)) < 0){
             LOGE("socket() fail.[%d]",errno);
             goto result_fail;
diff --git a/mbtk/libmbtk_lib_v2/net/mbtk_sock2.c b/mbtk/libmbtk_lib_v2/net/mbtk_sock2.c
index 2b508a5..45ae0b6 100755
--- a/mbtk/libmbtk_lib_v2/net/mbtk_sock2.c
+++ b/mbtk/libmbtk_lib_v2/net/mbtk_sock2.c
@@ -44,6 +44,7 @@
 
 #include "mbtk_sock2.h"
 #include "mbtk_sock_internal.h"
+#include "mbtk_str.h"
 //#include "mbtk_openssl.h"
 
 #define SA struct sockaddr
@@ -97,6 +98,7 @@
     return FALSE;
 }
 
+#if 0
 static bool sock_is_close(int sockfd)
 {
     char buff[32];
@@ -113,6 +115,7 @@
 
     return TRUE;
 }
+#endif
 
 static int sock_info_find_by_fd(int handle,int fd)
 {
@@ -181,7 +184,7 @@
                             && (epoll_events[i].events & EPOLLOUT)) {
                             LOGD("%d can read and write.",epoll_events[i].data.fd);
                             int error = -1;
-                            int len = sizeof(int);
+                            socklen_t len = sizeof(int);
                             if(getsockopt(epoll_events[i].data.fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0){
                                 LOGE("getsockopt fail.[%d]",errno);
                             }else{
@@ -627,9 +630,9 @@
         }
     }
 
-    inter_info->ctx = &ctx;
+    inter_info->ctx = ctx;
 
-    inter_info->ssl = &ssl;
+    inter_info->ssl = ssl;
 
     return 0;
 }
@@ -772,7 +775,7 @@
             if (FD_ISSET(mbtk_sock[handle]->inter_infos[index_free].fd, &rset)
                 && FD_ISSET(mbtk_sock[handle]->inter_infos[index_free].fd, &wset)) {
                 int error = -1;
-                int len = sizeof(int);
+                socklen_t len = sizeof(int);
                 LOGE("Can read and write.");
                 if(getsockopt(mbtk_sock[handle]->inter_infos[index_free].fd, SOL_SOCKET, SO_ERROR, &error, &len) < 0){
                     LOGE("getsockopt fail.[%d]",errno);
@@ -818,7 +821,7 @@
                 printf("\nmbtk_sock_read:\n%s\n",mbtk_ftp_ssl_read_buf_s);
 
             char cmd_buff[50];
-            int len=0,code;
+            int len=0;
             memset(cmd_buff,0,sizeof(cmd_buff));
 
             len = snprintf(cmd_buff, 50, "AUTH TLS\r\n");
@@ -908,11 +911,11 @@
     }
 
 #ifdef MBTK_POLARSSL_SUPPORT
-    if(mbtk_sock[handle]->inter_infos[index_free].ssl!=NULL);
+    if(mbtk_sock[handle]->inter_infos[index_free].ssl!=NULL)
         printf("\nmbtk_sock[handle]->inter_infos[index_free].ssl not empty\n");
     return mbtk_polarssl_close(&mbtk_sock[handle]->inter_infos[index_free]);
 #else
-    if(mbtk_sock[handle]->inter_infos[index_free].ssl!=NULL);
+    if(mbtk_sock[handle]->inter_infos[index_free].ssl!=NULL)
         printf("\nmbtk_sock[handle]->inter_infos[index_free].ssl not empty\n");
     return mbtk_openssl_close(&mbtk_sock[handle]->inter_infos[index_free]);
 #endif
@@ -964,9 +967,9 @@
         while(count < buf_len){
             if(mbtk_sock[handle]->infos[index].is_support_ssl) {
 #ifdef MBTK_POLARSSL_SUPPORT
-                len = mbtk_polarssl_write(inter_info->ssl,(char*)buffer + count,buf_len - count);
+                len = mbtk_polarssl_write(inter_info->ssl,(const unsigned char*)buffer + count,buf_len - count);
 #else
-            len = mbtk_openssl_write(inter_info->ssl,(char*)buffer + count,buf_len - count);
+            len = mbtk_openssl_write(inter_info->ssl,(const unsigned char *)buffer + count,buf_len - count);
 
 #endif
             } else
@@ -1073,9 +1076,9 @@
             try_count++;
             if(mbtk_sock[handle]->infos[index].is_support_ssl) {
 #ifdef MBTK_POLARSSL_SUPPORT
-                len = mbtk_polarssl_read(inter_info->ssl,(char*)buffer + count,buf_len - count);
+                len = mbtk_polarssl_read(inter_info->ssl,(unsigned char*)buffer + count,buf_len - count);
 #else
-            len = mbtk_openssl_read(inter_info->ssl,(char*)buffer + count,buf_len - count);
+            len = mbtk_openssl_read(inter_info->ssl,(unsigned char *)buffer + count,buf_len - count);
 
 #endif
             } else
@@ -1224,12 +1227,12 @@
     }
 
     unsigned int count = 0;
-    unsigned int read_count = 0;
+//    unsigned int read_count = 0;
     memset(buf_ptr, 0, buf_len);
     char *temp_ptr = (char *)buffer;
 copy_angin_ssl:
     while(*read_line_count > 0 && *temp_ptr != '\n') {
-        if(*temp_ptr == NULL)
+        if(temp_ptr == NULL)
         {
             printf("\n*temp_ptr is null\n");
             goto read_end;
@@ -1249,9 +1252,9 @@
                 try_count++;
                 if(mbtk_sock[handle]->infos[index].is_support_ssl) {
 #ifdef MBTK_POLARSSL_SUPPORT
-                    len = mbtk_polarssl_read(inter_info->ssl,(char*)buffer + count,buf_len - count);
+                    len = mbtk_polarssl_read(inter_info->ssl,(unsigned char*)buffer + count,buf_len - count);
 #else
-                    len = mbtk_openssl_read(inter_info->ssl,(char*)buffer + count,buf_len - count);
+                    len = mbtk_openssl_read(inter_info->ssl,(unsigned char*)buffer + count,buf_len - count);
 #endif
                 } else
                     len = read(inter_info->fd,(char*)buffer + count,buf_len - count);
@@ -1425,9 +1428,9 @@
         while(read_count < buf_len) {
             if(mbtk_sock[handle]->infos[index].is_support_ssl) {
 #ifdef MBTK_POLARSSL_SUPPORT
-                len = ssl_read(inter_info->ssl,(char*)buffer + read_count,buf_len - read_count);
+                len = ssl_read(inter_info->ssl,(unsigned char*)buffer + read_count,buf_len - read_count);
 #else
-                len = mbtk_openssl_read(inter_info->ssl,(char*)buffer + read_count,buf_len - read_count);
+                len = mbtk_openssl_read(inter_info->ssl,(unsigned char*)buffer + read_count,buf_len - read_count);
 
 #endif
             } else
@@ -1516,9 +1519,9 @@
         memset(buffer,0x0,buf_len);
         if(mbtk_sock[handle]->infos[index].is_support_ssl) {
 #ifdef MBTK_POLARSSL_SUPPORT
-            len = ssl_read(inter_info->ssl,(char*)buffer,buf_len);
+            len = ssl_read(inter_info->ssl,(unsigned char*)buffer,buf_len);
 #else
-            len = mbtk_openssl_read(inter_info->ssl,(char*)buffer,buf_len);
+            len = mbtk_openssl_read(inter_info->ssl,(unsigned char*)buffer,buf_len);
 
 #endif
         } else
@@ -1717,7 +1720,7 @@
         return -1;
     }
 
-    unsigned int count = 0;
+//    unsigned int count = 0;
     int len = 0;
     if(mbtk_sock[handle]->infos[index].type == MBTK_SOCK_TCP) {
         if(ioctl(inter_info->fd, FIONREAD, &len))
diff --git a/mbtk/libmbtk_lib_v2/ril/mbtk_pdu_sms.c b/mbtk/libmbtk_lib_v2/ril/mbtk_pdu_sms.c
index 05da8a8..c00a924 100755
--- a/mbtk/libmbtk_lib_v2/ril/mbtk_pdu_sms.c
+++ b/mbtk/libmbtk_lib_v2/ril/mbtk_pdu_sms.c
@@ -166,7 +166,7 @@
     result = (char *) malloc(sizeof(char) * (len + 2));

     //wmemset(result, 0, sizeof(char) * (len + 1));

     buf = result;

-    

+

     if (strncmp(data + index + 2, "91", 2) == 0) {

         sprintf(buf++, "+");

     }

@@ -461,7 +461,7 @@
 

     if (is_acsii((unsigned char*)Data) == 0) {

         int len;

-        len = utf8len((unsigned char *) Data); 

+        len = utf8len((unsigned char *) Data);

 

         u_int16_t *code = (u_int16_t *) malloc(sizeof(u_int16_t) * len);

         utf8toutf16((unsigned char *) Data, code, len, &len);

@@ -559,7 +559,7 @@
             else

                 return NULL;

         }

-        if (UDC == NULL || utf8len(UDC) <= room) {

+        if (UDC == NULL || utf8len((unsigned char *)UDC) <= room) {

             result = (struct UDS *) malloc(sizeof(struct UDS));

             result->Data = (char **)malloc(sizeof(char *));

             result->total = 1;

@@ -580,7 +580,7 @@
             if (room < 1)

                 return NULL;

 

-            int len = utf8len(UDC);

+            int len = utf8len((unsigned char *)UDC);

 

             result = (struct UDS *) malloc(sizeof(struct UDS));

             result->total = 0;

@@ -590,12 +590,12 @@
             for (i = 0; i < len; i += room) {

 		    int real_size;

                 if (i + room < len) {

-		    real_size = utf8_get_size(UDC + index, room);

+		    real_size = utf8_get_size((unsigned char *)UDC + index, room);

                     result->Data[result->total] = (char*)malloc(sizeof(char) * (real_size + 1));

                     strcpy(result->Data[result->total++],sub_str(UDC, index, real_size));

                 }

                 else {

-		    real_size = utf8_get_size(UDC + index, len - i);

+		    real_size = utf8_get_size((unsigned char *)UDC + index, len - i);

                     result->Data[result->total] = (char*)malloc(sizeof(char) * (real_size + 1));

                     strcpy(result->Data[result->total++], sub_str(UDC, index, -1));

                 }

@@ -696,7 +696,6 @@
 char *SoloPDUEncoding(char *SCA, char *DA, char *UC, struct UDHS *udhs, enum EnumDCS DCS) {

     char *result;

     char *buf, *ret;

-    int index;

 

     result = (char *) malloc(sizeof(char) * 400);

     buf = result;

@@ -932,11 +931,12 @@
 

 char *UDHEncoding(struct UDHS *udhs, int *UDHL) {

 

-    *UDHL = 0;

+    int i = 0;

 

     if (udhs == NULL || udhs->count == 0)

         return "";

-	int i = 0;

+

+    *UDHL = 0;

     for (i = 0; i < udhs->count; i++) {

         *UDHL += udhs->UDH[i].count + 2;

     }

@@ -948,7 +948,7 @@
 

     sprintf(buf, "%02X", *UDHL);

     buf += 2;

-	

+

     for (i = 0; i < udhs->count; i++) {

         // 信息元素标识1字节

         sprintf(buf, "%02X", udhs->UDH[i].IEI);

@@ -967,7 +967,6 @@
     // 加上1字节的用户数据头长度

     (*UDHL)++;

     return result;

-

 }

 

 char *UDCEncoding(char *UDC, int *UDCL, int UDHL, enum EnumDCS DCS) {

diff --git a/mbtk/libmbtk_lib_v2/ril/ril_utils.c b/mbtk/libmbtk_lib_v2/ril/ril_utils.c
index 9c39019..236c06f 100755
--- a/mbtk/libmbtk_lib_v2/ril/ril_utils.c
+++ b/mbtk/libmbtk_lib_v2/ril/ril_utils.c
@@ -157,12 +157,12 @@
 */
 int str_2_ipv6(const void *ip_str, void *ipv6)
 {
-    const uint8 *ptr = (const uint8*)ip_str;
+    const char *ptr = (const char*)ip_str;
     uint8 *ipv6_ptr = (uint8*)ipv6;
     ipv6_ptr[0] = (uint8)atoi(ptr);
     int i = 1;
     while(i < 16) {
-        ptr = (const uint8*)strstr(ptr, ".");
+        ptr = (const char*)strstr(ptr, ".");
         if(ptr == NULL)
             return -1;
         ptr++;
@@ -183,8 +183,8 @@
     int i = 0;
     int index = 0;
     while(i < 16) {
-        index += sprintf(ipv6_ptr + index, "%02x%02x", ptr[i], ptr[i + 1]);
-        index += sprintf(ipv6_ptr + index, ":");
+        index += sprintf((char*)ipv6_ptr + index, "%02x%02x", ptr[i], ptr[i + 1]);
+        index += sprintf((char*)ipv6_ptr + index, ":");
         i += 2;
     }
 
diff --git a/mbtk/libmbtk_lib_v2/sleep/mbtk_lpm.c b/mbtk/libmbtk_lib_v2/sleep/mbtk_lpm.c
new file mode 100755
index 0000000..19681a0
--- /dev/null
+++ b/mbtk/libmbtk_lib_v2/sleep/mbtk_lpm.c
@@ -0,0 +1,215 @@
+#include <stdio.h>

+#include <time.h>

+#include <sys/time.h>

+#include <unistd.h>

+#include <sys/un.h>

+#include <sys/socket.h>

+#include <netinet/in.h>

+#include <arpa/inet.h>

+#include <errno.h>

+#include <sys/ioctl.h>

+#include <net/if.h>

+#include <string.h>

+#include <fcntl.h>

+#include <signal.h>

+#include <stdlib.h>

+#include <sys/stat.h>

+#include <sys/file.h>

+#include <stddef.h>

+#include <sys/types.h>

+#include <pthread.h>

+#include <sys/epoll.h>

+#include <linux/input.h>

+

+

+#include "mbtk_lpm.h"

+#include "mbtk_type.h"

+#include "mbtk_log.h"

+#include "mbtk_utils.h"

+

+static mbtk_lpm_handler_t lpm_init;

+

+static pthread_t lpm_t;

+static int epoll_fd_t = -1;

+static int fd_t = -1;

+static int socket_t[2];

+

+static int sleep_epoll_deregister(int epoll_fd,int fd )

+{

+    int  ret;

+    do {

+        ret = epoll_ctl( epoll_fd, EPOLL_CTL_DEL, fd, NULL );

+    } while (ret < 0 && errno == EINTR);

+    return ret;

+}

+

+static int sleep_epoll_register(int epoll_fd, int fd)

+{

+    struct epoll_event  ev;

+    int    ret, flags;

+

+    /* important: make the fd non-blocking */

+    flags = fcntl(fd, F_GETFL);

+    fcntl(fd, F_SETFL, flags | O_NONBLOCK);

+

+    ev.events  = EPOLLIN;

+    ev.data.fd = fd;

+    do {

+        ret = epoll_ctl( epoll_fd, EPOLL_CTL_ADD, fd, &ev );

+    } while (ret < 0 && errno == EINTR);

+

+    return ret;

+}

+

+

+void *threadFunction(void *arg)

+{

+    int pinValue;

+    int i;

+    char buf[8] = {0};

+    struct input_event ev_input = { 0 };

+    const int size = sizeof(struct input_event);

+

+    epoll_fd_t = epoll_create(2);

+

+    fd_t = open("/dev/input/event2", O_RDONLY);

+    LOGI("init pthread_event2");

+

+    sleep_epoll_register(epoll_fd_t, fd_t);

+    sleep_epoll_register(epoll_fd_t, socket_t[1]);

+

+    while (true)

+    {

+        struct epoll_event events[2];

+

+        int numEvents = epoll_wait(epoll_fd_t, events, 2, -1);

+

+        for (i = 0; i < numEvents; ++i)

+        {

+            if ((events[i].events & EPOLLERR) || (events[i].events & EPOLLHUP))

+            {

+                LOGE("Error on GPIO device.");

+                return NULL;

+            }

+            else if ((events[i].events & EPOLLIN) || (events[i].events & EPOLLET))

+            {

+                //handleInterrupt(events[i].data.fd);

+                if (events[i].data.fd == socket_t[1])

+                {

+                    memset(buf, 0, sizeof(buf));

+                    mbtk_read(socket_t[1], buf, sizeof(buf));

+                    if (1 == atoi(buf))

+                    {

+                        if(close(fd_t) == 0)

+                            LOGI("close(fd_t)ing");

+

+                        sleep_epoll_deregister(epoll_fd_t, socket_t[1]);

+                        sleep_epoll_deregister(epoll_fd_t, fd_t);

+

+                        LOGI("do pthread_exit");

+                        return NULL;

+                    }

+                }

+                else if (events[i].data.fd == fd_t)

+                {

+                    LOGI("go pthread_event");

+                    memset(&ev_input, 0x00, size);

+                    mbtk_read(fd_t, &ev_input, size);

+                    LOGI("ev_input type = %x, code = %x, value = %x", ev_input.type, ev_input.code,ev_input.value);

+

+                    if (ev_input.type == 4 && ev_input.code == 3)

+                    {

+                        LOGI(">>>>ev_input.value = [%d]",ev_input.value);

+                        pinValue = (int)ev_input.value;

+                        lpm_init(pinValue);

+                    }

+                }

+                else

+                {

+                    LOGE("Unknown events[i].data.fd = %d", events[i].data.fd);

+                }

+            }

+       }

+    }

+    return NULL;

+}

+

+int mbtk_lpm_init(mbtk_lpm_handler_t mbtk_lpm_handler)

+{

+    if (socketpair( AF_LOCAL, SOCK_STREAM, 0, socket_t ) < 0 )

+    {

+        LOGE("[mbtk_lpm_init] could not create thread control socket pair: %s", strerror(errno));

+

+        /*close the control socket pair && Retry again.*/

+        if(socket_t[0] > 0)

+        {

+            close(socket_t[0] );

+            socket_t[0] = -1;

+        }

+

+        if(socket_t[1] > 0)

+        {

+            close(socket_t[1] );

+            socket_t[1] = -1;

+        }

+        return -1;

+    }

+

+    lpm_init = mbtk_lpm_handler;

+

+    pthread_attr_t thread_attr;

+    pthread_attr_init(&thread_attr);

+

+    if(pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED))

+    {

+        LOGE("pthread_attr_setdetachstate() fail");

+        return -1;

+    }

+

+    if(pthread_create(&lpm_t, &thread_attr, threadFunction, NULL))

+    {

+        LOGE("mbtk_lpm_init can't create thread");

+        return -1;

+    }

+

+    pthread_attr_destroy(&thread_attr);

+

+    return 0;

+}

+

+int mbtk_lpm_deinit(void)

+{

+    char buf[4]={0};

+

+    if (fd_t == -1)

+        return 0;

+

+    if (fd_t != -1)

+    {

+        //char   cmd = 1;

+        strcpy(buf, "1");

+//        void*  dummy = NULL;

+        mbtk_write( socket_t[0], buf, sizeof(buf) );

+

+        sleep(1);

+        // close the control socket pair

+        if(socket_t[0] > 0)

+        {

+            close(socket_t[0] );

+            socket_t[0] = -1;

+        }

+        if(socket_t[1] > 0)

+        {

+            close(socket_t[1] );

+            socket_t[1] = -1;

+        }

+

+        //重置还原

+        fd_t = -1;

+

+    }

+

+    return 0;

+}

+

+

diff --git a/mbtk/libmbtk_lib_v2/sleep/mbtk_sleep.c b/mbtk/libmbtk_lib_v2/sleep/mbtk_sleep.c
new file mode 100755
index 0000000..25c3997
--- /dev/null
+++ b/mbtk/libmbtk_lib_v2/sleep/mbtk_sleep.c
@@ -0,0 +1,172 @@
+#include "mbtk_sleep.h"
+#include "mbtk_log.h"
+#include "mbtk_utils.h"
+
+static mbtk_lock_name_s mbtk_lock_name[LOCK_MAX_SIZE]={0};
+
+
+int mbtk_autosuspend_enable(char enable)
+{
+    if((enable == 1) || enable == '1')
+    {
+        if(!access("/sys/power/autosleep", W_OK))
+        {
+            mbtk_system("echo mem > /sys/power/autosleep");
+            autosleep_enable = TRUE;
+            return 0;
+        }
+        else
+        {
+            LOGE("/sys/power/autosleep can not write.");
+            return -1;
+        }
+    }
+    else if((enable == 0) || enable == '0')
+    {
+        if(!access("/sys/power/autosleep", W_OK))
+        {
+            mbtk_system("echo off > /sys/power/autosleep");
+            autosleep_enable = FALSE;
+            return 0;
+        }
+        else
+        {
+            LOGE("/sys/power/autosleep can not write.");
+            return -1;
+        }
+    }
+    else
+    {
+        LOGE("qser_autosuspend_enablecan enable err.");
+        return -1;
+    }
+
+    return 0;
+}
+
+int mbtk_wakelock_create(const char* name , size_t len)
+{
+    int len_t;
+
+    len_t = strlen(name);
+
+    if((name != NULL) && (len < 33) && (len_t < 33))
+    {
+        int i;
+        for(i=1 ;i<LOCK_MAX_SIZE;i++)
+        {
+            if(strcmp(mbtk_lock_name[i].name, name) == 0)
+            {
+                LOGE("Repeated names.");
+                return -1;
+            }
+        }
+
+        for(i=1 ;i<LOCK_MAX_SIZE;i++)
+        {
+            if(mbtk_lock_name[i].fd == 0)
+                break;
+        }
+
+        if (i >= LOCK_MAX_SIZE)
+        {
+            LOGE("Fd is full.");
+            return -1;
+        }
+
+        memcpy(mbtk_lock_name[i].name, name, strlen(name)+1);
+        mbtk_lock_name[i].fd = i;
+        return mbtk_lock_name[i].fd -1;//Starting from scratch
+    }
+    else
+        return -1;
+
+    return -1;
+}
+
+int mbtk_wakelock_lock(int fd)
+{
+    int i;
+    for(i=1;i<LOCK_MAX_SIZE;i++)
+    {
+        if(mbtk_lock_name[i].fd -1 == fd)
+            break;
+    }
+    if(i == LOCK_MAX_SIZE)
+    {
+        LOGE("LOCK_MAX_SIZE is full\n");
+        return -1;
+    }
+
+    if(!access("/sys/power/wake_lock", W_OK))
+    {
+        char cmd[128]={0};
+        sprintf(cmd, "echo %s > /sys/power/wake_lock", mbtk_lock_name[i].name);
+        mbtk_system(cmd);
+        return 0;
+    }
+    else
+    {
+        LOGE("/sys/power/wake_lock can not write.");
+        return -1;
+    }
+
+    return 0;
+}
+
+int mbtk_wakelock_unlock(int fd)
+{
+    int i;
+    for(i=1;i<LOCK_MAX_SIZE;i++)
+    {
+        if(mbtk_lock_name[i].fd -1 == fd)
+            break;
+    }
+    if(i == LOCK_MAX_SIZE)
+    {
+        LOGE("LOCK_MAX_SIZE is full\n");
+        return -1;
+    }
+
+    if(!access("/sys/power/wake_unlock", W_OK))
+    {
+        char cmd[128]={0};
+        sprintf(cmd, "echo %s > /sys/power/wake_unlock", mbtk_lock_name[i].name);
+        mbtk_system(cmd);
+        return 0;
+    }
+    else
+    {
+        LOGE("/sys/power/wake_unlock can not write.");
+        return -1;
+    }
+
+    return 0;
+}
+
+int mbtk_wakelock_destroy(int fd)
+{
+    int i;
+    for(i=1;i<LOCK_MAX_SIZE;i++)
+    {
+        if(mbtk_lock_name[i].fd -1 == fd)
+        break;
+    }
+
+    if(i == LOCK_MAX_SIZE)
+    {
+        LOGE("LOCK_MAX_SIZE is full\n");
+        return -1;
+    }
+    else
+    {
+        mbtk_lock_name[i].fd = 0;
+        memset(mbtk_lock_name[i].name, 0, 64);
+        return 0;
+    }
+
+    return 0;
+}
+
+
+
diff --git a/mbtk/libmbtk_lib_v2/tcpip/mbtk_tcpip_at.c b/mbtk/libmbtk_lib_v2/tcpip/mbtk_tcpip_at.c
index fadb1a6..967e7fa 100755
--- a/mbtk/libmbtk_lib_v2/tcpip/mbtk_tcpip_at.c
+++ b/mbtk/libmbtk_lib_v2/tcpip/mbtk_tcpip_at.c
@@ -500,7 +500,7 @@
     }
 
     if(tcpip_link[link_id].type == MBTK_TCPIP_TYPE_CLIENT) {
-        if(tcpip_handle, tcpip_link[link_id].tcpip_info.cli_info.read_cb) {
+        if(tcpip_handle && tcpip_link[link_id].tcpip_info.cli_info.read_cb) {
             LOGE("Set read_cb function,can not manual read.");
             return -1;
         }
diff --git a/mbtk/libmbtk_lib_v2/wifi/sta_cli.c b/mbtk/libmbtk_lib_v2/wifi/sta_cli.c
index 0cf37fd..9dbd202 100755
--- a/mbtk/libmbtk_lib_v2/wifi/sta_cli.c
+++ b/mbtk/libmbtk_lib_v2/wifi/sta_cli.c
@@ -12,11 +12,14 @@
 #include <sys/ioctl.h>

 #include <net/if.h>

 #include <string.h>

-

+#include <ctype.h>

+#include <stdlib.h>

 

 #include "sta_cli.h"

 #include "sta_ctrl.h"

 #include "mbtk_log.h"

+#include "mbtk_utils.h"

+#include "mbtk_str.h"

 

 //#include "sta_log.h"

 //#include "mbtk_string.h"

@@ -29,6 +32,7 @@
 #define STA_MAC_LEN 17	  // xx:xx:xx:xx:xx:xx

 #define STA_SSID_MAX_LEN (32 * 5)

 

+bool sta_ctrl_system(const char   *command);

 

 #ifndef INFTIM

 #define INFTIM          (-1)    /* infinite poll timeout */

@@ -66,7 +70,7 @@
 static pthread_cond_t cond;

 static pthread_mutex_t mutex;

 static int sta_cli_conn_fd = -1;

-static char sta_cli_buf[STA_BUF_SIZE];

+//static char sta_cli_buf[STA_BUF_SIZE];

 static bool sta_should_send_connected_msg = TRUE;

 //static bool sta_connected = FALSE;

 static bool sta_disconnectting = FALSE;

@@ -79,19 +83,20 @@
     FILE *fd_tmp = NULL;

 

     fd_tmp = popen("cat /etc/wifi/sta_network.conf | grep -w 'SSID'   | cut -d '=' -f 2","r");

-  

+

     if(fd_tmp){

-        char buf[200] = {0};

-        fgets(ssid,200,fd_tmp); 

+//        char buf[200] = {0};

+        if(fgets(ssid,200,fd_tmp) == NULL)

+            return -1;

         pclose(fd_tmp);

         if(strlen(ssid) > 0){

            LOGE("test 100:%s, len:%d\n", ssid, strlen(ssid));

-            

+

         }else{// Open wpa_supplicant

             LOGE("test 101:%s\n", ssid);

         }

     }else{

-       

+

             LOGE("test 102:%s\n");

     }

 

@@ -103,19 +108,20 @@
     FILE *fd_tmp = NULL;

 

     fd_tmp = popen("cat /etc/wifi/sta_network.conf | grep -w 'PASSWORD'   | cut -d '=' -f 2","r");

-  

+

     if(fd_tmp){

-        char buf[200] = {0};

-        fgets(psk,200,fd_tmp);

+//        char buf[200] = {0};

+        if(fgets(psk,200,fd_tmp) == NULL)

+            return -1;

         pclose(fd_tmp);

         if(strlen(psk) > 0){

            LOGE("test 100:%s\n", psk);

-            

+

         }else{// Open wpa_supplicant

             LOGE("test 101:%s\n", psk);

         }

     }else{

-       

+

             LOGE("test 102:%s\n");

     }

 

@@ -129,9 +135,9 @@
     char buf[100] = {0};

     snprintf(buf, 100, "sed -i 's/SSID=.*$/SSID=%s/g' /etc/wifi/sta_network.conf", ssid);

     LOGE("set ssid:%s", buf);

-    system(buf);

-    

-    

+    mbtk_system(buf);

+

+

     return 0;

 }

 

@@ -141,16 +147,16 @@
     char buf[100] = {0};

     snprintf(buf, 100, "sed -i 's/PASSWORD=.*$/PASSWORD=%s/g' /etc/wifi/sta_network.conf", psk);

     LOGE("set ssid:%s", buf);

-    system(buf);

-    

-    

+    mbtk_system(buf);

+

+

     return 0;

 }

 

 

 

 

-

+#if 0

 static char*

 sta_cli_ssid_process

 (

@@ -186,7 +192,7 @@
     }

     return result;

 }

-

+#endif

 

 static char*

 sta_cli_mac_get

@@ -239,7 +245,9 @@
     stream = popen("hostname","r");

     if(stream != NULL)

     {

-		fgets(host, 100, stream);

+		if(fgets(host, 100, stream) == NULL) {

+            return NULL;

+		}

 		pclose(stream);

 		int index = str_indexof(host,"\n");

 		if(strlen(host) > 0

@@ -276,8 +284,7 @@
 			"%ld",t);

 	}

 

-	snprintf(name,name_len,

-		"%s-%s",host,mac);

+	snprintf(name,name_len,"%s-%s",host,mac);

 

 	return name;

 }

@@ -334,8 +341,8 @@
     // Connected to AP

     if(str_contains(msg, "CTRL-EVENT-CONNECTED")){

 		//sta_connected = TRUE;

-		char sta_name[100];

-		sta_cli_sta_name_get(sta_name,100);

+		char sta_name[200];

+		sta_cli_sta_name_get(sta_name,200);

 		char cmd[200];

 		int size = snprintf(cmd,200,

 			"dhcpcd -h %s -o domain_name_servers --noipv4ll wlan0",sta_name);

@@ -524,11 +531,11 @@
 	memcpy(tmp,data_base,strlen(data_base));

 	bzero(data_base,len);

 

-	char *ptr_pre = tmp;

+	const char *ptr_pre = tmp;

 	ptr = strstr(ptr_pre,"\r\n");

 	LOGE("line:%s\n",ptr == NULL?"NULL":ptr);

 	char ssid[STA_BUF_SIZE] = {0};

-	char *p;

+	const char *p;

 	while(ptr)

 	{

 		LOGE("Get line.\n");

@@ -1090,11 +1097,11 @@
 static sta_err_enum

 sta_cli_cmd_set_network_process

 (

-	char *c

+	const char *c

 )

 {

 	LOGE("cmd = %s\n",c);

-	char *ptr = c;

+	const char *ptr = c;

 

     sta_cli_cmd_id = CMD_ID_SET_NETWORK;

 	sta_err_enum err = STA_ERR_SUCCESS;

@@ -1373,12 +1380,12 @@
             sta_cli_ssid_get(ssid);

             len = strlen(ssid);

             ssid[len - 1] = '\0';

-            

+

             sta_cli_psk_get(psk);

             len = strlen(psk);

             psk[len - 1] = '\0';

 

-            

+

             int size = snprintf(buf,STA_BUF_SIZE,

                 "%s %d ssid \"%s\"",

                 STA_CMD_SET_NETWORK,

@@ -1387,7 +1394,7 @@
             LOGE("test6\n");

             buf[size] = '\0';

 

-         

+

             err = sta_cli_cmd_set_network(buf,NULL);

             LOGE("test7\n");

             if(STA_ERR_SUCCESS == err){

diff --git a/mbtk/libmbtk_lib_v2/wifi/sta_ctrl.c b/mbtk/libmbtk_lib_v2/wifi/sta_ctrl.c
index e5e24aa..cad497c 100755
--- a/mbtk/libmbtk_lib_v2/wifi/sta_ctrl.c
+++ b/mbtk/libmbtk_lib_v2/wifi/sta_ctrl.c
@@ -11,6 +11,7 @@
 #include "wpa_ctrl.h"

 #include "sta_ctrl.h"

 #include "mbtk_log.h"

+#include "mbtk_utils.h"

 

 //#include "sta_log.h"

 

@@ -41,7 +42,7 @@
     char *value

 );

 

-extern struct wpa_ctrl;

+// extern struct wpa_ctrl;

 

 static struct wpa_ctrl *sta_ctrl_conn;

 static struct wpa_ctrl *sta_mon_conn;

@@ -108,9 +109,12 @@
         bzero(pid_s, STA_BUF_SIZE);

         if(cmd)

         {

-            fgets(pid_s, STA_BUF_SIZE, cmd);

+            if(fgets(pid_s, STA_BUF_SIZE, cmd) == NULL) {

+

+            }

             pclose(cmd);

         }

+

         pid = atoi(pid_s);

         LOGE("%s pid =%d\n", name,pid);

         /* If pid is zero we break from while*/

@@ -142,7 +146,9 @@
     bzero(pid_s, STA_BUF_SIZE);

     if(cmd)

     {

-        fgets(pid_s, STA_BUF_SIZE, cmd);

+        if(fgets(pid_s, STA_BUF_SIZE, cmd) == NULL) {

+

+        }

         pclose(cmd);

     }

 

@@ -165,7 +171,7 @@
 {

     LOGE("Thread[%ld] run().\n",pthread_self());

 

-    int nready;

+    int nready = 0;

     struct epoll_event ev_sock,ev_pipe,events[20];

     int epfd = epoll_create(256);

     ev_sock.data.fd = wpa_ctrl_get_fd(sta_mon_conn);

@@ -252,7 +258,7 @@
         LOGE("sta_ctrl_conf_file_parse() fail(%d).\n",result);

         return result;

     }

-    snprintf(ctrl_path + strlen(ctrl_path),10,

+    sprintf(ctrl_path + strlen(ctrl_path),

         "/%s",

         sta_ctrl_ifname);

 

@@ -363,7 +369,7 @@
                 }else{

                     break;

                 }

-                *tmp--;

+                tmp--;

             }

 

             int size = snprintf(value,100,

@@ -416,7 +422,7 @@
             LOGE("\n");

     }

 

-end_success:

+//end_success:

 

     return result;

 end_fail:

@@ -441,7 +447,9 @@
 

     if(fd_tmp){

         char buf[200] = {0};

-        fgets(buf,200,fd_tmp);

+        if(fgets(buf,200,fd_tmp) == NULL) {

+

+        }

         pclose(fd_tmp);

         if(strlen(buf) > 0){

             LOGE("Driver %s fail.(%s)\n",(open?"open":"close"),buf);

@@ -500,19 +508,21 @@
     FILE *fd_tmp = popen("pidof wpa_supplicant","r");

     if(fd_tmp){

         char buf[200] = {0};

-        fgets(buf,200,fd_tmp);

+        if(fgets(buf,200,fd_tmp) == NULL) {

+

+        }

         pclose(fd_tmp);

         if(strlen(buf) > 0){

             LOGE("wpa_supplicant is running.(%s)\n",buf);

         }else{// Open wpa_supplicant

             bzero(buf,200);

-            

+

             snprintf(buf,200,

                 "wpa_supplicant -Dnl80211 -c%s -i%s -f%s -ddd &",

                 conf_file,

                 interface,

                 WPA_SUPPLICANT_LOG_FILE);

-            

+

             /*

              snprintf(buf,200,

                 "wpa_supplicant -Dnl80211 -iwlan0 -c/etc/wifi/wpa_supplicant.conf -B");

@@ -538,7 +548,7 @@
         goto end_fail;

     }

 

-end_success:

+//end_success:

 

     return result;

 end_fail:

@@ -563,7 +573,7 @@
 

     sta_event_thread_is_running = 0;

     // End thread.

-    write(sta_ctrl_pipe_fd[1],"0",1);

+    mbtk_write(sta_ctrl_pipe_fd[1],"0",1);

 

 

     LOGE("Waitting for thread(%ld) exit.\n",sta_event_thread_id);

@@ -591,7 +601,7 @@
         }

     }

 

-end_success:

+//end_success:

     LOGE("sta_ctrl_wpa_deinit() end(success).\n");

     return result;

 end_fail:

diff --git a/mbtk/mbtk_rild_v2/src/atchannel.c b/mbtk/mbtk_rild_v2/src/atchannel.c
index 56b1d08..fe96df1 100755
--- a/mbtk/mbtk_rild_v2/src/atchannel.c
+++ b/mbtk/mbtk_rild_v2/src/atchannel.c
@@ -847,7 +847,7 @@
 
     pthread_attr_init (&attr);
     pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-    ret = pthread_create(&s_tid_reader, &attr, readerLoop, &attr);
+    ret = pthread_create(&s_tid_reader, &attr, readerLoop, NULL);
     if (ret < 0)
     {
         LOGE("AT thread create fail.");
@@ -855,7 +855,7 @@
     }
 
     pthread_t uart_tid_reader;
-    ret = pthread_create(&uart_tid_reader, &attr, readerUrcLoop, &attr);
+    ret = pthread_create(&uart_tid_reader, &attr, readerUrcLoop, NULL);
     if (ret < 0)
     {
         LOGE("Uart thread create fail.");
@@ -1244,7 +1244,7 @@
  */
 int at_handshake()
 {
-    int i;
+//    int i;
     int err = 0;
 
     if (0 != pthread_equal(s_tid_reader, pthread_self()))
diff --git a/mbtk/mbtk_rild_v2/src/main.c b/mbtk/mbtk_rild_v2/src/main.c
index c1a20c8..e2020fc 100755
--- a/mbtk/mbtk_rild_v2/src/main.c
+++ b/mbtk/mbtk_rild_v2/src/main.c
@@ -32,12 +32,14 @@
 #include "mbtk_str.h"

 #include "mbtk_queue.h"

 

+#ifndef TEMP_FAILURE_RETRY

 #define TEMP_FAILURE_RETRY(exp) ({         \

     typeof (exp) _rc;                      \

     do {                                   \

         _rc = (exp);                       \

     } while (_rc == -1 && errno == EINTR); \

     _rc; })

+#endif

 

 #define BUFFER_SIZE 2048

 #define UEVENT_USIM_DEV "/devices/virtual/usim_event/usim0"

@@ -176,7 +178,7 @@
     if(!ril_net_ready) {

         if(access(MBTK_BOOT_NET_READY , X_OK) == 0) {

             LOGD("Exec : %s", MBTK_BOOT_NET_READY);

-            system(MBTK_BOOT_NET_READY);

+            mbtk_system(MBTK_BOOT_NET_READY);

         } else {

             LOGE("%s can not exec.", MBTK_BOOT_NET_READY);

         }

@@ -192,7 +194,7 @@
     if(!ril_server_ready) {

         if(access(MBTK_BOOT_SERVER_READY , X_OK) == 0) {

             LOGD("Exec : %s", MBTK_BOOT_SERVER_READY);

-            system(MBTK_BOOT_SERVER_READY);

+            mbtk_system(MBTK_BOOT_SERVER_READY);

         } else {

             LOGE("%s can not exec.", MBTK_BOOT_SERVER_READY);

         }

@@ -290,7 +292,7 @@
     }
 }

 

-static void ril_state_change(ril_msg_id_enum msg_id, void *data, int data_len)

+static void ril_state_change(ril_msg_id_enum msg_id, const void *data, int data_len)

 {
     sock_cli_info_t *cli = NULL;

     list_first(ril_info.sock_client_list);

@@ -679,6 +681,11 @@
         state.tech = (mbtk_radio_technology_enum)tmp_int; // AcT

     }

 

+    if(state.reg_state == MBTK_NET_REG_STATE_HOME

+        || state.reg_state == MBTK_NET_REG_STATE_ROAMING) {

+        mbtk_net_ready();

+    }

+

     urc_msg_distribute(false, RIL_MSG_ID_IND_NET_REG_STATE_CHANGE, &state, sizeof(mbtk_ril_net_reg_state_info_t));

 CGREG_EXIT:

     free(tmp_s);

@@ -749,21 +756,30 @@
         // "+CGEV: ME PDN ACT ")) { // +CGEV: ME PDN ACT <cid>,1

         mbtk_ril_pdp_state_info_t cgev_info;

         memset(&cgev_info, 0, sizeof(mbtk_ril_pdp_state_info_t));

-        if (sscanf(s, "+CGEV: NW PDN DEACT %d", &(cgev_info.cid)) == 1) {

+        int cid, reason = 0;

+        memset(&cgev_info, 0, sizeof(mbtk_ril_pdp_state_info_t));

+        if (sscanf(s, "+CGEV: NW PDN DEACT %d", &cid) == 1) {

+            cgev_info.cid = (uint16)cid;

             cgev_info.action = FALSE;

-        } else if (sscanf(s, "+CGEV: ME PDN DEACT %d", &(cgev_info.cid)) == 1) {

+        } else if (sscanf(s, "+CGEV: ME PDN DEACT %d", &cid) == 1) {

+            cgev_info.cid = (uint16)cid;

             cgev_info.action = FALSE;

-        } else if(sscanf(s, "+CGEV: ME PDN ACT %d,%d", &(cgev_info.cid), &(cgev_info.reason)) == 2

-                || sscanf(s, "+CGEV: ME PDN ACT %d", &(cgev_info.cid)) == 1) {

+        } else if(sscanf(s, "+CGEV: ME PDN ACT %d,%d", &cid, &reason) == 2

+                || sscanf(s, "+CGEV: ME PDN ACT %d", &cid) == 1) {

+            cgev_info.cid = (uint16)cid;

+            cgev_info.reason = (uint16)reason;

             cgev_info.action = TRUE;

         } else if (!strcmp(s, "+CGEV: ME DETACH")) {

             if(cgact_wait.waitting) {

                 cgev_info.cid = cgact_wait.cid;

             }

             cgev_info.action = FALSE;

-        } else if (sscanf(s, "+CGEV: NW MODIFY %d,%d", &(cgev_info.cid), &(cgev_info.reason)) == 2) {

+        } else if (sscanf(s, "+CGEV: NW MODIFY %d,%d", &cid, &reason) == 2) {

+            cgev_info.cid = (uint16)cid;

+            cgev_info.reason = (uint16)reason;

             cgev_info.action = TRUE;

-        } else if(sscanf(s, "+CGEV: EPS PDN ACT %d", &(cgev_info.cid)) == 1) {

+        } else if(sscanf(s, "+CGEV: EPS PDN ACT %d", &cid) == 1) {

+            cgev_info.cid = (uint16)cid;

             cgev_info.action = TRUE;

         } else {

             LOGD(">>>>>>>>>No process +CGEV <<<<<<<<<");

@@ -2400,7 +2416,7 @@
         band_info.band_support.lte_ext_band = info_modem.band_lte_ext;

     }
 
-    bool is_first = TRUE;
+//    bool is_first = TRUE;

     while(!band_info.band_set_success) {

         // Set band.

 #if 0

@@ -2500,7 +2516,7 @@
     pthread_mutex_init(&ril_info.msg_mutex, NULL);

     pthread_cond_init(&ril_info.msg_cond, NULL);

 
-    pthread_t info_pid, pack_pid, monitor_pid, urc_pid, bootconn_pid;
+    pthread_t info_pid, pack_pid/*, monitor_pid, urc_pid, bootconn_pid*/;

     pthread_attr_t thread_attr;
     pthread_attr_init(&thread_attr);
     if(pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED))
diff --git a/mbtk/mbtk_rild_v2/src/ril_call.c b/mbtk/mbtk_rild_v2/src/ril_call.c
index 6264972..3891143 100755
--- a/mbtk/mbtk_rild_v2/src/ril_call.c
+++ b/mbtk/mbtk_rild_v2/src/ril_call.c
@@ -27,8 +27,8 @@
 static int req_call_start(char *phont_number, int *cme_err)
 {
     ATResponse *response = NULL;
-    int tmp_int;
-    char *tmp_str = NULL;
+//    int tmp_int;
+//    char *tmp_str = NULL;
     char cmd[100] = {0};
     sprintf(cmd, "ATD%s;", phont_number);
     int err = at_send_command(cmd, &response);
diff --git a/mbtk/mbtk_rild_v2/src/ril_data_call.c b/mbtk/mbtk_rild_v2/src/ril_data_call.c
index 14d1128..d5bcb2c 100755
--- a/mbtk/mbtk_rild_v2/src/ril_data_call.c
+++ b/mbtk/mbtk_rild_v2/src/ril_data_call.c
@@ -5,10 +5,12 @@
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <netinet/in.h>
+#include <arpa/inet.h>
 #include <pthread.h>
 #include <sys/epoll.h>
 #include <fcntl.h>
 #include <signal.h>
+#include <cutils/properties.h>
 
 #include "mbtk_type.h"
 #include "mbtk_ril.h"
@@ -16,6 +18,8 @@
 #include "at_tok.h"
 #include "mbtk_utils.h"
 #include "ril_info.h"
+#include "mbtk_ifc.h"
+#include "mbtk_str.h"
 
 ril_cgact_wait_t cgact_wait;
 static ril_data_call_info_t info_list[MBTK_APN_CID_MAX];
@@ -23,6 +27,7 @@
 static int req_apn_get(bool get_def_cid, mbtk_apn_info_array_t *apns, int *cme_err);
 static int req_apn_set(mbtk_apn_info_t *apn, int *cme_err);
 static void apn_prop_get(mbtk_apn_info_array_t *apns);
+void ril_rsp_pack_send(int fd, int ril_id, int msg_index, const void* data, int data_len);
 
 /*
 IPv4 : 10.255.74.26
@@ -56,7 +61,7 @@
         // Add default route.
         memset(buf, 0, sizeof(buf));
         sprintf(buf, "route add default dev ccinet%d", cid - 1);
-        system(buf);
+        mbtk_system(buf);
     }
 }
 
@@ -390,7 +395,7 @@
             if(!is_change) {
                 index = 0;
                 while(index < apns.num) {
-                    if(strcmp(apns.apns[index].apn,apn->apn) == 0) {
+                    if(strcmp((char*)apns.apns[index].apn,(char*)apn->apn) == 0) {
                         LOGW("APN : %s exist.", apn->apn);
                         return -1;
                     }
@@ -657,9 +662,9 @@
         if(!str_empty(apn->apn)) {
             snprintf(prop_data, 1024, "%d,%d,%d,%s,%s,%s,%s", apn->ip_type, apn->auth, apn->auto_boot_call,
                 apn->apn,
-                str_empty(apn->user) ? "NULL" : apn->user,
-                str_empty(apn->pass) ? "NULL" : apn->pass,
-                str_empty(apn->pass) ? "NULL" : apn->type);
+                str_empty(apn->user) ? "NULL" : (char*)apn->user,
+                str_empty(apn->pass) ? "NULL" : (char*)apn->pass,
+                str_empty(apn->pass) ? "NULL" : (char*)apn->type);
         }
 
 #if 0
@@ -808,7 +813,7 @@
         lines_ptr = lines_ptr->p_next;
     }
 
-    char prop_name[128] = {0};
+ //   char prop_name[128] = {0};
     char prop_data[1024] = {0};
     char def_cid[10] = {0};
     sprintf(def_cid, "%d", MBTK_RIL_CID_DEF);
@@ -872,7 +877,7 @@
                 break;
             }
         }
-        if(strlen(apn->apn) > 0) {
+        if(strlen((char*)apn->apn) > 0) {
             index += sprintf(cmd + index,"\"%s\"", apn->apn);
         }
 
diff --git a/mbtk/mbtk_rild_v2/src/ril_dev.c b/mbtk/mbtk_rild_v2/src/ril_dev.c
index 0fe2d2f..4d267de 100755
--- a/mbtk/mbtk_rild_v2/src/ril_dev.c
+++ b/mbtk/mbtk_rild_v2/src/ril_dev.c
@@ -221,7 +221,7 @@
 static int req_volte_get(int *state, int *cme_err)
 {
     ATResponse *response = NULL;
-    char *tmp_ptr = NULL;
+//    char *tmp_ptr = NULL;
     int err = at_send_command_singleline("AT+ACONFIG?", "", &response);
 
     if (err < 0 || response->success == 0 || !response->p_intermediates){
diff --git a/mbtk/mbtk_rild_v2/src/ril_ecall.c b/mbtk/mbtk_rild_v2/src/ril_ecall.c
index 4de85b4..3c61159 100755
--- a/mbtk/mbtk_rild_v2/src/ril_ecall.c
+++ b/mbtk/mbtk_rild_v2/src/ril_ecall.c
@@ -24,7 +24,7 @@
 static int cfg_ecalldata_get(mbtk_ecall_cfg_item_enum type, uint32 *value, int *cme_err)
 {
     ATResponse *response = NULL;
-    char *tmp_ptr = NULL;
+//    char *tmp_ptr = NULL;
     int tmp_int;
     char cmd[100] = {0};
     int err = 0;
@@ -462,7 +462,7 @@
 {
     ATResponse *response = NULL;
     char *tmp_ptr = NULL;
-    int tmp_int;
+//    int tmp_int;
     int err = 0;
 
     cfg->type = type;
@@ -934,7 +934,7 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, msd, strlen(msd));
+                    ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, msd, strlen((char*)msd));
                 }
             }
             else     // Set
@@ -1170,7 +1170,7 @@
             memset(number, 0, sizeof(number));
             if(pack->data_len == 0 || pack->data == NULL)
             {
-                if(req_ecall_sms_num_get(number, &cme_err) || strlen(number) == 0 || cme_err != MBTK_RIL_ERR_CME_NON)
+                if(req_ecall_sms_num_get(number, &cme_err) || strlen((char*)number) == 0 || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
                         err = MBTK_RIL_ERR_CME + cme_err;
@@ -1181,7 +1181,7 @@
                 }
                 else
                 {
-                    ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, number, strlen(number));
+                    ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, number, strlen((char*)number));
                 }
             }
             else     // Set
diff --git a/mbtk/mbtk_rild_v2/src/ril_net.c b/mbtk/mbtk_rild_v2/src/ril_net.c
index 16d3118..8aacb7c 100755
--- a/mbtk/mbtk_rild_v2/src/ril_net.c
+++ b/mbtk/mbtk_rild_v2/src/ril_net.c
@@ -1150,7 +1150,7 @@
 static int req_cell_info_set(const char *cmgl, char *reg, int len, int *cme_err)
 {
     ATResponse *response = NULL;
-    char cmd[30] = {0};
+    char cmd[500] = {0};
 	char data[218] = {0};
     int err = 0;
 
@@ -1168,8 +1168,8 @@
 
         ATLine* lines_ptr = response->p_intermediates;
         char *line = NULL;
-        int reg_len = 0;
-		bool flag = false;
+//        int reg_len = 0;
+//		bool flag = false;
         while(lines_ptr)
         {
             line = lines_ptr->line;
diff --git a/mbtk/mbtk_rild_v2/src/ril_pb.c b/mbtk/mbtk_rild_v2/src/ril_pb.c
index 088aa46..522f578 100755
--- a/mbtk/mbtk_rild_v2/src/ril_pb.c
+++ b/mbtk/mbtk_rild_v2/src/ril_pb.c
@@ -25,7 +25,7 @@
 mbtk_ril_err_enum pb_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack)
 {
     mbtk_ril_err_enum err = MBTK_RIL_ERR_SUCCESS;
-    int cme_err = MBTK_RIL_ERR_CME_NON;
+//    int cme_err = MBTK_RIL_ERR_CME_NON;
     switch(pack->msg_id)
     {
         case RIL_MSG_ID_PB_STATE:
diff --git a/mbtk/mbtk_rild_v2/src/ril_sim.c b/mbtk/mbtk_rild_v2/src/ril_sim.c
index ebc09f2..78ef0f0 100755
--- a/mbtk/mbtk_rild_v2/src/ril_sim.c
+++ b/mbtk/mbtk_rild_v2/src/ril_sim.c
@@ -157,7 +157,7 @@
 static int req_sim_type_get(uint8 *type, int *cme_err)
 {
     ATResponse *response = NULL;
-    char *tmp_ptr = NULL;
+//    char *tmp_ptr = NULL;
     int err = at_send_command_singleline("AT*EUICC?", "*EUICC:", &response);
 
     if (err < 0 || response->success == 0 || !response->p_intermediates){
@@ -297,7 +297,7 @@
 static int req_sim_lock_state_get(int *state, int *cme_err)
 {
     ATResponse *response = NULL;
-    char cmd[64]={0};
+//    char cmd[64]={0};
 
     int err = at_send_command_singleline("AT+CLCK=SC,2", "+CLCK:", &response);
     if (err < 0 || response == NULL || response->success == 0 || !response->p_intermediates){
@@ -501,7 +501,8 @@
 static int req_pin_puk_last_times_get(mbtk_pin_puk_last_times_t *times, int *cme_err)
 {
     ATResponse *response = NULL;
-    char *tmp_ptr = NULL;
+//    char *tmp_ptr = NULL;
+    int tmp_int;
     int err = at_send_command_singleline("AT+EPIN?", "+EPIN:", &response);
 
     if (err < 0 || response->success == 0 || !response->p_intermediates){
@@ -516,29 +517,33 @@
         goto exit;
     }
     mbtk_pin_puk_last_times_t last_times={0};
-    err = at_tok_nextint(&line, &(last_times.p1_retry));
+    err = at_tok_nextint(&line, &tmp_int);
     if (err < 0)
     {
         goto exit;
     }
+    last_times.p1_retry = (uint8_t)tmp_int;
     times->p1_retry = last_times.p1_retry;
-    err = at_tok_nextint(&line, &(last_times.p2_retry));
+    err = at_tok_nextint(&line, &tmp_int);
     if (err < 0)
     {
         goto exit;
     }
+    last_times.p2_retry = (uint8_t)tmp_int;
     times->p2_retry = last_times.p2_retry;
-    err = at_tok_nextint(&line, &(last_times.puk1_retry));
+    err = at_tok_nextint(&line, &tmp_int);
     if (err < 0)
     {
         goto exit;
     }
+    last_times.puk1_retry = (uint8_t)tmp_int;
     times->puk1_retry = last_times.puk1_retry;
-    err = at_tok_nextint(&line, &(last_times.puk2_retry));
+    err = at_tok_nextint(&line, &tmp_int);
     if (err < 0)
     {
         goto exit;
     }
+    last_times.puk2_retry = (uint8_t)tmp_int;
     times->puk2_retry = last_times.puk2_retry;
 
 exit:
@@ -546,6 +551,7 @@
     return err;
 }
 
+
 /*
 AT+CPOL?
 *EUICC: 1
@@ -555,7 +561,7 @@
 static int req_plmn_get(mbtk_plmn_info *info, int *cme_err)
 {
     ATResponse *response = NULL;
-    char *tmp_ptr = NULL;
+//    char *tmp_ptr = NULL;
     int err = at_send_command_multiline("AT+CPOL?", "+CPOL:", &response);
 
     if (err < 0 || response->success == 0 || !response->p_intermediates){
diff --git a/mbtk/mbtk_rild_v2/src/ril_sms.c b/mbtk/mbtk_rild_v2/src/ril_sms.c
index 081ad01..c2c87d6 100755
--- a/mbtk/mbtk_rild_v2/src/ril_sms.c
+++ b/mbtk/mbtk_rild_v2/src/ril_sms.c
@@ -29,7 +29,7 @@
 static int req_cmgf_get(int *state, int *cme_err)
 {
     ATResponse *response = NULL;
-    char *tmp_ptr = NULL;
+//    char *tmp_ptr = NULL;
     int err = at_send_command_singleline("AT+CMGF?", "", &response);
 
     if (err < 0 || response->success == 0 || !response->p_intermediates){
@@ -63,8 +63,8 @@
 */
 static int req_cmgf_set(int state, int *cme_err)
 {
-    printf("req_cmgf_set()-------------start\n");
-    printf("state:%d\n",state);
+    LOGD("req_cmgf_set()-------------start");
+    LOGD("state:%d",state);
     ATResponse *response = NULL;
     char cmd[30] = {0};
     if(state)
@@ -76,7 +76,7 @@
         strcpy(cmd, "AT+CMGF=0");
     }
 
-    printf("req_cmgf_set()----cmd:%s\n", cmd);
+    LOGD("req_cmgf_set()----cmd:%s", cmd);
     int err = at_send_command(cmd, &response);
 
     if (err < 0 || response->success == 0) {
@@ -127,7 +127,7 @@
 {
 	printf("req_cpms_get------------start(3)\n");
     ATResponse *response = NULL;
-    char *tmp_ptr = NULL;
+//    char *tmp_ptr = NULL;
     int err = at_send_command_singleline("AT+CPMS?", "", &response);
 
     if (err < 0 || response->success == 0 || !response->p_intermediates){
@@ -226,15 +226,15 @@
 */
 static int req_cmgs_set(char *cmgs, char *reg, int len, int *cme_err)
 {
-    printf("req_cmgs_set()----------------start\n");
-    printf("cmgs:%s\n", cmgs);
+    LOGD("req_cmgs_set()----------------start");
+    LOGD("cmgs:%s", cmgs);
     ATResponse *response = NULL;
     char cmd[30] = {0};
 	char data[218] = {0};
 	char pnum[20] = {0};
     char *ptr = cmgs;
     int err = 0;
-	int data_len = 0;
+//	int data_len = 0;
 
 	char *src = strstr(cmgs, ",");
 	if(src != NULL)
@@ -249,14 +249,21 @@
 		memcpy(data, src, data_len);
 		//LOG("[XIAORUI]req_cmgs_set()----------------data %s",data);
 	}
+    else
+    {
+        LOGD("cmgs param is error");
+        return -1;
+    }
+    LOGD("num:%s", pnum);
+    LOGD("data:%s", data);
 
 	sprintf(cmd, "AT+CMGS=%s", pnum);
-	LOG("cmd:%s,data:%s---------", cmd,data);
+    LOGD("cmd:%s", cmd);
 
 	if(strlen(cmd) > 0)
 	{
 		int err = at_send_command_sms(cmd, data, "+CMGS: ", &response);
-		printf("err:%d, response:%d\n", err, response->success);
+		LOGD("err:%d, response:%d", err, response->success);
 
 		if (err < 0 || response->success == 0) {
 	        *cme_err = at_get_cme_error(response);
@@ -265,7 +272,7 @@
 		char *line;
 		line = response->p_intermediates->line;
 		memcpy(reg, line, strlen(line));
-		printf("line:%s\n", line);
+		LOGD("line:%s", line);
 
 	}
     err = 0;
@@ -328,10 +335,10 @@
     printf("0req_cmgd_set()--------------start\n");
     printf("cmgd:%s\n", cmgd);
     ATResponse *response = NULL;
-    char cmd[30] = {0};
+    char cmd[500] = {0};
 	char data[218] = {0};
-	char pnum[13] = {0};
-    char *ptr = cmgd;
+//	char pnum[13] = {0};
+//    char *ptr = cmgd;
     int err = 0;
 
 	memcpy(data, cmgd, len );
@@ -368,7 +375,7 @@
 static int req_cmgd_get(char *reg, int *cme_err)
 {
     ATResponse *response = NULL;
-    char *tmp_ptr = NULL;
+//    char *tmp_ptr = NULL;
     int err = at_send_command_singleline("AT+CMGD=?", "+CMGD:", &response);
 
     if (err < 0 || response->success == 0 || !response->p_intermediates){
@@ -424,7 +431,7 @@
 	int s_index = 0, g_index = 0;
 	bool index_flag = false;
 	char *ptr_index = index_data;
-	char phone[50];
+//	char phone[50];
 	char number[5] = {0};
     int err = 0;
 
@@ -512,8 +519,8 @@
 
 	if(index_flag)
 	{
-		memset(reg, 0, sizeof(reg));
-		memcpy(reg, ptr_index, strlen(ptr_index) );
+		// memset(reg, 0, sizeof(reg));
+		memcpy(reg, ptr_index, strlen(ptr_index) + 1);
 	}
     err = 0;
 exit:
@@ -530,7 +537,7 @@
 static int req_csca_get(char *req, int *cme_err)
 {
     ATResponse *response = NULL;
-    char *tmp_ptr = NULL;
+//    char *tmp_ptr = NULL;
     int err = at_send_command_singleline("AT+CSCA?", "", &response);
 
     if (err < 0 || response->success == 0 || !response->p_intermediates){
@@ -563,10 +570,10 @@
     printf("req_csca_set()--------------start\n");
     printf("csca:%s\n", csca);
     ATResponse *response = NULL;
-    char cmd[30] = {0};
+    char cmd[500] = {0};
 	char data[218] = {0};
-	char pnum[13] = {0};
-    char *ptr = csca;
+//	char pnum[13] = {0};
+//    char *ptr = csca;
     int err = 0;
 
 	memcpy(data, csca, len);
@@ -596,10 +603,10 @@
     printf("req_csmp_set()-------------------start\n");
     printf("csmp:%s\n", csmp);
     ATResponse *response = NULL;
-    char cmd[30] = {0};
+    char cmd[500] = {0};
 	char data[218] = {0};
-	char pnum[13] = {0};
-    char *ptr = csmp;
+//	char pnum[13] = {0};
+//    char *ptr = csmp;
     int err = 0;
 
 	memcpy(data, csmp, len);
@@ -631,8 +638,8 @@
     ATResponse *response = NULL;
     char cmd[30] = {0};
 	char data[218] = {0};
-	char pnum[13] = {0};
-    char *ptr = cscb;
+//	char pnum[13] = {0};
+//    char *ptr = cscb;
     int err = 0;
 
 	memcpy(data, cscb, len);
@@ -839,7 +846,7 @@
         {
             if(pack->data_len == 0 || pack->data == NULL)   // SET at+cnmi=1,2.
             {
-                int state;
+//                int state;
                 if(req_cnmi_set(&cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_RIL_ERR_CME_NON) {
diff --git a/mbtk/mbtk_sdk_ready_v2/src/main.c b/mbtk/mbtk_sdk_ready_v2/src/main.c
index bed49c7..c69729b 100755
--- a/mbtk/mbtk_sdk_ready_v2/src/main.c
+++ b/mbtk/mbtk_sdk_ready_v2/src/main.c
@@ -1,12 +1,13 @@
 #if 1
 #include <stdio.h>
-//#include <stdlib.h>
-//#include <unistd.h>
+#include <stdlib.h>
+#include <unistd.h>
 #include <errno.h>
 #include <pthread.h>
 //#include <string.h>
 #include <fcntl.h>
 //#include <signal.h>
+#include <cutils/properties.h>
 
 #include "mbtk_log.h"
 #include "mbtk_ril_api.h"
@@ -29,7 +30,7 @@
 static mbtk_ready_status_type modem_check(void)
 {
     char imei[16]= {0};
-    int cme_err = 0;
+//    int cme_err = 0;
 
     mbtk_ril_err_enum ret;
     if(!ril_inited) {
diff --git a/mbtk/mbtk_servicesd_v2/src/instance_monitor_service.c b/mbtk/mbtk_servicesd_v2/src/instance_monitor_service.c
index 2557304..a814bd6 100755
--- a/mbtk/mbtk_servicesd_v2/src/instance_monitor_service.c
+++ b/mbtk/mbtk_servicesd_v2/src/instance_monitor_service.c
@@ -31,7 +31,7 @@
 static void program_start(instance_info_t *info)
 {
     LOGD("Will start program : %s", info->ins_name);
-    system(info->ins_cmd);
+    mbtk_system(info->ins_cmd);
 }
 
 static int pidof(const char *program)
diff --git a/mbtk/mbtk_servicesd_v2/src/led_control_service.c b/mbtk/mbtk_servicesd_v2/src/led_control_service.c
index 7fd53dc..9f87cf5 100755
--- a/mbtk/mbtk_servicesd_v2/src/led_control_service.c
+++ b/mbtk/mbtk_servicesd_v2/src/led_control_service.c
@@ -31,9 +31,9 @@
 int mbtk_read_ccinet(void)
 {
     FILE *fp;
-    int ret = 0;
+//    int ret = 0;
     char buffer[1024];
-    char type[10]={0};
+//    char type[10]={0};
 
     fp = popen("ifconfig", "r");
     if (fp == NULL) {
@@ -41,7 +41,9 @@
         return -1;
     }
 
-    fread(buffer,1, sizeof(buffer) -1, fp);
+    if(fread(buffer,1, sizeof(buffer) -1, fp) <= 0) {
+
+    }
     //LOGE("[led]buffer:%s\n", buffer);
     pclose(fp); //
 
@@ -290,7 +292,7 @@
 
 int mbtk_led_init(void)
 {
-    int ret = MBTK_RESULT_FAIL;
+//    int ret = MBTK_RESULT_FAIL;
 
     mbtk_led_gpio_init(MBTK_STATUS_LED);
     mbtk_led_gpio_init(MBTK_NET_LED);
@@ -299,7 +301,7 @@
 
     pthread_attr_t thread_attr;
     pthread_t net_led_thread_id;
-    pthread_t status_led_thread_id;
+//    pthread_t status_led_thread_id;
     pthread_attr_init(&thread_attr);
     if(pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED))
     {
diff --git a/mbtk/mbtk_servicesd_v2/src/main.c b/mbtk/mbtk_servicesd_v2/src/main.c
index 6afe654..f546cd3 100755
--- a/mbtk/mbtk_servicesd_v2/src/main.c
+++ b/mbtk/mbtk_servicesd_v2/src/main.c
@@ -22,6 +22,8 @@
 #include "mbtk_type.h"
 #include "mbtk_log.h"
 #include "instance_info.h"
+#include "mbtk_str.h"
+#include "mbtk_utils.h"
 
 #define MBTK_SERVICES_PID_FILE "/var/run/mbtk_servicesd.pid"
 #define MBTK_SERVICES_CONF_FILE "/etc/mbtk_servicesd.conf"
diff --git a/mbtk/mbtk_servicesd_v2/src/ntp_service.c b/mbtk/mbtk_servicesd_v2/src/ntp_service.c
index c552d88..7772544 100755
--- a/mbtk/mbtk_servicesd_v2/src/ntp_service.c
+++ b/mbtk/mbtk_servicesd_v2/src/ntp_service.c
@@ -34,7 +34,7 @@
 static int metis_strptime(char *str_time)
 {
     struct tm stm;
-    char dateTime[30];
+//    char dateTime[30];
     struct timeval tv;
     if(strptime(str_time, "%Y-%m-%d %H:%M:%S",&stm) != NULL)
     {
diff --git a/mbtk/test/libmbtk_ecall/mbtk_ecall_test_v2.c b/mbtk/test/libmbtk_ecall/mbtk_ecall_test_v2.c
index f625369..9ec898d 100755
--- a/mbtk/test/libmbtk_ecall/mbtk_ecall_test_v2.c
+++ b/mbtk/test/libmbtk_ecall/mbtk_ecall_test_v2.c
@@ -13,6 +13,7 @@
 
 #include "mbtk_ril_api.h"
 
+#if 0
 #define CLI_THREAD_MAX 3
 
 typedef struct {
@@ -23,6 +24,7 @@
 
 static ril_cli_thread_info_t cli_threads[CLI_THREAD_MAX];
 static int cli_pid_index = 1;
+#endif
 
 static void help()
 {
@@ -41,6 +43,7 @@
     printf("gain <0/1/2> <gain>: Set ecall DSP gain.\n");
 }
 
+#if 0
 static void thread_exit_with_wait()
 {
     int i = 0;
@@ -58,6 +61,7 @@
         i++;
     }
 }
+#endif
 
 static void ecall_state_change_cb(const void* data, int data_len)
 {
@@ -77,21 +81,21 @@
         case SIGINT: // Ctrl + C
         {
             LOGI("Exit by SIGINT.\n");
-            thread_exit_with_wait();
+//            thread_exit_with_wait();
             mbtk_ril_deinit();
             exit(0);
         }
         case SIGQUIT: // Ctrl + \ (类似 SIGINT ,但要产生core文件)
         {
             LOGI("Exit by SIGQUIT.\n");
-            thread_exit_with_wait();
+//            thread_exit_with_wait();
             mbtk_ril_deinit();
             exit(0);
         }
         case SIGTERM:// 默认kill   (同 SIGKILL ,但 SIGKILL 不可捕获)
         {
             LOGI("Exit by SIGTERM.\n");
-            thread_exit_with_wait();
+//            thread_exit_with_wait();
             mbtk_ril_deinit();
             exit(0);
         }
@@ -113,6 +117,7 @@
     }
 }
 
+#if 0
 static char* thread_id2name(pthread_t pid)
 {
     int i = 0;
@@ -150,6 +155,7 @@
     printf("[%s] exit.\n", thread_id2name(cli->pid));
     return NULL;
 }
+#endif
 
 int main(int argc, char *argv[])
 {
@@ -197,7 +203,7 @@
                 memset(&cfg, 0, sizeof(mbtk_ecall_msd_cfg_info_t));
                 int item;
                 int count = sscanf(cmd, "msdcfg %d %s", &item, cfg.data);
-                if(count == 2 && strlen(cfg.data) > 0) {
+                if(count == 2 && strlen((char*)cfg.data) > 0) {
                     cfg.item_type = (mbtk_ecall_msd_item_enum)item;
                     err = mbtk_ecall_msd_item_set(&cfg);
                     if(err != MBTK_RIL_ERR_SUCCESS) {
@@ -232,7 +238,7 @@
                     }
                 } else { // Set
                     int count = sscanf(cmd, "msd %s", msd);
-                    if(count == 1 && strlen(msd) > 0) { // set
+                    if(count == 1 && strlen((char*)msd) > 0) { // set
                         err = mbtk_ecall_msd_set(msd);
                         if(err != MBTK_RIL_ERR_SUCCESS) {
                             printf("Error : %d\n", err);
@@ -458,7 +464,7 @@
                     }
                 } else { // Set
                     int count = sscanf(cmd, "sms_num %s", number);
-                    if(count == 1 && strlen(number) > 0) {
+                    if(count == 1 && strlen((char*)number) > 0) {
                         err = mbtk_ecall_sms_number_set(number);
                         if(err != MBTK_RIL_ERR_SUCCESS) {
                             printf("Error : %d\n", err);
@@ -510,9 +516,9 @@
         }
     }
 
-    thread_exit_with_wait();
+//    thread_exit_with_wait();
 
-exit:
+//exit:
     mbtk_ril_deinit();
 
     LOG("Client exec complete.");
diff --git a/mbtk/test/libmbtk_ril/mbtk_ril_test.c b/mbtk/test/libmbtk_ril/mbtk_ril_test.c
index dc0c65d..a95e571 100755
--- a/mbtk/test/libmbtk_ril/mbtk_ril_test.c
+++ b/mbtk/test/libmbtk_ril/mbtk_ril_test.c
@@ -10,11 +10,16 @@
 #include <string.h>
 #include <fcntl.h>
 #include <signal.h>
+#include <arpa/inet.h>
 
 #include "mbtk_ril_api.h"
+#include "mbtk_str.h"
 
 #define CLI_THREAD_MAX 3
 
+#define RIL_DEBUG_THREAD 0
+
+#if RIL_DEBUG_THREAD
 typedef struct {
     pthread_t pid;
     bool is_running;
@@ -23,6 +28,7 @@
 
 static ril_cli_thread_info_t cli_threads[CLI_THREAD_MAX];
 static int cli_pid_index = 1;
+#endif
 
 static void help()
 {
@@ -84,6 +90,7 @@
     printf("ims_reg: Get IMS register state.\n");
 }
 
+#if RIL_DEBUG_THREAD
 static void thread_exit_with_wait()
 {
     int i = 0;
@@ -101,11 +108,12 @@
         i++;
     }
 }
+#endif
 
 static void ril_ser_state_change_cb(const void* data, int data_len)
 {
     if(data) {
-        uint8 *ptr = (const char*)data;
+        const uint8 *ptr = (const uint8*)data;
         mbtk_ril_ser_state_enum state = (mbtk_ril_ser_state_enum)ptr[0];
         printf("ril server state : %d.\n", state);
     }
@@ -182,21 +190,27 @@
         case SIGINT: // Ctrl + C
         {
             LOGI("Exit by SIGINT.\n");
+#if RIL_DEBUG_THREAD
             thread_exit_with_wait();
+#endif
             mbtk_ril_deinit();
             exit(0);
         }
         case SIGQUIT: // Ctrl + \ (类似 SIGINT ,但要产生core文件)
         {
             LOGI("Exit by SIGQUIT.\n");
+#if RIL_DEBUG_THREAD
             thread_exit_with_wait();
+#endif
             mbtk_ril_deinit();
             exit(0);
         }
         case SIGTERM:// 默认kill   (同 SIGKILL ,但 SIGKILL 不可捕获)
         {
             LOGI("Exit by SIGTERM.\n");
+#if RIL_DEBUG_THREAD
             thread_exit_with_wait();
+#endif
             mbtk_ril_deinit();
             exit(0);
         }
@@ -218,6 +232,7 @@
     }
 }
 
+#if RIL_DEBUG_THREAD
 static char* thread_id2name(pthread_t pid)
 {
     int i = 0;
@@ -255,6 +270,7 @@
     printf("[%s] exit.\n", thread_id2name(cli->pid));
     return NULL;
 }
+#endif
 
 int main(int argc, char *argv[])
 {
@@ -298,7 +314,7 @@
 
     mbtk_ecall_state_change_cb_reg(ecall_state_change_cb);
 
-#if 0
+#if RIL_DEBUG_THREAD
     memset(cli_threads, 0, sizeof(ril_cli_thread_info_t) * CLI_THREAD_MAX);
 
     pthread_t pid1, pid2, pid3;
@@ -739,10 +755,10 @@
                             // printf("APN : %d, %s, %s\n", apns.apns[i].cid, apn2str(apns.apns[i].ip_type), apns.apns[i].apn);
                             printf("APN : %d, %s, auth-%d, auto_save-%d, auto_boot_call-%d, %s, %s, %s, %s\n", apns.apns[i].cid, apn2str(apns.apns[i].ip_type),
                                 apns.apns[i].auth, apns.apns[i].auto_save, apns.apns[i].auto_boot_call,
-                                str_empty(apns.apns[i].apn) ? "NULL" : apns.apns[i].apn,
-                                str_empty(apns.apns[i].user) ? "NULL" : apns.apns[i].user,
-                                str_empty(apns.apns[i].pass) ? "NULL" : apns.apns[i].pass,
-                                str_empty(apns.apns[i].type) ? "NULL" : apns.apns[i].type);
+                                str_empty(apns.apns[i].apn) ? "NULL" : (char*)apns.apns[i].apn,
+                                str_empty(apns.apns[i].user) ? "NULL" : (char*)apns.apns[i].user,
+                                str_empty(apns.apns[i].pass) ? "NULL" : (char*)apns.apns[i].pass,
+                                str_empty(apns.apns[i].type) ? "NULL" : (char*)apns.apns[i].type);
                             i++;
                         }
                         printf("Def route : %d, def dns : %d\n", apns.cid_for_def_route, apns.cid_for_def_dns);
@@ -757,7 +773,7 @@
                                     &def_route, &as_dns, apn.apn);
 
                     // Delete APN
-                    if(strcmp(apn.apn,"null") == 0 || strcmp(apn.apn,"NULL") == 0) {
+                    if(strcmp((char*)apn.apn,"null") == 0 || strcmp((char*)apn.apn,"NULL") == 0) {
                         memset(apn.apn, 0, sizeof(apn.apn));
                     }
                     if(count == 7) {
@@ -1001,7 +1017,7 @@
                     printf("Call success.\n");
                 }
             } else if(!strncasecmp(cmd, "hangup", 6)){
-                int phone_id;
+                int phone_id = 1;
                 if(!strcasecmp(cmd, "hangup")) { // hang up all
                     err = mbtk_call_hang();
                     if(err) {
@@ -1125,7 +1141,7 @@
 				char mem[100] = {0};
                 char resp[100] = {0};
                 if(!strcasecmp(cmd, "cpms")) { // Get
-                    err = mbtk_sms_cpms_get(&mem);
+                    err = mbtk_sms_cpms_get(mem);
                     if(err) {
                         printf("Error : %d\n", err);
                     } else {
@@ -1484,9 +1500,10 @@
         }
     }
 
+#if RIL_DEBUG_THREAD
     thread_exit_with_wait();
-
 exit:
+#endif
     mbtk_ril_deinit();
 
     LOG("Client exec complete.");