new_func_wifi_2

Change-Id: I2d61e39dacb155df5e9af72f3eacb704a2c58935
diff --git a/mbtk/libmbtk_lib/wifi/sta_cli.c b/mbtk/libmbtk_lib/wifi/sta_cli.c
index 316d70f..0cf37fd 100644
--- a/mbtk/libmbtk_lib/wifi/sta_cli.c
+++ b/mbtk/libmbtk_lib/wifi/sta_cli.c
@@ -16,6 +16,8 @@
 

 #include "sta_cli.h"

 #include "sta_ctrl.h"

+#include "mbtk_log.h"

+

 //#include "sta_log.h"

 //#include "mbtk_string.h"

 

@@ -83,14 +85,14 @@
         fgets(ssid,200,fd_tmp); 

         pclose(fd_tmp);

         if(strlen(ssid) > 0){

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

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

             

         }else{// Open wpa_supplicant

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

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

         }

     }else{

        

-            printf("test 102:%s\n");

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

     }

 

     return 0;

@@ -107,20 +109,47 @@
         fgets(psk,200,fd_tmp);

         pclose(fd_tmp);

         if(strlen(psk) > 0){

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

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

             

         }else{// Open wpa_supplicant

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

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

         }

     }else{

        

-            printf("test 102:%s\n");

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

     }

 

     return 0;

 }

 

 

+int sta_cli_ssid_set(char *ssid)

+{

+

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

+    

+    

+    return 0;

+}

+

+int sta_cli_psk_set(char *psk)

+{

+

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

+    

+    

+    return 0;

+}

+

+

+

+

 

 static char*

 sta_cli_ssid_process

@@ -135,7 +164,7 @@
     int i;

     for (i = 0; i < strlen(ssid); i++){

         if (!isascii(ssid[i])){

-            //printf("0x%02x\n",(unsigned char)ssid[i]);

+            //LOGE("0x%02x\n",(unsigned char)ssid[i]);

             //return 0;

             ascii = 0;

             break;

@@ -149,7 +178,7 @@
     }else{

 		int pos = 0;

         for (i = 0; i < strlen(ssid); i++){

-            printf("0x%02x\n",(unsigned char)ssid[i]);

+            LOGE("0x%02x\n",(unsigned char)ssid[i]);

         	snprintf(result + pos,len - pos,

                 "%02x",(unsigned char)ssid[i]);

 			pos += 2;

@@ -173,13 +202,13 @@
 

     if((sock=socket(AF_INET,SOCK_STREAM,0))<0)

     {

-        printf("socket:errno(%d)\n",errno);

+        LOGE("socket:errno(%d)\n",errno);

         return NULL;

     }

     strcpy(ifreq.ifr_name,ifname);

     if(ioctl(sock,SIOCGIFHWADDR,&ifreq) <0)

     {

-		printf("ioctl:errno(%d)\n",errno);

+		LOGE("ioctl:errno(%d)\n",errno);

         return NULL;

     }

     snprintf(mac,mac_len,

@@ -268,12 +297,12 @@
     buf[len] = '\0';

     if(sta_cli_conn_fd != -1){

         if(write(sta_cli_conn_fd,buf,len) != len){

-            printf("Send open msg to client fail.\n");

+            LOGE("Send open msg to client fail.\n");

         }else{

-            printf("Send open msg to client success.\n");

+            LOGE("Send open msg to client success.\n");

         }

     }else{

-        printf("No client connected.\n");

+        LOGE("No client connected.\n");

     }

 	sta_should_send_connected_msg = FALSE;

 }

@@ -285,16 +314,16 @@
     char *msg

 )

 {

-    printf("cmd_id = %d,[%s]\n",sta_cli_cmd_id,msg);

+    LOGE("cmd_id = %d,[%s]\n",sta_cli_cmd_id,msg);

 

 //    if(sta_cli_conn_fd != -1){

 //        if(write(sta_cli_conn_fd,msg,strlen(msg)) != strlen(msg)){

-//            printf("Send msg to client fail.\n");

+//            LOGE("Send msg to client fail.\n");

 //        }else{

-//            printf("Send msg to client success.\n");

+//            LOGE("Send msg to client success.\n");

 //        }

 //    }else{

-//        printf("No client connected.\n");

+//        LOGE("No client connected.\n");

 //    }

 

 	// Send msg(CMD_OPEN_SUCCESS) to wifi_server.

@@ -321,12 +350,12 @@
             if(sta_cli_conn_fd != -1){

 				usleep(500);

                 if(write(sta_cli_conn_fd,buf,len) != len){

-                    printf("Send msg to client fail.\n");

+                    LOGE("Send msg to client fail.\n");

                 }else{

-                    printf("Send msg to client success.\n");

+                    LOGE("Send msg to client success.\n");

                 }

             }else{

-                printf("No client connected.\n");

+                LOGE("No client connected.\n");

             }

         }

         return;

@@ -346,12 +375,12 @@
 	        buf[len] = '\0';

 	        if(sta_cli_conn_fd != -1){

 	            if(write(sta_cli_conn_fd,buf,len) != len){

-	                printf("Send msg to client fail.\n");

+	                LOGE("Send msg to client fail.\n");

 	            }else{

-	                printf("Send msg to client success.\n");

+	                LOGE("Send msg to client success.\n");

 	            }

 	        }else{

-	            printf("No client connected.\n");

+	            LOGE("No client connected.\n");

 	        }

 			//sta_connected = FALSE;

 			//pthread_mutex_unlock(&sta_mutex);

@@ -371,7 +400,7 @@
         case CMD_ID_SCAN:

         {

             if(str_contains(msg, "CTRL-EVENT-SCAN-RESULTS")){

-                printf("Start resume thread.\n");

+                LOGE("Start resume thread.\n");

                 pthread_mutex_lock(&mutex);

                 pthread_cond_signal(&cond);

                 //pthread_cond_broadcast(&cond);

@@ -380,7 +409,7 @@
             break;

         }

         default:

-            printf("cmd_id[%d] unknown.\n",sta_cli_cmd_id);

+            LOGE("cmd_id[%d] unknown.\n",sta_cli_cmd_id);

             break;

     }

 }

@@ -394,14 +423,14 @@
     struct timeval now_1;

     struct timespec outtime;

     int thread_id = pthread_self();

-    printf("Thread(%ld) pause.\n",thread_id);

+    LOGE("Thread(%ld) pause.\n",thread_id);

     pthread_mutex_lock(&mutex);

     gettimeofday(&now_1, NULL);

     outtime.tv_sec = now_1.tv_sec + time / 1000;

     outtime.tv_nsec = now_1.tv_usec * 1000;

     pthread_cond_timedwait(&cond, &mutex, &outtime);

     pthread_mutex_unlock(&mutex);

-    printf("Thread(%ld) resume.\n",thread_id);

+    LOGE("Thread(%ld) resume.\n",thread_id);

 }

 

 static bool

@@ -451,7 +480,7 @@
 )

 {

 	char *data_base = data;

-    printf("SCAN:\n%s\n",reply);

+    LOGE("SCAN:\n%s\n",reply);

     bzero(data,len);

     const char *ptr = reply;

     bool start = FALSE;

@@ -488,7 +517,7 @@
         }

     }

 

-    printf("SCAN 0:\n%s\n",data_base);

+    LOGE("SCAN 0:\n%s\n",data_base);

 

 	// Delete empty ssid line.

 	char *tmp = (char*)calloc(len,1);

@@ -497,16 +526,16 @@
 

 	char *ptr_pre = tmp;

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

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

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

 	char ssid[STA_BUF_SIZE] = {0};

 	char *p;

 	while(ptr)

 	{

-		printf("Get line.\n");

+		LOGE("Get line.\n");

 		// Get ssid.

 		if(*(ptr - 1) == ',') // No ssid

 		{

-			printf("Delete one line.\n");

+			LOGE("Delete one line.\n");

 		}else{

 			char s[STA_BUF_SIZE] = {0};

 			p = ptr - 1;

@@ -516,10 +545,10 @@
 			}

 			p += 2;

 			memcpy(s,p,len);

-			printf("ssid = %s;s = %s\n",ssid,s);

+			LOGE("ssid = %s;s = %s\n",ssid,s);

 			if(str_contains(ssid,s))

 			{

-				printf("Jump the same ssid:%s\n",s);

+				LOGE("Jump the same ssid:%s\n",s);

 				ptr_pre = ptr + 2;

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

 				continue;

@@ -531,18 +560,18 @@
 			memcpy(ssid + strlen(ssid),s,len);

 

 			memcpy(data_base + strlen(data_base),ptr_pre,ptr + 2 - ptr_pre);

-			printf("Copy ssid:\"%s\"\n",s);

+			LOGE("Copy ssid:\"%s\"\n",s);

 		}

 		ptr_pre = ptr + 2;

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

 	}

 

-	printf("Scan parse end.\n");

+	LOGE("Scan parse end.\n");

 

 	free(tmp);

 	tmp = NULL;

 

-	printf("SCAN 1:\n%s\n",data_base);

+	LOGE("SCAN 1:\n%s\n",data_base);

 

     return STA_ERR_SUCCESS;

 }

@@ -555,7 +584,7 @@
     size_t data_len

 )

 {

-    printf("STATUS:\n%s\n",reply);

+    LOGE("STATUS:\n%s\n",reply);

 

     bzero(data,data_len);

 

@@ -597,7 +626,7 @@
 		}else{

 			memcpy(data + len,",",1);

 			len += 1;

-			printf("Not get own MAC address.\n");

+			LOGE("Not get own MAC address.\n");

 		}

 

 		// net_id

@@ -612,7 +641,7 @@
 		}else{

 			memcpy(data + len,",",1);

 			len += 1;

-			printf("Not get net id.\n");

+			LOGE("Not get net id.\n");

 		}

 

 		// ssid

@@ -627,7 +656,7 @@
 		}else{

 			memcpy(data + len,",",1);

 			len += 1;

-			printf("Not get ssid.\n");

+			LOGE("Not get ssid.\n");

 		}

 

 		// freq

@@ -644,7 +673,7 @@
 		}else{

 			memcpy(data + len,",",1);

 			len += 1;

-			printf("Not get freq.\n");

+			LOGE("Not get freq.\n");

 		}

 

 		// auth

@@ -679,13 +708,13 @@
 				}else{

 					memcpy(data + len,",",1);

 					len += 1;

-					printf("Not get group_cipher.\n");

+					LOGE("Not get group_cipher.\n");

 				}

 			}

 		}else{

 			memcpy(data + len,",",1);

 			len += 1;

-			printf("Not get key_mgmt.\n");

+			LOGE("Not get key_mgmt.\n");

 		}

 

 		// mac_ap

@@ -705,7 +734,7 @@
 		}else{

 			memcpy(data + len,",",1);

 			len += 1;

-			printf("Not get IP.\n");

+			LOGE("Not get IP.\n");

 		}

 	}else{

 		memcpy(data + len,"0",1);

@@ -723,7 +752,7 @@
 		}else{

 			memcpy(data + len,",",1);

 			len += 1;

-			printf("Not get MAC address.\n");

+			LOGE("Not get MAC address.\n");

 		}

 

 		memcpy(data + len,",,,,,,,",7);

@@ -734,7 +763,7 @@
 	len += 2;

 	data[len] = '\0';

 

-    printf("STATUS:\n%s\n",data);

+    LOGE("STATUS:\n%s\n",data);

 #undef BUF_SIZE

     return STA_ERR_SUCCESS;

 }

@@ -747,7 +776,7 @@
     size_t len

 )

 {

-    printf("MIB:\n%s\n",reply);

+    LOGE("MIB:\n%s\n",reply);

 

     memcpy(data,reply,strlen(reply));

 

@@ -762,7 +791,7 @@
     size_t len

 )

 {

-    printf("LIST_NETWORK:\n%s\n",reply);

+    LOGE("LIST_NETWORK:\n%s\n",reply);

 

     bzero(data,len);

     const char *ptr = reply;

@@ -808,7 +837,7 @@
 

     //memcpy(data,reply,strlen(reply));

 

-    printf("LIST_NETWORK:\n%s\n",data);

+    LOGE("LIST_NETWORK:\n%s\n",data);

 

     return STA_ERR_SUCCESS;

 }

