Fix code warning.

Change-Id: Ib11fb49f528d3688351ae349d5b4e307c28b3967
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: