Fix warning as error for V2

Change-Id: I70cfd971fda629011ba1be84fef15afea196d393
diff --git a/mbtk/libmbtk_lib_v2/wifi/sta_cli.c b/mbtk/libmbtk_lib_v2/wifi/sta_cli.c
index 0cf37fd..9dbd202 100755
--- a/mbtk/libmbtk_lib_v2/wifi/sta_cli.c
+++ b/mbtk/libmbtk_lib_v2/wifi/sta_cli.c
@@ -12,11 +12,14 @@
 #include <sys/ioctl.h>

 #include <net/if.h>

 #include <string.h>

-

+#include <ctype.h>

+#include <stdlib.h>

 

 #include "sta_cli.h"

 #include "sta_ctrl.h"

 #include "mbtk_log.h"

+#include "mbtk_utils.h"

+#include "mbtk_str.h"

 

 //#include "sta_log.h"

 //#include "mbtk_string.h"

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

 #define STA_SSID_MAX_LEN (32 * 5)

 

+bool sta_ctrl_system(const char   *command);

 

 #ifndef INFTIM

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

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

 static pthread_mutex_t mutex;

 static int sta_cli_conn_fd = -1;

-static char sta_cli_buf[STA_BUF_SIZE];

+//static char sta_cli_buf[STA_BUF_SIZE];

 static bool sta_should_send_connected_msg = TRUE;

 //static bool sta_connected = FALSE;

 static bool sta_disconnectting = FALSE;

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

 

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

-  

+

     if(fd_tmp){

-        char buf[200] = {0};

-        fgets(ssid,200,fd_tmp); 

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

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

+            return -1;

         pclose(fd_tmp);

         if(strlen(ssid) > 0){

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

-            

+

         }else{// Open wpa_supplicant

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

         }

     }else{

-       

+

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

     }

 

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

 

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

-  

+

     if(fd_tmp){

-        char buf[200] = {0};

-        fgets(psk,200,fd_tmp);

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

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

+            return -1;

         pclose(fd_tmp);

         if(strlen(psk) > 0){

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

-            

+

         }else{// Open wpa_supplicant

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

         }

     }else{

-       

+

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

     }

 

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

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

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

-    system(buf);

-    

-    

+    mbtk_system(buf);

+

+

     return 0;

 }

 

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

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

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

-    system(buf);

-    

-    

+    mbtk_system(buf);

+

+

     return 0;

 }

 

 

 

 

-

+#if 0

 static char*

 sta_cli_ssid_process

 (

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

     return result;

 }

-

+#endif

 

 static char*

 sta_cli_mac_get

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

     if(stream != NULL)

     {

-		fgets(host, 100, stream);

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

+            return NULL;

+		}

 		pclose(stream);

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

 		if(strlen(host) > 0

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

 	}

 

-	snprintf(name,name_len,

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

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

 

 	return name;

 }

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

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

 		//sta_connected = TRUE;

-		char sta_name[100];

-		sta_cli_sta_name_get(sta_name,100);

+		char sta_name[200];

+		sta_cli_sta_name_get(sta_name,200);

 		char cmd[200];

 		int size = snprintf(cmd,200,

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

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

 	bzero(data_base,len);

 

-	char *ptr_pre = tmp;

+	const char *ptr_pre = tmp;

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

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

 	char ssid[STA_BUF_SIZE] = {0};

-	char *p;

+	const char *p;

 	while(ptr)

 	{

 		LOGE("Get line.\n");

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

 sta_cli_cmd_set_network_process

 (

-	char *c

+	const char *c

 )

 {

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

-	char *ptr = c;

+	const char *ptr = c;

 

     sta_cli_cmd_id = CMD_ID_SET_NETWORK;

 	sta_err_enum err = STA_ERR_SUCCESS;

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

             len = strlen(ssid);

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

-            

+

             sta_cli_psk_get(psk);

             len = strlen(psk);

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

 

-            

+

             int size = snprintf(buf,STA_BUF_SIZE,

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

                 STA_CMD_SET_NETWORK,

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

             buf[size] = '\0';

 

-         

+

             err = sta_cli_cmd_set_network(buf,NULL);

             LOGE("test7\n");

             if(STA_ERR_SUCCESS == err){

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

 #include "sta_ctrl.h"

 #include "mbtk_log.h"

+#include "mbtk_utils.h"

 

 //#include "sta_log.h"

 

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

 );

 

-extern struct wpa_ctrl;

+// extern struct wpa_ctrl;

 

 static struct wpa_ctrl *sta_ctrl_conn;

 static struct wpa_ctrl *sta_mon_conn;

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

         if(cmd)

         {

-            fgets(pid_s, STA_BUF_SIZE, cmd);

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

+

+            }

             pclose(cmd);

         }

+

         pid = atoi(pid_s);

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

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

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

     if(cmd)

     {

-        fgets(pid_s, STA_BUF_SIZE, cmd);

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

+

+        }

         pclose(cmd);

     }

 

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

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

 

-    int nready;

+    int nready = 0;

     struct epoll_event ev_sock,ev_pipe,events[20];

     int epfd = epoll_create(256);

     ev_sock.data.fd = wpa_ctrl_get_fd(sta_mon_conn);

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

         return result;

     }

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

+    sprintf(ctrl_path + strlen(ctrl_path),

         "/%s",

         sta_ctrl_ifname);

 

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

                     break;

                 }

-                *tmp--;

+                tmp--;

             }

 

             int size = snprintf(value,100,

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

     }

 

-end_success:

+//end_success:

 

     return result;

 end_fail:

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

     if(fd_tmp){

         char buf[200] = {0};

-        fgets(buf,200,fd_tmp);

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

+

+        }

         pclose(fd_tmp);

         if(strlen(buf) > 0){

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

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

     if(fd_tmp){

         char buf[200] = {0};

-        fgets(buf,200,fd_tmp);

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

+

+        }

         pclose(fd_tmp);

         if(strlen(buf) > 0){

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

         }else{// Open wpa_supplicant

             bzero(buf,200);

-            

+

             snprintf(buf,200,

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

                 conf_file,

                 interface,

                 WPA_SUPPLICANT_LOG_FILE);

-            

+

             /*

              snprintf(buf,200,

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

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

     }

 

-end_success:

+//end_success:

 

     return result;

 end_fail:

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

     sta_event_thread_is_running = 0;

     // End thread.

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

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

 

 

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

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

     }

 

-end_success:

+//end_success:

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

     return result;

 end_fail: