Fix code warning.

Change-Id: Ib11fb49f528d3688351ae349d5b4e307c28b3967
diff --git a/mbtk/aboot-tiny/jacana/jacana_main.c b/mbtk/aboot-tiny/jacana/jacana_main.c
index 96b4c53..abd0ef3 100755
--- a/mbtk/aboot-tiny/jacana/jacana_main.c
+++ b/mbtk/aboot-tiny/jacana/jacana_main.c
@@ -39,7 +39,9 @@
     fd = open((const char*)gpioCtrlPath, O_WRONLY);
 
     if (fd >= 0)    {
-        write(fd, str, strlen(str));
+        if(write(fd, str, strlen(str))) {
+
+        }
         close(fd);
     }
 }
@@ -57,20 +59,20 @@
 
 static int gpsHalFWDone()
 {
-    dubheWrite("on");  
+    dubheWrite("on");
     return 0;
 }
 
 static int gpsHalFWFail()
 {
-    dubheWrite("off");  
+    dubheWrite("off");
     return 0;
 }
 /*---------------------------------------------------------------------------*/
 void *
 jacana_mem_alloc(size_t size)
 {
-  void *ptr;  
+  void *ptr;
   ptr = malloc(size);
   return ptr;
 }
@@ -241,10 +243,10 @@
 //  }
 
   /* Mark Done. */
-  if (!ret)  
+  if (!ret)
     gpsHalFWDone();
   else
     gpsHalFWFail();
-  
+
   return ret;
 }
diff --git a/mbtk/include/mbtk/mbtk_info_api.h b/mbtk/include/mbtk/mbtk_info_api.h
index 09fce5f..fef67fd 100755
--- a/mbtk/include/mbtk/mbtk_info_api.h
+++ b/mbtk/include/mbtk/mbtk_info_api.h
@@ -59,20 +59,20 @@
     MBTK_OFFERING,

 } mbtk_call_stat_enum;

 

-typedef enum {

+typedef enum {
     MBTK_ECALL_CFG_ITEM_T3 = 0,         // ms

     MBTK_ECALL_CFG_ITEM_T5,             // ms

     MBTK_ECALL_CFG_ITEM_T6,             // ms

     MBTK_ECALL_CFG_ITEM_T7,             // ms

     MBTK_ECALL_CFG_ITEM_TH,             // ms

     MBTK_ECALL_CFG_ITEM_TIMER_CALLBACK,     // T9       // 5

-    MBTK_ECALL_CFG_ITEM_TIMER_CLEARDOWN,     // T2

-    MBTK_ECALL_CFG_ITEM_TIMER_DEREG,    // T10

-    MBTK_ECALL_CFG_ITEM_TIMER_DIAL,     // "dial"

-    MBTK_ECALL_CFG_ITEM_TIMER_REDIAL,   // "redialtmr"

+    MBTK_ECALL_CFG_ITEM_TIMER_CLEARDOWN,     // T2
+    MBTK_ECALL_CFG_ITEM_TIMER_DEREG,    // T10
+    MBTK_ECALL_CFG_ITEM_TIMER_DIAL,     // "dial"
+    MBTK_ECALL_CFG_ITEM_TIMER_REDIAL,   // "redialtmr"
     MBTK_ECALL_CFG_ITEM_TIMER_SMS,      // "sms"        // 10

-    MBTK_ECALL_CFG_ITEM_REDIALCNT,      // "redialcnt"

-    MBTK_ECALL_CFG_ITEM_SMSPROCESS,     // "smsprocess"

+    MBTK_ECALL_CFG_ITEM_REDIALCNT,      // "redialcnt"
+    MBTK_ECALL_CFG_ITEM_SMSPROCESS,     // "smsprocess"
     MBTK_ECALL_CFG_ITEM_SMSMSDCNT,       // "smsmsdcnt"

 

     MBTK_ECALL_CFG_ITEM_MAX

@@ -657,14 +657,14 @@
     uint32 timer_t7;    // ms

     uint32 timer_th;    // ms

 

-    uint32 timer_callback; // s (T9)
+    uint32 timer_callback; // s (T9)

     uint32 timer_cleardown; // s (T2)

     uint32 timer_dereg;     // s (T10)

     uint32 timer_dial;  // s

     uint32 timer_redialtmr; // s

     uint32 timer_sms;   // s

 

-    uint32 redialcnt;
+    uint32 redialcnt;

     uint32 smsprocess;

     uint32 smsmsdcnt;

 #else

@@ -686,7 +686,7 @@
 } mbtk_ecall_gain_info_t;

 

 

-

+int ipv6_2_str(const void *ipv6, void *ipv6_str);

 

 mbtk_info_handle_t* mbtk_info_handle_get();

 

@@ -1164,114 +1164,114 @@
 //set led

 int mbtk_led_set(mbtk_info_handle_t* handle, mbtk_led_type type, mbtk_led_status status);

 

-

-/*

-* Set msd item.

-*

-*/

+
+/*
+* Set msd item.
+*
+*/
 int mbtk_ecall_msd_item_set(mbtk_info_handle_t* handle, const mbtk_ecall_msd_cfg_info_t *msd_cfg);

-

-/*

-* Generate msd after msd item set.

-*

-*/

+
+/*
+* Generate msd after msd item set.
+*
+*/
 int mbtk_ecall_msd_gen(mbtk_info_handle_t* handle);

-

-/*

-* Set ecall msd.

-*

-*/

+
+/*
+* Set ecall msd.
+*
+*/
 int mbtk_ecall_msd_set(mbtk_info_handle_t* handle, const void* msd);

-

-/*

-* Get ecall msd.

-*

-*/

+
+/*
+* Get ecall msd.
+*
+*/
 int mbtk_ecall_msd_get(mbtk_info_handle_t* handle, void* msd);

-

-

-/*

-* Set ecall msd item.

-*

-*/

+
+
+/*
+* Set ecall msd item.
+*
+*/
 int mbtk_ecall_push(mbtk_info_handle_t* handle);

-

-/*

-* Set ecall only configs.

-*

-*/

+
+/*
+* Set ecall only configs.
+*
+*/
 int mbtk_ecall_only_set(mbtk_info_handle_t* handle, const mbtk_ecall_only_info_t* info);

-

-/*

-* Get ecall only configs.

-*

-*/

+
+/*
+* Get ecall only configs.
+*
+*/
 int mbtk_ecall_only_get(mbtk_info_handle_t* handle, mbtk_ecall_only_info_t* info);

-

-/*

-* Set ecall network reg.

-*

-*/

+
+/*
+* Set ecall network reg.
+*
+*/
 int mbtk_ecall_reg_set(mbtk_info_handle_t* handle, int reg);

-

-/*

-* Start ecall dial start.

-*

-*/

+
+/*
+* Start ecall dial start.
+*
+*/
 int mbtk_ecall_dial_start(mbtk_info_handle_t* handle, mbtk_ecall_dial_type_enum type);

-

-/*

-* Get ecall dial state.

-*

-*/

+
+/*
+* Get ecall dial state.
+*
+*/
 int mbtk_ecall_dial_state_get(mbtk_info_handle_t* handle, mbtk_ecall_dial_type_enum* type);

-

-/*

-* Set ecall mode.

-*

-*/

+
+/*
+* Set ecall mode.
+*
+*/
 int mbtk_ecall_mode_set(mbtk_info_handle_t* handle, mbtk_ecall_mode_type_enum mode);

-

-/*

-* Get ecall mode.

-*

-*/

+
+/*
+* Get ecall mode.
+*
+*/
 int mbtk_ecall_mode_get(mbtk_info_handle_t* handle, mbtk_ecall_mode_type_enum *mode);

-

-/*

-* Set ecall configs.

-*

-*/

+
+/*
+* Set ecall configs.
+*
+*/
 int mbtk_ecall_cfg_set(mbtk_info_handle_t* handle, const mbtk_ecall_cfg_info_t *cfg);

-

-/*

-* Get ecall configs.

-*

-*/

+
+/*
+* Get ecall configs.
+*
+*/
 int mbtk_ecall_cfg_get(mbtk_info_handle_t* handle, mbtk_ecall_cfg_info_t* cfg);

-

-/*

-* Set ecall sms number.

-*

-*/

+
+/*
+* Set ecall sms number.
+*
+*/
 int mbtk_ecall_sms_number_set(mbtk_info_handle_t* handle, const void *number);

-

-/*

-* Get ecall sms number.

-*

-*/

+
+/*
+* Get ecall sms number.
+*
+*/
 int mbtk_ecall_sms_number_get(mbtk_info_handle_t* handle, void *number);

-

-/*

-* Set ecall mute speaker.

-*

-*/

+
+/*
+* Set ecall mute speaker.
+*
+*/
 int mbtk_ecall_mute_spk_set(mbtk_info_handle_t* handle, int mute);

-

-/*

-* Set ecall dsp gain.

-*

-*/

+
+/*
+* Set ecall dsp gain.
+*
+*/
 int mbtk_ecall_dsp_gain_set(mbtk_info_handle_t* handle, const mbtk_ecall_gain_info_t *gain_info);

 

 /*

diff --git a/mbtk/include/mbtk/mbtk_sock2.h b/mbtk/include/mbtk/mbtk_sock2.h
index 52d75cc..c56a2c0 100755
--- a/mbtk/include/mbtk/mbtk_sock2.h
+++ b/mbtk/include/mbtk/mbtk_sock2.h
@@ -73,8 +73,8 @@
 
 typedef struct {
     int state;
-    char* addr;
-    char* if_name;
+    const char* addr;
+    const char* if_name;
 } mbtk_net_cb_info_s;
 
 typedef struct {
@@ -153,7 +153,7 @@
                 unsigned int timeout,
                 int *mbtk_errno);
 extern int mbtk_sock_write(mbtk_sock_handle handle,mbtk_sock_session session,
-                void *buffer,
+                const void *buffer,
                 unsigned int buf_len,
                 unsigned int timeout,
                 int *mbtk_errno);
diff --git a/mbtk/include/mbtk/mbtk_type.h b/mbtk/include/mbtk/mbtk_type.h
index f948ab9..c7fc885 100755
--- a/mbtk/include/mbtk/mbtk_type.h
+++ b/mbtk/include/mbtk/mbtk_type.h
@@ -17,7 +17,10 @@
 
 #ifndef UNUSED
 #define UNUSED(param) ((void) param)
-#define UNUSEDPARAM UNUSED
+#endif
+
+#ifndef UNUSEDPARAM
+#define UNUSEDPARAM(param) ((void) param)
 #endif
 
 #ifndef TRUE
diff --git a/mbtk/include/mbtk/mbtk_utils.h b/mbtk/include/mbtk/mbtk_utils.h
index 5d4c1a2..6a532f9 100755
--- a/mbtk/include/mbtk/mbtk_utils.h
+++ b/mbtk/include/mbtk/mbtk_utils.h
@@ -92,6 +92,15 @@
 
 int app_already_running(const char *pid_file);
 
+void mbtk_system(const void* cmd);
+
+void mbtk_write(int fd,const void *buf, size_t len);
+
+void mbtk_read(int fd,void *buf, size_t len);
+
+void mbtk_close(int fd);
+
+
 #ifdef __cplusplus
 } // extern "C"
 #endif
diff --git a/mbtk/libmbtk_lib/audio/mbtk_pcm_stream.c b/mbtk/libmbtk_lib/audio/mbtk_pcm_stream.c
index 213534b..82d28ce 100755
--- a/mbtk/libmbtk_lib/audio/mbtk_pcm_stream.c
+++ b/mbtk/libmbtk_lib/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);
@@ -697,8 +700,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,7 +751,6 @@
     return (void *)aud_hdl;
 
 error:
-    value = 0;
     free(aud_hdl);
     return NULL;
 }
@@ -781,11 +781,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)
@@ -870,7 +865,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;
@@ -947,10 +941,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);
+                }
             }
         }
 
@@ -968,7 +963,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/audio/mbtk_wav.c b/mbtk/libmbtk_lib/audio/mbtk_wav.c
index ac4bed8..403db74 100755
--- a/mbtk/libmbtk_lib/audio/mbtk_wav.c
+++ b/mbtk/libmbtk_lib/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"
@@ -122,7 +123,10 @@
         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;
@@ -177,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);
@@ -185,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);
@@ -353,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);
diff --git a/mbtk/libmbtk_lib/coap/mbtk_coap.c b/mbtk/libmbtk_lib/coap/mbtk_coap.c
index 226fd5c..2fd96a8 100755
--- a/mbtk/libmbtk_lib/coap/mbtk_coap.c
+++ b/mbtk/libmbtk_lib/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/coap/mbtk_coap_api.cpp b/mbtk/libmbtk_lib/coap/mbtk_coap_api.cpp
index 0a6dc19..c864fe0 100755
--- a/mbtk/libmbtk_lib/coap/mbtk_coap_api.cpp
+++ b/mbtk/libmbtk_lib/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/common/mbtk_adc.c b/mbtk/libmbtk_lib/common/mbtk_adc.c
index 55cce7c..601d9b0 100755
--- a/mbtk/libmbtk_lib/common/mbtk_adc.c
+++ b/mbtk/libmbtk_lib/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/common/mbtk_at.c b/mbtk/libmbtk_lib/common/mbtk_at.c
index 8721a52..8262756 100755
--- a/mbtk/libmbtk_lib/common/mbtk_at.c
+++ b/mbtk/libmbtk_lib/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/common/mbtk_bs_position.c b/mbtk/libmbtk_lib/common/mbtk_bs_position.c
index 0119ae5..0b1d6e3 100755
--- a/mbtk/libmbtk_lib/common/mbtk_bs_position.c
+++ b/mbtk/libmbtk_lib/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/common/mbtk_debug.c b/mbtk/libmbtk_lib/common/mbtk_debug.c
index e9280c9..23e8431 100755
--- a/mbtk/libmbtk_lib/common/mbtk_debug.c
+++ b/mbtk/libmbtk_lib/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/common/mbtk_log.c b/mbtk/libmbtk_lib/common/mbtk_log.c
index fcdf0b1..3ffca33 100755
--- a/mbtk/libmbtk_lib/common/mbtk_log.c
+++ b/mbtk/libmbtk_lib/common/mbtk_log.c
@@ -35,7 +35,7 @@
 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;
@@ -88,6 +88,7 @@
     va_list ap;
     struct timeval log_time;
     int length = 0;
+    int ret = 0;
 
     va_start(ap, format);
     length = vsnprintf(buf, sizeof(buf), format, ap);
@@ -111,10 +112,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 +168,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/common/mbtk_ntp.c b/mbtk/libmbtk_lib/common/mbtk_ntp.c
index 5b23e37..704643a 100755
--- a/mbtk/libmbtk_lib/common/mbtk_ntp.c
+++ b/mbtk/libmbtk_lib/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/common/mbtk_utils.c b/mbtk/libmbtk_lib/common/mbtk_utils.c
index fe4d716..afade99 100755
--- a/mbtk/libmbtk_lib/common/mbtk_utils.c
+++ b/mbtk/libmbtk_lib/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/fota/mbtk_fota.c b/mbtk/libmbtk_lib/fota/mbtk_fota.c
index 323ec9b..6d5d3e8 100755
--- a/mbtk/libmbtk_lib/fota/mbtk_fota.c
+++ b/mbtk/libmbtk_lib/fota/mbtk_fota.c
@@ -23,7 +23,8 @@
 

 #include "mbtk_fota.h"

 #include "mbtk_log.h"

-

+#include "mbtk_utils.h"

+#include "mbtk_type.h"

 

 #ifdef DEBUG

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

@@ -31,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;

@@ -164,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

@@ -202,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

@@ -246,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

@@ -285,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

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

 

     if (is_reboot) {

-        system("sync");

-        system("reboot");

+        mbtk_system("sync");

+        mbtk_system("reboot");

     }

     return 0;

 

@@ -345,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");

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

 int mbtk_fota_init(fota_callback cb)

 {

-    int id;

     int retries = 0;

 

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

diff --git a/mbtk/libmbtk_lib/ftp/mbtk_ftp.c b/mbtk/libmbtk_lib/ftp/mbtk_ftp.c
index f485ec7..69208d6 100755
--- a/mbtk/libmbtk_lib/ftp/mbtk_ftp.c
+++ b/mbtk/libmbtk_lib/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/ftp/mbtk_ftp_at.c b/mbtk/libmbtk_lib/ftp/mbtk_ftp_at.c
index 3541e2b..958b0d0 100755
--- a/mbtk/libmbtk_lib/ftp/mbtk_ftp_at.c
+++ b/mbtk/libmbtk_lib/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/gnss/mbtk_gnss.c b/mbtk/libmbtk_lib/gnss/mbtk_gnss.c
index cf9af27..707b9de 100755
--- a/mbtk/libmbtk_lib/gnss/mbtk_gnss.c
+++ b/mbtk/libmbtk_lib/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/http/mbtk_http_base.c b/mbtk/libmbtk_lib/http/mbtk_http_base.c
index 657b838..ab4b0ef 100755
--- a/mbtk/libmbtk_lib/http/mbtk_http_base.c
+++ b/mbtk/libmbtk_lib/http/mbtk_http_base.c
@@ -4,25 +4,24 @@
 #include "mbtk_log.h"
 #include "mbtk_http_base.h"
 
-static void http_sock_cb_func(int handle, int fd, int event);
-
 static bool http_sock_inited = FALSE;
-static int http_handle = -1;
-static int http_fd = -1;
+static mbtk_sock_handle http_handle = -1;
+static mbtk_sock_session http_fd = -1;
 
-static void http_sock_cb_func(int handle, int fd, int event)
+static void http_sock_cb_func(mbtk_sock_handle handle, mbtk_sock_cb_info_s *sock_info)
 {
-    if(http_handle == handle && http_fd == fd) {
-        if(event & EPOLLIN) { // READ
+    if(http_handle == handle && sock_info && http_fd == sock_info->sock_fd) {
+        if(sock_info->event & EPOLLIN) { // READ
 
-        } else if(event & EPOLLRDHUP) { // Close
+        } else if(sock_info->event & EPOLLRDHUP) { // Close
 
         } else {
-            LOGW("Unknown event:%x",event);
+            LOGW("Unknown event:%x",sock_info->event);
         }
     }
 }
 
+
 int mbtk_http_init()
 {
     if(http_sock_inited) {
diff --git a/mbtk/libmbtk_lib/mqtt/MQTTClient.c b/mbtk/libmbtk_lib/mqtt/MQTTClient.c
index 4a349a7..b197a85 100755
--- a/mbtk/libmbtk_lib/mqtt/MQTTClient.c
+++ b/mbtk/libmbtk_lib/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/mqtt/MQTTPacket/MQTTFormat.c b/mbtk/libmbtk_lib/mqtt/MQTTPacket/MQTTFormat.c
index 3015a0e..9878492 100755
--- a/mbtk/libmbtk_lib/mqtt/MQTTPacket/MQTTFormat.c
+++ b/mbtk/libmbtk_lib/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/mqtt/mbtk_mqtt.c b/mbtk/libmbtk_lib/mqtt/mbtk_mqtt.c
index 3b78429..40bd5e5 100755
--- a/mbtk/libmbtk_lib/mqtt/mbtk_mqtt.c
+++ b/mbtk/libmbtk_lib/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/net/mbtk_ifc.c b/mbtk/libmbtk_lib/net/mbtk_ifc.c
index 51267f5..3a7b24b 100755
--- a/mbtk/libmbtk_lib/net/mbtk_ifc.c
+++ b/mbtk/libmbtk_lib/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/net/mbtk_net_control.c b/mbtk/libmbtk_lib/net/mbtk_net_control.c
index 722efda..458f940 100755
--- a/mbtk/libmbtk_lib/net/mbtk_net_control.c
+++ b/mbtk/libmbtk_lib/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/net/mbtk_sock.c b/mbtk/libmbtk_lib/net/mbtk_sock.c
index d52abdb..ccd872f 100755
--- a/mbtk/libmbtk_lib/net/mbtk_sock.c
+++ b/mbtk/libmbtk_lib/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/net/mbtk_sock2.c b/mbtk/libmbtk_lib/net/mbtk_sock2.c
index ae5329e..45ae0b6 100755
--- a/mbtk/libmbtk_lib/net/mbtk_sock2.c
+++ b/mbtk/libmbtk_lib/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,18 +911,18 @@
     }
 
 #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
 }
 
 extern int mbtk_sock_write(mbtk_sock_handle handle,mbtk_sock_session session,
-                void *buffer,
+                const void *buffer,
                 unsigned int buf_len,
                 unsigned int timeout,
                 int *mbtk_errno)
@@ -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/ril/mbtk_info.c b/mbtk/libmbtk_lib/ril/mbtk_info.c
index 58358ca..78e289e 100755
--- a/mbtk/libmbtk_lib/ril/mbtk_info.c
+++ b/mbtk/libmbtk_lib/ril/mbtk_info.c
@@ -9,7 +9,7 @@
 #include "mbtk_list.h"
 #include "mbtk_utils.h"
 
-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;
@@ -51,7 +51,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;
@@ -155,12 +155,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 = strstr(ptr, ".");
         if(ptr == NULL)
             return -1;
         ptr++;
@@ -181,8 +181,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/ril/mbtk_info.h b/mbtk/libmbtk_lib/ril/mbtk_info.h
index 462e2b9..c52e916 100755
--- a/mbtk/libmbtk_lib/ril/mbtk_info.h
+++ b/mbtk/libmbtk_lib/ril/mbtk_info.h
@@ -465,7 +465,7 @@
 {
     uint16 info_id;
     uint16 info_err;
-    const uint8 *data;
+    uint8 *data;
     uint16 data_len;
 } mbtk_info_pack_t;
 
diff --git a/mbtk/libmbtk_lib/ril/mbtk_info_api.c b/mbtk/libmbtk_lib/ril/mbtk_info_api.c
index b5fc96d..9fca322 100755
--- a/mbtk/libmbtk_lib/ril/mbtk_info_api.c
+++ b/mbtk/libmbtk_lib/ril/mbtk_info_api.c
@@ -14,7 +14,7 @@
 #include "mbtk_info.h"
 #include "mbtk_list.h"
 #include "mbtk_utils.h"
-
+#include "mbtk_str.h"
 #include "time.h"
 
 
@@ -411,7 +411,7 @@
         // log_hex("data", send_buff, send_buff_len);
         // mbtk_info_pack_data_set(pack, data, data_len);
         pack->data_len = (uint16)send_buff_len;
-        pack->data = (const uint8*)send_buff;
+        pack->data = (uint8*)send_buff;
     }
 
     pthread_mutex_lock(&handle->send_mutex);
@@ -546,7 +546,7 @@
     {
         if(handle->exit_fd[1] > 0)
         {
-            write(handle->exit_fd[1], "EXIT", 4);
+            mbtk_write(handle->exit_fd[1], "EXIT", 4);
         }
         pthread_join(handle->read_thread_id,NULL);
         LOG("mbtk_info_handle_get() server not ready.");
@@ -587,7 +587,7 @@
     }
 
     if((*handle)->exit_fd[1] > 0) {
-        write((*handle)->exit_fd[1], "EXIT", 4);
+        mbtk_write((*handle)->exit_fd[1], "EXIT", 4);
     }
 
     // Wait read_thread exit.
@@ -1766,7 +1766,7 @@
 */
 int mbtk_net_time_get(mbtk_info_handle_t* handle, char* time_str)
 {
-    uint8 buff[SOCK_MSG_LEN_MAX] = {0};
+    char buff[SOCK_MSG_LEN_MAX] = {0};
     if(handle == NULL || time_str == NULL)
     {
         LOGE("ARG error.");
@@ -1776,7 +1776,7 @@
     if(info_item_process(handle, MBTK_INFO_ID_DEV_CELL_TIME_REQ, NULL, 0, buff) > 0) {
         memcpy(time_str,buff,strlen(buff));
 
-        uint8 *temp = strstr(time_str, ",");
+        char *temp = strstr(time_str, ",");
         if(temp) {
             *temp = ' '; // ',' -> ' '
 
@@ -1787,7 +1787,7 @@
 
             if(temp) {
                 // Copy +XX or -XX
-                uint8 *last_ptr = temp + strlen(temp) + 1;
+                char *last_ptr = temp + strlen(temp) + 1;
                 while(last_ptr > temp) {
                     *last_ptr = *(last_ptr - 1);
                     last_ptr--;
@@ -2222,7 +2222,7 @@
     //  /sys/devices/virtual/usim_event/usim0/send_event
     char cmd[100] = {0};
     sprintf(cmd, "echo %d > /sys/devices/virtual/usim_event/usim0/send_event", power ? 0 : 1);
-    system(cmd);
+    mbtk_system(cmd);
 
     return 0;
 }
@@ -2243,15 +2243,15 @@
 
     switch(type) {
         case 0: {
-            system("reboot");
+            mbtk_system("reboot");
             break;
         }
         case 1: {
-            system("poweroff");
+            mbtk_system("poweroff");
             break;
         }
         case 2: {
-            system("halt");
+            mbtk_system("halt");
             break;
         }
         default: {
diff --git a/mbtk/libmbtk_lib/ril/mbtk_pdu_sms.c b/mbtk/libmbtk_lib/ril/mbtk_pdu_sms.c
index 05da8a8..c00a924 100755
--- a/mbtk/libmbtk_lib/ril/mbtk_pdu_sms.c
+++ b/mbtk/libmbtk_lib/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/sleep/mbtk_lpm.c b/mbtk/libmbtk_lib/sleep/mbtk_lpm.c
index b18a660..19681a0 100755
--- a/mbtk/libmbtk_lib/sleep/mbtk_lpm.c
+++ b/mbtk/libmbtk_lib/sleep/mbtk_lpm.c
@@ -25,6 +25,7 @@
 #include "mbtk_lpm.h"

 #include "mbtk_type.h"

 #include "mbtk_log.h"

+#include "mbtk_utils.h"

 

 static mbtk_lpm_handler_t lpm_init;

 

@@ -56,7 +57,7 @@
     do {

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

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

-    

+

     return ret;

 }

 

@@ -80,8 +81,6 @@
     while (true)

     {

         struct epoll_event events[2];

-        struct epoll_event ev;

-        int cmd = 0;

 

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

 

@@ -98,7 +97,7 @@
                 if (events[i].data.fd == socket_t[1])

                 {

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

-                    read(socket_t[1], buf, sizeof(buf));

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

                     if (1 == atoi(buf))

                     {

                         if(close(fd_t) == 0)

@@ -115,7 +114,7 @@
                 {

                     LOGI("go pthread_event");

                     memset(&ev_input, 0x00, size);

-                    read(fd_t, &ev_input, 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)

@@ -137,7 +136,7 @@
 

 int mbtk_lpm_init(mbtk_lpm_handler_t mbtk_lpm_handler)

 {

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

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

     {

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

 

@@ -147,7 +146,7 @@
             close(socket_t[0] );

             socket_t[0] = -1;

         }

-        

+

         if(socket_t[1] > 0)

         {

             close(socket_t[1] );

@@ -189,8 +188,8 @@
     {

         //char   cmd = 1;

         strcpy(buf, "1");

-        void*  dummy = NULL;

-        write( socket_t[0], buf, sizeof(buf) );

+//        void*  dummy = NULL;

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

 

         sleep(1);

         // close the control socket pair

diff --git a/mbtk/libmbtk_lib/sleep/mbtk_sleep.c b/mbtk/libmbtk_lib/sleep/mbtk_sleep.c
index c2b8be0..25c3997 100755
--- a/mbtk/libmbtk_lib/sleep/mbtk_sleep.c
+++ b/mbtk/libmbtk_lib/sleep/mbtk_sleep.c
@@ -1,5 +1,6 @@
 #include "mbtk_sleep.h"
 #include "mbtk_log.h"
+#include "mbtk_utils.h"
 
 static mbtk_lock_name_s mbtk_lock_name[LOCK_MAX_SIZE]={0};
 
@@ -10,7 +11,7 @@
     {
         if(!access("/sys/power/autosleep", W_OK))
         {
-            system("echo mem > /sys/power/autosleep");
+            mbtk_system("echo mem > /sys/power/autosleep");
             autosleep_enable = TRUE;
             return 0;
         }
@@ -24,7 +25,7 @@
     {
         if(!access("/sys/power/autosleep", W_OK))
         {
-            system("echo off > /sys/power/autosleep");
+            mbtk_system("echo off > /sys/power/autosleep");
             autosleep_enable = FALSE;
             return 0;
         }
@@ -66,7 +67,7 @@
             if(mbtk_lock_name[i].fd == 0)
                 break;
         }
-        
+
         if (i >= LOCK_MAX_SIZE)
         {
             LOGE("Fd is full.");
@@ -101,7 +102,7 @@
     {
         char cmd[128]={0};
         sprintf(cmd, "echo %s > /sys/power/wake_lock", mbtk_lock_name[i].name);
-        system(cmd);
+        mbtk_system(cmd);
         return 0;
     }
     else
@@ -131,7 +132,7 @@
     {
         char cmd[128]={0};
         sprintf(cmd, "echo %s > /sys/power/wake_unlock", mbtk_lock_name[i].name);
-        system(cmd);
+        mbtk_system(cmd);
         return 0;
     }
     else
diff --git a/mbtk/libmbtk_lib/tcpip/mbtk_tcpip_at.c b/mbtk/libmbtk_lib/tcpip/mbtk_tcpip_at.c
index fadb1a6..967e7fa 100755
--- a/mbtk/libmbtk_lib/tcpip/mbtk_tcpip_at.c
+++ b/mbtk/libmbtk_lib/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/wifi/sta_cli.c b/mbtk/libmbtk_lib/wifi/sta_cli.c
old mode 100644
new mode 100755
index 0cf37fd..9dbd202
--- a/mbtk/libmbtk_lib/wifi/sta_cli.c
+++ b/mbtk/libmbtk_lib/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/wifi/sta_ctrl.c b/mbtk/libmbtk_lib/wifi/sta_ctrl.c
old mode 100644
new mode 100755
index e5e24aa..cad497c
--- a/mbtk/libmbtk_lib/wifi/sta_ctrl.c
+++ b/mbtk/libmbtk_lib/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/libmbtk_lib_v2/http/mbtk_http_base.c b/mbtk/libmbtk_lib_v2/http/mbtk_http_base.c
index 657b838..6fbf898 100755
--- a/mbtk/libmbtk_lib_v2/http/mbtk_http_base.c
+++ b/mbtk/libmbtk_lib_v2/http/mbtk_http_base.c
@@ -4,21 +4,21 @@
 #include "mbtk_log.h"
 #include "mbtk_http_base.h"
 
-static void http_sock_cb_func(int handle, int fd, int event);
+static void http_sock_cb_func(mbtk_sock_handle handle, mbtk_sock_cb_info_s *sock_info);
 
 static bool http_sock_inited = FALSE;
-static int http_handle = -1;
-static int http_fd = -1;
+static mbtk_sock_handle http_handle = -1;
+static mbtk_sock_session http_fd = -1;
 
-static void http_sock_cb_func(int handle, int fd, int event)
+static void http_sock_cb_func(mbtk_sock_handle handle, mbtk_sock_cb_info_s *sock_info)
 {
-    if(http_handle == handle && http_fd == fd) {
-        if(event & EPOLLIN) { // READ
+    if(http_handle == handle && sock_info && http_fd == sock_info->sock_fd) {
+        if(sock_info->event & EPOLLIN) { // READ
 
-        } else if(event & EPOLLRDHUP) { // Close
+        } else if(sock_info->event & EPOLLRDHUP) { // Close
 
         } else {
-            LOGW("Unknown event:%x",event);
+            LOGW("Unknown event:%x",sock_info->event);
         }
     }
 }
diff --git a/mbtk/libmbtk_lib_v2/net/mbtk_sock2.c b/mbtk/libmbtk_lib_v2/net/mbtk_sock2.c
index ae5329e..2b508a5 100755
--- a/mbtk/libmbtk_lib_v2/net/mbtk_sock2.c
+++ b/mbtk/libmbtk_lib_v2/net/mbtk_sock2.c
@@ -919,7 +919,7 @@
 }
 
 extern int mbtk_sock_write(mbtk_sock_handle handle,mbtk_sock_session session,
-                void *buffer,
+                const void *buffer,
                 unsigned int buf_len,
                 unsigned int timeout,
                 int *mbtk_errno)
diff --git a/mbtk/mbtk_adbd/src/main.c b/mbtk/mbtk_adbd/src/main.c
index 036ba24..f52f1d4 100755
--- a/mbtk/mbtk_adbd/src/main.c
+++ b/mbtk/mbtk_adbd/src/main.c
@@ -8,6 +8,7 @@
 #include <time.h>
 #include <sys/time.h>
 #include <termios.h>    //UART
+#include <pthread.h>
 
 #include "mbtk_log.h"
 #include "mbtk_adb_info.h"
@@ -194,7 +195,10 @@
 
             LOGD("CONN_SUCCESS");
 
-            chdir("/");
+
+            if(chdir("/")) {
+                LOGE("chdir / fail.");
+            }
             break;
         }
         case MBTK_ADB_MSG_PUSH:
@@ -267,7 +271,7 @@
                 LOGD("Kill cmd:%s", shell_cmd + 6);
                 char cmd[1024] = {0};
                 snprintf(cmd,1024,"kill `pidof %s | awk '{print $1}'`", shell_cmd + 6);
-                system(cmd);
+                mbtk_system(cmd);
             } else {
                 LOGE("Kill Command/AT error.");
             }
diff --git a/mbtk/mbtk_gnssd/agps/8122_agnss.c b/mbtk/mbtk_gnssd/agps/8122_agnss.c
index 34eef09..0bb7c5a 100755
--- a/mbtk/mbtk_gnssd/agps/8122_agnss.c
+++ b/mbtk/mbtk_gnssd/agps/8122_agnss.c
@@ -27,7 +27,7 @@
 
 static int hd_agnss_uart_write(uint8_t *buf, uint32_t len)
 {
-    int TxLen;
+    int TxLen = -1;
     if(hd_fd > 0)
     {
         TxLen = write(hd_fd,buf,len);
@@ -80,7 +80,7 @@
     return src_len + 8;
 }
 
-/************************************time inject*************************************/ 
+/************************************time inject*************************************/
 static int gnss_inject_time(HD_AGNSS_UTC_TIME_TYPE *time)
 {
     uint8_t cmd[24] = {0}; /* packet head+payload */
@@ -185,7 +185,7 @@
     return 0;
 }
 
-/************************************eph data inject*************************************/ 
+/************************************eph data inject*************************************/
 /**
 * @brief get the eph frame and send to HD80xx
 * @param data: the pointer of the eph data file
@@ -207,12 +207,12 @@
         LOGE("malloc fail");
         return INJECT_RESULT_FAIL;
     }
-    
+
     eph_file_fd = open(eph_file_path, O_RDWR);
     if (eph_file_fd <= 0)
     {
         LOGE("%s open file FAIL. errno:%d\n", __FUNCTION__, errno);
-        goto error; 
+        goto error;
     }
     while(0 < (size = read(eph_file_fd, (databuf + left_size), BUFFER_SIZE)))
     {
@@ -230,7 +230,7 @@
                     if(write_size < 0)
                     {
                         LOGE("hd_agnss_uart_write fail");
-                        goto error; 
+                        goto error;
                     }
                     LOGD("%s Write[%d]\r\n", __FUNCTION__, write_size);
                     hd_agnss_delay(50);
@@ -281,7 +281,7 @@
             }
         }
     }
-    
+
     if(databuf)
     {
         free(databuf);
@@ -326,17 +326,17 @@
                             HD_AGNSS_UTC_TIME_TYPE *UTC_time)
 {
     int ret = INJECT_RESULT_SUCCESS;
-    if (UTC_time != NULL) 
+    if (UTC_time != NULL)
     {
         gnss_inject_time(UTC_time);
     }
 
-    if ((latitude != 0) && (longitude != 0)) 
+    if ((latitude != 0) && (longitude != 0))
     {
         gnss_inject_location(latitude, longitude, altitude, accuracy);
     }
 
-    if (eph_file_path != NULL) 
+    if (eph_file_path != NULL)
     {
         ret = gnss_eph_inject_data(eph_file_path);
         if(ret < 0)
diff --git a/mbtk/mbtk_gnssd/gnss_6228.c b/mbtk/mbtk_gnssd/gnss_6228.c
index 9bbe8f4..17ecda1 100755
--- a/mbtk/mbtk_gnssd/gnss_6228.c
+++ b/mbtk/mbtk_gnssd/gnss_6228.c
Binary files differ
diff --git a/mbtk/mbtk_gnssd/gnss_asr5311.c b/mbtk/mbtk_gnssd/gnss_asr5311.c
index c3088bb..1f4d8db 100755
--- a/mbtk/mbtk_gnssd/gnss_asr5311.c
+++ b/mbtk/mbtk_gnssd/gnss_asr5311.c
@@ -37,8 +37,8 @@
 #define GNSS_PLATFORM_STATUS_PATH    "/sys/devices/platform/asr-gps/status"

 

 static char config_msg_pm5[]    = "PMTEST,5";

-static char config_msg_pm4[]    = "PMTEST,4";

-static char config_msg_boot[]   = "START,1";

+//static char config_msg_pm4[]    = "PMTEST,4";

+//static char config_msg_boot[]   = "START,1";

 

 static pthread_cond_t read_cond;

 static pthread_mutex_t read_mutex;

@@ -57,8 +57,8 @@
     LOGD("aboot fw_download timeout");

     gnss_fw_download_timeout_state = 1;

     //log2file("%s: gnss fw download timeout\n", __func__);

-    

-    system("killall aboot-tiny");

+

+    mbtk_system("killall aboot-tiny");

 }

 

 static int gnss_fw_download_timer_init(void)

@@ -92,7 +92,7 @@
             return -1;

         }

     }

-    

+

     struct itimerspec  ts;

 

     memset (&ts, 0x00, sizeof (struct itimerspec));

@@ -119,7 +119,7 @@
     memset (&ts, 0x00, sizeof (struct itimerspec));

     ts.it_value.tv_sec = 0;

     ts.it_value.tv_nsec = 0;

-    ts.it_interval.tv_sec = 0;          

+    ts.it_interval.tv_sec = 0;

     ts.it_interval.tv_nsec = 0;

     rc = timer_settime(gnss_fw_download_timer_id, 0, &ts, NULL);

     LOGD("fw_download timer stop %d", rc);

@@ -162,7 +162,7 @@
     fd = open(GNSS_PLATFORM_CTRL_PATH, O_WRONLY);

 

     if (fd >= 0) {

-        write(fd, str, strlen(str));

+        mbtk_write(fd, str, strlen(str));

         close(fd);

     }

 }

@@ -279,7 +279,7 @@
 	LOGD("aboot-tiny start");

 retry_download:

     gnss_fw_download_timer_start();

-    system(cmd);

+    mbtk_system(cmd);

     gnss_fw_download_timer_stop();

     if(gnss_fw_download_timeout_state == 1)

     {

@@ -315,7 +315,7 @@
             }

         }

     }

-	

+

 	LOGD("aboot-tiny stop");

 

     return 0;

@@ -323,7 +323,7 @@
 

 void gnss_5311_set_cb(const void *data, int data_len)

 {

-    const char *buff = (const char*)data;

+//    const char *buff = (const char*)data;

     if(setting_busy) { // Has setting cmd process.

         gnss_cmd_rsp_process(data, data_len);

     }

@@ -367,7 +367,7 @@
                 gnss_set_result = GNSS_ERR_ARG;

                 goto set_fail;

             }

-            

+

             uint32 new_mode = 0;

             if(ret_num >= 1)

             {

@@ -486,7 +486,7 @@
             }

 

             should_wait_rsp = TRUE;

-        } 

+        }

         else if(memcmp(cmd, "$MINEL", 6) == 0) //$MINEL,<elev>

         {

             uint32 elev = 0;

@@ -503,7 +503,7 @@
             LOGD("cmd: %s", send_cmd);

             gnss_send_cmd(fd, send_cmd, send_cmd_len);

             should_wait_rsp = TRUE;

-        } 

+        }

         else if(memcmp(cmd, "$NMEACFG", 8) == 0) // $NMEACFG,<ver>

         {

             uint32 mode,ver = 0;

@@ -536,7 +536,7 @@
             goto set_fail;

         }

 

-set_success:

+//set_success:

         if(should_wait_rsp) {

             setting_waitting = TRUE;

             pthread_mutex_lock(&read_mutex);

diff --git a/mbtk/mbtk_gnssd/gnss_hd8122.c b/mbtk/mbtk_gnssd/gnss_hd8122.c
index e61bfe6..531bbcc 100755
--- a/mbtk/mbtk_gnssd/gnss_hd8122.c
+++ b/mbtk/mbtk_gnssd/gnss_hd8122.c
@@ -29,6 +29,9 @@
 #include "hd8122_dl/hd8040_upgrade.h"
 #include "agps/agnss_http_download.h"
 #include "agps/8122_agnss.h"
+#include "mbtk_utils.h"
+// #include "hd8122_dl/port.h"
+
 
 #define UART_BITRATE_NMEA_DEF_FW    115200   // Default bitrate.
 #define GNSS_POWER_GPIO 43
@@ -64,7 +67,7 @@
 static int gnss_cmd_rsp_len = 0;
 
 int gnss_write(int fd, const void *data, int data_len);
-int OpenUart(char* UART_DEV);
+int OpenUart(const char* UART_DEV);
 int uart_close(int fd);
 int fw_update_boot(int uart_fd, uint8_t *data, uint32_t len);
 
@@ -150,6 +153,7 @@
     }
 }
 
+#if 0
 static int msg_remove(uint8 gid, uint8 sid)
 {
     int i = msg_find(gid, sid);
@@ -165,6 +169,7 @@
         return -1;
     }
 }
+#endif
 
 static int msg_count()
 {
@@ -382,7 +387,7 @@
 
 static void gnss_cmd_rsp_process(const void *data, int data_len)
 {
-    const char *ptr = (const char*)data;
+//    const char *ptr = (const char*)data;
     log_hex("RSP", data, data_len);
 
     hd8122_id_ack_enum ack_nak = HD8122_ID_ACK_ACK;
@@ -406,7 +411,7 @@
             pthread_mutex_unlock(&read_mutex);
             setting_waitting = FALSE;
         }
-        
+
     }
     else
     {
@@ -557,7 +562,7 @@
     return GNSS_ERR_OK;
 }
 
-
+#if 0
 static gnss_err_enum gnss_8122_nmeaver(int fd, uint8 ver)
 {
     uint8 buff[GNSS_PACK_BUFF_SIZE];
@@ -572,18 +577,19 @@
     gnss_write(fd, buff, len);
     return GNSS_ERR_OK;
 }
+#endif
 
 int gnss_8122_dev_open()
 {
     //return mbtk_gpio_value_set(GNSS_POWER_GPIO, MBTK_GPIO_DIRECT_OUT, 1);
-    system("i2cset -y -f 2 0x31 0x15 0x86");
+    mbtk_system("i2cset -y -f 2 0x31 0x15 0x86");
     return 0;
 }
 
 int gnss_8122_dev_close(int fd)
 {
     //return mbtk_gpio_value_set(GNSS_POWER_GPIO, MBTK_GPIO_DIRECT_OUT, 0);
-    system("i2cset -y -f 2 0x31 0x15 0x00");
+    mbtk_system("i2cset -y -f 2 0x31 0x15 0x00");
     return 0;
 }
 
@@ -649,7 +655,7 @@
         LOGE("gnss_fwdl_enable fail");
         goto error;
     }
-    
+
     int ret = fw_update_boot(uart_fd, g_bin_buff, len);
     if (ret < 0)
     {
@@ -665,7 +671,7 @@
         LOGD("upgrade FAIL, fail style:%d", ret);
         goto error;
     }
-    
+
     if(gnss_8122_dev_close(0))
     {
         LOGE("close gnss device fail:%d", errno);
@@ -700,32 +706,32 @@
     int eph_type = 0;
     int alam_flag = 0;
     int ret = -1;
-    char url[256] = {0};
+    char url[1024] = {0};
     if(2 == sscanf(param, "%d,%d", &eph_type, &alam_flag))
     {
         if((gnss_eph_data_enum)eph_type == GNSS_EPH_GPS)
         {
-            snprintf(url, 256,AGNSS_URL, AGNSS_EPH_GPS);
+            snprintf(url, sizeof(url),AGNSS_URL, AGNSS_EPH_GPS);
         }
         else if((gnss_eph_data_enum)eph_type == GNSS_EPH_BDS)
         {
-            snprintf(url, 256,AGNSS_URL, AGNSS_EPH_BDS);
+            snprintf(url, sizeof(url),AGNSS_URL, AGNSS_EPH_BDS);
         }
         else if((gnss_eph_data_enum)eph_type == GNSS_EPH_GLO)
         {
-            snprintf(url, 256,AGNSS_URL, AGNSS_EPH_GLO);
+            snprintf(url, sizeof(url),AGNSS_URL, AGNSS_EPH_GLO);
         }
         else if((gnss_eph_data_enum)eph_type == GNSS_EPH_GPS_BDS)
         {
-            snprintf(url, 256,AGNSS_URL, AGNSS_EPH_GPS_BDS);
+            snprintf(url, sizeof(url),AGNSS_URL, AGNSS_EPH_GPS_BDS);
         }
         else if((gnss_eph_data_enum)eph_type == GNSS_EPH_GPS_GLO)
         {
-            snprintf(url, 256,AGNSS_URL, AGNSS_EPH_GPS_GLO);
+            snprintf(url, sizeof(url),AGNSS_URL, AGNSS_EPH_GPS_GLO);
         }
         else if((gnss_eph_data_enum)eph_type == GNSS_EPH_CFG)
         {
-            snprintf(url, 256,"%s?compid=%s&token=%s", strlen(agps_info.host) > 0 ? agps_info.host : "http://uagnss.allystar.com:80/ephemeris/HD_GPS.hdb",
+            snprintf(url, sizeof(url),"%s?compid=%s&token=%s", strlen(agps_info.host) > 0 ? agps_info.host : "http://uagnss.allystar.com:80/ephemeris/HD_GPS.hdb",
                                                         strlen(agps_info.id) > 0 ? agps_info.id : "yikecs1",
                                                         strlen(agps_info.passwd) > 0 ? agps_info.passwd : "Z38w5urAuawubTxi");
         }
@@ -767,7 +773,7 @@
 
 void gnss_8122_set_cb(const void *data, int data_len)
 {
-    const char *buff = (const char*)data;
+//    const char *buff = (const char*)data;
     if(setting_busy)   // Has setting cmd process.
     {
         gnss_cmd_rsp_process(data, data_len);
@@ -1098,12 +1104,12 @@
                               0x00, 0x00, 0x00, 0x00, 0x30, 0x62, 0x9F, 0x37,
                               0x28, 0x29, 0x30, 0xB8, 0xBD, 0x37, 0x06, 0x36,
                               0x00, 0x00, 0x00, 0x00};
-            
+
             if(2 == sscanf(cmd, "$PZ90CONV,%d,%d", &local, &ref))
             {
                 LOGD("set pz90conv: %d, %d", local, ref);
 
-                
+
                 if(local == 1 && ref == 0) //PZ90
                 {
                     //
@@ -1168,7 +1174,7 @@
             goto set_fail;
         }
 
-    set_success:
+//    set_success:
         if(should_wait_rsp)
         {
             setting_waitting = TRUE;
diff --git a/mbtk/mbtk_gnssd/gnss_ipc.c b/mbtk/mbtk_gnssd/gnss_ipc.c
index 65db6a3..3bb1442 100755
--- a/mbtk/mbtk_gnssd/gnss_ipc.c
+++ b/mbtk/mbtk_gnssd/gnss_ipc.c
@@ -36,6 +36,8 @@
 static int sock_cli_fds[SOCK_CLIENT_MAX];
 
 int gnss_write(int fd, const void* buf, unsigned int buf_len);
+int gnss_agnss_get_eph(const void* param);
+
 
 static int gnss_cli_fd_find(int fd)
 {
diff --git a/mbtk/mbtk_gnssd/gnss_log.c b/mbtk/mbtk_gnssd/gnss_log.c
index ef3204c..0e1ba35 100755
--- a/mbtk/mbtk_gnssd/gnss_log.c
+++ b/mbtk/mbtk_gnssd/gnss_log.c
@@ -27,11 +27,12 @@
 

 #include "gnss_log.h"

 #include "mbtk_log.h"

+#include "mbtk_utils.h"

 

 #define GNSS_LOG_FOLDER_PATH      "/user_data/mbtk_log"

 #define GNSS_LOG_FILE_PATH        "/user_data/mbtk_log/mbtk_gnss_log.txt"

 #define GNSS_LOG_LAST_FILE_PATH   "/user_data/mbtk_log/mbtk_gnss_last_log.txt"

-#define GNSS_LOG_GNSS_FILE_HEAD   "\n[-------------------mbtk gnss log V1.0-------------------][%d]\n"

+#define GNSS_LOG_GNSS_FILE_HEAD   "\n[-------------------mbtk gnss log V1.0-------------------][%ld]\n"

 #define GNSS_LOG_FILE_MAX_SIZE    10485760 //10 * 1024 * 1024 10M

 #define GNSS_TIME_CHECK_NUM       10

 

@@ -44,32 +45,32 @@
 {

     int head_len = 0;

     int ret = -1;

-    if(access(GNSS_LOG_FOLDER_PATH, F_OK) != 0) 

+    if(access(GNSS_LOG_FOLDER_PATH, F_OK) != 0)

     {

         ret = mkdir(GNSS_LOG_FOLDER_PATH, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);

-        if (ret != 0) 

+        if (ret != 0)

         {

             LOGE("Failed to create folder.");

             return -1;

         }

     }

 

-    if(access(GNSS_LOG_FILE_PATH, F_OK) == 0 && mv_flag) 

+    if(access(GNSS_LOG_FILE_PATH, F_OK) == 0 && mv_flag)

     {

         char cmd[128] = {0};

         memset(cmd, 0x0, 128);

         snprintf(cmd, 128, "mv %s %s", GNSS_LOG_FILE_PATH, GNSS_LOG_LAST_FILE_PATH);

         LOGE("cmd: [%s].", cmd);

-        system(cmd);

+        mbtk_system(cmd);

     }

 

     *fd = open(GNSS_LOG_FILE_PATH, O_CREAT | O_WRONLY | O_APPEND | O_NONBLOCK, 0644);

-    if(*fd < 0) 

+    if(*fd < 0)

     {

         LOGE("Open file fail [errno = %d].", errno);

         return -1;

     }

-    else 

+    else

     {

         char temp[128] = {0};

         struct stat st;

@@ -78,11 +79,11 @@
         snprintf(temp, 128, GNSS_LOG_GNSS_FILE_HEAD, *size);

         head_len = (int)strlen(temp);

         ret = write(*fd, temp, head_len);

-        if(ret == head_len) 

+        if(ret == head_len)

         {

             *size += ret;

         }

-        else 

+        else

         {

             LOGE("write head fail [errno = %d].", errno);

             goto error;

@@ -115,7 +116,7 @@
     {

         diff = sys_time - gps_time;

     }

-    

+

     gnss_test_log("sys time[%ld], gps time[%ld], diff time[%ld]", sys_time, gps_time, diff);

 }

 

@@ -134,16 +135,16 @@
 void gnss_test_log(const char* format, ...)

 {

     int ret;

-    

-    if(log_file_fd < 0) 

+

+    if(log_file_fd < 0)

     {

         ret = log_file_init(&log_file_fd, &log_file_size, false);

-        if(ret < 0) 

+        if(ret < 0)

         {

             LOGE("log_file_init fail.");

             return;

         }

-        else 

+        else

         {

             LOGE("log fd: [%d], log size: [%ld].", log_file_fd, log_file_size);

         }

@@ -154,15 +155,15 @@
     int length = 0;

     char write_buf[1096] = {0};

     int write_length = 0;

-    

+

     va_list ap;

     struct timeval log_time;

 

     va_start(ap, format);

     length = vsnprintf(param_buf, 1023, format, ap);

     va_end(ap);

-    

-    if (length < 0 || 0 == length) 

+

+    if (length < 0 || 0 == length)

     {

         LOGE("vsnprintf fail.");

         return;

@@ -178,50 +179,50 @@
     gettimeofday(&log_time, NULL);

     struct tm* tm_t = localtime(&(log_time.tv_sec));

     strftime(tmp, 50, "%F %T", tm_t);

-    

+

     write_length = snprintf(write_buf, 1096, "[%s %03d]--->%s", tmp, (int)(log_time.tv_usec / 1000), param_buf);

     if(write_length <= 0)

     {

         LOGE("snprintf fail.");

         return;

     }

-    

-    if((log_file_size + write_length) > GNSS_LOG_FILE_MAX_SIZE) 

+

+    if((log_file_size + write_length) > GNSS_LOG_FILE_MAX_SIZE)

     {

         close(log_file_fd);

         log_file_fd = -1;

         log_file_size = 0;

 

         ret = log_file_init(&log_file_fd, &log_file_size, true);

-        if(ret < 0) 

+        if(ret < 0)

         {

             LOGE("log_file_init fail.");

             goto error;

         }

-        else 

+        else

         {

             LOGE("log fd: [%d], log size: [%ld].", log_file_fd, log_file_size);

         }

     }

-    

+

     ret = write(log_file_fd, write_buf, write_length);

-    if(ret == write_length) 

+    if(ret == write_length)

     {

         log_file_size += ret;

     }

-    else 

+    else

     {

         goto error;

     }

-    

-    

-    if (log_file_fd > 2) 

+

+

+    if (log_file_fd > 2)

     {

         fsync(log_file_fd);

-    } 

+    }

     return;

 error:

-    if(log_file_fd > 0) 

+    if(log_file_fd > 0)

     {

         close(log_file_fd);

         log_file_fd = -1;

diff --git a/mbtk/mbtk_gnssd/gnss_main.c b/mbtk/mbtk_gnssd/gnss_main.c
index a495f4f..26f3a4d 100755
--- a/mbtk/mbtk_gnssd/gnss_main.c
+++ b/mbtk/mbtk_gnssd/gnss_main.c
@@ -20,6 +20,7 @@
 #include "gnss_asr5311.h"
 #include "gnss_n50db.h"
 #include "gnss_log.h"
+#include "mbtk_utils.h"
 
 #define GNSS_DEBUG 1
 #define GNSS_UBUS_ENABLE 1
@@ -257,12 +258,12 @@
 
         if(fd == nmea_log_fd) {
             if(nmea_log_fd > 0) {
-                write(nmea_log_fd, data, data_len);
+                mbtk_write(nmea_log_fd, data, data_len);
                 debug_fd_len += data_len;
             }
         } else if(fd == debug_fd) {
             if(debug_fd > 0) {
-                write(debug_fd, data, data_len);
+                mbtk_write(debug_fd, data, data_len);
                 debug_fd_len += data_len;
             }
         }
@@ -885,7 +886,7 @@
 
     // Wait for read thread exit.
     if(gnss_info.exit_fd[1] > 0) {
-        write(gnss_info.exit_fd[1], "exit", 4);
+        mbtk_write(gnss_info.exit_fd[1], "exit", 4);
     }
 
     gnss_info.state = GNSS_STATE_CLOSING;
@@ -989,7 +990,7 @@
         LOGE("gnss not ready");
         return GNSS_ERR_UNKNOWN;
     }
-    
+
     if(gnss_info.gnss_agnss_inject)
     {
         return gnss_info.gnss_agnss_inject(gnss_info.fd);
@@ -998,7 +999,7 @@
     {
         return GNSS_ERR_UNSUPPORT;
     }
-    
+
     return GNSS_ERR_OK;
 }
 
diff --git a/mbtk/mbtk_gnssd/gnss_utils.c b/mbtk/mbtk_gnssd/gnss_utils.c
index d114b4b..7fb9c3e 100755
--- a/mbtk/mbtk_gnssd/gnss_utils.c
+++ b/mbtk/mbtk_gnssd/gnss_utils.c
@@ -8,6 +8,7 @@
 #include <stdarg.h>
 #include <pty.h>
 #include <libubox/uloop.h>
+#include <cutils/properties.h>
 #include <time.h>
 #include <sys/time.h>
 
@@ -15,6 +16,7 @@
 #include "mbtk_log.h"
 #include "gnss_log.h"
 #include "mbtk_gnss.h"
+#include "mbtk_utils.h"
 
 #define DATABITS    CS8
 #define STOPBITS    0
@@ -477,7 +479,7 @@
 
     time_t _t = mktime(&tmp_time);//parse location tmp_time
 
-    
+
 
     return _t;
 }
@@ -550,7 +552,7 @@
 
                   struct timeval tv;
                   tv.tv_sec = _t;
-                  tv.tv_sec += 28800;  //cst 
+                  tv.tv_sec += 28800;  //cst
                   tv.tv_usec = 0;
 
 #endif
@@ -559,7 +561,7 @@
                         mbtk_gnss_time_set_flag = 0;
                     } else {
                         LOGD("%s: 1111, Set time success \n", __func__);
-                        system("hwclock -w rtc0");
+                        mbtk_system("hwclock -w rtc0");
                         mbtk_gnss_time_set_flag = 1;
                     }
                 }
diff --git a/mbtk/mbtk_gnssd/hd8122_dl/fwup.c b/mbtk/mbtk_gnssd/hd8122_dl/fwup.c
index 9b667cf..b2662aa 100755
--- a/mbtk/mbtk_gnssd/hd8122_dl/fwup.c
+++ b/mbtk/mbtk_gnssd/hd8122_dl/fwup.c
@@ -316,7 +316,7 @@
 int fw_update_boot(int uart_fd, uint8_t *data, uint32_t len)

 {

 	int i = 1;

-	uint8_t dataAck[10];

+//	uint8_t dataAck[10];

 	//1st 1KB send at last

 	uint8_t *data1st1k = data;

     uint8_t recvBuf[READ_LENGTH] = {0};

diff --git a/mbtk/mbtk_gnssd/hd8122_dl/port.c b/mbtk/mbtk_gnssd/hd8122_dl/port.c
index 89e1596..68c32f1 100755
--- a/mbtk/mbtk_gnssd/hd8122_dl/port.c
+++ b/mbtk/mbtk_gnssd/hd8122_dl/port.c
@@ -475,7 +475,7 @@
     return 0;

 }

 

-int OpenUart(char* UART_DEV)

+int OpenUart(const char* UART_DEV)

 {

     int fd=0;

 

diff --git a/mbtk/mbtk_gnssd/hd8122_dl/port.h b/mbtk/mbtk_gnssd/hd8122_dl/port.h
index 5e55db8..ace1d97 100755
--- a/mbtk/mbtk_gnssd/hd8122_dl/port.h
+++ b/mbtk/mbtk_gnssd/hd8122_dl/port.h
@@ -46,6 +46,6 @@
 extern void clearBuffer(int fd, int selector);

 extern int uart_open(unsigned char * GPS_DEVICE);

 extern int uart_close(int fd);

-extern int OpenUart(char* UART_DEV);

+extern int OpenUart(const char* UART_DEV);

 extern int set_baudrate(int fd, uint8_t baud);

 #endif

diff --git a/mbtk/mbtk_logd/alog_read.c b/mbtk/mbtk_logd/alog_read.c
index a907662..cfb7556 100755
--- a/mbtk/mbtk_logd/alog_read.c
+++ b/mbtk/mbtk_logd/alog_read.c
@@ -9,7 +9,12 @@
 #include <time.h>
 #include <unistd.h>
 #include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include <pthread.h>
+
 #include "log_config.h"
+#include "mbtk_utils.h"
 
 #define  ALOG_DEV "/dev/log_radio"
 #define LOG_CONFIG_LEN 50
@@ -35,7 +40,7 @@
     android_LogPriority priority;
     int32_t pid;
     int32_t tid;
-    const char * tag;
+    char * tag;
     size_t messageLen;
     const char * message;
 } AndroidLogEntry;
@@ -45,10 +50,11 @@
 static int log_size = 1 * 1024 * 1024;
 
 static log_config_entry *config = NULL;
-static char tmp_log[48] = {0};
+static char tmp_log[1024] = {0};
 
 static int fd_radio = 0;
 
+int tcp_connect(char* ip, int port);
 
 void hex_print(char* buf, int len)
 {
@@ -135,7 +141,7 @@
 int alog_process(char* data, int len, AndroidLogEntry *entry)
 {
     int i, n = 0;
-    int tmp_len;
+//    int tmp_len;
 
     for (i = 0; i < len;) {
         if (data[i] == '\0') {
@@ -202,32 +208,32 @@
     int index = 0;
     int len = 0;
     struct stat s;
-    
+
 
     static char buffer[MAX_BUFFER_SIZE] = {0};
     static int buffer_index = 0;
-    
+
     if(access(tmp_log, W_OK) != 0)
     {
         fd_radio = open(tmp_log, O_CREAT | O_WRONLY| O_APPEND, 0600);
-        if (fd_radio < 0) 
+        if (fd_radio < 0)
         {
             fprintf(stderr, "failed to open %s: %s\n", tmp_log, strerror(errno));
             exit(-1);
         }
-        
+
     }
 
 
     if (log_size && (!stat(tmp_log, &s)) && (s.st_size > log_size))
     {
         fd_radio = get_rotate_file(fd_radio, log_file, _file_list);
-        if (fd_radio < 0) 
+        if (fd_radio < 0)
         {
             fprintf(stderr, "failed to open %s: %s\n", log_file, strerror(errno));
             exit(-1);
         }
-      
+
     }
 
     if(fileter_log(entry->priority, entry->tag, config->filter_list))
@@ -242,7 +248,7 @@
 
     totalLen = snprintf(defaultBuffer, sizeof(defaultBuffer),
     "%s %c/%s (%d): %s\n", timeBuf, priChar, entry->tag, entry->pid, entry->message);
-    
+
     len = strlen(defaultBuffer);
     if(access("/etc/syslog_encrypt_flag", F_OK) == 0)
     {
@@ -256,33 +262,33 @@
     if(buffer_index >= RADIOLOG_BUFF_SIZE)
     {
         // Flush the buffer if it's full
-        if (write(fd_radio, buffer, buffer_index) < 0) 
+        if (write(fd_radio, buffer, buffer_index) < 0)
         {
             perror("write error");
             return -1;
         }
         buffer_index = 0; // Reset buffer index after flushing
     }
-        
+
     if(totalLen < RADIOLOG_BUFF_SIZE)
     {
-        //copy buf to buffer 
+        //copy buf to buffer
         memcpy(buffer + buffer_index, defaultBuffer, totalLen);
         buffer_index += totalLen;
     }
     else
     {
-        write(fd_radio, defaultBuffer, totalLen);
+        mbtk_write(fd_radio, defaultBuffer, totalLen);
     }
-        
-    
+
+
     return 0;
 }
 
 void* alog_thread(void* argv)
 {
     int dev_fd, ret;
-    int log_fd;
+//    int log_fd;
     AndroidLogEntry entry;
     char buf[512] = {0};
     static struct file_list_t file_list;
@@ -312,33 +318,33 @@
 		strncpy(log_file, config->out_path, LOG_CONFIG_LEN - 1);
 	}
 
-    if (config->ip && config->port) 
+    if (config->ip && config->port)
     {
         int port = atoi(config->port);
         printf("%s %d : %s:%s\n", __FUNCTION__, __LINE__, config->ip, config->port);
-        log_fd = tcp_connect(config->ip, port);
-    } 
-    else if (strlen(log_file) > 0) 
+        tcp_connect(config->ip, port);
+    }
+    else if (strlen(log_file) > 0)
     {
         //sprintf(tmp_log, "/tmp/log%s", strstr_tail(log_file, "/"));
-        
+
         snprintf(tmp_log,sizeof(tmp_log), "%s", log_file);
         // 先将文件保存到 /tmp/log/ 目录下,后面到达 rotate_file_size 后,转移到out_path
-       
-    } 
-    else 
+
+    }
+    else
     {
-        log_fd = STDOUT_FILENO;
+        //log_fd = STDOUT_FILENO;
     }
     if(config->rotate_file_size)
     {
         log_size = config->rotate_file_size;
     }
     printf("android log start...\n");
-    while (1) 
+    while (1)
     {
         ret = read(dev_fd, buf, sizeof(buf));
-        if (ret < 0) 
+        if (ret < 0)
         {
             printf("read error\n");
             break;
@@ -348,7 +354,7 @@
         memset(buf, 0, sizeof(buf));
     }
     close(dev_fd);
-   
+
     printf("%s exit \n", __FUNCTION__);
     pthread_exit(NULL);
 	return NULL;
diff --git a/mbtk/mbtk_logd/log_config.h b/mbtk/mbtk_logd/log_config.h
index c37ce24..b3ca188 100755
--- a/mbtk/mbtk_logd/log_config.h
+++ b/mbtk/mbtk_logd/log_config.h
@@ -21,9 +21,9 @@
 
 typedef struct log_config_entry_t {
     int enable;
-    char *name;
+    const char *name;
     int send_fd;
-    char *out_path;
+    const char *out_path;
     char *ip;
     char *port;
     int rotate_file_size;
diff --git a/mbtk/mbtk_logd/main.c b/mbtk/mbtk_logd/main.c
index 7925381..ef750e8 100755
--- a/mbtk/mbtk_logd/main.c
+++ b/mbtk/mbtk_logd/main.c
@@ -41,9 +41,9 @@
             }
             _filter_list = entry->filter_list;
             for (n = 0; n < 10; n++) {
-                printf("%s %d: malloc %x!\n", __FUNCTION__, __LINE__, _filter_list);
+                printf("%s %d: malloc %p!\n", __FUNCTION__, __LINE__, _filter_list);
                 if (_filter_list) {
-                    printf("%s %d: malloc %x!\n", __FUNCTION__, __LINE__, _filter_list->next);
+                    printf("%s %d: malloc %p!\n", __FUNCTION__, __LINE__, _filter_list->next);
                     if (_filter_list->tag) {
                         free(_filter_list->tag);
                     }
@@ -69,7 +69,7 @@
     json_object* fileter_listjson = NULL;
     log_config_entry* entry;
     int i, n, ret, array_length;
-    char* cmdval = NULL;
+    const char* cmdval = NULL;
 
     printf("MBTK_LOGD: in parse_config\n");
     jsonobj = json_object_from_file(LOG_CONFIG_PATH);
@@ -108,7 +108,7 @@
 
         json_object_object_get_ex(datajson, "name", &listjson);
         entry->name = json_object_get_string(listjson);
-        printf("cmdval: %x, %s\n", entry->name, entry->name);
+        printf("cmdval: %s\n", entry->name);
 
         json_object_object_get_ex(datajson, "log_file", &listjson);
         entry->out_path = json_object_get_string(listjson);
diff --git a/mbtk/mbtk_rild/inc/atchannel.h b/mbtk/mbtk_rild/inc/atchannel.h
index b97cb27..c841d7a 100755
--- a/mbtk/mbtk_rild/inc/atchannel.h
+++ b/mbtk/mbtk_rild/inc/atchannel.h
@@ -131,6 +131,7 @@
     CME_ERROR_NON_CME = -1,
     CME_SUCCESS = 0,
     CME_SIM_NOT_INSERTED = 10,
+    CME_SIM_ABSENT = 13,
     CME_ERROR_UNKNOWN
 } AT_CME_Error;
 
diff --git a/mbtk/mbtk_rild/src/atchannel.c b/mbtk/mbtk_rild/src/atchannel.c
index 56b1d08..fe96df1 100755
--- a/mbtk/mbtk_rild/src/atchannel.c
+++ b/mbtk/mbtk_rild/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/src/main.c b/mbtk/mbtk_rild/src/main.c
old mode 100644
new mode 100755
index 8df913b..afff8d5
--- a/mbtk/mbtk_rild/src/main.c
+++ b/mbtk/mbtk_rild/src/main.c
@@ -27,12 +27,14 @@
 #include "info_data.h"

 #include "mbtk_led.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"

@@ -58,7 +60,7 @@
 static bool is_first_boot = FALSE;

 

 void setRadioPower(int isOn);

-int urc_msg_distribute(bool async_process, info_urc_msg_id_enum msg, void *data, int data_len);

+int urc_msg_distribute(bool async_process, info_urc_msg_id_enum msg, const void *data, int data_len);

 int mbtk_signal_log(char *data);

 

 /* Called on command thread */

@@ -79,7 +81,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)

     {

@@ -155,7 +157,7 @@
     if(is_first_boot) {

         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);

         }

@@ -432,7 +434,7 @@
     else if(strStartsWith(s, "+CGREG:")     // GMS/WCDMA data registed.

          || strStartsWith(s, "+CEREG:"))    // LTE data registed.

     {

-        char* tmp_s = s + 7;

+        const char* tmp_s = s + 7;

         static bool net_led_gms_wcdma = FALSE;

         static bool net_led_lte = FALSE;

         while(*tmp_s && *tmp_s == ' ')

@@ -1524,6 +1526,7 @@
     return sock;

 }

 

+#if 0

 static void ril_get_cgpaddr_ip_process()

 {

     int err, skip;

@@ -1592,6 +1595,7 @@
 error:

     at_response_free(p_response);

 }

+#endif

 

 static void sim_state_change(bool plug_in) {

     if(plug_in) {

@@ -1761,6 +1765,7 @@
 int InProduction_Mode(void);

 void server_ready_set(void);

 

+#if 0

 
 /*
  *Get mtdblock which name is ASR_FLAG
@@ -1795,7 +1800,7 @@
 	fclose(fd);
 	return ((find == 1) ? 0 : -1);

 }
-
+

 static int readFromMTD(const char *path, unsigned int offset, void *buf, int size)

 {
 	int ret, fd;
@@ -1850,7 +1855,7 @@
 	close(fd);
 	return 0;
 }

-

+#endif

 static void fota_result_check()

 {

 #if 0

@@ -1886,7 +1891,7 @@
     if(is_first_boot) {

         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);

         }

@@ -1918,7 +1923,7 @@
 

     int fd = open(MBTK_RILD_TEMP_FILE, O_CREAT | O_RDWR, 0644);

     if(fd > 0) {

-        char buff[10] = {0};

+        char buff[100] = {0};

         int count = 0;

         if(read(fd, buff, sizeof(buff)) > 0) {

             count = atoi(buff);

@@ -1936,7 +1941,7 @@
         count++;

         memset(buff, 0, sizeof(buff));

         snprintf(buff, sizeof(buff), "%d", count);

-        write(fd, buff, strlen(buff));

+        mbtk_write(fd, buff, strlen(buff));

         close(fd);

     } else {

         is_first_boot = FALSE;

diff --git a/mbtk/mbtk_rild/src/mbtk_call.c b/mbtk/mbtk_rild/src/mbtk_call.c
index 94c835f..272e8be 100755
--- a/mbtk/mbtk_rild/src/mbtk_call.c
+++ b/mbtk/mbtk_rild/src/mbtk_call.c
@@ -28,8 +28,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);
@@ -151,7 +151,7 @@
     ATResponse *response = NULL;
     int tmp_int;
     char *tmp_str = NULL;
-    
+
     int err = at_send_command_multiline("AT+CLCC", "+CLCC:", &response);
     if (err < 0 || response->success == 0){
         *cme_err = at_get_cme_error(response);
diff --git a/mbtk/mbtk_rild/src/mbtk_data_call.c b/mbtk/mbtk_rild/src/mbtk_data_call.c
index 5215f77..321fb7c 100755
--- a/mbtk/mbtk_rild/src/mbtk_data_call.c
+++ b/mbtk/mbtk_rild/src/mbtk_data_call.c
@@ -1,5 +1,9 @@
 #if 1
+#include <ctype.h>
+
 #include "mbtk_data_call.h"
+#include "mbtk_info.h"
+#include "mbtk_utils.h"
 
 #define MBTK_RESULT_FAIL     -1
 #define MBTK_RESULT_SUCCESS  0
@@ -134,7 +138,7 @@
     int offset = 0;
     int fd = -1;
     sprintf(buf, "route add default dev ccinet%d", cid -1);
-    system(buf);
+    mbtk_system(buf);
 
     memset(buf, 0x0, 1024);
     memset(dns, 0x0, 128);
@@ -223,8 +227,8 @@
             LOGE("MNC not find !");
             return MBTK_RESULT_SUCCESS;
         }
-    }  
-    
+    }
+
     {
         int default_apn_name_length = p - ((char *)apninfo_s[1].apn_name) -1;
         LOGD("[qser_data] qser_check_apn_type default_apn_name_length = [%d]!", default_apn_name_length);
@@ -248,7 +252,7 @@
                         break;
                     }
                 }
-                
+
                 i++;
             }
 
@@ -270,7 +274,7 @@
         LOGE("paran is NULL.");
         return MBTK_RESULT_FAIL;
     }
-     
+
     //check 2 - 7
     int pdp_type_tmp = 1;
     for (;pdp_type_tmp <= MBTK_APN_CID_MAX; pdp_type_tmp++)
@@ -289,7 +293,7 @@
                     return MBTK_RESULT_FAIL;
                 }
             }
-            
+
             if(0x0 != apn_name[0])
             {
                 if (strcmp((char *)apninfo_s[pdp_type_tmp].apn_name, (char *)apn_name) == 0)
@@ -341,7 +345,7 @@
             LOGE("get user pass fail!ret [%d].", ret);
             return MBTK_RESULT_FAIL;
         }
-        
+
         mbtk_ip_type_enum local_ip_type = (mbtk_ip_type_enum)atoi(&local_ip[0]);
 
         if(apn->ip_type != local_ip_type || strcmp((char *)apn->apn, local_apn_name))
@@ -396,7 +400,7 @@
 
     sprintf(buff, "%s%d", MBTK_APN_TYPE, cid);
     property_set(buff, "NULL");
-    
+
     memset(&apninfo_s[cid], 0x0, sizeof(mbtk_qser_apn_info_s));
     return MBTK_RESULT_SUCCESS;
 }
@@ -599,10 +603,10 @@
         return MBTK_RESULT_FAIL;
     }
 
-    int ret = -1;
+//    int ret = -1;
     char buff[32] = {0};
     int cid = apn.cid;
-    
+
     memset(&apninfo_s[cid], 0x0, sizeof(mbtk_qser_apn_info_s));
     apninfo_s[cid].cid = apn.cid;
     apninfo_s[cid].ip_type = apn.ip_type;
@@ -619,14 +623,14 @@
     {
         memcpy(apninfo_s[cid].user_pass, apn.pass, strlen((char *)apn.pass));
     }
-   
+
     memcpy(apninfo_s[cid].apn_type, apn_type, strlen((char *)apn_type));
     if(state_save)
     {
         sprintf(buff, "%s%d", MBTK_APN_TYPE, apn.cid);
         property_set(buff, (char *)apn_type);
     }
-    
+
 
     if(state_save)
     {
@@ -659,7 +663,7 @@
     int len = 0;
     int ret = -1;
     memset(apn, 0x0, sizeof(mbtk_apn_info_t));
-    
+
     // cid
     apn->cid = (int)*str++;
 
@@ -686,7 +690,7 @@
             LOGE("cid is error.");
             return MBTK_RESULT_FAIL;
         }
-        
+
         if(apn->cid == 1)
         {
             LOGE("cid 1 no support set.");
@@ -720,7 +724,7 @@
         LOGE("auth input error!");
         return MBTK_RESULT_FAIL;
     }
-    
+
     // apn
     len = byte_2_uint16(str, false);
     str += sizeof(uint16);
@@ -759,12 +763,12 @@
 
     LOGD("APN : %d, %d, %s, %s, %s, %s, %s.", apn->cid,
                                         apn->ip_type,
-                                        (str_empty(apn->apn) ? "NULL" : apn->apn),
-                                        (str_empty(apn->user) ? "NULL" : apn->user),
-                                        (str_empty(apn->pass) ? "NULL" : apn->pass),
-                                        (str_empty(apn->auth) ? "NULL" : apn->auth),
-                                        (str_empty(apn_type) ? "NULL" : apn_type));
-    
+                                        (str_empty(apn->apn) ? "NULL" : (char*)apn->apn),
+                                        (str_empty(apn->user) ? "NULL" : (char*)apn->user),
+                                        (str_empty(apn->pass) ? "NULL" : (char*)apn->pass),
+                                        (str_empty(apn->auth) ? "NULL" : (char*)apn->auth),
+                                        (str_empty(apn_type) ? "NULL" : (char*)apn_type));
+
     ret = mbtk_apn_check_num1(apn_type, apn->apn, apn->cid);
     if(ret < 0)
     {
diff --git a/mbtk/mbtk_rild/src/mbtk_info_server.c b/mbtk/mbtk_rild/src/mbtk_info_server.c
index 27d08d4..f935a65 100755
--- a/mbtk/mbtk_rild/src/mbtk_info_server.c
+++ b/mbtk/mbtk_rild/src/mbtk_info_server.c
@@ -10,6 +10,7 @@
 #include <fcntl.h>
 #include <signal.h>
 #include <cutils/properties.h>
+#include <sys/time.h>
 
 #include "mbtk_type.h"
 #include "mbtk_info.h"
@@ -38,9 +39,9 @@
 static mbtk_queue_node_t info_queue;
 static pthread_cond_t info_cond;
 static pthread_mutex_t info_mutex;
-static mbtk_queue_node_t urc_queue;
-static pthread_cond_t urc_cond;
-static pthread_mutex_t urc_mutex;
+//static mbtk_queue_node_t urc_queue;
+//static pthread_cond_t urc_cond;
+//static pthread_mutex_t urc_mutex;
 static band_set_info_t band_set_info;
 static bool band_set_success = FALSE;
 static mbtk_modem_band_area_enum band_area;
@@ -66,6 +67,9 @@
 static mbtk_signal_info_t signal_globe;
 
 mbtk_info_err_enum ecall_pack_req_process(sock_client_info_t* cli_info, mbtk_info_pack_t* pack);
+void apn_prop_get();
+int mbtk_signal_log(char *data);
+
 
 /*
 AT*POWERIND=0"
@@ -130,6 +134,7 @@
 {
     ATResponse *response = NULL;
     char cmd[100] = {0};
+    int err = 0;
 
     if ((state->mode == 1 && state->oosPhase[0] == 0 && state->oosPhase[1] == 0 && state->oosPhase[2] == 0) \
         || state->mode == 0)
@@ -158,7 +163,7 @@
     }
 
     LOG("Set the oos command is = [%s]\n", cmd);
-    int err = at_send_command(cmd, &response);
+    err = at_send_command(cmd, &response);
     if (err < 0 || response->success == 0){
         *cme_err = at_get_cme_error(response);
         goto exit;
@@ -289,7 +294,7 @@
         {
             //mbtk_info_pack_data_set(pack, data, data_len);
             pack->data_len = (uint16)data_len;
-            pack->data = (const uint8*)data;
+            pack->data = (uint8*)data;
         }
         mbtk_info_pack_send(fd, pack);
         mbtk_info_pack_free(&pack);
@@ -303,12 +308,12 @@
 static int apn_prop_set(mbtk_apn_info_t *apn)
 {
     char prop_name[20] = {0};
-    char prop_data[300] = {0};
+    char prop_data[1024] = {0};
     sprintf(prop_name, "%s_%d",MBTK_APN_PROP,apn->cid);
-    snprintf(prop_data, 300, "%d,%s,%s,%s,%s", apn->ip_type, apn->apn,
-        str_empty(apn->user) ? "NULL" : apn->user,
-        str_empty(apn->pass) ? "NULL" : apn->pass,
-        str_empty(apn->auth) ? "NULL" : apn->auth);
+    snprintf(prop_data, sizeof(prop_data), "%d,%s,%s,%s,%s", apn->ip_type, apn->apn,
+        str_empty(apn->user) ? "NULL" : (char*)apn->user,
+        str_empty(apn->pass) ? "NULL" : (char*)apn->pass,
+        str_empty(apn->auth) ? "NULL" : (char*)apn->auth);
 
     return property_set(prop_name, prop_data);
 }
@@ -394,6 +399,7 @@
 #endif
 }
 
+#if 0
 static int parseRegistrationState(char *str, int *items, int **response)
 {
     int err;
@@ -518,7 +524,7 @@
     free(resp);
     return -1;
 }
-
+#endif
 /*
 0: minimum functionality
 1: full functionality
@@ -586,7 +592,7 @@
                 break;
 
             case CME_SIM_NOT_INSERTED:
-            case 13: //sim fail,as "sim absent"
+            case CME_SIM_ABSENT: //sim fail,as "sim absent"
                 ret = MBTK_SIM_ABSENT;
                 goto done;
 
@@ -709,7 +715,7 @@
         memcpy(apn_name, ptr_1, ptr_2 - ptr_1); // apn
 
         // Check ip_type and apn_name
-        if(ip_type != apn->ip_type || strcmp(apn_name, apn->apn)) {
+        if(ip_type != apn->ip_type || strcmp(apn_name, (char*)apn->apn)) {
             LOGD("APN Changed, not get user/pass/auth.");
             return -1;
         }
@@ -752,7 +758,7 @@
 static int req_plmn_get(mbtk_plmn_info *type, 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){
@@ -815,7 +821,7 @@
 static int req_sim_card_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){
@@ -852,7 +858,8 @@
 static int req_pin_puk_last_times_get(mbtk_pin_puk_last_times *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){
@@ -867,29 +874,33 @@
         goto exit;
     }
     mbtk_pin_puk_last_times 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:
@@ -1139,7 +1150,7 @@
 static int req_time_set(int type, char *time, int *cme_err)
 {
     ATResponse *response = NULL;
-    int tmp_int;
+//    int tmp_int;
     char cmd[200] = {0};
     if(str_empty(time)){
         sprintf(cmd, "AT+SYSTIME=%d", type);
@@ -1343,7 +1354,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){
@@ -1859,10 +1870,10 @@
 
 OK
 */
-static int req_get_pin_state(mbtk_enable_pin_info *state, int *cme_err)
+static int req_get_pin_state(mbtk_pin_state_enum *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)
@@ -1898,11 +1909,11 @@
 
     if(clck == 1)
     {
-        state = MBTK_PIN_ENABLE;
+        *state = MBTK_PIN_ENABLE;
     }
     else
     {
-        state = MBTK_PIN_DISABLE;
+        *state = MBTK_PIN_DISABLE;
     }
 exit:
     at_response_free(response);
@@ -2213,8 +2224,8 @@
 static int req_available_net_get(void* buff, int *cme_err)
 {
     ATResponse *response = NULL;
-    char *tmp_ptr = NULL;
-    int tmp_int;
+//    char *tmp_ptr = NULL;
+//    int tmp_int;
     int buff_size = 0;
     int err = at_send_command_singleline("AT+COPS=?", "+COPS:", &response);
 
@@ -2728,7 +2739,7 @@
     printf("req_cmgl_set(2)-----------------start\n");
     printf("cmgl:%s\n", cmgl);
     ATResponse *response = NULL;
-    char cmd[30] = {0};
+    char cmd[500] = {0};
 	char data[218] = {0};
     int err = 0;
 
@@ -2748,8 +2759,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;
@@ -3116,9 +3127,9 @@
 static int net_ims_get(int *reg, int *cme_err)
 {
     ATResponse *response = NULL;
-    int tmp_int, tmp_reg = 0;
+    int tmp_reg = 0;
     int err;
-    char *tmp_str = NULL;
+//    char *tmp_str = NULL;
 
     err = at_send_command_singleline("AT+ACONFIG?", "", &response);
     if (err < 0 || response->success == 0 || !response->p_intermediates){
@@ -3146,7 +3157,7 @@
     ATResponse *response = NULL;
     int tmp_int, tmp_reg = -1;
     int err;
-    char *tmp_str = NULL;
+//    char *tmp_str = NULL;
 
     err = at_send_command_multiline("AT+CIREG?", "+CIREG:", &response);
     if (err < 0 || response->success == 0 || !response->p_intermediates){
@@ -3301,10 +3312,10 @@
                     uint16_2_byte((uint16)0, data_ptr, false);
                     data_ptr += sizeof(uint16);
                 } else {
-                    uint16_2_byte((uint16)strlen(apn.user), data_ptr, false);
+                    uint16_2_byte((uint16)strlen((char*)apn.user), data_ptr, false);
                     data_ptr += sizeof(uint16);
-                    memcpy(data_ptr, apn.user, strlen(apn.user));
-                    data_ptr += strlen(apn.user);
+                    memcpy(data_ptr, apn.user, strlen((char*)apn.user));
+                    data_ptr += strlen((char*)apn.user);
                 }
 
                 // pass
@@ -3312,10 +3323,10 @@
                     uint16_2_byte((uint16)0, data_ptr, false);
                     data_ptr += sizeof(uint16);
                 } else {
-                    uint16_2_byte((uint16)strlen(apn.pass), data_ptr, false);
+                    uint16_2_byte((uint16)strlen((char*)apn.pass), data_ptr, false);
                     data_ptr += sizeof(uint16);
-                    memcpy(data_ptr, apn.pass, strlen(apn.pass));
-                    data_ptr += strlen(apn.pass);
+                    memcpy(data_ptr, apn.pass, strlen((char*)apn.pass));
+                    data_ptr += strlen((char*)apn.pass);
                 }
 
                 // auth
@@ -3323,10 +3334,10 @@
                     uint16_2_byte((uint16)0, data_ptr, false);
                     data_ptr += sizeof(uint16);
                 } else {
-                    uint16_2_byte((uint16)strlen(apn.auth), data_ptr, false);
+                    uint16_2_byte((uint16)strlen((char*)apn.auth), data_ptr, false);
                     data_ptr += sizeof(uint16);
-                    memcpy(data_ptr, apn.auth, strlen(apn.auth));
-                    data_ptr += strlen(apn.auth);
+                    memcpy(data_ptr, apn.auth, strlen((char*)apn.auth));
+                    data_ptr += strlen((char*)apn.auth);
                 }
             }
 
@@ -3565,7 +3576,7 @@
             break;
         }
     }
-    if(strlen(apn->apn) > 0) {
+    if(strlen((char*)apn->apn) > 0) {
         index += sprintf(cmd + index,"\"%s\"", apn->apn);
     }
 
@@ -3582,11 +3593,11 @@
 
         memset(cmd,0,400);
         int cmd_auth=0;
-        if(strstr(apn->auth,"NONE"))
+        if(strstr((char*)apn->auth,"NONE"))
             cmd_auth = 0;
-        else if(strstr(apn->auth,"PAP"))
+        else if(strstr((char*)apn->auth,"PAP"))
             cmd_auth = 1;
-        else if(strstr(apn->auth,"CHAP"))
+        else if(strstr((char*)apn->auth,"CHAP"))
             cmd_auth = 2;
 #if 0
         else if(strstr(apn->auth,"PAP AND CHAP"))
@@ -3644,6 +3655,7 @@
     }
 }
 
+#if 0
 /*
 AT+CGDATA="",6
 CONNECT
@@ -3659,7 +3671,7 @@
 {
     ATResponse *response = NULL;
     char cmd[400] = {0};
-    int index = 0;
+//    int index = 0;
     int err = 0;
 
     err = at_send_command_singleline("AT+COPS?", "+COPS:", &response);
@@ -3671,7 +3683,7 @@
     }
 
     int tmp_int;
-    char cmd_buf[64];
+    char *cmd_buf = NULL;
     char *line = response->p_intermediates->line;
     err = at_tok_start(&line);
     if (err < 0)
@@ -3703,7 +3715,7 @@
     if(tmp_int == 7 && cid == 1)    //LTE && cid = 1
     {
         ATResponse *response = NULL;
-        char cmd[400] = {0};
+//        char cmd[400] = {0};
         int err = 0;
 
         err = at_send_command("AT+CFUN=1", &response);
@@ -3717,7 +3729,8 @@
     else
     {
         ATResponse *response = NULL;
-        char cmd[400] = {0};
+//        char cmd[400] = {0};
+        memset(cmd, 0, sizeof(cmd));
         int err = 0;
         sprintf(cmd, "AT+CGDATA=\"\",%d", cid);
         err = at_send_command(cmd, &response);
@@ -3733,6 +3746,7 @@
     at_response_free(response);
     return err;
 }
+#endif
 
 /*
 AT+CGACT?
@@ -4064,6 +4078,7 @@
     return err;
 }
 
+#if 0
 /*
 AT+CGCONTRDP
 +CGCONTRDP: 1,5,"cmnet.MNC000.MCC460.GPRS","10.156.238.86","","223.87.253.100","223.87.253.253","","",0,0
@@ -4148,7 +4163,7 @@
                     goto exit;
                 }
 
-                if(inet_ntop(AF_INET6, tmp_ipv6, apn->ipv6, 50) == NULL) {
+                if(inet_ntop(AF_INET6, tmp_ipv6, (char*)apn->ipv6, 50) == NULL) {
                     err = -1;
                     LOGE("inet_ntop ipv6 ip fail.");
                     goto exit;
@@ -4163,6 +4178,7 @@
     at_response_free(response);
     return err;
 }
+#endif
 
 mbtk_info_err_enum call_pack_req_process(sock_client_info_t* cli_info, mbtk_info_pack_t* pack);
 mbtk_info_err_enum sms_pack_req_process(sock_client_info_t* cli_info, mbtk_info_pack_t* pack);
@@ -5187,8 +5203,8 @@
                         ptr += len;
                     }
 
-                    LOGD("APN : %d, %d, %s, %s, %s, %s", apn.cid, apn.ip_type, str_empty(apn.apn) ? "NULL" : apn.apn,
-                        str_empty(apn.user) ? "NULL" : apn.user, str_empty(apn.pass) ? "NULL" : apn.pass, str_empty(apn.auth) ? "NULL" : apn.auth);
+                    LOGD("APN : %d, %d, %s, %s, %s, %s", apn.cid, apn.ip_type, str_empty(apn.apn) ? "NULL" : (char*)apn.apn,
+                        str_empty(apn.user) ? "NULL" : (char*)apn.user, str_empty(apn.pass) ? "NULL" : (char*)apn.pass, str_empty(apn.auth) ? "NULL" : (char*)apn.auth);
                     if(req_apn_set(&apn, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
                     {
                         if(cme_err != MBTK_INFO_ERR_CME_NON) {
@@ -5237,7 +5253,7 @@
                 }
                 else
                 {
-                    const uint8* ptr = pack->data;
+//                    const uint8* ptr = pack->data;
                     mbtk_apn_info_t apn;
                     mbtk_apn_req_type_enum req_type = MBTK_APN_REQ_TYPE_SET;
                     uint8 apn_type[MBTK_QSER_APN_NAME_SIZE] = {0};
@@ -5801,7 +5817,6 @@
                 }
                 else     // Set OOS
                 {
-                    mbtk_oos_info *state = (mbtk_oos_info *)pack->data;
                     if(pack->data_len != sizeof(mbtk_oos_info))
                     {
                         err = MBTK_INFO_ERR_REQ_PARAMETER;
@@ -5809,6 +5824,7 @@
                         break;
                     }
 
+                    mbtk_oos_info *state = (mbtk_oos_info *)pack->data;
                     if(req_oos_set(state, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
                     {
                         if(cme_err != MBTK_INFO_ERR_CME_NON) {
@@ -5910,7 +5926,7 @@
     return 0;
 }
 
-static void radio_state_change(void *data, int data_len)
+static void radio_state_change(const void *data, int data_len)
 {
     uint8 *data_ptr = (uint8*)data;
     if(data_ptr[0]) {
@@ -5936,7 +5952,7 @@
     }
 }
 
-static void pdp_state_change(void *data, int data_len)
+static void pdp_state_change(const void *data, int data_len)
 {
     sock_client_info_t *cli = NULL;
     list_first(sock_client_list);
@@ -5954,7 +5970,7 @@
     }
 }
 
-static void net_state_change(void *data, int data_len)
+static void net_state_change(const void *data, int data_len)
 {
     sock_client_info_t *cli = NULL;
     list_first(sock_client_list);
@@ -5973,7 +5989,7 @@
     }
 }
 
-static void call_state_change(void *data, int data_len)
+static void call_state_change(const void *data, int data_len)
 {
     sock_client_info_t *cli = NULL;
     list_first(sock_client_list);
@@ -5992,7 +6008,7 @@
     }
 }
 
-static void sim_state_change(void *data, int data_len)
+static void sim_state_change(const void *data, int data_len)
 {
     sock_client_info_t *cli = NULL;
     list_first(sock_client_list);
@@ -6011,7 +6027,7 @@
     }
 }
 
-static void sms_state_change(void *data, int data_len)
+static void sms_state_change(const void *data, int data_len)
 {
     sock_client_info_t *cli = NULL;
     list_first(sock_client_list);
@@ -6030,7 +6046,7 @@
     }
 }
 
-static void signal_state_change(void *data, int data_len)
+static void signal_state_change(const void *data, int data_len)
 {
     sock_client_info_t *cli = NULL;
     list_first(sock_client_list);
@@ -6050,7 +6066,7 @@
 }
 
 
-int urc_msg_distribute(bool async_process, info_urc_msg_id_enum msg, void *data, int data_len)
+int urc_msg_distribute(bool async_process, info_urc_msg_id_enum msg, const void *data, int data_len)
 {
 #if 0
     if(urc_queue.count >= PACK_PROCESS_QUEUE_MAX)
@@ -6309,7 +6325,7 @@
                         // "data_len"
                         pack->data_len = 5;
 
-                        char *p = (char *)malloc(5);
+                        uint8 *p = (uint8 *)malloc(5);
                         p[0] = MBTK_DATA_CALL_START;
                         p[1] = i;
                         p[2] = 0;
@@ -6926,6 +6942,7 @@
     }
 }
 
+#if 0
 /*
 root@OpenWrt:/usrdata# cat /proc/mtd
 dev:    size   erasesize  name
@@ -6954,7 +6971,7 @@
 		return -1;
     }
 
-    int fp = fopen("/proc/mtd", "r");
+    FILE* fp = fopen("/proc/mtd", "r");
 	if (fp == NULL) {
 		LOGE("Open MTD failed!");
 		return -1;
@@ -6972,11 +6989,12 @@
 
     return -1;
 }
-
+#endif
+#if 0
 static int custom_partition_read(const char *name, mbtk_cust_info_t *cust_info)
 {
-    int fd = 0, ret = 0;
-    unsigned int step = 0, offset = 0, flaglen = 0;
+    int fd = 0;
+    unsigned int flaglen = 0;
     flaglen = sizeof(mbtk_cust_info_t);
 
     char mtd_path[50] = {0};
@@ -7012,6 +7030,7 @@
     close(fd);
     return -1;
 }
+#endif
 
 /*
 AT*BAND=15,78,147,482,134742231
@@ -7067,11 +7086,12 @@
     return NULL;
 }
 
+#if 0
 static void* net_monitor_thread(void* arg)
 {
     UNUSED(arg);
     // Start network monitor
-    int cid;
+//    int cid;
     while(1) {
 #if 0
         // Config IP
@@ -7157,7 +7177,9 @@
     LOGD("monitor_thread exit.");
     return NULL;
 }
+#endif
 
+#if 0
 static void* urc_process_thread(void* arg)
 {
     UNUSED(arg);
@@ -7215,6 +7237,7 @@
 
     return NULL;
 }
+#endif
 
 static void ril_at_ready_process()
 {
@@ -7232,7 +7255,7 @@
         at_send_command("AT+CEREG=2", NULL);
     }
 
-    int count = 0;
+//    int count = 0;
 #endif
     net_info.sim_state = getSIMStatus();
 #if 0
@@ -7342,7 +7365,7 @@
         goto error;
     }
 
-    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/src/mbtk_led.c b/mbtk/mbtk_rild/src/mbtk_led.c
index 27fd24f..a850f10 100755
--- a/mbtk/mbtk_rild/src/mbtk_led.c
+++ b/mbtk/mbtk_rild/src/mbtk_led.c
@@ -24,26 +24,28 @@
 static mbtk_net_led_type mbtk_net_led_prev_state = MBTK_NET_LED_SEARCH_NETWORK;
 static mbtk_status_led_type mbtk_status_led_state = MBTK_STATUS_LED_CLOSE;
 
-static int MBTK_NET_LED_LOCK_SET = 0; 
+static int MBTK_NET_LED_LOCK_SET = 0;
 /****************************VARIABLE***************************************/
 
 /******************************FUNC*****************************************/
-int mbtk_read_ccinet(void) 
+int mbtk_read_ccinet(void)
 {
     FILE *fp;
-    int ret = 0;
-    char buffer[1024]; 
-    char type[10]={0};
-    
-    fp = popen("ifconfig", "r"); 
+//    int ret = 0;
+    char buffer[1024];
+//    char type[10]={0};
+
+    fp = popen("ifconfig", "r");
     if (fp == NULL) {
         printf("popen fail\n");
         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); // 
+    pclose(fp); //
 
     char *p1 = strstr(buffer, "ccinet");
     if(p1 == NULL)
@@ -187,7 +189,7 @@
         result = write(fd,"1",1);
     }
     close(fd);
-    
+
     if(result != 1)
     {
         LOGE("[led]Set gpio[%d] value fail.", gpio);
@@ -292,7 +294,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);
@@ -301,7 +303,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_rild/src/mbtk_phonebook.c b/mbtk/mbtk_rild/src/mbtk_phonebook.c
index 215727c..34611cb 100755
--- a/mbtk/mbtk_rild/src/mbtk_phonebook.c
+++ b/mbtk/mbtk_rild/src/mbtk_phonebook.c
@@ -25,7 +25,7 @@
 mbtk_info_err_enum pb_pack_req_process(sock_client_info_t* cli_info, mbtk_info_pack_t* pack)
 {
     mbtk_info_err_enum err = MBTK_INFO_ERR_SUCCESS;
-    int cme_err = MBTK_INFO_ERR_CME_NON;
+//    int cme_err = MBTK_INFO_ERR_CME_NON;
     switch(pack->info_id)
     {
         case MBTK_INFO_ID_PB_STATE_REQ:
diff --git a/mbtk/mbtk_rild/src/mbtk_sms.c b/mbtk/mbtk_rild/src/mbtk_sms.c
index 79752e7..c2e0f36 100755
--- a/mbtk/mbtk_rild/src/mbtk_sms.c
+++ b/mbtk/mbtk_rild/src/mbtk_sms.c
@@ -30,7 +30,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){
@@ -128,7 +128,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){
@@ -235,7 +235,7 @@
 	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)
@@ -254,10 +254,10 @@
     }
     LOGD("num:%s", pnum);
     LOGD("data:%s", data);
-    
+
 	sprintf(cmd, "AT+CMGS=%s", pnum);
     LOGD("cmd:%s", cmd);
-    
+
 	if(strlen(cmd) > 0)
 	{
 		int err = at_send_command_sms(cmd, data, "+CMGS: ", &response);
@@ -302,7 +302,7 @@
 
 	sprintf(cmd, "AT+CMGW=%s", pnum);
 	printf("cmd:%s,data:%s---------\n", cmd,data);
-	
+
 	if(strlen(cmd) > 0)
 	{
 		int err = at_send_command_sms(cmd, data, "+CMGW: ", &response);
@@ -333,16 +333,16 @@
     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 );
 	sprintf(cmd, "AT+CMGD=%s", data);
 	printf("cmd:%s,data:%s---------\n", cmd,data);
-	
+
 	if(strlen(cmd) > 0)
 	{
 		int err = at_send_command(cmd, &response);
@@ -373,7 +373,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){
@@ -407,7 +407,7 @@
 
 
 /*
-AT+CMGL="ALL"	
+AT+CMGL="ALL"
 
 +CMGL: 1,"REC READ","10658678",,"22.11.14 10:41:44 GMT+8"
 
@@ -429,7 +429,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;
 
@@ -458,7 +458,7 @@
 
 	ptr1 = NULL;
 	ptr2 = NULL;
-	
+
 	if(strlen(cmd) > 0)
 	{
         err = at_send_command_multiline(cmd, "", &response);
@@ -517,8 +517,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:
@@ -535,7 +535,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){
@@ -557,7 +557,7 @@
     {
         err = -1;
     }
-    
+
 exit:
     at_response_free(response);
     return err;
@@ -568,16 +568,16 @@
     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);
 	sprintf(cmd, "AT+CSCA=%s", data);
 	printf("cmd:%s,data:%s---------\n", cmd,data);
-	
+
 	if(strlen(cmd) > 0)
 	{
 		int err = at_send_command(cmd, &response);
@@ -601,16 +601,16 @@
     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);
 	sprintf(cmd, "AT+CSMP=%s", data);
 	printf("cmd:%s,data:%s---------\n", cmd,data);
-	
+
 	if(strlen(cmd) > 0)
 	{
 		int err = at_send_command(cmd, &response);
@@ -636,14 +636,14 @@
     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);
 	sprintf(cmd, "AT+CSCB=%s", cscb);
 	printf("cmd:%s,data:%s---------\n", cmd,data);
-	
+
 	if(strlen(cmd) > 0)
 	{
 		int err = at_send_command(cmd, &response);
@@ -695,10 +695,10 @@
 			*cme_err = at_get_cme_error(response);
 			goto exit;
 		}
-		
+
 		char *line = response->p_intermediates->line;
 		printf("line:%s\n", line);
-		
+
 		char *tmp_str = NULL;
 		err = at_tok_nextstr(&line, &tmp_str); // phone_number
 		if (err < 0)
@@ -859,7 +859,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_INFO_ERR_CME_NON)
                 {
                     printf("set req_cnmi_set() fail.\n");
diff --git a/mbtk/mbtk_rild/src/ril_ecall.c b/mbtk/mbtk_rild/src/ril_ecall.c
index e0a6265..7e3a03e 100755
--- a/mbtk/mbtk_rild/src/ril_ecall.c
+++ b/mbtk/mbtk_rild/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
                 {
-                    pack_rsp_send(cli_info->fd, RIL_MSG_ID_ECALL_MSD_RSP, msd, strlen(msd));
+                    pack_rsp_send(cli_info->fd, RIL_MSG_ID_ECALL_MSD_RSP, 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_INFO_ERR_CME_NON)
+                if(req_ecall_sms_num_get(number, &cme_err) || strlen((char*)number) == 0 || cme_err != MBTK_INFO_ERR_CME_NON)
                 {
                     if(cme_err != MBTK_INFO_ERR_CME_NON) {
                         err = MBTK_INFO_ERR_CME + cme_err;
@@ -1181,7 +1181,7 @@
                 }
                 else
                 {
-                    pack_rsp_send(cli_info->fd, RIL_MSG_ID_ECALL_SMS_NUM_RSP, number, strlen(number));
+                    pack_rsp_send(cli_info->fd, RIL_MSG_ID_ECALL_SMS_NUM_RSP, number, strlen((char*)number));
                 }
             }
             else     // Set
diff --git a/mbtk/mbtk_rild_v2/src/main.c b/mbtk/mbtk_rild_v2/src/main.c
index f0dfb60..c1a20c8 100755
--- a/mbtk/mbtk_rild_v2/src/main.c
+++ b/mbtk/mbtk_rild_v2/src/main.c
@@ -308,7 +308,7 @@
     }
 }

 

-static int urc_msg_distribute(bool async_process, ril_msg_id_enum msg_id, void *data, int data_len)

+static int urc_msg_distribute(bool async_process, ril_msg_id_enum msg_id, const void *data, int data_len)

 {

     // Send urc msg to client.

     if(msg_id > RIL_MSG_ID_IND_BEGIN && msg_id < RIL_MSG_ID_IND_END) {

diff --git a/mbtk/mbtk_sdk_ready/src/main.c b/mbtk/mbtk_sdk_ready/src/main.c
index bcb696b..d571f15 100755
--- a/mbtk/mbtk_sdk_ready/src/main.c
+++ b/mbtk/mbtk_sdk_ready/src/main.c
@@ -1,15 +1,17 @@
 #if 1
 #include <stdio.h>
 //#include <stdlib.h>
-//#include <unistd.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_info_api.h"
+#include "mbtk_utils.h"
 
 #define MBTK_RESULT_FAIL -1
 #define MBTK_RESULT_SUCCESS 0
diff --git a/mbtk/mbtk_servicesd/instance_monitor_service.c b/mbtk/mbtk_servicesd/instance_monitor_service.c
index 2557304..a814bd6 100755
--- a/mbtk/mbtk_servicesd/instance_monitor_service.c
+++ b/mbtk/mbtk_servicesd/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/main.c b/mbtk/mbtk_servicesd/main.c
index 6afe654..f546cd3 100755
--- a/mbtk/mbtk_servicesd/main.c
+++ b/mbtk/mbtk_servicesd/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_utils/at.c b/mbtk/mbtk_utils/at.c
index 950d3e2..1e8f91b 100755
--- a/mbtk/mbtk_utils/at.c
+++ b/mbtk/mbtk_utils/at.c
@@ -11,9 +11,11 @@
 #include <netinet/in.h>
 #include <signal.h>
 #include <unistd.h>
+#include <pthread.h>
 #include <sys/select.h>
 
 #include "mbtk_type.h"
+#include "mbtk_utils.h"
 
 //#define AT_TYPE_SOCKET
 #define MBTK_LOG
@@ -39,8 +41,8 @@
     AT_MODE_DEV_2
 } at_mode_enum;
 
-static int epoll_fd = -1;
-static struct epoll_event epoll_events[20];
+// static int epoll_fd = -1;
+// static struct epoll_event epoll_events[20];
 static int at_fd = -1;
 static at_mode_enum at_mode = AT_MODE_SOCK_1;
 
@@ -54,15 +56,16 @@
 		"NO DIALTONE",
 		NULL};
 
-//#ifdef AT_TYPE_SOCKET
+#ifndef TEMP_FAILURE_RETRY
 #define TEMP_FAILURE_RETRY(exp) ({         \
     typeof (exp) _rc;                      \
     do {                                   \
         _rc = (exp);                       \
     } while (_rc == -1 && errno == EINTR); \
     _rc; })
-//#endif
+#endif
 
+#if 0
 static void at_epoll_change(int is_add,int fd)
 {
     struct epoll_event ev;
@@ -95,6 +98,7 @@
 
     return 0;
 }
+#endif
 
 //#ifdef AT_TYPE_SOCKET
 int openSocket(const char* sockname)
@@ -349,7 +353,7 @@
     pthread_attr_t attr;
     pthread_attr_init (&attr);
     pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
-    int ret = pthread_create(&tid, &attr, read_thread_run, &attr);
+    int ret = pthread_create(&tid, &attr, read_thread_run, NULL);
     if (ret < 0)
     {
         LOGE("pthread_create\n");
@@ -595,10 +599,10 @@
                         memset(write_buff, 0x0, 1024);
                         printf("%s\n", read_buff);
                         len = snprintf(write_buff, 1024, "%s\n", read_buff);
-                        write(at_fd, write_buff, len);
+                        mbtk_write(at_fd, write_buff, len);
                     } else {
                         printf("Read error:%d\n",errno);
-                        return NULL;
+                        return -1;
                     }
                 }
 #endif
diff --git a/mbtk/mbtk_utils/device_info.c b/mbtk/mbtk_utils/device_info.c
index 6d22c34..864cb36 100755
--- a/mbtk/mbtk_utils/device_info.c
+++ b/mbtk/mbtk_utils/device_info.c
@@ -1,3 +1,4 @@
+#include <string.h>
 #include "mbtk_type.h"
 #include "mbtk_device.h"
 
diff --git a/mbtk/mbtk_utils/mbtk_reboot.c b/mbtk/mbtk_utils/mbtk_reboot.c
index 3263d73..d839ae6 100755
--- a/mbtk/mbtk_utils/mbtk_reboot.c
+++ b/mbtk/mbtk_utils/mbtk_reboot.c
@@ -1,6 +1,8 @@
+#include <string.h>
 #include "mbtk_type.h"
 #include "mbtk_device.h"
-
+#include "mbtk_utils.h"
+#if 0
 static char* band_2_str(mbtk_modem_band_area_enum band_area)
 {
     switch(band_area)
@@ -13,6 +15,7 @@
             return "ALL";
     }
 }
+#endif
 
 static void help()
 {
@@ -22,7 +25,7 @@
 int main(int argc, char *argv[])
 {
     if(argc == 1) {
-        system("reboot -f");
+        mbtk_system("reboot -f");
     } else if(argc == 2) {
         if(strcmp(argv[1], "download")) {
             help();
@@ -48,8 +51,8 @@
         return -1;
     }
 
-    system("sync");
-    system("reboot -f");
+    mbtk_system("sync");
+    mbtk_system("reboot -f");
 
     return 0;
 }
diff --git a/mbtk/test/libmbtk_audio/mbtk_pcm_play_test.c b/mbtk/test/libmbtk_audio/mbtk_pcm_play_test.c
index c11e06a..329d8e2 100755
--- a/mbtk/test/libmbtk_audio/mbtk_pcm_play_test.c
+++ b/mbtk/test/libmbtk_audio/mbtk_pcm_play_test.c
@@ -2,9 +2,13 @@
 #include <unistd.h>
 #include <stdio.h>
 #include <fcntl.h>
+#include <string.h>
+#include <stdlib.h>
 
 #include "audio_if_api.h"
 #include "mbtk_audio2.h"
+#include "mbtk_log.h"
+#include "mbtk_utils.h"
 
 #define BUFF_SIZE 4096
 
@@ -54,7 +58,7 @@
         return -1;
     }
 
-    read(fd, &riff_wave_header, sizeof(riff_wave_header));
+    mbtk_read(fd, &riff_wave_header, sizeof(riff_wave_header));
     if ((riff_wave_header.riff_id != ID_RIFF) || (riff_wave_header.wave_id != ID_WAVE)) {
         printf("Error: '%s' is not a riff/wave file\n", path);
         close(fd);
@@ -62,11 +66,11 @@
     }
 
     do {
-        read(fd, &chunk_header, sizeof(chunk_header));
+        mbtk_read(fd, &chunk_header, sizeof(chunk_header));
 
         switch (chunk_header.id) {
             case ID_FMT:
-                read(fd, &chunk_fmt, sizeof(chunk_fmt));
+                mbtk_read(fd, &chunk_fmt, sizeof(chunk_fmt));
                 /* If the format header is larger, skip the rest */
                 if (chunk_header.sz > sizeof(chunk_fmt))
                     lseek(fd, chunk_header.sz - sizeof(chunk_fmt), SEEK_CUR);
diff --git a/mbtk/test/libmbtk_audio/mbtk_pcm_recorder_test.c b/mbtk/test/libmbtk_audio/mbtk_pcm_recorder_test.c
index 748e599..5f7e03d 100755
--- a/mbtk/test/libmbtk_audio/mbtk_pcm_recorder_test.c
+++ b/mbtk/test/libmbtk_audio/mbtk_pcm_recorder_test.c
@@ -3,6 +3,8 @@
 #include <stdio.h>
 #include <fcntl.h>
 #include <signal.h>
+#include <stdlib.h>
+#include <string.h>
 
 #include "mbtk_audio2.h"
 #include "mbtk_log.h"
@@ -53,7 +55,7 @@
     while(running)
     {
         memset(cmd, 0, 100);
-        int err;
+//        int err;
         printf("1 : Recorder    2 : Pause    3 : Resume    4 : Stop    Other : Exit\n");
         if(fgets(cmd, 100, stdin))
         {
@@ -102,7 +104,7 @@
         }
     }
 
-exit:
+//exit:
     if(mbtk_audio_pcm_deinit()) {
         printf("mbtk_audio_pcm_deinit() fail.\n");
         return -1;
diff --git a/mbtk/test/libmbtk_audio/mbtk_wav_play_test.c b/mbtk/test/libmbtk_audio/mbtk_wav_play_test.c
index b5108f4..c3167b8 100755
--- a/mbtk/test/libmbtk_audio/mbtk_wav_play_test.c
+++ b/mbtk/test/libmbtk_audio/mbtk_wav_play_test.c
@@ -3,9 +3,12 @@
 #include <stdio.h>
 #include <fcntl.h>
 #include <signal.h>
+#include <stdlib.h>
+#include <string.h>
 
 #include "mbtk_audio2.h"
 #include "mbtk_audio_ubus.h"
+#include "mbtk_log.h"
 
 static void sig_handler(int sig)
 {
@@ -41,12 +44,12 @@
     signal(SIGTERM, sig_handler);
 
     char cmd[100];
-    int dsp=0;
+//    int dsp=0;
     bool running = TRUE;
     while(running)
     {
         memset(cmd, 0, 100);
-        int err;
+//        int err;
         printf("1 : Play    2 : Pause    3 : Resume   4 : dsp set  5 : Stop    Other : Exit\n");
         if(fgets(cmd, 100, stdin))
         {
@@ -104,7 +107,7 @@
         }
     }
 
-exit:
+//exit:
     if(mbtk_audio_wav_deinit()) {
         printf("mbtk_audio_wav_deinit() fail.\n");
         return -1;
diff --git a/mbtk/test/libmbtk_audio/mbtk_wav_recorder_test.c b/mbtk/test/libmbtk_audio/mbtk_wav_recorder_test.c
index 2f9a1a2..0ad1ddf 100755
--- a/mbtk/test/libmbtk_audio/mbtk_wav_recorder_test.c
+++ b/mbtk/test/libmbtk_audio/mbtk_wav_recorder_test.c
@@ -3,8 +3,11 @@
 #include <stdio.h>
 #include <fcntl.h>
 #include <signal.h>
+#include <stdlib.h>
+#include <string.h>
 
 #include "mbtk_audio2.h"
+#include "mbtk_log.h"
 
 static void sig_handler(int sig)
 {
@@ -44,7 +47,6 @@
     while(running)
     {
         memset(cmd, 0, 100);
-        int err;
         printf("1 : Recorder    2 : Pause    3 : Resume    4 : Stop    Other : Exit\n");
         if(fgets(cmd, 100, stdin))
         {
@@ -93,7 +95,7 @@
         }
     }
 
-exit:
+//exit:
     if(mbtk_audio_wav_deinit()) {
         printf("mbtk_audio_wav_deinit() fail.\n");
         return -1;
diff --git a/mbtk/test/libmbtk_coap/mbtk_coap_test.c b/mbtk/test/libmbtk_coap/mbtk_coap_test.c
index b211913..1d8e9ad 100755
--- a/mbtk/test/libmbtk_coap/mbtk_coap_test.c
+++ b/mbtk/test/libmbtk_coap/mbtk_coap_test.c
@@ -1,4 +1,6 @@
 #include <string.h>
+#include <unistd.h>
+
 #include "mbtk_type.h"
 #include "mbtk_coap.h"
 #include "mbtk_coap_api.h"
@@ -10,9 +12,9 @@
 
 int main(int argc, char *argv[])
 {
-    char operator[10];
-    int opt;
-    int    ret     = -1;
+    //char operator[10];
+  //  int opt;
+//    int    ret     = -1;
 
 	printf("coap_demo star\r\n");
 	coap_get_method();
@@ -26,8 +28,8 @@
 
 int coap_get_method(void)
 {
-	int ret = -1;
-	ret = mbtk_coap_ecoapnew_exec_cmd("134.102.218.18",5683,0,0);    //server ip, port
+//	int ret = -1;
+	mbtk_coap_ecoapnew_exec_cmd("134.102.218.18",5683,0,0);    //server ip, port
 	mbtk_coap_ecoapmsgid_exec_cmd(1);								//set message id
 	mbtk_coap_ecoaptype_exec_cmd(0);								//set message type
 	mbtk_coap_ecoapcode_exec_cmd(1);								//set Get request method
@@ -40,8 +42,8 @@
 
 int coap_post_method(void)
 {
-	int ret = -1;
-	ret = mbtk_coap_ecoapnew_exec_cmd("134.102.218.18",5683,0,0);     //server ip, port
+//	int ret = -1;
+	mbtk_coap_ecoapnew_exec_cmd("134.102.218.18",5683,0,0);     //server ip, port
 	mbtk_coap_ecoapmsgid_exec_cmd(3);            					//set message id
 	mbtk_coap_ecoaptype_exec_cmd(0);             					//set message type
 	mbtk_coap_ecoapcode_exec_cmd(2);			 					//set Post request method
diff --git a/mbtk/test/libmbtk_ecall/mbtk_ecall_test_v1.c b/mbtk/test/libmbtk_ecall/mbtk_ecall_test_v1.c
index a1b8f01..bec5b32 100755
--- a/mbtk/test/libmbtk_ecall/mbtk_ecall_test_v1.c
+++ b/mbtk/test/libmbtk_ecall/mbtk_ecall_test_v1.c
@@ -131,7 +131,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(info_handle, &cfg);
                     if(err) {
@@ -166,7 +166,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(info_handle, msd);
                         if(err) {
                             printf("Error : %d\n", err);
@@ -394,7 +394,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(info_handle, number);
                         if(err) {
                             printf("Error : %d\n", err);
@@ -445,7 +445,7 @@
         }
     }
 
-exit:
+//exit:
     mbtk_info_handle_free(&info_handle);
 
     LOG("Client exec complete.");
diff --git a/mbtk/test/libmbtk_ftp/mbtk_ftp_test.c b/mbtk/test/libmbtk_ftp/mbtk_ftp_test.c
index 481108d..ce69cde 100755
--- a/mbtk/test/libmbtk_ftp/mbtk_ftp_test.c
+++ b/mbtk/test/libmbtk_ftp/mbtk_ftp_test.c
@@ -122,18 +122,19 @@
     char cmd[50];
     while(1) {
         memset(cmd, 0, 50);
-        gets(cmd);
-        if(!strcasecmp(cmd, "q")) {
-            break;
-        } else {
-            ftp_cmd_process(handle, cmd);
+        if(fgets(cmd, sizeof(cmd), stdin) != NULL) {
+            if(!strcasecmp(cmd, "q")) {
+                break;
+            } else {
+                ftp_cmd_process(handle, cmd);
+            }
         }
 
         printf("CMD:");
     }
 
     printf("FTP test success.\n");
-ftp_quit:
+//ftp_quit:
     mbtk_ftp_quit(handle);
 ftp_exit:
     mbtk_ftp_deinit(handle);
diff --git a/mbtk/test/libmbtk_gnss/mbtk_gnss_test.c b/mbtk/test/libmbtk_gnss/mbtk_gnss_test.c
index e710fa2..e74ad1f 100755
--- a/mbtk/test/libmbtk_gnss/mbtk_gnss_test.c
+++ b/mbtk/test/libmbtk_gnss/mbtk_gnss_test.c
Binary files differ
diff --git a/mbtk/test/libmbtk_lib/mbtk_timer_test.c b/mbtk/test/libmbtk_lib/mbtk_timer_test.c
index 7b24ef2..f903b26 100755
--- a/mbtk/test/libmbtk_lib/mbtk_timer_test.c
+++ b/mbtk/test/libmbtk_lib/mbtk_timer_test.c
@@ -2,6 +2,8 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <stdlib.h>
+#include <unistd.h>
 
 #include "mbtk_utils.h"
 #include "mbtk_log.h"
@@ -14,7 +16,7 @@
 {
     char *str = "----------------------Timeout---------------------------\n";
     if(fd > 0) {
-        write(fd, str, strlen(str));
+        mbtk_write(fd, str, strlen(str));
     }
 
     printf("%s", str);
diff --git a/mbtk/test/libmbtk_mqtt/mbtk_mqtt_aliyun_test.c b/mbtk/test/libmbtk_mqtt/mbtk_mqtt_aliyun_test.c
index 923b123..fc6820e 100755
--- a/mbtk/test/libmbtk_mqtt/mbtk_mqtt_aliyun_test.c
+++ b/mbtk/test/libmbtk_mqtt/mbtk_mqtt_aliyun_test.c
@@ -18,6 +18,8 @@
 */
 
 int aliyun_xiyinyimi_connect(mbtk_mqtt_device_session_t *device, regnwl_info_t *regn);
+void iot_yield(Cloud_MQTT_t *piot_mqtt,iot_device_info_t *gateway);
+
 
 struct opts_struct opts = {
     (char *)"iot-dev", 0, (char *)"\n", QOS0, "admin", "password", (char *)"localhost", 1883, 0
@@ -40,7 +42,7 @@
     return miot_mqtt;
 }
 
-void mqtt_data_rx_cb(void *pbuf, int len) 
+void mqtt_data_rx_cb(void *pbuf, int len)
 {
 
     printf("data = %s\n", (unsigned char *)pbuf);	//打印接收到的数据
@@ -49,7 +51,7 @@
 
 void MQTTMessageArrived_Cb(MessageData* md)
 {
-    MQTTMessage *message = md->message; 
+    MQTTMessage *message = md->message;
 
     Cloud_MQTT_t *piot_mqtt = get_mqtt_t();
 
@@ -63,7 +65,7 @@
 {
     while (gateway.iotstatus != IOT_STATUS_DROP){
         printf("gateway.iotstatus is %d\n",gateway.iotstatus);
-        iot_yield(arg,&gateway);									//维持服务器稳定,断开重连
+        iot_yield((Cloud_MQTT_t*)arg,&gateway);									//维持服务器稳定,断开重连
     }
     printf("gateway.iotstatus is IOT_STATUS_DROP");
 //    mqtt_device_disconnect(arg);
@@ -78,9 +80,9 @@
 {
 
     printf("aliyun mqtt start2\n");
-    int ret, len; 
+//  int ret, len;
     char will_msg[256] = {"hello world"};						//初始化遗嘱数据
-    static int i = 0;
+//  static int i = 0;
 
     mbtk_mqtt_device_session_t mbtk_mqtt_device = {0};
     memcpy(mbtk_mqtt_device.device_name, argv[1] , strlen(argv[1]));
@@ -98,8 +100,8 @@
     mbtk_aliyun_mqtt_one_type_one_secret_unregin_set_info_init(Iot_mqtt, &mbtk_mqtt_device,60*1000,4,mqtt_data_rx_cb);
 
     mqtt_will_msg_set(Iot_mqtt, will_msg, strlen(will_msg));	//设置遗嘱
-    set_mqtt_t(Iot_mqtt);   
-    ret = mbtk_aliyun_mqtt_one_type_one_secret_unregin_device_connect(Iot_mqtt);						//初始化并连接mqtt服务器
+    set_mqtt_t(Iot_mqtt);
+    mbtk_aliyun_mqtt_one_type_one_secret_unregin_device_connect(Iot_mqtt);						//初始化并连接mqtt服务器
 
     printf("connect success\n");
     int rc = mbtk_MQTTSubscribe(&Iot_mqtt->Client, Iot_mqtt->sub_topic, opts.qos, MQTTMessageArrived_Cb);
@@ -124,7 +126,7 @@
 int aliyun_xiyinyimi_connect(mbtk_mqtt_device_session_t *device, regnwl_info_t *regn)
 {
 
-    int ret, len; 
+    int ret;
     char will_msg[256] = {"hello world"};						//初始化遗嘱数据
     static int retry_count = 0;
     pthread_t thread_ID;      //定义线程id
@@ -133,17 +135,17 @@
     Cloud_MQTT_t *Iot_mqtt;
     Iot_mqtt = (Cloud_MQTT_t *)malloc(sizeof(Cloud_MQTT_t));
     memset(Iot_mqtt,0x0,sizeof(Cloud_MQTT_t));
-    
 
-    iot_aliyun_mqtt_one_type_one_secret_unregin_connect_init(Iot_mqtt,device, regn->clientId, regn->deviceToken, 30,3,"aaa","aaa",mqtt_data_rx_cb);	
 
-//    iot_mqtt_init(Iot_mqtt,host,port, client, user, pass,30,3,"aaa","aaa",mqtt_data_rx_cb);	
+    iot_aliyun_mqtt_one_type_one_secret_unregin_connect_init(Iot_mqtt,device, regn->clientId, regn->deviceToken, 30,3,"aaa","aaa",mqtt_data_rx_cb);
+
+//    iot_mqtt_init(Iot_mqtt,host,port, client, user, pass,30,3,"aaa","aaa",mqtt_data_rx_cb);
 
     mqtt_will_msg_set(Iot_mqtt, will_msg, strlen(will_msg));	//设置遗嘱
 
-    set_mqtt_t(Iot_mqtt);    
+    set_mqtt_t(Iot_mqtt);
     ret = mqtt_device_connect(Iot_mqtt);						//初始化并连接mqtt服务器
-    
+
 
     while (ret < 0 && retry_count <= 5) {
         printf("ret = %d\r\n", ret);
@@ -155,7 +157,7 @@
     if(ret < 0 && retry_count > 5)
     {
         printf("reconnect times more than 5 exit\n");
-        return NULL;
+        return -1;
     }
     retry_count = 0;
 
@@ -167,7 +169,7 @@
         return 0;
     }
     gateway.iotstatus = IOT_STATUS_CONNECT;
-    
+
     pthread_create(&thread_ID, NULL, &mqtt_thread, (void *)Iot_mqtt);	//创建一个线程执行mqtt客户端
     pthread_detach(thread_ID);	//设置线程结束收尸
 
diff --git a/mbtk/test/libmbtk_mqtt/mbtk_mqtt_test.c b/mbtk/test/libmbtk_mqtt/mbtk_mqtt_test.c
index 5d99258..684878f 100755
--- a/mbtk/test/libmbtk_mqtt/mbtk_mqtt_test.c
+++ b/mbtk/test/libmbtk_mqtt/mbtk_mqtt_test.c
@@ -11,6 +11,7 @@
 #include "fcntl.h"
 #include "mbtk_sock2.h"
 
+void iot_yield(Cloud_MQTT_t *piot_mqtt,iot_device_info_t *gateway);
 
 struct opts_struct opts = {
     (char *)"iot-dev", 0, (char *)"\n", QOS0, "admin", "password", (char *)"localhost", 1883, 0
@@ -70,7 +71,7 @@
         printf("input error.\n example:./mqtt_test 192.168.1.1 8080 clientid username password\n");
         return 0;
     }
-    int ret, len;
+    int ret ;
     char will_msg[256] = {"hello world"};						//初始化遗嘱数据
     static int retry_count = 0;
     pthread_t thread_ID;      //定义线程id
@@ -96,7 +97,7 @@
     if(ret < 0 && retry_count > 5)
     {
         printf("reconnect times more than 5 exit\n");
-        return NULL;
+        return -1;
     }
     retry_count = 0;
 
diff --git a/mbtk/test/libmbtk_ril/mbtk_info_test.c b/mbtk/test/libmbtk_ril/mbtk_info_test.c
index 116fd4f..5f6135c 100755
--- a/mbtk/test/libmbtk_ril/mbtk_info_test.c
+++ b/mbtk/test/libmbtk_ril/mbtk_info_test.c
@@ -108,7 +108,7 @@
 	uint8 *ptr = (uint8*)data;
 		printf("3sms_state_change_cb() : %s\n", ptr);
 
-	struct SMS_Struct s = PDUDecoding(ptr);
+	struct SMS_Struct s = PDUDecoding((char*)ptr);
 	printf("服务中心地址: %s\n", s.SCA);
     printf("发送方地址: %s\n", s.OA);
     printf("服务中心时间戳: %s\n", s.SCTS);
@@ -134,9 +134,10 @@
 #include <netinet/in.h>
 #include <arpa/inet.h>
 
+#if 0
 static void test2(int is_ipv6, char *ip)
 {
-    char ipaddr[20] = {0};
+//    char ipaddr[20] = {0};
 	if(is_ipv6) {
         struct in6_addr sin_addr;
         if(inet_pton(AF_INET6, ip, &sin_addr) < 0) {
@@ -153,6 +154,7 @@
         }
 	}
 }
+#endif
 
 
 static void help()
@@ -414,7 +416,7 @@
 				{
                     printf("ptr == NULL\n");
                     list_node_t* cell_list = NULL;
-                    int type;
+                    mbtk_cell_type_enum type;
                     err = mbtk_cell_get(info_handle, &type, &cell_list);
                     if(err || cell_list == NULL) {
                         printf("Error : %d\n", err);
@@ -619,7 +621,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(info_handle);
                     if(err) {
@@ -821,7 +823,7 @@
                         printf("APN Num:%d\n", apn_num);
                         int i = 0;
                         while(i < apn_num) {
-                            printf("APN : %d, %s, %s\n", apns[i].cid, apn2str(apns[i].ip_type), apns[i].apn);
+                            printf("APN : %d, %d, %s\n", apns[i].cid, apns[i].ip_type, apns[i].apn);
                             i++;
                         }
                     }
@@ -1000,7 +1002,7 @@
 				char mem[100] = {0};
                 char resp[100] = {0};
                 if(!strcasecmp(cmd, "cpms")) { // Get
-                    err = mbtk_sms_cpms_get(info_handle, &mem);
+                    err = mbtk_sms_cpms_get(info_handle, mem);
                     if(err) {
                         printf("Error : %d\n", err);
                     } else {
@@ -1317,7 +1319,7 @@
 #if 1
     while(1)
     {
-        sleep(1000 * 365 * 24 * 60 * 60);
+        sleep(365 * 24 * 60 * 60);
     }
 #else
     sleep(1);
diff --git a/mbtk/test/libmbtk_tcpip/mbtk_tcpip_test.c b/mbtk/test/libmbtk_tcpip/mbtk_tcpip_test.c
index d30d706..8a7d279 100755
--- a/mbtk/test/libmbtk_tcpip/mbtk_tcpip_test.c
+++ b/mbtk/test/libmbtk_tcpip/mbtk_tcpip_test.c
@@ -177,11 +177,15 @@
                 char type[10] = {0};
                 int read_cb_set;
                 memset(&info, 0x0, sizeof(mbtk_tcpip_info_t));
+                int ack_support,ssl_support,ignore_cert;
                 int count = sscanf(cmd, "link_open %d %s %d %d %s %s %d %d %d %d %d %d", &(info.link_id),
                                 info.ser_addr, &(info.ser_port), &(info.local_port), prot_type, type,
-                                &(info.ack_support), &(info.ssl_support), &(info.ignore_cert), &(info.heartbeat_time),
+                                &ack_support, &ssl_support, &ignore_cert, &(info.heartbeat_time),
                                 &(info.delay_time), &read_cb_set);
                 if(count == 12) {
+                    info.ack_support = (bool)ack_support;
+                    info.ssl_support = (bool)ssl_support;
+                    info.ignore_cert = (bool)ignore_cert;
                     if(!strncasecmp(prot_type, "UDP", 3)) {
                         info.prot_type = MBTK_SOCK_UDP;
                     } else {
@@ -327,7 +331,7 @@
 #if 1
     while(1)
     {
-        sleep(1000 * 365 * 24 * 60 * 60);
+        sleep(365 * 24 * 60 * 60);
     }
 #else
     sleep(1);
diff --git a/mbtk/test/libmbtk_tcpip/tcp_test.c b/mbtk/test/libmbtk_tcpip/tcp_test.c
index 51daace..550514b 100755
--- a/mbtk/test/libmbtk_tcpip/tcp_test.c
+++ b/mbtk/test/libmbtk_tcpip/tcp_test.c
@@ -14,6 +14,7 @@
 #include "mbtk_tcpip.h"
 #include "mbtk_log.h"
 
+#if 0
 
 static void help()
 {
@@ -86,7 +87,7 @@
         }
     }
 }
-
+#endif
 void tcpip_print_tcp_info(mbtk_tcpip_tcp_state_info_s *info)
 {
     printf("Link - %d\n", info->link_id);
@@ -116,17 +117,17 @@
 
     printf(">>>>>>>>>>>START TCP TEST>>>>>>>>>>>>>\r\n");
     mbtk_tcpip_err_enum err;
-        
+
     mbtk_tcpip_info_t info;
     memset(&info, 0x0, sizeof(mbtk_tcpip_info_t));
     char *ip = "www.chaixiongfeng.group";
-    strcpy(&info.ser_addr,ip);
+    strcpy(info.ser_addr,ip);
     info.link_id=1;
     info.ser_port =45002;
     info.prot_type = MBTK_SOCK_TCP;
     info.tcpip_type = MBTK_TCPIP_TYPE_CLIENT;
     info.read_cb = NULL;
-        
+
 
     err = mbtk_tcpip_sock_open((const mbtk_tcpip_info_t*)(&info));
     if(err == MBTK_TCPIP_ERR_SUCCESS) {
@@ -135,42 +136,42 @@
         printf("Link open fail:%d\n", err);
         return 0;
     }
-    
+
     while(1)
     {
         char *data="stargcharge connect\r\n";
         int len = mbtk_tcpip_send(1, data, strlen(data), NULL, 0);
-        if(len == strlen(data)) 
+        if(len == strlen(data))
         {
             printf("Send success:%d.\n", len);
-        } 
-        else 
+        }
+        else
         {
             printf("Send fail:%d/%d\n", len, strlen(data));
         }
 
         char buff[128];
         len = mbtk_tcpip_read(1, buff, 128);
-        if(len > 0) 
+        if(len > 0)
         {
             printf("RECV[%d]:%s\n", len, buff);
         }
-        else 
+        else
         {
             printf("RECV fail:%d\n", len);
         }
 
         err = mbtk_tcpip_sock_close(1);
-        if(err == MBTK_TCPIP_ERR_SUCCESS) 
+        if(err == MBTK_TCPIP_ERR_SUCCESS)
         {
             printf("Link close success.\n");
-        } 
-        else 
+        }
+        else
         {
             printf("Link close fail:%d\n", err);
         }
         sleep(5);
-    }      
+    }
 }
 
 
diff --git a/mbtk/test/libmbtk_wifi/mbtk_wifi_test.c b/mbtk/test/libmbtk_wifi/mbtk_wifi_test.c
old mode 100644
new mode 100755
index 1842b2a..bc5a5a7
--- a/mbtk/test/libmbtk_wifi/mbtk_wifi_test.c
+++ b/mbtk/test/libmbtk_wifi/mbtk_wifi_test.c
@@ -2,8 +2,9 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 
-
+#include "mbtk_utils.h"
 #define STA_BUF_SIZE 2048
 
 
@@ -71,10 +72,10 @@
         printf("Parse cmd fail.\n");
     }
 
-    system("udhcpc -i wlan0");
+    mbtk_system("udhcpc -i wlan0");
 
-    
-    
+
+
     return 0;
 }
 
diff --git a/mbtk/test/others/framebuffer_demo.c b/mbtk/test/others/framebuffer_demo.c
index 281e9ab..bc35a07 100755
--- a/mbtk/test/others/framebuffer_demo.c
+++ b/mbtk/test/others/framebuffer_demo.c
@@ -10,6 +10,8 @@
 #include <sys/mman.h>
 #include <math.h>
 
+#include "mbtk_utils.h"
+
 /**< \brief 根据实际情况修改,此处为unsigned short是565的屏,根据程序打印出的
     bits_per_pixel的值可以判断出输出格式是565还是888 */
 // typedef unsigned int color_t;
@@ -122,8 +124,8 @@
         return;
     }
 
-    read(fd , &filehead , sizeof(filehead));
-    read(fd , &infohead , sizeof(infohead));
+    mbtk_read(fd , &filehead , sizeof(filehead));
+    mbtk_read(fd , &infohead , sizeof(infohead));
     printf("bfType: 0x%x, bfSize: %d, bfOffBits: 0x%x\n", filehead.bfType, filehead.bfSize, filehead.bfOffBits);
 
     printf("biSize: %d, biWidth: %d, biHeight: %d\n", infohead.biSize, infohead.biWidth, infohead.biHeight);
@@ -155,11 +157,11 @@
     }
 
     printf("biSizeImage:%d, width_error: %d\n", infohead.biSizeImage, width_error);
-    read(fd , p_data , infohead.biSizeImage);
+    mbtk_read(fd , p_data , infohead.biSizeImage);
     p = p_data;
 
     int ret;
-    char data[24] = {0};
+    char data[100] = {0};
     int debug_fd = open("/data/debug_fb", O_RDWR|O_CREAT|O_TRUNC, 0644);
     if (debug_fd < 0) {
         printf("debug_fb open error\n");
@@ -168,7 +170,7 @@
     printf("height:%d, width:%d\n", infohead.biHeight, infohead.biWidth);
     for(j = infohead.biHeight - 1; j >= 0; j--) {
         for(i = 0; i < infohead.biWidth; i++) {
-            c = transform_func(p);
+            c = transform_func((char*)p);
             // c = *p;
             p += pixel_byte;
             // c = ((c >> 8) & 0x00ff) | ((c & 0x00ff) << 8);
diff --git a/mbtk/test/others/key_ev_demo.c b/mbtk/test/others/key_ev_demo.c
index 190e4a6..728b5d0 100755
--- a/mbtk/test/others/key_ev_demo.c
+++ b/mbtk/test/others/key_ev_demo.c
@@ -76,6 +76,7 @@
     return 0;
 }
 
+#if 0
 static void ev_exit(void)
 {
     while (ev_count > 0)
@@ -83,6 +84,7 @@
         close(ev_fds[--ev_count].fd);
     }
 }
+#endif
 
 /* wait: 0 dont wait; -1 wait forever; >0 wait ms */
 static int ev_get(struct input_event *ev, int wait_ms)
diff --git a/mbtk/test/others/mbtk_debug_test.c b/mbtk/test/others/mbtk_debug_test.c
index 3057abf..39c8105 100755
--- a/mbtk/test/others/mbtk_debug_test.c
+++ b/mbtk/test/others/mbtk_debug_test.c
@@ -1,4 +1,5 @@
 #include <stdio.h>
+#include <pthread.h>
 
 #include "mbtk_log.h"
 #include "mbtk_utils.h"
@@ -7,7 +8,7 @@
 void test3()
 {
     printf("%s start\n", __FUNCTION__);
-    char *ptr = 10;
+    char *ptr = (char*)10;
     *ptr = 'a';
     printf("%s end\n", __FUNCTION__);
 }
diff --git a/mbtk/test/others/mbtk_gnss_cli.c b/mbtk/test/others/mbtk_gnss_cli.c
index 8699a39..825d501 100755
--- a/mbtk/test/others/mbtk_gnss_cli.c
+++ b/mbtk/test/others/mbtk_gnss_cli.c
@@ -27,6 +27,7 @@
 #include "mbtk_log.h"
 #include "mbtk_type.h"
 #include "mbtk_gnss.h"
+#include "mbtk_utils.h"
 
 #define GNSS_SOCK_PATH "/tmp/mbtk_gnss_sock"
 
@@ -81,15 +82,15 @@
     } else if(cmd == GNSS_CMD_DEINIT) {
         sprintf(buff, "gnss_deinit");
     } else if(cmd == GNSS_CMD_SETTING) {
-        sprintf(buff, "gnss_setting:%s", arg);
+        sprintf(buff, "gnss_setting:%s", (char*)arg);
     } else if(cmd == GNSS_CMD_DL) {
-        sprintf(buff, "gnss_dl:%s", arg);
+        sprintf(buff, "gnss_dl:%s", (char*)arg);
     } else {
         printf("Unknown cmd.\n");
         return -1;
     }
 
-    write(sock_listen_fd, buff, strlen(buff));
+    mbtk_write(sock_listen_fd, buff, strlen(buff));
 
     int len = 0;
     char *rsp = NULL;
diff --git a/mbtk/test/others/partition_write_demo.c b/mbtk/test/others/partition_write_demo.c
index 1256d75..5edfa2d 100755
--- a/mbtk/test/others/partition_write_demo.c
+++ b/mbtk/test/others/partition_write_demo.c
@@ -3,6 +3,7 @@
 #include <fcntl.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <unistd.h>
 
 int main(int argc, char *argv[])
 {
@@ -20,11 +21,11 @@
 
     while((len = write(fd, buffer, sizeof(buffer))) > 0){
         count += len;
-        printf("write : %d\n", count);
+        printf("write : %ld\n", count);
         //usleep(1000);
     }
 
-    printf("Write complete,len = %d, errno = %d\n", len, errno);
+    printf("Write complete,len = %ld, errno = %d\n", len, errno);
 
     close(fd);
 #else
diff --git a/mbtk/test/others/proc_demo.c b/mbtk/test/others/proc_demo.c
index 7712b4c..929984c 100755
--- a/mbtk/test/others/proc_demo.c
+++ b/mbtk/test/others/proc_demo.c
@@ -11,7 +11,7 @@
 
 void test(int c)
 {
-    int d = 10;
+//    int d = 10;
     //printf("函数参数:test_c = %p, 局部变量:d = %p\n", &c, &d);
 }
 
diff --git a/mbtk/test/others/touch_ev_demo.c b/mbtk/test/others/touch_ev_demo.c
index b7ae90d..133384b 100755
--- a/mbtk/test/others/touch_ev_demo.c
+++ b/mbtk/test/others/touch_ev_demo.c
@@ -20,6 +20,8 @@
 #include <dirent.h>
 #include <stdbool.h>
 
+// #include "mbtk_log.h"
+
 #ifndef TRUE
 #define TRUE   1   /* Boolean true value. */
 #endif
@@ -234,7 +236,7 @@
 void ev_dispatch(void)
 {
     unsigned n;
-    int ret;
+//    int ret;
 
     for (n = 0; n < ev_count; n++) {
         ev_callback cb = ev_fdinfo[n].cb;
@@ -356,7 +358,7 @@
 
 int main(int argc, char *argv[])
 {
-    mbtk_log_init(NULL, "MBTK_EVENT");
+    // mbtk_log_init(NULL, "MBTK_EVENT");
 
     if(ev_init(NULL)) {
         LOGE("ev_init() fail.");
diff --git a/mbtk/test/others/usb_check.c b/mbtk/test/others/usb_check.c
index 9aa5ebf..7a8fc43 100755
--- a/mbtk/test/others/usb_check.c
+++ b/mbtk/test/others/usb_check.c
@@ -3,6 +3,7 @@
 #include <stdlib.h>
 #include <signal.h>
 #include <fcntl.h>
+#include <string.h>
 
 #include "mbtk_utils.h"
 
@@ -26,8 +27,8 @@
         while(running){
             memset(buff, 0, 1024);
             if(mbtk_cmd_line("cat /sys/class/android_usb/android0/state", buff, 1024)) {
-                write(fd, buff, strlen(buff));
-                write(fd, "\n", 1);
+                mbtk_write(fd, buff, strlen(buff));
+                mbtk_write(fd, "\n", 1);
             }
             sleep(1);
         }