@@ -823,17 +852,17 @@
     if(err == STA_ERR_SUCCESS){

         if(strncmp(cmd,STA_CMD_SCAN,strlen(STA_CMD_SCAN)) == 0

             && strncmp(sta_cli_cmd_reply,STA_TAG_CMD_FAIL_BUSY,strlen(STA_TAG_CMD_FAIL_BUSY)) == 0){

-            printf("\"%s\" busy.\n",cmd);

+            LOGE("\"%s\" busy.\n",cmd);

             return STA_ERR_SUCCESS;

         }

 

         if(strncmp(sta_cli_cmd_reply,STA_TAG_CMD_FAIL,strlen(STA_TAG_CMD_FAIL)) == 0){

-            printf("\"%s\" fail.\n",cmd);

+            LOGE("\"%s\" fail.\n",cmd);

             return STA_ERR_UNKNOWN;

         }

-        printf("[%s]:\n%s\n",cmd,sta_cli_cmd_reply);

+        LOGE("[%s]:\n%s\n",cmd,sta_cli_cmd_reply);

     }else{

-        printf("[%s]:FAIL\n",cmd);

+        LOGE("[%s]:FAIL\n",cmd);

     }

     return err;

 }

@@ -864,17 +893,17 @@
                     data,

                     len);

             }else{

-                printf("SCAN_RESULTS cmd fail.\n");

+                LOGE("SCAN_RESULTS cmd fail.\n");

                 return STA_ERR_UNKNOWN;

             }

         }else{

             sta_cli_cmd_id = CMD_ID_NON;

-            printf("SCAN cmd fail.\n");

+            LOGE("SCAN cmd fail.\n");

             return STA_ERR_UNKNOWN;

         }

     }else{

         sta_cli_cmd_id = CMD_ID_NON;

-        printf("SCAN cmd fail.\n");

+        LOGE("SCAN cmd fail.\n");

         return err;

     }

 }

@@ -910,11 +939,11 @@
 			ptr++; // Point to flag.

 

 			memcpy(flag,ptr,len);

-			printf("%s : %s\n",ssid,flag);

+			LOGE("%s : %s\n",ssid,flag);

 			return flag;

 		}

     }else{

-		printf("SCAN_RESULTS cmd fail.");

+		LOGE("SCAN_RESULTS cmd fail.");

 		return NULL;

     }

     return NULL;

@@ -938,7 +967,7 @@
             data,

             len);

     }else{

-        printf("STATUS cmd fail.\n");

+        LOGE("STATUS cmd fail.\n");

         return err;

     }

 }

@@ -960,7 +989,7 @@
             data,

             len);

     }else{

-        printf("MIB cmd fail.\n");

+        LOGE("MIB cmd fail.\n");

         return err;

     }

 }

@@ -978,12 +1007,12 @@
         if(strncmp(sta_cli_cmd_reply,"OK",2) == 0){

             return STA_ERR_SUCCESS;

         }else{

-            printf("RECONFIGURE cmd fail.\n");

+            LOGE("RECONFIGURE cmd fail.\n");

             return STA_ERR_UNKNOWN;

         }

     }else{

         sta_cli_cmd_id = CMD_ID_NON;

-        printf("RECONFIGURE cmd fail.\n");

+        LOGE("RECONFIGURE cmd fail.\n");

         return err;

     }

 }

@@ -1001,12 +1030,12 @@
         if(strncmp(sta_cli_cmd_reply,"OK",2) == 0){

             return STA_ERR_SUCCESS;

         }else{

-            printf("DISCONNECT cmd fail.\n");

+            LOGE("DISCONNECT cmd fail.\n");

             return STA_ERR_UNKNOWN;

         }

     }else{

         sta_cli_cmd_id = CMD_ID_NON;

-        printf("DISCONNECT cmd fail.\n");

+        LOGE("DISCONNECT cmd fail.\n");

         return err;

     }

 }

@@ -1024,12 +1053,12 @@
         if(strncmp(sta_cli_cmd_reply,"OK",2) == 0){

             return STA_ERR_SUCCESS;

         }else{

-            printf("RECONNECT cmd fail.\n");

+            LOGE("RECONNECT cmd fail.\n");

             return STA_ERR_UNKNOWN;

         }

     }else{

         sta_cli_cmd_id = CMD_ID_NON;

-        printf("RECONNECT cmd fail.\n");

+        LOGE("RECONNECT cmd fail.\n");

         return err;

     }

 }

@@ -1048,12 +1077,12 @@
         if(strncmp(sta_cli_cmd_reply,"OK",2) == 0){

             return STA_ERR_SUCCESS;

         }else{

-            printf("SAVE_CONFIG cmd fail.\n");

+            LOGE("SAVE_CONFIG cmd fail.\n");

             return STA_ERR_UNKNOWN;

         }

     }else{

         sta_cli_cmd_id = CMD_ID_NON;

-        printf("SAVE_CONFIG cmd fail.\n");

+        LOGE("SAVE_CONFIG cmd fail.\n");

         return err;

     }

 }

@@ -1064,7 +1093,7 @@
 	char *c

 )

 {

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

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

 	char *ptr = c;

 

     sta_cli_cmd_id = CMD_ID_SET_NETWORK;

@@ -1088,22 +1117,22 @@
 	    if(STA_ERR_SUCCESS == err){

 	        if(strncmp(sta_cli_cmd_reply,"OK",2) == 0){

 	            //return STA_ERR_SUCCESS;

-	            printf("Success:%s\n",cmd);

+	            LOGE("Success:%s\n",cmd);

 	        }else{

-	            printf("Fail:%s\n",cmd);

+	            LOGE("Fail:%s\n",cmd);

 				sta_cli_cmd_id = CMD_ID_NON;

 	            return STA_ERR_UNKNOWN;

 	        }

 	    }else{

 	        sta_cli_cmd_id = CMD_ID_NON;

-	        printf("Fail:%s\n",cmd);

+	        LOGE("Fail:%s\n",cmd);

 	        return err;

 	    }

 

 		if(ptr == NULL)

 			break;

 

-		printf("ptr = %s",ptr);

+		LOGE("ptr = %s",ptr);

 

 		index = str_indexof(ptr,"#");

 		bzero(cmd,100);

@@ -1129,26 +1158,26 @@
     const char *flag

 )

 {

-	printf("cmd = %s\n",cmd);

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

 	char buf[500];

-    printf("test11\n");

+    LOGE("test11\n");

 	int index = str_indexof(cmd," psk ");

-    printf("test12\n");

+    LOGE("test12\n");

 	int net_id = atoi(cmd + strlen(STA_CMD_SET_NETWORK) + 1);

-    printf("test13\n");

+    LOGE("test13\n");

 	if(index > 0){ // Is set "psk"

-	    printf("test14\n");

+	    LOGE("test14\n");

 		char psk[64] = {0};

 		int start = index + 5; // " psk "

 		if(*(cmd + start) == '"')

 		{

-		    printf("test15\n");

+		    LOGE("test15\n");

 			memcpy(psk,cmd + start + 1,strlen(cmd) - start - 2);

 		}else{

-            printf("test16\n");

+            LOGE("test16\n");

 			memcpy(psk,cmd + start,strlen(cmd) - start);

 		}

-		printf("psk = %s\n",psk);

+		LOGE("psk = %s\n",psk);

 

 		// Set to OPEN (No psk)

 		// SET_NETWORK <net_id> key_mgmt NONE

@@ -1212,7 +1241,7 @@
 	}

 	else // SSID

 	{

-	    printf("test21\n");

+	    LOGE("test21\n");

 		index = str_indexof(cmd," ssid ");

 		char ssid[STA_BUF_SIZE] = {0};

 		int start = index + 6; // " ssid "

@@ -1222,12 +1251,12 @@
 		}else{

 			memcpy(ssid,cmd + start,strlen(cmd) - start);

 		}

-		printf("ssid = %s\n",ssid);

+		LOGE("ssid = %s\n",ssid);

 

 

 		//char ssid_result[STA_SSID_MAX_LEN + 1];

 		//sta_cli_ssid_process(ssid,ssid_result,STA_SSID_MAX_LEN + 2 + 1);

-       // printf("test22, ssid_result: %s\n", ssid_result);

+       // LOGE("test22, ssid_result: %s\n", ssid_result);

 		char cmd_result[STA_BUF_SIZE];

 		int size = snprintf(cmd_result,STA_BUF_SIZE,

 			"%s %d ssid %s",

@@ -1235,7 +1264,7 @@
 			net_id,

 			ssid);

 		cmd_result[size] = '\0';

-		printf("cmd = %s\n",cmd_result);

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

 

 		return sta_cli_cmd_set_network_process(cmd);

 	}

@@ -1269,11 +1298,11 @@
             tmp--;

         }

 

-        printf("GET_NETWORK:%s.\n",value);

+        LOGE("GET_NETWORK:%s.\n",value);

         return STA_ERR_SUCCESS;

     }else{

         sta_cli_cmd_id = CMD_ID_NON;

-        printf("GET_NETWORK cmd fail.\n");

+        LOGE("GET_NETWORK cmd fail.\n");

         return err;

     }

 }

@@ -1291,12 +1320,12 @@
         if(strncmp(sta_cli_cmd_reply,"OK",2) == 0){

             return STA_ERR_SUCCESS;

         }else{

-            printf("REMOVE_NETWORK cmd fail.\n");

+            LOGE("REMOVE_NETWORK cmd fail.\n");

             return STA_ERR_UNKNOWN;

         }

     }else{

         sta_cli_cmd_id = CMD_ID_NON;

-        printf("REMOVE_NETWORK cmd fail.\n");

+        LOGE("REMOVE_NETWORK cmd fail.\n");

         return err;

     }

 }

@@ -1308,17 +1337,17 @@
     const char *cmd

 )

 {

-	printf("cmd = %s\n",cmd);

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

     sta_cli_cmd_id = CMD_ID_ADD_NETWORK;

     sta_err_enum err = sta_cli_process_cmd(STA_CMD_ADD_NETWORK);

-    printf("test1\n");

+    LOGE("test1\n");

     if(STA_ERR_SUCCESS == err){

         sta_cli_cmd_id = CMD_ID_NON;

         int net_id = atoi(sta_cli_cmd_reply);

-        printf("test2\n");

+        LOGE("test2\n");

         if(net_id >= 0){ // Add network success.

             // Point to ssid

-            printf("test3\n");

+            LOGE("test3\n");

             /*

             const char *ptr = cmd + strlen(STA_CMD_ADD_NETWORK) + 1;

 

@@ -1331,7 +1360,7 @@
 

 

             char ssid[STA_BUF_SIZE] = {0};

-            printf("test4\n");

+            LOGE("test4\n");

             memcpy(ssid,ptr,pass_ptr - ptr - 1);

             */

 

@@ -1339,7 +1368,7 @@
             char ssid[STA_BUF_SIZE] = {'\0'};

             char psk[STA_BUF_SIZE] = {'\0'};

             int len = 0;

-            printf("test5\n");

+            LOGE("test5\n");

 

             sta_cli_ssid_get(ssid);

             len = strlen(ssid);

@@ -1355,12 +1384,12 @@
                 STA_CMD_SET_NETWORK,

                 net_id,

                 ssid);

-            printf("test6\n");

+            LOGE("test6\n");

             buf[size] = '\0';

 

          

             err = sta_cli_cmd_set_network(buf,NULL);

-            printf("test7\n");

+            LOGE("test7\n");

             if(STA_ERR_SUCCESS == err){

 				char flag[50];

 				sta_cli_flag_get(ssid,flag,50);

@@ -1388,11 +1417,11 @@
 

             return err;

         }else{

-            printf("ADD_NETWORK cmd fail.\n");

+            LOGE("ADD_NETWORK cmd fail.\n");

             return STA_ERR_UNKNOWN;

         }

     }else{

-        printf("ADD_NETWORK cmd fail.\n");

+        LOGE("ADD_NETWORK cmd fail.\n");

         sta_cli_cmd_id = CMD_ID_NON;

         return err;

     }

@@ -1411,12 +1440,12 @@
         if(strncmp(sta_cli_cmd_reply,"OK",2) == 0){

             return STA_ERR_SUCCESS;

         }else{

-            printf("DISABLE_NETWORK cmd fail.\n");

+            LOGE("DISABLE_NETWORK cmd fail.\n");

             return STA_ERR_UNKNOWN;

         }

     }else{

         sta_cli_cmd_id = CMD_ID_NON;

-        printf("DISABLE_NETWORK cmd fail.\n");

+        LOGE("DISABLE_NETWORK cmd fail.\n");

         return err;

     }

 }

@@ -1434,12 +1463,12 @@
         if(strncmp(sta_cli_cmd_reply,"OK",2) == 0){

             return STA_ERR_SUCCESS;

         }else{

-            printf("ENABLE_NETWORK cmd fail.\n");

+            LOGE("ENABLE_NETWORK cmd fail.\n");

             return STA_ERR_UNKNOWN;

         }

     }else{

         sta_cli_cmd_id = CMD_ID_NON;

-        printf("ENABLE_NETWORK cmd fail.\n");

+        LOGE("ENABLE_NETWORK cmd fail.\n");

         return err;

     }

 }

@@ -1457,12 +1486,12 @@
         if(strncmp(sta_cli_cmd_reply,"OK",2) == 0){

             return STA_ERR_SUCCESS;

         }else{

-            printf("SELECT_NETWORK cmd fail.\n");

+            LOGE("SELECT_NETWORK cmd fail.\n");

             return STA_ERR_UNKNOWN;

         }

     }else{

         sta_cli_cmd_id = CMD_ID_NON;

-        printf("SELECT_NETWORK cmd fail.\n");

+        LOGE("SELECT_NETWORK cmd fail.\n");

         return err;

     }

 }

@@ -1484,7 +1513,7 @@
             data,

             len);

     }else{

-        printf("LIST_NETWORKS cmd fail.\n");

+        LOGE("LIST_NETWORKS cmd fail.\n");

         return err;

     }

 }

@@ -1502,12 +1531,12 @@
         if(strncmp(sta_cli_cmd_reply,"OK",2) == 0){

             return STA_ERR_SUCCESS;

         }else{

-            printf("REASSOCIATE cmd fail.\n");

+            LOGE("REASSOCIATE cmd fail.\n");

             return STA_ERR_UNKNOWN;

         }

     }else{

         sta_cli_cmd_id = CMD_ID_NON;

-        printf("REASSOCIATE cmd fail.\n");

+        LOGE("REASSOCIATE cmd fail.\n");

         return err;

     }

 }

@@ -1525,12 +1554,12 @@
         if(strncmp(sta_cli_cmd_reply,"OK",2) == 0){

             return STA_ERR_SUCCESS;

         }else{

-            printf("REATTACH cmd fail.\n");

+            LOGE("REATTACH cmd fail.\n");

             return STA_ERR_UNKNOWN;

         }

     }else{

         sta_cli_cmd_id = CMD_ID_NON;

-        printf("REATTACH cmd fail.\n");

+        LOGE("REATTACH cmd fail.\n");

         return err;

     }

 }

@@ -1543,7 +1572,7 @@
 {

     sta_err_enum result = STA_ERR_SUCCESS;

     if((result = sta_ctrl_driver_init(TRUE)) != STA_ERR_SUCCESS){

-        printf("Driver init fail(%d).\n",result);

+        LOGE("Driver init fail(%d).\n",result);

         return result;

     }

 

@@ -1551,7 +1580,7 @@
         "/etc/wifi/wpa_supplicant.conf",

         "wlan0",

         sta_cli_wpa_msg_cb)) != STA_ERR_SUCCESS){

-        printf("wpa_supplicant init fail(%d).\n",result);

+        LOGE("wpa_supplicant init fail(%d).\n",result);

         return result;

     }

 	//pthread_mutex_init(&sta_mutex,NULL);

@@ -1566,12 +1595,12 @@
 {

     sta_err_enum result = STA_ERR_SUCCESS;

     if((result = sta_ctrl_wpa_deinit()) != STA_ERR_SUCCESS){

-        printf("sta_ctrl_wpa_deinit fail(%d).",result);

+        LOGE("sta_ctrl_wpa_deinit fail(%d).",result);

         return result;

     }

 

     if((result = sta_ctrl_driver_init(FALSE)) != STA_ERR_SUCCESS){

-        printf("Driver close fail(%d).\n",result);

+        LOGE("Driver close fail(%d).\n",result);

         return result;

     }

 	//pthread_mutex_destroy(&sta_mutex);

@@ -1594,7 +1623,7 @@
     size_t reply_len

 )

 {

-	printf("cmd:%s\n",cmd);

+	LOGE("cmd:%s\n",cmd);

     bzero(reply,reply_len);

     sta_err_enum err = STA_ERR_UNKNOWN;

     if(strncmp(cmd,(STA_CMD_OPEN),strlen(STA_CMD_OPEN)) == 0){

@@ -1637,9 +1666,7 @@
         err = sta_cli_cmd_scan(cmd, data,STA_BUF_SIZE);

         if(err == STA_ERR_SUCCESS){

             snprintf(reply,reply_len,

-                "%s-%s-%s"STA_CMD_SEPARATED,

-                STA_TAG_CMD,

-                cmd,

+                "%s"STA_CMD_SEPARATED,

                 data);

         }else{

             snprintf(reply,reply_len,

@@ -1721,7 +1748,7 @@
 #endif

 		if(err == STA_ERR_SUCCESS)

 		{

-			printf("sta_cli_cmd_disconnect success.\n");

+			LOGE("sta_cli_cmd_disconnect success.\n");

 			//pthread_mutex_lock(&sta_mutex);

 			//if(sta_connected)

 			//{

@@ -1739,7 +1766,7 @@
 							mac_ap,

 							STA_MAC_LEN + 1)) // Disconnected.

 						{

-							printf("Disconnected success.\n");

+							LOGE("Disconnected success.\n");

 							snprintf(reply,reply_len,

 								"%s-%s-%s"STA_CMD_SEPARATED,

 								STA_TAG_CMD,

@@ -1748,18 +1775,18 @@
 							ok = TRUE;

 							break;

 						}else{ // Connected.

-							printf("Not disconnected.Try again(STATUS).\n");

+							LOGE("Not disconnected.Try again(STATUS).\n");

 							usleep(500);

 						}

 				    }else{

-				        printf("STATUS cmd fail.\n");

+				        LOGE("STATUS cmd fail.\n");

 				        break;

 				    }

 				}

 

 				if(!ok) // fail

 				{

-					printf("Disconnect fail.\n");

+					LOGE("Disconnect fail.\n");

 		            snprintf(reply,reply_len,

 		                "%s-%s-%s:%d"STA_CMD_SEPARATED,

 		                STA_TAG_CMD,

@@ -1771,7 +1798,7 @@
 			//}

 			//pthread_mutex_unlock(&sta_mutex);

 		}else{

-			printf("sta_cli_cmd_disconnect fail.\n");

+			LOGE("sta_cli_cmd_disconnect fail.\n");

             snprintf(reply,reply_len,

                 "%s-%s-%s:%d"STA_CMD_SEPARATED,

                 STA_TAG_CMD,

@@ -1999,7 +2026,7 @@
                 err);

         }

     }else{

-        printf("Unknown cmd:%s\n",cmd);

+        LOGE("Unknown cmd:%s\n",cmd);

         return FALSE;

     }

     return TRUE;